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.
|
|
|
|
|
|
|
|
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/>.
|
2007-12-01 10:47:15 +00:00
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
#ifndef CONDUCTOR_H
|
|
|
|
#define CONDUCTOR_H
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../autoNum/assignvariables.h"
|
|
|
|
#include "../conductorproperties.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
|
2015-08-09 12:06:31 +00:00
|
|
|
#include <QGraphicsPathItem>
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
class ConductorProfile;
|
|
|
|
class ConductorSegmentProfile;
|
|
|
|
class Diagram;
|
|
|
|
class Terminal;
|
2007-10-03 17:02:39 +00:00
|
|
|
class ConductorSegment;
|
2010-05-08 21:24:43 +00:00
|
|
|
class ConductorTextItem;
|
2007-04-12 03:13:13 +00:00
|
|
|
class Element;
|
2014-07-21 20:44:32 +00:00
|
|
|
class QETDiagramEditor;
|
2016-08-29 15:37:42 +00:00
|
|
|
class NumerotationContext;
|
2017-08-02 15:26:14 +00:00
|
|
|
class QetGraphicsHandlerItem;
|
|
|
|
|
2007-10-20 19:27:16 +00:00
|
|
|
typedef QPair<QPointF, Qt::Corner> ConductorBend;
|
2007-10-22 20:27:39 +00:00
|
|
|
typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
2007-04-12 03:13:13 +00:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
This class represents a conductor, i.e. a wire between two element
|
|
|
|
terminals.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
2021-03-11 19:52:50 +01:00
|
|
|
class Conductor : public QGraphicsObject
|
2015-08-09 12:06:31 +00:00
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
|
|
|
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
|
|
|
|
Q_PROPERTY(ConductorProperties properties READ properties WRITE setProperties)
|
|
|
|
Q_PROPERTY(autonum::sequentialNumbers sequenceNum READ sequenceNum WRITE setSequenceNum)
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void propertiesChange();
|
|
|
|
|
|
|
|
public:
|
|
|
|
Conductor(Terminal *, Terminal *);
|
|
|
|
~Conductor() override;
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Conductor(const Conductor &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1001 };
|
|
|
|
enum Highlight { None, Normal, Alert };
|
|
|
|
|
|
|
|
Terminal *terminal1;
|
|
|
|
Terminal *terminal2;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
@brief type
|
|
|
|
Enable the use of qgraphicsitem_cast
|
|
|
|
to safely cast a QGraphicsItem into a conductor.
|
|
|
|
@return the QGraphicsItem type
|
|
|
|
*/
|
|
|
|
int type() const override { return Type; }
|
|
|
|
Diagram *diagram() const;
|
|
|
|
ConductorTextItem *textItem() const;
|
|
|
|
void updatePath(const QRectF & = QRectF());
|
|
|
|
|
|
|
|
//This method do nothing, it's only made to be used with Q_PROPERTY
|
|
|
|
//It's used to anim the path when is change
|
|
|
|
void updatePathAnimate(const int = 1) {updatePath();}
|
|
|
|
int fakePath() {return 1;}
|
|
|
|
|
|
|
|
void paint(
|
|
|
|
QPainter *,
|
|
|
|
const QStyleOptionGraphicsItem *,
|
|
|
|
QWidget *) override;
|
|
|
|
QRectF boundingRect() const override;
|
|
|
|
QPainterPath shape() const override;
|
|
|
|
virtual QPainterPath nearShape() const;
|
|
|
|
qreal length() const;
|
|
|
|
ConductorSegment *middleSegment();
|
|
|
|
QPointF posForText(Qt::Orientations &flag);
|
|
|
|
void refreshText();
|
|
|
|
void setPath(const QPainterPath &path);
|
|
|
|
QPainterPath path() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool valideXml (QDomElement &);
|
2021-03-11 19:52:50 +01:00
|
|
|
bool fromXml (QDomElement &);
|
|
|
|
QDomElement toXml (
|
|
|
|
QDomDocument &,
|
|
|
|
QHash<Terminal *,
|
|
|
|
int> &) const;
|
2020-10-17 20:25:30 +02:00
|
|
|
private:
|
|
|
|
bool pathFromXml(const QDomElement &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
QVector <QPointF> handlerPoints() const;
|
|
|
|
const QList<ConductorSegment *> segmentsList() const;
|
|
|
|
|
|
|
|
void setPropertyToPotential(
|
|
|
|
const ConductorProperties &property,
|
|
|
|
bool only_text = false);
|
|
|
|
void setProperties(const ConductorProperties &property);
|
|
|
|
ConductorProperties properties() const;
|
|
|
|
|
|
|
|
void setProfile(const ConductorProfile &, Qt::Corner);
|
|
|
|
ConductorProfile profile(Qt::Corner) const;
|
|
|
|
void setProfiles(const ConductorProfilesGroup &);
|
|
|
|
ConductorProfilesGroup profiles() const;
|
|
|
|
void calculateTextItemPosition();
|
|
|
|
virtual Highlight highlight() const;
|
|
|
|
virtual void setHighlighted(Highlight);
|
|
|
|
QSet<Conductor *> relatedPotentialConductors(
|
|
|
|
const bool all_diagram = true,
|
|
|
|
QList <Terminal *> *t_list=nullptr);
|
|
|
|
QETDiagramEditor* diagramEditor() const;
|
|
|
|
void editProperty ();
|
|
|
|
|
|
|
|
autonum::sequentialNumbers sequenceNum () const
|
|
|
|
{return m_autoNum_seq;}
|
|
|
|
autonum::sequentialNumbers& rSequenceNum()
|
|
|
|
{return m_autoNum_seq;}
|
|
|
|
void setSequenceNum(const autonum::sequentialNumbers& sn);
|
|
|
|
|
2024-04-24 14:14:40 +02:00
|
|
|
QList<QPointF> junctions() const;
|
2020-10-17 20:25:30 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setUpConnectionForFormula(
|
|
|
|
QString old_formula, QString new_formula);
|
|
|
|
autonum::sequentialNumbers m_autoNum_seq;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setFreezeLabel(bool freeze);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void displayedTextChanged();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void mouseDoubleClickEvent(
|
|
|
|
QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(
|
|
|
|
QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
QVariant itemChange(
|
|
|
|
GraphicsItemChange, const QVariant &) override;
|
|
|
|
bool sceneEventFilter(
|
|
|
|
QGraphicsItem *watched, QEvent *event) override;
|
|
|
|
|
|
|
|
private:
|
2025-02-14 16:47:39 +01:00
|
|
|
void adjustHandlerPos();
|
2020-10-17 20:25:30 +02:00
|
|
|
|
|
|
|
void handlerMousePressEvent(
|
|
|
|
QetGraphicsHandlerItem *qghi,
|
|
|
|
QGraphicsSceneMouseEvent *event);
|
|
|
|
void handlerMouseMoveEvent(
|
|
|
|
QetGraphicsHandlerItem *qghi,
|
|
|
|
QGraphicsSceneMouseEvent *event);
|
|
|
|
void handlerMouseReleaseEvent(
|
|
|
|
QetGraphicsHandlerItem *qghi,
|
|
|
|
QGraphicsSceneMouseEvent *event);
|
|
|
|
void addHandler();
|
|
|
|
void removeHandler();
|
|
|
|
|
|
|
|
|
|
|
|
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
|
|
|
int m_vector_index = -1;
|
2021-03-11 19:52:50 +01:00
|
|
|
bool m_mouse_over;
|
2020-10-17 20:25:30 +02:00
|
|
|
/// Functional properties
|
|
|
|
ConductorProperties m_properties;
|
|
|
|
/// Text input for non simple, non-singleline conductors
|
2021-03-11 19:52:50 +01:00
|
|
|
ConductorTextItem *m_text_item;
|
2020-10-17 20:25:30 +02:00
|
|
|
/// Segments composing the conductor
|
2021-03-11 19:52:50 +01:00
|
|
|
ConductorSegment *segments;
|
2022-12-04 08:21:12 -05:00
|
|
|
/// Attributes related to mouse interaction
|
2021-03-11 19:52:50 +01:00
|
|
|
bool m_moving_segment;
|
2020-10-17 20:25:30 +02:00
|
|
|
int moved_point;
|
|
|
|
qreal m_previous_z_value;
|
|
|
|
ConductorSegment *m_moved_segment;
|
|
|
|
QPointF before_mov_text_pos_;
|
|
|
|
/// Whether the conductor was manually modified by users
|
2021-03-11 19:52:50 +01:00
|
|
|
bool modified_path;
|
2020-10-17 20:25:30 +02:00
|
|
|
/// Whether the current profile should be saved as soon as possible
|
2021-03-11 19:52:50 +01:00
|
|
|
bool has_to_save_profile;
|
2020-10-17 20:25:30 +02:00
|
|
|
/// conductor profile: "photography" of what the conductor is supposed to look
|
|
|
|
/// like - there is one profile per kind of traject
|
|
|
|
ConductorProfilesGroup conductor_profiles;
|
|
|
|
/// Define whether and how the conductor should be highlighted
|
2021-03-11 19:52:50 +01:00
|
|
|
Highlight must_highlight_;
|
2020-10-17 20:25:30 +02:00
|
|
|
bool m_valid;
|
|
|
|
bool m_freeze_label = false;
|
|
|
|
|
|
|
|
/// QPen et QBrush objects used to draw conductors
|
|
|
|
static QPen conductor_pen;
|
|
|
|
static QBrush conductor_brush;
|
|
|
|
static bool pen_and_brush_initialized;
|
|
|
|
QPainterPath m_path;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void segmentsToPath();
|
|
|
|
void saveProfile(bool = true);
|
|
|
|
void generateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
|
|
|
|
void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
|
|
|
|
uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
|
|
|
|
QList<QPointF> segmentsToPoints() const;
|
|
|
|
QList<ConductorBend> bends() const;
|
|
|
|
|
|
|
|
void pointsToSegments(const QList<QPointF>&);
|
|
|
|
Qt::Corner currentPathType() const;
|
|
|
|
void deleteSegments();
|
|
|
|
static int getCoeff(const qreal &, const qreal &);
|
|
|
|
static int getSign(const qreal &);
|
|
|
|
QHash<ConductorSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConductorSegmentProfile *> &, const qreal & = 0.01) const;
|
2024-04-24 14:14:40 +02:00
|
|
|
static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 10);
|
2020-10-17 20:25:30 +02:00
|
|
|
static Qt::Corner movementType(const QPointF &, const QPointF &);
|
|
|
|
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
|
2007-04-12 03:13:13 +00:00
|
|
|
};
|
2014-10-07 19:51:26 +00:00
|
|
|
|
2025-02-28 20:25:31 +01:00
|
|
|
Conductor * longestConductorInPotential (Conductor *conductor, bool all_diagram = false);
|
2014-10-07 19:51:26 +00:00
|
|
|
QList <Conductor *> relatedConductors (const Conductor *conductor);
|
|
|
|
|
|
|
|
|
|
|
|
//return true if @a is between or at @b and @c.
|
|
|
|
template <typename T>
|
|
|
|
bool isBetween (const T a, const T b, const T c) {
|
2020-10-17 20:25:30 +02:00
|
|
|
return (b <= c)? (a >= b && a <= c) : (a <= b && a >= c);
|
2014-10-07 19:51:26 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|