2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2011-03-02 00:16:40 +00:00
|
|
|
Copyright 2006-2011 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/>.
|
|
|
|
*/
|
2006-10-27 15:47:22 +00:00
|
|
|
#ifndef ELEMENT_H
|
2007-04-09 02:56:47 +00:00
|
|
|
#define ELEMENT_H
|
|
|
|
#include <QtGui>
|
|
|
|
#include "terminal.h"
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "orientationset.h"
|
2007-10-21 16:10:21 +00:00
|
|
|
class Diagram;
|
2009-04-04 21:47:07 +00:00
|
|
|
class ElementTextItem;
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Cette classe abstraite represente un element electrique.
|
|
|
|
*/
|
2008-07-09 21:14:30 +00:00
|
|
|
class Element : public QObject, public QGraphicsItem {
|
|
|
|
|
|
|
|
Q_OBJECT
|
2011-02-20 19:43:26 +00:00
|
|
|
Q_INTERFACES(QGraphicsItem)
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// constructeurs, destructeur
|
|
|
|
public:
|
|
|
|
Element(QGraphicsItem * = 0, Diagram * = 0);
|
|
|
|
virtual ~Element();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Element(const Element &);
|
|
|
|
|
|
|
|
// attributs
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1000 };
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
protected:
|
2007-12-16 14:05:39 +00:00
|
|
|
/**
|
|
|
|
orientations de l'element :
|
|
|
|
* autorisations
|
|
|
|
* orientation en cours
|
|
|
|
* orientation par defaut
|
|
|
|
@see OrientationSet
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
OrientationSet ori;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QSize dimensions;
|
|
|
|
QPoint hotspot_coord;
|
2009-04-03 19:30:25 +00:00
|
|
|
QPixmap preview;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// methodes
|
|
|
|
public:
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
|
|
|
permet de caster un QGraphicsItem en Element avec qgraphicsitem_cast
|
|
|
|
@return le type de QGraphicsItem
|
|
|
|
*/
|
2007-04-09 02:56:47 +00:00
|
|
|
virtual int type() const { return Type; }
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
// methodes virtuelles pures a definir dans les classes enfants
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return la liste des bornes de cet element
|
2007-09-05 20:42:08 +00:00
|
|
|
virtual QList<Terminal *> terminals() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return la liste des conducteurs relies a cet element
|
2007-10-03 17:02:39 +00:00
|
|
|
virtual QList<Conductor *> conductors() const = 0;
|
2009-04-04 21:47:07 +00:00
|
|
|
/// @return la liste des champs de textes de cet element
|
|
|
|
virtual QList<ElementTextItem *> texts() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return le nombre de bornes actuel de cet element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int terminalsCount() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return le nombre de bornes minimum de cet element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int minTerminalsCount() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return le nombre de bornes maximum de cet element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int maxTerminalsCount() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
|
|
|
Dessine l'element
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return L'ID du type de l'element
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual QString typeId() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/// @return Le nom de l'element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual QString name() const = 0;
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2010-04-25 12:12:59 +00:00
|
|
|
virtual bool isHighlighted() const;
|
|
|
|
virtual void setHighlighted(bool);
|
2007-04-12 03:13:13 +00:00
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QSize setSize(int, int);
|
2009-05-17 02:13:40 +00:00
|
|
|
QSize size() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
QPixmap pixmap();
|
|
|
|
|
|
|
|
// methodes relatives au point de saisie
|
|
|
|
QPoint setHotspot(QPoint);
|
|
|
|
QPoint hotspot() const;
|
|
|
|
|
|
|
|
// methodes relatives a la selection
|
|
|
|
void select();
|
|
|
|
void deselect();
|
|
|
|
|
|
|
|
// methodes relatives a la position
|
|
|
|
void setPos(const QPointF &);
|
|
|
|
void setPos(qreal, qreal);
|
|
|
|
|
|
|
|
// methodes relatives aux connexions internes
|
2007-12-09 10:30:35 +00:00
|
|
|
bool internalConnections();
|
|
|
|
void setInternalConnections(bool);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// methodes relatives aux fichiers XML
|
|
|
|
static bool valideXml(QDomElement &);
|
2010-07-18 19:16:52 +00:00
|
|
|
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
|
2007-10-27 13:18:17 +00:00
|
|
|
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
// methodes d'acces aux possibilites d'orientation
|
2007-06-30 17:41:07 +00:00
|
|
|
bool setOrientation(QET::Orientation o);
|
|
|
|
const OrientationSet &orientation() const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
2008-03-01 17:39:44 +00:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *);
|
2007-04-09 02:56:47 +00:00
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
2007-09-15 22:14:23 +00:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
private:
|
2007-12-09 10:30:35 +00:00
|
|
|
bool internal_connections;
|
2010-04-25 12:12:59 +00:00
|
|
|
bool must_highlight_;
|
2010-05-08 21:24:43 +00:00
|
|
|
bool first_move_;
|
2007-04-09 02:56:47 +00:00
|
|
|
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
2010-04-25 12:12:59 +00:00
|
|
|
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
|
2007-04-09 02:56:47 +00:00
|
|
|
void updatePixmap();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de savoir si l'element accepte les connexions internes,
|
|
|
|
c'est-a-dire que ses bornes peuvent etre reliees entre elles
|
|
|
|
@return true si l'element accepte les connexions internes, false sinon
|
|
|
|
*/
|
2007-12-09 10:30:35 +00:00
|
|
|
inline bool Element::internalConnections() {
|
|
|
|
return(internal_connections);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de specifier si l'element accepte les connexions internes,
|
|
|
|
c'est-a-dire que ses bornes peuvent etre reliees entre elles
|
2007-12-16 14:05:39 +00:00
|
|
|
@param ic true pour que l'element accepte les connexions internes, false pour
|
2007-04-09 02:56:47 +00:00
|
|
|
qu'il les interdise
|
|
|
|
*/
|
2007-12-09 10:30:35 +00:00
|
|
|
inline void Element::setInternalConnections(bool ic) {
|
|
|
|
internal_connections = ic;
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de connaitre l'orientation actuelle de l'element
|
|
|
|
@return L'orientation actuelle de l'element
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
inline const OrientationSet & Element::orientation() const {
|
2007-04-09 02:56:47 +00:00
|
|
|
return(ori);
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|