element data : add terminal type enum and terminal function enum

This commit is contained in:
joshua
2021-02-16 19:44:57 +01:00
parent 8f85cacb06
commit 444f62a1f8
2 changed files with 127 additions and 5 deletions

View File

@@ -102,6 +102,22 @@ QDomElement ElementData::kindInfoToXml(QDomDocument &document)
returned_elmt.appendChild(xml_count);
}
else if (m_type == ElementData::Terminale)
{
//type
auto xml_type = document.createElement("kindInformation");
xml_type.setAttribute("name", "type");
auto type_txt = document.createTextNode(terminalTypeToString(m_terminal_type));
xml_type.appendChild(type_txt);
returned_elmt.appendChild(xml_type);
//function
auto xml_func = document.createElement("kindInformation");
xml_func.setAttribute("name", "function");
auto func_txt = document.createTextNode(terminalFunctionToString(m_terminal_function));
xml_type.appendChild(xml_func);
returned_elmt.appendChild(xml_func);
}
return returned_elmt;
}
@@ -124,6 +140,12 @@ bool ElementData::operator==(const ElementData &data) const
return false;
}
}
else if (data.m_type == ElementData::Terminale) {
if (data.m_terminal_type != m_terminal_type ||
data.m_terminal_function != m_terminal_function) {
return false;
}
}
if(data.m_informations != m_informations) {
return false;
@@ -281,10 +303,75 @@ ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
return ElementData::NO;
}
QString ElementData::terminalTypeToString(ElementData::TerminalType type)
{
switch (type) {
case ElementData::TTGeneric :
return QString("generic");
case ElementData::Fuse :
return QString("fuse");
case ElementData::Sectional:
return QString("sectional");
case ElementData::Diode:
return QString("didoe");
}
}
ElementData::TerminalType ElementData::terminalTypeFromString(const QString &string)
{
if (string == "generic") {
return ElementData::TTGeneric;
} else if (string == "fuse") {
return ElementData::Fuse;
} else if (string == "sectional") {
return ElementData::Sectional;
} else if (string == "diode") {
return ElementData::Diode;
}
qDebug() << "ElementData::terminalTypeFromString : string : "
<< string
<< " don't exist, return failsafe value 'generic'";
return ElementData::TTGeneric;
}
QString ElementData::terminalFunctionToString(ElementData::TerminalFunction function)
{
switch (function) {
case ElementData::TFGeneric:
return QString("generic");
case ElementData::Phase:
return QString ("phase");
case ElementData::Neutral:
return QString("neutral");
case ElementData::PE:
return QString("pe");
}
}
ElementData::TerminalFunction ElementData::terminalFunctionFromString(const QString &string)
{
if (string == "generic") {
return ElementData::TFGeneric;
} else if (string == "phase") {
return ElementData::Phase;
} else if (string == "neutral") {
return ElementData::Neutral;
} else if (string == "pe") {
return ElementData::PE;
}
qDebug() << "ElementData::terminalFunctionFromString : string : "
<< string
<< " don't exist, return failsafe value 'generic'";
return ElementData::TFGeneric;
}
void ElementData::kindInfoFromXml(const QDomElement &xml_element)
{
if (m_type == ElementData::Master ||
m_type == ElementData::Slave)
m_type == ElementData::Slave ||
m_type == ElementData::Terminale)
{
auto xml_kind = xml_element.firstChildElement("kindInformations");
for (const auto &dom_elmt : QETXML::findInDomElement(xml_kind, "kindInformation"))
@@ -307,6 +394,13 @@ void ElementData::kindInfoFromXml(const QDomElement &xml_element)
m_contact_count = dom_elmt.text().toInt();
}
}
else if (m_type == ElementData::Terminale) {
if (name == "type") {
m_terminal_type = terminalTypeFromString(dom_elmt.text());
} else if (name == "function") {
m_terminal_function = terminalFunctionFromString(dom_elmt.text());
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
@@ -66,6 +66,22 @@ class ElementData : public PropertiesInterface
};
Q_ENUM(SlaveState)
enum TerminalType {
TTGeneric,
Fuse,
Sectional,
Diode
};
Q_ENUM(TerminalType)
enum TerminalFunction {
TFGeneric,
Phase,
Neutral,
PE
};
Q_ENUM(TerminalFunction)
ElementData() {}
~ElementData() override {}
@@ -90,12 +106,24 @@ class ElementData : public PropertiesInterface
static QString slaveStateToString(ElementData::SlaveState type);
static ElementData::SlaveState slaveStateFromString(const QString &string);
static QString terminalTypeToString(ElementData::TerminalType type);
static ElementData::TerminalType terminalTypeFromString(const QString &string);
static QString terminalFunctionToString(ElementData::TerminalFunction function);
static ElementData::TerminalFunction terminalFunctionFromString(const QString &string);
// must be public, because this class is a private member
// of Element/ element editor and they must access this data
ElementData::Type m_type = ElementData::Simple;
ElementData::MasterType m_master_type = ElementData::Coil;
ElementData::SlaveType m_slave_type = ElementData::SSimple;
ElementData::SlaveState m_slave_state = ElementData::NO;
ElementData::TerminalType m_terminal_type = ElementData::TTGeneric;
ElementData::TerminalFunction m_terminal_function = ElementData::TFGeneric;
int m_contact_count = 1;
DiagramContext m_informations;
NamesList m_names_list;