2021-02-12 19:28:07 +01:00
|
|
|
/*
|
|
|
|
Copyright 2006-2021 The QElectroTech Team
|
|
|
|
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/>.
|
|
|
|
*/
|
2020-05-25 22:17:17 +02:00
|
|
|
#include "terminaldata.h"
|
|
|
|
|
|
|
|
#include <QGraphicsObject>
|
2021-02-06 18:35:55 +01:00
|
|
|
#include <QDebug>
|
2020-05-25 22:17:17 +02:00
|
|
|
|
|
|
|
TerminalData::TerminalData():
|
2020-10-17 20:25:30 +02:00
|
|
|
PropertiesInterface()
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
init();
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TerminalData::TerminalData(QGraphicsObject *parent):
|
2020-10-17 20:25:30 +02:00
|
|
|
PropertiesInterface(),
|
|
|
|
q(parent)
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
init();
|
2020-05-26 18:47:24 +02:00
|
|
|
}
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void TerminalData::init()
|
|
|
|
{
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TerminalData::~TerminalData()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-19 20:05:58 +02:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief TerminalData::setParent
|
|
|
|
@param parent
|
2020-07-19 20:05:58 +02:00
|
|
|
*/
|
2020-05-25 22:17:17 +02:00
|
|
|
void TerminalData::setParent(QGraphicsObject* parent)
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
q = parent;
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 20:05:58 +02:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief TerminalData::toSettings
|
|
|
|
Save properties to setting file.
|
2020-07-19 20:05:58 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
QString is use for prefix a word befor the name of each paramètre
|
|
|
|
@param settings UNUSED
|
|
|
|
@param prefix UNUSED
|
2020-07-19 20:05:58 +02:00
|
|
|
*/
|
2020-10-19 11:07:04 +02:00
|
|
|
void TerminalData::toSettings(QSettings &settings, const QString &prefix) const
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-06-20 21:22:41 +02:00
|
|
|
{
|
2021-02-05 21:20:37 +01:00
|
|
|
Q_UNUSED(settings)
|
|
|
|
Q_UNUSED(prefix)
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 20:05:58 +02:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief TerminalData::fromSettings
|
|
|
|
load properties to setting file.
|
2020-07-19 20:05:58 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
QString is use for prefix a word befor the name of each paramètre
|
|
|
|
@param settings UNUSED
|
|
|
|
@param prefix UNUSED
|
2020-07-19 20:05:58 +02:00
|
|
|
*/
|
2020-10-19 11:07:04 +02:00
|
|
|
void TerminalData::fromSettings(QSettings &settings, const QString& prefix)
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2021-02-06 18:35:55 +01:00
|
|
|
Q_UNUSED(settings)
|
|
|
|
Q_UNUSED(prefix)
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 20:05:58 +02:00
|
|
|
/**
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief TerminalData::toXml
|
|
|
|
Save properties to xml element
|
|
|
|
write the name, number, position and orientation of the terminal
|
|
|
|
to xml_element
|
|
|
|
|
|
|
|
@note This method is only called from the PartTerminal
|
|
|
|
and should never called from the Terminal class
|
|
|
|
@param xml_document
|
|
|
|
@return xml_element : DomElement with
|
|
|
|
the name, number, position and orientation of the terminal
|
2020-07-19 20:05:58 +02:00
|
|
|
*/
|
2020-05-25 22:17:17 +02:00
|
|
|
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
QDomElement xml_element = xml_document.createElement("terminaldata");
|
|
|
|
|
|
|
|
// m_pos cannot be stored, because in the partterminal it will not be updated.
|
|
|
|
// In PartTerminal m_pos is the position of the dock, in Terminal m_pos is the second side of the terminal
|
|
|
|
// This is hold for legacy compability reason
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "x", m_pos.x()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "y", m_pos.y()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "name", m_name));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation)));
|
2021-02-24 18:48:59 +01:00
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "type", typeToString(m_type)));
|
2020-10-17 20:25:30 +02:00
|
|
|
|
|
|
|
return(xml_element);
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
2020-07-19 20:05:58 +02:00
|
|
|
|
2020-10-16 11:43:45 +02:00
|
|
|
/*
|
2020-10-17 20:25:30 +02:00
|
|
|
@brief TerminalData::fromXml
|
|
|
|
load properties to xml element
|
2020-07-19 20:05:58 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
@note This method is only called from the PartTerminal
|
|
|
|
and should never called from the Terminal class
|
|
|
|
@param xml_element
|
|
|
|
@return true if succeeded / false if the attribute is not real
|
2020-07-19 20:05:58 +02:00
|
|
|
*/
|
2020-10-16 11:43:45 +02:00
|
|
|
bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-10-17 20:25:30 +02:00
|
|
|
qreal term_x = 0.0;
|
|
|
|
qreal term_y = 0.0;
|
2020-07-19 20:05:58 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// reads the position of the terminal
|
|
|
|
// lit la position de la borne
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
if (propertyDouble(xml_element, "x", &term_x))
|
|
|
|
return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
if (propertyDouble(xml_element, "y", &term_y))
|
|
|
|
return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
m_pos = QPointF(term_x, term_y);
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// emit posFromXML(QPointF(term_x, term_y));
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// do not write uuid from this class, because only PartTerminal::fromXml need
|
|
|
|
// to write it to xml file. Terminal::fromXml does not need.
|
|
|
|
// if the attribute not exists, means, the element is created with an
|
|
|
|
// older version of qet. So use the legacy approach
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
//if (propertyString(xml_element, "name", &m_name))
|
|
|
|
// return false;
|
|
|
|
propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
QString o;
|
|
|
|
if (propertyString(xml_element, "orientation", &o))
|
|
|
|
return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// read the orientation of the terminal
|
|
|
|
// lit l'orientation de la borne
|
2020-10-19 11:07:04 +02:00
|
|
|
m_orientation = orientationFromString(o);
|
2021-02-23 17:35:55 +01:00
|
|
|
|
2021-02-24 18:48:59 +01:00
|
|
|
QString type;
|
2021-02-25 16:55:13 +01:00
|
|
|
if (propertyString(xml_element, "type", &type) == PropertyFlags::Success)
|
|
|
|
m_type = typeFromString(type);
|
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
return true;
|
2020-10-16 11:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TerminalData::valideXml(const QDomElement& xml_element) {
|
2020-10-17 20:25:30 +02:00
|
|
|
if (propertyDouble(xml_element, "x"))
|
|
|
|
return false;
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2021-02-25 16:55:13 +01:00
|
|
|
// Old projects do not have this property.
|
|
|
|
// if (propertyString(xml_element, "type"))
|
|
|
|
// return false;
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2021-02-23 17:35:55 +01:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
// legacy elements do not have an uuid
|
|
|
|
// if (propertyUuid(xml_element, "uuid"))
|
|
|
|
// return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
//if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
|
|
|
// return false;
|
2020-10-16 11:43:45 +02:00
|
|
|
|
2020-10-17 20:25:30 +02:00
|
|
|
if (propertyString(xml_element, "orientation"))
|
|
|
|
return false;
|
|
|
|
return true;
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
2021-02-06 18:35:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TerminalData::typeToString
|
|
|
|
* @param type
|
|
|
|
* @return type into a QString
|
|
|
|
*/
|
|
|
|
QString TerminalData::typeToString(TerminalData::Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Generic:
|
|
|
|
return QString("Generic");
|
2021-02-12 19:28:07 +01:00
|
|
|
case Inner :
|
|
|
|
return QString("Inner");
|
|
|
|
case Outer :
|
|
|
|
return QString("Outer");
|
2021-02-06 18:35:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TerminalData::typeFromString
|
|
|
|
* @param string
|
|
|
|
* @return The type describe in string to TerminalData::Type.
|
|
|
|
* if string doesn't describe a type, TerminalData::Generic is returned
|
|
|
|
*/
|
|
|
|
TerminalData::Type TerminalData::typeFromString(const QString &string)
|
|
|
|
{
|
|
|
|
if (string == "Generic") {
|
|
|
|
return TerminalData::Generic;
|
2021-02-12 19:28:07 +01:00
|
|
|
} else if (string == "Inner") {
|
|
|
|
return TerminalData::Inner;
|
|
|
|
} else if (string == "Outer") {
|
|
|
|
return TerminalData::Outer;
|
2021-02-06 18:35:55 +01:00
|
|
|
} else {
|
|
|
|
qDebug() << "TerminalData::typeFromString, argument string is invalid"
|
|
|
|
" failsafe type 'TerminalData::Generic' is returned";
|
|
|
|
return TerminalData::Generic;
|
|
|
|
}
|
|
|
|
}
|