2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 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
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#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
|
|
|
*/
|
|
|
|
class Terminal : public QGraphicsItem {
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2014-05-29 13:46:04 +00:00
|
|
|
Terminal(QPointF, Qet::Orientation, Element * = 0, Diagram * = 0);
|
|
|
|
Terminal(qreal, qreal, Qet::Orientation, Element * = 0, Diagram * = 0);
|
|
|
|
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = 0, Diagram * = 0);
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual ~Terminal();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
|
|
|
Terminal(const Terminal &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2007-10-21 16:10:21 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
|
|
|
Terminal
|
|
|
|
@return the QGraphicsItem type
|
2007-10-21 16:10:21 +00:00
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual int type() const { return Type; }
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// implementation of QGraphicsItem pure virtual methods
|
2007-04-09 02:56:47 +00:00
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods to manage conductors attached to the terminal
|
2007-10-03 17:02:39 +00:00
|
|
|
bool addConductor(Conductor *);
|
|
|
|
void removeConductor(Conductor *);
|
2010-04-18 20:48:15 +00:00
|
|
|
int conductorsCount() const;
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2010-04-18 20:48:15 +00:00
|
|
|
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
|
2007-04-09 02:56:47 +00:00
|
|
|
void hoverEnterEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void hoverLeaveEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
|
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:
|
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_);
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|