2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-10-16 11:45:17 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
|
|
|
This file is part of QElectroTech.
|
2020-10-03 15:48:40 +02:00
|
|
|
|
2020-10-16 11:45:17 +02:00
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2020-10-03 15:48:40 +02:00
|
|
|
|
2020-10-16 11:45:17 +02:00
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2020-10-03 15:48:40 +02:00
|
|
|
|
2020-10-16 11:45:17 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
2007-12-01 10:47:15 +00:00
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
#ifndef TERMINAL_H
|
|
|
|
#define TERMINAL_H
|
2015-03-02 20:14:56 +00:00
|
|
|
#include <QtWidgets>
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtXml>
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "qet.h"
|
2020-10-16 11:43:45 +02:00
|
|
|
#include "propertiesinterface.h"
|
|
|
|
|
2007-10-03 17:02:39 +00:00
|
|
|
class Conductor;
|
2007-04-09 02:56:47 +00:00
|
|
|
class Diagram;
|
2007-04-12 03:13:13 +00:00
|
|
|
class Element;
|
2020-05-25 22:17:17 +02:00
|
|
|
class TerminalData;
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
2020-10-16 11:45:17 +02:00
|
|
|
@brief The Terminal class
|
|
|
|
This class represents a terminal of an electrical element, i.e. a possible
|
|
|
|
plug point for conductors.
|
|
|
|
This class handles all mouse events for connecting conductors
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2020-10-16 11:43:45 +02:00
|
|
|
class Terminal : public QGraphicsObject, public PropertiesInterface
|
2015-09-10 08:48:33 +00:00
|
|
|
{
|
2020-10-16 11:45:17 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void conductorWasAdded(Conductor *conductor);
|
|
|
|
void conductorWasRemoved(Conductor *conductor);
|
|
|
|
|
|
|
|
// constructors, destructor
|
|
|
|
public:
|
|
|
|
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
|
|
|
|
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
|
|
|
|
Terminal(TerminalData* data, Element *e = nullptr);
|
|
|
|
Terminal(QPointF, Qet::Orientation, QString number,
|
|
|
|
QString name, bool hiddenName, Element * = nullptr);
|
|
|
|
~Terminal() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Terminal(const Terminal &);
|
|
|
|
|
|
|
|
// methods
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
@brief type
|
|
|
|
Enable the use of qgraphicsitem_cast to safely
|
|
|
|
cast a QGraphicsItem into a Terminal
|
|
|
|
@return the QGraphicsItem type
|
|
|
|
*/
|
|
|
|
int type() const override { return Type; }
|
|
|
|
|
|
|
|
void paint(
|
|
|
|
QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *,
|
|
|
|
QWidget *) override;
|
|
|
|
void drawHelpLine (bool draw = true);
|
|
|
|
QLineF HelpLine () const;
|
|
|
|
QRectF boundingRect () const override;
|
|
|
|
|
|
|
|
// methods to manage conductors attached to the terminal
|
|
|
|
Terminal* alignedWithTerminal () const;
|
|
|
|
bool addConductor (Conductor *conductor);
|
|
|
|
void removeConductor (Conductor *conductor);
|
|
|
|
int conductorsCount () const;
|
|
|
|
Diagram *diagram () const;
|
|
|
|
Element *parentElement () const;
|
|
|
|
QUuid uuid () const;
|
2020-10-16 11:43:45 +02:00
|
|
|
int ID() const;
|
|
|
|
QPointF dockPos();
|
|
|
|
QPointF originPos();
|
2020-10-16 11:45:17 +02:00
|
|
|
|
|
|
|
QList<Conductor *> conductors() const;
|
|
|
|
Qet::Orientation orientation() const;
|
|
|
|
QPointF dockConductor() const;
|
|
|
|
QString number() const;
|
|
|
|
QString name() const;
|
|
|
|
void setNumber(QString number);
|
|
|
|
void setName(QString name, bool hiddenName);
|
|
|
|
void updateConductor();
|
|
|
|
bool isLinkedTo(Terminal *);
|
|
|
|
bool canBeLinkedTo(Terminal *);
|
2020-10-16 11:43:45 +02:00
|
|
|
void setID(int id);
|
2020-10-16 11:45:17 +02:00
|
|
|
|
|
|
|
// methods related to XML import/export
|
2020-10-16 11:43:45 +02:00
|
|
|
static bool valideXml(const QDomElement &);
|
|
|
|
bool fromXml (const QDomElement &) override;
|
|
|
|
QDomElement toXml (QDomDocument &) const override;
|
2020-10-16 11:45:17 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// methods related to events management
|
|
|
|
void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1002 };
|
|
|
|
|
|
|
|
static const qreal terminalSize;
|
|
|
|
static const qreal Z;
|
|
|
|
// Various static colors used for hover effects
|
2020-10-16 11:43:45 +02:00
|
|
|
// The assignement is in the cpp file
|
2020-10-16 11:45:17 +02:00
|
|
|
/// default color
|
|
|
|
static QColor neutralColor;
|
|
|
|
/// color for legal actions
|
|
|
|
static QColor allowedColor;
|
|
|
|
/// color for allowed but fuzzy or not recommended actions
|
|
|
|
static QColor warningColor;
|
|
|
|
/// color for forbidden actions
|
|
|
|
static QColor forbiddenColor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_draw_help_line{false};
|
|
|
|
QGraphicsLineItem *m_help_line{nullptr};
|
|
|
|
QGraphicsLineItem *m_help_line_a{nullptr};
|
|
|
|
|
|
|
|
|
|
|
|
TerminalData* d;
|
|
|
|
|
|
|
|
/// Parent electrical element
|
|
|
|
Element *parent_element_{nullptr};
|
|
|
|
public:
|
|
|
|
/// docking point for parent element
|
|
|
|
QPointF dock_elmt_;
|
|
|
|
private:
|
|
|
|
/// List of conductors attached to the terminal
|
|
|
|
QList<Conductor *> conductors_;
|
|
|
|
/**
|
|
|
|
Pointer to a rectangle representing the terminal bounding rect;
|
|
|
|
used to calculate the bounding rect once only;
|
|
|
|
used a pointer because boundingRect() is supposed to be const.
|
|
|
|
*/
|
|
|
|
QRectF *br_{nullptr};
|
|
|
|
/// Last terminal seen through an attached conductor
|
2020-10-16 11:43:45 +02:00
|
|
|
Terminal *previous_terminal_{nullptr};
|
2020-10-16 11:45:17 +02:00
|
|
|
/// Whether the mouse pointer is hovering the terminal
|
2020-10-16 11:43:45 +02:00
|
|
|
bool hovered_{false};
|
2020-10-16 11:45:17 +02:00
|
|
|
/// Color used for the hover effect
|
2020-10-16 11:43:45 +02:00
|
|
|
QColor hovered_color_{Terminal::hovered_color_};
|
2020-10-16 11:45:17 +02:00
|
|
|
/// Number of Terminal
|
|
|
|
QString number_terminal_;
|
2020-10-16 11:43:45 +02:00
|
|
|
bool name_terminal_hidden{true};
|
|
|
|
|
|
|
|
/// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead.
|
|
|
|
int m_id{-1};
|
2020-10-16 11:45:17 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void init(QString number, QString name, bool hiddenName);
|
|
|
|
void init(QPointF pf, Qet::Orientation o, QString number,
|
|
|
|
QString name, bool hiddenName);
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-10-16 11:45:17 +02:00
|
|
|
@brief Terminal::conductorsCount
|
|
|
|
@return the number of conductors attached to the terminal.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
inline int Terminal::conductorsCount() const
|
|
|
|
{
|
2020-10-16 11:45:17 +02:00
|
|
|
return(conductors_.size());
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:43:59 +00:00
|
|
|
/**
|
2020-10-16 11:45:17 +02:00
|
|
|
@brief Terminal::number
|
|
|
|
@return the number of terminal.
|
2013-11-12 18:43:59 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
inline QString Terminal::number() const
|
|
|
|
{
|
2020-10-16 11:45:17 +02:00
|
|
|
return(number_terminal_);
|
2013-11-12 18:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
|
2020-10-16 11:45:17 +02:00
|
|
|
const bool all_diagram = true);
|
2014-10-09 09:02:41 +00:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|