DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaGraphicArrow.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from src/SchemaEditor/SchemaGraphicArrow.cpp to apps/SchemaEditor/SchemaGraphicArrow.cpp).
5
7#include <QPainter>
8#include <QPen>
13#include <cmath>
14
16 SchemaGraphicObject* EndItem,
17 bool IsInheritance,
18 bool IsComposite,
19 QString ArrowName,
20 QString ArrowCardinality,
21 QGraphicsItem* parent)
22 : QGraphicsLineItem(parent)
23 , Start(StartItem)
24 , End(EndItem)
25 , Inheritance(IsInheritance)
26 , Composite(IsComposite)
27 , Name(ArrowName)
28 , Cardinality(ArrowCardinality)
29 , Label(nullptr)
30 , LastDegree(0)
31 , LastRotation(0)
32{
33 // setPen(QPen(Qt::black,2,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
34 setFlag(ItemIsSelectable, true);
35 // LabelString = Name + " - " + Cardinality;
36
37 if (!Start->collidesWithItem(End) && !Inheritance) {
38 Label = new QGraphicsSimpleTextItem(Name + " - " + Cardinality);
39 Label->setParentItem(this);
40 }
41}
42
44
45QRectF
47{
48 qreal extra = (pen().width() + 20) / 2.0 + 10;
49 return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(), line().p2().y() - line().p1().y()))
50 .normalized()
51 .adjusted(-extra, -extra, extra, extra);
52}
53
54QPainterPath
56{
57 QPainterPath path = QGraphicsLineItem::shape();
58 path.addPolygon(ArrowHead);
59 path.addText(line().p2() + QPoint(10, 10), QFont("Helvetica [Cronyx]", 10), Cardinality);
60 path.addText(line().p1() + QPoint(-10, -10), QFont("Helvetica [Cronyx]", 10), Cardinality);
61 return path;
62}
63
64void
66{
67 QLineF line(mapFromItem(Start, 0, 0), mapFromItem(End, 0, 0));
68 setLine(line);
69}
70
76
79{
80 return End;
81}
82
83bool
88
89void
91{
92 if (Inheritance) {
94 } else {
96 }
97}
98
99void
104
105void
106dbse::SchemaGraphicArrow::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
107{
108 Q_UNUSED(option)
109 Q_UNUSED(widget)
110
111 if (Start->collidesWithItem(End)) {
112 return;
113 }
114
115 QPen myPen = pen();
116 myPen.setColor(Qt::black);
117
118 QFont Font("Helvetica [Cronyx]", 10);
119 qreal arrowSize = 10;
120 painter->setFont(Font);
121 painter->setPen(myPen);
122 painter->setBrush(Qt::black);
123
124 QLineF centerLine(Start->mapToScene(Start->boundingRect().center()), End->mapToScene(End->boundingRect().center()));
125 QPolygonF startPolygon = QPolygonF(Start->boundingRect());
126 QPolygonF endPolygon = QPolygonF(End->boundingRect());
127 QPointF p1 = endPolygon.first() + End->pos();
128 QPointF p2;
129 QPointF intersectPointStart;
130 QPointF intersectPointEnd;
131 QLineF polyLine;
132
133 for (int i = 1; i < endPolygon.count(); ++i) {
134 p2 = endPolygon.at(i) + End->pos();
135 polyLine = QLineF(p1, p2);
136 QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointEnd);
137
138 if (intersectType == QLineF::BoundedIntersection) {
139 break;
140 }
141
142 p1 = p2;
143 }
144
145 p1 = startPolygon.first() + Start->pos();
146
147 for (int i = 1; i < startPolygon.count(); ++i) {
148 p2 = startPolygon.at(i) + Start->pos();
149 polyLine = QLineF(p1, p2);
150 QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointStart);
151
152 if (intersectType == QLineF::BoundedIntersection) {
153 break;
154 }
155
156 p1 = p2;
157 }
158
159 setLine(QLineF(intersectPointEnd, intersectPointStart));
160
161 double angle = ::acos(line().dx() / line().length());
162
163 if (line().dy() >= 0) {
164 angle = (M_PI * 2) - angle;
165 }
166
167 QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize);
168 QPointF arrowP2 =
169 line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, cos(angle + M_PI - M_PI / 3) * arrowSize);
170 QPointF middlePoint = QPointF((arrowP1.x() + arrowP2.x()) / 2, (arrowP1.y() + arrowP2.y()) / 2);
171 QPointF arrowP3 = QPointF(line().p1().x() - 2 * (line().p1().x() - middlePoint.x()),
172 line().p1().y() - 2 * (line().p1().y() - middlePoint.y()));
173 ArrowHead.clear();
174 ArrowHead << line().p1() << arrowP1 << arrowP2;
175
176 QFontMetrics Metrics(Font);
177 Metrics.boundingRect(Name + " - " + Cardinality);
178
179 painter->drawLine(line());
180 qreal degree = (angle * 180) / M_PI;
181
182 if (Label) {
183
184 Label->setRotation(-degree + LastDegree);
185
186 if (degree >= 90 && degree < 270) {
187 Label->setTransformOriginPoint(Label->boundingRect().center());
188 Label->setRotation(-180);
189 Label->setTransformOriginPoint(0, 0);
190 LastRotation = 180;
191 Label->setPos(line().p2() + QPointF(-5 * cos(angle), 5 * sin(angle)));
192 } else {
193 Label->setTransformOriginPoint(Label->boundingRect().center());
194 Label->setRotation(360);
195 Label->setTransformOriginPoint(0, 0);
196 LastRotation = -180;
197
198 if (Composite) {
199 Label->setPos(line().p1() + QPointF(20 * cos(angle), -20 * sin(angle)));
200 } else {
201 Label->setPos(line().p1() + QPointF(5 * cos(angle), -5 * sin(angle)));
202 }
203 }
204
205 LastDegree = degree;
206 }
207
208 if (Inheritance) {
209 painter->drawPolygon(ArrowHead);
210 } else if (Composite) {
212 ArrowHead.clear();
213 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
214 painter->drawPolygon(ArrowHead);
215 }
216}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
SchemaGraphicObject * GetEndItem() const
SchemaGraphicArrow(SchemaGraphicObject *StartItem, SchemaGraphicObject *EndItem, bool IsInheritance, bool IsComposite, QString ArrowName, QString ArrowCardinality, QGraphicsItem *parent=nullptr)
Including QT Headers.
SchemaGraphicObject * Start
void SetLabelScene(SchemaGraphicsScene *Scene)
SchemaGraphicObject * End
QGraphicsSimpleTextItem * Label
SchemaGraphicObject * GetStartItem() const