2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2015-02-20 14:56:22 +00:00
|
|
|
Copyright 2006-2015 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
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
#include "qet.h"
|
2013-11-14 10:11:22 +00:00
|
|
|
#include "qetgraphicsitem.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "diagramcontext.h"
|
|
|
|
|
2009-04-04 21:47:07 +00:00
|
|
|
class ElementTextItem;
|
2014-07-21 20:44:32 +00:00
|
|
|
class QETProject;
|
|
|
|
class Terminal;
|
|
|
|
class Conductor;
|
2013-12-29 13:27:46 +00:00
|
|
|
|
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
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
class Element : public QetGraphicsItem {
|
2008-07-09 21:14:30 +00:00
|
|
|
Q_OBJECT
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2014-12-14 13:06:21 +00:00
|
|
|
// constructors, destructor
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2014-12-14 13:06:21 +00:00
|
|
|
Element(QGraphicsItem * = 0);
|
|
|
|
virtual ~Element();
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
2014-12-14 13:06:21 +00:00
|
|
|
Element(const Element &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2014-12-14 13:06:21 +00:00
|
|
|
// attributes
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2015-01-07 19:35:42 +00:00
|
|
|
/**
|
|
|
|
* Enable the use of qgraphicsitem_cast to safely cast
|
|
|
|
* a QGraphicsItem into an Element.
|
|
|
|
* @return the QGraphicsItem type
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
enum { Type = UserType + 1000 };
|
2015-01-07 19:35:42 +00:00
|
|
|
virtual int type() const { return Type; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The kind enum
|
|
|
|
* Used to know the kind of this element (master, slave, report ect...)
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
enum kind {Simple = 1,
|
|
|
|
NextReport = 2,
|
|
|
|
PreviousReport = 4,
|
|
|
|
AllReport = 6,
|
|
|
|
Master = 8,
|
|
|
|
Slave = 16,
|
|
|
|
Terminale = 32};
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
private:
|
2015-01-07 19:35:42 +00:00
|
|
|
QSize dimensions;
|
|
|
|
QPoint hotspot_coord;
|
|
|
|
QPixmap preview;
|
2014-02-12 17:36:35 +00:00
|
|
|
|
2015-01-07 19:35:42 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of terminals for this element
|
2007-09-05 20:42:08 +00:00
|
|
|
virtual QList<Terminal *> terminals() const = 0;
|
2015-01-07 19:35:42 +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;
|
2015-01-07 19:35:42 +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;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the text field tagged with @tagg or NULL if text field isn't found
|
2014-06-27 18:34:18 +00:00
|
|
|
virtual ElementTextItem* taggedText(const QString &tagg) const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of lines items in this element
|
2014-01-10 18:25:14 +00:00
|
|
|
virtual QList<QLineF *> lines() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of rectangles items in this element
|
2014-01-10 18:25:14 +00:00
|
|
|
virtual QList<QRectF *> rectangles() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of bounding rectangles for circles items in this element
|
2014-01-10 18:25:14 +00:00
|
|
|
virtual QList<QRectF *> circles() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of polygons in this element
|
2014-01-11 08:31:39 +00:00
|
|
|
virtual QList<QVector<QPointF> *> polygons() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the list of arcs in this element
|
2014-01-11 08:31:39 +00:00
|
|
|
virtual QList<QVector<qreal> *> arcs() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the current number of terminals of this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int terminalsCount() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the minimum number of terminals for this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int minTerminalsCount() const = 0;
|
2015-01-07 19:35:42 +00:00
|
|
|
/// @return the maximum number of terminals for this element
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int maxTerminalsCount() const = 0;
|
2013-12-31 14:39:34 +00:00
|
|
|
|
2015-01-09 17:18:16 +00:00
|
|
|
QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
|
2014-02-12 17:36:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*related method and attributes,
|
|
|
|
*about none graphic thing
|
|
|
|
*like the linked element or information about this element
|
|
|
|
*/
|
|
|
|
//METHODS related to linked element
|
2015-01-07 19:35:42 +00:00
|
|
|
public:
|
|
|
|
bool isFree () const;
|
|
|
|
virtual void linkToElement (Element *) {}
|
|
|
|
virtual void unlinkAllElements () {}
|
|
|
|
virtual void unlinkElement (Element *) {}
|
|
|
|
virtual void initLink (QETProject *);
|
|
|
|
QList<Element *> linkedElements ();
|
|
|
|
virtual int linkType() const {return link_type_;} // @return the linkable type
|
|
|
|
void newUuid() {uuid_ = QUuid::createUuid();} //create new uuid for this element
|
|
|
|
|
|
|
|
//ATTRIBUTES related to linked element
|
2014-10-23 08:05:53 +00:00
|
|
|
protected:
|
|
|
|
QList <Element *> connected_elements;
|
2015-01-07 19:35:42 +00:00
|
|
|
QList <QUuid> tmp_uuids_link;
|
|
|
|
QUuid uuid_;
|
|
|
|
kind link_type_;
|
2014-02-12 17:36:35 +00:00
|
|
|
|
2014-10-23 08:05:53 +00:00
|
|
|
signals:
|
2015-05-27 07:22:50 +00:00
|
|
|
void linkedElementChanged(); //This signal is emtied when the linked elements with this element change
|
2014-11-18 23:00:06 +00:00
|
|
|
void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
|
2014-03-21 14:40:33 +00:00
|
|
|
|
2015-01-09 17:18:16 +00:00
|
|
|
//METHODS related to information
|
2014-10-23 08:05:53 +00:00
|
|
|
public:
|
|
|
|
DiagramContext elementInformations ()const {return element_informations_;}
|
|
|
|
DiagramContext& rElementInformations () {return element_informations_;}
|
|
|
|
virtual void setElementInformations (DiagramContext dc);
|
|
|
|
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information
|
|
|
|
//about the herited class like contactelement for know
|
|
|
|
// kind of contact (simple tempo) or number of contact show by the element.
|
2014-02-12 17:36:35 +00:00
|
|
|
|
2014-10-23 08:05:53 +00:00
|
|
|
//ATTRIBUTES
|
|
|
|
protected:
|
|
|
|
DiagramContext element_informations_, kind_informations_;
|
2013-12-31 14:39:34 +00:00
|
|
|
|
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
|
|
|
*/
|
2014-02-12 17:36:35 +00:00
|
|
|
public:
|
2015-03-04 21:13:13 +00:00
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
|
|
|
|
/// @return This element type ID
|
|
|
|
virtual QString typeId() const = 0;
|
|
|
|
/// @return the human name for this element
|
|
|
|
virtual QString name() const = 0;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2015-03-04 21:13:13 +00:00
|
|
|
virtual bool isHighlighted() const;
|
|
|
|
virtual void setHighlighted(bool);
|
|
|
|
void displayHelpLine(bool b = true);
|
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QSize setSize(int, int);
|
|
|
|
QSize size() const;
|
|
|
|
QPixmap pixmap();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
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
|
|
|
|
2013-11-14 10:11:22 +00:00
|
|
|
virtual void rotateBy(const qreal &);
|
2013-11-29 14:42:03 +00:00
|
|
|
virtual void editProperty();
|
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;
|
2013-12-31 14:39:34 +00:00
|
|
|
QUuid uuid() 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:
|
2014-12-14 18:51:49 +00:00
|
|
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
private:
|
2014-12-14 18:51:49 +00:00
|
|
|
bool must_highlight_;
|
|
|
|
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
void updatePixmap();
|
2014-11-16 14:15:32 +00:00
|
|
|
|
|
|
|
protected:
|
2015-01-07 19:35:42 +00:00
|
|
|
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent *event );
|
|
|
|
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event );
|
|
|
|
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * );
|
|
|
|
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * );
|
|
|
|
|
2014-12-14 18:51:49 +00:00
|
|
|
private:
|
|
|
|
bool m_mouse_over;
|
2014-11-16 14:15:32 +00:00
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
2014-03-18 12:35:36 +00:00
|
|
|
bool comparPos(const Element * elmt1, const Element * elmt2);
|
|
|
|
|
2013-12-28 13:28:27 +00:00
|
|
|
inline bool Element::isFree() const {
|
|
|
|
return (connected_elements.isEmpty());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-31 14:39:34 +00:00
|
|
|
/**
|
|
|
|
* @brief Element::uuid
|
|
|
|
* @return the uuid of this element
|
|
|
|
*/
|
|
|
|
inline QUuid Element::uuid() const {
|
|
|
|
return uuid_;
|
|
|
|
}
|
|
|
|
|
2014-03-18 12:35:36 +00:00
|
|
|
/**
|
|
|
|
* @brief Element::linkedElements
|
|
|
|
* @return the list of linked elements, the list is sorted by position
|
|
|
|
*/
|
|
|
|
inline QList <Element *> Element::linkedElements() {
|
|
|
|
qSort(connected_elements.begin(), connected_elements.end(), comparPos);
|
2013-12-31 17:01:14 +00:00
|
|
|
return connected_elements;
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|