2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00: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-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00: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-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../qetgraphicsitem/terminal.h"
|
2018-07-19 14:14:31 +00:00
|
|
|
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../conductorautonumerotation.h"
|
|
|
|
#include "../diagram.h"
|
|
|
|
#include "../diagramcommands.h"
|
|
|
|
#include "../qetgraphicsitem/conductor.h"
|
|
|
|
#include "../qetgraphicsitem/element.h"
|
2016-08-29 15:37:42 +00:00
|
|
|
#include "conductortextitem.h"
|
2020-05-25 22:17:17 +02:00
|
|
|
#include "terminaldata.h"
|
2006-10-27 15:47:22 +00:00
|
|
|
|
2020-12-08 19:57:35 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
QColor Terminal::neutralColor = QColor(Qt::blue);
|
|
|
|
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
|
|
|
QColor Terminal::warningColor = QColor("#ff8000");
|
|
|
|
QColor Terminal::forbiddenColor = QColor(Qt::red);
|
2007-10-10 22:35:32 +00:00
|
|
|
const qreal Terminal::terminalSize = 4.0;
|
2018-06-17 18:21:56 +00:00
|
|
|
const qreal Terminal::Z = 1000;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
2020-08-18 21:28:52 +02:00
|
|
|
@brief Terminal::init
|
2010-04-18 20:48:15 +00:00
|
|
|
Methode privee pour initialiser la borne.
|
2013-11-16 16:53:46 +00:00
|
|
|
@param number of terminal
|
|
|
|
@param name of terminal
|
2020-08-18 21:28:52 +02:00
|
|
|
@param hiddenName
|
2006-10-27 15:47:22 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::init(
|
|
|
|
QString number, QString name, bool hiddenName)
|
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
hovered_color_ = Terminal::neutralColor;
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// calcul de la position du point d'amarrage a l'element
|
2020-07-15 18:20:08 +02:00
|
|
|
dock_elmt_ = d->m_pos;
|
|
|
|
switch(d->m_orientation) {
|
2014-05-29 13:46:04 +00:00
|
|
|
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
|
|
|
|
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
|
|
|
|
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
|
|
|
|
case Qet::South:
|
2010-04-18 20:48:15 +00:00
|
|
|
default : dock_elmt_ += QPointF(0, -Terminal::terminalSize);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2013-11-12 18:43:59 +00:00
|
|
|
// Number of terminal
|
2018-07-19 14:14:31 +00:00
|
|
|
number_terminal_ = std::move(number);
|
2013-11-16 16:53:46 +00:00
|
|
|
// Name of terminal
|
2018-07-19 14:14:31 +00:00
|
|
|
name_terminal_ = std::move(name);
|
2013-11-16 16:53:46 +00:00
|
|
|
name_terminal_hidden = hiddenName;
|
2006-10-27 15:47:22 +00:00
|
|
|
// par defaut : pas de conducteur
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// QRectF null
|
2010-04-18 20:48:15 +00:00
|
|
|
br_ = new QRectF();
|
2017-08-05 02:06:59 +00:00
|
|
|
previous_terminal_ = nullptr;
|
2006-10-27 15:47:22 +00:00
|
|
|
// divers
|
2015-03-02 20:14:56 +00:00
|
|
|
setAcceptHoverEvents(true);
|
2006-10-27 15:47:22 +00:00
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
2010-04-18 20:48:15 +00:00
|
|
|
hovered_ = false;
|
2009-04-03 19:30:25 +00:00
|
|
|
setToolTip(QObject::tr("Borne", "tooltip"));
|
2018-06-17 18:21:56 +00:00
|
|
|
setZValue(Z);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 22:17:17 +02:00
|
|
|
/*!
|
2020-08-16 11:19:36 +02:00
|
|
|
\brief Terminal::init
|
|
|
|
Additionaly to the init above, this method stores position and orientation into the data class
|
|
|
|
\param pf
|
|
|
|
\param o
|
|
|
|
\param number
|
|
|
|
\param name
|
|
|
|
\param hiddenName
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::init(
|
|
|
|
QPointF pf,
|
|
|
|
Qet::Orientation o,
|
|
|
|
QString number,
|
|
|
|
QString name,
|
|
|
|
bool hiddenName)
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
// definition du pount d'amarrage pour un conducteur
|
|
|
|
d->m_pos = pf;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-07-15 18:20:08 +02:00
|
|
|
// definition de l'orientation de la borne (par defaut : sud)
|
|
|
|
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
|
|
|
|
else d->m_orientation = o;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-07-15 18:20:08 +02:00
|
|
|
init(number, name, hiddenName);
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
|
|
|
initialise une borne
|
|
|
|
@param pf position du point d'amarrage pour un conducteur
|
|
|
|
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
|
|
|
|
@param e Element auquel cette borne appartient
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
2015-09-10 08:48:33 +00:00
|
|
|
QGraphicsObject(e),
|
2020-07-15 18:20:08 +02:00
|
|
|
d(new TerminalData(this)),
|
|
|
|
parent_element_ (e)
|
2007-06-30 17:41:07 +00:00
|
|
|
{
|
2013-11-16 16:53:46 +00:00
|
|
|
init(pf, o, "_", "_", false);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
initialise une borne
|
|
|
|
@param pf_x Abscisse du point d'amarrage pour un conducteur
|
|
|
|
@param pf_y Ordonnee du point d'amarrage pour un conducteur
|
|
|
|
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
|
|
|
|
@param e Element auquel cette borne appartient
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
2015-09-10 08:48:33 +00:00
|
|
|
QGraphicsObject(e),
|
2020-07-15 18:20:08 +02:00
|
|
|
d(new TerminalData(this)),
|
|
|
|
parent_element_ (e)
|
2007-06-30 17:41:07 +00:00
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
init(QPointF(pf_x, pf_y), o, "_", "_", false);
|
2013-11-13 11:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
initialise une borne
|
|
|
|
@param pf position du point d'amarrage pour un conducteur
|
|
|
|
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
|
|
|
|
@param num number of terminal (ex 3 - 4 for NO)
|
2013-11-16 16:53:46 +00:00
|
|
|
@param name of terminal
|
|
|
|
@param hiddenName hide or show the name
|
2013-11-13 11:55:27 +00:00
|
|
|
@param e Element auquel cette borne appartient
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Terminal::Terminal(
|
|
|
|
QPointF pf,
|
|
|
|
Qet::Orientation o,
|
|
|
|
QString num,
|
|
|
|
QString name,
|
|
|
|
bool hiddenName,
|
|
|
|
Element *e) :
|
2015-09-10 08:48:33 +00:00
|
|
|
QGraphicsObject (e),
|
2020-07-15 18:20:08 +02:00
|
|
|
d(new TerminalData(this)),
|
|
|
|
parent_element_ (e)
|
2013-11-13 11:55:27 +00:00
|
|
|
{
|
2018-07-19 14:14:31 +00:00
|
|
|
init(pf, o, std::move(num), std::move(name), hiddenName);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 22:17:17 +02:00
|
|
|
Terminal::Terminal(TerminalData* data, Element* e) :
|
2020-07-15 18:20:08 +02:00
|
|
|
QGraphicsObject(e),
|
|
|
|
d(data),
|
|
|
|
parent_element_(e)
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-09-24 17:01:33 +02:00
|
|
|
#if TODO_LIST
|
|
|
|
#pragma message("@TODO what is when multiple parents exist. So the other relation is lost.")
|
|
|
|
#endif
|
2020-07-15 18:20:08 +02:00
|
|
|
// TODO: what is when multiple parents exist. So the other relation is lost.
|
|
|
|
d->setParent(this);
|
|
|
|
init("_", "_", false);
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
|
|
|
Destructeur
|
2007-04-12 03:13:13 +00:00
|
|
|
La destruction de la borne entraine la destruction des conducteurs
|
|
|
|
associes.
|
2006-10-27 15:47:22 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Terminal::~Terminal()
|
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(Conductor *c, conductors_) delete c;
|
2010-04-18 20:48:15 +00:00
|
|
|
delete br_;
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de connaitre l'orientation de la borne. Si le parent de la borne
|
|
|
|
est bien un Element, cette fonction renvoie l'orientation par rapport a
|
|
|
|
la scene de la borne, en tenant compte du fait que l'element ait pu etre
|
|
|
|
pivote. Sinon elle renvoie son sens normal.
|
2007-01-29 20:14:26 +00:00
|
|
|
@return L'orientation actuelle de la Terminal.
|
2006-10-27 15:47:22 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Qet::Orientation Terminal::orientation() const
|
|
|
|
{
|
2018-07-30 15:24:29 +00:00
|
|
|
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
2006-11-09 19:19:51 +00:00
|
|
|
// orientations actuelle et par defaut de l'element
|
2013-11-14 10:11:22 +00:00
|
|
|
int ori_cur = elt -> orientation();
|
2020-07-15 18:20:08 +02:00
|
|
|
if (ori_cur == 0) return(d->m_orientation);
|
2006-10-27 15:47:22 +00:00
|
|
|
else {
|
2007-01-20 18:11:42 +00:00
|
|
|
// calcul l'angle de rotation implique par l'orientation de l'element parent
|
2006-11-09 19:19:51 +00:00
|
|
|
// angle de rotation de la borne sur la scene, divise par 90
|
2020-07-15 18:20:08 +02:00
|
|
|
int angle = ori_cur + d->m_orientation;
|
2006-11-09 19:19:51 +00:00
|
|
|
while (angle >= 4) angle -= 4;
|
2014-05-29 13:46:04 +00:00
|
|
|
return((Qet::Orientation)angle);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2020-07-15 18:20:08 +02:00
|
|
|
} else return(d->m_orientation);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 11:55:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::setNumber
|
|
|
|
@param number
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::setNumber(QString number)
|
|
|
|
{
|
2018-07-19 14:14:31 +00:00
|
|
|
number_terminal_ = std::move(number);
|
2013-11-13 11:55:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 16:53:46 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::setName
|
2020-08-19 21:24:48 +02:00
|
|
|
@param name : QString
|
|
|
|
@param hiddenName : bool
|
2020-07-15 18:17:39 +02:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::setName(QString name, bool hiddenName)
|
|
|
|
{
|
2018-07-19 14:14:31 +00:00
|
|
|
name_terminal_ = std::move(name);
|
2013-11-16 16:53:46 +00:00
|
|
|
name_terminal_hidden = hiddenName;
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::addConductor
|
|
|
|
Add a conductor to this terminal
|
|
|
|
@param conductor : the conductor to add.
|
|
|
|
@return true if the conductor was successfully added
|
|
|
|
*/
|
2015-09-10 08:48:33 +00:00
|
|
|
bool Terminal::addConductor(Conductor *conductor)
|
|
|
|
{
|
|
|
|
if (!conductor) return(false);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
|
|
|
Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)),
|
|
|
|
"Terminal::addConductor",
|
|
|
|
"The conductor must be linked exactly once to this terminal");
|
|
|
|
|
|
|
|
//Get the other terminal where the conductor must be linked
|
|
|
|
Terminal *other_terminal = (conductor -> terminal1 == this)
|
|
|
|
? conductor->terminal2 : conductor->terminal1;
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
//Check if this terminal isn't already linked with other_terminal
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Conductor* cond, conductors_)
|
2015-09-10 08:48:33 +00:00
|
|
|
if (cond -> terminal1 == other_terminal || cond -> terminal2 == other_terminal)
|
|
|
|
return false; //They already a conductor linked to this and other_terminal
|
|
|
|
|
|
|
|
conductors_.append(conductor);
|
|
|
|
emit conductorWasAdded(conductor);
|
2006-10-27 15:47:22 +00:00
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::removeConductor
|
|
|
|
Remove a conductor from this terminal
|
|
|
|
@param conductor : conductor to remove
|
|
|
|
*/
|
2015-09-10 08:48:33 +00:00
|
|
|
void Terminal::removeConductor(Conductor *conductor)
|
|
|
|
{
|
|
|
|
int index = conductors_.indexOf(conductor);
|
2006-10-27 15:47:22 +00:00
|
|
|
if (index == -1) return;
|
2010-04-18 20:48:15 +00:00
|
|
|
conductors_.removeAt(index);
|
2015-09-10 08:48:33 +00:00
|
|
|
emit conductorWasRemoved(conductor);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::paint
|
2006-10-27 15:47:22 +00:00
|
|
|
Fonction de dessin des bornes
|
2020-10-03 15:48:40 +02:00
|
|
|
@param painter Le QPainter a utiliser
|
2006-10-27 15:47:22 +00:00
|
|
|
@param options Les options de dessin
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::paint(
|
2020-10-03 15:48:40 +02:00
|
|
|
QPainter *painter,
|
2020-09-07 22:03:40 +02:00
|
|
|
const QStyleOptionGraphicsItem *options,
|
|
|
|
QWidget *)
|
|
|
|
{
|
2009-04-05 11:48:26 +00:00
|
|
|
// en dessous d'un certain zoom, les bornes ne sont plus dessinees
|
2020-10-03 15:48:40 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
2009-04-05 11:48:26 +00:00
|
|
|
if (options && options -> levelOfDetail < 0.5) return;
|
2020-10-03 15:48:40 +02:00
|
|
|
#else
|
|
|
|
#if TODO_LIST
|
|
|
|
#pragma message("@TODO remove code for QT 6 or later")
|
|
|
|
#endif
|
|
|
|
if (options && options->levelOfDetailFromTransform(painter->worldTransform()) < 0.5)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
painter -> save();
|
2015-11-19 15:19:45 +00:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
//annulation des renderhints
|
2020-10-03 15:48:40 +02:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
|
|
|
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
|
|
|
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// on travaille avec les coordonnees de l'element parent
|
2020-07-15 18:20:08 +02:00
|
|
|
QPointF c = mapFromParent(d->m_pos);
|
2010-04-18 20:48:15 +00:00
|
|
|
QPointF e = mapFromParent(dock_elmt_);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
QPen t;
|
|
|
|
t.setWidthF(1.0);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2020-10-03 15:48:40 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
|
|
|
if (options && options -> levelOfDetail < 1.0)
|
|
|
|
#else
|
|
|
|
#if TODO_LIST
|
|
|
|
#pragma message("@TODO remove code for QT 6 or later")
|
|
|
|
#endif
|
|
|
|
if (options && options->levelOfDetailFromTransform(painter->worldTransform()) < 1.0)
|
|
|
|
#endif
|
|
|
|
{
|
2009-04-05 11:48:26 +00:00
|
|
|
t.setCosmetic(true);
|
|
|
|
}
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// dessin de la borne en rouge
|
|
|
|
t.setColor(Qt::red);
|
2020-10-03 15:48:40 +02:00
|
|
|
painter -> setPen(t);
|
|
|
|
painter -> drawLine(c, e);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// dessin du point d'amarrage au conducteur en bleu
|
2010-04-18 20:48:15 +00:00
|
|
|
t.setColor(hovered_color_);
|
2020-10-03 15:48:40 +02:00
|
|
|
painter -> setPen(t);
|
|
|
|
painter -> setBrush(hovered_color_);
|
2010-04-18 20:48:15 +00:00
|
|
|
if (hovered_) {
|
2020-10-03 15:48:40 +02:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
|
|
|
|
} else painter -> drawPoint(c);
|
2015-01-07 19:21:17 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
//Draw help line if needed,
|
2015-01-18 11:28:56 +00:00
|
|
|
if (diagram() && m_draw_help_line)
|
2015-01-07 19:21:17 +00:00
|
|
|
{
|
2020-09-07 22:03:40 +02:00
|
|
|
//Draw the help line with same orientation of terminal
|
|
|
|
//Only if there isn't docked conductor
|
2015-01-18 11:28:56 +00:00
|
|
|
if (conductors().isEmpty())
|
|
|
|
{
|
|
|
|
if (!m_help_line)
|
|
|
|
m_help_line = new QGraphicsLineItem(this);
|
2015-01-19 12:13:27 +00:00
|
|
|
QPen pen;
|
|
|
|
pen.setColor(Qt::darkBlue);
|
2015-01-07 19:21:17 +00:00
|
|
|
|
2015-01-18 11:28:56 +00:00
|
|
|
QLineF line(HelpLine());
|
2015-01-07 19:21:17 +00:00
|
|
|
|
2015-01-18 11:28:56 +00:00
|
|
|
if (diagram() -> project() -> autoConductor())
|
2015-01-11 11:10:57 +00:00
|
|
|
{
|
|
|
|
Terminal *t = alignedWithTerminal();
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
line.setP2(t -> dockConductor());
|
2015-01-18 11:28:56 +00:00
|
|
|
pen.setColor(Qt::darkGreen);
|
2015-01-11 11:10:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-18 11:28:56 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
//Map the line (in scene coordinate) to m_help_line coordinate
|
2015-01-18 11:28:56 +00:00
|
|
|
line.setP1(m_help_line -> mapFromScene(line.p1()));
|
|
|
|
line.setP2(m_help_line -> mapFromScene(line.p2()));
|
|
|
|
m_help_line -> setPen(pen);
|
|
|
|
m_help_line -> setLine(line);
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
//Draw the help line perpendicular to the terminal
|
2015-01-18 11:28:56 +00:00
|
|
|
if (!m_help_line_a)
|
|
|
|
{
|
|
|
|
m_help_line_a = new QGraphicsLineItem(this);
|
|
|
|
QPen pen;
|
2015-06-28 12:37:10 +00:00
|
|
|
pen.setColor(Diagram::background_color == Qt::darkGray ? Qt::lightGray : Qt::darkGray);
|
2015-01-18 11:28:56 +00:00
|
|
|
m_help_line_a -> setPen(pen);
|
2015-01-07 19:21:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 18:07:18 +00:00
|
|
|
QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
|
2015-01-18 11:28:56 +00:00
|
|
|
QLineF line;
|
|
|
|
|
|
|
|
if (Qet::isHorizontal(orientation()))
|
|
|
|
{
|
|
|
|
line.setP1(QPointF(dockConductor().x(), rect.topLeft().y()));
|
|
|
|
line.setP2(QPointF(dockConductor().x(), rect.bottomLeft().y()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line.setP1(QPointF(rect.topLeft().x(), dockConductor().y()));
|
|
|
|
line.setP2(QPointF(rect.topRight().x(), dockConductor().y()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Map the line (in scene coordinate) to m_help_line_a coordinate
|
|
|
|
line.setP1(m_help_line_a -> mapFromScene(line.p1()));
|
|
|
|
line.setP2(m_help_line_a -> mapFromScene(line.p2()));
|
|
|
|
m_help_line_a -> setLine(line);
|
2015-01-07 19:21:17 +00:00
|
|
|
}
|
2015-01-19 00:12:05 +00:00
|
|
|
|
2020-10-03 15:48:40 +02:00
|
|
|
painter -> restore();
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 19:21:17 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::drawHelpLine
|
|
|
|
@param draw : true, display the help line
|
|
|
|
false, hide it.
|
|
|
|
*/
|
2015-01-07 19:21:17 +00:00
|
|
|
void Terminal::drawHelpLine(bool draw)
|
|
|
|
{
|
|
|
|
if (m_draw_help_line == draw) return;
|
|
|
|
|
|
|
|
m_draw_help_line = draw;
|
|
|
|
|
2015-01-18 11:28:56 +00:00
|
|
|
if (!draw)
|
2015-01-07 19:21:17 +00:00
|
|
|
{
|
2015-01-18 11:28:56 +00:00
|
|
|
if (m_help_line)
|
|
|
|
{
|
|
|
|
delete m_help_line;
|
|
|
|
m_help_line = nullptr;
|
|
|
|
}
|
|
|
|
if (m_help_line_a)
|
|
|
|
{
|
|
|
|
delete m_help_line_a;
|
|
|
|
m_help_line_a = nullptr;
|
|
|
|
}
|
2015-01-07 19:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::HelpLine
|
|
|
|
@return a line with coordinate P1 the dock point of conductor
|
|
|
|
and P2 the border of diagram, according to the orientation of terminal
|
|
|
|
The line is in scene coordinate;
|
|
|
|
*/
|
2015-01-07 19:21:17 +00:00
|
|
|
QLineF Terminal::HelpLine() const
|
|
|
|
{
|
|
|
|
QPointF scene_dock = dockConductor();
|
2015-03-18 18:07:18 +00:00
|
|
|
QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
|
2015-01-07 19:21:17 +00:00
|
|
|
|
|
|
|
QLineF line(scene_dock , QPointF());
|
|
|
|
|
|
|
|
//Set te second point of line to the edge of diagram,
|
|
|
|
//according with the orientation of this terminal
|
|
|
|
switch (orientation())
|
|
|
|
{
|
|
|
|
case Qet::North:
|
|
|
|
line.setP2(QPointF(scene_dock.x(), rect.top()));
|
|
|
|
break;
|
|
|
|
case Qet::East:
|
|
|
|
line.setP2(QPointF(rect.right() , scene_dock.y()));
|
|
|
|
break;
|
|
|
|
case Qet::South:
|
|
|
|
line.setP2(QPointF(scene_dock.x(), rect.bottom()));
|
|
|
|
break;
|
|
|
|
case Qet::West:
|
|
|
|
line.setP2(QPointF(rect.left(), scene_dock.y()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::boundingRect
|
2006-10-27 15:47:22 +00:00
|
|
|
@return Le rectangle (en precision flottante) delimitant la borne et ses alentours.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF Terminal::boundingRect() const
|
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
if (br_ -> isNull())
|
|
|
|
{
|
|
|
|
qreal dcx = d->m_pos.x();
|
|
|
|
qreal dcy = d->m_pos.y();
|
2010-04-18 20:48:15 +00:00
|
|
|
qreal dex = dock_elmt_.x();
|
|
|
|
qreal dey = dock_elmt_.y();
|
2020-07-15 18:20:08 +02:00
|
|
|
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
|
2010-04-18 20:48:15 +00:00
|
|
|
origin += QPointF(-3.0, -3.0);
|
|
|
|
qreal w = qAbs((int)(dcx - dex)) + 7;
|
|
|
|
qreal h = qAbs((int)(dcy - dey)) + 7;
|
|
|
|
*br_ = QRectF(origin, QSizeF(w, h));
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2010-04-18 20:48:15 +00:00
|
|
|
return(*br_);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 19:21:17 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::alignedWithTerminal
|
|
|
|
If this terminal is aligned with an other terminal
|
|
|
|
and is orientation is opposed return the other terminal
|
|
|
|
else return nullptr
|
|
|
|
@return
|
|
|
|
*/
|
2015-01-07 19:21:17 +00:00
|
|
|
Terminal* Terminal::alignedWithTerminal() const
|
|
|
|
{
|
|
|
|
QLineF line(HelpLine());
|
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(line.p1());
|
|
|
|
path.lineTo(line.p2());
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Get all QGraphicsItem in the alignement of this terminal
|
2015-01-07 19:21:17 +00:00
|
|
|
QList <QGraphicsItem *> qgi_list = diagram() -> items(path);
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Remove all terminals of the parent element
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Terminal *t, parent_element_ -> terminals())
|
2015-01-07 19:21:17 +00:00
|
|
|
qgi_list.removeAll(t);
|
|
|
|
|
|
|
|
if (qgi_list.isEmpty()) return nullptr;
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Get terminals only if orientation is opposed with this terminal
|
2015-01-07 19:21:17 +00:00
|
|
|
QList <Terminal *> available_terminals;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QGraphicsItem *qgi, qgi_list)
|
2015-01-07 19:21:17 +00:00
|
|
|
{
|
2018-07-30 15:24:29 +00:00
|
|
|
if (Terminal *tt = qgraphicsitem_cast <Terminal *> (qgi))
|
2015-01-07 19:21:17 +00:00
|
|
|
{
|
2020-07-15 18:17:39 +02:00
|
|
|
//Call QET::lineContainsPoint to be sure the line intersect
|
|
|
|
//the dock point and not an other part of terminal
|
2015-01-07 19:21:17 +00:00
|
|
|
if (Qet::isOpposed(orientation(), tt -> orientation()) &&
|
|
|
|
QET::lineContainsPoint(line, tt -> dockConductor()))
|
|
|
|
{
|
|
|
|
available_terminals << tt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (available_terminals.isEmpty()) return nullptr;
|
|
|
|
if (available_terminals.size() == 1) return (available_terminals.first());
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Available_terminals have several terminals, we get the nearest terminal
|
2015-01-07 19:21:17 +00:00
|
|
|
line.setP2(available_terminals.first() -> dockConductor());
|
|
|
|
qreal current_lenght = line.length();
|
|
|
|
Terminal *nearest_terminal = available_terminals.takeFirst();
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Search the nearest terminal to this one
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Terminal *terminal, available_terminals)
|
2015-01-07 19:21:17 +00:00
|
|
|
{
|
|
|
|
line.setP2(terminal -> dockConductor());
|
|
|
|
if (line.length() < current_lenght)
|
|
|
|
{
|
|
|
|
current_lenght = line.length();
|
|
|
|
nearest_terminal = terminal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nearest_terminal;
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::hoverEnterEvent
|
2006-10-27 15:47:22 +00:00
|
|
|
Gere l'entree de la souris sur la zone de la Borne.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *)
|
|
|
|
{
|
2010-04-18 20:48:15 +00:00
|
|
|
hovered_ = true;
|
2006-10-27 15:47:22 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::hoverMoveEvent
|
2006-10-27 15:47:22 +00:00
|
|
|
Gere les mouvements de la souris sur la zone de la Borne.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::hoverMoveEvent(QGraphicsSceneHoverEvent *) {}
|
2006-10-27 15:47:22 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::hoverLeaveEvent
|
2006-10-27 15:47:22 +00:00
|
|
|
Gere le fait que la souris sorte de la zone de la Borne.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
|
|
|
|
{
|
2010-04-18 20:48:15 +00:00
|
|
|
hovered_ = false;
|
2006-10-27 15:47:22 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::mousePressEvent
|
2006-10-27 15:47:22 +00:00
|
|
|
Gere le fait qu'on enfonce un bouton de la souris sur la Borne.
|
|
|
|
@param e L'evenement souris correspondant
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
|
|
|
{
|
2020-07-15 18:17:39 +02:00
|
|
|
if (Diagram *diag = diagram()) {
|
|
|
|
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
|
|
|
|
diag -> setConductorStop(e -> scenePos());
|
|
|
|
diag -> setConductor(true);
|
2007-04-15 19:22:54 +00:00
|
|
|
//setCursor(Qt::CrossCursor);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::mouseMoveEvent
|
2006-10-27 15:47:22 +00:00
|
|
|
Gere le fait qu'on bouge la souris sur la Borne.
|
|
|
|
@param e L'evenement souris correspondant
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
|
|
|
{
|
2020-09-24 17:01:33 +02:00
|
|
|
// pendant la pose d'un conducteur, on adopte un autre curseur
|
2007-04-15 19:22:54 +00:00
|
|
|
//setCursor(Qt::CrossCursor);
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// d'un mouvement a l'autre, il faut retirer l'effet hover de la borne precedente
|
2010-04-18 20:48:15 +00:00
|
|
|
if (previous_terminal_) {
|
|
|
|
if (previous_terminal_ == this) hovered_ = true;
|
|
|
|
else previous_terminal_ -> hovered_ = false;
|
|
|
|
previous_terminal_ -> hovered_color_ = previous_terminal_ -> neutralColor;
|
|
|
|
previous_terminal_ -> update();
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2020-07-15 18:17:39 +02:00
|
|
|
|
|
|
|
Diagram *diag = diagram();
|
|
|
|
if (!diag) return;
|
2007-01-29 00:41:12 +00:00
|
|
|
// si la scene est un Diagram, on actualise le poseur de conducteur
|
2020-07-15 18:17:39 +02:00
|
|
|
diag -> setConductorStop(e -> scenePos());
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// on recupere la liste des qgi sous le pointeur
|
2020-07-15 18:17:39 +02:00
|
|
|
QList<QGraphicsItem *> qgis = diag -> items(e -> scenePos());
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/* le qgi le plus haut
|
2007-10-03 17:02:39 +00:00
|
|
|
= le poseur de conductor
|
2006-10-27 15:47:22 +00:00
|
|
|
= le premier element de la liste
|
|
|
|
= la liste ne peut etre vide
|
|
|
|
= on prend le deuxieme element de la liste
|
|
|
|
*/
|
2007-01-29 20:14:26 +00:00
|
|
|
Q_ASSERT_X(!(qgis.isEmpty()), "Terminal::mouseMoveEvent", "La liste d'items ne devrait pas etre vide");
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
// s'il n'y rien d'autre que le poseur de conducteur dans la liste, on arrete la
|
|
|
|
if (qgis.size() <= 1) return;
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
// sinon on prend le deuxieme element de la liste et on verifie s'il s'agit d'une borne
|
|
|
|
QGraphicsItem *qgi = qgis.at(1);
|
|
|
|
// si le qgi est une borne...
|
2018-07-30 15:24:29 +00:00
|
|
|
Terminal *other_terminal = qgraphicsitem_cast<Terminal *>(qgi);
|
2010-04-18 20:48:15 +00:00
|
|
|
if (!other_terminal) return;
|
|
|
|
previous_terminal_ = other_terminal;
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
// s'il s'agit d'une borne, on lui applique l'effet hover approprie
|
|
|
|
if (!canBeLinkedTo(other_terminal)) {
|
|
|
|
other_terminal -> hovered_color_ = forbiddenColor;
|
|
|
|
} else if (other_terminal -> conductorsCount()) {
|
|
|
|
other_terminal -> hovered_color_ = warningColor;
|
|
|
|
} else {
|
|
|
|
other_terminal -> hovered_color_ = allowedColor;
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2020-09-07 22:03:40 +02:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
other_terminal -> hovered_ = true;
|
|
|
|
other_terminal -> update();
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::mouseReleaseEvent
|
|
|
|
@param e
|
|
|
|
*/
|
2015-01-09 17:18:16 +00:00
|
|
|
void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
|
|
|
{
|
2017-08-05 02:06:59 +00:00
|
|
|
previous_terminal_ = nullptr;
|
2015-01-09 17:18:16 +00:00
|
|
|
hovered_color_ = neutralColor;
|
|
|
|
|
2015-08-17 17:01:39 +00:00
|
|
|
if (!diagram()) return;
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Stop conductor preview
|
2015-08-17 17:01:39 +00:00
|
|
|
diagram() -> setConductor(false);
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Get item under cursor
|
2015-08-17 17:01:39 +00:00
|
|
|
QGraphicsItem *qgi = diagram() -> itemAt(e -> scenePos(), QTransform());
|
|
|
|
if (!qgi) return;
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Element must be a terminal
|
2018-07-30 15:24:29 +00:00
|
|
|
Terminal *other_terminal = qgraphicsitem_cast<Terminal *>(qgi);
|
2015-08-17 17:01:39 +00:00
|
|
|
if (!other_terminal) return;
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2015-08-17 17:01:39 +00:00
|
|
|
other_terminal -> hovered_color_ = neutralColor;
|
|
|
|
other_terminal -> hovered_ = false;
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//We stop her if we can't link this terminal with other terminal
|
2015-08-17 17:01:39 +00:00
|
|
|
if (!canBeLinkedTo(other_terminal)) return;
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Create conductor
|
2018-07-30 15:24:29 +00:00
|
|
|
Conductor *new_conductor = new Conductor(this, other_terminal);
|
2015-08-17 17:01:39 +00:00
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Get all conductors at the same potential of new conductors
|
2015-08-17 17:01:39 +00:00
|
|
|
QSet <Conductor *> conductors_list = new_conductor->relatedPotentialConductors();
|
|
|
|
|
2020-07-15 18:17:39 +02:00
|
|
|
//Compare the properties of every conductors stored in conductors_list,
|
|
|
|
//if every conductors properties is equal, we use this properties for the new conductor.
|
2015-08-17 17:01:39 +00:00
|
|
|
ConductorProperties others_properties;
|
|
|
|
bool use_properties = false;
|
|
|
|
if (!conductors_list.isEmpty())
|
|
|
|
{
|
|
|
|
use_properties = true;
|
|
|
|
others_properties = (*conductors_list.begin())->properties();
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Conductor *conductor, conductors_list) {
|
2015-08-17 17:01:39 +00:00
|
|
|
if (conductor->properties() != others_properties)
|
|
|
|
use_properties = false;
|
2016-08-29 15:37:42 +00:00
|
|
|
}
|
2015-08-17 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QUndoCommand *undo = new QUndoCommand();
|
2016-12-07 18:56:31 +00:00
|
|
|
QUndoCommand *aic = new AddItemCommand<Conductor *>(new_conductor, diagram(), QPointF(), undo);
|
|
|
|
undo->setText(aic->text());
|
2015-08-17 17:01:39 +00:00
|
|
|
|
2016-12-06 19:49:18 +00:00
|
|
|
if (use_properties)
|
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
Conductor *other = conductors_list.values().first();
|
2016-12-08 15:06:46 +00:00
|
|
|
new_conductor->rSequenceNum() = other->sequenceNum();
|
2015-08-17 17:01:39 +00:00
|
|
|
new_conductor->setProperties(others_properties);
|
2016-08-29 15:37:42 +00:00
|
|
|
}
|
2015-08-17 17:01:39 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-29 15:37:42 +00:00
|
|
|
//Autonum it
|
2015-08-17 17:01:39 +00:00
|
|
|
ConductorAutoNumerotation can (new_conductor, diagram(), undo);
|
2015-01-09 17:18:16 +00:00
|
|
|
can.numerate();
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2016-08-29 15:37:42 +00:00
|
|
|
//Add undo command to the parent diagram
|
2015-08-17 17:01:39 +00:00
|
|
|
diagram() -> undoStack().push(undo);
|
2016-12-06 19:49:18 +00:00
|
|
|
if (use_properties)
|
|
|
|
{
|
2020-07-15 18:20:08 +02:00
|
|
|
Conductor *other = conductors_list.values().first();
|
2016-12-28 10:03:47 +00:00
|
|
|
new_conductor->setProperties(other->properties());
|
2016-08-29 15:37:42 +00:00
|
|
|
}
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::updateConductor
|
|
|
|
Update the path of conductor docked to this terminal
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void Terminal::updateConductor()
|
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Conductor *conductor, conductors_)
|
2015-09-15 08:20:39 +00:00
|
|
|
conductor->updatePath();
|
2010-04-18 20:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::isLinkedTo
|
2010-04-18 20:48:15 +00:00
|
|
|
@param other_terminal Autre borne
|
|
|
|
@return true si cette borne est reliee a other_terminal, false sion
|
|
|
|
*/
|
|
|
|
bool Terminal::isLinkedTo(Terminal *other_terminal) {
|
|
|
|
if (other_terminal == this) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
bool already_linked = false;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Conductor *c, conductors_) {
|
2010-04-18 20:48:15 +00:00
|
|
|
if (c -> terminal1 == other_terminal || c -> terminal2 == other_terminal) {
|
|
|
|
already_linked = true;
|
|
|
|
break;
|
2006-11-30 18:05:02 +00:00
|
|
|
}
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
2010-04-18 20:48:15 +00:00
|
|
|
return(already_linked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Terminal::canBeLinkedTo
|
|
|
|
Checking if the terminal can be linked to \p other_terminal or not
|
|
|
|
Reasons for not linable:
|
|
|
|
- \p other_terminal is this terminal
|
|
|
|
- this terminal is already connected to \p other_terminal
|
|
|
|
@param other_terminal
|
2020-08-18 21:28:52 +02:00
|
|
|
@return true if this terminal can be linked to other_terminal,
|
2020-07-15 18:17:39 +02:00
|
|
|
otherwise false
|
|
|
|
*/
|
2014-12-23 19:00:37 +00:00
|
|
|
bool Terminal::canBeLinkedTo(Terminal *other_terminal)
|
|
|
|
{
|
|
|
|
if (other_terminal == this || isLinkedTo(other_terminal))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::conductors
|
2006-10-27 15:47:22 +00:00
|
|
|
@return La liste des conducteurs lies a cette borne
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QList<Conductor *> Terminal::conductors() const
|
|
|
|
{
|
2010-04-18 20:48:15 +00:00
|
|
|
return(conductors_);
|
2006-10-27 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::toXml
|
2006-10-27 15:47:22 +00:00
|
|
|
Methode d'export en XML
|
|
|
|
@param doc Le Document XML a utiliser pour creer l'element XML
|
|
|
|
@return un QDomElement representant cette borne
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QDomElement Terminal::toXml(QDomDocument &doc) const
|
|
|
|
{
|
2007-03-09 19:18:55 +00:00
|
|
|
QDomElement qdo = doc.createElement("terminal");
|
2020-07-15 18:20:08 +02:00
|
|
|
|
|
|
|
// for backward compatibility
|
|
|
|
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
|
|
|
|
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
|
|
|
|
// end for backward compatibility
|
|
|
|
|
|
|
|
qdo.setAttribute("orientation", d->m_orientation);
|
2013-11-12 18:43:59 +00:00
|
|
|
qdo.setAttribute("number", number_terminal_);
|
2013-11-21 16:24:55 +00:00
|
|
|
qdo.setAttribute("name", name_terminal_);
|
|
|
|
qdo.setAttribute("nameHidden", name_terminal_hidden);
|
2006-10-27 15:47:22 +00:00
|
|
|
return(qdo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::valideXml
|
2006-10-27 15:47:22 +00:00
|
|
|
Permet de savoir si un element XML represente une borne
|
2007-10-21 16:10:21 +00:00
|
|
|
@param terminal Le QDomElement a analyser
|
2006-10-27 15:47:22 +00:00
|
|
|
@return true si le QDomElement passe en parametre est une borne, false sinon
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool Terminal::valideXml(QDomElement &terminal)
|
|
|
|
{
|
2006-10-27 15:47:22 +00:00
|
|
|
// verifie le nom du tag
|
2007-03-09 19:18:55 +00:00
|
|
|
if (terminal.tagName() != "terminal") return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// verifie la presence des attributs minimaux
|
2007-01-29 20:14:26 +00:00
|
|
|
if (!terminal.hasAttribute("x")) return(false);
|
|
|
|
if (!terminal.hasAttribute("y")) return(false);
|
|
|
|
if (!terminal.hasAttribute("orientation")) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
bool conv_ok;
|
|
|
|
// parse l'abscisse
|
2007-01-29 20:14:26 +00:00
|
|
|
terminal.attribute("x").toDouble(&conv_ok);
|
2006-10-27 15:47:22 +00:00
|
|
|
if (!conv_ok) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// parse l'ordonnee
|
2007-01-29 20:14:26 +00:00
|
|
|
terminal.attribute("y").toDouble(&conv_ok);
|
2006-10-27 15:47:22 +00:00
|
|
|
if (!conv_ok) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// parse l'id
|
2007-01-29 20:14:26 +00:00
|
|
|
terminal.attribute("id").toInt(&conv_ok);
|
2006-10-27 15:47:22 +00:00
|
|
|
if (!conv_ok) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// parse l'orientation
|
2007-01-29 20:14:26 +00:00
|
|
|
int terminal_or = terminal.attribute("orientation").toInt(&conv_ok);
|
2006-10-27 15:47:22 +00:00
|
|
|
if (!conv_ok) return(false);
|
2020-07-15 18:20:08 +02:00
|
|
|
if (terminal_or != Qet::North
|
|
|
|
&& terminal_or != Qet::South
|
|
|
|
&& terminal_or != Qet::East
|
|
|
|
&& terminal_or != Qet::West) return(false);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
// a ce stade, la borne est syntaxiquement correcte
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::fromXml
|
|
|
|
Permet de savoir si un element XML represente cette borne. Attention,
|
|
|
|
l'element XML n'est pas verifie
|
2007-10-21 16:10:21 +00:00
|
|
|
@param terminal Le QDomElement a analyser
|
2020-07-15 18:02:11 +02:00
|
|
|
@return true si la borne "se reconnait"
|
|
|
|
(memes coordonnes, meme orientation), false sinon
|
2006-10-27 15:47:22 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool Terminal::fromXml(QDomElement &terminal)
|
|
|
|
{
|
2013-11-21 16:24:55 +00:00
|
|
|
number_terminal_ = terminal.attribute("number");
|
|
|
|
name_terminal_ = terminal.attribute("name");
|
|
|
|
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
return (
|
2010-04-18 20:48:15 +00:00
|
|
|
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
|
|
|
|
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
|
2020-07-15 18:17:39 +02:00
|
|
|
(terminal.attribute("orientation").toInt() == d->m_orientation)
|
2006-10-27 15:47:22 +00:00
|
|
|
);
|
|
|
|
}
|
2007-09-25 23:24:36 +00:00
|
|
|
|
2020-05-25 22:17:17 +02:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::dockConductor
|
|
|
|
@return the position, relative to the scene, of the docking point for
|
|
|
|
conductors.
|
2020-05-25 22:17:17 +02:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF Terminal::dockConductor() const
|
|
|
|
{
|
2020-07-15 18:17:39 +02:00
|
|
|
return(mapToScene(d->m_pos));
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::diagram
|
|
|
|
@return le Diagram auquel cette borne appartient,
|
|
|
|
ou 0 si cette borne est independant
|
2010-04-18 20:48:15 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Diagram *Terminal::diagram() const
|
|
|
|
{
|
2007-09-25 23:24:36 +00:00
|
|
|
return(qobject_cast<Diagram *>(scene()));
|
|
|
|
}
|
2010-04-18 20:48:15 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief Terminal::parentElement
|
2010-04-18 20:48:15 +00:00
|
|
|
@return L'element auquel cette borne est rattachee
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Element *Terminal::parentElement() const
|
|
|
|
{
|
2010-04-18 20:48:15 +00:00
|
|
|
return(parent_element_);
|
|
|
|
}
|
2013-11-13 11:55:27 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
QUuid Terminal::uuid() const
|
|
|
|
{
|
2020-07-15 18:17:39 +02:00
|
|
|
return d->m_uuid;
|
2020-05-26 18:47:24 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 09:02:41 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief Conductor::relatedPotentialTerminal
|
|
|
|
Return terminal at the same potential from the same
|
2020-08-18 21:28:52 +02:00
|
|
|
parent element of terminal.
|
2020-07-15 18:17:39 +02:00
|
|
|
For folio report, return the terminal of linked other report.
|
|
|
|
For Terminal element, return the other terminal of terminal element.
|
2020-08-08 23:58:17 +02:00
|
|
|
@param terminal : to start search
|
2020-07-15 18:17:39 +02:00
|
|
|
@param all_diagram :if true return all related terminal,
|
2020-08-18 21:28:52 +02:00
|
|
|
false return only terminal in the same diagram of t
|
2020-07-15 18:17:39 +02:00
|
|
|
@return the list of terminal at the same potential
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QList<Terminal *> relatedPotentialTerminal (
|
|
|
|
const Terminal *terminal, const bool all_diagram)
|
2018-04-07 13:25:05 +00:00
|
|
|
{
|
2020-09-07 22:03:40 +02:00
|
|
|
// If terminal parent element is a folio report.
|
2018-04-07 13:25:05 +00:00
|
|
|
if (all_diagram && terminal -> parentElement() -> linkType() & Element::AllReport)
|
|
|
|
{
|
2014-10-09 09:02:41 +00:00
|
|
|
QList <Element *> elmt_list = terminal -> parentElement() -> linkedElements();
|
2018-04-07 13:25:05 +00:00
|
|
|
if (!elmt_list.isEmpty())
|
|
|
|
{
|
|
|
|
return (elmt_list.first()->terminals());
|
2014-10-09 09:02:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-07 22:03:40 +02:00
|
|
|
// If terminal parent element is a Terminal element.
|
2018-04-07 13:25:05 +00:00
|
|
|
else if (terminal -> parentElement() -> linkType() & Element::Terminale)
|
|
|
|
{
|
|
|
|
QList <Terminal *> terminals = terminal->parentElement()->terminals();
|
|
|
|
terminals.removeAll(const_cast<Terminal *>(terminal));
|
|
|
|
return terminals;
|
2014-10-09 09:02:41 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:25:05 +00:00
|
|
|
return QList<Terminal *>();
|
2014-10-09 09:02:41 +00:00
|
|
|
}
|
|
|
|
|