2008-10-08 22:11:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* 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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
#ifndef SIMULSCENE_H
|
|
|
|
|
#define SIMULSCENE_H
|
|
|
|
|
|
|
|
|
|
#include <QGraphicsScene>
|
2008-11-21 23:56:10 +00:00
|
|
|
#include <graphicsellipseitem.h>
|
2008-12-20 17:26:58 +00:00
|
|
|
#include <QMap>
|
2008-10-08 22:11:27 +00:00
|
|
|
|
|
|
|
|
class QTimeLine;
|
|
|
|
|
class HomoEFieldItem;
|
2008-10-14 19:31:02 +00:00
|
|
|
class HomoBFieldItem;
|
2008-10-08 22:11:27 +00:00
|
|
|
class QGraphicsRectItem;
|
|
|
|
|
class QGraphicsItemGroup;
|
2008-10-11 23:16:51 +00:00
|
|
|
class QGraphicsItemAnimation;
|
2008-11-11 20:31:04 +00:00
|
|
|
class QGraphicsPathItem;
|
|
|
|
|
class QPainterPath;
|
2008-11-16 22:18:15 +00:00
|
|
|
class QListWidget;
|
|
|
|
|
class FieldItem;
|
2008-11-21 23:56:10 +00:00
|
|
|
class StopperItem;
|
2008-10-08 22:11:27 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@author Peter Dahlberg <pdahlberg@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
class SimulScene : public QGraphicsScene {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2008-11-15 13:55:29 +00:00
|
|
|
enum SceneMode {
|
|
|
|
|
HomoEFieldItemInsert,
|
|
|
|
|
FieldItemEdit,
|
|
|
|
|
HomoBFieldItemInsert,
|
2008-11-21 23:56:10 +00:00
|
|
|
StopperItemInsert,
|
2008-11-15 13:55:29 +00:00
|
|
|
ProbeChargeItemPlace
|
|
|
|
|
};
|
2008-10-08 22:11:27 +00:00
|
|
|
enum ItemType {ResizeRectItem};
|
|
|
|
|
SimulScene ( QObject* parent = 0);
|
2008-11-16 22:18:15 +00:00
|
|
|
qreal getHighestZIndexVisible(); //hoechsten z-index der sichtbaren items
|
|
|
|
|
qreal getHighestZIndexFieldItems(); //hoechsten z-index der Felder ausgeben
|
2008-11-17 21:54:18 +00:00
|
|
|
qreal getLowestZIndexFieldItems();
|
2008-10-08 22:11:27 +00:00
|
|
|
|
|
|
|
|
~SimulScene();
|
|
|
|
|
double getTimePerStep();
|
2008-12-07 22:11:41 +00:00
|
|
|
double getMeterPerPx() const;
|
|
|
|
|
double getPxPerSec() const;
|
2008-10-08 22:11:27 +00:00
|
|
|
int getSteps();
|
|
|
|
|
|
|
|
|
|
//! gibt die Wirkende Kraft zurück (in Newton)
|
|
|
|
|
/*!
|
|
|
|
|
\param point der Punkt der abgeprüft werden soll
|
|
|
|
|
\param charge Die Ladung, auf die die Kraft ausgeübt wird
|
2008-10-18 16:03:06 +00:00
|
|
|
\param speedX Aktuelle Geschwindigkeit in x-Richtung
|
|
|
|
|
\param speedY Aktuelle Geschwindigkeit in y-Richtung
|
|
|
|
|
\param xy rückgabe in x oder y-Richtung
|
2008-10-08 22:11:27 +00:00
|
|
|
*/
|
2008-10-18 16:03:06 +00:00
|
|
|
double getPowerAt(QPointF point, double charge, double speedX, double speedY, char xy);
|
2008-11-22 16:45:09 +00:00
|
|
|
bool stopsHere(const QPointF &p1,const QPointF &p2);
|
2008-10-18 16:03:06 +00:00
|
|
|
|
|
|
|
|
QWidget* getProbeDockWidget() const;
|
2008-11-13 22:10:20 +00:00
|
|
|
|
|
|
|
|
bool isFlightPathVisible();
|
|
|
|
|
int getTimeLineDuration();
|
2008-11-16 22:18:15 +00:00
|
|
|
QListWidget* getFieldListWidget();
|
|
|
|
|
QList<QGraphicsItem*> getItemsInZOrder();
|
|
|
|
|
QList<QGraphicsItem*> getFieldItemsInZOrder();
|
2008-10-08 22:11:27 +00:00
|
|
|
|
2008-11-21 23:56:10 +00:00
|
|
|
GraphicsEllipseItem* getProbeChargeItem();
|
|
|
|
|
|
2008-11-23 13:45:09 +00:00
|
|
|
void clearFlightPath();
|
|
|
|
|
|
2008-12-22 22:34:28 +00:00
|
|
|
QList<QVariant> getSaveDataList();
|
|
|
|
|
void setSaveDataList(QList<QVariant> list);
|
|
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
public slots:
|
|
|
|
|
void setSceneMode(SceneMode mode);
|
|
|
|
|
void startTimer();
|
2008-11-02 20:34:58 +00:00
|
|
|
void stopTimer();
|
2008-12-06 22:54:33 +00:00
|
|
|
void pauseTimer(bool yesno);
|
|
|
|
|
void startPauseTimer(bool yesno);
|
2008-10-08 22:11:27 +00:00
|
|
|
void deleteSelectedFieldItems();
|
|
|
|
|
void setTimePerStep(double time);
|
|
|
|
|
///starte die Berechnung der teilchenbahn(en)
|
|
|
|
|
void startCalculation();
|
|
|
|
|
void setSteps(int steps);
|
|
|
|
|
|
2008-10-14 19:31:02 +00:00
|
|
|
void setMeterPerPx ( double theValue );
|
2008-12-07 22:11:41 +00:00
|
|
|
void setPxPerSec ( double theValue );
|
2008-11-11 20:31:04 +00:00
|
|
|
void setFlightPathVisible(bool visible = true);
|
2008-11-13 22:10:20 +00:00
|
|
|
void setTimeLineDuration(int duration);
|
|
|
|
|
|
2008-11-16 22:18:15 +00:00
|
|
|
void moveFieldItemDown(QGraphicsItem* fieldItem);
|
|
|
|
|
void moveSelectedFieldItemDown();
|
|
|
|
|
void moveFieldItemUp(QGraphicsItem* fieldItem);
|
|
|
|
|
void moveSelectedFieldItemUp();
|
2008-11-17 15:56:27 +00:00
|
|
|
void moveFieldItemOnTop(QGraphicsItem* fieldItem);
|
|
|
|
|
void moveSelectedFieldItemOnTop();
|
|
|
|
|
void moveFieldItemOnBottom(QGraphicsItem* fieldItem);
|
|
|
|
|
void moveSelectedFieldItemOnBottom();
|
2008-12-06 22:54:33 +00:00
|
|
|
void resetScene();
|
2008-12-20 17:26:58 +00:00
|
|
|
void handleTimeLineValueChange(qreal value);
|
2008-10-08 22:11:27 +00:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void displayResizeRects(bool move = false);
|
|
|
|
|
///does the same as displayResizeRects(true)
|
|
|
|
|
void moveResizeRects();
|
2008-11-11 20:31:04 +00:00
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
signals:
|
|
|
|
|
void sceneModeChanged(int mode);
|
|
|
|
|
void stepsChanged(int steps);
|
|
|
|
|
void timePerStepChanged(double timePerStep);
|
2008-10-11 23:16:51 +00:00
|
|
|
void meterPerPxChanged(double meterPerPx);
|
2008-12-07 22:11:41 +00:00
|
|
|
void pxPerSecChanged(double pxps);
|
2008-11-11 20:31:04 +00:00
|
|
|
void flightPathVisibilityChanged(bool visible);
|
2008-11-13 22:10:20 +00:00
|
|
|
void timeLineDurationChanged(int duration);
|
2008-12-06 22:54:33 +00:00
|
|
|
void timeLineInRunningState(bool yesno = false);
|
2008-12-07 22:11:41 +00:00
|
|
|
void realSimulTimeChanged(QString theString);
|
2008-12-20 17:26:58 +00:00
|
|
|
|
|
|
|
|
void probeSpeedXChanged(QString text);
|
|
|
|
|
void probespeedYChanged(QString text);
|
|
|
|
|
void probeSpeedChanged(QString text);
|
2008-10-08 22:11:27 +00:00
|
|
|
private:
|
|
|
|
|
QTimeLine *timer;
|
2008-11-12 21:50:47 +00:00
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
SceneMode myMode;
|
|
|
|
|
|
2008-11-21 23:56:10 +00:00
|
|
|
///Zeit pro Step in sekunden
|
2008-10-08 22:11:27 +00:00
|
|
|
double timePerStep;
|
|
|
|
|
///anzahl der Steps
|
|
|
|
|
int steps;
|
|
|
|
|
///ein Pixel entspricht so viel meter
|
|
|
|
|
double meterPerPx;
|
2008-12-07 22:11:41 +00:00
|
|
|
///Animationsgescheindigkeit in px/s (durchschnittlich)
|
|
|
|
|
double pxPerSec;
|
|
|
|
|
|
2008-10-14 19:31:02 +00:00
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
HomoEFieldItem *currHomoEfieldInsertItem; //Aktuell erstelltes Item
|
|
|
|
|
HomoEFieldItem *currHomoEfieldEditItem;
|
2008-10-14 19:31:02 +00:00
|
|
|
|
|
|
|
|
HomoBFieldItem *currHomoBfieldInsertItem; //Aktuell erstelltes Item
|
|
|
|
|
HomoBFieldItem *currHomoBfieldEditItem;
|
|
|
|
|
|
2008-11-21 23:56:10 +00:00
|
|
|
StopperItem *currStopperInsertItem; //Aktuell erstelltes Item
|
|
|
|
|
StopperItem *currStopperEditItem;
|
|
|
|
|
|
2008-11-15 13:55:29 +00:00
|
|
|
bool ChargePlacementInProgress; //ladung wird gerade platziert
|
|
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
QGraphicsItem *pressedResizeItem;
|
|
|
|
|
|
|
|
|
|
GraphicsEllipseItem *ellipse1;
|
2008-10-11 23:16:51 +00:00
|
|
|
QGraphicsItemAnimation *ani;
|
2008-11-11 20:31:04 +00:00
|
|
|
|
|
|
|
|
QGraphicsPathItem *pathItem1;
|
2008-11-16 22:18:15 +00:00
|
|
|
QListWidget* fieldListWidget;
|
2008-10-08 22:11:27 +00:00
|
|
|
|
2008-12-20 17:26:58 +00:00
|
|
|
QMap<double, int> aniStepList;
|
2008-10-08 22:11:27 +00:00
|
|
|
|
|
|
|
|
//rechtecke zur groesenaenderung
|
|
|
|
|
struct resizeRects {
|
|
|
|
|
QGraphicsRectItem *leftTopResizeItem;
|
|
|
|
|
QGraphicsRectItem *leftResizeItem;
|
|
|
|
|
QGraphicsRectItem *leftBottomResizeItem;
|
|
|
|
|
QGraphicsRectItem *bottomResizeItem;
|
|
|
|
|
QGraphicsRectItem *rightBottomResizeItem;
|
|
|
|
|
QGraphicsRectItem *rightRezizeItem;
|
|
|
|
|
QGraphicsRectItem *rightTopResizeItem;
|
|
|
|
|
QGraphicsRectItem *topResizeItem;
|
|
|
|
|
};
|
|
|
|
|
resizeRects reRects;
|
|
|
|
|
void createResizeRects();
|
|
|
|
|
|
|
|
|
|
void calculateItemResize(
|
|
|
|
|
QGraphicsSceneMouseEvent *mouseEvent,
|
|
|
|
|
QGraphicsRectItem *pressedRectItem,
|
|
|
|
|
QRectF &currRect,
|
|
|
|
|
QPointF &newPos,
|
|
|
|
|
qreal minWidth,
|
|
|
|
|
qreal minHeight
|
|
|
|
|
);
|
|
|
|
|
|
2008-11-13 15:17:17 +00:00
|
|
|
QList<HomoEFieldItem*> calcEFieldList;
|
|
|
|
|
QList<HomoBFieldItem*> calcBFieldList;
|
2008-11-22 16:45:09 +00:00
|
|
|
QList<StopperItem*> calcStopperList;
|
2008-11-16 22:18:15 +00:00
|
|
|
|
2008-11-17 15:56:27 +00:00
|
|
|
static const qreal FieldDefaultZValue = 10.0; //default z-value fuer Felder
|
|
|
|
|
static const qreal FieldZStep = 1e-10; //schritt, um den der z-index erhoeht wird
|
2008-11-16 22:18:15 +00:00
|
|
|
|
2008-12-06 22:54:33 +00:00
|
|
|
void setupVars();
|
|
|
|
|
|
2008-11-16 22:18:15 +00:00
|
|
|
|
2008-11-13 15:17:17 +00:00
|
|
|
|
2008-10-08 22:11:27 +00:00
|
|
|
protected:
|
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
|
|
|
|
void keyPressEvent ( QKeyEvent * keyEvent );
|
2008-12-09 22:01:57 +00:00
|
|
|
void drawBackground ( QPainter * painter, const QRectF & rect );
|
2008-10-08 22:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|