2021-02-13 13:07:36 +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/>.
|
|
|
|
*/
|
|
|
|
#include "elementdata.h"
|
|
|
|
#include "../qetxml.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
2021-03-11 19:52:50 +01:00
|
|
|
void ElementData::toSettings(QSettings &settings, const QString prefix) const {
|
2021-02-13 13:07:36 +01:00
|
|
|
Q_UNUSED(settings)
|
|
|
|
Q_UNUSED(prefix)
|
|
|
|
}
|
|
|
|
|
2021-03-11 19:52:50 +01:00
|
|
|
void ElementData::fromSettings(const QSettings &settings, const QString prefix) {
|
2021-02-13 13:07:36 +01:00
|
|
|
Q_UNUSED(settings)
|
|
|
|
Q_UNUSED(prefix)
|
|
|
|
}
|
|
|
|
|
2021-03-11 19:52:50 +01:00
|
|
|
QDomElement ElementData::toXml(QDomDocument &xml_element) const {
|
|
|
|
Q_UNUSED(xml_element)
|
|
|
|
return QDomElement();
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::fromXml
|
|
|
|
* load properties from xml element.
|
|
|
|
* The tag name of xml_element must be definition
|
|
|
|
* and have an attribute "type"
|
|
|
|
* @param xml_element : tagName must be 'definition'
|
|
|
|
* @return true is successfuly loaded
|
|
|
|
*/
|
2021-03-11 19:52:50 +01:00
|
|
|
bool ElementData::fromXml(const QDomElement &xml_element)
|
2021-02-13 13:07:36 +01:00
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if(xml_element.tagName() != QLatin1String("definition") ||
|
|
|
|
xml_element.attribute(QStringLiteral("type")) != QLatin1String("element")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-01 22:45:59 +02:00
|
|
|
m_type = typeFromString(xml_element.attribute(QStringLiteral("link_type"), QStringLiteral("simple")));
|
2021-02-13 13:07:36 +01:00
|
|
|
kindInfoFromXml(xml_element);
|
2022-06-01 22:45:59 +02:00
|
|
|
m_informations.fromXml(xml_element.firstChildElement(QStringLiteral("elementInformations")),
|
|
|
|
QStringLiteral("elementInformation"));
|
2021-02-13 13:07:36 +01:00
|
|
|
m_names_list.fromXml(xml_element);
|
|
|
|
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_draw_info = xml_element.firstChildElement(QStringLiteral("informations"));
|
|
|
|
if(xml_draw_info.tagName() == QLatin1String("informations")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
m_drawing_information = xml_draw_info.text();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-13 21:38:36 +01:00
|
|
|
QDomElement ElementData::kindInfoToXml(QDomDocument &document)
|
|
|
|
{
|
|
|
|
//kindInformations
|
2022-06-01 22:45:59 +02:00
|
|
|
auto returned_elmt = document.createElement(QStringLiteral("kindInformations"));
|
2021-02-13 21:38:36 +01:00
|
|
|
|
|
|
|
if (m_type == ElementData::Master)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_type = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_type.setAttribute(QStringLiteral("name"), QStringLiteral("type"));
|
2021-02-13 21:38:36 +01:00
|
|
|
auto type_txt = document.createTextNode(masterTypeToString(m_master_type));
|
|
|
|
xml_type.appendChild(type_txt);
|
|
|
|
|
|
|
|
returned_elmt.appendChild(xml_type);
|
|
|
|
}
|
|
|
|
else if (m_type == ElementData::Slave)
|
|
|
|
{
|
|
|
|
//type
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_type = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_type.setAttribute(QStringLiteral("name"), QStringLiteral("type"));
|
2021-02-13 21:38:36 +01:00
|
|
|
auto type_txt = document.createTextNode(slaveTypeToString(m_slave_type));
|
|
|
|
xml_type.appendChild(type_txt);
|
|
|
|
returned_elmt.appendChild(xml_type);
|
|
|
|
|
|
|
|
//state
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_state = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_state.setAttribute(QStringLiteral("name"), QStringLiteral("state"));
|
2021-02-13 21:38:36 +01:00
|
|
|
auto state_txt = document.createTextNode(slaveStateToString(m_slave_state));
|
|
|
|
xml_state.appendChild(state_txt);
|
|
|
|
|
|
|
|
returned_elmt.appendChild(xml_state);
|
|
|
|
|
|
|
|
//contact count
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_count = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_count.setAttribute(QStringLiteral("name"), QStringLiteral("number"));
|
2021-02-13 21:38:36 +01:00
|
|
|
auto count_txt = document.createTextNode(QString::number(m_contact_count));
|
|
|
|
xml_count.appendChild(count_txt);
|
|
|
|
|
|
|
|
returned_elmt.appendChild(xml_count);
|
|
|
|
}
|
2021-02-16 19:44:57 +01:00
|
|
|
else if (m_type == ElementData::Terminale)
|
|
|
|
{
|
|
|
|
//type
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_type = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_type.setAttribute(QStringLiteral("name"), QStringLiteral("type"));
|
2021-02-16 19:44:57 +01:00
|
|
|
auto type_txt = document.createTextNode(terminalTypeToString(m_terminal_type));
|
|
|
|
xml_type.appendChild(type_txt);
|
|
|
|
returned_elmt.appendChild(xml_type);
|
|
|
|
|
|
|
|
//function
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_func = document.createElement(QStringLiteral("kindInformation"));
|
|
|
|
xml_func.setAttribute(QStringLiteral("name"), QStringLiteral("function"));
|
2021-02-16 19:44:57 +01:00
|
|
|
auto func_txt = document.createTextNode(terminalFunctionToString(m_terminal_function));
|
2021-02-16 21:39:09 +01:00
|
|
|
xml_func.appendChild(func_txt);
|
2021-02-16 19:44:57 +01:00
|
|
|
returned_elmt.appendChild(xml_func);
|
|
|
|
}
|
2021-02-13 21:38:36 +01:00
|
|
|
|
|
|
|
return returned_elmt;
|
|
|
|
}
|
|
|
|
|
2021-07-17 13:44:44 +02:00
|
|
|
/**
|
|
|
|
* @brief ElementData::setTerminalType
|
|
|
|
* Override the terminal type by \p t_type
|
|
|
|
* @param t_type
|
|
|
|
*/
|
|
|
|
void ElementData::setTerminalType(ElementData::TerminalType t_type)
|
|
|
|
{
|
|
|
|
if (t_type == m_terminal_type) {
|
|
|
|
m_terminal_type_is_override = false;
|
|
|
|
} else {
|
|
|
|
m_override_terminal_type = t_type;
|
|
|
|
m_terminal_type_is_override = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::terminalType
|
|
|
|
* @return the terminal type or overrided terminal type if set
|
|
|
|
*/
|
|
|
|
ElementData::TerminalType ElementData::terminalType() const
|
|
|
|
{
|
|
|
|
return m_terminal_type_is_override ?
|
|
|
|
m_override_terminal_type :
|
|
|
|
m_terminal_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::setTerminalFunction
|
|
|
|
* Override the terminal function by \p t_function
|
|
|
|
* @param t_function
|
|
|
|
*/
|
|
|
|
void ElementData::setTerminalFunction(ElementData::TerminalFunction t_function)
|
|
|
|
{
|
|
|
|
if (t_function == m_terminal_function) {
|
|
|
|
m_terminal_function_is_override = false;
|
|
|
|
} else {
|
|
|
|
m_override_terminal_function = t_function;
|
|
|
|
m_terminal_function_is_override = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::terminalFunction
|
|
|
|
* @return the terminal function or overrided terminal function if set
|
|
|
|
*/
|
|
|
|
ElementData::TerminalFunction ElementData::terminalFunction() const
|
|
|
|
{
|
|
|
|
return m_terminal_function_is_override ?
|
|
|
|
m_override_terminal_function :
|
|
|
|
m_terminal_function;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::setTerminalLED
|
|
|
|
* Override the terminal led by \p led
|
|
|
|
* @param led
|
|
|
|
*/
|
|
|
|
void ElementData::setTerminalLED(bool led)
|
|
|
|
{
|
|
|
|
if (led == m_terminal_led) {
|
|
|
|
m_terminal_led_is_override = false;
|
|
|
|
} else {
|
|
|
|
m_override_terminal_led = led;
|
|
|
|
m_terminal_led_is_override = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementData::terminalLed
|
|
|
|
* @return if terminal have led or overrided led if set
|
|
|
|
*/
|
|
|
|
bool ElementData::terminalLed() const
|
|
|
|
{
|
|
|
|
return m_terminal_led_is_override ?
|
|
|
|
m_override_terminal_led :
|
|
|
|
m_terminal_led;
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:34:48 +02:00
|
|
|
/**
|
|
|
|
* @brief ElementData::terminalPropertiesIsOverrided
|
|
|
|
* @return true if at least one sub properties of terminal type is overrided
|
|
|
|
*/
|
|
|
|
bool ElementData::terminalPropertiesIsOverrided() const
|
|
|
|
{
|
|
|
|
if (m_terminal_type_is_override
|
|
|
|
|| m_terminal_function_is_override
|
|
|
|
|| m_terminal_led_is_override) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-13 21:38:36 +01:00
|
|
|
bool ElementData::operator==(const ElementData &data) const
|
|
|
|
{
|
|
|
|
if (data.m_type != m_type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.m_type == ElementData::Master) {
|
|
|
|
if(data.m_master_type != m_master_type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (data.m_type == ElementData::Slave) {
|
2021-02-16 19:44:57 +01:00
|
|
|
if (data.m_slave_state != m_slave_state ||
|
|
|
|
data.m_slave_type != m_slave_type ||
|
2021-02-13 21:38:36 +01:00
|
|
|
data.m_contact_count != m_contact_count) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 19:44:57 +01:00
|
|
|
else if (data.m_type == ElementData::Terminale) {
|
2021-07-17 13:44:44 +02:00
|
|
|
//Check terminal type or overrided terminal type
|
|
|
|
if (data.m_terminal_type_is_override != m_terminal_type_is_override) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_terminal_type_is_override) {
|
|
|
|
if(data.m_override_terminal_type != m_override_terminal_type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (data.m_terminal_type != m_terminal_type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check terminal led or override terminal led
|
|
|
|
if (data.m_terminal_led_is_override != m_terminal_led_is_override) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_terminal_led_is_override) {
|
|
|
|
if (data.m_override_terminal_led != m_override_terminal_led) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (data.m_terminal_led != m_terminal_led) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check terminal function or overrided terminal function
|
|
|
|
if (data.m_terminal_function_is_override != m_terminal_function_is_override) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_terminal_function_is_override) {
|
|
|
|
if (data.m_override_terminal_function != m_override_terminal_function) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (data.m_terminal_function != m_terminal_function) {
|
2021-02-16 19:44:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-02-13 21:38:36 +01:00
|
|
|
|
|
|
|
if(data.m_informations != m_informations) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.m_names_list != m_names_list) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_drawing_information != m_drawing_information) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElementData::operator !=(const ElementData &data) const {
|
|
|
|
return !(*this == data);
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:02:29 +02:00
|
|
|
QString ElementData::typeToString() const {
|
|
|
|
return typeToString(m_type);
|
|
|
|
}
|
|
|
|
|
2021-02-13 13:07:36 +01:00
|
|
|
QString ElementData::typeToString(ElementData::Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ElementData::Simple :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("simple");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::NextReport :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("next_report");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::PreviousReport :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("previous_report");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Master :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("master");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Slave :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("slave");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Terminale :
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("terminal");
|
2022-05-13 20:02:29 +02:00
|
|
|
case ElementData::Thumbnail:
|
2022-05-16 08:59:25 +02:00
|
|
|
return QStringLiteral("thumbnail");
|
2021-02-13 13:07:36 +01:00
|
|
|
default:
|
|
|
|
qDebug() << "ElementData::typeToString : type don't exist"
|
|
|
|
<< "return failsafe value 'simple'";
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("simple");
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::Type ElementData::typeFromString(const QString &string)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (string == QLatin1String("simple")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Simple;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("next_report")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::NextReport;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("previous_report")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::PreviousReport;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("master")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Master;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("slave")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Slave;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("terminal")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Terminale;
|
2022-05-16 08:59:25 +02:00
|
|
|
} else if (string == QLatin1String("thumbnail")) {
|
2022-05-13 20:02:29 +02:00
|
|
|
return ElementData::Thumbnail;
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Return simple if nothing match
|
|
|
|
qDebug() << "ElementData::typeFromString : string "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'simple";
|
|
|
|
return ElementData::Simple;
|
|
|
|
}
|
|
|
|
|
2022-06-01 22:29:12 +02:00
|
|
|
QString ElementData::masterTypeToString() const {
|
|
|
|
if (m_type == Master)
|
|
|
|
return masterTypeToString(m_master_type);
|
|
|
|
else
|
|
|
|
return QLatin1String();
|
|
|
|
}
|
|
|
|
|
2021-02-13 13:07:36 +01:00
|
|
|
QString ElementData::masterTypeToString(ElementData::MasterType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ElementData::Coil:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("coil");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Protection:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("protection");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Commutator:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("commutator");
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::MasterType ElementData::masterTypeFromString(const QString &string)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (string == QLatin1String("coil")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Coil;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("protection")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Protection;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("commutator")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Commutator;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "ElementData::masterTypeFromString : string "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'coil'";
|
|
|
|
return ElementData::Coil;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ElementData::slaveTypeToString(ElementData::SlaveType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ElementData::SSimple:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("simple");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::Power:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("power");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::DelayOn:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("delayOn");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::DelayOff:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("delayOff");
|
2021-02-13 13:07:36 +01:00
|
|
|
case ElementData::delayOnOff:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("delayOnOff");
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::SlaveType ElementData::slaveTypeFromString(const QString &string)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (string == QLatin1String("simple")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::SSimple;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("power")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::Power;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("delayOn")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::DelayOn;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("delayOff")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::DelayOff;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("delayOnOff")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::delayOnOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "ElementData::slaveTypeFromSting : string "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'simple'";
|
|
|
|
return ElementData::SSimple;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ElementData::slaveStateToString(ElementData::SlaveState type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case NO:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("NO");
|
2021-02-13 13:07:36 +01:00
|
|
|
case NC:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("NC");
|
2021-02-13 13:07:36 +01:00
|
|
|
case SW:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("SW");
|
2022-06-22 18:02:13 +02:00
|
|
|
case Other:
|
|
|
|
return QStringLiteral("Other");
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (string == QLatin1String("NO")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::NO;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("NC")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::NC;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("SW")) {
|
2021-02-13 13:07:36 +01:00
|
|
|
return ElementData::SW;
|
2022-06-22 18:02:13 +02:00
|
|
|
} else if (string == QLatin1String("Other")){
|
|
|
|
return ElementData::Other;
|
|
|
|
}
|
2021-02-13 13:07:36 +01:00
|
|
|
|
|
|
|
qDebug() << "ElementData::slaveStateFromString : string : "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'NO'";
|
|
|
|
return ElementData::NO;
|
|
|
|
}
|
|
|
|
|
2021-02-16 19:44:57 +01:00
|
|
|
QString ElementData::terminalTypeToString(ElementData::TerminalType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ElementData::TTGeneric :
|
2021-05-21 19:15:26 +02:00
|
|
|
return QStringLiteral("generic");
|
|
|
|
case ElementData::TTFuse :
|
|
|
|
return QStringLiteral("fuse");
|
|
|
|
case ElementData::TTSectional:
|
|
|
|
return QStringLiteral("sectional");
|
|
|
|
case ElementData::TTDiode:
|
|
|
|
return QStringLiteral("diode");
|
|
|
|
case ElementData::TTGround:
|
|
|
|
return QStringLiteral("ground");
|
2021-02-16 19:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::TerminalType ElementData::terminalTypeFromString(const QString &string)
|
|
|
|
{
|
2021-05-21 19:15:26 +02:00
|
|
|
if (string == QLatin1String("generic")) {
|
2021-02-16 19:44:57 +01:00
|
|
|
return ElementData::TTGeneric;
|
2021-05-21 19:15:26 +02:00
|
|
|
} else if (string == QLatin1String("fuse")) {
|
|
|
|
return ElementData::TTFuse;
|
|
|
|
} else if (string == QLatin1String("sectional")) {
|
|
|
|
return ElementData::TTSectional;
|
|
|
|
} else if (string == QLatin1String("diode")) {
|
|
|
|
return ElementData::TTDiode;
|
|
|
|
} else if (string == QLatin1String("ground")) {
|
|
|
|
return ElementData::TTGround;
|
2021-02-16 19:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "ElementData::terminalTypeFromString : string : "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'generic'";
|
|
|
|
return ElementData::TTGeneric;
|
|
|
|
}
|
|
|
|
|
2021-06-07 19:26:41 +02:00
|
|
|
QString ElementData::translatedTerminalType(ElementData::TerminalType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ElementData::TTGeneric :
|
2021-07-17 13:44:44 +02:00
|
|
|
return QObject::tr("Générique", "generic terminal element type");
|
2021-06-07 19:26:41 +02:00
|
|
|
case ElementData::TTFuse :
|
2021-07-17 13:44:44 +02:00
|
|
|
return QObject::tr("Fusible", "fuse terminal element type");
|
2021-06-07 19:26:41 +02:00
|
|
|
case ElementData::TTSectional:
|
2021-07-17 13:44:44 +02:00
|
|
|
return QObject::tr("Sectionable", "sectional terminal element type");
|
2021-06-07 19:26:41 +02:00
|
|
|
case ElementData::TTDiode:
|
2021-07-17 13:44:44 +02:00
|
|
|
return QObject::tr("Diode", "diode terminal element type");
|
2021-06-07 19:26:41 +02:00
|
|
|
case ElementData::TTGround:
|
2021-07-17 13:44:44 +02:00
|
|
|
return QObject::tr("Terre", "ground terminal element type");
|
2021-06-07 19:26:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 19:44:57 +01:00
|
|
|
QString ElementData::terminalFunctionToString(ElementData::TerminalFunction function)
|
|
|
|
{
|
|
|
|
switch (function) {
|
|
|
|
case ElementData::TFGeneric:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("generic");
|
2021-05-21 19:15:26 +02:00
|
|
|
case ElementData::TFPhase:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral ("phase");
|
2021-05-21 19:15:26 +02:00
|
|
|
case ElementData::TFNeutral:
|
2022-06-01 22:45:59 +02:00
|
|
|
return QStringLiteral("neutral");
|
2021-02-16 19:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementData::TerminalFunction ElementData::terminalFunctionFromString(const QString &string)
|
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (string == QLatin1String("generic")) {
|
2021-02-16 19:44:57 +01:00
|
|
|
return ElementData::TFGeneric;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("phase")) {
|
2021-05-21 19:15:26 +02:00
|
|
|
return ElementData::TFPhase;
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (string == QLatin1String("neutral")) {
|
2021-05-21 19:15:26 +02:00
|
|
|
return ElementData::TFNeutral;
|
2021-02-16 19:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "ElementData::terminalFunctionFromString : string : "
|
|
|
|
<< string
|
|
|
|
<< " don't exist, return failsafe value 'generic'";
|
|
|
|
return ElementData::TFGeneric;
|
|
|
|
}
|
|
|
|
|
2021-07-17 13:44:44 +02:00
|
|
|
QString ElementData::translatedTerminalFunction(ElementData::TerminalFunction function)
|
|
|
|
{
|
|
|
|
switch (function) {
|
|
|
|
case TFGeneric : return QObject::tr("Générique", "generic terminal element function");
|
|
|
|
case TFPhase : return QObject::tr("Phase", "phase terminal element function" );
|
|
|
|
case TFNeutral : return QObject::tr("Neutre", "neutral terminal element function");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 13:07:36 +01:00
|
|
|
void ElementData::kindInfoFromXml(const QDomElement &xml_element)
|
|
|
|
{
|
2021-02-13 21:38:36 +01:00
|
|
|
if (m_type == ElementData::Master ||
|
2021-02-16 19:44:57 +01:00
|
|
|
m_type == ElementData::Slave ||
|
|
|
|
m_type == ElementData::Terminale)
|
2021-02-13 13:07:36 +01:00
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
auto xml_kind = xml_element.firstChildElement(QStringLiteral("kindInformations"));
|
|
|
|
for (const auto &dom_elmt : QETXML::findInDomElement(xml_kind, QStringLiteral("kindInformation")))
|
2021-02-13 21:38:36 +01:00
|
|
|
{
|
2022-06-01 22:45:59 +02:00
|
|
|
if (!dom_elmt.hasAttribute(QStringLiteral("name"))) {
|
2021-02-13 21:38:36 +01:00
|
|
|
continue;
|
|
|
|
}
|
2022-06-01 22:45:59 +02:00
|
|
|
auto name = dom_elmt.attribute(QStringLiteral("name"));
|
2021-02-13 13:07:36 +01:00
|
|
|
|
2021-02-13 21:38:36 +01:00
|
|
|
if (m_type == ElementData::Master &&
|
2022-06-01 22:45:59 +02:00
|
|
|
name == QLatin1String("type")) {
|
2021-02-13 21:38:36 +01:00
|
|
|
m_master_type = masterTypeFromString(dom_elmt.text());
|
|
|
|
}
|
|
|
|
else if (m_type == ElementData::Slave ) {
|
2022-06-01 22:45:59 +02:00
|
|
|
if (name == QLatin1String("type")) {
|
2021-02-13 21:38:36 +01:00
|
|
|
m_slave_type = slaveTypeFromString(dom_elmt.text());
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (name == QLatin1String("state")) {
|
2021-02-13 21:38:36 +01:00
|
|
|
m_slave_state = slaveStateFromString(dom_elmt.text());
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (name == QLatin1String("number")) {
|
2021-02-13 21:38:36 +01:00
|
|
|
m_contact_count = dom_elmt.text().toInt();
|
|
|
|
}
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
2021-02-16 19:44:57 +01:00
|
|
|
else if (m_type == ElementData::Terminale) {
|
2022-06-01 22:45:59 +02:00
|
|
|
if (name == QLatin1String("type")) {
|
2021-02-16 19:44:57 +01:00
|
|
|
m_terminal_type = terminalTypeFromString(dom_elmt.text());
|
2022-06-01 22:45:59 +02:00
|
|
|
} else if (name == QLatin1String("function")) {
|
2021-02-16 19:44:57 +01:00
|
|
|
m_terminal_function = terminalFunctionFromString(dom_elmt.text());
|
|
|
|
}
|
2022-05-15 14:29:01 +02:00
|
|
|
|
2021-02-16 19:44:57 +01:00
|
|
|
}
|
2021-02-13 13:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|