2007-12-01 10:47:15 +00:00
/*
2012-01-01 22:51:51 +00:00
Copyright 2006 - 2012 Xavier Guerrin
2007-12-01 10:47:15 +00:00
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-01-29 20:14:26 +00:00
# include "terminal.h"
2007-01-29 00:41:12 +00:00
# include "diagram.h"
2006-10-27 15:47:22 +00:00
# include "element.h"
2007-10-03 17:02:39 +00:00
# include "conductor.h"
2007-09-25 23:24:36 +00:00
# include "diagramcommands.h"
2008-02-25 18:28:19 +00:00
# include "qetapp.h"
2006-10-27 15:47:22 +00:00
2010-04-18 20:48:15 +00:00
QColor Terminal : : neutralColor = QColor ( Qt : : blue ) ;
QColor Terminal : : allowedColor = QColor ( Qt : : darkGreen ) ;
QColor Terminal : : warningColor = QColor ( " #ff8000 " ) ;
QColor Terminal : : forbiddenColor = QColor ( Qt : : red ) ;
2007-10-10 22:35:32 +00:00
const qreal Terminal : : terminalSize = 4.0 ;
2007-06-30 17:41:07 +00:00
2006-10-27 15:47:22 +00:00
/**
2010-04-18 20:48:15 +00:00
Methode privee pour initialiser la borne .
2006-10-27 15:47:22 +00:00
@ param pf position du point d ' amarrage pour un conducteur
@ param o orientation de la borne : Qt : : Horizontal ou Qt : : Vertical
*/
2013-11-12 18:43:59 +00:00
void Terminal : : init ( QPointF pf , QET : : Orientation o , QString number ) {
2006-10-27 15:47:22 +00:00
// definition du pount d'amarrage pour un conducteur
2010-04-18 20:48:15 +00:00
dock_conductor_ = pf ;
2006-10-27 15:47:22 +00:00
2010-04-18 20:48:15 +00:00
// definition de l'orientation de la borne (par defaut : sud)
if ( o < QET : : North | | o > QET : : West ) ori_ = QET : : South ;
else ori_ = o ;
2006-10-27 15:47:22 +00:00
// calcul de la position du point d'amarrage a l'element
2010-04-18 20:48:15 +00:00
dock_elmt_ = dock_conductor_ ;
switch ( ori_ ) {
case QET : : North : dock_elmt_ + = QPointF ( 0 , Terminal : : terminalSize ) ; break ;
case QET : : East : dock_elmt_ + = QPointF ( - Terminal : : terminalSize , 0 ) ; break ;
case QET : : West : dock_elmt_ + = QPointF ( Terminal : : terminalSize , 0 ) ; break ;
2007-06-30 17:41:07 +00:00
case QET : : South :
2010-04-18 20:48:15 +00:00
default : dock_elmt_ + = QPointF ( 0 , - Terminal : : terminalSize ) ;
2006-10-27 15:47:22 +00:00
}
2013-11-12 18:43:59 +00:00
// Number of terminal
number_terminal_ = number ;
2006-10-27 15:47:22 +00:00
// par defaut : pas de conducteur
// QRectF null
2010-04-18 20:48:15 +00:00
br_ = new QRectF ( ) ;
previous_terminal_ = 0 ;
2006-10-27 15:47:22 +00:00
// divers
setAcceptsHoverEvents ( true ) ;
setAcceptedMouseButtons ( Qt : : LeftButton ) ;
2010-04-18 20:48:15 +00:00
hovered_ = false ;
2009-04-03 19:30:25 +00:00
setToolTip ( QObject : : tr ( " Borne " , " tooltip " ) ) ;
2006-10-27 15:47:22 +00:00
}
/**
initialise une borne
@ param pf position du point d ' amarrage pour un conducteur
@ param o orientation de la borne : Qt : : Horizontal ou Qt : : Vertical
@ param e Element auquel cette borne appartient
@ param s Scene sur laquelle figure cette borne
*/
2013-11-12 18:43:59 +00:00
Terminal : : Terminal ( QPointF pf , QET : : Orientation o , QString num , Element * e , Diagram * s ) :
2007-06-30 17:41:07 +00:00
QGraphicsItem ( e , s ) ,
2010-04-18 20:48:15 +00:00
parent_element_ ( e ) ,
hovered_color_ ( Terminal : : neutralColor )
2007-06-30 17:41:07 +00:00
{
2013-11-12 18:43:59 +00:00
init ( pf , o , num ) ;
2006-10-27 15:47:22 +00:00
}
/**
initialise une borne
@ param pf_x Abscisse du point d ' amarrage pour un conducteur
@ param pf_y Ordonnee du point d ' amarrage pour un conducteur
@ param o orientation de la borne : Qt : : Horizontal ou Qt : : Vertical
@ param e Element auquel cette borne appartient
@ param s Scene sur laquelle figure cette borne
*/
2013-11-12 18:43:59 +00:00
Terminal : : Terminal ( qreal pf_x , qreal pf_y , QET : : Orientation o , QString num , Element * e , Diagram * s ) :
2007-06-30 17:41:07 +00:00
QGraphicsItem ( e , s ) ,
2010-04-18 20:48:15 +00:00
parent_element_ ( e ) ,
hovered_color_ ( Terminal : : neutralColor )
2007-06-30 17:41:07 +00:00
{
2013-11-12 18:43:59 +00:00
init ( QPointF ( pf_x , pf_y ) , o , num ) ;
2006-10-27 15:47:22 +00:00
}
/**
Destructeur
2007-04-12 03:13:13 +00:00
La destruction de la borne entraine la destruction des conducteurs
associes .
2006-10-27 15:47:22 +00:00
*/
2007-01-29 20:14:26 +00:00
Terminal : : ~ Terminal ( ) {
2010-04-18 20:48:15 +00:00
foreach ( Conductor * c , conductors_ ) delete c ;
delete br_ ;
2006-10-27 15:47:22 +00:00
}
/**
Permet de connaitre l ' orientation de la borne . Si le parent de la borne
est bien un Element , cette fonction renvoie l ' orientation par rapport a
la scene de la borne , en tenant compte du fait que l ' element ait pu etre
pivote . Sinon elle renvoie son sens normal .
2007-01-29 20:14:26 +00:00
@ return L ' orientation actuelle de la Terminal .
2006-10-27 15:47:22 +00:00
*/
2007-06-30 17:41:07 +00:00
QET : : Orientation Terminal : : orientation ( ) const {
2006-10-27 15:47:22 +00:00
if ( Element * elt = qgraphicsitem_cast < Element * > ( parentItem ( ) ) ) {
2006-11-09 19:19:51 +00:00
// orientations actuelle et par defaut de l'element
2007-06-30 17:41:07 +00:00
QET : : Orientation ori_cur = elt - > orientation ( ) . current ( ) ;
QET : : Orientation ori_def = elt - > orientation ( ) . defaultOrientation ( ) ;
2010-04-18 20:48:15 +00:00
if ( ori_cur = = ori_def ) return ( ori_ ) ;
2006-10-27 15:47:22 +00:00
else {
2007-01-20 18:11:42 +00:00
// calcul l'angle de rotation implique par l'orientation de l'element parent
2006-11-09 19:19:51 +00:00
// angle de rotation de la borne sur la scene, divise par 90
2010-04-18 20:48:15 +00:00
int angle = ori_cur - ori_def + ori_ ;
2006-11-09 19:19:51 +00:00
while ( angle > = 4 ) angle - = 4 ;
2007-06-30 17:41:07 +00:00
return ( ( QET : : Orientation ) angle ) ;
2006-10-27 15:47:22 +00:00
}
2010-04-18 20:48:15 +00:00
} else return ( ori_ ) ;
2006-10-27 15:47:22 +00:00
}
/**
2007-10-03 17:02:39 +00:00
Attribue un conductor a la borne
2006-10-27 15:47:22 +00:00
@ param f Le conducteur a rattacher a cette borne
*/
2007-10-03 17:02:39 +00:00
bool Terminal : : addConductor ( Conductor * f ) {
2006-10-27 15:47:22 +00:00
// pointeur 0 refuse
if ( ! f ) return ( false ) ;
// une seule des deux bornes du conducteur doit etre this
2008-07-30 12:44:57 +00:00
Q_ASSERT_X ( ( ( f - > terminal1 = = this ) ^ ( f - > terminal2 = = this ) ) , " Terminal::addConductor " , " Le conductor devrait etre relie exactement une fois a la terminal en cours " ) ;
2006-10-27 15:47:22 +00:00
// determine l'autre borne a laquelle cette borne va etre relie grace au conducteur
2007-01-29 20:14:26 +00:00
Terminal * autre_terminal = ( f - > terminal1 = = this ) ? f - > terminal2 : f - > terminal1 ;
2006-10-27 15:47:22 +00:00
// verifie que la borne n'est pas deja reliee avec l'autre borne
bool deja_liees = false ;
2010-04-18 20:48:15 +00:00
foreach ( Conductor * conductor , conductors_ ) {
2007-10-03 17:02:39 +00:00
if ( conductor - > terminal1 = = autre_terminal | | conductor - > terminal2 = = autre_terminal ) deja_liees = true ;
2006-10-27 15:47:22 +00:00
}
// si les deux bornes sont deja reliees, on refuse d'ajouter le conducteur
if ( deja_liees ) return ( false ) ;
// sinon on ajoute le conducteur
2010-04-18 20:48:15 +00:00
conductors_ . append ( f ) ;
2006-10-27 15:47:22 +00:00
return ( true ) ;
}
2007-04-09 02:56:47 +00:00
/**
Enleve un conducteur donne a la borne
@ param f Conducteur a enlever
*/
2007-10-03 17:02:39 +00:00
void Terminal : : removeConductor ( Conductor * f ) {
2010-04-18 20:48:15 +00:00
int index = conductors_ . indexOf ( f ) ;
2006-10-27 15:47:22 +00:00
if ( index = = - 1 ) return ;
2010-04-18 20:48:15 +00:00
conductors_ . removeAt ( index ) ;
2006-10-27 15:47:22 +00:00
}
/**
Fonction de dessin des bornes
@ param p Le QPainter a utiliser
@ param options Les options de dessin
@ param widget Le widget sur lequel on dessine
*/
2007-10-11 12:34:53 +00:00
void Terminal : : paint ( QPainter * p , const QStyleOptionGraphicsItem * options , QWidget * widget ) {
2009-04-05 11:48:26 +00:00
// en dessous d'un certain zoom, les bornes ne sont plus dessinees
if ( options & & options - > levelOfDetail < 0.5 ) return ;
2006-10-27 15:47:22 +00:00
p - > save ( ) ;
2009-06-23 21:47:53 +00:00
# ifndef Q_WS_WIN
2007-10-11 12:34:53 +00:00
// corrige un bug de rendu ne se produisant que lors du rendu sur QGraphicsScene sous X11 au zoom par defaut
2008-08-23 10:55:37 +00:00
static bool must_correct_rendering_bug = QETApp : : settings ( ) . value ( " correct-rendering " , false ) . toBool ( ) ;
2007-10-11 12:34:53 +00:00
if ( must_correct_rendering_bug ) {
Diagram * dia = diagram ( ) ;
if ( dia & & options - > levelOfDetail = = 1.0 & & widget ) {
// calcule la rotation qu'a subi l'element
qreal applied_rotation = 0.0 ;
if ( Element * elt = qgraphicsitem_cast < Element * > ( parentItem ( ) ) ) {
// orientations actuelle et par defaut de l'element
QET : : Orientation ori_cur = elt - > orientation ( ) . current ( ) ;
QET : : Orientation ori_def = elt - > orientation ( ) . defaultOrientation ( ) ;
2009-12-13 16:43:35 +00:00
applied_rotation = QET : : correctAngle ( 90.0 * ( ori_cur - ori_def ) ) ;
2007-10-11 12:34:53 +00:00
}
if ( applied_rotation = = 90.0 ) p - > translate ( 1.0 , - 1.0 ) ;
else if ( applied_rotation = = 180.0 ) p - > translate ( - 1.0 , - 1.0 ) ;
else if ( applied_rotation = = 270.0 ) p - > translate ( - 1.0 , 1.0 ) ;
}
}
# endif
2006-10-27 15:47:22 +00:00
//annulation des renderhints
p - > setRenderHint ( QPainter : : Antialiasing , false ) ;
p - > setRenderHint ( QPainter : : TextAntialiasing , false ) ;
p - > setRenderHint ( QPainter : : SmoothPixmapTransform , false ) ;
// on travaille avec les coordonnees de l'element parent
2010-04-18 20:48:15 +00:00
QPointF c = mapFromParent ( dock_conductor_ ) ;
QPointF e = mapFromParent ( dock_elmt_ ) ;
2006-10-27 15:47:22 +00:00
QPen t ;
t . setWidthF ( 1.0 ) ;
2009-04-05 11:48:26 +00:00
if ( options & & options - > levelOfDetail < 1.0 ) {
t . setCosmetic ( true ) ;
}
2006-10-27 15:47:22 +00:00
// dessin de la borne en rouge
t . setColor ( Qt : : red ) ;
p - > setPen ( t ) ;
2010-04-18 20:48:15 +00:00
p - > drawLine ( c , e ) ;
2006-10-27 15:47:22 +00:00
// dessin du point d'amarrage au conducteur en bleu
2010-04-18 20:48:15 +00:00
t . setColor ( hovered_color_ ) ;
2006-10-27 15:47:22 +00:00
p - > setPen ( t ) ;
2010-04-18 20:48:15 +00:00
p - > setBrush ( hovered_color_ ) ;
if ( hovered_ ) {
2007-02-14 01:08:29 +00:00
p - > setRenderHint ( QPainter : : Antialiasing , true ) ;
2010-04-18 20:48:15 +00:00
p - > drawEllipse ( QRectF ( c . x ( ) - 2.5 , c . y ( ) - 2.5 , 5.0 , 5.0 ) ) ;
} else p - > drawPoint ( c ) ;
2006-10-27 15:47:22 +00:00
p - > restore ( ) ;
}
/**
@ return Le rectangle ( en precision flottante ) delimitant la borne et ses alentours .
*/
2007-01-29 20:14:26 +00:00
QRectF Terminal : : boundingRect ( ) const {
2010-04-18 20:48:15 +00:00
if ( br_ - > isNull ( ) ) {
qreal dcx = dock_conductor_ . x ( ) ;
qreal dcy = dock_conductor_ . y ( ) ;
qreal dex = dock_elmt_ . x ( ) ;
qreal dey = dock_elmt_ . y ( ) ;
QPointF origin = ( dcx < = dex & & dcy < = dey ? dock_conductor_ : dock_elmt_ ) ;
origin + = QPointF ( - 3.0 , - 3.0 ) ;
qreal w = qAbs ( ( int ) ( dcx - dex ) ) + 7 ;
qreal h = qAbs ( ( int ) ( dcy - dey ) ) + 7 ;
* br_ = QRectF ( origin , QSizeF ( w , h ) ) ;
2006-10-27 15:47:22 +00:00
}
2010-04-18 20:48:15 +00:00
return ( * br_ ) ;
2006-10-27 15:47:22 +00:00
}
/**
Gere l ' entree de la souris sur la zone de la Borne .
*/
2007-01-29 20:14:26 +00:00
void Terminal : : hoverEnterEvent ( QGraphicsSceneHoverEvent * ) {
2010-04-18 20:48:15 +00:00
hovered_ = true ;
2006-10-27 15:47:22 +00:00
update ( ) ;
}
/**
Gere les mouvements de la souris sur la zone de la Borne .
*/
2007-01-29 20:14:26 +00:00
void Terminal : : hoverMoveEvent ( QGraphicsSceneHoverEvent * ) {
2006-10-27 15:47:22 +00:00
}
/**
Gere le fait que la souris sorte de la zone de la Borne .
*/
2007-01-29 20:14:26 +00:00
void Terminal : : hoverLeaveEvent ( QGraphicsSceneHoverEvent * ) {
2010-04-18 20:48:15 +00:00
hovered_ = false ;
2006-10-27 15:47:22 +00:00
update ( ) ;
}
/**
Gere le fait qu ' on enfonce un bouton de la souris sur la Borne .
@ param e L ' evenement souris correspondant
*/
2007-01-29 20:14:26 +00:00
void Terminal : : mousePressEvent ( QGraphicsSceneMouseEvent * e ) {
2010-04-18 20:48:15 +00:00
if ( Diagram * d = diagram ( ) ) {
d - > setConductorStart ( mapToScene ( QPointF ( dock_conductor_ ) ) ) ;
d - > setConductorStop ( e - > scenePos ( ) ) ;
d - > setConductor ( true ) ;
2007-04-15 19:22:54 +00:00
//setCursor(Qt::CrossCursor);
2006-10-27 15:47:22 +00:00
}
}
/**
Gere le fait qu ' on bouge la souris sur la Borne .
@ param e L ' evenement souris correspondant
*/
2007-01-29 20:14:26 +00:00
void Terminal : : mouseMoveEvent ( QGraphicsSceneMouseEvent * e ) {
2006-10-27 15:47:22 +00:00
// pendant la pose d'un conducteur, on adopte un autre curseur
2007-04-15 19:22:54 +00:00
//setCursor(Qt::CrossCursor);
2006-10-27 15:47:22 +00:00
// d'un mouvement a l'autre, il faut retirer l'effet hover de la borne precedente
2010-04-18 20:48:15 +00:00
if ( previous_terminal_ ) {
if ( previous_terminal_ = = this ) hovered_ = true ;
else previous_terminal_ - > hovered_ = false ;
previous_terminal_ - > hovered_color_ = previous_terminal_ - > neutralColor ;
previous_terminal_ - > update ( ) ;
2006-10-27 15:47:22 +00:00
}
2007-09-25 23:24:36 +00:00
2010-04-18 20:48:15 +00:00
Diagram * d = diagram ( ) ;
if ( ! d ) return ;
2007-01-29 00:41:12 +00:00
// si la scene est un Diagram, on actualise le poseur de conducteur
2010-04-18 20:48:15 +00:00
d - > setConductorStop ( e - > scenePos ( ) ) ;
2006-10-27 15:47:22 +00:00
// on recupere la liste des qgi sous le pointeur
2010-04-18 20:48:15 +00:00
QList < QGraphicsItem * > qgis = d - > items ( e - > scenePos ( ) ) ;
2006-10-27 15:47:22 +00:00
/* le qgi le plus haut
2007-10-03 17:02:39 +00:00
= le poseur de conductor
2006-10-27 15:47:22 +00:00
= le premier element de la liste
= la liste ne peut etre vide
= on prend le deuxieme element de la liste
*/
2007-01-29 20:14:26 +00:00
Q_ASSERT_X ( ! ( qgis . isEmpty ( ) ) , " Terminal::mouseMoveEvent " , " La liste d'items ne devrait pas etre vide " ) ;
2006-10-27 15:47:22 +00:00
2010-04-18 20:48:15 +00:00
// s'il n'y rien d'autre que le poseur de conducteur dans la liste, on arrete la
if ( qgis . size ( ) < = 1 ) return ;
// sinon on prend le deuxieme element de la liste et on verifie s'il s'agit d'une borne
QGraphicsItem * qgi = qgis . at ( 1 ) ;
// si le qgi est une borne...
Terminal * other_terminal = qgraphicsitem_cast < Terminal * > ( qgi ) ;
if ( ! other_terminal ) return ;
previous_terminal_ = other_terminal ;
// s'il s'agit d'une borne, on lui applique l'effet hover approprie
if ( ! canBeLinkedTo ( other_terminal ) ) {
other_terminal - > hovered_color_ = forbiddenColor ;
} else if ( other_terminal - > conductorsCount ( ) ) {
other_terminal - > hovered_color_ = warningColor ;
} else {
other_terminal - > hovered_color_ = allowedColor ;
2006-10-27 15:47:22 +00:00
}
2010-04-18 20:48:15 +00:00
other_terminal - > hovered_ = true ;
other_terminal - > update ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
Gere le fait qu ' on relache la souris sur la Borne .
@ param e L ' evenement souris correspondant
*/
2007-01-29 20:14:26 +00:00
void Terminal : : mouseReleaseEvent ( QGraphicsSceneMouseEvent * e ) {
2007-04-15 19:22:54 +00:00
//setCursor(Qt::ArrowCursor);
2010-04-18 20:48:15 +00:00
previous_terminal_ = 0 ;
hovered_color_ = neutralColor ;
2007-01-29 00:41:12 +00:00
// verifie que la scene est bien un Diagram
2010-04-18 20:48:15 +00:00
if ( Diagram * d = diagram ( ) ) {
2006-10-27 15:47:22 +00:00
// on arrete de dessiner l'apercu du conducteur
2010-04-18 20:48:15 +00:00
d - > setConductor ( false ) ;
2006-10-27 15:47:22 +00:00
// on recupere l'element sous le pointeur lors du MouseReleaseEvent
2010-04-18 20:48:15 +00:00
QGraphicsItem * qgi = d - > itemAt ( e - > scenePos ( ) ) ;
2006-10-27 15:47:22 +00:00
// s'il n'y a rien, on arrete la
if ( ! qgi ) return ;
// idem si l'element obtenu n'est pas une borne
2010-04-18 20:48:15 +00:00
Terminal * other_terminal = qgraphicsitem_cast < Terminal * > ( qgi ) ;
if ( ! other_terminal ) return ;
2006-10-27 15:47:22 +00:00
// on remet la couleur de hover a sa valeur par defaut
2010-04-18 20:48:15 +00:00
other_terminal - > hovered_color_ = neutralColor ;
other_terminal - > hovered_ = false ;
// on s'arrete la s'il n'est pas possible de relier les bornes
if ( ! canBeLinkedTo ( other_terminal ) ) return ;
2006-10-27 15:47:22 +00:00
// autrement, on pose un conducteur
2010-04-18 20:48:15 +00:00
Conductor * new_conductor = new Conductor ( this , other_terminal ) ;
new_conductor - > setProperties ( d - > defaultConductorProperties ) ;
d - > undoStack ( ) . push ( new AddConductorCommand ( d , new_conductor ) ) ;
2013-04-04 16:57:15 +00:00
new_conductor - > autoText ( ) ;
2006-10-27 15:47:22 +00:00
}
}
/**
2010-05-04 20:18:30 +00:00
Met a jour l ' eventuel conducteur relie a la borne .
2006-11-30 18:05:02 +00:00
@ param newpos Position de l ' element parent a prendre en compte
2006-10-27 15:47:22 +00:00
*/
2010-05-04 20:18:30 +00:00
void Terminal : : updateConductor ( ) {
2006-11-30 18:05:02 +00:00
if ( ! scene ( ) | | ! parentItem ( ) ) return ;
2010-04-18 20:48:15 +00:00
foreach ( Conductor * conductor , conductors_ ) {
2007-10-03 17:02:39 +00:00
if ( conductor - > isDestroyed ( ) ) continue ;
2010-05-04 20:36:55 +00:00
conductor - > updatePath ( ) ;
2010-04-18 20:48:15 +00:00
}
}
/**
@ param other_terminal Autre borne
@ return true si cette borne est reliee a other_terminal , false sion
*/
bool Terminal : : isLinkedTo ( Terminal * other_terminal ) {
if ( other_terminal = = this ) return ( false ) ;
bool already_linked = false ;
foreach ( Conductor * c , conductors_ ) {
if ( c - > terminal1 = = other_terminal | | c - > terminal2 = = other_terminal ) {
already_linked = true ;
break ;
2006-11-30 18:05:02 +00:00
}
2006-10-27 15:47:22 +00:00
}
2010-04-18 20:48:15 +00:00
return ( already_linked ) ;
}
/**
@ param other_terminal Autre borne
@ return true si cette borne peut etre reliee a other_terminal , false sion
*/
bool Terminal : : canBeLinkedTo ( Terminal * other_terminal ) {
if ( other_terminal = = this ) return ( false ) ;
// l'autre borne appartient-elle au meme element ?
bool same_element = other_terminal - > parentElement ( ) = = parentElement ( ) ;
// les connexions internes sont-elles autorisees ?
bool internal_connections_allowed = parentElement ( ) - > internalConnections ( ) ;
// les deux bornes sont-elles deja liees ?
bool already_linked = isLinkedTo ( other_terminal ) ;
// la liaison des deux bornes est-elle interdite ?
bool link_forbidden = ( same_element & & ! internal_connections_allowed ) | | already_linked ;
return ( ! link_forbidden ) ;
2006-10-27 15:47:22 +00:00
}
/**
@ return La liste des conducteurs lies a cette borne
*/
2007-10-03 17:02:39 +00:00
QList < Conductor * > Terminal : : conductors ( ) const {
2010-04-18 20:48:15 +00:00
return ( conductors_ ) ;
2006-10-27 15:47:22 +00:00
}
/**
Methode d ' export en XML
@ param doc Le Document XML a utiliser pour creer l ' element XML
@ return un QDomElement representant cette borne
*/
2007-01-29 20:14:26 +00:00
QDomElement Terminal : : toXml ( QDomDocument & doc ) const {
2007-03-09 19:18:55 +00:00
QDomElement qdo = doc . createElement ( " terminal " ) ;
2010-04-18 20:48:15 +00:00
qdo . setAttribute ( " x " , QString ( " %1 " ) . arg ( dock_elmt_ . x ( ) ) ) ;
qdo . setAttribute ( " y " , QString ( " %1 " ) . arg ( dock_elmt_ . y ( ) ) ) ;
qdo . setAttribute ( " orientation " , ori_ ) ;
2013-11-12 18:43:59 +00:00
qdo . setAttribute ( " number " , number_terminal_ ) ;
2006-10-27 15:47:22 +00:00
return ( qdo ) ;
}
/**
Permet de savoir si un element XML represente une borne
2007-10-21 16:10:21 +00:00
@ param terminal Le QDomElement a analyser
2006-10-27 15:47:22 +00:00
@ return true si le QDomElement passe en parametre est une borne , false sinon
*/
2007-01-29 20:14:26 +00:00
bool Terminal : : valideXml ( QDomElement & terminal ) {
2006-10-27 15:47:22 +00:00
// verifie le nom du tag
2007-03-09 19:18:55 +00:00
if ( terminal . tagName ( ) ! = " terminal " ) return ( false ) ;
2006-10-27 15:47:22 +00:00
// verifie la presence des attributs minimaux
2007-01-29 20:14:26 +00:00
if ( ! terminal . hasAttribute ( " x " ) ) return ( false ) ;
if ( ! terminal . hasAttribute ( " y " ) ) return ( false ) ;
if ( ! terminal . hasAttribute ( " orientation " ) ) return ( false ) ;
2013-11-12 18:43:59 +00:00
if ( ! terminal . hasAttribute ( " number " ) ) return ( false ) ;
2006-10-27 15:47:22 +00:00
bool conv_ok ;
// parse l'abscisse
2007-01-29 20:14:26 +00:00
terminal . attribute ( " x " ) . toDouble ( & conv_ok ) ;
2006-10-27 15:47:22 +00:00
if ( ! conv_ok ) return ( false ) ;
// parse l'ordonnee
2007-01-29 20:14:26 +00:00
terminal . attribute ( " y " ) . toDouble ( & conv_ok ) ;
2006-10-27 15:47:22 +00:00
if ( ! conv_ok ) return ( false ) ;
// parse l'id
2007-01-29 20:14:26 +00:00
terminal . attribute ( " id " ) . toInt ( & conv_ok ) ;
2006-10-27 15:47:22 +00:00
if ( ! conv_ok ) return ( false ) ;
// parse l'orientation
2007-01-29 20:14:26 +00:00
int terminal_or = terminal . attribute ( " orientation " ) . toInt ( & conv_ok ) ;
2006-10-27 15:47:22 +00:00
if ( ! conv_ok ) return ( false ) ;
2007-06-30 17:41:07 +00:00
if ( terminal_or ! = QET : : North & & terminal_or ! = QET : : South & & terminal_or ! = QET : : East & & terminal_or ! = QET : : West ) return ( false ) ;
2006-10-27 15:47:22 +00:00
// a ce stade, la borne est syntaxiquement correcte
return ( true ) ;
}
/**
Permet de savoir si un element XML represente cette borne . Attention , l ' element XML n ' est pas verifie
2007-10-21 16:10:21 +00:00
@ param terminal Le QDomElement a analyser
2006-10-27 15:47:22 +00:00
@ return true si la borne " se reconnait " ( memes coordonnes , meme orientation ) , false sinon
*/
2007-01-29 20:14:26 +00:00
bool Terminal : : fromXml ( QDomElement & terminal ) {
2006-10-27 15:47:22 +00:00
return (
2010-04-18 20:48:15 +00:00
qFuzzyCompare ( terminal . attribute ( " x " ) . toDouble ( ) , dock_elmt_ . x ( ) ) & &
qFuzzyCompare ( terminal . attribute ( " y " ) . toDouble ( ) , dock_elmt_ . y ( ) ) & &
2013-11-12 18:43:59 +00:00
terminal . attribute ( " orientation " ) . toInt ( ) = = ori_ & &
terminal . attribute ( " number " ) . toInt ( ) = = number_terminal_
2006-10-27 15:47:22 +00:00
) ;
}
2007-09-25 23:24:36 +00:00
2010-04-18 20:48:15 +00:00
/**
@ return le Diagram auquel cette borne appartient , ou 0 si cette borne est independant
*/
2007-09-25 23:24:36 +00:00
Diagram * Terminal : : diagram ( ) const {
return ( qobject_cast < Diagram * > ( scene ( ) ) ) ;
}
2010-04-18 20:48:15 +00:00
/**
@ return L ' element auquel cette borne est rattachee
*/
Element * Terminal : : parentElement ( ) const {
return ( parent_element_ ) ;
}