Transition.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 
27 #include <graphviz/types.h>
28 #include <graphviz/graph.h>
29 #include <graphviz/gvc.h>
30 
31 #include <QGraphicsScene>
32 #include <QGraphicsEllipseItem>
33 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsPolygonItem>
35 #include <QPolygonF>
36 #include <QtCore/QString>
37 #include <QtCore/QStringList>
38 #include <QFont>
39 #include <QGraphicsSceneMouseEvent>
40 
41 #include <utility>
42 
43 using floatPair = std::pair<float, float>;
44 
45 class StateChartGraphEdge : public QGraphicsPathItem
46 {
47 
48 public:
49 
50  /*
51  * @brief StateChartGraphEdge copy constructor
52  * It's supposed to be a copy constructor but not implemented as such
53  */
55  /*
56  * @brief StateChartGraphEdge constructs "empty" StateChartGraphEdge as child of scene
57  * @param scene GraphicsScene the new object belongs to
58  */
59  StateChartGraphEdge(QGraphicsScene* scene = 0);
60  /*
61  * @brief StateChartGraphEdge constructs an StateChartGraphEdge from gvGraphNode
62  * @param gvGraphNode the graphviz node this node represents
63  * @param m_transitionName name of transition that is represented by this edge
64  * @param scene GraphicsScene the edge belongs to
65  * @param dpi dpi value needed to paint the edge
66  */
67  StateChartGraphEdge(Agedge_t* gvGraphNode, const QString& transitionName, QGraphicsScene* scene = 0, float dpi = 72.0f);
70 
71  void setTransitionName(const QString& name);
73  {
74  return m_transitionName;
75  }
76 
77  /*
78  * @brief m_Path the edge's path
79  * Approximated by Bezier curves.
80  */
81  QPainterPath m_Path;
82  /*
83  * @brief headNode the node from which the edge starts.
84  */
85  QString m_headNode;
86  /*
87  * @brief tailNode the node to which the edge leads.
88  */
89  QString m_tailNode;
90 
91  /*
92  * @brief startControlPoint start point of the edge
93  */
95  /*
96  * @brief endControlPoint end point of the edge
97  */
99 
101 
102  bool infoBoxClicked(const QPointF& point);
103  void setLineTo(QPointF newEndPoint);
104  void setLineFrom(QPointF newStartPoint);
105  void unfoldInfoBox();
106  void foldInfoBox();
107  QPointF getEndPoint();
108  QPointF getStartPoint();
109 private:
110  /*
111  * @brief m_Arrow the edge's end arrow
112  */
113  QGraphicsPolygonItem* m_Arrow; //it's only set but never used
114 
115  /*
116  * @brief m_Cross
117  */
118  QGraphicsPathItem* m_Cross; //TODO: find out what it's there for
119 
120  /*
121  * @brief m_InfoText text of m_InfoBox
122  */
123  QGraphicsSimpleTextItem* m_InfoText;
124 
125  /*
126  * @brief m_InfoBox box containing edge information
127  */
128  QGraphicsRectItem* m_InfoBox;
129 
130  QPainterPath m_CrossPainter;
131  QGraphicsSimpleTextItem* m_pTransitionLabel;
132  QGraphicsEllipseItem* m_pTransitionInfoPoint; //TODO: find out what it's there for
133  float m_InfoPointRadius;
134  float m_ArrowScale;
135 
136  /*
137  * @brief m_transitionName the name of the transition represented by this edge.
138  */
139  QString m_transitionName;
140 
141  //private functions
142 
143  void setInfoPointPosition(QPointF newPosition, double labelAngle);
144 
145  /*
146  * @brief StateChartGraphEdge::setArrowHeadPosition sets the arrowheads position
147  * The arrowhead's shape also is calculated.
148  * @param headLineSegmentStart start of arrow segment
149  * @param headLineSegmentEnd point of arrowhead
150  */
151  void setArrowHeadPosition(QPointF headLineSegmentStart, QPointF headLineSegmentEnd);
152 
153  /*
154  * @brief calcLengthOfLine calculates length of line between start and end
155  * @param start start of line
156  * @param end end of line
157  * @return length of line between start and end
158  */
159  float calcLengthOfLine(floatPair start, floatPair end);
160  /*
161  * @brief calcLengthOfLine calculates length of line between start and end
162  * @param start start of line
163  * @param end end of line
164  * @return length of line between start and end
165  */
166  float calcLengthOfLine(QPointF start, QPointF end);
167  /*
168  * @brief calcControlPoints calculates all the control points of the edge.
169  * @param gvGraphEdge the edge whose control points are to be calculated
170  * @return vector of controlPoints starting with startpoint and ending with endpoint
171  */
172  std::vector<floatPair> calcControlPoints(Agedge_t* gvGraphEdge);
173  /*
174  * @brief calcPath construct path with the given controlPoints
175  * @param controlPoints control points for Bezier polygon
176  */
177  void calcPath(std::vector<floatPair> controlPoints);
178 
179  friend class GVGraphStateChart;
180 };
181 
StateChartGraphEdge
Definition: Transition.h:45
StateChartGraphEdge::m_endControlPoint
floatPair m_endControlPoint
Definition: Transition.h:98
StateChartGraphEdge::GVGraphStateChart
friend class GVGraphStateChart
Definition: Transition.h:179
StateChartGraphEdge::m_bInfoBoxUnfolded
bool m_bInfoBoxUnfolded
Definition: Transition.h:100
StateChartGraphEdge::getTransitionName
QString getTransitionName()
Definition: Transition.h:72
StateChartGraphEdge::m_tailNode
QString m_tailNode
Definition: Transition.h:89
StateChartGraphEdge::StateChartGraphEdge
StateChartGraphEdge(const StateChartGraphEdge &)
Definition: Transition.cpp:40
StateChartGraphEdge::m_Path
QPainterPath m_Path
Definition: Transition.h:81
StateChartGraphEdge::unfoldInfoBox
void unfoldInfoBox()
Definition: Transition.cpp:388
StateChartGraphEdge::~StateChartGraphEdge
~StateChartGraphEdge()
Definition: Transition.cpp:130
StateChartGraphEdge::setTransitionName
void setTransitionName(const QString &name)
Definition: Transition.cpp:140
floatPair
std::pair< float, float > floatPair
Definition: Transition.h:43
StateChartGraphEdge::m_headNode
QString m_headNode
Definition: Transition.h:85
StateChartGraphEdge::getStartPoint
QPointF getStartPoint()
Definition: Transition.cpp:378
StateChartGraphEdge::setLineTo
void setLineTo(QPointF newEndPoint)
Definition: Transition.cpp:146
StateChartGraphEdge::infoBoxClicked
bool infoBoxClicked(const QPointF &point)
Definition: Transition.cpp:433
StateChartGraphEdge::getEndPoint
QPointF getEndPoint()
Definition: Transition.cpp:372
StateChartGraphEdge::m_startControlPoint
floatPair m_startControlPoint
Definition: Transition.h:94
StateChartGraphEdge::setLineFrom
void setLineFrom(QPointF newStartPoint)
Definition: Transition.cpp:183
StateChartGraphEdge::operator=
StateChartGraphEdge & operator=(const StateChartGraphEdge &)
Definition: Transition.cpp:383
StateChartGraphEdge::foldInfoBox
void foldInfoBox()
Definition: Transition.cpp:410