mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Revert pull request #48
This commit is contained in:
@@ -863,53 +863,6 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider
|
||||
return(from_xml);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief findTerminal
|
||||
* Find terminal to which the conductor should be connected
|
||||
* \param conductor_index 1 or 2 depending on which terminal is searched
|
||||
* \param f Conductor xml element
|
||||
* \param table_adr_id Hash table to all terminal id assignement (legacy)
|
||||
* \param added_elements Elements found in the xml file
|
||||
* \return
|
||||
*/
|
||||
Terminal* findTerminal(int conductor_index, QDomElement& f, QHash<int, Terminal *>& table_adr_id, QList<Element *>& added_elements) {
|
||||
assert(conductor_index == 1 || conductor_index == 2);
|
||||
|
||||
QString element_index = "element" + QString::number(conductor_index);
|
||||
QString terminal_index = "terminal" + QString::number(conductor_index);
|
||||
|
||||
if (f.hasAttribute(element_index)) {
|
||||
QUuid element_uuid = QUuid(f.attribute(element_index));
|
||||
// element1 did not exist in the conductor part of the xml until prior 0.7
|
||||
// It is used as an indicator that uuid's are used to identify terminals
|
||||
bool element_found = false;
|
||||
for (auto element: added_elements) {
|
||||
if (element->uuid() != element_uuid)
|
||||
continue;
|
||||
element_found = true;
|
||||
QUuid terminal_uuid = QUuid(f.attribute(terminal_index));
|
||||
for (auto terminal: element->terminals()) {
|
||||
if (terminal->uuid() != terminal_uuid)
|
||||
continue;
|
||||
|
||||
return terminal;
|
||||
}
|
||||
qDebug() << "Diagram::fromXml() : "<< terminal_index << ":" << terminal_uuid << "not found in " << element_index << ":" << element_uuid;
|
||||
break;
|
||||
}
|
||||
if (!element_found)
|
||||
qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found";
|
||||
} else {
|
||||
// Backward compatibility. Until version 0.7 a generated id is used to link the terminal.
|
||||
int id_p1 = f.attribute(terminal_index).toInt();
|
||||
if (!table_adr_id.contains(id_p1)) {
|
||||
qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found";
|
||||
} else
|
||||
return table_adr_id.value(id_p1);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Importe le schema decrit dans un element XML. Si une position est
|
||||
precisee, les elements importes sont positionnes de maniere a ce que le
|
||||
@@ -1078,22 +1031,26 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
if (!Conductor::valideXml(f)) continue;
|
||||
|
||||
//Check if terminal that conductor must be linked is know
|
||||
|
||||
Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements);
|
||||
Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements);
|
||||
|
||||
if (p1 && p2 && p1 != p2)
|
||||
{
|
||||
Conductor *c = new Conductor(p1, p2);
|
||||
if (c->isValid())
|
||||
{
|
||||
addItem(c);
|
||||
c -> fromXml(f);
|
||||
added_conductors << c;
|
||||
}
|
||||
else
|
||||
delete c;
|
||||
}
|
||||
int id_p1 = f.attribute("terminal1").toInt();
|
||||
int id_p2 = f.attribute("terminal2").toInt();
|
||||
if (table_adr_id.contains(id_p1) && table_adr_id.contains(id_p2))
|
||||
{
|
||||
Terminal *p1 = table_adr_id.value(id_p1);
|
||||
Terminal *p2 = table_adr_id.value(id_p2);
|
||||
if (p1 != p2)
|
||||
{
|
||||
Conductor *c = new Conductor(p1, p2);
|
||||
if (c->isValid())
|
||||
{
|
||||
addItem(c);
|
||||
c -> fromXml(f);
|
||||
added_conductors << c;
|
||||
}
|
||||
else
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
else qDebug() << "Diagram::fromXml() : Le chargement du conducteur" << id_p1 << id_p2 << "a echoue";
|
||||
}
|
||||
|
||||
//Load tables
|
||||
|
||||
@@ -25,11 +25,9 @@
|
||||
@param scene La scene sur laquelle figure cette borne
|
||||
*/
|
||||
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
CustomElementGraphicPart(editor, parent)
|
||||
CustomElementGraphicPart(editor, parent),
|
||||
m_orientation(Qet::North)
|
||||
{
|
||||
d = new TerminalData(this);
|
||||
d->m_orientation = Qet::North;
|
||||
d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
||||
updateSecondPoint();
|
||||
setZValue(100000);
|
||||
}
|
||||
@@ -43,8 +41,15 @@ PartTerminal::~PartTerminal() {
|
||||
@param xml_elmt Element XML a lire
|
||||
*/
|
||||
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
d->fromXml(xml_elmt);
|
||||
setPos(d->m_pos);
|
||||
// lit la position de la borne
|
||||
qreal term_x = 0.0, term_y = 0.0;
|
||||
QET::attributeIsAReal(xml_elmt, "x", &term_x);
|
||||
QET::attributeIsAReal(xml_elmt, "y", &term_y);
|
||||
setPos(QPointF(term_x, term_y));
|
||||
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = Qet::orientationFromString(xml_elmt.attribute("orientation"));
|
||||
|
||||
updateSecondPoint();
|
||||
}
|
||||
|
||||
@@ -54,7 +59,18 @@ void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
@return un element XML decrivant la borne
|
||||
*/
|
||||
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
|
||||
return d->toXml(xml_document);
|
||||
QDomElement xml_element = xml_document.createElement("terminal");
|
||||
|
||||
// ecrit la position de la borne
|
||||
xml_element.setAttribute("x", QString("%1").arg(scenePos().x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(scenePos().y()));
|
||||
|
||||
|
||||
// ecrit l'orientation de la borne
|
||||
xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
|
||||
// Write name and number to XML
|
||||
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +95,7 @@ void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, Q
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||
p -> setPen(t);
|
||||
p -> drawLine(QPointF(0.0, 0.0), d->second_point);
|
||||
p -> drawLine(QPointF(0.0, 0.0), second_point);
|
||||
|
||||
// dessin du point d'amarrage au conducteur en bleu
|
||||
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
||||
@@ -99,7 +115,7 @@ void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, Q
|
||||
QPainterPath PartTerminal::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.lineTo(d->second_point);
|
||||
shape.lineTo(second_point);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(1);
|
||||
@@ -113,7 +129,7 @@ QPainterPath PartTerminal::shape() const
|
||||
*/
|
||||
QRectF PartTerminal::boundingRect() const
|
||||
{
|
||||
QRectF br(QPointF(0, 0), d->second_point);
|
||||
QRectF br(QPointF(0, 0), second_point);
|
||||
br = br.normalized();
|
||||
|
||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||
@@ -127,31 +143,24 @@ QRectF PartTerminal::boundingRect() const
|
||||
*/
|
||||
void PartTerminal::setOrientation(Qet::Orientation ori)
|
||||
{
|
||||
if (d->m_orientation == ori) return;
|
||||
if (m_orientation == ori) return;
|
||||
prepareGeometryChange();
|
||||
d->m_orientation = ori;
|
||||
m_orientation = ori;
|
||||
updateSecondPoint();
|
||||
emit orientationChanged();
|
||||
}
|
||||
|
||||
void PartTerminal::setName(QString& name)
|
||||
{
|
||||
if (d->m_name == name) return;
|
||||
d->m_name = name;
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
Met a jour la position du second point en fonction de la position et de
|
||||
l'orientation de la borne.
|
||||
*/
|
||||
void PartTerminal::updateSecondPoint() {
|
||||
qreal ts = 4.0; // terminal size
|
||||
switch(d->m_orientation) {
|
||||
case Qet::North: d->second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d->second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d->second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d->second_point = QPointF(ts, 0.0); break;
|
||||
switch(m_orientation) {
|
||||
case Qet::North: second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : second_point = QPointF(ts, 0.0); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#define PART_TERMINAL_H
|
||||
|
||||
#include "customelementgraphicpart.h"
|
||||
#include "QUuid"
|
||||
#include "terminaldata.h"
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +31,6 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
|
||||
|
||||
public:
|
||||
@@ -45,7 +42,12 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
|
||||
signals:
|
||||
void orientationChanged();
|
||||
void nameChanged();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
Qet::Orientation m_orientation;
|
||||
QPointF second_point;
|
||||
|
||||
|
||||
// methods
|
||||
public:
|
||||
@@ -55,7 +57,7 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
* @return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
QString name() const override { return d->m_name; }
|
||||
QString name() const override { return(QObject::tr("borne", "element part name")); }
|
||||
QString xmlName() const override { return(QString("terminal")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
@@ -69,14 +71,11 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
|
||||
Qet::Orientation orientation() const {return d->m_orientation;}
|
||||
Qet::Orientation orientation() const {return m_orientation;}
|
||||
void setOrientation(Qet::Orientation ori);
|
||||
|
||||
void setName(QString& name);
|
||||
|
||||
private:
|
||||
void updateSecondPoint();
|
||||
TerminalData* d; // pointer to the terminal data
|
||||
|
||||
private:
|
||||
QPointF saved_position_;
|
||||
|
||||
@@ -34,8 +34,8 @@ class PropertiesInterface
|
||||
virtual void toSettings (QSettings &settings, const QString = QString()) const =0;
|
||||
virtual void fromSettings (const QSettings &settings, const QString = QString()) =0;
|
||||
// Save/load properties to xml element
|
||||
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
|
||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
||||
virtual void toXml (QDomElement &xml_element) const =0;
|
||||
virtual void fromXml (const QDomElement &xml_element) =0;
|
||||
};
|
||||
|
||||
#endif // PROPERTIESINTERFACE_H
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "terminaldata.h"
|
||||
|
||||
#include <QGraphicsObject>
|
||||
|
||||
TerminalData::TerminalData():
|
||||
PropertiesInterface()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
TerminalData::TerminalData(QGraphicsObject *parent):
|
||||
PropertiesInterface(),
|
||||
q(parent)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void TerminalData::init() {
|
||||
}
|
||||
|
||||
TerminalData::~TerminalData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TerminalData::setParent(QGraphicsObject* parent)
|
||||
{
|
||||
q = parent;
|
||||
}
|
||||
|
||||
void TerminalData::toSettings(QSettings &settings, const QString) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TerminalData::fromSettings(const QSettings &settings, const QString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("terminal");
|
||||
|
||||
// ecrit la position de la borne
|
||||
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
|
||||
|
||||
|
||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
||||
xml_element.setAttribute("name", m_name);
|
||||
|
||||
// ecrit l'orientation de la borne
|
||||
xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
|
||||
// Write name and number to XML
|
||||
|
||||
return(xml_element);
|
||||
}
|
||||
bool TerminalData::fromXml (const QDomElement &xml_element)
|
||||
{
|
||||
// lit la position de la borne
|
||||
qreal term_x = 0.0, term_y = 0.0;
|
||||
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
|
||||
return false;
|
||||
|
||||
if (!QET::attributeIsAReal(xml_element, "y", &term_y))
|
||||
return false;
|
||||
|
||||
m_pos = QPointF(term_x, term_y);
|
||||
|
||||
//emit posFromXML(QPointF(term_x, term_y));
|
||||
|
||||
QString uuid = xml_element.attribute("uuid");
|
||||
// update part and add uuid, which is used in the new version to connect terminals together
|
||||
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
|
||||
// to identify terminals
|
||||
if (!uuid.isEmpty())
|
||||
m_uuid = QUuid(uuid);
|
||||
|
||||
m_name = xml_element.attribute("name");
|
||||
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = Qet::orientationFromString(xml_element.attribute("orientation"));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef TERMINALDATA_H
|
||||
#define TERMINALDATA_H
|
||||
|
||||
#include "propertiesinterface.h"
|
||||
#include "qet.h"
|
||||
|
||||
#include <QUuid>
|
||||
#include <QPointF>
|
||||
|
||||
class QGraphicsObject;
|
||||
|
||||
/*!
|
||||
* \brief The TerminalData class
|
||||
* Data of the terminal. Stored in extra class so it can be used by PartTerminal and Terminal without
|
||||
* defining everything again.
|
||||
*/
|
||||
class TerminalData : public PropertiesInterface
|
||||
{
|
||||
public:
|
||||
TerminalData();
|
||||
TerminalData(QGraphicsObject* parent);
|
||||
~TerminalData();
|
||||
|
||||
void init();
|
||||
|
||||
void setParent(QGraphicsObject* parent);
|
||||
|
||||
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre
|
||||
void toSettings(QSettings &settings, const QString = QString()) const override;
|
||||
void fromSettings(const QSettings &settings, const QString = QString()) override;
|
||||
// Save/load properties to xml element
|
||||
// This method is only called from the PartTerminal and should never called from the Terminal class
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
|
||||
// must be public, because this class is a private member of PartTerminal/Terminal and they must
|
||||
// access this data
|
||||
public:
|
||||
/*!
|
||||
* \brief m_orientation
|
||||
* Orientation of the terminal
|
||||
*/
|
||||
Qet::Orientation m_orientation;
|
||||
/*!
|
||||
* \brief second_point
|
||||
* Position of the second point of the terminal in scene coordinates
|
||||
*/
|
||||
QPointF second_point;
|
||||
/*!
|
||||
* \brief m_uuid
|
||||
* Uuid of the terminal.
|
||||
*
|
||||
* In elementscene.cpp an element gets a new uuid when saving the element. In the current state
|
||||
* each connection is made by using the local position of the terminal and a dynamic id. In the new
|
||||
* case, each terminal should have it's own uuid to identify it uniquely. When changing each time this
|
||||
* uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists,
|
||||
* use this one and don't create a new one.
|
||||
*/
|
||||
QUuid m_uuid;
|
||||
/*!
|
||||
* \brief m_name
|
||||
* Name of the element. It can be used to create wiring harness tables
|
||||
*/
|
||||
QString m_name;
|
||||
|
||||
/*!
|
||||
* \brief m_pos
|
||||
* Position of the terminal. The second point is calculated from this position and the orientation
|
||||
* Important: this variable is only updated during read from xml and not during mouse move!
|
||||
* It is used to store the initial position so that PartTerminal and Terminal have access to it.
|
||||
*/
|
||||
QPointF m_pos;
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
};
|
||||
|
||||
#endif // TERMINALDATA_H
|
||||
@@ -93,12 +93,8 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi
|
||||
* Save to xml
|
||||
* @param xml_element: QDomElement to use for saving
|
||||
*/
|
||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
||||
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
xml_element.setAttribute("type", m_key);
|
||||
|
||||
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
|
||||
void XRefProperties::toXml(QDomElement &xml_element) const {
|
||||
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
xml_element.setAttribute("displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
@@ -118,8 +114,6 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.setAttribute(key + "prefix", m_prefix.value(key));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +121,7 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
||||
* Load from xml
|
||||
* @param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
void XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
|
||||
QString display = xml_element.attribute("displayhas", "cross");
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
@@ -149,7 +143,6 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
foreach (QString key, m_prefix_keys) {
|
||||
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,8 +42,8 @@ class XRefProperties : public PropertiesInterface
|
||||
|
||||
void toSettings (QSettings &settings, const QString = QString()) const override;
|
||||
void fromSettings (const QSettings &settings, const QString = QString()) override;
|
||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void toXml (QDomElement &xml_element) const override;
|
||||
void fromXml (const QDomElement &xml_element) override;
|
||||
|
||||
static QHash<QString, XRefProperties> defaultProperties();
|
||||
|
||||
@@ -73,8 +73,6 @@ class XRefProperties : public PropertiesInterface
|
||||
void setOffset(const int offset) {m_offset = offset;}
|
||||
int offset() const {return m_offset;}
|
||||
|
||||
void setKey(QString& key) {m_key = key;}
|
||||
|
||||
private:
|
||||
bool m_show_power_ctc;
|
||||
DisplayHas m_display;
|
||||
@@ -85,7 +83,6 @@ class XRefProperties : public PropertiesInterface
|
||||
QString m_master_label;
|
||||
QString m_slave_label;
|
||||
int m_offset;
|
||||
QString m_key;
|
||||
};
|
||||
|
||||
#endif // XREFPROPERTIES_H
|
||||
|
||||
@@ -581,27 +581,13 @@ bool Conductor::valideXml(QDomElement &e){
|
||||
if (!e.hasAttribute("terminal2")) return(false);
|
||||
|
||||
bool conv_ok;
|
||||
// parse l'abscisse
|
||||
if (e.hasAttribute("element1")) {
|
||||
if (QUuid(e.attribute("element1")).isNull())
|
||||
return false;
|
||||
if (QUuid(e.attribute("terminal1")).isNull())
|
||||
return false;
|
||||
} else {
|
||||
e.attribute("terminal1").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
}
|
||||
// parse l'abscisse
|
||||
e.attribute("terminal1").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
|
||||
// parse l'ordonnee
|
||||
if (e.hasAttribute("element2")) {
|
||||
if (QUuid(e.attribute("element2")).isNull())
|
||||
return false;
|
||||
if (QUuid(e.attribute("terminal2")).isNull())
|
||||
return false;
|
||||
} else {
|
||||
e.attribute("terminal2").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
}
|
||||
e.attribute("terminal2").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -1010,23 +996,8 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
||||
|
||||
dom_element.setAttribute("x", QString::number(pos().x()));
|
||||
dom_element.setAttribute("y", QString::number(pos().y()));
|
||||
|
||||
// Terminal is uniquely identified by the uuid of the terminal and the element
|
||||
if (terminal1->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
|
||||
}
|
||||
|
||||
if (terminal2->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
|
||||
}
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2));
|
||||
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
|
||||
|
||||
// on n'exporte les segments du conducteur que si ceux-ci ont
|
||||
@@ -1062,8 +1033,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
||||
|
||||
/**
|
||||
* @brief Conductor::pathFromXml
|
||||
* Generate the path (of the line) from xml file by checking the segments in the xml
|
||||
* file
|
||||
* Generate the path from xml file
|
||||
* @param e
|
||||
* @return true if generate path success else return false
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "elementprovider.h"
|
||||
#include "diagramposition.h"
|
||||
#include "terminal.h"
|
||||
#include "terminaldata.h"
|
||||
#include "PropertiesEditor/propertieseditordialog.h"
|
||||
#include "elementpropertieswidget.h"
|
||||
#include "numerotationcontextcommands.h"
|
||||
@@ -561,22 +560,36 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
|
||||
return deti;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Element::parseTerminal
|
||||
* Parse partTerminal from xml structure
|
||||
* \param dom_element
|
||||
* \return
|
||||
*/
|
||||
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
||||
{
|
||||
|
||||
TerminalData* data = new TerminalData();
|
||||
if (!data->fromXml(dom_element)) {
|
||||
delete data;
|
||||
return nullptr;
|
||||
}
|
||||
qreal terminalx, terminaly;
|
||||
Qet::Orientation terminalo;
|
||||
if (!QET::attributeIsAReal(dom_element, QString("x"), &terminalx)) {
|
||||
return(nullptr);
|
||||
}
|
||||
if (!QET::attributeIsAReal(dom_element, QString("y"), &terminaly)) {
|
||||
return(nullptr);
|
||||
}
|
||||
if (!dom_element.hasAttribute("orientation")) {
|
||||
return(nullptr);
|
||||
}
|
||||
if (dom_element.attribute("orientation") == "n") {
|
||||
terminalo = Qet::North;
|
||||
}
|
||||
else if (dom_element.attribute("orientation") == "s") {
|
||||
terminalo = Qet::South;
|
||||
}
|
||||
else if (dom_element.attribute("orientation") == "e") {
|
||||
terminalo = Qet::East;
|
||||
}
|
||||
else if (dom_element.attribute("orientation") == "w") {
|
||||
terminalo = Qet::West;
|
||||
}
|
||||
else {
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
Terminal *new_terminal = new Terminal(data, this);
|
||||
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
|
||||
m_terminals << new_terminal;
|
||||
|
||||
//Sort from top to bottom and left to rigth
|
||||
@@ -1047,7 +1060,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
foreach(Terminal *t, terminals()) {
|
||||
// alors on enregistre la borne
|
||||
QDomElement terminal = t -> toXml(document);
|
||||
terminal.setAttribute("id", id_terminal); // for backward compatibility
|
||||
terminal.setAttribute("id", id_terminal);
|
||||
table_adr_id.insert(t, id_terminal ++);
|
||||
xml_terminals.appendChild(terminal);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "diagramcommands.h"
|
||||
#include "conductorautonumerotation.h"
|
||||
#include "conductortextitem.h"
|
||||
#include "terminaldata.h"
|
||||
|
||||
QColor Terminal::neutralColor = QColor(Qt::blue);
|
||||
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
||||
@@ -40,13 +39,17 @@ const qreal Terminal::Z = 1000;
|
||||
@param number of terminal
|
||||
@param name of terminal
|
||||
*/
|
||||
void Terminal::init(QString number, QString name, bool hiddenName) {
|
||||
|
||||
hovered_color_ = Terminal::neutralColor;
|
||||
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName) {
|
||||
// definition du pount d'amarrage pour un conducteur
|
||||
dock_conductor_ = pf;
|
||||
|
||||
// definition de l'orientation de la borne (par defaut : sud)
|
||||
if (o < Qet::North || o > Qet::West) ori_ = Qet::South;
|
||||
else ori_ = o;
|
||||
|
||||
// calcul de la position du point d'amarrage a l'element
|
||||
dock_elmt_ = d->m_pos;
|
||||
switch(d->m_orientation) {
|
||||
dock_elmt_ = dock_conductor_;
|
||||
switch(ori_) {
|
||||
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
|
||||
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
|
||||
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
|
||||
@@ -71,27 +74,6 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
|
||||
setZValue(Z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Terminal::init
|
||||
* Additionaly to the init above, this method stores position and orientation into the data class
|
||||
* \param pf
|
||||
* \param o
|
||||
* \param number
|
||||
* \param name
|
||||
* \param hiddenName
|
||||
*/
|
||||
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName)
|
||||
{
|
||||
// definition du pount d'amarrage pour un conducteur
|
||||
d->m_pos = pf;
|
||||
|
||||
// definition de l'orientation de la borne (par defaut : sud)
|
||||
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
|
||||
else d->m_orientation = o;
|
||||
|
||||
init(number, name, hiddenName);
|
||||
}
|
||||
|
||||
/**
|
||||
initialise une borne
|
||||
@param pf position du point d'amarrage pour un conducteur
|
||||
@@ -101,8 +83,11 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
|
||||
*/
|
||||
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
||||
QGraphicsObject(e),
|
||||
d(new TerminalData(this)),
|
||||
parent_element_ (e)
|
||||
m_draw_help_line(false),
|
||||
m_help_line (nullptr),
|
||||
m_help_line_a (nullptr),
|
||||
parent_element_ (e),
|
||||
hovered_color_ (Terminal::neutralColor)
|
||||
{
|
||||
init(pf, o, "_", "_", false);
|
||||
}
|
||||
@@ -117,10 +102,13 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
||||
*/
|
||||
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
||||
QGraphicsObject(e),
|
||||
d(new TerminalData(this)),
|
||||
parent_element_ (e)
|
||||
m_draw_help_line (false),
|
||||
m_help_line (nullptr),
|
||||
m_help_line_a (nullptr),
|
||||
parent_element_ (e),
|
||||
hovered_color_ (Terminal::neutralColor)
|
||||
{
|
||||
init(QPointF(pf_x, pf_y), o, "_", "_", false);
|
||||
init(QPointF(pf_x, pf_y), o, "_", "_", false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,22 +123,15 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
||||
*/
|
||||
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
|
||||
QGraphicsObject (e),
|
||||
d(new TerminalData(this)),
|
||||
parent_element_ (e)
|
||||
m_draw_help_line (false),
|
||||
m_help_line (nullptr),
|
||||
m_help_line_a (nullptr),
|
||||
parent_element_ (e),
|
||||
hovered_color_ (Terminal::neutralColor)
|
||||
{
|
||||
init(pf, o, std::move(num), std::move(name), hiddenName);
|
||||
}
|
||||
|
||||
Terminal::Terminal(TerminalData* data, Element* e) :
|
||||
QGraphicsObject(e),
|
||||
d(data),
|
||||
parent_element_(e)
|
||||
{
|
||||
// TODO: what is when multiple parents exist. So the other relation is lost.
|
||||
d->setParent(this);
|
||||
init("_", "_", false);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructeur
|
||||
La destruction de la borne entraine la destruction des conducteurs
|
||||
@@ -172,15 +153,15 @@ Qet::Orientation Terminal::orientation() const {
|
||||
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
||||
// orientations actuelle et par defaut de l'element
|
||||
int ori_cur = elt -> orientation();
|
||||
if (ori_cur == 0) return(d->m_orientation);
|
||||
if (ori_cur == 0) return(ori_);
|
||||
else {
|
||||
// calcul l'angle de rotation implique par l'orientation de l'element parent
|
||||
// angle de rotation de la borne sur la scene, divise par 90
|
||||
int angle = ori_cur + d->m_orientation;
|
||||
int angle = ori_cur + ori_;
|
||||
while (angle >= 4) angle -= 4;
|
||||
return((Qet::Orientation)angle);
|
||||
}
|
||||
} else return(d->m_orientation);
|
||||
} else return(ori_);
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +238,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
|
||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
// on travaille avec les coordonnees de l'element parent
|
||||
QPointF c = mapFromParent(d->m_pos);
|
||||
QPointF c = mapFromParent(dock_conductor_);
|
||||
QPointF e = mapFromParent(dock_elmt_);
|
||||
|
||||
QPen t;
|
||||
@@ -409,11 +390,11 @@ QLineF Terminal::HelpLine() const
|
||||
*/
|
||||
QRectF Terminal::boundingRect() const {
|
||||
if (br_ -> isNull()) {
|
||||
qreal dcx = d->m_pos.x();
|
||||
qreal dcy = d->m_pos.y();
|
||||
qreal dcx = dock_conductor_.x();
|
||||
qreal dcy = dock_conductor_.y();
|
||||
qreal dex = dock_elmt_.x();
|
||||
qreal dey = dock_elmt_.y();
|
||||
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
|
||||
QPointF origin = (dcx <= dex && dcy <= dey ? dock_conductor_ : dock_elmt_);
|
||||
origin += QPointF(-3.0, -3.0);
|
||||
qreal w = qAbs((int)(dcx - dex)) + 7;
|
||||
qreal h = qAbs((int)(dcy - dey)) + 7;
|
||||
@@ -511,10 +492,10 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (Diagram *diag = diagram()) {
|
||||
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
|
||||
diag -> setConductorStop(e -> scenePos());
|
||||
diag -> setConductor(true);
|
||||
if (Diagram *d = diagram()) {
|
||||
d -> setConductorStart(mapToScene(QPointF(dock_conductor_)));
|
||||
d -> setConductorStop(e -> scenePos());
|
||||
d -> setConductor(true);
|
||||
//setCursor(Qt::CrossCursor);
|
||||
}
|
||||
}
|
||||
@@ -536,13 +517,13 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
|
||||
|
||||
Diagram *diag = diagram();
|
||||
if (!diag) return;
|
||||
Diagram *d = diagram();
|
||||
if (!d) return;
|
||||
// si la scene est un Diagram, on actualise le poseur de conducteur
|
||||
diag -> setConductorStop(e -> scenePos());
|
||||
d -> setConductorStop(e -> scenePos());
|
||||
|
||||
// on recupere la liste des qgi sous le pointeur
|
||||
QList<QGraphicsItem *> qgis = diag -> items(e -> scenePos());
|
||||
QList<QGraphicsItem *> qgis = d -> items(e -> scenePos());
|
||||
|
||||
/* le qgi le plus haut
|
||||
= le poseur de conductor
|
||||
@@ -678,10 +659,6 @@ bool Terminal::isLinkedTo(Terminal *other_terminal) {
|
||||
|
||||
/**
|
||||
* @brief Terminal::canBeLinkedTo
|
||||
* Checking if the terminal can be linked to \p other_terminal or not
|
||||
* Reasons for not linable:
|
||||
* - \p other_terminal is this terminal
|
||||
* - this terminal is already connected to \p other_terminal
|
||||
* @param other_terminal
|
||||
* @return true if this terminal can be linked to @other_terminal,
|
||||
* otherwise false
|
||||
@@ -708,9 +685,9 @@ QList<Conductor *> Terminal::conductors() const {
|
||||
*/
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
QDomElement qdo = doc.createElement("terminal");
|
||||
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); // for backward compatibility
|
||||
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));// for backward compatibility
|
||||
qdo.setAttribute("orientation", d->m_orientation);
|
||||
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
|
||||
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
|
||||
qdo.setAttribute("orientation", ori_);
|
||||
qdo.setAttribute("number", number_terminal_);
|
||||
qdo.setAttribute("name", name_terminal_);
|
||||
qdo.setAttribute("nameHidden", name_terminal_hidden);
|
||||
@@ -762,22 +739,13 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
||||
number_terminal_ = terminal.attribute("number");
|
||||
name_terminal_ = terminal.attribute("name");
|
||||
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
||||
|
||||
return (
|
||||
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
|
||||
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
|
||||
(terminal.attribute("orientation").toInt() == d->m_orientation)
|
||||
(terminal.attribute("orientation").toInt() == ori_)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the position, relative to the scene, of the docking point for
|
||||
conductors.
|
||||
*/
|
||||
inline QPointF Terminal::dockConductor() const {
|
||||
return(mapToScene(d->m_pos));
|
||||
}
|
||||
|
||||
/**
|
||||
@return le Diagram auquel cette borne appartient, ou 0 si cette borne est independant
|
||||
*/
|
||||
@@ -792,10 +760,6 @@ Element *Terminal::parentElement() const {
|
||||
return(parent_element_);
|
||||
}
|
||||
|
||||
QUuid Terminal::uuid() const {
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conductor::relatedPotentialTerminal
|
||||
* Return terminal at the same potential from the same
|
||||
|
||||
@@ -23,12 +23,9 @@
|
||||
class Conductor;
|
||||
class Diagram;
|
||||
class Element;
|
||||
class TerminalData;
|
||||
|
||||
/**
|
||||
This class represents a terminal of an electrical element, i.e. a possible
|
||||
plug point for conductors.
|
||||
This class handles all mouse events for connecting conductors
|
||||
*/
|
||||
class Terminal : public QGraphicsObject
|
||||
{
|
||||
@@ -42,7 +39,6 @@ class Terminal : public QGraphicsObject
|
||||
public:
|
||||
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
|
||||
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
|
||||
Terminal(TerminalData* data, Element *e = nullptr);
|
||||
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
|
||||
~Terminal() override;
|
||||
|
||||
@@ -67,7 +63,6 @@ class Terminal : public QGraphicsObject
|
||||
int conductorsCount () const;
|
||||
Diagram *diagram () const;
|
||||
Element *parentElement () const;
|
||||
QUuid uuid () const;
|
||||
|
||||
QList<Conductor *> conductors() const;
|
||||
Qet::Orientation orientation() const;
|
||||
@@ -111,23 +106,24 @@ class Terminal : public QGraphicsObject
|
||||
static QColor forbiddenColor;
|
||||
|
||||
private:
|
||||
bool m_draw_help_line{false};
|
||||
QGraphicsLineItem *m_help_line{nullptr};
|
||||
QGraphicsLineItem *m_help_line_a{nullptr};
|
||||
|
||||
|
||||
TerminalData* d;
|
||||
bool m_draw_help_line;
|
||||
QGraphicsLineItem *m_help_line;
|
||||
QGraphicsLineItem *m_help_line_a;
|
||||
|
||||
/// Parent electrical element
|
||||
Element *parent_element_{nullptr};
|
||||
Element *parent_element_;
|
||||
/// docking point for conductors
|
||||
QPointF dock_conductor_;
|
||||
/// docking point for parent element
|
||||
QPointF dock_elmt_;
|
||||
/// terminal orientation
|
||||
Qet::Orientation ori_;
|
||||
/// List of conductors attached to the terminal
|
||||
QList<Conductor *> conductors_;
|
||||
/// Pointer to a rectangle representing the terminal bounding rect;
|
||||
/// used to calculate the bounding rect once only;
|
||||
/// used a pointer because boundingRect() is supposed to be const.
|
||||
QRectF *br_{nullptr};
|
||||
QRectF *br_;
|
||||
/// Last terminal seen through an attached conductor
|
||||
Terminal *previous_terminal_;
|
||||
/// Whether the mouse pointer is hovering the terminal
|
||||
@@ -141,8 +137,7 @@ class Terminal : public QGraphicsObject
|
||||
bool name_terminal_hidden;
|
||||
|
||||
private:
|
||||
void init(QString number, QString name, bool hiddenName);
|
||||
void init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName);
|
||||
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -152,6 +147,14 @@ inline int Terminal::conductorsCount() const {
|
||||
return(conductors_.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@return the position, relative to the scene, of the docking point for
|
||||
conductors.
|
||||
*/
|
||||
inline QPointF Terminal::dockConductor() const {
|
||||
return(mapToScene(dock_conductor_));
|
||||
}
|
||||
|
||||
/**
|
||||
@return the number of terminal.
|
||||
*/
|
||||
|
||||
@@ -1582,10 +1582,11 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) {
|
||||
|
||||
// export default XRef properties
|
||||
QDomElement xrefs_elmt = xml_document.createElement("xrefs");
|
||||
foreach (QString key, defaultXRefProperties().keys()) {
|
||||
defaultXRefProperties()[key].setKey(key);
|
||||
QDomElement xref_elmt = defaultXRefProperties()[key].toXml(xml_document);
|
||||
xrefs_elmt.appendChild(xref_elmt);
|
||||
foreach (QString key, defaultXRefProperties().keys()) {
|
||||
QDomElement xref_elmt = xml_document.createElement("xref");
|
||||
xref_elmt.setAttribute("type", key);
|
||||
defaultXRefProperties()[key].toXml(xref_elmt);
|
||||
xrefs_elmt.appendChild(xref_elmt);
|
||||
}
|
||||
xml_element.appendChild(xrefs_elmt);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user