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/>.
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
#ifndef CONDUCTOR_H
|
|
|
|
#define CONDUCTOR_H
|
2014-07-21 20:44:32 +00:00
|
|
|
|
2007-10-14 14:44:33 +00:00
|
|
|
#include "conductorproperties.h"
|
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;
|
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
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents a conductor, i.e. a wire between two element
|
|
|
|
terminals.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
2008-07-09 21:14:30 +00:00
|
|
|
class Conductor : public QObject, public QGraphicsPathItem {
|
|
|
|
|
|
|
|
Q_OBJECT
|
2014-07-09 16:50:30 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
|
|
|
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2010-04-18 17:59:54 +00:00
|
|
|
Conductor(Terminal *, Terminal *, Diagram * = 0);
|
2007-10-03 17:02:39 +00:00
|
|
|
virtual ~Conductor();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
private:
|
2007-10-03 17:02:39 +00:00
|
|
|
Conductor(const Conductor &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1001 };
|
2010-05-09 00:30:41 +00:00
|
|
|
enum Highlight { None, Normal, Alert };
|
2007-09-20 20:16:08 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// First terminal the wire is attached to
|
2007-04-12 03:13:13 +00:00
|
|
|
Terminal *terminal1;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Second terminal the wire is attached to
|
2007-04-12 03:13:13 +00:00
|
|
|
Terminal *terminal2;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
|
|
|
Conductor.
|
|
|
|
@return the QGraphicsItem type
|
2007-12-16 13:21:28 +00:00
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual int type() const { return Type; }
|
|
|
|
void destroy();
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return true if this conductor is destroyed
|
|
|
|
bool isDestroyed() const { return(destroyed_); }
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2010-05-08 21:24:43 +00:00
|
|
|
ConductorTextItem *textItem() const;
|
2010-05-04 20:36:55 +00:00
|
|
|
void updatePath(const QRectF & = QRectF());
|
2014-07-09 16:50:30 +00:00
|
|
|
|
|
|
|
//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;}
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
virtual QPainterPath shape() const;
|
2010-05-08 21:24:43 +00:00
|
|
|
virtual qreal nearDistance() const;
|
|
|
|
virtual QPainterPath nearShape() const;
|
|
|
|
virtual QPainterPath variableShape(const qreal &) const;
|
|
|
|
virtual bool isNearConductor(const QPointF &);
|
2007-04-12 03:13:13 +00:00
|
|
|
qreal length();
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorSegment *middleSegment();
|
2014-09-26 08:48:55 +00:00
|
|
|
QPointF posForText(Qt::Orientations &flag);
|
2007-10-20 19:27:16 +00:00
|
|
|
bool containsPoint(const QPointF &) const;
|
2007-10-03 13:11:47 +00:00
|
|
|
QString text() const;
|
|
|
|
void setText(const QString &);
|
2007-04-12 03:13:13 +00:00
|
|
|
static bool valideXml(QDomElement &);
|
|
|
|
bool fromXml(QDomElement &);
|
|
|
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
2007-10-03 17:02:39 +00:00
|
|
|
const QList<ConductorSegment *> segmentsList() const;
|
2007-10-14 14:44:33 +00:00
|
|
|
void setProperties(const ConductorProperties &);
|
|
|
|
ConductorProperties properties() const;
|
2007-10-22 20:27:39 +00:00
|
|
|
void setProfile(const ConductorProfile &, Qt::Corner);
|
|
|
|
ConductorProfile profile(Qt::Corner) const;
|
|
|
|
void setProfiles(const ConductorProfilesGroup &);
|
|
|
|
ConductorProfilesGroup profiles() const;
|
2007-10-14 14:44:33 +00:00
|
|
|
void readProperties();
|
2010-05-08 21:24:43 +00:00
|
|
|
void adjustTextItemPosition();
|
2010-05-09 00:30:41 +00:00
|
|
|
virtual Highlight highlight() const;
|
|
|
|
virtual void setHighlighted(Highlight);
|
2013-04-04 16:57:15 +00:00
|
|
|
void autoText();
|
|
|
|
QSet<Conductor *> relatedPotentialConductors(QList <Terminal *> *t_list=0);
|
|
|
|
QETDiagramEditor* diagramEditor() const;
|
2014-09-02 18:41:25 +00:00
|
|
|
void editProperty ();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2008-07-09 21:14:30 +00:00
|
|
|
public slots:
|
|
|
|
void displayedTextChanged();
|
2010-05-08 21:24:43 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
protected:
|
2014-09-02 18:41:25 +00:00
|
|
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
|
2007-09-26 22:57:53 +00:00
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
2009-12-13 22:28:03 +00:00
|
|
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
|
|
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
|
2007-09-26 22:57:53 +00:00
|
|
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
2009-12-13 22:28:03 +00:00
|
|
|
virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-10-01 14:08:11 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Functional properties
|
2007-10-14 14:44:33 +00:00
|
|
|
ConductorProperties properties_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether this conductor is still valid
|
|
|
|
bool destroyed_;
|
|
|
|
/// Text input for non simple, non-singleline conductors
|
2010-05-08 21:24:43 +00:00
|
|
|
ConductorTextItem *text_item;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Segments composing the conductor
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorSegment *segments;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Attributs related to mouse interaction
|
2007-10-01 14:08:11 +00:00
|
|
|
QPointF press_point;
|
|
|
|
bool moving_point;
|
|
|
|
bool moving_segment;
|
|
|
|
int moved_point;
|
|
|
|
qreal previous_z_value;
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorSegment *moved_segment;
|
2010-05-08 21:24:43 +00:00
|
|
|
QPointF before_mov_text_pos_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether the conductor was manually modified by users
|
2007-10-01 14:08:11 +00:00
|
|
|
bool modified_path;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether the current profile should be saved as soon as possible
|
2007-10-01 14:08:11 +00:00
|
|
|
bool has_to_save_profile;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// conductor profile: "photography" of what the conductor is supposed to look
|
|
|
|
/// like - there is one profile per kind of traject
|
2007-10-22 20:27:39 +00:00
|
|
|
ConductorProfilesGroup conductor_profiles;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// QPen et QBrush objects used to draw conductors
|
2007-10-03 17:02:39 +00:00
|
|
|
static QPen conductor_pen;
|
|
|
|
static QBrush conductor_brush;
|
2007-10-20 19:27:16 +00:00
|
|
|
static QBrush square_brush;
|
2007-10-01 14:08:11 +00:00
|
|
|
static bool pen_and_brush_initialized;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Scale factor to render square used to move segments
|
2010-01-03 19:51:02 +00:00
|
|
|
qreal segments_squares_scale_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Define whether and how the conductor should be highlighted
|
2010-05-09 00:30:41 +00:00
|
|
|
Highlight must_highlight_;
|
2007-10-01 14:08:11 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
|
|
|
void segmentsToPath();
|
2007-09-28 21:58:42 +00:00
|
|
|
void saveProfile(bool = true);
|
2014-05-29 13:46:04 +00:00
|
|
|
void generateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
|
|
|
|
void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
|
2012-11-09 21:09:24 +00:00
|
|
|
uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
|
2007-04-12 03:13:13 +00:00
|
|
|
QList<QPointF> segmentsToPoints() const;
|
2007-10-20 19:27:16 +00:00
|
|
|
QSet<Conductor *> relatedConductors() const;
|
|
|
|
QList<ConductorBend> bends() const;
|
|
|
|
QList<QPointF> junctions() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
void pointsToSegments(QList<QPointF>);
|
|
|
|
bool hasClickedOn(QPointF, QPointF) const;
|
|
|
|
void calculateTextItemPosition();
|
2007-10-22 20:27:39 +00:00
|
|
|
Qt::Corner currentPathType() const;
|
2007-11-04 17:37:10 +00:00
|
|
|
void deleteSegments();
|
2007-09-20 20:16:08 +00:00
|
|
|
static int getCoeff(const qreal &, const qreal &);
|
|
|
|
static int getSign(const qreal &);
|
2007-10-03 17:02:39 +00:00
|
|
|
QHash<ConductorSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConductorSegmentProfile *> &, const qreal & = 0.01) const;
|
2014-05-29 13:46:04 +00:00
|
|
|
static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0);
|
2007-10-03 17:02:39 +00:00
|
|
|
static qreal conductor_bound(qreal, qreal, qreal, qreal = 0.0);
|
|
|
|
static qreal conductor_bound(qreal, qreal, bool);
|
2007-10-22 20:27:39 +00:00
|
|
|
static Qt::Corner movementType(const QPointF &, const QPointF &);
|
2010-05-08 21:24:43 +00:00
|
|
|
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
|
2013-12-31 17:01:14 +00:00
|
|
|
Terminal * relatedPotentialTerminal (Terminal *);
|
2007-04-12 03:13:13 +00:00
|
|
|
};
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|