2007-12-01 10:47:15 +00:00
|
|
|
/*
|
|
|
|
Copyright 2006-2007 Xavier Guerrin
|
|
|
|
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
|
2007-04-12 03:13:13 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#include "terminal.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
#include "conductorprofile.h"
|
2007-10-14 14:44:33 +00:00
|
|
|
#include "conductorproperties.h"
|
2007-09-26 22:57:53 +00:00
|
|
|
#include "diagramtextitem.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
class ConductorSegment;
|
2007-04-12 03:13:13 +00:00
|
|
|
class Element;
|
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
|
|
|
/**
|
|
|
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
class Conductor : public QGraphicsPathItem {
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// constructeurs, destructeur
|
|
|
|
public:
|
2007-10-03 17:02:39 +00:00
|
|
|
Conductor(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0);
|
|
|
|
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
|
|
|
|
|
|
|
// attributs
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1001 };
|
2007-09-20 20:16:08 +00:00
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// premiere borne a laquelle le fil est rattache
|
2007-04-12 03:13:13 +00:00
|
|
|
Terminal *terminal1;
|
2007-10-10 17:50:26 +00:00
|
|
|
/// deuxieme borne a laquelle le fil est rattache
|
2007-04-12 03:13:13 +00:00
|
|
|
Terminal *terminal2;
|
|
|
|
|
|
|
|
// methodes
|
|
|
|
public:
|
|
|
|
virtual int type() const { return Type; }
|
|
|
|
void destroy();
|
2007-10-21 16:10:21 +00:00
|
|
|
/// @return true si ce conducteur est detruit
|
2007-04-12 03:13:13 +00:00
|
|
|
bool isDestroyed() const { return(destroyed); }
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &);
|
|
|
|
void update(const QRectF & = QRectF());
|
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
virtual QPainterPath shape() const;
|
|
|
|
qreal length();
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorSegment *middleSegment();
|
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();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
protected:
|
2007-09-26 22:57:53 +00:00
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-10-01 14:08:11 +00:00
|
|
|
private:
|
2007-10-14 14:44:33 +00:00
|
|
|
/// caracteristiques du conducteur
|
|
|
|
ConductorProperties properties_;
|
2007-10-01 14:08:11 +00:00
|
|
|
/// booleen indiquant si le fil est encore valide
|
|
|
|
bool destroyed;
|
|
|
|
/// champ de texte editable pour les conducteurs non unifilaires
|
|
|
|
DiagramTextItem *text_item;
|
2007-10-10 17:50:26 +00:00
|
|
|
/// segments composant le conducteur
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorSegment *segments;
|
2007-10-10 17:50:26 +00:00
|
|
|
/// attributs lies aux manipulations a la souris
|
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;
|
2007-10-01 14:08:11 +00:00
|
|
|
/// booleen indiquant si le conducteur a ete modifie manuellement par l'utilisateur
|
|
|
|
bool modified_path;
|
|
|
|
/// booleen indiquant s'il faut sauver le profil courant au plus tot
|
|
|
|
bool has_to_save_profile;
|
2007-10-22 20:27:39 +00:00
|
|
|
/// profil du conducteur : "photo" de ce a quoi le conducteur doit ressembler - il y a un profil par type de trajet
|
|
|
|
ConductorProfilesGroup conductor_profiles;
|
2007-10-01 14:08:11 +00:00
|
|
|
/// QPen et QBrush utilises pour dessiner les conducteurs
|
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;
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
|
|
|
void segmentsToPath();
|
2007-09-28 21:58:42 +00:00
|
|
|
void saveProfile(bool = true);
|
2007-10-03 17:02:39 +00:00
|
|
|
void priv_calculeConductor(const QPointF &, QET::Orientation, const QPointF &, QET::Orientation);
|
|
|
|
void priv_modifieConductor(const QPointF &, QET::Orientation, const QPointF &, QET::Orientation);
|
|
|
|
uint nbSegments(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;
|
2007-06-30 17:41:07 +00:00
|
|
|
static QPointF extendTerminal(const QPointF &, QET::Orientation, qreal = 12.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 &);
|
2007-04-12 03:13:13 +00:00
|
|
|
};
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|