mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Classe "Conducteur" renommee en "Conducer"
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@46 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include <QtDebug>
|
||||
#include "conducteur.h"
|
||||
#include "conducer.h"
|
||||
#include "element.h"
|
||||
|
||||
bool Conducteur::pen_and_brush_initialized = false;
|
||||
QPen Conducteur::conducer_pen = QPen();
|
||||
QBrush Conducteur::conducer_brush = QBrush();
|
||||
bool Conducer::pen_and_brush_initialized = false;
|
||||
QPen Conducer::conducer_pen = QPen();
|
||||
QBrush Conducer::conducer_brush = QBrush();
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -13,13 +13,13 @@ QBrush Conducteur::conducer_brush = QBrush();
|
||||
@param parent Element parent du conducteur (0 par defaut)
|
||||
@param scene QGraphicsScene auquelle appartient le conducteur
|
||||
*/
|
||||
Conducteur::Conducteur(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) : QGraphicsPathItem(parent, scene) {
|
||||
Conducer::Conducer(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) : QGraphicsPathItem(parent, scene) {
|
||||
// bornes que le conducteur relie
|
||||
terminal1 = p1;
|
||||
terminal2 = p2;
|
||||
// ajout du conducteur a la liste de conducteurs de chacune des deux bornes
|
||||
bool ajout_p1 = terminal1 -> addConducteur(this);
|
||||
bool ajout_p2 = terminal2 -> addConducteur(this);
|
||||
bool ajout_p1 = terminal1 -> addConducer(this);
|
||||
bool ajout_p2 = terminal2 -> addConducer(this);
|
||||
// en cas d'echec de l'ajout (conducteur deja existant notamment)
|
||||
if (!ajout_p1 || !ajout_p2) return;
|
||||
destroyed = false;
|
||||
@@ -36,7 +36,7 @@ Conducteur::Conducteur(Terminal *p1, Terminal* p2, Element *parent, QGraphicsSce
|
||||
pen_and_brush_initialized = true;
|
||||
}
|
||||
// calcul du rendu du conducteur
|
||||
priv_calculeConducteur(terminal1 -> amarrageConducteur(), terminal1 -> orientation(), terminal2 -> amarrageConducteur(), terminal2 -> orientation());
|
||||
priv_calculeConducer(terminal1 -> amarrageConducer(), terminal1 -> orientation(), terminal2 -> amarrageConducer(), terminal2 -> orientation());
|
||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ Conducteur::Conducteur(Terminal *p1, Terminal* p2, Element *parent, QGraphicsSce
|
||||
Met a jour la representation graphique du conducteur.
|
||||
@param rect Rectangle a mettre a jour
|
||||
*/
|
||||
void Conducteur::update(const QRectF &rect) {
|
||||
void Conducer::update(const QRectF &rect) {
|
||||
// utilise soit la fonction priv_modifieConducteur soit la fonction priv_calculeConducteur
|
||||
void (Conducteur::* fonction_update) (const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
fonction_update = (points.count() && modified_path) ? &Conducteur::priv_modifieConducteur : &Conducteur::priv_calculeConducteur;
|
||||
void (Conducer::* fonction_update) (const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
fonction_update = (points.count() && modified_path) ? &Conducer::priv_modifieConducer : &Conducer::priv_calculeConducer;
|
||||
|
||||
// appelle la bonne fonction pour calculer l'aspect du conducteur
|
||||
(this ->* fonction_update)(
|
||||
terminal1 -> amarrageConducteur(), terminal1 -> orientation(),
|
||||
terminal2 -> amarrageConducteur(), terminal2 -> orientation()
|
||||
terminal1 -> amarrageConducer(), terminal1 -> orientation(),
|
||||
terminal2 -> amarrageConducer(), terminal2 -> orientation()
|
||||
);
|
||||
QGraphicsPathItem::update(rect);
|
||||
}
|
||||
@@ -64,29 +64,29 @@ void Conducteur::update(const QRectF &rect) {
|
||||
@param b Borne
|
||||
@param pos position de la borne b
|
||||
*/
|
||||
void Conducteur::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPointF &newpos) {
|
||||
void Conducer::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPointF &newpos) {
|
||||
QPointF p1, p2;
|
||||
if (b == terminal1) {
|
||||
p1 = newpos;
|
||||
p2 = terminal2 -> amarrageConducteur();
|
||||
p2 = terminal2 -> amarrageConducer();
|
||||
} else if (b == terminal2) {
|
||||
p1 = terminal1 -> amarrageConducteur();
|
||||
p1 = terminal1 -> amarrageConducer();
|
||||
p2 = newpos;
|
||||
} else {
|
||||
p1 = terminal1 -> amarrageConducteur();
|
||||
p2 = terminal2 -> amarrageConducteur();
|
||||
p1 = terminal1 -> amarrageConducer();
|
||||
p2 = terminal2 -> amarrageConducer();
|
||||
}
|
||||
if (points.count() && modified_path)
|
||||
priv_modifieConducteur(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||
priv_modifieConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||
else
|
||||
priv_calculeConducteur(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||
priv_calculeConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||
QGraphicsPathItem::update(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
Genere le QPainterPath a partir de la liste des points
|
||||
*/
|
||||
void Conducteur::pointsToPath() {
|
||||
void Conducer::pointsToPath() {
|
||||
QPainterPath path;
|
||||
bool moveto_done = false;
|
||||
foreach(QPointF point, points) {
|
||||
@@ -105,12 +105,12 @@ void Conducteur::pointsToPath() {
|
||||
@param p2 Coordonnees du point d'amarrage de la borne 2
|
||||
@param o2 Orientation de la borne 2
|
||||
*/
|
||||
void Conducteur::priv_modifieConducteur(const QPointF &p1, Terminal::Orientation, const QPointF &p2, Terminal::Orientation) {
|
||||
Q_ASSERT_X(points.count() > 1, "priv_modifieConducteur", "pas de points a modifier");
|
||||
void Conducer::priv_modifieConducer(const QPointF &p1, Terminal::Orientation, const QPointF &p2, Terminal::Orientation) {
|
||||
Q_ASSERT_X(points.count() > 1, "priv_modifieConducer", "pas de points a modifier");
|
||||
|
||||
// recupere les dernieres coordonnees connues des bornes
|
||||
QPointF old_p1 = mapFromScene(terminal1 -> amarrageConducteur());
|
||||
QPointF old_p2 = mapFromScene(terminal2 -> amarrageConducteur());
|
||||
QPointF old_p1 = mapFromScene(terminal1 -> amarrageConducer());
|
||||
QPointF old_p2 = mapFromScene(terminal2 -> amarrageConducer());
|
||||
|
||||
// recupere les coordonnees fournies des bornes
|
||||
QPointF new_p1 = mapFromScene(p1);
|
||||
@@ -151,7 +151,7 @@ void Conducteur::priv_modifieConducteur(const QPointF &p1, Terminal::Orientation
|
||||
@param p2 Coordonnees du point d'amarrage de la borne 2
|
||||
@param o2 Orientation de la borne 2
|
||||
*/
|
||||
void Conducteur::priv_calculeConducteur(const QPointF &p1, Terminal::Orientation o1, const QPointF &p2, Terminal::Orientation o2) {
|
||||
void Conducer::priv_calculeConducer(const QPointF &p1, Terminal::Orientation o1, const QPointF &p2, Terminal::Orientation o2) {
|
||||
QPointF sp1, sp2, depart, newp1, newp2, arrivee, depart0, arrivee0;
|
||||
Terminal::Orientation ori_depart, ori_arrivee;
|
||||
points.clear();
|
||||
@@ -240,7 +240,7 @@ void Conducteur::priv_calculeConducteur(const QPointF &p1, Terminal::Orientation
|
||||
@param ext_size la taille de la prolongation
|
||||
@return le point correspondant a la borne apres prolongation
|
||||
*/
|
||||
QPointF Conducteur::extendTerminal(const QPointF &terminal, Terminal::Orientation terminal_orientation, qreal ext_size) {
|
||||
QPointF Conducer::extendTerminal(const QPointF &terminal, Terminal::Orientation terminal_orientation, qreal ext_size) {
|
||||
QPointF extended_terminal;
|
||||
switch(terminal_orientation) {
|
||||
case Terminal::Nord:
|
||||
@@ -266,7 +266,7 @@ QPointF Conducteur::extendTerminal(const QPointF &terminal, Terminal::Orientatio
|
||||
@param qsogi Les options de style pour le conducteur
|
||||
@param qw Le QWidget sur lequel on dessine
|
||||
*/
|
||||
void Conducteur::paint(QPainter *qp, const QStyleOptionGraphicsItem */*qsogi*/, QWidget */*qw*/) {
|
||||
void Conducer::paint(QPainter *qp, const QStyleOptionGraphicsItem */*qsogi*/, QWidget */*qw*/) {
|
||||
qp -> save();
|
||||
qp -> setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
@@ -300,7 +300,7 @@ void Conducteur::paint(QPainter *qp, const QStyleOptionGraphicsItem */*qsogi*/,
|
||||
@param b La seconde orientation de Borne
|
||||
@return Un booleen a true si les deux orientations de bornes sont sur le meme axe
|
||||
*/
|
||||
bool Conducteur::surLeMemeAxe(Terminal::Orientation a, Terminal::Orientation b) {
|
||||
bool Conducer::surLeMemeAxe(Terminal::Orientation a, Terminal::Orientation b) {
|
||||
if ((a == Terminal::Nord || a == Terminal::Sud) && (b == Terminal::Nord || b == Terminal::Sud)) return(true);
|
||||
else if ((a == Terminal::Est || a == Terminal::Ouest) && (b == Terminal::Est || b == Terminal::Ouest)) return(true);
|
||||
else return(false);
|
||||
@@ -311,7 +311,7 @@ bool Conducteur::surLeMemeAxe(Terminal::Orientation a, Terminal::Orientation b)
|
||||
@param a L'orientation de borne
|
||||
@return True si l'orientation de borne est horizontale, false sinon
|
||||
*/
|
||||
bool Conducteur::estHorizontale(Terminal::Orientation a) {
|
||||
bool Conducer::estHorizontale(Terminal::Orientation a) {
|
||||
return(a == Terminal::Est || a == Terminal::Ouest);
|
||||
}
|
||||
|
||||
@@ -320,17 +320,17 @@ bool Conducteur::estHorizontale(Terminal::Orientation a) {
|
||||
@param a L'orientation de borne
|
||||
@return True si l'orientation de borne est verticale, false sinon
|
||||
*/
|
||||
bool Conducteur::estVerticale(Terminal::Orientation a) {
|
||||
bool Conducer::estVerticale(Terminal::Orientation a) {
|
||||
return(a == Terminal::Nord || a == Terminal::Sud);
|
||||
}
|
||||
|
||||
/**
|
||||
Methode de preparation a la destruction du conducteur ; le conducteur se detache de ses deux bornes
|
||||
*/
|
||||
void Conducteur::destroy() {
|
||||
void Conducer::destroy() {
|
||||
destroyed = true;
|
||||
terminal1 -> removeConducteur(this);
|
||||
terminal2 -> removeConducteur(this);
|
||||
terminal1 -> removeConducer(this);
|
||||
terminal2 -> removeConducer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +338,7 @@ void Conducteur::destroy() {
|
||||
@param e Un element XML sense represente un Conducteur
|
||||
@return true si l'element XML represente bien un Conducteur ; false sinon
|
||||
*/
|
||||
bool Conducteur::valideXml(QDomElement &e){
|
||||
bool Conducer::valideXml(QDomElement &e){
|
||||
// verifie le nom du tag
|
||||
if (e.tagName() != "conducteur") return(false);
|
||||
|
||||
@@ -361,7 +361,7 @@ bool Conducteur::valideXml(QDomElement &e){
|
||||
Gere les clics sur le conducteur.
|
||||
@param e L'evenement decrivant le clic.
|
||||
*/
|
||||
void Conducteur::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Conducer::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// clic gauche
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
press_point = mapFromScene(e -> pos());
|
||||
@@ -395,7 +395,7 @@ void Conducteur::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
-mettre le flag "trajet modifie" a true
|
||||
-gerer les contraintes
|
||||
*/
|
||||
void Conducteur::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Conducer::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// clic gauche
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
if (moving_point) {
|
||||
@@ -504,7 +504,7 @@ void Conducteur::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
Gere les relachements de boutons de souris sur le conducteur
|
||||
@param e L'evenement decrivant le lacher de bouton.
|
||||
*/
|
||||
void Conducteur::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Conducer::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// clic gauche
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
moving_point = false;
|
||||
@@ -515,7 +515,7 @@ void Conducteur::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
/**
|
||||
@return Le rectangle delimitant l'espace de dessin du conducteur
|
||||
*/
|
||||
QRectF Conducteur::boundingRect() const {
|
||||
QRectF Conducer::boundingRect() const {
|
||||
QRectF retour = QGraphicsPathItem::boundingRect();
|
||||
retour.adjust(-5.0, -5.0, 5.0, 5.0);
|
||||
return(retour);
|
||||
@@ -524,7 +524,7 @@ QRectF Conducteur::boundingRect() const {
|
||||
/**
|
||||
@return La forme / zone "cliquable" du conducteur
|
||||
*/
|
||||
QPainterPath Conducteur::shape() const {
|
||||
QPainterPath Conducer::shape() const {
|
||||
QPainterPath area;
|
||||
QPointF previous_point;
|
||||
QPointF *point1, *point2;
|
||||
@@ -564,7 +564,7 @@ QPainterPath Conducteur::shape() const {
|
||||
/**
|
||||
Met à jour deux listes de reels.
|
||||
*/
|
||||
void Conducteur::updatePoints() {
|
||||
void Conducer::updatePoints() {
|
||||
int s = points.size();
|
||||
moves_x.clear();
|
||||
moves_y.clear();
|
||||
@@ -578,7 +578,7 @@ void Conducteur::updatePoints() {
|
||||
orig_dist_2_terms_y = b2.y() - b1.y();
|
||||
}
|
||||
|
||||
qreal Conducteur::conducer_bound(qreal tobound, qreal bound1, qreal bound2) {
|
||||
qreal Conducer::conducer_bound(qreal tobound, qreal bound1, qreal bound2) {
|
||||
qreal space = 5.0;
|
||||
if (bound1 < bound2) {
|
||||
return(qBound(bound1 + space, tobound, bound2 - space));
|
||||
@@ -587,7 +587,7 @@ qreal Conducteur::conducer_bound(qreal tobound, qreal bound1, qreal bound2) {
|
||||
}
|
||||
}
|
||||
|
||||
qreal Conducteur::conducer_bound(qreal tobound, qreal bound, bool positive) {
|
||||
qreal Conducer::conducer_bound(qreal tobound, qreal bound, bool positive) {
|
||||
qreal space = 5.0;
|
||||
return(positive ? qMax(tobound, bound + space) : qMin(tobound, bound - space));
|
||||
}
|
||||
@@ -6,12 +6,12 @@
|
||||
/**
|
||||
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
||||
*/
|
||||
class Conducteur : public QGraphicsPathItem {
|
||||
class Conducer : public QGraphicsPathItem {
|
||||
public:
|
||||
enum { Type = UserType + 1001 };
|
||||
virtual int type() const { return Type; }
|
||||
Conducteur(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0);
|
||||
//virtual ~Conducteur();
|
||||
Conducer(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0);
|
||||
//virtual ~Conducer();
|
||||
|
||||
void destroy();
|
||||
bool isDestroyed() const { return(destroyed); }
|
||||
@@ -51,8 +51,8 @@
|
||||
|
||||
void pointsToPath();
|
||||
void updatePoints();
|
||||
void priv_calculeConducteur(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
void priv_modifieConducteur(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
void priv_calculeConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
void priv_modifieConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation);
|
||||
static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0);
|
||||
static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation);
|
||||
static bool estHorizontale(Terminal::Orientation a);
|
||||
50
diagram.cpp
50
diagram.cpp
@@ -1,5 +1,5 @@
|
||||
#include <math.h>
|
||||
#include "conducteur.h"
|
||||
#include "conducer.h"
|
||||
#include "elementperso.h"
|
||||
#include "diagram.h"
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
*/
|
||||
Diagram::Diagram(QObject *parent) : QGraphicsScene(parent) {
|
||||
setBackgroundBrush(Qt::white);
|
||||
poseur_de_conducteur = new QGraphicsLineItem(0, 0);
|
||||
poseur_de_conducteur -> setZValue(1000000);
|
||||
poseur_de_conducer = new QGraphicsLineItem(0, 0);
|
||||
poseur_de_conducer -> setZValue(1000000);
|
||||
QPen t;
|
||||
t.setColor(Qt::black);
|
||||
t.setWidthF(1.5);
|
||||
t.setStyle(Qt::DashLine);
|
||||
poseur_de_conducteur -> setPen(t);
|
||||
poseur_de_conducteur -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
|
||||
poseur_de_conducer -> setPen(t);
|
||||
poseur_de_conducer -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
|
||||
doit_dessiner_grille = true;
|
||||
connect(this, SIGNAL(changed(const QList<QRectF> &)), this, SLOT(slot_checkSelectionChange()));
|
||||
}
|
||||
@@ -158,7 +158,7 @@ QDomDocument Diagram::toXml(bool diagram) {
|
||||
|
||||
// creation de deux listes : une qui contient les elements, une qui contient les conducteurs
|
||||
QList<Element *> liste_elements;
|
||||
QList<Conducteur *> liste_conducteurs;
|
||||
QList<Conducer *> liste_conducers;
|
||||
|
||||
|
||||
// Determine les elements a « XMLiser »
|
||||
@@ -166,11 +166,11 @@ QDomDocument Diagram::toXml(bool diagram) {
|
||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||
if (diagram) liste_elements << elmt;
|
||||
else if (elmt -> isSelected()) liste_elements << elmt;
|
||||
} else if (Conducteur *f = qgraphicsitem_cast<Conducteur *>(qgi)) {
|
||||
if (diagram) liste_conducteurs << f;
|
||||
} else if (Conducer *f = qgraphicsitem_cast<Conducer *>(qgi)) {
|
||||
if (diagram) liste_conducers << f;
|
||||
// lorsqu'on n'exporte pas tout le diagram, il faut retirer les conducteurs non selectionnes
|
||||
// et pour l'instant, les conducteurs non selectionnes sont les conducteurs dont un des elements n'est pas relie
|
||||
else if (f -> terminal1 -> parentItem() -> isSelected() && f -> terminal2 -> parentItem() -> isSelected()) liste_conducteurs << f;
|
||||
else if (f -> terminal1 -> parentItem() -> isSelected() && f -> terminal2 -> parentItem() -> isSelected()) liste_conducers << f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,15 +219,15 @@ QDomDocument Diagram::toXml(bool diagram) {
|
||||
racine.appendChild(elements);
|
||||
|
||||
// enregistrement des conducteurs
|
||||
if (liste_conducteurs.isEmpty()) return(document);
|
||||
QDomElement conducteurs = document.createElement("conducteurs");
|
||||
foreach(Conducteur *f, liste_conducteurs) {
|
||||
QDomElement conducteur = document.createElement("conducteur");
|
||||
conducteur.setAttribute("borne1", table_adr_id.value(f -> terminal1));
|
||||
conducteur.setAttribute("borne2", table_adr_id.value(f -> terminal2));
|
||||
conducteurs.appendChild(conducteur);
|
||||
if (liste_conducers.isEmpty()) return(document);
|
||||
QDomElement conducers = document.createElement("conducteurs");
|
||||
foreach(Conducer *f, liste_conducers) {
|
||||
QDomElement conducer = document.createElement("conducteur");
|
||||
conducer.setAttribute("borne1", table_adr_id.value(f -> terminal1));
|
||||
conducer.setAttribute("borne2", table_adr_id.value(f -> terminal2));
|
||||
conducers.appendChild(conducer);
|
||||
}
|
||||
racine.appendChild(conducteurs);
|
||||
racine.appendChild(conducers);
|
||||
|
||||
// on retourne le document XML ainsi genere
|
||||
return(document);
|
||||
@@ -312,13 +312,13 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in
|
||||
// chargement de tous les Conducteurs du fichier XML
|
||||
for (QDomNode node = racine.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
||||
// on s'interesse a l'element XML "conducteurs" (= groupe de conducteurs)
|
||||
QDomElement conducteurs = node.toElement();
|
||||
if(conducteurs.isNull() || conducteurs.tagName() != "conducteurs") continue;
|
||||
QDomElement conducers = node.toElement();
|
||||
if(conducers.isNull() || conducers.tagName() != "conducteurs") continue;
|
||||
// parcours des enfants de l'element XML "conducteurs"
|
||||
for (QDomNode n = conducteurs.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||
for (QDomNode n = conducers.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||
// on s'interesse a l'element XML "element" (elements eux-memes)
|
||||
QDomElement f = n.toElement();
|
||||
if (f.isNull() || !Conducteur::valideXml(f)) continue;
|
||||
if (f.isNull() || !Conducer::valideXml(f)) continue;
|
||||
// verifie que les bornes que le conducteur relie sont connues
|
||||
int id_p1 = f.attribute("borne1").toInt();
|
||||
int id_p2 = f.attribute("borne2").toInt();
|
||||
@@ -327,12 +327,12 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in
|
||||
Terminal *p1 = table_adr_id.value(id_p1);
|
||||
Terminal *p2 = table_adr_id.value(id_p2);
|
||||
if (p1 != p2) {
|
||||
bool peut_poser_conducteur = true;
|
||||
bool peut_poser_conducer = true;
|
||||
bool cia = ((Element *)p2 -> parentItem()) -> connexionsInternesAcceptees();
|
||||
if (!cia) foreach(QGraphicsItem *item, p2 -> parentItem() -> children()) if (item == p1) peut_poser_conducteur = false;
|
||||
if (peut_poser_conducteur) new Conducteur(table_adr_id.value(id_p1), table_adr_id.value(id_p2), 0, this);
|
||||
if (!cia) foreach(QGraphicsItem *item, p2 -> parentItem() -> children()) if (item == p1) peut_poser_conducer = false;
|
||||
if (peut_poser_conducer) new Conducer(table_adr_id.value(id_p1), table_adr_id.value(id_p2), 0, this);
|
||||
}
|
||||
} else qDebug() << "Le chargement du conducteur" << id_p1 << id_p2 << "a echoue";
|
||||
} else qDebug() << "Le chargement du conducer" << id_p1 << id_p2 << "a echoue";
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
|
||||
12
diagram.h
12
diagram.h
@@ -14,15 +14,15 @@
|
||||
public:
|
||||
Diagram(QObject * = 0);
|
||||
void drawBackground(QPainter *, const QRectF &);
|
||||
inline void poseConducteur(bool pf) {
|
||||
inline void poseConducer(bool pf) {
|
||||
if (pf) {
|
||||
if (!poseur_de_conducteur -> scene()) addItem(poseur_de_conducteur);
|
||||
if (!poseur_de_conducer -> scene()) addItem(poseur_de_conducer);
|
||||
} else {
|
||||
if (poseur_de_conducteur -> scene()) removeItem(poseur_de_conducteur);
|
||||
if (poseur_de_conducer -> scene()) removeItem(poseur_de_conducer);
|
||||
}
|
||||
}
|
||||
inline void setDepart (QPointF d) { poseur_de_conducteur -> setLine(QLineF(d, poseur_de_conducteur -> line().p2())); }
|
||||
inline void setArrivee(QPointF a) { poseur_de_conducteur -> setLine(QLineF(poseur_de_conducteur -> line().p1(), a)); }
|
||||
inline void setDepart (QPointF d) { poseur_de_conducer -> setLine(QLineF(d, poseur_de_conducer -> line().p2())); }
|
||||
inline void setArrivee(QPointF a) { poseur_de_conducer -> setLine(QLineF(poseur_de_conducer -> line().p1(), a)); }
|
||||
QImage toImage(int = -1, int = -1, bool = true);
|
||||
QSize imageSize() const;
|
||||
QDomDocument toXml(bool = true);
|
||||
@@ -33,7 +33,7 @@
|
||||
QRectF border() const;
|
||||
|
||||
private:
|
||||
QGraphicsLineItem *poseur_de_conducteur;
|
||||
QGraphicsLineItem *poseur_de_conducer;
|
||||
bool doit_dessiner_grille;
|
||||
Element *elementFromXml(QDomElement &, QHash<int, Terminal *> &);
|
||||
|
||||
|
||||
@@ -84,14 +84,14 @@ void DiagramView::selectInvert() {
|
||||
void DiagramView::supprimer() {
|
||||
|
||||
QList<QGraphicsItem *> garbage_elmt;
|
||||
QList<QGraphicsItem *> garbage_conducteurs;
|
||||
QList<QGraphicsItem *> garbage_conducers;
|
||||
|
||||
// creation de deux listes : une pour les conducteurs, une pour les elements
|
||||
foreach (QGraphicsItem *qgi, scene -> selectedItems()) {
|
||||
// pour chaque qgi selectionne, il s'agit soit d'un element soit d'un conducteur
|
||||
if (qgraphicsitem_cast<Conducteur *>(qgi)) {
|
||||
if (qgraphicsitem_cast<Conducer *>(qgi)) {
|
||||
// s'il s'agit d'un conducteur, on le met dans la liste des conducteurs
|
||||
if (!garbage_conducteurs.contains(qgi)) garbage_conducteurs.append(qgi);
|
||||
if (!garbage_conducers.contains(qgi)) garbage_conducers.append(qgi);
|
||||
} else if (qgraphicsitem_cast<Element *>(qgi)) {
|
||||
// s'il s'agit d'un element, on veille a enlever ses conducteurs
|
||||
if (!garbage_elmt.contains(qgi)) garbage_elmt.append(qgi);
|
||||
@@ -100,8 +100,8 @@ void DiagramView::supprimer() {
|
||||
// si cet enfant est une borne
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(child)) {
|
||||
// alors chaque conducteur de la borne est recense
|
||||
foreach (Conducteur *f, p -> conducteurs()) {
|
||||
if (!garbage_conducteurs.contains(f)) garbage_conducteurs.append(f);
|
||||
foreach (Conducer *f, p -> conducers()) {
|
||||
if (!garbage_conducers.contains(f)) garbage_conducers.append(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,8 +110,8 @@ void DiagramView::supprimer() {
|
||||
scene -> clearSelection();
|
||||
|
||||
// "destroying" the wires, removing them from the scene and stocking them into the « garbage »
|
||||
foreach (QGraphicsItem *qgi, garbage_conducteurs) {
|
||||
if (Conducteur *f = qgraphicsitem_cast<Conducteur *>(qgi)) {
|
||||
foreach (QGraphicsItem *qgi, garbage_conducers) {
|
||||
if (Conducer *f = qgraphicsitem_cast<Conducer *>(qgi)) {
|
||||
f -> destroy();
|
||||
scene -> removeItem(f);
|
||||
throwToGarbage(f);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QtGui>
|
||||
class Diagram;
|
||||
#include "element.h"
|
||||
#include "conducteur.h"
|
||||
#include "conducer.h"
|
||||
#define TAILLE_GRILLE 10
|
||||
/**
|
||||
Classe representant graphiquement un schema electrique
|
||||
|
||||
@@ -107,11 +107,11 @@ QPixmap Element::pixmap() {
|
||||
QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == QGraphicsItem::ItemPositionChange) {
|
||||
foreach(QGraphicsItem *qgi, children()) {
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducteur(value.toPointF());
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducer(value.toPointF());
|
||||
}
|
||||
} else if (change == QGraphicsItem::ItemSelectedChange) {
|
||||
foreach(QGraphicsItem *qgi, children()) {
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducteur();
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducer();
|
||||
}
|
||||
}
|
||||
return(QGraphicsItem::itemChange(change, value));
|
||||
@@ -126,7 +126,7 @@ bool Element::setOrientation(Terminal::Orientation o) {
|
||||
ori = o;
|
||||
update();
|
||||
foreach(QGraphicsItem *qgi, children()) {
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducteur();
|
||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducer();
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ INCLUDEPATH += .
|
||||
HEADERS += aboutqet.h \
|
||||
borderinset.h \
|
||||
terminal.h \
|
||||
conducteur.h \
|
||||
conducer.h \
|
||||
element.h \
|
||||
elementfixe.h \
|
||||
elementperso.h \
|
||||
@@ -23,7 +23,7 @@ HEADERS += aboutqet.h \
|
||||
SOURCES += aboutqet.cpp \
|
||||
borderinset.cpp \
|
||||
terminal.cpp \
|
||||
conducteur.cpp \
|
||||
conducer.cpp \
|
||||
element.cpp \
|
||||
elementfixe.cpp \
|
||||
elementperso.cpp \
|
||||
|
||||
62
terminal.cpp
62
terminal.cpp
@@ -1,7 +1,7 @@
|
||||
#include "terminal.h"
|
||||
#include "diagram.h"
|
||||
#include "element.h"
|
||||
#include "conducteur.h"
|
||||
#include "conducer.h"
|
||||
|
||||
/**
|
||||
Fonction privee pour initialiser la borne.
|
||||
@@ -10,14 +10,14 @@
|
||||
*/
|
||||
void Terminal::initialise(QPointF pf, Terminal::Orientation o) {
|
||||
// definition du pount d'amarrage pour un conducteur
|
||||
amarrage_conducteur = pf;
|
||||
amarrage_conducer = pf;
|
||||
|
||||
// definition de l'orientation de la terminal (par defaut : sud)
|
||||
if (o < Terminal::Nord || o > Terminal::Ouest) sens = Terminal::Sud;
|
||||
else sens = o;
|
||||
|
||||
// calcul de la position du point d'amarrage a l'element
|
||||
amarrage_elmt = amarrage_conducteur;
|
||||
amarrage_elmt = amarrage_conducer;
|
||||
switch(sens) {
|
||||
case Terminal::Nord : amarrage_elmt += QPointF(0, TAILLE_BORNE); break;
|
||||
case Terminal::Est : amarrage_elmt += QPointF(-TAILLE_BORNE, 0); break;
|
||||
@@ -107,37 +107,37 @@ Terminal::Orientation Terminal::orientation() const {
|
||||
}
|
||||
|
||||
/**
|
||||
Attribue un conducteur a la borne
|
||||
Attribue un conducer a la borne
|
||||
@param f Le conducteur a rattacher a cette borne
|
||||
*/
|
||||
bool Terminal::addConducteur(Conducteur *f) {
|
||||
bool Terminal::addConducer(Conducer *f) {
|
||||
// pointeur 0 refuse
|
||||
if (!f) return(false);
|
||||
|
||||
// une seule des deux bornes du conducteur doit etre this
|
||||
Q_ASSERT_X((f -> terminal1 == this ^ f -> terminal2 == this), "Terminal::addConducteur", "Le conducteur devrait etre relie exactement une fois a la terminal en cours");
|
||||
Q_ASSERT_X((f -> terminal1 == this ^ f -> terminal2 == this), "Terminal::addConducer", "Le conducer devrait etre relie exactement une fois a la terminal en cours");
|
||||
|
||||
// determine l'autre borne a laquelle cette borne va etre relie grace au conducteur
|
||||
Terminal *autre_terminal = (f -> terminal1 == this) ? f -> terminal2 : f -> terminal1;
|
||||
|
||||
// verifie que la borne n'est pas deja reliee avec l'autre borne
|
||||
bool deja_liees = false;
|
||||
foreach (Conducteur* conducteur, liste_conducteurs) {
|
||||
if (conducteur -> terminal1 == autre_terminal || conducteur -> terminal2 == autre_terminal) deja_liees = true;
|
||||
foreach (Conducer* conducer, liste_conducers) {
|
||||
if (conducer -> terminal1 == autre_terminal || conducer -> terminal2 == autre_terminal) deja_liees = true;
|
||||
}
|
||||
|
||||
// si les deux bornes sont deja reliees, on refuse d'ajouter le conducteur
|
||||
if (deja_liees) return(false);
|
||||
|
||||
// sinon on ajoute le conducteur
|
||||
liste_conducteurs.append(f);
|
||||
liste_conducers.append(f);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Terminal::removeConducteur(Conducteur *f) {
|
||||
int index = liste_conducteurs.indexOf(f);
|
||||
void Terminal::removeConducer(Conducer *f) {
|
||||
int index = liste_conducers.indexOf(f);
|
||||
if (index == -1) return;
|
||||
liste_conducteurs.removeAt(index);
|
||||
liste_conducers.removeAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +155,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) {
|
||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
// on travaille avec les coordonnees de l'element parent
|
||||
QPointF f = mapFromParent(amarrage_conducteur);
|
||||
QPointF f = mapFromParent(amarrage_conducer);
|
||||
QPointF e = mapFromParent(amarrage_elmt);
|
||||
|
||||
QPen t;
|
||||
@@ -181,12 +181,12 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) {
|
||||
*/
|
||||
QRectF Terminal::boundingRect() const {
|
||||
if (br -> isNull()) {
|
||||
qreal afx = amarrage_conducteur.x();
|
||||
qreal afy = amarrage_conducteur.y();
|
||||
qreal afx = amarrage_conducer.x();
|
||||
qreal afy = amarrage_conducer.y();
|
||||
qreal aex = amarrage_elmt.x();
|
||||
qreal aey = amarrage_elmt.y();
|
||||
QPointF origine;
|
||||
origine = (afx <= aex && afy <= aey ? amarrage_conducteur : amarrage_elmt);
|
||||
origine = (afx <= aex && afy <= aey ? amarrage_conducer : amarrage_elmt);
|
||||
origine += QPointF(-3.0, -3.0);
|
||||
qreal w = qAbs((int)(afx - aex)) + 7;
|
||||
qreal h = qAbs((int)(afy - aey)) + 7;
|
||||
@@ -223,9 +223,9 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
*/
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (Diagram *s = qobject_cast<Diagram *>(scene())) {
|
||||
s -> setDepart(mapToScene(QPointF(amarrage_conducteur)));
|
||||
s -> setDepart(mapToScene(QPointF(amarrage_conducer)));
|
||||
s -> setArrivee(e -> scenePos());
|
||||
s -> poseConducteur(true);
|
||||
s -> poseConducer(true);
|
||||
setCursor(Qt::CrossCursor);
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
QList<QGraphicsItem *> qgis = scene() -> items(e -> scenePos());
|
||||
|
||||
/* le qgi le plus haut
|
||||
= le poseur de conducteur
|
||||
= le poseur de conducer
|
||||
= le premier element de la liste
|
||||
= la liste ne peut etre vide
|
||||
= on prend le deuxieme element de la liste
|
||||
@@ -275,11 +275,11 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (((Element *)parentItem()) -> connexionsInternesAcceptees())
|
||||
p -> couleur_hovered = p -> couleur_autorise;
|
||||
else p -> couleur_hovered = p -> couleur_interdit;
|
||||
} else if (p -> nbConducteurs()) {
|
||||
} else if (p -> nbConducers()) {
|
||||
// si la borne a deja un conducteur
|
||||
// verifie que cette borne n'est pas deja reliee a l'autre borne
|
||||
bool deja_reliee = false;
|
||||
foreach (Conducteur *f, liste_conducteurs) {
|
||||
foreach (Conducer *f, liste_conducers) {
|
||||
if (f -> terminal1 == p || f -> terminal2 == p) {
|
||||
deja_reliee = true;
|
||||
break;
|
||||
@@ -309,7 +309,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// verifie que la scene est bien un Diagram
|
||||
if (Diagram *s = qobject_cast<Diagram *>(scene())) {
|
||||
// on arrete de dessiner l'apercu du conducteur
|
||||
s -> poseConducteur(false);
|
||||
s -> poseConducer(false);
|
||||
// on recupere l'element sous le pointeur lors du MouseReleaseEvent
|
||||
QGraphicsItem *qgi = s -> itemAt(e -> scenePos());
|
||||
// s'il n'y a rien, on arrete la
|
||||
@@ -325,9 +325,9 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
bool cia = ((Element *)parentItem()) -> connexionsInternesAcceptees();
|
||||
if (!cia) foreach(QGraphicsItem *item, parentItem() -> children()) if (item == p) return;
|
||||
// derniere verification : verifier que cette borne n'est pas deja reliee a l'autre borne
|
||||
foreach (Conducteur *f, liste_conducteurs) if (f -> terminal1 == p || f -> terminal2 == p) return;
|
||||
foreach (Conducer *f, liste_conducers) if (f -> terminal1 == p || f -> terminal2 == p) return;
|
||||
// autrement, on pose un conducteur
|
||||
new Conducteur(this, (Terminal *)qgi, 0, scene());
|
||||
new Conducer(this, (Terminal *)qgi, 0, scene());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,16 +335,16 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
Met a jour l'eventuel conducteur relie a la Terminal.
|
||||
@param newpos Position de l'element parent a prendre en compte
|
||||
*/
|
||||
void Terminal::updateConducteur(QPointF newpos) {
|
||||
void Terminal::updateConducer(QPointF newpos) {
|
||||
if (!scene() || !parentItem()) return;
|
||||
foreach (Conducteur *conducteur, liste_conducteurs) {
|
||||
if (conducteur -> isDestroyed()) continue;
|
||||
if (newpos == QPointF()) conducteur -> update(QRectF());
|
||||
foreach (Conducer *conducer, liste_conducers) {
|
||||
if (conducer -> isDestroyed()) continue;
|
||||
if (newpos == QPointF()) conducer -> update(QRectF());
|
||||
else {
|
||||
// determine la translation subie par l'element parent
|
||||
QPointF translation = newpos - parentItem() -> pos();
|
||||
// rafraichit le conducteur en tenant compte de la translation
|
||||
conducteur -> updateWithNewPos(QRectF(), this, amarrageConducteur() + translation);
|
||||
conducer -> updateWithNewPos(QRectF(), this, amarrageConducer() + translation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,8 +352,8 @@ void Terminal::updateConducteur(QPointF newpos) {
|
||||
/**
|
||||
@return La liste des conducteurs lies a cette borne
|
||||
*/
|
||||
QList<Conducteur *> Terminal::conducteurs() const {
|
||||
return(liste_conducteurs);
|
||||
QList<Conducer *> Terminal::conducers() const {
|
||||
return(liste_conducers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
20
terminal.h
20
terminal.h
@@ -3,7 +3,7 @@
|
||||
#define TAILLE_BORNE 4
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
class Conducteur;
|
||||
class Conducer;
|
||||
class Element;
|
||||
class Diagram;
|
||||
/**
|
||||
@@ -32,15 +32,15 @@
|
||||
QRectF boundingRect() const;
|
||||
|
||||
// methodes de manipulation des conducteurs lies a cette borne
|
||||
bool addConducteur(Conducteur *);
|
||||
void removeConducteur(Conducteur *);
|
||||
inline int nbConducteurs() const { return(liste_conducteurs.size()); }
|
||||
bool addConducer(Conducer *);
|
||||
void removeConducer(Conducer *);
|
||||
inline int nbConducers() const { return(liste_conducers.size()); }
|
||||
|
||||
// methodes de lecture
|
||||
QList<Conducteur *> conducteurs() const;
|
||||
QList<Conducer *> conducers() const;
|
||||
Terminal::Orientation orientation() const;
|
||||
inline QPointF amarrageConducteur() const { return(mapToScene(amarrage_conducteur)); }
|
||||
void updateConducteur(QPointF = QPointF());
|
||||
inline QPointF amarrageConducer() const { return(mapToScene(amarrage_conducer)); }
|
||||
void updateConducer(QPointF = QPointF());
|
||||
|
||||
// methodes relatives a l'import/export au format XML
|
||||
static bool valideXml(QDomElement &);
|
||||
@@ -60,12 +60,12 @@
|
||||
// pointeur vers la QGraphicsScene de type Diagram (evite quelques casts en interne)
|
||||
Diagram *diagram_scene;
|
||||
// coordonnees des points d'amarrage
|
||||
QPointF amarrage_conducteur;
|
||||
QPointF amarrage_conducer;
|
||||
QPointF amarrage_elmt;
|
||||
// orientation de la borne
|
||||
Terminal::Orientation sens;
|
||||
// liste des conducteurs lies a cette borne
|
||||
QList<Conducteur *> liste_conducteurs;
|
||||
// liste des conducers lies a cette borne
|
||||
QList<Conducer *> liste_conducers;
|
||||
// pointeur vers un rectangle correspondant au bounding rect ; permet de ne calculer le bounding rect qu'une seule fois ; le pointeur c'est parce que le compilo exige une methode const
|
||||
QRectF *br;
|
||||
Terminal *terminal_precedente;
|
||||
|
||||
Reference in New Issue
Block a user