2006-10-27 15:47:22 +00:00
|
|
|
#ifndef CONDUCTEUR_H
|
2007-04-12 03:13:13 +00:00
|
|
|
#define CONDUCTEUR_H
|
|
|
|
#include <QtGui>
|
|
|
|
#include "terminal.h"
|
2007-09-20 20:16:08 +00:00
|
|
|
#include "conducerprofile.h"
|
2007-04-12 03:13:13 +00:00
|
|
|
class ConducerSegment;
|
|
|
|
class Element;
|
|
|
|
/**
|
|
|
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
|
|
|
*/
|
|
|
|
class Conducer : public QGraphicsPathItem {
|
|
|
|
|
|
|
|
// constructeurs, destructeur
|
|
|
|
public:
|
|
|
|
Conducer(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0);
|
|
|
|
virtual ~Conducer();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Conducer(const Conducer &);
|
|
|
|
|
|
|
|
// attributs
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1001 };
|
2007-09-20 20:16:08 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
///Premiere borne a laquelle le fil est rattache
|
|
|
|
Terminal *terminal1;
|
|
|
|
///Deuxieme borne a laquelle le fil est rattache
|
|
|
|
Terminal *terminal2;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// booleen indiquant si le fil est encore valide
|
|
|
|
bool destroyed;
|
|
|
|
QGraphicsTextItem *text_item;
|
|
|
|
ConducerSegment *segments;
|
|
|
|
QPointF press_point;
|
|
|
|
bool moving_point;
|
|
|
|
bool moving_segment;
|
|
|
|
int moved_point;
|
|
|
|
qreal previous_z_value;
|
|
|
|
ConducerSegment *moved_segment;
|
|
|
|
bool modified_path;
|
2007-09-20 20:16:08 +00:00
|
|
|
bool has_to_save_profile;
|
|
|
|
ConducerProfile conducer_profile;
|
2007-04-12 03:13:13 +00:00
|
|
|
static QPen conducer_pen;
|
|
|
|
static QBrush conducer_brush;
|
|
|
|
static bool pen_and_brush_initialized;
|
|
|
|
|
|
|
|
// methodes
|
|
|
|
public:
|
|
|
|
virtual int type() const { return Type; }
|
|
|
|
void destroy();
|
|
|
|
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();
|
|
|
|
ConducerSegment *middleSegment();
|
|
|
|
static bool valideXml(QDomElement &);
|
|
|
|
bool fromXml(QDomElement &);
|
|
|
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
2007-09-20 20:16:08 +00:00
|
|
|
const QList<ConducerSegment *> segmentsList() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void segmentsToPath();
|
2007-09-20 20:16:08 +00:00
|
|
|
void saveProfile();
|
2007-06-30 17:41:07 +00:00
|
|
|
void priv_calculeConducer(const QPointF &, QET::Orientation, const QPointF &, QET::Orientation);
|
|
|
|
void priv_modifieConducer(const QPointF &, QET::Orientation, const QPointF &, QET::Orientation);
|
2007-09-20 20:16:08 +00:00
|
|
|
uint nbSegments(QET::ConducerSegmentType = QET::Both) const;
|
2007-04-12 03:13:13 +00:00
|
|
|
QList<QPointF> segmentsToPoints() const;
|
|
|
|
void pointsToSegments(QList<QPointF>);
|
|
|
|
bool hasClickedOn(QPointF, QPointF) const;
|
|
|
|
void calculateTextItemPosition();
|
2007-09-20 20:16:08 +00:00
|
|
|
static int getCoeff(const qreal &, const qreal &);
|
|
|
|
static int getSign(const qreal &);
|
|
|
|
QHash<ConducerSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConducerSegmentProfile *> &, const qreal & = 0.01) const;
|
2007-06-30 17:41:07 +00:00
|
|
|
static QPointF extendTerminal(const QPointF &, QET::Orientation, qreal = 12.0);
|
2007-09-20 20:16:08 +00:00
|
|
|
static qreal conducer_bound(qreal, qreal, qreal, qreal = 0.0);
|
|
|
|
static qreal conducer_bound(qreal, qreal, bool);
|
2007-04-12 03:13:13 +00:00
|
|
|
};
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|