diff --git a/lsim.kdevelop.pcs b/lsim.kdevelop.pcs index 690f6af..1dd25db 100644 Binary files a/lsim.kdevelop.pcs and b/lsim.kdevelop.pcs differ diff --git a/lsim.kdevses b/lsim.kdevses index e200843..6ee4192 100644 --- a/lsim.kdevses +++ b/lsim.kdevses @@ -1,7 +1,7 @@ - + @@ -9,7 +9,7 @@ - + @@ -18,25 +18,25 @@ - + - + - + - + - + - + @@ -45,10 +45,10 @@ - + - + @@ -60,17 +60,20 @@ - + - + - + + + + diff --git a/src/expdoublespinbox.cpp b/src/expdoublespinbox.cpp index 20800a1..27d7717 100644 --- a/src/expdoublespinbox.cpp +++ b/src/expdoublespinbox.cpp @@ -38,7 +38,10 @@ ExpDoubleSpinBox::~ExpDoubleSpinBox() { double ExpDoubleSpinBox::valueFromText ( const QString& text ) const { - return text.toDouble(); + QString myText(text); + myText.chop(suffix().size()); + myText.remove(prefix().size()); + return myText.toDouble(); } QString ExpDoubleSpinBox::textFromValue ( double val ) const { @@ -58,13 +61,17 @@ QString ExpDoubleSpinBox::textFromValue ( double val ) const { } QValidator::State ExpDoubleSpinBox::validate ( QString & input, int & pos ) const { + QString myInput(input); + myInput.chop(suffix().size()); + myInput.remove(prefix().size()); + QLocale loc; QChar decpoint = loc.decimalPoint(); //Locale abhaengiger dezimaltrenner QString regExpString =QString("[\\-,\\+]?\\d*\\%1?\\d+([e,E][\\-,\\+]\\d+)?").arg(decpoint); QRegExp regExp(regExpString); QValidator *validator = new QRegExpValidator(regExp, 0); //qDebug() << validator->validate(input,pos); - return validator->validate(input,pos); + return validator->validate(myInput,pos); } QDoubleSpinBox::StepEnabled ExpDoubleSpinBox::stepEnabled () const { diff --git a/src/graphicsellipseitem.cpp b/src/graphicsellipseitem.cpp index 6f07ac3..e8a2412 100644 --- a/src/graphicsellipseitem.cpp +++ b/src/graphicsellipseitem.cpp @@ -33,9 +33,10 @@ GraphicsEllipseItem::GraphicsEllipseItem() { setFlag(ItemIsFocusable); //setCacheMode(QGraphicsItem::DeviceCoordinateCache); //startTimer(100); + myProbeChargeWidget = new ProbeChargeWidget(0,0,this); setMasse(9.10938188e-31); setCharge(-1.6e-19); - myProbeChargeWidget = new ProbeChargeWidget(0,0,this); + currProbePath = new QList; speedListX = new QList; speedListY = new QList; @@ -54,12 +55,23 @@ void GraphicsEllipseItem::mousePressEvent ( QGraphicsSceneMouseEvent *event ) { //QGraphicsEllipseItem::mousePressEvent(event); } +void GraphicsEllipseItem::handleSceneChange(const QList & /*region*/) { + if (myScenePos != scenePos()) { + myScenePos = scenePos(); + emit ScenePosChanged(myScenePos); + emit ScenePosXChanged(myScenePos.x()); + emit ScenePosYChanged(myScenePos.y()); + } + +} /*! \fn GraphicsEllipseItem::calculateProbePath() */ -void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpeedX , double startSpeedY) { +void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { + double startSpeedX = getStartSpeedX(); + double startSpeedY = getStartSpeedY(); SimulScene* myScene = dynamic_cast(scene()); //wenn noch zu keiner scene gehoerend abbruch if (myScene == 0) return; @@ -137,7 +149,7 @@ double GraphicsEllipseItem::getCharge() const { } -void GraphicsEllipseItem::setCharge ( const long double& theValue ) { +void GraphicsEllipseItem::setCharge ( const double& theValue ) { if (charge == theValue) return; charge = theValue; emit chargeChanged(theValue); @@ -174,3 +186,21 @@ void GraphicsEllipseItem::setStartSpeedY ( double theValue ) { startSpeedY = theValue; emit startSpeedYChanged(theValue); } + + +/*! + \fn GraphicsEllipseItem::setScenePosY(double posY) + */ +void GraphicsEllipseItem::setScenePosY(double newPosY) +{ + moveBy(0, newPosY - scenePos().y()); +} + + +/*! + \fn GraphicsEllipseItem::setScenePosX(double posX) + */ +void GraphicsEllipseItem::setScenePosX(double newPosX) +{ + moveBy(newPosX - scenePos().x(),0 ); +} diff --git a/src/graphicsellipseitem.h b/src/graphicsellipseitem.h index df62f45..3f66ab1 100644 --- a/src/graphicsellipseitem.h +++ b/src/graphicsellipseitem.h @@ -71,25 +71,33 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { ///Startgeschwindigkeit des teilchens in y-Richtung double startSpeedY; + QPointF myScenePos; + public slots: //! Berechnet die Bewegung der Probeladung /*! \param steps Anzahl der auszufürenden Schriite */ - void calculateProbePath (QPointF startPoint = QPointF(0,0) , double startSpeedX = 0, double startSpeedY = 0); + void calculateProbePath (QPointF startPoint = QPointF(0,0)); void setMasse ( const double& theValue ); - void setCharge ( const long double& theValue ); + void setCharge ( const double& theValue ); void setStartSpeedX ( double theValue ); void setStartSpeedY ( double theValue ); + void setScenePosY(double newPosY); + void setScenePosX(double newPosX); + void handleSceneChange(const QList & /*region*/); signals: void startSpeedXChanged(double speed); void startSpeedYChanged(double speed); void masseChanged(double masse); void chargeChanged(double Charge); + void ScenePosChanged(QPointF newpos); + void ScenePosXChanged(double newX); + void ScenePosYChanged(double newY); diff --git a/src/homobfieldwidget.cpp b/src/homobfieldwidget.cpp index 6ada381..4dc20af 100644 --- a/src/homobfieldwidget.cpp +++ b/src/homobfieldwidget.cpp @@ -87,8 +87,9 @@ void HomoBFieldWidget::createWidget() { ExpDoubleSpinBox* fieldFluxDensityBox = new ExpDoubleSpinBox; fieldFluxDensityBox->setRange(-1e+200,1e+200); fieldFluxDensityBox->setDecimals(40); - fieldFluxDensityBox->setDisplayDecimals(2); + fieldFluxDensityBox->setDisplayDecimals(3); fieldFluxDensityBox->setKeyboardTracking(false); + fieldFluxDensityBox->setSuffix(" T"); connect(homoBField ,SIGNAL(fluxDensityChanged(double)),fieldFluxDensityBox, SLOT(setValue(double)) ); connect(fieldFluxDensityBox, SIGNAL(valueChanged(double)),homoBField ,SLOT(setFluxDensity(double)) ); diff --git a/src/homoefieldwidget.cpp b/src/homoefieldwidget.cpp index 2ed1f6e..d01afba 100644 --- a/src/homoefieldwidget.cpp +++ b/src/homoefieldwidget.cpp @@ -112,14 +112,16 @@ void HomoEFieldWidget::createWidget() fieldPowerBox->setDecimals(35); fieldPowerBox->setDisplayDecimals(3); fieldPowerBox->setKeyboardTracking(false); + fieldPowerBox->setSuffix(" V/m"); connect(homoEField ,SIGNAL(fieldPowerChanged(double)),fieldPowerBox, SLOT(setValue(double)) ); connect(fieldPowerBox, SIGNAL(valueChanged(double)),homoEField ,SLOT(setFieldPower(double)) ); ExpDoubleSpinBox* voltageBox = new ExpDoubleSpinBox; voltageBox->setRange(-1e+200,1e+200); - fieldPowerBox->setDecimals(35); - fieldPowerBox->setDisplayDecimals(3); + voltageBox->setDecimals(35); + voltageBox->setDisplayDecimals(3); voltageBox->setKeyboardTracking(false); + voltageBox->setSuffix(" V"); QGridLayout* constGridLayout = new QGridLayout; //constGridLayout->setSizeConstraint(QLayout::SetFixedSize); diff --git a/src/probechargewidget.cpp b/src/probechargewidget.cpp index ba936c1..97dbbc3 100644 --- a/src/probechargewidget.cpp +++ b/src/probechargewidget.cpp @@ -27,6 +27,7 @@ #include ProbeChargeWidget::ProbeChargeWidget ( QWidget* parent, Qt::WindowFlags f, GraphicsEllipseItem* ellipse ) : QWidget (parent, f ) { + ellipseItem = ellipse; createWidget(); } @@ -43,72 +44,90 @@ void ProbeChargeWidget::createWidget() rotationDial->setWrapping(true); - QDoubleSpinBox *heightBox = new QDoubleSpinBox; + ExpDoubleSpinBox *startSpeedYBox = new ExpDoubleSpinBox; + startSpeedYBox->setDecimals(50); + startSpeedYBox->setDisplayDecimals(3); + startSpeedYBox->setRange(-3e+8, 3e+8); + startSpeedYBox->setKeyboardTracking(false); + connect(startSpeedYBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setStartSpeedY(double)) ); + connect(ellipseItem, SIGNAL(startSpeedYChanged(double)), startSpeedYBox, SLOT(setValue(double)) ); - - - QDoubleSpinBox *widthBox = new QDoubleSpinBox; + ExpDoubleSpinBox *startSpeedXBox = new ExpDoubleSpinBox; + startSpeedXBox->setDecimals(50); + startSpeedXBox->setDisplayDecimals(3); + startSpeedXBox->setRange(-3e+8, 3e+8); + startSpeedXBox->setKeyboardTracking(false); + connect(startSpeedXBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setStartSpeedX(double)) ); + connect(ellipseItem, SIGNAL(startSpeedXChanged(double)), startSpeedXBox, SLOT(setValue(double)) ); QLabel* xLabel = new QLabel(tr("x:")); QLabel* yLabel = new QLabel(tr("y:")); - QLabel* widthLabel = new QLabel(tr("Breite(l):")); - QLabel* heightLabel = new QLabel(tr("H\366he(d):")); - QLabel* rotationLabel = new QLabel(tr("Rotation:")); + QLabel* startSpeedYLabel = new QLabel(tr("Startgeschwindigkeit y:")); + QLabel* startSpeedXLabel = new QLabel(tr("Startgeschwindigkeit x:")); QDoubleSpinBox *posXBox = new QDoubleSpinBox; posXBox->setRange(-5000, 5000); + posXBox->setKeyboardTracking(false); + connect(posXBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setScenePosX(double)) ); + connect(ellipseItem, SIGNAL(ScenePosXChanged(double)), posXBox, SLOT(setValue(double)) ); QDoubleSpinBox *posYBox = new QDoubleSpinBox; posYBox->setRange(-5000, 5000); - - - QSpinBox* rotationBox = new QSpinBox; - rotationBox->setRange(0,359); - rotationBox->setSuffix("\260"); - rotationBox->setWrapping(true); - + posYBox->setKeyboardTracking(false); + connect(posYBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setScenePosY(double)) ); + connect(ellipseItem, SIGNAL(ScenePosYChanged(double)), posYBox, SLOT(setValue(double)) ); QGridLayout* geomGridLayout = new QGridLayout; //geomGridLayout->setSizeConstraint(QLayout::SetFixedSize); - geomGridLayout->addWidget(heightBox,4,1); - geomGridLayout->addWidget(rotationBox,0,1); + geomGridLayout->addWidget(startSpeedYBox,4,1); geomGridLayout->addWidget(posYBox,2,1); geomGridLayout->addWidget(posXBox,1,1); geomGridLayout->addWidget(xLabel,1,0,Qt::AlignRight); geomGridLayout->addWidget(yLabel,2,0,Qt::AlignRight); - geomGridLayout->addWidget(heightLabel,4,0,Qt::AlignRight); - geomGridLayout->addWidget(widthLabel,3,0,Qt::AlignRight); - geomGridLayout->addWidget(rotationLabel,0,0,Qt::AlignRight); - geomGridLayout->addWidget(widthBox,3,1); + geomGridLayout->addWidget(startSpeedYLabel,4,0,Qt::AlignRight); + geomGridLayout->addWidget(startSpeedXLabel,3,0,Qt::AlignRight); + geomGridLayout->addWidget(startSpeedXBox,3,1); //geomGridLayout->addWidget(rotationDial, 1,0,2,2); QGroupBox* geometryBox = new QGroupBox(tr("Geometrie")); geometryBox->setLayout(geomGridLayout); - QLabel* fieldPowerLabel = new QLabel(tr("Feldst\344rke:")); - QLabel* voltageLabel = new QLabel(tr("Spannung:")); + QLabel* chargeLabel = new QLabel(tr("Ladung:")); + QLabel* masseLabel = new QLabel(tr("Masse:")); - ExpDoubleSpinBox* fieldPowerBox = new ExpDoubleSpinBox; - fieldPowerBox->setRange(-1e+200,1e+200); + ExpDoubleSpinBox* chargeBox = new ExpDoubleSpinBox; + chargeBox->setRange(-1e+200,1e+200); + chargeBox->setDecimals(50); + chargeBox->setDisplayDecimals(3); + chargeBox->setKeyboardTracking(false); + chargeBox->setSuffix(" As"); + connect(chargeBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setCharge(double)) ); + connect(ellipseItem, SIGNAL(chargeChanged(double)), chargeBox, SLOT(setValue(double)) ); - ExpDoubleSpinBox* voltageBox = new ExpDoubleSpinBox; - voltageBox->setRange(-1e+200,1e+200); + ExpDoubleSpinBox* masseBox = new ExpDoubleSpinBox; + masseBox->setRange(-1e+200,1e+200); + masseBox->setDecimals(50); + masseBox->setDisplayDecimals(3); + masseBox->setKeyboardTracking(false); + masseBox->setSuffix(" kg"); + connect(masseBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setMasse(double)) ); + connect(ellipseItem, SIGNAL(masseChanged(double)), masseBox, SLOT(setValue(double)) ); QGridLayout* constGridLayout = new QGridLayout; //constGridLayout->setSizeConstraint(QLayout::SetFixedSize); - constGridLayout->addWidget(fieldPowerBox,0,1); - constGridLayout->addWidget(voltageBox,1,1); - constGridLayout->addWidget(fieldPowerLabel,0,0,Qt::AlignRight); - constGridLayout->addWidget(voltageLabel,1,0,Qt::AlignRight); + constGridLayout->addWidget(chargeBox,0,1); + constGridLayout->addWidget(masseBox,1,1); + constGridLayout->addWidget(chargeLabel,0,0,Qt::AlignRight); + constGridLayout->addWidget(masseLabel,1,0,Qt::AlignRight); - QGroupBox* fieldConstantsBox = new QGroupBox(tr("Feldkonstanten")); + QGroupBox* fieldConstantsBox = new QGroupBox(tr("Konstanten")); fieldConstantsBox->setLayout(constGridLayout); @@ -117,10 +136,9 @@ void ProbeChargeWidget::createWidget() mainLayout -> addWidget(fieldConstantsBox); mainLayout -> addStretch(); - QWidget::setTabOrder (rotationBox, posXBox); QWidget::setTabOrder (posXBox, posYBox); - QWidget::setTabOrder (posYBox, widthBox); - QWidget::setTabOrder (widthBox, heightBox); + QWidget::setTabOrder (posYBox, startSpeedYBox); + QWidget::setTabOrder (startSpeedYBox, startSpeedXBox); this -> setLayout(mainLayout); } diff --git a/src/simulscene.cpp b/src/simulscene.cpp index fc33ce9..f0ae3b9 100644 --- a/src/simulscene.cpp +++ b/src/simulscene.cpp @@ -74,7 +74,8 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { ellipse1->setBrush(Qt::red); ellipse1->setZValue(1); //ellipse1->scale(4,4); - ellipse1->setAcceptDrops(true); + ellipse1->setAcceptDrops(true); + connect(this,SIGNAL(changed(QList)),ellipse1,SLOT(handleSceneChange(QList))); addItem(ellipse1); @@ -629,9 +630,9 @@ double SimulScene::getPowerAt(QPointF point, double charge, double speedX, doubl double PowerRadAngle; //Winkel des Lorentzkraftvektors zur x-Achse im Bogenmass if (myHomoBFieldItem->getIsDirectionIntoPlane()) { - PowerRadAngle = speedRadAngle - PI/2.0; - } else { PowerRadAngle = speedRadAngle + PI/2.0; + } else { + PowerRadAngle = speedRadAngle - PI/2.0; } //qDebug()<< PowerRadAngle;