2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
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"
|
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;
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents a terminal of an electrical element, i.e. a possible
|
|
|
|
plug point for conductors.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2015-09-10 08:48:33 +00:00
|
|
|
class Terminal : public QGraphicsObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void conductorWasAdded(Conductor *conductor);
|
|
|
|
void conductorWasRemoved(Conductor *conductor);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
// constructors, destructor
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
|
|
|
|
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
|
|
|
|
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~Terminal() override;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
2014-12-14 13:06:21 +00:00
|
|
|
Terminal(const Terminal &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2015-01-07 19:21:17 +00:00
|
|
|
//Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a Terminal
|
|
|
|
//@return the QGraphicsItem type
|
2017-08-05 02:10:01 +00:00
|
|
|
int type() const override { return Type; }
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
2015-01-07 19:21:17 +00:00
|
|
|
void drawHelpLine (bool draw = true);
|
|
|
|
QLineF HelpLine () const;
|
2017-08-05 02:10:01 +00:00
|
|
|
QRectF boundingRect () const override;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2015-01-07 19:21:17 +00:00
|
|
|
// methods to manage conductors attached to the terminal
|
|
|
|
Terminal* alignedWithTerminal () const;
|
2015-09-10 08:48:33 +00:00
|
|
|
bool addConductor (Conductor *conductor);
|
|
|
|
void removeConductor (Conductor *conductor);
|
2015-01-07 19:21:17 +00:00
|
|
|
int conductorsCount () const;
|
|
|
|
Diagram *diagram () const;
|
|
|
|
Element *parentElement () const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2007-10-03 17:02:39 +00:00
|
|
|
QList<Conductor *> conductors() const;
|
2014-05-29 13:46:04 +00:00
|
|
|
Qet::Orientation orientation() const;
|
2010-04-18 20:48:15 +00:00
|
|
|
QPointF dockConductor() const;
|
2013-11-12 18:43:59 +00:00
|
|
|
QString number() const;
|
2013-11-16 16:53:46 +00:00
|
|
|
QString name() const;
|
2013-11-13 11:55:27 +00:00
|
|
|
void setNumber(QString number);
|
2013-11-16 16:53:46 +00:00
|
|
|
void setName(QString name, bool hiddenName);
|
2010-05-04 20:18:30 +00:00
|
|
|
void updateConductor();
|
2010-04-18 20:48:15 +00:00
|
|
|
bool isLinkedTo(Terminal *);
|
|
|
|
bool canBeLinkedTo(Terminal *);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to XML import/export
|
2007-04-09 02:56:47 +00:00
|
|
|
static bool valideXml(QDomElement &);
|
2007-04-12 03:13:13 +00:00
|
|
|
bool fromXml (QDomElement &);
|
|
|
|
QDomElement toXml (QDomDocument &) const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
protected:
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to events management
|
2017-08-05 02:10:01 +00:00
|
|
|
void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1002 };
|
2012-11-09 21:09:24 +00:00
|
|
|
/// terminal length
|
2007-10-10 22:35:32 +00:00
|
|
|
static const qreal terminalSize;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// Various static colors used for hover effects
|
|
|
|
/// default color
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor neutralColor;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// color for legal actions
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor allowedColor;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// color for allowed but fuzzy or not recommended actions
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor warningColor;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// color for forbidden actions
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor forbiddenColor;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
private:
|
2015-01-07 19:21:17 +00:00
|
|
|
bool m_draw_help_line;
|
|
|
|
QGraphicsLineItem *m_help_line;
|
2015-01-18 11:28:56 +00:00
|
|
|
QGraphicsLineItem *m_help_line_a;
|
2015-01-07 19:21:17 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Parent electrical element
|
2010-04-18 20:48:15 +00:00
|
|
|
Element *parent_element_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// docking point for conductors
|
2010-04-18 20:48:15 +00:00
|
|
|
QPointF dock_conductor_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// docking point for parent element
|
2010-04-18 20:48:15 +00:00
|
|
|
QPointF dock_elmt_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// terminal orientation
|
2014-05-29 13:46:04 +00:00
|
|
|
Qet::Orientation ori_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List of conductors attached to the terminal
|
2010-04-18 20:48:15 +00:00
|
|
|
QList<Conductor *> conductors_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// 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.
|
2010-04-18 20:48:15 +00:00
|
|
|
QRectF *br_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Last terminal seen through an attached conductor
|
2010-04-18 20:48:15 +00:00
|
|
|
Terminal *previous_terminal_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether the mouse pointer is hovering the terminal
|
2010-04-18 20:48:15 +00:00
|
|
|
bool hovered_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Color used for the hover effect
|
2010-04-18 20:48:15 +00:00
|
|
|
QColor hovered_color_;
|
2013-11-12 18:43:59 +00:00
|
|
|
/// Number of Terminal
|
|
|
|
QString number_terminal_;
|
2013-11-16 16:53:46 +00:00
|
|
|
/// Name of Terminal
|
|
|
|
QString name_terminal_;
|
|
|
|
bool name_terminal_hidden;
|
2010-04-18 20:48:15 +00:00
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
private:
|
2014-05-29 13:46:04 +00:00
|
|
|
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName);
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return the number of conductors attached to the terminal.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
inline int Terminal::conductorsCount() const {
|
|
|
|
return(conductors_.size());
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return the position, relative to the scene, of the docking point for
|
|
|
|
conductors.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
inline QPointF Terminal::dockConductor() const {
|
|
|
|
return(mapToScene(dock_conductor_));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:43:59 +00:00
|
|
|
/**
|
|
|
|
@return the number of terminal.
|
|
|
|
*/
|
|
|
|
inline QString Terminal::number() const {
|
|
|
|
return(number_terminal_);
|
|
|
|
}
|
|
|
|
|
2013-11-16 16:53:46 +00:00
|
|
|
/**
|
|
|
|
@return the name of terminal.
|
|
|
|
*/
|
|
|
|
inline QString Terminal::name() const {
|
|
|
|
return(name_terminal_);
|
|
|
|
}
|
|
|
|
|
2014-10-09 09:02:41 +00:00
|
|
|
Terminal * relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true);
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|