2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2025-01-04 13:37:40 +01:00
|
|
|
Copyright 2006-2025 The QElectroTech Team
|
2020-10-17 20:25:30 +02:00
|
|
|
This file is part of QElectroTech.
|
2020-10-03 15:48:40 +02:00
|
|
|
|
2020-10-17 20:25:30 +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-17 20:25:30 +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-17 20:25:30 +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
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "partterminal.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
2020-12-10 18:44:03 +01:00
|
|
|
#include "../../qetgraphicsitem/terminal.h"
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief PartTerminal::PartTerminal
|
|
|
|
@param editor :
|
|
|
|
L'editeur d'element concerne
|
|
|
|
@param parent :
|
|
|
|
Le QGraphicsItem parent de cette borne
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2015-02-09 08:57:40 +00:00
|
|
|
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
2020-10-17 20:25:30 +02:00
|
|
|
CustomElementGraphicPart(editor, parent)
|
2007-06-30 17:41:07 +00:00
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
d = new TerminalData(this);
|
|
|
|
d -> m_orientation = Qet::North;
|
|
|
|
d -> m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
|
|
|
updateSecondPoint();
|
|
|
|
setZValue(100000);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2020-09-07 22:03:40 +02:00
|
|
|
PartTerminal::~PartTerminal()
|
|
|
|
{
|
2010-02-18 00:42:41 +00:00
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Importe les proprietes d'une borne depuis un element XML
|
|
|
|
@param xml_elmt Element XML a lire
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2021-03-11 19:52:50 +01:00
|
|
|
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
|
|
|
d -> fromXml(xml_elmt);
|
2020-10-17 20:25:30 +02:00
|
|
|
setPos(d -> m_pos);
|
|
|
|
updateSecondPoint();
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Exporte la borne en XML
|
|
|
|
@param xml_document Document XML a utiliser pour creer l'element XML
|
|
|
|
@return un element XML decrivant la borne
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2021-03-11 19:52:50 +01:00
|
|
|
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const
|
|
|
|
{
|
|
|
|
return d -> toXml(xml_document);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Dessine la borne
|
|
|
|
@param painter QPainter a utiliser pour rendre le dessin
|
|
|
|
@param options Options pour affiner le rendu
|
|
|
|
@param widget Widget sur lequel le rendu est effectue
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2020-10-03 15:48:40 +02:00
|
|
|
void PartTerminal::paint(
|
2020-10-17 20:25:30 +02:00
|
|
|
QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *options,
|
|
|
|
QWidget *widget)
|
2020-10-03 15:48:40 +02:00
|
|
|
{
|
2021-02-12 19:28:07 +01:00
|
|
|
Q_UNUSED(widget)
|
2020-10-17 20:25:30 +02:00
|
|
|
painter -> save();
|
2020-08-13 11:39:07 +01:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// annulation des renderhints
|
2021-03-11 19:52:50 +01:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
|
|
|
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
2020-10-17 20:25:30 +02:00
|
|
|
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
2020-08-13 11:39:07 +01:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
QPen t;
|
|
|
|
t.setWidthF(1.0);
|
2020-10-03 15:48:40 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
|
|
|
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
2020-10-03 15:48:40 +02:00
|
|
|
#else
|
|
|
|
#if TODO_LIST
|
|
|
|
#pragma message("@TODO remove code for QT 6 or later")
|
|
|
|
#endif
|
2020-10-17 20:25:30 +02:00
|
|
|
t.setCosmetic(
|
|
|
|
options
|
|
|
|
&& options->levelOfDetailFromTransform(
|
|
|
|
painter->worldTransform())
|
|
|
|
< 1.0);
|
2020-10-03 15:48:40 +02:00
|
|
|
#endif
|
2020-10-17 20:25:30 +02:00
|
|
|
// dessin de la borne en rouge
|
|
|
|
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
|
|
|
painter -> setPen(t);
|
2021-02-06 18:35:55 +01:00
|
|
|
painter -> drawLine(QPointF(0.0, 0.0), d -> m_second_point);
|
2020-10-16 11:45:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// dessin du point d'amarrage au conducteur en bleu
|
|
|
|
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
|
|
|
painter -> setPen(t);
|
|
|
|
painter -> setBrush(Terminal::neutralColor);
|
|
|
|
painter -> drawPoint(QPointF(0.0, 0.0));
|
|
|
|
painter -> restore();
|
2020-10-16 11:45:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
if (m_hovered)
|
|
|
|
drawShadowShape(painter);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief PartTerminal::shape
|
|
|
|
@return the shape of this item
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPainterPath PartTerminal::shape() const
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
QPainterPath shape;
|
2021-02-06 18:35:55 +01:00
|
|
|
shape.lineTo(d -> m_second_point);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
QPainterPathStroker pps;
|
|
|
|
pps.setWidth(1);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
return (pps.createStroke(shape));
|
2015-02-09 08:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief PartTerminal::boundingRect
|
|
|
|
@return the bounding rect of this item
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF PartTerminal::boundingRect() const
|
|
|
|
{
|
2021-02-06 18:35:55 +01:00
|
|
|
QRectF br(QPointF(0, 0), d -> m_second_point);
|
2020-10-17 20:25:30 +02:00
|
|
|
br = br.normalized();
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
|
|
|
br.adjust(-adjust, -adjust, adjust, adjust);
|
|
|
|
return(br);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 20:38:39 +02:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Definit l'orientation de la borne
|
|
|
|
@param ori la nouvelle orientation de la borne
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2020-08-13 11:39:07 +01:00
|
|
|
void PartTerminal::setOrientation(Qet::Orientation ori) {
|
2020-10-17 20:25:30 +02:00
|
|
|
if (d -> m_orientation == ori) return;
|
|
|
|
prepareGeometryChange();
|
|
|
|
d -> m_orientation = ori;
|
|
|
|
updateSecondPoint();
|
|
|
|
emit orientationChanged();
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
2021-09-13 20:38:39 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-13 21:00:44 +02:00
|
|
|
Redefines setRotation to call setOrientation
|
|
|
|
@param angle
|
2021-09-13 20:38:39 +02:00
|
|
|
*/
|
|
|
|
void PartTerminal::setRotation(qreal angle) {
|
2021-09-13 21:00:44 +02:00
|
|
|
qreal angle_mod = std::fmod(angle,360);
|
|
|
|
Qet::Orientation new_ori = Qet::North;
|
2021-09-13 20:38:39 +02:00
|
|
|
|
2021-09-13 21:00:44 +02:00
|
|
|
if (0 <= angle_mod && angle_mod < 90 ) new_ori = Qet::North;
|
|
|
|
else if (90 <= angle_mod && angle_mod < 180) new_ori = Qet::East;
|
|
|
|
else if (180 <= angle_mod && angle_mod < 270) new_ori = Qet::South;
|
|
|
|
else new_ori = Qet::West;
|
2021-09-13 20:38:39 +02:00
|
|
|
|
2021-09-13 21:00:44 +02:00
|
|
|
setOrientation(new_ori);
|
2021-09-13 20:38:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal PartTerminal::rotation() const {
|
2021-09-13 21:00:44 +02:00
|
|
|
switch (d->m_orientation) {
|
|
|
|
case Qet::North : return 0;
|
|
|
|
case Qet::East : return 90;
|
|
|
|
case Qet::South : return 180;
|
|
|
|
case Qet::West : return 270;
|
|
|
|
}
|
2024-04-07 15:17:04 +02:00
|
|
|
return 0;
|
2021-09-13 20:38:39 +02:00
|
|
|
}
|
|
|
|
|
2020-08-02 12:07:22 +02:00
|
|
|
/**
|
2024-02-15 22:04:11 +01:00
|
|
|
@brief PartTerminal::setTerminalName
|
2020-10-17 20:25:30 +02:00
|
|
|
@param name
|
2020-08-02 12:07:22 +02:00
|
|
|
*/
|
2024-02-15 22:04:11 +01:00
|
|
|
void PartTerminal::setTerminalName(const QString& name) {
|
2020-10-17 20:25:30 +02:00
|
|
|
if (d -> m_name == name) return;
|
|
|
|
d -> m_name = name;
|
|
|
|
emit nameChanged();
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2021-02-12 19:28:07 +01:00
|
|
|
/**
|
|
|
|
* @brief PartTerminal::setTerminalType
|
|
|
|
* Set the type of terminal to 'type'
|
|
|
|
* @param type
|
|
|
|
*/
|
|
|
|
void PartTerminal::setTerminalType(TerminalData::Type type)
|
|
|
|
{
|
|
|
|
if (d->m_type == type) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->m_type = type;
|
|
|
|
emit terminalTypeChanged();
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void PartTerminal::setNewUuid()
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
d -> m_uuid = QUuid::createUuid();
|
2020-08-12 15:45:48 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Met a jour la position du second point en fonction de la position et de
|
|
|
|
l'orientation de la borne.
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void PartTerminal::updateSecondPoint()
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
qreal ts = 4.0; // terminal size
|
|
|
|
switch(d -> m_orientation) {
|
2021-02-06 18:35:55 +01:00
|
|
|
case Qet::North: d -> m_second_point = QPointF(0.0, ts); break;
|
|
|
|
case Qet::East : d -> m_second_point = QPointF(-ts, 0.0); break;
|
|
|
|
case Qet::South: d -> m_second_point = QPointF(0.0, -ts); break;
|
|
|
|
case Qet::West : d -> m_second_point = QPointF(ts, 0.0); break;
|
2020-10-17 20:25:30 +02:00
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
2007-12-15 21:57:00 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
|
|
|
conservee / enregistree.
|
|
|
|
Une borne est toujours pertinente ; cette fonction renvoie donc
|
|
|
|
toujours false
|
2007-12-15 21:57:00 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool PartTerminal::isUseless() const
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
return(false);
|
2007-12-15 21:57:00 +00:00
|
|
|
}
|
2013-02-08 22:05:12 +00:00
|
|
|
|
2013-02-11 18:35:13 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@return the minimum, margin-less rectangle this part can fit into, in scene
|
|
|
|
coordinates. It is different from boundingRect() because it is not supposed
|
|
|
|
to imply any margin, and it is different from shape because it is a regular
|
|
|
|
rectangle, not a complex shape.
|
2013-02-11 18:35:13 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF PartTerminal::sceneGeometricRect() const
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
return(sceneBoundingRect());
|
2013-02-11 18:35:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 22:05:12 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Start the user-induced transformation, provided this primitive is contained
|
|
|
|
within the \a initial_selection_rect bounding rectangle.
|
2013-02-08 22:05:12 +00:00
|
|
|
*/
|
|
|
|
void PartTerminal::startUserTransformation(const QRectF &initial_selection_rect) {
|
2020-10-17 20:25:30 +02:00
|
|
|
Q_UNUSED(initial_selection_rect)
|
2021-03-11 19:52:50 +01:00
|
|
|
saved_position_ = scenePos();
|
2013-02-08 22:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
2013-02-08 22:05:12 +00:00
|
|
|
*/
|
|
|
|
void PartTerminal::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) {
|
2020-10-17 20:25:30 +02:00
|
|
|
QPointF mapped_point = mapPoints(
|
2021-03-11 19:52:50 +01:00
|
|
|
initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_position_).first();
|
2020-10-17 20:25:30 +02:00
|
|
|
setPos(mapped_point);
|
2013-02-08 22:05:12 +00:00
|
|
|
}
|