2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2013-06-18 11:10:19 +00:00
|
|
|
Copyright 2006-2013 The QElectroTech Team
|
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"
|
2013-11-14 10:11:22 +00:00
|
|
|
#include "qetgraphicsitem.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
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This is the base class for electrical elements.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2013-11-14 10:11:22 +00:00
|
|
|
class Element : public QetGraphicsItem {
|
2008-07-09 21:14:30 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
|
|
|
Element(QGraphicsItem * = 0, Diagram * = 0);
|
|
|
|
virtual ~Element();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Element(const Element &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1000 };
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
private:
|
|
|
|
QSize dimensions;
|
|
|
|
QPoint hotspot_coord;
|
2009-04-03 19:30:25 +00:00
|
|
|
QPixmap preview;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into an
|
|
|
|
Element.
|
|
|
|
@return the QGraphicsItem type
|
2007-12-16 13:21:28 +00:00
|
|
|
*/
|
2007-04-09 02:56:47 +00:00
|
|
|
virtual int type() const { return Type; }
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// pure virtual methods to be defined in derived classes
|
|
|
|
/// @return the list of terminals for this element
|
2007-09-05 20:42:08 +00:00
|
|
|
virtual QList<Terminal *> terminals() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the list of conductors attached to this element
|
2007-10-03 17:02:39 +00:00
|
|
|
virtual QList<Conductor *> conductors() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the list of text items attached to this element
|
2009-04-04 21:47:07 +00:00
|
|
|
virtual QList<ElementTextItem *> texts() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the current number of terminals of this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int terminalsCount() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the minimum number of terminals for this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int minTerminalsCount() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the maximum number of terminals for this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int maxTerminalsCount() const = 0;
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Draw this element
|
2007-12-16 13:21:28 +00:00
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return This element type ID
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual QString typeId() const = 0;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the human name for this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual QString name() const = 0;
|
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();
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to the hotspot
|
2007-04-12 03:13:13 +00:00
|
|
|
QPoint setHotspot(QPoint);
|
|
|
|
QPoint hotspot() const;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// selection-related methods
|
2007-04-12 03:13:13 +00:00
|
|
|
void select();
|
2013-11-14 10:11:22 +00:00
|
|
|
void deselect();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to internal connections
|
2007-12-09 10:30:35 +00:00
|
|
|
bool internalConnections();
|
|
|
|
void setInternalConnections(bool);
|
2013-11-14 10:11:22 +00:00
|
|
|
virtual void rotateBy(const qreal &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to XML import/export
|
2007-04-12 03:13:13 +00:00
|
|
|
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
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// orientation-related methods
|
2013-11-14 10:11:22 +00:00
|
|
|
int orientation() const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
|
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
bool internal_connections_;
|
2010-04-25 12:12:59 +00:00
|
|
|
bool must_highlight_;
|
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();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Indicate whether this element allows internal connections, i.e. whether its
|
|
|
|
terminals can be linked together using a conductor.
|
|
|
|
@return true if internal connections are accepted, false otherwise
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-12-09 10:30:35 +00:00
|
|
|
inline bool Element::internalConnections() {
|
2012-11-09 21:09:24 +00:00
|
|
|
return(internal_connections_);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Specify whether this element allows internal connections, i.e. whether its
|
|
|
|
terminals can be linked together using a conductor.
|
|
|
|
@return true for internal connections to be accepted, false otherwise
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-12-09 10:30:35 +00:00
|
|
|
inline void Element::setInternalConnections(bool ic) {
|
2012-11-09 21:09:24 +00:00
|
|
|
internal_connections_ = ic;
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Indicate the current orientation of this element
|
2013-11-14 10:11:22 +00:00
|
|
|
O = 0°
|
|
|
|
1 = 90°
|
|
|
|
2 = 180°
|
|
|
|
3 = 270°
|
2012-11-09 21:09:24 +00:00
|
|
|
@return the current orientation of this element
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2013-11-14 10:11:22 +00:00
|
|
|
inline int Element::orientation() const {
|
|
|
|
return(QET::correctAngle(rotation())/90);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|