• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

C:/CVUT/diplomka/Automata_editor/sources/automataWorkSimulator.h

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  * Main simulation class, implements simulation logic.
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;     //!< determines, if it's possible to do step back
00030     bool    hasStateAfter() const;      //!< determines, if it's possible to process next step
00031     bool    isPlaying() const;          //!< determines, if automatic simulation is running
00032     bool    isSet() const;              //!< determines, if input is set correctly
00033     int     getPos() const;             //!< returns current position in input string
00034 
00035     //! helper struct for storing configurations
00036     struct Configuration
00037     {
00038         enum EStatus { eNoStatus, eAccepted, eError };
00039         QStringList activeStates;                       //!< active states in current configuration
00040         QStringList processed;                          //!< processed part of input
00041         QStringList input;                              //!< left part of input
00042         EStatus     status;                             //!< configuration status, \value eError means that no next step is possible
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();                         //!< runs simulation dialog
00055     
00056     bool setInput(const QString &text); //!< sets input string, if it's correctly defined
00057     
00058     void stepForward();                 //!< process single step
00059     
00060     void stepBackward();                //!< reverts last step
00061     
00062     void play();                        //!< runs automatic simulation
00063     
00064     void pause();                       //!< stops automatic simulation
00065     
00066     void reset();                       //!< resets state of simulation
00067 
00068     void generateSlideshow();           //!< processes all steps of simulation and stores it to slideshow
00069 
00070 signals:
00071     void finished();                            //!< signal emited when simulation ends
00072     void setStatesMarked(QList<State*>, bool);  //!< signal catched by editor \sa Editor::setStatesMarked()
00073 
00074 protected slots:
00075     void animate();         //!< processes single step of animation (called by timer)
00076     void dialogClosed();
00077 
00078     void processStep();     //!< processes single step of simulation
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;   //!< position in input stringList
00104     StringProcessor::TCharacterList         m_inputList;
00105     QScopedPointer<SimulationDialog>        m_dialog;
00106     
00107     //! step back uses undoStack, so when then is steping forward required again, only redo is done
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  * Dialog for manipulation with simulation.
00140  * \sa AutomataWorkSimulator
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(); //!< called from simulator (owner)
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; //!< if true, latex symbols are drawed in symbol font,
00180                                        //!< otherwise is printed latex syntax (e.g. \alpha)
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 /*state*/);
00195     void stepSpeedChanged(double /*time*/);
00196     void animSpeedChanged(double /*time*/);
00197 };
00198 
00199 #endif

Generated on Tue Jan 4 2011 03:03:22 for Autoamata editor by  doxygen 1.7.0