QElectroTech  0.8-dev
terminal.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 TERMINAL_H
19 #define TERMINAL_H
20 #include <QtWidgets>
21 #include <QtXml>
22 #include "qet.h"
23 class Conductor;
24 class Diagram;
25 class Element;
26 class TerminalData;
27 
34 class Terminal : public QGraphicsObject
35 {
36  Q_OBJECT
37 
38  signals:
39  void conductorWasAdded(Conductor *conductor);
40  void conductorWasRemoved(Conductor *conductor);
41 
42  // constructors, destructor
43  public:
44  Terminal(QPointF, Qet::Orientation, Element * = nullptr);
45  Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
46  Terminal(TerminalData* data, Element *e = nullptr);
47  Terminal(QPointF, Qet::Orientation, QString number,
48  QString name, bool hiddenName, Element * = nullptr);
49  ~Terminal() override;
50 
51  private:
52  Terminal(const Terminal &);
53 
54  // methods
55  public:
62  int type() const override { return Type; }
63 
64  void paint (QPainter *,const QStyleOptionGraphicsItem *,
65  QWidget *) override;
66  void drawHelpLine (bool draw = true);
67  QLineF HelpLine () const;
68  QRectF boundingRect () const override;
69 
70  // methods to manage conductors attached to the terminal
71  Terminal* alignedWithTerminal () const;
72  bool addConductor (Conductor *conductor);
73  void removeConductor (Conductor *conductor);
74  int conductorsCount () const;
75  Diagram *diagram () const;
76  Element *parentElement () const;
77  QUuid uuid () const;
78 
79  QList<Conductor *> conductors() const;
81  QPointF dockConductor() const;
82  QString number() const;
83  QString name() const;
84  void setNumber(QString number);
85  void setName(QString name, bool hiddenName);
86  void updateConductor();
87  bool isLinkedTo(Terminal *);
88  bool canBeLinkedTo(Terminal *);
89 
90  // methods related to XML import/export
91  static bool valideXml(QDomElement &);
92  bool fromXml (QDomElement &);
93  QDomElement toXml (QDomDocument &) const;
94 
95  protected:
96  // methods related to events management
97  void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
98  void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
99  void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
100  void mousePressEvent (QGraphicsSceneMouseEvent *) override;
101  void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
102  void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
103 
104  // attributes
105  public:
106  enum { Type = UserType + 1002 };
107 
108  static const qreal terminalSize;
109  static const qreal Z;
110  // Various static colors used for hover effects
112  static QColor neutralColor;
114  static QColor allowedColor;
116  static QColor warningColor;
118  static QColor forbiddenColor;
119 
120  private:
121  bool m_draw_help_line{false};
122  QGraphicsLineItem *m_help_line{nullptr};
123  QGraphicsLineItem *m_help_line_a{nullptr};
124 
125 
127 
131  QPointF dock_elmt_;
133  QList<Conductor *> conductors_;
139  QRectF *br_{nullptr};
143  bool hovered_;
149  QString name_terminal_;
151 
152  private:
153  void init(QString number, QString name, bool hiddenName);
154  void init(QPointF pf, Qet::Orientation o, QString number,
155  QString name, bool hiddenName);
156 };
157 
162 inline int Terminal::conductorsCount() const {
163  return(conductors_.size());
164 }
165 
170 inline QString Terminal::number() const {
171  return(number_terminal_);
172 }
173 
178 inline QString Terminal::name() const {
179  return(name_terminal_);
180 }
181 
182 QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
183  const bool all_diagram = true);
184 
185 #endif
Element::Terminale
@ Terminale
Definition: element.h:57
Terminal::valideXml
static bool valideXml(QDomElement &)
Terminal::valideXml Permet de savoir si un element XML represente une borne.
Definition: terminal.cpp:746
TerminalData::m_orientation
Qet::Orientation m_orientation
m_orientation Orientation of the terminal
Definition: terminaldata.h:43
Terminal::conductors
QList< Conductor * > conductors() const
Terminal::conductors.
Definition: terminal.cpp:715
Qet::isOpposed
static bool isOpposed(Qet::Orientation a, Qet::Orientation b)
Qet::isOpposed.
Definition: qet.cpp:77
Diagram::background_color
static QColor background_color
background color of diagram
Definition: diagram.h:99
Conductor::sequenceNum
autonum::sequentialNumbers sequenceNum
Definition: conductor.h:49
Qet::West
@ West
Definition: qet.h:209
Terminal::Type
@ Type
Definition: terminal.h:106
Terminal::conductorWasRemoved
void conductorWasRemoved(Conductor *conductor)
Conductor::terminal2
Terminal * terminal2
Definition: conductor.h:68
diagramcommands.h
Conductor::setProperties
void setProperties(const ConductorProperties &property)
Conductor::setProperties Set property as current property of conductor.
Definition: conductor.cpp:1538
Terminal::number_terminal_
QString number_terminal_
Number of Terminal.
Definition: terminal.h:147
Terminal::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Terminal::paint Fonction de dessin des bornes.
Definition: terminal.cpp:253
Conductor::updatePath
void updatePath(const QRectF &=QRectF())
Definition: conductor.cpp:161
Terminal::hovered_color_
QColor hovered_color_
Color used for the hover effect.
Definition: terminal.h:145
conductor.h
QET::lineContainsPoint
bool lineContainsPoint(const QLineF &, const QPointF &)
Definition: qet.cpp:150
conductortextitem.h
Terminal::diagram
Diagram * diagram() const
Terminal::diagram.
Definition: terminal.cpp:814
Terminal::parent_element_
Element * parent_element_
Parent electrical element.
Definition: terminal.h:129
Terminal::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseReleaseEvent.
Definition: terminal.cpp:596
Terminal::name
QString name() const
Terminal::name.
Definition: terminal.h:178
Terminal::name_terminal_hidden
bool name_terminal_hidden
Definition: terminal.h:150
relatedPotentialTerminal
QList< Terminal * > relatedPotentialTerminal(const Terminal *terminal, const bool all_diagram)
Conductor::relatedPotentialTerminal Return terminal at the same potential from the same parent elemen...
Definition: terminal.cpp:841
Terminal::Z
static const qreal Z
Definition: terminal.h:109
Terminal::HelpLine
QLineF HelpLine() const
Terminal::HelpLine.
Definition: terminal.cpp:386
TerminalData::m_pos
QPointF m_pos
m_pos Position of the terminal. The second point is calculated from this position and the orientation
Definition: terminaldata.h:82
Terminal::fromXml
bool fromXml(QDomElement &)
Terminal::fromXml Permet de savoir si un element XML represente cette borne. Attention,...
Definition: terminal.cpp:788
Terminal::parentElement
Element * parentElement() const
Terminal::parentElement.
Definition: terminal.cpp:822
Terminal::dock_elmt_
QPointF dock_elmt_
docking point for parent element
Definition: terminal.h:131
Terminal::setNumber
void setNumber(QString number)
Terminal::setNumber.
Definition: terminal.cpp:195
Terminal::uuid
QUuid uuid() const
Definition: terminal.cpp:826
ConductorAutoNumerotation::numerate
void numerate()
ConductorAutoNumerotation::numerate execute the automatic numerotation.
Definition: conductorautonumerotation.cpp:56
Terminal::neutralColor
static QColor neutralColor
default color
Definition: terminal.h:112
Conductor::terminal1
Terminal * terminal1
Definition: conductor.h:67
Terminal::warningColor
static QColor warningColor
color for allowed but fuzzy or not recommended actions
Definition: terminal.h:116
Terminal::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverEnterEvent Gere l'entree de la souris sur la zone de la Borne.
Definition: terminal.cpp:500
Terminal::forbiddenColor
static QColor forbiddenColor
color for forbidden actions
Definition: terminal.h:118
Terminal::isLinkedTo
bool isLinkedTo(Terminal *)
Terminal::isLinkedTo.
Definition: terminal.cpp:680
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
qet.h
Terminal::m_help_line_a
QGraphicsLineItem * m_help_line_a
Definition: terminal.h:123
Conductor::rSequenceNum
autonum::sequentialNumbers & rSequenceNum()
Definition: conductor.h:132
Terminal::d
TerminalData * d
Definition: terminal.h:126
QET::Icons::Conductor
QIcon Conductor
Definition: qeticons.cpp:35
Terminal::type
int type() const override
type Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a Terminal
Definition: terminal.h:62
Terminal::removeConductor
void removeConductor(Conductor *conductor)
Terminal::removeConductor Remove a conductor from this terminal.
Definition: terminal.cpp:239
TerminalData
The TerminalData class Data of the terminal. Stored in extra class so it can be used by PartTerminal ...
Definition: terminaldata.h:20
Terminal::previous_terminal_
Terminal * previous_terminal_
Last terminal seen through an attached conductor.
Definition: terminal.h:141
Qet::Orientation
Orientation
Orientation (used for electrical elements and their terminals)
Definition: qet.h:206
Terminal::setName
void setName(QString name, bool hiddenName)
Terminal::setName.
Definition: terminal.cpp:204
AddItemCommand
The AddItemCommand class This command add an item in a diagram The item to add is template,...
Definition: diagramcommands.h:42
element.h
Conductor::properties
ConductorProperties properties
Definition: conductor.h:48
Terminal::~Terminal
~Terminal() override
Definition: terminal.cpp:163
Terminal::conductors_
QList< Conductor * > conductors_
List of conductors attached to the terminal.
Definition: terminal.h:133
Element
Definition: element.h:41
Terminal::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverMoveEvent Gere les mouvements de la souris sur la zone de la Borne.
Definition: terminal.cpp:509
Element::terminals
QList< Terminal * > terminals() const
Element::terminals.
Definition: element.cpp:136
Terminal::name_terminal_
QString name_terminal_
Name of Terminal.
Definition: terminal.h:149
Terminal::drawHelpLine
void drawHelpLine(bool draw=true)
Terminal::drawHelpLine.
Definition: terminal.cpp:359
Element::AllReport
@ AllReport
Definition: element.h:54
Terminal::addConductor
bool addConductor(Conductor *conductor)
Terminal::addConductor Add a conductor to this terminal.
Definition: terminal.cpp:215
Terminal::canBeLinkedTo
bool canBeLinkedTo(Terminal *)
Terminal::canBeLinkedTo Checking if the terminal can be linked to other_terminal or not Reasons for n...
Definition: terminal.cpp:703
Terminal::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverLeaveEvent Gere le fait que la souris sorte de la zone de la Borne.
Definition: terminal.cpp:516
conductorautonumerotation.h
terminaldata.h
relatedPotentialTerminal
QList< Terminal * > relatedPotentialTerminal(const Terminal *terminal, const bool all_diagram=true)
Conductor::relatedPotentialTerminal Return terminal at the same potential from the same parent elemen...
Definition: terminal.cpp:841
Qet::isHorizontal
static bool isHorizontal(Qet::Orientation)
Qet::isHorizontal.
Definition: qet.cpp:107
ConductorAutoNumerotation
The ConductorAutoNumerotation class.
Definition: conductorautonumerotation.h:33
Qet::North
@ North
Definition: qet.h:206
Terminal::conductorWasAdded
void conductorWasAdded(Conductor *conductor)
Terminal::init
void init(QString number, QString name, bool hiddenName)
Terminal::init Methode privee pour initialiser la borne.
Definition: terminal.cpp:43
Terminal::conductorsCount
int conductorsCount() const
Terminal::conductorsCount.
Definition: terminal.h:162
Conductor::relatedPotentialConductors
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:1647
Terminal::m_help_line
QGraphicsLineItem * m_help_line
Definition: terminal.h:122
Terminal::boundingRect
QRectF boundingRect() const override
Terminal::boundingRect.
Definition: terminal.cpp:418
Terminal::number
QString number() const
Terminal::number.
Definition: terminal.h:170
Qet::South
@ South
Definition: qet.h:208
Terminal::m_draw_help_line
bool m_draw_help_line
Definition: terminal.h:121
ConductorProperties
The ConductorProperties class This class represents the functional properties of a particular conduct...
Definition: conductorproperties.h:68
Terminal::Terminal
Terminal(const Terminal &)
Terminal::alignedWithTerminal
Terminal * alignedWithTerminal() const
Terminal::alignedWithTerminal If this terminal is aligned with an other terminal and is orientation i...
Definition: terminal.cpp:441
TerminalData::m_uuid
QUuid m_uuid
m_uuid Uuid of the terminal.
Definition: terminaldata.h:64
Terminal::updateConductor
void updateConductor()
Terminal::updateConductor Update the path of conductor docked to this terminal.
Definition: terminal.cpp:670
Terminal::toXml
QDomElement toXml(QDomDocument &) const
Terminal::toXml Methode d'export en XML.
Definition: terminal.cpp:725
Terminal::dockConductor
QPointF dockConductor() const
Terminal::dockConductor.
Definition: terminal.cpp:805
Conductor
Definition: conductor.h:43
Qet::East
@ East
Definition: qet.h:207
terminal.h
Terminal::Terminal
Terminal(QPointF, Qet::Orientation, Element *=nullptr)
Definition: terminal.cpp:103
TerminalData::setParent
void setParent(QGraphicsObject *parent)
TerminalData::setParent.
Definition: terminaldata.cpp:30
Terminal
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition: terminal.h:35
Terminal::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *) override
Terminal::mousePressEvent Gere le fait qu'on enfonce un bouton de la souris sur la Borne.
Definition: terminal.cpp:526
Terminal::terminalSize
static const qreal terminalSize
Definition: terminal.h:108
Terminal::br_
QRectF * br_
Definition: terminal.h:139
Terminal::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseMoveEvent Gere le fait qu'on bouge la souris sur la Borne.
Definition: terminal.cpp:540
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
Terminal::orientation
Qet::Orientation orientation() const
Definition: terminal.cpp:175
diagram.h
Terminal::allowedColor
static QColor allowedColor
color for legal actions
Definition: terminal.h:114
Terminal::hovered_
bool hovered_
Whether the mouse pointer is hovering the terminal.
Definition: terminal.h:143