/*************************************************************************** * Copyright (C) 2008 by Peter Dahlberg * * pdahlberg@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "graphicsellipseitem.h" #include #include #include #include #include "simulscene.h" #include "probechargewidget.h" GraphicsEllipseItem::GraphicsEllipseItem() { setFlag(ItemIsMovable); setFlag(ItemIsSelectable); setFlag(ItemIsFocusable); //setCacheMode(QGraphicsItem::DeviceCoordinateCache); //startTimer(100); setMasse(9.10938188e-31); setCharge(-1.6e-19); myProbeChargeWidget = new ProbeChargeWidget(0,0,this); currProbePath = new QList; speedListX = new QList; speedListY = new QList; } void GraphicsEllipseItem::timerEvent ( QTimerEvent * event ) { static double vx; vx++; //moveBy(vx/20.0,vx/20.0*vx/20.0); } GraphicsEllipseItem::~GraphicsEllipseItem() { } void GraphicsEllipseItem::mousePressEvent ( QGraphicsSceneMouseEvent *event ) { //QGraphicsEllipseItem::mousePressEvent(event); } /*! \fn GraphicsEllipseItem::calculateProbePath() */ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpeedX , double startSpeedY) { SimulScene* myScene = dynamic_cast(scene()); //wenn noch zu keiner scene gehoerend abbruch if (myScene == 0) return; //parameter der scene in lokale variablen uebernehmen double timePerStep = myScene->getTimePerStep(); int steps = myScene->getSteps(); double meterPerPx = myScene->getMeterPerPx(); //listen leeren currProbePath->clear(); speedListX->clear(); speedListY->clear(); //startwerte in die listen setzen currProbePath->append(startPoint); speedListX->append(startSpeedX); speedListY->append(startSpeedY); for(int i = 1; i< steps;++i) { double powerX = myScene->getPowerAt(currProbePath->at(i-1), charge, 'x'); double powerY = myScene->getPowerAt(currProbePath->at(i-1), charge, 'y'); double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0); double deltaDistXaccel = 0.5 * (powerX/getMasse()) * (timePerStep/1000.0) * (timePerStep/1000.0); double deltaDistYaccel = 0.5 * (powerY/getMasse()) * (timePerStep/1000.0) * (timePerStep/1000.0); double deltaDistX = (deltaDistXconst + deltaDistXaccel); double deltaDistY = (deltaDistYconst + deltaDistYaccel); currProbePath->append(QPointF(currProbePath->at(i-1).x() + deltaDistX/meterPerPx,currProbePath->at(i-1).y() + deltaDistY/meterPerPx)); speedListX->append(speedListX->at(i-1) + (powerX/getMasse()) * (timePerStep/1000.0)); speedListY->append(speedListY->at(i-1) + (powerY/getMasse()) * (timePerStep/1000.0)); } qDebug()<< "Probe Path: " <<*currProbePath; qDebug()<< "speed x: "<<*speedListX; qDebug()<< "speed y: "<<*speedListY; qDebug()<at(12); qDebug()<at(12); qDebug()<<"power x: "<< (double)myScene->getPowerAt(QPointF(0,0), charge, 'x'); qDebug()<<"power y: " << (double)myScene->getPowerAt(QPointF(0,0), charge, 'y'); } long double GraphicsEllipseItem::getMasse() const { return masse; } void GraphicsEllipseItem::setMasse ( const long double& theValue ) { if (masse == theValue) return; masse = theValue; } long double GraphicsEllipseItem::getCharge() const { return charge; } void GraphicsEllipseItem::setCharge ( const long double& theValue ) { if (charge == theValue) return; charge = theValue; } QWidget * GraphicsEllipseItem::getDockWidget() const { return myProbeChargeWidget; }