diff --git a/lsim.kdevelop b/lsim.kdevelop index ee263e1..c8982a4 100644 --- a/lsim.kdevelop +++ b/lsim.kdevelop @@ -161,7 +161,7 @@ /mnt/sdb1/c++/lsim - + diff --git a/lsim.kdevelop.pcs b/lsim.kdevelop.pcs index 288faa4..b46d0d2 100644 Binary files a/lsim.kdevelop.pcs and b/lsim.kdevelop.pcs differ diff --git a/lsim.kdevses b/lsim.kdevses index b768951..df05c45 100644 --- a/lsim.kdevses +++ b/lsim.kdevses @@ -1,24 +1,24 @@ - + - + - + - + - + - + - + @@ -35,6 +35,18 @@ + + + + + + + + + + + + diff --git a/src/graphicsellipseitem.cpp b/src/graphicsellipseitem.cpp index 829d610..5970f2e 100644 --- a/src/graphicsellipseitem.cpp +++ b/src/graphicsellipseitem.cpp @@ -102,7 +102,7 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { currProbePath->append(startPoint); speedListX->append(startSpeedX); speedListY->append(startSpeedY); - realSimulTime =0; + realSimulTime = 0; //startpunkt in den Pfad setzen flightPath = QPainterPath(startPoint); @@ -145,7 +145,7 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { currProbePath->append(newPoint); speedListX->append(newspeedX); speedListY->append(newspeedY); - + realSimulTime += timePerStep; if (i%path_entry_step == 0 || i==steps) flightPath.lineTo(newPoint); @@ -252,3 +252,9 @@ void GraphicsEllipseItem::setFlightPath ( const QPainterPath& theValue ) { if (flightPath==theValue) return; flightPath = theValue; } + + +double GraphicsEllipseItem::getRealSimulTime() const { + return realSimulTime; +} + diff --git a/src/graphicsellipseitem.h b/src/graphicsellipseitem.h index 10e048f..3692482 100644 --- a/src/graphicsellipseitem.h +++ b/src/graphicsellipseitem.h @@ -50,6 +50,7 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { double getMasse(double speed = 0); QPainterPath getFlightPath() const; + double getRealSimulTime() const; protected: @@ -63,7 +64,7 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem { ///Liste Der Geschwindigkeitsanteile in y-richtung QList *speedListY; ///Gesamtzeilt der der Simulation - double *realSimulTime; + double realSimulTime; ///Masse der Probeladung in kg double masse; ///Ladung der Probleadung in As diff --git a/src/lsim.cpp b/src/lsim.cpp index 622e38f..829b099 100644 --- a/src/lsim.cpp +++ b/src/lsim.cpp @@ -49,6 +49,7 @@ lsim::lsim() { createStatusBar(); createDocks(); setMode(EditMode); + connect(simulscene, SIGNAL(timeLineDurationChanged(int)),this, SLOT(timeLineDurationChangeWrapperToSec(int))); } void lsim::closeEvent (QCloseEvent *event) { @@ -233,17 +234,17 @@ void lsim::createMenus() { void lsim::createToolBars() { windowModeBar = new QToolBar(tr("Modus")); - windowModeBar->setIconSize(QSize(22,22)); + windowModeBar->setIconSize(QSize(24,24)); windowModeBar->addAction(acts.editModeAct); windowModeBar->addAction(acts.simulationModeAct); timerControlBar = new QToolBar (tr ("Timer")); - timerControlBar->setIconSize(QSize(22,22)); + timerControlBar->setIconSize(QSize(24,24)); timerControlBar->addAction(acts.timerPause); timerControlBar->addAction(acts.timerStop); sceneModeBar = new QToolBar (tr ("Edit")); - sceneModeBar->setIconSize(QSize(22,22)); + sceneModeBar->setIconSize(QSize(24,24)); sceneModeBar->addAction(acts.itemEditModeAct); sceneModeBar->addAction(acts.insertEFieldItemAct); sceneModeBar->addAction(acts.insertBFieldItemAct); @@ -251,14 +252,13 @@ void lsim::createToolBars() { sceneModeBar->addAction(acts.probeChargeItemPlaceAct); upDownBar = new QToolBar(tr("Feldanordnungsreihenfolge")); - upDownBar->setIconSize(QSize(20,20)); + upDownBar->setIconSize(QSize(21,21)); upDownBar->addAction(acts.moveItemOnBottom); upDownBar->addAction(acts.moveItemDown); upDownBar->addAction(acts.moveItemUp); upDownBar->addAction(acts.moveItemOnTop); addToolBar(windowModeBar); - } void lsim::initWindowMode(WindowMode newMode) { @@ -395,19 +395,27 @@ void lsim::createDocks() { connect(simulscene, SIGNAL(flightPathVisibilityChanged(bool)),flight_path_box, SLOT(setChecked(bool))); //timer laenge Box - QSpinBox *timer_box = new QSpinBox; + QDoubleSpinBox *timer_box = new QDoubleSpinBox; timer_box->setRange(1.0, 1e+10); - timer_box->setKeyboardTracking(false); - timer_box->setValue(simulscene->getTimeLineDuration()); - timer_box->setSuffix(" ms"); - connect(timer_box, SIGNAL(valueChanged(int)),simulscene, SLOT(setTimeLineDuration(int))); + timer_box->setDecimals(3); + //timer_box->setKeyboardTracking(false); + timer_box->setValue(simulscene->getTimeLineDuration()/1000.0); + timer_box->setSuffix(" s"); + connect(timer_box, SIGNAL(valueChanged(double)),this, SLOT(timeLineDurationSetWrapperToMsec(double))); + connect(timer_box, SIGNAL(valueChanged(double)),acts.timerStop, SLOT(trigger())); //connect(timer_box, SIGNAL(valueChanged(int)),simulscene, SLOT(stopTimer())); - connect(simulscene, SIGNAL(timeLineDurationChanged(int)),timer_box, SLOT(setValue(int))); + connect(this, SIGNAL(timeLineDurationChangedSec(double)),timer_box, SLOT(setValue(double))); + + //Echte simulationsdauer + QLabel *real_simul_time_shower = new QLabel(tr("keine Daten")); + real_simul_time_shower->setTextInteractionFlags(Qt::TextSelectableByMouse); + connect(simulscene, SIGNAL(realSimulTimeChanged(QString)),real_simul_time_shower, SLOT(setText(QString))); //description labels QLabel *flight_path_label = new QLabel(tr("Flugbahn anzeigen:")); QLabel *timer_label = new QLabel(tr("L\344nge der Animation:")); + QLabel *real_simul_time_label = new QLabel(tr("\"Reale\" Simulationsdauer:")); //grid layout QGridLayout *simulOptGridLayout = new QGridLayout; @@ -415,6 +423,8 @@ void lsim::createDocks() { simulOptGridLayout->addWidget(flight_path_box,3,1); simulOptGridLayout->addWidget(timer_label,4,0,Qt::AlignRight); simulOptGridLayout->addWidget(timer_box,4,1); + simulOptGridLayout->addWidget(real_simul_time_label,5,0,Qt::AlignRight); + simulOptGridLayout->addWidget(real_simul_time_shower,5,1); QGroupBox *simulOptGroupBox = new QGroupBox(tr("Allgemeines")); simulOptGroupBox->setLayout(simulOptGridLayout); @@ -456,6 +466,14 @@ void lsim::createDocks() { } +void lsim::timeLineDurationChangeWrapperToSec(int length) { + emit timeLineDurationChangedSec((double)length/1000.0); +} + +void lsim::timeLineDurationSetWrapperToMsec(double length) { + simulscene->setTimeLineDuration(int(length*1000)); +} + void lsim::actModeSwitcher(QAction *action) { simulscene->setSceneMode((SimulScene::SceneMode)action->data().toInt()); } @@ -525,11 +543,13 @@ void lsim::startCalculation() { if (simulscene->getMeterPerPx() == 0) { QMessageBox::critical (this,tr("B\366ser Fehler!"),tr("Die Wegl\344nge pro Pixel darf nicht 0 sein!")); + setMode(EditMode); return; } if (simulscene->getProbeChargeItem()->getMasse(0) == 0) { QMessageBox::critical (this,tr("B\366ser Fehler!"),tr("Die Masse der Probeladung darf nicht 0 sein!")); + setMode(EditMode); return; } @@ -542,7 +562,7 @@ void lsim::startCalculation() { statusBar()->clearMessage(); } void lsim::startTimer() { - if( qApp->focusWidget() !=0) qApp->focusWidget()->clearFocus(); + clearAnyFocus(); simulscene->startTimer(); } void lsim::handleDockLocationChange() { diff --git a/src/lsim.h b/src/lsim.h index 5c34280..1df402f 100644 --- a/src/lsim.h +++ b/src/lsim.h @@ -70,6 +70,9 @@ class lsim: public QMainWindow { void clearAnyFocus(); void resetAll(); + void timeLineDurationChangeWrapperToSec(int length); + void timeLineDurationSetWrapperToMsec(double length); + private: void createActions(); void createMenus(); @@ -134,6 +137,7 @@ class lsim: public QMainWindow { WindowMode myMode; signals: void windowModeChanged(WindowMode mode); + void timeLineDurationChangedSec(double duration); }; #endif diff --git a/src/simulscene.cpp b/src/simulscene.cpp index 12ce1ef..84fe65e 100644 --- a/src/simulscene.cpp +++ b/src/simulscene.cpp @@ -39,7 +39,6 @@ #include - SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { fieldListWidget = new QListWidget(); @@ -109,6 +108,7 @@ void SimulScene::setupVars() { setSteps(300000); //setMeterPerPx(1/1000.0); setMeterPerPx(0.01); + setPxPerSec(90.0); timer->setFrameRange(0,100); timer->setUpdateInterval(30); @@ -810,6 +810,16 @@ void SimulScene::startCalculation() { ani->setPosAt(i/(double)currSteps, ellipse1->getCurrProbePath()->at(i) ); } } + + //aenderungen bestimmter Werte bekanntgeben + QString realSimulTimeString(QLocale().toString(ellipse1->getRealSimulTime(),'g')); + realSimulTimeString.append(" s"); + emit realSimulTimeChanged(realSimulTimeString); + + //brauchbare Animationsdauer bestimmen + setTimeLineDuration(ellipse1->getFlightPath().length()/getPxPerSec() * 1000.0); + + } @@ -894,6 +904,9 @@ double SimulScene::getMeterPerPx() const { return meterPerPx; } +double SimulScene::getPxPerSec() const { + return pxPerSec; +} void SimulScene::setMeterPerPx ( double theValue ) { if (theValue == meterPerPx) return; @@ -901,6 +914,12 @@ void SimulScene::setMeterPerPx ( double theValue ) { emit meterPerPxChanged(theValue); } +void SimulScene::setPxPerSec ( double theValue ) { + if (theValue == pxPerSec) return; + pxPerSec = theValue; + emit pxPerSecChanged(theValue); +} + /*! \fn SimulScene::getProbeDockWidget() const diff --git a/src/simulscene.h b/src/simulscene.h index 5273a17..bf94972 100644 --- a/src/simulscene.h +++ b/src/simulscene.h @@ -56,6 +56,8 @@ class SimulScene : public QGraphicsScene { ~SimulScene(); double getTimePerStep(); + double getMeterPerPx() const; + double getPxPerSec() const; int getSteps(); //! gibt die Wirkende Kraft zurück (in Newton) @@ -94,7 +96,7 @@ class SimulScene : public QGraphicsScene { void setSteps(int steps); void setMeterPerPx ( double theValue ); - double getMeterPerPx() const; + void setPxPerSec ( double theValue ); void setFlightPathVisible(bool visible = true); void setTimeLineDuration(int duration); @@ -118,9 +120,11 @@ class SimulScene : public QGraphicsScene { void stepsChanged(int steps); void timePerStepChanged(double timePerStep); void meterPerPxChanged(double meterPerPx); + void pxPerSecChanged(double pxps); void flightPathVisibilityChanged(bool visible); void timeLineDurationChanged(int duration); void timeLineInRunningState(bool yesno = false); + void realSimulTimeChanged(QString theString); private: QTimeLine *timer; @@ -132,6 +136,9 @@ class SimulScene : public QGraphicsScene { int steps; ///ein Pixel entspricht so viel meter double meterPerPx; + ///Animationsgescheindigkeit in px/s (durchschnittlich) + double pxPerSec; + HomoEFieldItem *currHomoEfieldInsertItem; //Aktuell erstelltes Item HomoEFieldItem *currHomoEfieldEditItem;