2007-12-01 10:47:15 +00:00
|
|
|
/*
|
|
|
|
Copyright 2006-2007 Xavier Guerrin
|
|
|
|
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;
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Cette classe abstraite represente un element electrique.
|
|
|
|
*/
|
|
|
|
class Element : public 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-06-30 17:41:07 +00:00
|
|
|
OrientationSet ori;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QSize dimensions;
|
|
|
|
QPoint hotspot_coord;
|
|
|
|
QPixmap apercu;
|
|
|
|
|
|
|
|
// methodes
|
|
|
|
public:
|
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-09-05 20:42:08 +00:00
|
|
|
virtual QList<Terminal *> terminals() const = 0;
|
2007-10-03 17:02:39 +00:00
|
|
|
virtual QList<Conductor *> conductors() const = 0;
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual int nbTerminals() const = 0;
|
|
|
|
virtual int nbTerminalsMin() const = 0;
|
|
|
|
virtual int nbTerminalsMax() const = 0;
|
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
|
|
|
|
virtual QString typeId() const = 0;
|
|
|
|
virtual QString nom() const = 0;
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QSize setSize(int, int);
|
|
|
|
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
|
|
|
|
bool connexionsInternesAcceptees();
|
|
|
|
void setConnexionsInternesAcceptees(bool cia);
|
|
|
|
|
|
|
|
// methodes relatives aux fichiers XML
|
|
|
|
static bool valideXml(QDomElement &);
|
2007-10-27 13:18:17 +00:00
|
|
|
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &);
|
|
|
|
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 *);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
2007-09-15 22:14:23 +00:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool peut_relier_ses_propres_terminals;
|
|
|
|
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
inline bool Element::connexionsInternesAcceptees() {
|
|
|
|
return(peut_relier_ses_propres_terminals);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de specifier si l'element accepte les connexions internes,
|
|
|
|
c'est-a-dire que ses bornes peuvent etre reliees entre elles
|
|
|
|
@param cia true pour que l'element accepte les connexions internes, false pour
|
|
|
|
qu'il les interdise
|
|
|
|
*/
|
|
|
|
inline void Element::setConnexionsInternesAcceptees(bool cia) {
|
|
|
|
peut_relier_ses_propres_terminals = cia;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|