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

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

Go to the documentation of this file.
00001 #ifndef TRANSITION_H_21234567890987654
00002 #define TRANSITION_H_21234567890987654
00003 
00004 #include "editor.h"
00005 #include "stringProcessor.h"
00006 #include "labelSyntaxChecker.h"
00007 
00008 #include "itransition.h"
00009 
00010 #include <QGraphicsItem>
00011 
00012 class State;
00013 class QTextStream;
00014 class QPolygonF;
00015 class QPointF;
00016 class LabelX;
00017 
00018 struct EdgePrevParams{
00019     Qt::PenStyle edgeLineStyle;
00020     float edgeLineWidth;
00021     QString edgeLineColor;
00022     QString edgeLabelColor;
00023     float edgeLabelScale;
00024     bool edgeLineDblStatus;
00025 
00026     float edgeLineBorderCoef;
00027     QString edgeLineBorderColor;
00028     float edgeLineDblCoef;
00029     float edgeLineDblSep;
00030 
00031     Qt::PenStyle dimEdgeLineStyle;
00032     QString dimEdgeLineColor;
00033     float dimEdgeLineCoef;
00034     QString dimEdgeLabelColor; 
00035 };
00036 
00037 class Transition : public QGraphicsItem
00038 {
00039 public:
00040     typedef QList<LabelX *> TLabelXList;
00041 
00042     Transition(Editor *parent, State *ss, State *es, bool dimmed);
00043     virtual ~Transition();
00044 
00045     friend class Parser;
00046     friend class TransitionExtendedDialog;
00047     friend class NextLabelsDialog;
00048     friend class TransitionEditWithDelCommand;
00049     friend class TransitionEditExtendedCommand;
00050     friend class TransitionStyleChangeCommand;
00051     friend struct TransitionSerializer;
00052     friend void Editor::exportToGraphML(const QString &fn);
00053 
00054     QString getLabelText() const;
00055     void setLabelText(const QString &label);
00056     virtual void setLabelPosition();
00057     virtual void setLabelPosition(LabelX *pLabel, float pos, bool isLeft, int width, int height);    
00058 
00059     LabelX *getLabel() const;
00060     const TLabelXList& getNextLabels() const { return nextLabels; } //! ??? Check return type correctness!!!
00061     
00062     void setLabelPos(float pos);
00063     float getLabelPos() const;
00064 
00065     QColor getColor() { return dimmed ? QColor(dimEdgeLineColor) : QColor(edgeLineColor); }
00066     QColor getLabelColor() { return dimmed ? QColor(dimEdgeLabelColor) : QColor(edgeLabelColor); }
00067 
00068     void addNextLabel(LabelX *pLabel);
00069     void removeNextLabel(LabelX *pLabel);
00070 
00071     virtual void adjust() = 0; //!< The only method where graphics changes are computed
00072 
00073     //! Return path mapped to scene
00074     virtual QPainterPath path() const { return p; }
00075     
00076     virtual QRectF boundingRect() const;
00077     virtual QPainterPath shape() const;
00078     virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00079     virtual void paintSelectionDecoration(QPainter *painter);
00080     
00081     virtual QString getTypeName() const = 0;
00082     virtual QString getTypeNameSuffix() const { return ""; }
00083 
00084     //! Assign to all referenced states (to theirs trList)
00085     virtual void assign() = 0;
00086     virtual void unassign() = 0;
00087 
00088     virtual void setDirection(int){}
00089     virtual int getDirection() const {return 0;}
00090 
00091     virtual void setArcAngle(int){} //!< for VArc and VCurve
00092     virtual void setNCurv(float){}
00093     virtual int getArcAngle() const {return 0;}
00094     virtual float getNCurv() const {return 0;}
00095 
00096     // TODO: how to solve this better? don't miss TransitionSerializer!
00097     virtual void setArcAngleB(int){} //!< only for VCurve
00098     virtual int getArcAngleB() const {return 0;}    
00099 
00100     bool isDimmed();
00101     void setDimmed(bool dim);
00102 
00103     void setChecked(bool checked = true);
00104     void setSelected(bool selected = true);
00105 
00106     State* getStartState() const { return startState; }
00107     virtual State* getEndState() const { if (endState) return endState; else return 0; }
00108 
00109     //! Pay attention to Loop - doesn't have end state, but getEndState() returns startState due to automaton sence
00110     bool hasEndState() const { if (endState) return true; else return false; }
00111 
00112     QString getStartStateName()  const;
00113     QString getEndStateName() const;
00114 
00115     //! \note Neded too if state type is changed
00116     void setStartState(State *state);
00117     void setEndState(State *state);
00118 
00119     Editor * getEditor() const { return editor; }
00120 
00121     // for export
00122     bool getVCParams(QTextStream &out, EdgePrevParams &prevParams) const; //!< VauCanSon-G params
00123     virtual QString getNextLabelsVCCommand() const;
00124 
00125     virtual QString getVCCommand() const = 0; //!< VauCanSon-G transition command
00126     
00127     // TODO: divide to subtypes (solve better)
00128     virtual QString getGraphMLParams() const { return ""; } //!< GraphML export
00129 
00130     //virtual QString getEPS() const = 0;
00131     
00132     void setEdgeLabelScale(float labelScale);
00133     void setDimEdgeLineCoef(float lineCoef);
00134     void setEdgeLineWidth(float lineWidth);
00135 
00136 protected:
00137     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
00138     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) = 0;
00139     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
00140 
00141     enum EIntersectionFindMethod {eFIND_FIRST, eFIND_TWO, eFIND_ALL};
00142 
00143     //virtual void makeAreas(const QPainterPath &p); //!< updates click and selection areas
00144     void  createStrokes(const QPainterPath &path);
00145     const QPainterPath& getClickPath() const;
00146     const QPainterPath& getSelectionPath() const;
00147 
00148     QPainterPath createShape(const QPainterPath &path, int bounds) const;
00149 
00150     QPainterPath m_clickPath; //!< holds area for mouse click
00151     QPainterPath m_selectionPath; //!< holds area showed when item is selected
00152     
00153     static QPolygonF findIntersectedPoints(const QPolygonF &curve, const QPolygonF &polygon,
00154                                            const EIntersectionFindMethod method);    
00155     
00156     //! Sincle transition path starts in circuit of state, only path is need
00157     //! This computes arrow points from anlge of last part of transition
00158     QPolygonF getArrowPolygon(const QPainterPath &path);
00159     QPolygonF m_arrowPoints; //!< default transition arrow, angle 0 degrees, pointing to point 0,0
00160 
00161     Editor *editor;
00162 
00163     State *startState, *endState;
00164     QPointF startPoint, endPoint;
00165 
00166     int m_labelFontSize;
00167     LabelX *label;
00168 
00169     //! next labels (command \LabelL, \LabelR) - stored as pair item + isLeft
00170     TLabelXList nextLabels;    
00171 
00172     QPolygonF pa;   //!< arrow polygon -> transformed and rotatted m_arrowPoints
00173     QPainterPath p; //!< path of transition
00174 
00175     bool dimmed;
00176     bool leftOriented;
00177 
00178     //! \name edge parameters
00179     //! \{
00180     Qt::PenStyle edgeLineStyle;
00181     float edgeLineWidth;
00182     QString edgeLineColor;
00183     QString edgeLabelColor;
00184     float edgeLabelScale;
00185     bool edgeLineDblStatus;
00186     //! \}
00187 
00188     //! \name transition parameters preset
00189     //! \{
00190     float edgeLineBorderCoef;
00191     QString edgeLineBorderColor;    
00192 
00193     float edgeLineDblCoef;
00194     float edgeLineDblSep;
00195     //! \}
00196 
00197     //! \name transition parameters dimmed
00198     //! \{
00199     Qt::PenStyle dimEdgeLineStyle;
00200     QString dimEdgeLineColor;
00201     float dimEdgeLineCoef;
00202     QString dimEdgeLabelColor;
00203     //! \}
00204 
00205     float m_lineWidth;
00206 
00207     bool checked; //!< coloring when selected
00208     const QColor checkedColor;
00209 
00210     EMouseClick m_lastMouseClickType;
00211 
00212     //! \name Support methods for ITransition
00213     //! \{
00214 public:
00215     QString getSourceState() const;
00216     QString getDestinationState() const;
00217    
00218     //! Returns all character occurences, supposed to be inspected to find alphabet and epsilon symbol.
00219     //! Used when automata setting detection is required.
00220     //! \sa Editor::getAutomata()
00221     void getCharactersOccurences(ITransition::TCharSet &characters) const;  // out
00222   
00223     //! Returns character on which transition passes.
00224     bool getCharacters(ITransition::TCharSet &characters,               // out
00225                        const ITransition::TCharSet &alphabet,           // in
00226                        const QString &alphabetSymbol,                   // in
00227                        const QString &epsilonSymbol) const;             // in
00228 
00229 protected:
00230     void showErrorReport(const QString &reportText = QString("")) const;
00231 
00232     //! Dismembers characters (found specific smybols and fill occurences param).
00233     void dismemberCharacters(const QStringList &occurences,             // in
00234                              ITransition::TCharSet &characters) const;  // out                             
00235     //! \}
00236 };
00237 
00238 #endif //TRANSITION_H_21234567890987654

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