QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
conductor.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef CONDUCTOR_H
19#define CONDUCTOR_H
20#include "../autoNum/assignvariables.h"
21#include "../conductorproperties.h"
22
23#include <QGraphicsPathItem>
24
27class Diagram;
28class Terminal;
31class Element;
35
36typedef QPair<QPointF, Qt::Corner> ConductorBend;
37typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
42class Conductor : public QGraphicsObject
43{
44 Q_OBJECT
45
46 Q_PROPERTY(QPointF pos READ pos WRITE setPos)
47 Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
49 Q_PROPERTY(autonum::sequentialNumbers sequenceNum READ sequenceNum WRITE setSequenceNum)
50
51 signals:
53
54 public:
56 ~Conductor() override;
57
58 bool isValid() const;
59
60 private:
62
63 public:
64 enum { Type = UserType + 1001 };
66
69
70 public:
77 int type() const override { return Type; }
78 Diagram *diagram() const;
80 void updatePath(const QRectF & = QRectF());
81
82 //This method do nothing, it's only made to be used with Q_PROPERTY
83 //It's used to anim the path when is change
84 void updatePathAnimate(const int = 1) {updatePath();}
85 int fakePath() {return 1;}
86
87 void paint(
88 QPainter *,
89 const QStyleOptionGraphicsItem *,
90 QWidget *) override;
91 QRectF boundingRect() const override;
92 QPainterPath shape() const override;
93 virtual QPainterPath nearShape() const;
94 qreal length() const;
96 QPointF posForText(Qt::Orientations &flag);
97 void refreshText();
98 void setPath(const QPainterPath &path);
99 QPainterPath path() const;
100
101 public:
102 static bool valideXml (QDomElement &);
103 bool fromXml (QDomElement &);
104 QDomElement toXml (
105 QDomDocument &,
106 QHash<Terminal *,
107 int> &) const;
108 private:
109 bool pathFromXml(const QDomElement &);
110
111 public:
112 QVector <QPointF> handlerPoints() const;
113 const QList<ConductorSegment *> segmentsList() const;
114
116 const ConductorProperties &property,
117 bool only_text = false);
118 void setProperties(const ConductorProperties &property);
120
121 void setProfile(const ConductorProfile &, Qt::Corner);
122 ConductorProfile profile(Qt::Corner) const;
126 virtual Highlight highlight() const;
127 virtual void setHighlighted(Highlight);
128 QSet<Conductor *> relatedPotentialConductors(
129 const bool all_diagram = true,
130 QList <Terminal *> *t_list=nullptr);
132 void editProperty ();
133
139
140 QList<QPointF> junctions() const;
141
142 private:
144 QString old_formula, QString new_formula);
146
147 public:
148 void setFreezeLabel(bool freeze);
149
150 public slots:
152
153 protected:
155 QGraphicsSceneMouseEvent *event) override;
156 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
158 QGraphicsSceneMouseEvent *event) override;
159 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
160 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
161 QVariant itemChange(
162 GraphicsItemChange, const QVariant &) override;
163 bool sceneEventFilter(
164 QGraphicsItem *watched, QEvent *event) override;
165
166 private:
167 void adjusteHandlerPos();
168
171 QGraphicsSceneMouseEvent *event);
174 QGraphicsSceneMouseEvent *event);
177 QGraphicsSceneMouseEvent *event);
178 void addHandler();
179 void removeHandler();
180
181
182 QVector<QetGraphicsHandlerItem *> m_handler_vector;
207 bool m_freeze_label = false;
208
210 static QPen conductor_pen;
211 static QBrush conductor_brush;
213 QPainterPath m_path;
214
215 private:
216 void segmentsToPath();
217 void saveProfile(bool = true);
218 void generateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
219 void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
221 QList<QPointF> segmentsToPoints() const;
222 QList<ConductorBend> bends() const;
223
224 void pointsToSegments(const QList<QPointF>&);
225 Qt::Corner currentPathType() const;
226 void deleteSegments();
227 static int getCoeff(const qreal &, const qreal &);
228 static int getSign(const qreal &);
229 QHash<ConductorSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConductorSegmentProfile *> &, const qreal & = 0.01) const;
230 static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 10);
231 static Qt::Corner movementType(const QPointF &, const QPointF &);
232 static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
233};
234
235Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false);
236QList <Conductor *> relatedConductors (const Conductor *conductor);
237
238
239//return true if @a is between or at @b and @c.
240template <typename T>
241bool isBetween (const T a, const T b, const T c) {
242 return (b <= c)? (a >= b && a <= c) : (a <= b && a >= c);
243}
244
245#endif
Definition conductor.h:43
bool has_to_save_profile
Whether the current profile should be saved as soon as possible.
Definition conductor.h:200
autonum::sequentialNumbers m_autoNum_seq
Definition conductor.h:145
void setSequenceNum(const autonum::sequentialNumbers &sn)
Definition conductor.cpp:1771
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
Conductor::sceneEventFilter.
Definition conductor.cpp:733
bool pathFromXml(const QDomElement &)
Conductor::pathFromXml Generate the path (of the line) from xml file by checking the segments in the ...
Definition conductor.cpp:1117
static QPen conductor_pen
QPen et QBrush objects used to draw conductors.
Definition conductor.h:210
int moved_point
Definition conductor.h:193
QETDiagramEditor * diagramEditor() const
Conductor::diagramEditor.
Definition conductor.cpp:1751
bool isValid() const
Conductor::isValid.
Definition conductor.cpp:153
void setProperties(const ConductorProperties &property)
Conductor::setProperties Set property as current property of conductor.
Definition conductor.cpp:1583
qreal length() const
Conductor::length.
Definition conductor.cpp:1232
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
Conductor::hoverEnterEvent Manage the hover enter event.
Definition conductor.cpp:669
ConductorProfile profile(Qt::Corner) const
Definition conductor.cpp:1487
Diagram * diagram() const
Definition conductor.cpp:580
uint segmentsCount(QET::ConductorSegmentType=QET::Both) const
Definition conductor.cpp:939
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
Conductor::handlerMouseReleaseEvent.
Definition conductor.cpp:845
void updatePathAnimate(const int=1)
Definition conductor.h:84
QPainterPath path() const
Definition conductor.cpp:1536
void generateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation)
Definition conductor.cpp:351
void deleteSegments()
Supprime les segments.
Definition conductor.cpp:1997
QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
Conductor::toXml Exporte les caracteristiques du conducteur sous forme d'une element XML.
Definition conductor.cpp:1035
void pointsToSegments(const QList< QPointF > &)
Definition conductor.cpp:983
int m_vector_index
Definition conductor.h:183
ConductorProperties properties
Definition conductor.h:48
ConductorProfilesGroup profiles() const
Definition conductor.cpp:1973
int type() const override
type Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a conductor.
Definition conductor.h:77
ConductorProfilesGroup conductor_profiles
Definition conductor.h:203
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Conductor::mouseReleaseEvent.
Definition conductor.cpp:658
QVariant itemChange(GraphicsItemChange, const QVariant &) override
Conductor::itemChange.
Definition conductor.cpp:692
ConductorProperties m_properties
Functional properties.
Definition conductor.h:186
QPointF pos
Definition conductor.h:46
Terminal * terminal1
Definition conductor.h:67
void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation)
Definition conductor.cpp:222
QRectF boundingRect() const override
Conductor::boundingRect.
Definition conductor.cpp:901
@ Type
Definition conductor.h:64
static bool pen_and_brush_initialized
Definition conductor.h:212
void displayedTextChanged()
Conductor::displayedTextChanged Update the properties (text) of this conductor and other conductors a...
Definition conductor.cpp:1652
virtual QPainterPath nearShape() const
Conductor::nearShape.
Definition conductor.cpp:927
ConductorSegment * middleSegment()
Definition conductor.cpp:1239
int animPath
Definition conductor.h:47
bool fromXml(QDomElement &)
Conductor::fromXml Load the conductor and her information from xml element.
Definition conductor.cpp:1001
QSet< Conductor * > relatedPotentialConductors(const bool all_diagram=true, QList< Terminal * > *t_list=nullptr)
Conductor::relatedPotentialConductors Return all conductors at the same potential of this conductor,...
Definition conductor.cpp:1693
void setProfiles(const ConductorProfilesGroup &)
Conductor::setProfiles.
Definition conductor.cpp:1982
void setPath(const QPainterPath &path)
Definition conductor.cpp:1526
void setFreezeLabel(bool freeze)
Conductor::setFreezeLabel Freeze this conductor label if true Unfreeze this conductor label if false.
Definition conductor.cpp:2111
bool modified_path
Whether the conductor was manually modified by users.
Definition conductor.h:198
static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal=10)
Conductor::extendTerminal.
Definition conductor.cpp:456
static int getSign(const qreal &)
Definition conductor.cpp:1460
int fakePath()
Definition conductor.h:85
Highlight must_highlight_
Define whether and how the conductor should be highlighted.
Definition conductor.h:205
QHash< ConductorSegmentProfile *, qreal > shareOffsetBetweenSegments(const qreal &offset, const QList< ConductorSegmentProfile * > &, const qreal &=0.01) const
Definition conductor.cpp:291
qreal m_previous_z_value
Definition conductor.h:194
Terminal * terminal2
Definition conductor.h:68
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Conductor::hoverLeaveEvent Manage the mouse leave event.
Definition conductor.cpp:680
virtual void setHighlighted(Highlight)
Definition conductor.cpp:1642
static int getCoeff(const qreal &, const qreal &)
Definition conductor.cpp:1452
Highlight
Definition conductor.h:65
@ None
Definition conductor.h:65
@ Normal
Definition conductor.h:65
@ Alert
Definition conductor.h:65
QList< QPointF > segmentsToPoints() const
Definition conductor.cpp:954
QPainterPath shape() const override
Conductor::shape.
Definition conductor.cpp:912
QVector< QPointF > handlerPoints() const
Conductor::handlerPoints.
Definition conductor.cpp:1195
bool m_valid
Definition conductor.h:206
void setPropertyToPotential(const ConductorProperties &property, bool only_text=false)
Conductor::setPropertiesToPotential.
Definition conductor.cpp:1552
Qt::Corner currentPathType() const
Definition conductor.cpp:1967
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Conductor::mouseDoubleClickEvent Manage the mouse double click.
Definition conductor.cpp:636
void setProfile(const ConductorProfile &, Qt::Corner)
Definition conductor.cpp:1469
ConductorTextItem * m_text_item
Text input for non simple, non-singleline conductors.
Definition conductor.h:188
static Qt::Corner movementType(const QPointF &, const QPointF &)
Definition conductor.cpp:1956
bool m_freeze_label
Definition conductor.h:207
autonum::sequentialNumbers & rSequenceNum()
Definition conductor.h:136
QPointF posForText(Qt::Orientations &flag)
Conductor::posForText Calculate and return the better pos for text.
Definition conductor.cpp:1263
void removeHandler()
Conductor::removeHandler Remove the handlers of this item.
Definition conductor.cpp:888
void calculateTextItemPosition()
Conductor::calculateTextItemPosition Move the text at middle of conductor (if is vertical or horizont...
Definition conductor.cpp:1334
void setUpConnectionForFormula(QString old_formula, QString new_formula)
Conductor::setUpConnectionForFormula setup connection according to the variable of formula.
Definition conductor.cpp:1783
bool m_mouse_over
Definition conductor.h:184
autonum::sequentialNumbers sequenceNum() const
Definition conductor.h:134
const QList< ConductorSegment * > segmentsList() const
Definition conductor.cpp:1213
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition conductor.h:182
autonum::sequentialNumbers sequenceNum
Definition conductor.h:49
QPointF before_mov_text_pos_
Definition conductor.h:196
void saveProfile(bool=true)
Definition conductor.cpp:1430
void editProperty()
Conductor::editProperty.
Definition conductor.cpp:1766
ConductorSegment * m_moved_segment
Definition conductor.h:195
ConductorSegment * segments
Segments composing the conductor.
Definition conductor.h:190
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Definition conductor.cpp:488
void adjusteHandlerPos()
Conductor::adjusteHandlerPos Adjust the position of the handler item.
Definition conductor.cpp:776
virtual Highlight highlight() const
Definition conductor.cpp:1634
ConductorTextItem * textItem() const
Definition conductor.cpp:588
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
Conductor::handlerMouseMoveEvent.
Definition conductor.cpp:817
QPainterPath m_path
Definition conductor.h:213
QList< QPointF > junctions() const
Definition conductor.cpp:1827
void segmentsToPath()
Conductor::segmentsToPath Generate the QPainterPath from the list of points.
Definition conductor.cpp:181
void propertiesChange()
bool m_moving_segment
Attributes related to mouse interaction.
Definition conductor.h:192
void refreshText()
Conductor::refreshText Refresh the text of this conductor. recalcule and set the text according to th...
Definition conductor.cpp:1497
QList< ConductorBend > bends() const
Definition conductor.cpp:1898
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &)
Conductor::movePointIntoPolygon.
Definition conductor.cpp:2013
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
Conductor::handlerMousePressEvent.
Definition conductor.cpp:794
static bool valideXml(QDomElement &)
Definition conductor.cpp:598
void updatePath(const QRectF &=QRectF())
Definition conductor.cpp:165
static QBrush conductor_brush
Definition conductor.h:211
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Conductor::mousePressEvent Manage the mouse press event.
Definition conductor.cpp:646
void addHandler()
Conductor::addHandler Add handlers for this item.
Definition conductor.cpp:868
Definition conductorprofile.h:28
The ConductorProperties class This class represents the functional properties of a particular conduct...
Definition conductorproperties.h:68
Definition conductorsegment.h:25
Definition conductorsegmentprofile.h:26
Definition conductortextitem.h:30
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition diagram.h:56
Definition element.h:43
Definition numerotationcontext.h:31
Definition qetdiagrameditor.h:55
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition qetgraphicshandleritem.h:37
Orientation
Orientation (used for electrical elements and their terminals)
Definition qet.h:210
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition terminal.h:36
Definition assignvariables.h:34
QPair< QPointF, Qt::Corner > ConductorBend
Definition conductor.h:36
bool isBetween(const T a, const T b, const T c)
Definition conductor.h:241
Conductor * longuestConductorInPotential(Conductor *conductor, bool all_diagram=false)
longuestConductorInPotential
Definition conductor.cpp:2081
QList< Conductor * > relatedConductors(const Conductor *conductor)
relatedConductors
Definition conductor.cpp:2098
QHash< Qt::Corner, ConductorProfile > ConductorProfilesGroup
Definition conductor.h:37
ConductorSegmentType
Known kinds of conductor segments.
Definition qet.h:84
@ Both
Invalid segment.
Definition qet.h:87
Definition assignvariables.cpp:31