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 <utility>
28
29#include <QFont>
30#include <QGraphicsEllipseItem>
31#include <QGraphicsPolygonItem>
32#include <QGraphicsScene>
33#include <QGraphicsSceneMouseEvent>
34#include <QGraphicsSimpleTextItem>
35#include <QPolygonF>
36#include <QtCore/QString>
37#include <QtCore/QStringList>
38
39#include <graphviz/graph.h>
40#include <graphviz/gvc.h>
41#include <graphviz/types.h>
42
43using floatPair = std::pair<float, float>;
44
45class StateChartGraphEdge : public QGraphicsPathItem
46{
47
48public:
49 /*
50 * @brief StateChartGraphEdge copy constructor
51 * It's supposed to be a copy constructor but not implemented as such
52 */
54 /*
55 * @brief StateChartGraphEdge constructs "empty" StateChartGraphEdge as child of scene
56 * @param scene GraphicsScene the new object belongs to
57 */
58 StateChartGraphEdge(QGraphicsScene* scene = 0);
59 /*
60 * @brief StateChartGraphEdge constructs an StateChartGraphEdge from gvGraphNode
61 * @param gvGraphNode the graphviz node this node represents
62 * @param m_transitionName name of transition that is represented by this edge
63 * @param scene GraphicsScene the edge belongs to
64 * @param dpi dpi value needed to paint the edge
65 */
66 StateChartGraphEdge(Agedge_t* gvGraphNode,
67 const QString& transitionName,
68 QGraphicsScene* scene = 0,
69 float dpi = 72.0f);
72
73 void setTransitionName(const QString& name);
74
75 QString
77 {
78 return m_transitionName;
79 }
80
81 /*
82 * @brief m_Path the edge's path
83 * Approximated by Bezier curves.
84 */
85 QPainterPath m_Path;
86 /*
87 * @brief headNode the node from which the edge starts.
88 */
89 QString m_headNode;
90 /*
91 * @brief tailNode the node to which the edge leads.
92 */
93 QString m_tailNode;
94
95 /*
96 * @brief startControlPoint start point of the edge
97 */
99 /*
100 * @brief endControlPoint end point of the edge
101 */
103
105
106 bool infoBoxClicked(const QPointF& point);
107 void setLineTo(QPointF newEndPoint);
108 void setLineFrom(QPointF newStartPoint);
109 void unfoldInfoBox();
110 void foldInfoBox();
111 QPointF getEndPoint();
112 QPointF getStartPoint();
113
114private:
115 /*
116 * @brief m_Arrow the edge's end arrow
117 */
118 QGraphicsPolygonItem* m_Arrow; //it's only set but never used
119
120 /*
121 * @brief m_Cross
122 */
123 QGraphicsPathItem* m_Cross; //TODO: find out what it's there for
124
125 /*
126 * @brief m_InfoText text of m_InfoBox
127 */
128 QGraphicsSimpleTextItem* m_InfoText;
129
130 /*
131 * @brief m_InfoBox box containing edge information
132 */
133 QGraphicsRectItem* m_InfoBox;
134
135 QPainterPath m_CrossPainter;
136 QGraphicsSimpleTextItem* m_pTransitionLabel;
137 QGraphicsEllipseItem* m_pTransitionInfoPoint; //TODO: find out what it's there for
138 float m_InfoPointRadius;
139 float m_ArrowScale;
140
141 /*
142 * @brief m_transitionName the name of the transition represented by this edge.
143 */
144 QString m_transitionName;
145
146 //private functions
147
148 void setInfoPointPosition(QPointF newPosition, double labelAngle);
149
150 /*
151 * @brief StateChartGraphEdge::setArrowHeadPosition sets the arrowheads position
152 * The arrowhead's shape also is calculated.
153 * @param headLineSegmentStart start of arrow segment
154 * @param headLineSegmentEnd point of arrowhead
155 */
156 void setArrowHeadPosition(QPointF headLineSegmentStart, QPointF headLineSegmentEnd);
157
158 /*
159 * @brief calcLengthOfLine calculates length of line between start and end
160 * @param start start of line
161 * @param end end of line
162 * @return length of line between start and end
163 */
164 float calcLengthOfLine(floatPair start, floatPair end);
165 /*
166 * @brief calcLengthOfLine calculates length of line between start and end
167 * @param start start of line
168 * @param end end of line
169 * @return length of line between start and end
170 */
171 float calcLengthOfLine(QPointF start, QPointF end);
172 /*
173 * @brief calcControlPoints calculates all the control points of the edge.
174 * @param gvGraphEdge the edge whose control points are to be calculated
175 * @return vector of controlPoints starting with startpoint and ending with endpoint
176 */
177 std::vector<floatPair> calcControlPoints(Agedge_t* gvGraphEdge);
178 /*
179 * @brief calcPath construct path with the given controlPoints
180 * @param controlPoints control points for Bezier polygon
181 */
182 void calcPath(std::vector<floatPair> controlPoints);
183
184 friend class GVGraphStateChart;
185};
std::pair< float, float > floatPair
Definition Transition.h:43
void setLineTo(QPointF newEndPoint)
void setLineFrom(QPointF newStartPoint)
StateChartGraphEdge & operator=(const StateChartGraphEdge &)
friend class GVGraphStateChart
Definition Transition.h:184
StateChartGraphEdge(const StateChartGraphEdge &)
void setTransitionName(const QString &name)
QPainterPath m_Path
Definition Transition.h:85
QString getTransitionName()
Definition Transition.h:76
bool infoBoxClicked(const QPointF &point)
floatPair m_startControlPoint
Definition Transition.h:98
floatPair m_endControlPoint
Definition Transition.h:102