2018-06-03 18:13:25 +00:00
|
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
|
Copyright 2006-2020 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"
|
2016-11-09 16:06:04 +00:00
|
|
|
|
#include "assignvariables.h"
|
2018-08-23 19:41:58 +00:00
|
|
|
|
#include "elementslocation.h"
|
|
|
|
|
#include "nameslist.h"
|
|
|
|
|
|
2017-02-03 13:48:42 +00:00
|
|
|
|
#include <algorithm>
|
2018-08-23 19:41:58 +00:00
|
|
|
|
#include <QPicture>
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
|
|
class QETProject;
|
|
|
|
|
class Terminal;
|
|
|
|
|
class Conductor;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
class DynamicElementTextItem;
|
2017-11-27 19:37:39 +00:00
|
|
|
|
class ElementTextItemGroup;
|
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
|
|
|
|
*/
|
2016-12-01 09:09:50 +00:00
|
|
|
|
class Element : public QetGraphicsItem
|
|
|
|
|
{
|
2017-10-19 09:10:23 +00:00
|
|
|
|
friend class DiagramEventAddElement;
|
|
|
|
|
|
2008-07-09 21:14:30 +00:00
|
|
|
|
Q_OBJECT
|
2007-04-12 03:13:13 +00:00
|
|
|
|
public:
|
2018-11-10 12:19:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief The kind enum
|
|
|
|
|
* Used to know the kind of this element (master, slave, report ect...)
|
|
|
|
|
*/
|
|
|
|
|
enum kind {Simple = 1,
|
2020-08-13 17:58:34 +02:00
|
|
|
|
NextReport = 2,
|
|
|
|
|
PreviousReport = 4,
|
|
|
|
|
AllReport = 6,
|
|
|
|
|
Master = 8,
|
|
|
|
|
Slave = 16,
|
|
|
|
|
Terminale = 32};
|
|
|
|
|
|
|
|
|
|
Element(const ElementsLocation &location,
|
|
|
|
|
QGraphicsItem * = nullptr,
|
|
|
|
|
int *state = nullptr,
|
|
|
|
|
Element::kind link_type = Element::Simple);
|
2017-08-05 02:10:01 +00:00
|
|
|
|
~Element() override;
|
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
|
|
|
|
/**
|
2016-12-08 16:54:41 +00:00
|
|
|
|
* Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into an Element.
|
2015-01-07 19:35:42 +00:00
|
|
|
|
* @return the QGraphicsItem type
|
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
|
enum { Type = UserType + 1000 };
|
2017-08-05 02:10:01 +00:00
|
|
|
|
int type() const override { return Type; }
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
2014-10-23 08:05:53 +00:00
|
|
|
|
signals:
|
2016-07-05 20:14:14 +00:00
|
|
|
|
void linkedElementChanged(); //This signal is emited when the linked elements with this element change
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void elementInfoChange(DiagramContext old_info,
|
|
|
|
|
DiagramContext new_info);
|
2017-11-27 19:37:39 +00:00
|
|
|
|
void textAdded(DynamicElementTextItem *deti);
|
|
|
|
|
void textRemoved(DynamicElementTextItem *deti);
|
|
|
|
|
void textsGroupAdded(ElementTextItemGroup *group);
|
|
|
|
|
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group);
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void textAddedToGroup(DynamicElementTextItem *text,
|
|
|
|
|
ElementTextItemGroup *group);
|
|
|
|
|
void textRemovedFromGroup(DynamicElementTextItem *text,
|
|
|
|
|
ElementTextItemGroup *group);
|
2014-03-21 14:40:33 +00:00
|
|
|
|
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
2014-10-23 08:05:53 +00:00
|
|
|
|
public:
|
2018-08-23 19:41:58 +00:00
|
|
|
|
QList<Terminal *> terminals() const;
|
|
|
|
|
QList<Conductor *> conductors() const;
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QList<QPair<Terminal *,Terminal *>> AlignedFreeTerminals() const;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
//METHODS related to information
|
2020-08-13 17:58:34 +02:00
|
|
|
|
DiagramContext elementInformations()const
|
|
|
|
|
{return m_element_informations;}
|
|
|
|
|
virtual void setElementInformations(DiagramContext dc);
|
|
|
|
|
DiagramContext kindInformations() const
|
|
|
|
|
{return m_kind_informations;} //@kind_information_ is used to store more information
|
2014-10-23 08:05:53 +00:00
|
|
|
|
//about the herited class like contactelement for know
|
|
|
|
|
// kind of contact (simple tempo) or number of contact show by the element.
|
2016-11-09 16:06:04 +00:00
|
|
|
|
|
2020-08-13 17:58:34 +02:00
|
|
|
|
autonum::sequentialNumbers sequenceStruct() const
|
|
|
|
|
{return m_autoNum_seq;}
|
|
|
|
|
autonum::sequentialNumbers& rSequenceStruct()
|
|
|
|
|
{return m_autoNum_seq;}
|
2016-12-01 09:09:50 +00:00
|
|
|
|
void setUpFormula(bool code_letter = true);
|
2016-07-13 21:25:29 +00:00
|
|
|
|
void setPrefix(QString);
|
2016-11-16 16:01:53 +00:00
|
|
|
|
QString getPrefix() const;
|
2016-12-10 12:00:52 +00:00
|
|
|
|
void freezeLabel(bool freeze);
|
2017-10-26 17:12:49 +00:00
|
|
|
|
bool isFreezeLabel() const {return m_freeze_label;}
|
2016-07-20 15:07:21 +00:00
|
|
|
|
void freezeNewAddedElement();
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QString actualLabel();
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
QString name() const override;
|
|
|
|
|
ElementsLocation location() const;
|
2015-03-04 21:13:13 +00:00
|
|
|
|
virtual void setHighlighted(bool);
|
|
|
|
|
void displayHelpLine(bool b = true);
|
|
|
|
|
QSize size() const;
|
|
|
|
|
QPixmap pixmap();
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QPoint setHotspot(QPoint);
|
|
|
|
|
QPoint hotspot() const;
|
|
|
|
|
void editProperty() override;
|
|
|
|
|
static bool valideXml(QDomElement &);
|
|
|
|
|
virtual bool fromXml(QDomElement &,
|
|
|
|
|
QHash<int,
|
|
|
|
|
Terminal *> &,
|
|
|
|
|
bool = false);
|
|
|
|
|
virtual QDomElement toXml(QDomDocument &,
|
|
|
|
|
QHash<Terminal *,
|
|
|
|
|
int> &) const;
|
|
|
|
|
QUuid uuid() const;
|
|
|
|
|
int orientation() const;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
//METHODS related to texts
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
|
|
|
|
|
void removeDynamicTextItem(DynamicElementTextItem *deti);
|
|
|
|
|
QList<DynamicElementTextItem *> dynamicTextItems() const;
|
2017-11-27 19:37:39 +00:00
|
|
|
|
ElementTextItemGroup *addTextGroup(const QString &name);
|
2017-11-29 14:49:12 +00:00
|
|
|
|
void addTextGroup(ElementTextItemGroup *group);
|
2017-11-27 19:37:39 +00:00
|
|
|
|
void removeTextGroup(ElementTextItemGroup *group);
|
|
|
|
|
ElementTextItemGroup *textGroup(const QString &name) const;
|
|
|
|
|
QList<ElementTextItemGroup *> textGroups() const;
|
2020-08-13 17:58:34 +02:00
|
|
|
|
bool addTextToGroup(DynamicElementTextItem *text,
|
|
|
|
|
ElementTextItemGroup *group);
|
|
|
|
|
bool removeTextFromGroup(DynamicElementTextItem *text,
|
|
|
|
|
ElementTextItemGroup *group);
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
//METHODS related to linked element
|
2020-08-13 17:58:34 +02:00
|
|
|
|
bool isFree() const;
|
|
|
|
|
virtual void linkToElement(Element *) {}
|
|
|
|
|
virtual void unlinkAllElements() {}
|
|
|
|
|
virtual void unlinkElement(Element *) {}
|
|
|
|
|
virtual void initLink(QETProject *);
|
2018-08-23 19:41:58 +00:00
|
|
|
|
QList<Element *> linkedElements ();
|
|
|
|
|
virtual kind linkType() const {return m_link_type;} // @return the linkable type
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QString linkTypeToString() const;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
|
2016-08-02 01:35:55 +00:00
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
|
protected:
|
2014-12-14 18:51:49 +00:00
|
|
|
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
2018-08-23 19:41:58 +00:00
|
|
|
|
void setSize(int, int);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void drawSelection(QPainter *,
|
|
|
|
|
const QStyleOptionGraphicsItem *);
|
|
|
|
|
void drawHighlight(QPainter *,
|
|
|
|
|
const QStyleOptionGraphicsItem *);
|
2018-08-23 19:41:58 +00:00
|
|
|
|
bool buildFromXml(const QDomElement &, int * = nullptr);
|
|
|
|
|
bool parseElement(const QDomElement &dom);
|
|
|
|
|
bool parseInput(const QDomElement &dom_element);
|
2020-08-13 17:58:34 +02:00
|
|
|
|
DynamicElementTextItem *parseDynamicText(
|
|
|
|
|
const QDomElement &dom_element);
|
2018-08-23 19:41:58 +00:00
|
|
|
|
Terminal *parseTerminal(const QDomElement &dom_element);
|
2014-11-16 14:15:32 +00:00
|
|
|
|
|
2018-08-23 19:41:58 +00:00
|
|
|
|
//Reimplemented from QGraphicsItem
|
|
|
|
|
public:
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void paint(QPainter *,
|
|
|
|
|
const QStyleOptionGraphicsItem *,
|
|
|
|
|
QWidget *) override;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
QRectF boundingRect() const override;
|
2014-11-16 14:15:32 +00:00
|
|
|
|
protected:
|
2020-08-13 17:58:34 +02:00
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
|
void mouseReleaseEvent(
|
|
|
|
|
QGraphicsSceneMouseEvent *event) override;
|
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
2015-01-07 19:35:42 +00:00
|
|
|
|
|
2017-10-19 09:10:23 +00:00
|
|
|
|
protected:
|
|
|
|
|
// @m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml)
|
|
|
|
|
// are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item
|
|
|
|
|
// and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QHash <DynamicElementTextItem *, QPointF>
|
|
|
|
|
m_converted_text_from_xml_description;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
//ATTRIBUTES related to linked element
|
|
|
|
|
QList <Element *> connected_elements;
|
|
|
|
|
QList <QUuid> tmp_uuids_link;
|
|
|
|
|
QUuid m_uuid;
|
2018-11-10 12:19:30 +00:00
|
|
|
|
kind m_link_type = Element::Simple;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
|
|
|
|
|
//ATTRIBUTES related to informations
|
|
|
|
|
DiagramContext m_element_informations, m_kind_informations;
|
|
|
|
|
autonum::sequentialNumbers m_autoNum_seq;
|
|
|
|
|
bool m_freeze_label = false;
|
|
|
|
|
QString m_F_str;
|
|
|
|
|
|
|
|
|
|
ElementsLocation m_location;
|
|
|
|
|
NamesList m_names;
|
|
|
|
|
QList <Terminal *> m_terminals;
|
|
|
|
|
const QPicture m_picture;
|
|
|
|
|
const QPicture m_low_zoom_picture;
|
|
|
|
|
|
2014-12-14 18:51:49 +00:00
|
|
|
|
private:
|
2018-08-23 19:41:58 +00:00
|
|
|
|
bool m_must_highlight = false;
|
|
|
|
|
QSize dimensions;
|
|
|
|
|
QPoint hotspot_coord;
|
|
|
|
|
bool m_mouse_over = false;
|
2016-07-13 21:25:29 +00:00
|
|
|
|
QString m_prefix;
|
2020-08-13 17:58:34 +02:00
|
|
|
|
QList <DynamicElementTextItem *> m_dynamic_text_list;
|
2017-11-27 19:37:39 +00:00
|
|
|
|
QList <ElementTextItemGroup *> m_texts_group;
|
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 {
|
2018-08-23 19:41:58 +00:00
|
|
|
|
return m_uuid;
|
2013-12-31 14:39:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2020-08-13 17:58:34 +02:00
|
|
|
|
std::sort(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
|