2006-10-27 15:47:22 +00:00
|
|
|
#ifndef CONDUCTEUR_H
|
|
|
|
#define CONDUCTEUR_H
|
|
|
|
#include <QtGui>
|
2007-01-29 20:14:26 +00:00
|
|
|
#include "terminal.h"
|
2007-02-14 01:08:29 +00:00
|
|
|
class ConducerSegment;
|
2006-10-27 15:47:22 +00:00
|
|
|
class Element;
|
|
|
|
/**
|
|
|
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
|
|
|
*/
|
2007-01-29 20:32:38 +00:00
|
|
|
class Conducer : public QGraphicsPathItem {
|
2006-10-27 15:47:22 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1001 };
|
|
|
|
virtual int type() const { return Type; }
|
2007-01-29 20:32:38 +00:00
|
|
|
Conducer(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0);
|
|
|
|
//virtual ~Conducer();
|
2006-10-27 15:47:22 +00:00
|
|
|
|
|
|
|
void destroy();
|
|
|
|
bool isDestroyed() const { return(destroyed); }
|
2007-01-29 20:14:26 +00:00
|
|
|
void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &);
|
2007-01-05 14:29:08 +00:00
|
|
|
void update(const QRectF & = QRectF());
|
2006-10-27 15:47:22 +00:00
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
2007-01-05 14:29:08 +00:00
|
|
|
QRectF boundingRect() const;
|
|
|
|
virtual QPainterPath shape() const;
|
2007-03-08 20:29:13 +00:00
|
|
|
qreal length();
|
|
|
|
ConducerSegment *middleSegment();
|
2006-10-27 15:47:22 +00:00
|
|
|
static bool valideXml(QDomElement &);
|
2007-02-18 19:33:15 +00:00
|
|
|
bool fromXml(QDomElement &);
|
2007-02-24 18:37:07 +00:00
|
|
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
2006-10-27 15:47:22 +00:00
|
|
|
|
|
|
|
///Premiere borne a laquelle le fil est rattache
|
2007-01-29 20:14:26 +00:00
|
|
|
Terminal *terminal1;
|
2006-10-27 15:47:22 +00:00
|
|
|
///Deuxieme borne a laquelle le fil est rattache
|
2007-01-29 20:14:26 +00:00
|
|
|
Terminal *terminal2;
|
2007-01-05 14:29:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
2007-02-15 20:00:20 +00:00
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
2007-01-05 14:29:08 +00:00
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
private:
|
|
|
|
/// booleen indiquant si le fil est encore valide
|
|
|
|
bool destroyed;
|
2007-03-08 20:29:13 +00:00
|
|
|
QGraphicsTextItem *text_item;
|
2007-02-14 01:08:29 +00:00
|
|
|
ConducerSegment *segments;
|
2007-01-05 14:29:08 +00:00
|
|
|
QList<qreal> moves_x;
|
|
|
|
QList<qreal> moves_y;
|
|
|
|
qreal orig_dist_2_terms_x;
|
|
|
|
qreal orig_dist_2_terms_y;
|
|
|
|
bool type_trajet_x;
|
|
|
|
QPointF press_point;
|
|
|
|
bool moving_point;
|
2007-02-14 01:08:29 +00:00
|
|
|
bool moving_segment;
|
2007-01-05 14:29:08 +00:00
|
|
|
int moved_point;
|
2007-02-15 20:00:20 +00:00
|
|
|
qreal previous_z_value;
|
2007-02-14 01:08:29 +00:00
|
|
|
ConducerSegment *moved_segment;
|
2007-01-05 14:29:08 +00:00
|
|
|
bool modified_path;
|
|
|
|
static QPen conducer_pen;
|
|
|
|
static QBrush conducer_brush;
|
|
|
|
static bool pen_and_brush_initialized;
|
2006-10-27 15:47:22 +00:00
|
|
|
|
2007-02-14 01:08:29 +00:00
|
|
|
void segmentsToPath();
|
2007-01-05 14:29:08 +00:00
|
|
|
void updatePoints();
|
2007-01-29 20:32:38 +00:00
|
|
|
void priv_calculeConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
|
|
|
void priv_modifieConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
2007-02-14 01:08:29 +00:00
|
|
|
int nbSegments();
|
|
|
|
|
|
|
|
QList<QPointF> segmentsToPoints() const;
|
|
|
|
void pointsToSegments(QList<QPointF>);
|
|
|
|
bool hasClickedOn(QPointF, QPointF);
|
2007-03-08 20:29:13 +00:00
|
|
|
void calculateTextItemPosition();
|
2007-01-29 20:14:26 +00:00
|
|
|
static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0);
|
|
|
|
static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation);
|
|
|
|
static bool estHorizontale(Terminal::Orientation a);
|
|
|
|
static bool estVerticale(Terminal::Orientation a);
|
2007-01-05 14:29:08 +00:00
|
|
|
static qreal conducer_bound(qreal tobound, qreal bound1, qreal bound2);
|
|
|
|
static qreal conducer_bound(qreal tobound, qreal bound, bool positive);
|
2006-10-27 15:47:22 +00:00
|
|
|
};
|
|
|
|
#endif
|