mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Mise en place du nouveau systeme de gestion de la rotation des elements - attention : changements dans l'interpretation de certains attributs des fichiers XML => les "sens" des elements sont desormais un chiffre : 0 = nord, 1 = est, 2 = sud, 3 = ouest
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@15 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
c51ca764dd
commit
ddf173b47b
19
borne.cpp
19
borne.cpp
@ -92,17 +92,16 @@ Borne::~Borne() {
|
|||||||
Borne::Orientation Borne::orientation() const {
|
Borne::Orientation Borne::orientation() const {
|
||||||
//true pour une orientation verticale, false pour une orientation horizontale
|
//true pour une orientation verticale, false pour une orientation horizontale
|
||||||
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
||||||
if (elt -> orientation()) return(sens);
|
// orientations actuelle et par defaut de l'element
|
||||||
|
Borne::Orientation ori_cur = elt -> orientation();
|
||||||
|
Borne::Orientation ori_def = elt -> defaultOrientation();
|
||||||
|
if (ori_cur == ori_def) return(sens);
|
||||||
else {
|
else {
|
||||||
Borne::Orientation retour;
|
/* calcul l'angle de rotation implique par l'orientation de l'element parent */
|
||||||
switch(sens) {
|
// angle de rotation de la borne sur la scene, divise par 90
|
||||||
case Borne::Nord : retour = Borne::Ouest; break;
|
int angle = ori_cur - ori_def + sens;
|
||||||
case Borne::Est : retour = Borne::Nord; break;
|
while (angle >= 4) angle -= 4;
|
||||||
case Borne::Ouest : retour = Borne::Sud; break;
|
return((Borne::Orientation)angle);
|
||||||
case Borne::Sud :
|
|
||||||
default : retour = Borne::Est;
|
|
||||||
}
|
|
||||||
return(retour);
|
|
||||||
}
|
}
|
||||||
} else return(sens);
|
} else return(sens);
|
||||||
}
|
}
|
||||||
|
2
borne.h
2
borne.h
@ -13,7 +13,7 @@
|
|||||||
class Borne : public QGraphicsItem {
|
class Borne : public QGraphicsItem {
|
||||||
public:
|
public:
|
||||||
// enum definissant l'orientation de la borne
|
// enum definissant l'orientation de la borne
|
||||||
enum Orientation {Nord, Sud, Est, Ouest};
|
enum Orientation {Nord, Est, Sud, Ouest};
|
||||||
|
|
||||||
// permet de caster un QGraphicsItem en Borne avec qgraphicsitem_cast
|
// permet de caster un QGraphicsItem en Borne avec qgraphicsitem_cast
|
||||||
enum { Type = UserType + 1002 };
|
enum { Type = UserType + 1002 };
|
||||||
|
23
element.cpp
23
element.cpp
@ -8,7 +8,6 @@
|
|||||||
Constructeur pour un element sans scene ni parent
|
Constructeur pour un element sans scene ni parent
|
||||||
*/
|
*/
|
||||||
Element::Element(QGraphicsItem *parent, Schema *scene) : QGraphicsItem(parent, scene) {
|
Element::Element(QGraphicsItem *parent, Schema *scene) : QGraphicsItem(parent, scene) {
|
||||||
sens = true;
|
|
||||||
peut_relier_ses_propres_bornes = false;
|
peut_relier_ses_propres_bornes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,29 +109,19 @@ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value) {
|
|||||||
return(QGraphicsItem::itemChange(change, value));
|
return(QGraphicsItem::itemChange(change, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
bool Element::setOrientation(Borne::Orientation o) {
|
||||||
@return L'orientation en cours de l'element : true pour une orientation verticale, false pour une orientation horizontale
|
// verifie que l'orientation demandee est acceptee
|
||||||
*/
|
if (!acceptOrientation(o)) return(false);
|
||||||
bool Element::orientation() const {
|
|
||||||
return(sens);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Inverse l'orientation de l'element
|
|
||||||
@return La nouvelle orientation : true pour une orientation verticale, false pour une orientation horizontale
|
|
||||||
*/
|
|
||||||
bool Element::invertOrientation() {
|
|
||||||
// inversion du sens
|
|
||||||
sens = !sens;
|
|
||||||
// on cache temporairement l'element pour eviter un bug graphique
|
// on cache temporairement l'element pour eviter un bug graphique
|
||||||
hide();
|
hide();
|
||||||
// rotation en consequence et rafraichissement de l'element graphique
|
// rotation en consequence et rafraichissement de l'element graphique
|
||||||
rotate(sens ? 90.0 : -90.0);
|
rotate(90.0 * (o - ori));
|
||||||
|
ori = o;
|
||||||
// on raffiche l'element, on le reselectionne et on le rafraichit
|
// on raffiche l'element, on le reselectionne et on le rafraichit
|
||||||
show();
|
show();
|
||||||
select();
|
select();
|
||||||
update();
|
update();
|
||||||
return(sens);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** Methodes protegees ***/
|
/*** Methodes protegees ***/
|
||||||
|
48
element.h
48
element.h
@ -33,16 +33,62 @@
|
|||||||
inline void setConnexionsInternesAcceptees(bool cia) { peut_relier_ses_propres_bornes = cia; }
|
inline void setConnexionsInternesAcceptees(bool cia) { peut_relier_ses_propres_bornes = cia; }
|
||||||
static bool valideXml(QDomElement &);
|
static bool valideXml(QDomElement &);
|
||||||
virtual bool fromXml(QDomElement &, QHash<int, Borne *>&) = 0;
|
virtual bool fromXml(QDomElement &, QHash<int, Borne *>&) = 0;
|
||||||
|
// methodes d'acces aux possibilites d'orientation
|
||||||
|
inline Borne::Orientation orientation() { return(ori); }
|
||||||
|
inline bool acceptOrientation(Borne::Orientation o) {
|
||||||
|
switch(o) {
|
||||||
|
case Borne::Nord: return(ori_n);
|
||||||
|
case Borne::Est: return(ori_e);
|
||||||
|
case Borne::Sud: return(ori_s);
|
||||||
|
case Borne::Ouest: return(ori_w);
|
||||||
|
default: return(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline Borne::Orientation defaultOrientation() { return(ori_d); }
|
||||||
|
inline Borne::Orientation nextAcceptableOrientation() {
|
||||||
|
Borne::Orientation retour = nextOrientation(ori);
|
||||||
|
for (int i = 0 ; i < 4 ; ++ i) {
|
||||||
|
if (acceptOrientation(retour)) return(retour);
|
||||||
|
retour = nextOrientation(retour);
|
||||||
|
}
|
||||||
|
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||||
|
return(Borne::Nord);
|
||||||
|
}
|
||||||
|
inline Borne::Orientation previousAcceptableOrientation() {
|
||||||
|
Borne::Orientation retour = previousOrientation(ori);
|
||||||
|
for (int i = 0 ; i < 4 ; ++ i) {
|
||||||
|
if (acceptOrientation(retour)) return(retour);
|
||||||
|
retour = previousOrientation(retour);
|
||||||
|
}
|
||||||
|
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||||
|
return(Borne::Nord);
|
||||||
|
}
|
||||||
|
bool setOrientation(Borne::Orientation o);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
bool ori_n;
|
||||||
|
bool ori_s;
|
||||||
|
bool ori_e;
|
||||||
|
bool ori_w;
|
||||||
|
Borne::Orientation ori_d;
|
||||||
|
Borne::Orientation ori;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool peut_relier_ses_propres_bornes;
|
bool peut_relier_ses_propres_bornes;
|
||||||
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
bool sens;
|
inline Borne::Orientation nextOrientation(Borne::Orientation o) {
|
||||||
|
if (o < 0 || o > 2) return(Borne::Nord);
|
||||||
|
return((Borne::Orientation)(o + 1));
|
||||||
|
}
|
||||||
|
inline Borne::Orientation previousOrientation(Borne::Orientation o) {
|
||||||
|
if (o < 0 || o > 3) return(Borne::Nord);
|
||||||
|
if (o == Borne::Nord) return(Borne::Ouest);
|
||||||
|
return((Borne::Orientation)(o - 1));
|
||||||
|
}
|
||||||
|
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
QPoint hotspot_coord;
|
QPoint hotspot_coord;
|
||||||
QPixmap apercu;
|
QPixmap apercu;
|
||||||
|
@ -44,7 +44,8 @@ ElementPerso::ElementPerso(QString &nom_fichier, QGraphicsItem *qgi, Schema *s,
|
|||||||
!attributeIsAnInteger(racine, QString("width"), &w) ||\
|
!attributeIsAnInteger(racine, QString("width"), &w) ||\
|
||||||
!attributeIsAnInteger(racine, QString("height"), &h) ||\
|
!attributeIsAnInteger(racine, QString("height"), &h) ||\
|
||||||
!attributeIsAnInteger(racine, QString("hotspot_x"), &hot_x) ||\
|
!attributeIsAnInteger(racine, QString("hotspot_x"), &hot_x) ||\
|
||||||
!attributeIsAnInteger(racine, QString("hotspot_y"), &hot_y)
|
!attributeIsAnInteger(racine, QString("hotspot_y"), &hot_y) ||\
|
||||||
|
!validOrientationAttribute(racine)
|
||||||
) {
|
) {
|
||||||
if (etat != NULL) *etat = 5;
|
if (etat != NULL) *etat = 5;
|
||||||
elmt_etat = 5;
|
elmt_etat = 5;
|
||||||
@ -209,3 +210,30 @@ bool ElementPerso::attributeIsAReal(QDomElement &e, QString nom_attribut, double
|
|||||||
if (reel != NULL) *reel = tmp;
|
if (reel != NULL) *reel = tmp;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ElementPerso::validOrientationAttribute(QDomElement &e) {
|
||||||
|
// verifie la presence de l'attribut orientation
|
||||||
|
if (!e.hasAttribute("orientation")) return(false);
|
||||||
|
QString t = e.attribute("orientation");
|
||||||
|
// verification syntaxique : 4 lettres, un d, que des y ou des n pour le reste
|
||||||
|
if (t.length() != 4) return(false);
|
||||||
|
int d_pos = -1;
|
||||||
|
for (int i = 0 ; i < 4 ; ++ i) {
|
||||||
|
QChar c = t.at(i);
|
||||||
|
if (c != 'd' && c != 'y' && c != 'n') return(false);
|
||||||
|
if (c == 'd') {
|
||||||
|
if (d_pos == -1) d_pos = i;
|
||||||
|
else return(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d_pos == -1) return(false);
|
||||||
|
|
||||||
|
// orientation : 4 lettres = nord/est/sud/ouest avec d = default, y = yes et n = no
|
||||||
|
ori_n = (t.at(0) == 'd' || t.at(0) == 'y');
|
||||||
|
ori_e = (t.at(1) == 'd' || t.at(1) == 'y');
|
||||||
|
ori_s = (t.at(2) == 'd' || t.at(2) == 'y');
|
||||||
|
ori_w = (t.at(3) == 'd' || t.at(3) == 'y');
|
||||||
|
ori_d = (Borne::Orientation)d_pos;
|
||||||
|
ori = ori_d;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
void setQPainterAntiAliasing(QPainter *, bool);
|
void setQPainterAntiAliasing(QPainter *, bool);
|
||||||
bool attributeIsAnInteger(QDomElement &, QString, int * = NULL);
|
bool attributeIsAnInteger(QDomElement &, QString, int * = NULL);
|
||||||
bool attributeIsAReal(QDomElement &, QString, double * = NULL);
|
bool attributeIsAReal(QDomElement &, QString, double * = NULL);
|
||||||
|
bool validOrientationAttribute(QDomElement &);
|
||||||
int nb_bornes;
|
int nb_bornes;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE definition SYSTEM "definition_element.dtd">
|
<!DOCTYPE definition SYSTEM "definition_element.dtd">
|
||||||
<definition type="element" nom="entree" width="20" height="40" hotspot_x="10" hotspot_y="15" orientation="dnny">
|
<definition type="element" nom="entree" width="20" height="40" hotspot_x="10" hotspot_y="15" orientation="dyyy">
|
||||||
<polygone x1="-7.5" y1="-13" x2="7.5" y2="-13" x3="0" y3="0" antialias="true" style="normal" />
|
<polygone x1="-7.5" y1="-13" x2="7.5" y2="-13" x3="0" y3="0" antialias="true" style="normal" />
|
||||||
<ligne x1="0" y1="0" x2="0" y2="13" antialias="false" style="normal" />
|
<ligne x1="0" y1="0" x2="0" y2="13" antialias="false" style="normal" />
|
||||||
<borne orientation="s" x="0" y="15" />
|
<borne orientation="s" x="0" y="15" />
|
||||||
|
@ -149,7 +149,7 @@ QDomDocument Schema::toXml(bool schema) {
|
|||||||
element.setAttribute("x", elmt -> pos().x());
|
element.setAttribute("x", elmt -> pos().x());
|
||||||
element.setAttribute("y", elmt -> pos().y());
|
element.setAttribute("y", elmt -> pos().y());
|
||||||
if (elmt -> isSelected()) element.setAttribute("selected", "selected");
|
if (elmt -> isSelected()) element.setAttribute("selected", "selected");
|
||||||
element.setAttribute("sens", elmt -> orientation() ? "true" : "false");
|
element.setAttribute("sens", QString("%1").arg(elmt -> orientation()));
|
||||||
|
|
||||||
// enregistrements des bornes de chaque appareil
|
// enregistrements des bornes de chaque appareil
|
||||||
QDomElement bornes = document.createElement("bornes");
|
QDomElement bornes = document.createElement("bornes");
|
||||||
@ -303,6 +303,8 @@ Element *Schema::elementFromXml(QDomElement &e, QHash<int, Borne *> &table_id_ad
|
|||||||
int etat;
|
int etat;
|
||||||
Element *nvel_elmt = new ElementPerso(chemin_fichier, 0, 0, &etat);
|
Element *nvel_elmt = new ElementPerso(chemin_fichier, 0, 0, &etat);
|
||||||
if (etat != 0) return(false);
|
if (etat != 0) return(false);
|
||||||
|
|
||||||
|
// charge les caracteristiques de l'element
|
||||||
bool retour = nvel_elmt -> fromXml(e, table_id_adr);
|
bool retour = nvel_elmt -> fromXml(e, table_id_adr);
|
||||||
if (!retour) {
|
if (!retour) {
|
||||||
delete nvel_elmt;
|
delete nvel_elmt;
|
||||||
@ -311,7 +313,10 @@ Element *Schema::elementFromXml(QDomElement &e, QHash<int, Borne *> &table_id_ad
|
|||||||
addItem(nvel_elmt);
|
addItem(nvel_elmt);
|
||||||
nvel_elmt -> setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
nvel_elmt -> setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||||
nvel_elmt -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
nvel_elmt -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
if (e.attribute("sens") == "false") nvel_elmt -> invertOrientation();
|
bool conv_ok;
|
||||||
|
int read_ori = e.attribute("sens").toInt(&conv_ok);
|
||||||
|
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = nvel_elmt -> defaultOrientation();
|
||||||
|
nvel_elmt -> setOrientation((Borne::Orientation)read_ori);
|
||||||
nvel_elmt -> setSelected(e.attribute("selected") == "selected");
|
nvel_elmt -> setSelected(e.attribute("selected") == "selected");
|
||||||
}
|
}
|
||||||
return(retour ? nvel_elmt : NULL);
|
return(retour ? nvel_elmt : NULL);
|
||||||
|
@ -151,7 +151,7 @@ void SchemaVue::pivoter() {
|
|||||||
if (scene -> selectedItems().isEmpty()) return;
|
if (scene -> selectedItems().isEmpty()) return;
|
||||||
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
||||||
if (Element *elt = qgraphicsitem_cast<Element *>(item)) {
|
if (Element *elt = qgraphicsitem_cast<Element *>(item)) {
|
||||||
elt -> invertOrientation();
|
elt -> setOrientation(elt -> nextAcceptableOrientation());
|
||||||
elt -> update();
|
elt -> update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user