Go to the documentation of this file.00001 #ifndef _AUTOMATAWORKSIMULATOR_H_68481631923_
00002 #define _AUTOMATAWORKSIMULATOR_H_68481631923_
00003
00004 #include "automataCreator.h"
00005 #include "stringProcessor.h"
00006
00007 #include <QObject>
00008 #include <QDialog>
00009 class Editor;
00010 class State;
00011 class SimulationMarker;
00012 class SimulationDialog;
00013 class QUndoStack;
00014
00015 #include <QTimer>
00016
00017
00018
00019
00020 class AutomataWorkSimulator : public QObject
00021 {
00022 Q_OBJECT
00023 public:
00024 AutomataWorkSimulator(Editor *editor, QUndoStack &undoStack,
00025 const QSharedPointer<AutomatonImpl> &automaton);
00026
00027 ~AutomataWorkSimulator();
00028
00029 bool hasStateBefore() const;
00030 bool hasStateAfter() const;
00031 bool isPlaying() const;
00032 bool isSet() const;
00033 int getPos() const;
00034
00035
00036 struct Configuration
00037 {
00038 enum EStatus { eNoStatus, eAccepted, eError };
00039 QStringList activeStates;
00040 QStringList processed;
00041 QStringList input;
00042 EStatus status;
00043
00044 Configuration(const QStringList &a, const QStringList &p, const QStringList &i, EStatus s = eNoStatus)
00045 : activeStates(a), processed(p), input(i), status(s)
00046 {}
00047 };
00048
00049 typedef QList<Configuration> TConfigurationList;
00050
00051 TConfigurationList getConfigurations() const;
00052
00053 public slots:
00054 void run();
00055
00056 bool setInput(const QString &text);
00057
00058 void stepForward();
00059
00060 void stepBackward();
00061
00062 void play();
00063
00064 void pause();
00065
00066 void reset();
00067
00068 void generateSlideshow();
00069
00070 signals:
00071 void finished();
00072 void setStatesMarked(QList<State*>, bool);
00073
00074 protected slots:
00075 void animate();
00076 void dialogClosed();
00077
00078 void processStep();
00079
00080 void stepSpeedChanged(double);
00081 void animSpeedChanged(double);
00082 void useAnimChanged(int);
00083
00084 protected:
00085 bool animateMove();
00086 void setActiveStatesMarked(bool);
00087 void doAnimation(const QList<QPainterPath> &paths);
00088 QList<QPainterPath> revertPaths(const QList<QPainterPath> &paths) const;
00089
00090 void refreshPlayingStatus();
00091
00092 bool getFileName(QString &fileName, bool &latexHeader);
00093 void saveInputState(QTextStream &out);
00094
00095 private:
00096 Editor *m_editor;
00097 QUndoStack &m_undoStack;
00098 int m_undoStackStartIdx;
00099
00100 QSharedPointer<AutomatonImpl> m_automaton;
00101 QList<SimulationMarker*> m_markers;
00102 Configuration::EStatus m_status;
00103 int m_inputIndex;
00104 StringProcessor::TCharacterList m_inputList;
00105 QScopedPointer<SimulationDialog> m_dialog;
00106
00107
00108 int m_backSteps;
00109
00110 StateImpl::TStateList m_activeStates;
00111 bool m_activeStatesAreMarked;
00112
00113 QScopedPointer<QTimer> m_simulationTimer;
00114 bool m_playing;
00115
00116 enum EAnimateState { eMoving, eStopped };
00117 QScopedPointer<QTimer> m_animationTimer;
00118 EAnimateState m_animationState;
00119 bool m_useAnimations;
00120 int m_pathCount;
00121 float m_animationSpeed;
00122
00123 TConfigurationList m_configurationList;
00124 QVector<StateImpl::TStateList> m_activeStatesMemory;
00125 QVector<QList<QPainterPath> > m_animationPathMemory;
00126 };
00127
00128
00129
00130 class QLabel;
00131 class QLineEdit;
00132 class QPushButton;
00133 class QTableWidget;
00134 class QTextEdit;
00135 class QCheckBox;
00136 class QDoubleSpinBox;
00137
00138
00139
00140
00141
00142 class SimulationDialog : public QDialog
00143 {
00144 Q_OBJECT
00145 public:
00146 SimulationDialog(Editor *editor, AutomataWorkSimulator *simulator);
00147 ~SimulationDialog();
00148
00149 int getInputLength() const;
00150 QString getInput() const;
00151
00152 static void showMessageSetInputFailed(QWidget *parent);
00153
00154 public slots:
00155 void updateState();
00156
00157 private:
00158 Editor *m_editor;
00159 AutomataWorkSimulator *m_simulator;
00160
00161 QLineEdit *m_edtInput;
00162
00163 QPushButton *m_btnStepFwd;
00164 QPushButton *m_btnStepBack;
00165 QPushButton *m_btnPlay;
00166 QPushButton *m_btnPause;
00167 QPushButton *m_btnReset;
00168
00169 QPushButton *m_btnGenerate;
00170
00171 QTextEdit *m_textSimulation;
00172
00173 QCheckBox *m_checkUseAnim;
00174 QDoubleSpinBox *m_stepSpeed;
00175 QDoubleSpinBox *m_animSpeed;
00176
00177 QCheckBox *m_checkPrettyPrint;
00178
00179 bool m_bUsePrettyPrint;
00180
00181
00182 protected slots:
00183 void appendSymbol(const QString &sybmol);
00184 void prettyPrintChanged(int state);
00185
00186 void stepForward();
00187 void play();
00188
00189 void set();
00190 bool setInput();
00191
00192 signals:
00193 void closed();
00194 void useAnimChanged(int );
00195 void stepSpeedChanged(double );
00196 void animSpeedChanged(double );
00197 };
00198
00199 #endif