diff --git a/lsim.kdevelop.pcs b/lsim.kdevelop.pcs index 322f3a9..a4d43f7 100644 Binary files a/lsim.kdevelop.pcs and b/lsim.kdevelop.pcs differ diff --git a/lsim.kdevses b/lsim.kdevses index 6156c28..3745896 100644 --- a/lsim.kdevses +++ b/lsim.kdevses @@ -1,61 +1,31 @@ - - - + + + - + - - + + - - + + - + - + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/graphicsellipseitem.cpp b/src/graphicsellipseitem.cpp index 03b3552..d0b0024 100644 --- a/src/graphicsellipseitem.cpp +++ b/src/graphicsellipseitem.cpp @@ -29,6 +29,7 @@ #include #include "constants.h" #include +#include GraphicsEllipseItem::GraphicsEllipseItem() { //setFlag(ItemIsMovable); @@ -51,6 +52,8 @@ void GraphicsEllipseItem::setupVars () { setStartSpeedX(0); setStartSpeedY(0); setPos(0,0); + setAdaptiveStepLength(0.01); + setAdaptiveStepControl(true); } void GraphicsEllipseItem::resetProbe() { @@ -120,9 +123,15 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { double powerX = myScene->getPowerAt(currProbePath->at(i-1), charge, speedListX->at(i-1),speedListY->at(i-1), 'x'); double powerY = myScene->getPowerAt(currProbePath->at(i-1), charge, speedListX->at(i-1),speedListY->at(i-1), 'y'); - if (combinedSpeed != 0) timePerStep = 0.008/(combinedSpeed/meterPerPx); - if (timePerStep < (1/10.0 * myScene->getTimePerStep())) timePerStep = 1/10.0 * myScene->getTimePerStep(); - if (timePerStep > (19.0/10.0 * myScene->getTimePerStep())) timePerStep = 19.0/10.0 * myScene->getTimePerStep(); + //automatische Zeitschrittanpassung 0.008 + if (isAdaptiveStepControlEnabled()&&combinedSpeed != 0) timePerStep = getAdaptiveStepLength()/(combinedSpeed/meterPerPx); + //if (timePerStep < (1/10.0 * myScene->getTimePerStep())) timePerStep = 1/10.0 * myScene->getTimePerStep(); + //if (timePerStep > (19.0/10.0 * myScene->getTimePerStep())) timePerStep = 19.0/10.0 * myScene->getTimePerStep(); + double combinedPower = sqrt(powerX*powerX+powerY*powerY); + if (isAdaptiveStepControlEnabled() && combinedPower !=0) { + timePerStep = fabs((-combinedSpeed + sqrt(combinedSpeed*combinedSpeed + 2*(combinedPower/myMasse)*getAdaptiveStepLength()*meterPerPx)) / (combinedPower/myMasse)); + } + //qDebug()<at(i-1).x() + deltaDistX/meterPerPx ,currProbePath->at(i-1).y() + deltaDistY/meterPerPx); + //Scrollbar int Probleme vermeiden + if (newPoint.x() + 10 > INT_MAX || newPoint.x() - 10 < INT_MIN) break; + if (newPoint.y() + 10 > INT_MAX || newPoint.y() - 10 < INT_MIN) break; + if (myScene->stopsHere(currProbePath->at(i-1),newPoint)) break; currProbePath->append(newPoint); @@ -192,7 +205,7 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { if (i%path_entry_step == 0 || i==currProbePath->count()) flightPath.lineTo(currProbePath->at(i)); } - //qDebug()<< "Probe Path: " <<*currProbePath; + qDebug()<< "Probe Path: " <<*currProbePath; //qDebug()<< "speed x: "<<*speedListX; //qDebug()<< "speed y: "<<*speedListY; //qDebug()<at(12); @@ -298,3 +311,27 @@ void GraphicsEllipseItem::setFlightPath ( const QPainterPath& theValue ) { + + +bool GraphicsEllipseItem::isAdaptiveStepControlEnabled() const { + return adaptiveStepControlEnabled; +} + + +void GraphicsEllipseItem::setAdaptiveStepControl ( bool theValue ) { + if (adaptiveStepControlEnabled == theValue) return; + adaptiveStepControlEnabled = theValue; + emit adaptiveStepControlChanged(theValue); +} + + +double GraphicsEllipseItem::getAdaptiveStepLength() const { + return adaptiveStepLength; +} + + +void GraphicsEllipseItem::setAdaptiveStepLength ( double theValue ) { + if (adaptiveStepLength == theValue) return; + adaptiveStepLength = theValue; + emit adaptiveStepLengthChanged(theValue); +} diff --git a/src/graphicsellipseitem.h b/src/graphicsellipseitem.h index ff35954..11670f4 100644 --- a/src/graphicsellipseitem.h +++ b/src/graphicsellipseitem.h @@ -52,6 +52,8 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { QPainterPath getFlightPath() const; double getRealSimulTime() const; + bool isAdaptiveStepControlEnabled() const; + double getAdaptiveStepLength() const; protected: @@ -76,6 +78,10 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { double startSpeedX; ///Startgeschwindigkeit des teilchens in y-Richtung double startSpeedY; + ///automatische Zeitschrittanpassung an/aus + bool adaptiveStepControlEnabled; + ///angenaeherte Schrittlaenge in px + double adaptiveStepLength; QPointF myScenePos; @@ -103,7 +109,10 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { void setFlightPath ( const QPainterPath& theValue ); void resetProbe(); + void setAdaptiveStepControl ( bool theValue ); + void setAdaptiveStepLength ( double theValue ); + signals: void startSpeedXChanged(double speed); void startSpeedYChanged(double speed); @@ -112,6 +121,8 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { void ScenePosChanged(QPointF newpos); void ScenePosXChanged(double newX); void ScenePosYChanged(double newY); + void adaptiveStepControlChanged(bool truefalse); + void adaptiveStepLengthChanged(double length); diff --git a/src/graphicsview.cpp b/src/graphicsview.cpp index 93c4641..285e8b4 100644 --- a/src/graphicsview.cpp +++ b/src/graphicsview.cpp @@ -101,6 +101,12 @@ void GraphicsView::disableOGLViewport() { //setViewport(new QWidget(parentWidget())); } +void GraphicsView::centerOnProbe() { + SimulScene* simulScene = dynamic_cast (scene()); + if (simulScene == 0) return; + centerOn(simulScene->getProbeChargeItem()); +} + GraphicsView::~GraphicsView() { } diff --git a/src/graphicsview.h b/src/graphicsview.h index 7714679..179fa73 100644 --- a/src/graphicsview.h +++ b/src/graphicsview.h @@ -38,6 +38,7 @@ class GraphicsView : public QGraphicsView { public slots: void enableOGLViewport(); void disableOGLViewport(); + void centerOnProbe(); private: QStatusBar * mainWindowStatusBar; diff --git a/src/lsim.cpp b/src/lsim.cpp index 2725852..dd9f8fc 100644 --- a/src/lsim.cpp +++ b/src/lsim.cpp @@ -102,14 +102,19 @@ void lsim::createActions() { acts.calculate->setStatusTip (tr ("Flugbahn berechnen")); connect (acts.calculate, SIGNAL (triggered()), this, SLOT (startCalculation())); - acts.resetAct = new QAction (tr ("reset"), this); - acts.resetAct->setStatusTip (tr ("reset")); + acts.resetAct = new QAction (tr ("Alles Zur\374cksetzen"), this); + acts.resetAct->setStatusTip (tr ("Alle Werte Zur\374cksetzen und alle Felder L\366schen")); connect (acts.resetAct, SIGNAL (triggered()), this, SLOT (resetAll())); acts.timerStart = new QAction (tr ("Timer Start"), this); acts.timerStart->setStatusTip (tr ("Timer starten")); connect (acts.timerStart, SIGNAL (triggered()), this, SLOT (startTimer())); + acts.centerOnProbeAct = new QAction (tr ("Ladungstr\344ger Zentrieren"), this); + acts.centerOnProbeAct->setStatusTip (tr ("Den Ladungstr\344ger Zentrieren")); + acts.centerOnProbeAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); + connect (acts.centerOnProbeAct, SIGNAL (triggered()), gview, SLOT (centerOnProbe())); + acts.timerStop = new QAction (tr ("Animation stoppen"), this); acts.timerStop->setStatusTip (tr ("Die Animation stoppen und Ladung an den Anfang zur\374cksetzen")); acts.timerStop->setIcon(QIcon(":icons/media-playback-stop.svg")); @@ -243,6 +248,8 @@ void lsim::createMenus() { viewMenu = menuBar()->addMenu(tr("&Ansicht")); + viewMenu->addAction(acts.centerOnProbeAct); + viewMenu->addSeparator(); viewMenu->addAction(acts.editModeAct); viewMenu->addAction(acts.simulationModeAct); viewMenu->addSeparator(); @@ -314,7 +321,7 @@ void lsim::initWindowMode(WindowMode newMode) { fieldItemEditDock->setVisible(true); probeItemDock->setVisible(true); sceneDock->setVisible(true); - gview->centerOn(simulscene->getProbeChargeItem()); + gview->centerOnProbe(); @@ -330,7 +337,7 @@ void lsim::initWindowMode(WindowMode newMode) { acts.itemEditModeAct->trigger(); simulscene->clearSelection(); acts.calculate->trigger(); - gview->centerOn(simulscene->getProbeChargeItem()); + gview->centerOnProbe(); } @@ -370,6 +377,24 @@ void lsim::createDocks() { connect(simulscene, SIGNAL(timePerStepChanged(double)),time_step_box, SLOT(setValue( double ))); + //automatische Schrittlaengen-box + ExpDoubleSpinBox *adaptive_step_length_box = new ExpDoubleSpinBox; + adaptive_step_length_box->setRange(pow(10,-100), pow(10,66)); + adaptive_step_length_box->setDecimals(100); + adaptive_step_length_box->setDisplayDecimals(3); + adaptive_step_length_box->setSuffix(" px"); + adaptive_step_length_box->setKeyboardTracking(false); + adaptive_step_length_box->setValue(simulscene->getProbeChargeItem()->getAdaptiveStepLength()); + connect(adaptive_step_length_box, SIGNAL(valueChanged(double)),simulscene->getProbeChargeItem(), SLOT(setAdaptiveStepLength(double))); + connect(simulscene->getProbeChargeItem(), SIGNAL(adaptiveStepLengthChanged(double)),adaptive_step_length_box, SLOT(setValue( double ))); + + //automatische schrittanpassungsbox + QCheckBox *adaptive_time_step_box = new QCheckBox(""); + adaptive_time_step_box->setChecked(simulscene->getProbeChargeItem()->isAdaptiveStepControlEnabled()); + connect(adaptive_time_step_box, SIGNAL(toggled(bool)),simulscene->getProbeChargeItem(), SLOT(setAdaptiveStepControl(bool))); + connect(simulscene->getProbeChargeItem(), SIGNAL(adaptiveStepControlChanged(bool)),adaptive_time_step_box, SLOT(setChecked(bool))); + connect(adaptive_time_step_box, SIGNAL(toggled(bool)),adaptive_step_length_box, SLOT(setEnabled(bool))); + //meterPerPixel Box ExpDoubleSpinBox *meter_per_px_box = new ExpDoubleSpinBox; meter_per_px_box->setRange(pow(10,-100), pow(10,66)); @@ -385,6 +410,7 @@ void lsim::createDocks() { QLabel *time_per_step_label = new QLabel(tr("Zeit pro Schritt:")); QLabel *steps_label = new QLabel(tr("Schritte:")); QLabel *meter_per_pixel_label = new QLabel(tr("Ein Pixel entspricht:")); + QLabel *adaptive_time_step_label = new QLabel(tr("Automatische Schrittl\344nge:")); //Scene settings Layout QGridLayout *sceneGridLayout = new QGridLayout; @@ -392,8 +418,12 @@ void lsim::createDocks() { sceneGridLayout->addWidget(steps_box,0,1); sceneGridLayout->addWidget(time_per_step_label,1,0,Qt::AlignRight); sceneGridLayout->addWidget(time_step_box,1,1); - sceneGridLayout->addWidget(meter_per_pixel_label,2,0,Qt::AlignRight); - sceneGridLayout->addWidget(meter_per_px_box,2,1); + sceneGridLayout->addWidget(adaptive_time_step_label,2,0,Qt::AlignRight); + sceneGridLayout->addWidget(adaptive_time_step_box,2,1); + sceneGridLayout->addWidget(adaptive_step_length_box,3,1); + sceneGridLayout->addWidget(meter_per_pixel_label,4,0,Qt::AlignRight); + sceneGridLayout->addWidget(meter_per_px_box,4,1); + QGroupBox *sceneGroupBox = new QGroupBox(tr("Allgemeines")); diff --git a/src/lsim.h b/src/lsim.h index 18958f2..d9966b1 100644 --- a/src/lsim.h +++ b/src/lsim.h @@ -122,6 +122,7 @@ class lsim: public QMainWindow { QAction *resetAct; QAction *fullScreenAct; + QAction *centerOnProbeAct; }; Actions acts;