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, bool IsInheritance,
17 bool IsComposite, QString ArrowName,
18 QString ArrowCardinality, QGraphicsItem * parent )
19 : QGraphicsLineItem ( parent ),
20 Start ( StartItem ),
21 End ( EndItem ),
22 Inheritance ( IsInheritance ),
23 Composite ( IsComposite ),
24 Name ( ArrowName ),
25 Cardinality ( ArrowCardinality ),
26 Label ( nullptr ),
27 LastDegree ( 0 ),
28 LastRotation ( 0 )
29{
30 //setPen(QPen(Qt::black,2,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
31 setFlag ( ItemIsSelectable, true );
32 //LabelString = Name + " - " + Cardinality;
33
34 if ( !Start->collidesWithItem ( End ) && !Inheritance )
35 {
36 Label = new QGraphicsSimpleTextItem ( Name + " - " + Cardinality );
37 Label->setParentItem ( this );
38 }
39
40}
41
45
47{
48 qreal extra = ( pen().width() + 20 ) / 2.0 + 10;
49 return QRectF ( line().p1(),
50 QSizeF ( line().p2().x() - line().p1().x(),
51 line().p2().y() - line().p1().y() ) ).normalized().adjusted (
52 -extra, -extra, extra, extra );
53}
54
56{
57 QPainterPath path = QGraphicsLineItem::shape();
58 path.addPolygon ( ArrowHead );
59 path.addText ( line().p2() + QPoint ( 10, 10 ), QFont ( "Helvetica [Cronyx]", 10 ),
61 path.addText ( line().p1() + QPoint ( -10, -10 ), QFont ( "Helvetica [Cronyx]", 10 ),
63 return path;
64}
65
67{
68 QLineF line ( mapFromItem ( Start, 0, 0 ), mapFromItem ( End, 0, 0 ) );
69 setLine ( line );
70}
71
76
81
86
88{
89 if ( Inheritance )
90 {
92 }
93 else
94 {
96 }
97}
98
100{
101 Scene->addItem ( Label );
102}
103
104void dbse::SchemaGraphicArrow::paint ( QPainter * painter,
105 const QStyleOptionGraphicsItem * option,
106 QWidget * widget )
107{
108 Q_UNUSED ( option )
109 Q_UNUSED ( widget )
110
111 if ( Start->collidesWithItem ( End ) )
112 {
113 return;
114 }
115
116 QPen myPen = pen();
117 myPen.setColor ( Qt::black );
118
119 QFont Font ( "Helvetica [Cronyx]", 10 );
120 qreal arrowSize = 10;
121 painter->setFont ( Font );
122 painter->setPen ( myPen );
123 painter->setBrush ( Qt::black );
124
125 QLineF centerLine ( Start->mapToScene ( Start->boundingRect().center() ),
126 End->mapToScene ( End->boundingRect().center() ) );
127 QPolygonF startPolygon = QPolygonF ( Start->boundingRect() );
128 QPolygonF endPolygon = QPolygonF ( End->boundingRect() );
129 QPointF p1 = endPolygon.first() + End->pos();
130 QPointF p2;
131 QPointF intersectPointStart;
132 QPointF intersectPointEnd;
133 QLineF polyLine;
134
135 for ( int i = 1; i < endPolygon.count(); ++i )
136 {
137 p2 = endPolygon.at ( i ) + End->pos();
138 polyLine = QLineF ( p1, p2 );
139 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine, &intersectPointEnd );
140
141 if ( intersectType == QLineF::BoundedIntersection )
142 {
143 break;
144 }
145
146 p1 = p2;
147 }
148
149 p1 = startPolygon.first() + Start->pos();
150
151 for ( int i = 1; i < startPolygon.count(); ++i )
152 {
153 p2 = startPolygon.at ( i ) + Start->pos();
154 polyLine = QLineF ( p1, p2 );
155 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine,
156 &intersectPointStart );
157
158 if ( intersectType == QLineF::BoundedIntersection )
159 {
160 break;
161 }
162
163 p1 = p2;
164 }
165
166 setLine ( QLineF ( intersectPointEnd, intersectPointStart ) );
167
168 double angle = ::acos ( line().dx() / line().length() );
169
170 if ( line().dy() >= 0 )
171 {
172 angle = ( M_PI * 2 ) - angle;
173 }
174
175 QPointF arrowP1 = line().p1()
176 + QPointF ( sin ( angle + M_PI / 3 ) * arrowSize, cos ( angle + M_PI / 3 ) * arrowSize );
177 QPointF arrowP2 = line().p1()
178 + QPointF ( sin ( angle + M_PI - M_PI / 3 ) * arrowSize,
179 cos ( angle + M_PI - M_PI / 3 ) * arrowSize );
180 QPointF middlePoint = QPointF ( ( arrowP1.x() + arrowP2.x() ) / 2,
181 ( arrowP1.y() + arrowP2.y() ) / 2 );
182 QPointF arrowP3 = QPointF ( line().p1().x() - 2 * ( line().p1().x() - middlePoint.x() ),
183 line().p1().y() - 2 * ( line().p1().y() - middlePoint.y() ) );
184 ArrowHead.clear();
185 ArrowHead << line().p1() << arrowP1 << arrowP2;
186
187 QFontMetrics Metrics ( Font );
188 Metrics.boundingRect ( Name + " - " + Cardinality );
189
190 painter->drawLine ( line() );
191 qreal degree = ( angle * 180 ) / M_PI;
192
193 if ( Label )
194 {
195
196 Label->setRotation ( -degree + LastDegree );
197
198 if ( degree >= 90 && degree < 270 )
199 {
200 Label->setTransformOriginPoint ( Label->boundingRect().center() );
201 Label->setRotation ( -180 );
202 Label->setTransformOriginPoint ( 0, 0 );
203 LastRotation = 180;
204 Label->setPos ( line().p2() + QPointF ( -5 * cos ( angle ), 5 * sin ( angle ) ) );
205 }
206 else
207 {
208 Label->setTransformOriginPoint ( Label->boundingRect().center() );
209 Label->setRotation ( 360 );
210 Label->setTransformOriginPoint ( 0, 0 );
211 LastRotation = -180;
212
213 if ( Composite )
214 {
215 Label->setPos ( line().p1() + QPointF ( 20 * cos ( angle ), -20 * sin ( angle ) ) );
216 }
217 else
218 {
219 Label->setPos ( line().p1() + QPointF ( 5 * cos ( angle ), -5 * sin ( angle ) ) );
220 }
221 }
222
223 LastDegree = degree;
224 }
225
226 if ( Inheritance )
227 {
228 painter->drawPolygon ( ArrowHead );
229 }
230 else if ( Composite )
231 {
233 ArrowHead.clear();
234 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
235 painter->drawPolygon ( ArrowHead );
236 }
237}
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