This commit is contained in:
Martin
2021-02-23 17:35:55 +01:00
7393 changed files with 173795 additions and 176624 deletions

View File

@@ -0,0 +1,406 @@
/*
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>
void ElementData::toSettings(QSettings &settings, const QString prefix) const {
Q_UNUSED(settings)
Q_UNUSED(prefix)
}
void ElementData::fromSettings(const QSettings &settings, const QString prefix) {
Q_UNUSED(settings)
Q_UNUSED(prefix)
}
QDomElement ElementData::toXml(QDomDocument &xml_element) const {
Q_UNUSED(xml_element)
return QDomElement();
}
/**
* @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
*/
bool ElementData::fromXml(const QDomElement &xml_element)
{
if(xml_element.tagName() != "definition" ||
xml_element.attribute("type") != "element") {
return false;
}
m_type = typeFromString(xml_element.attribute("link_type", "simple"));
kindInfoFromXml(xml_element);
m_informations.fromXml(xml_element.firstChildElement("elementInformations"),
"elementInformation");
m_names_list.fromXml(xml_element);
auto xml_draw_info = xml_element.firstChildElement("informations");
if(xml_draw_info.tagName() == "informations") {
m_drawing_information = xml_draw_info.text();
}
return true;
}
QDomElement ElementData::kindInfoToXml(QDomDocument &document)
{
//kindInformations
auto returned_elmt = document.createElement("kindInformations");
if (m_type == ElementData::Master)
{
auto xml_type = document.createElement("kindInformation");
xml_type.setAttribute("name", "type");
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
auto xml_type = document.createElement("kindInformation");
xml_type.setAttribute("name", "type");
auto type_txt = document.createTextNode(slaveTypeToString(m_slave_type));
xml_type.appendChild(type_txt);
returned_elmt.appendChild(xml_type);
//state
auto xml_state = document.createElement("kindInformation");
xml_state.setAttribute("name", "state");
auto state_txt = document.createTextNode(slaveStateToString(m_slave_state));
xml_state.appendChild(state_txt);
returned_elmt.appendChild(xml_state);
//contact count
auto xml_count = document.createElement("kindInformation");
xml_count.setAttribute("name", "number");
auto count_txt = document.createTextNode(QString::number(m_contact_count));
xml_count.appendChild(count_txt);
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_func.appendChild(func_txt);
returned_elmt.appendChild(xml_func);
}
return returned_elmt;
}
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) {
if (data.m_slave_state != m_slave_state ||
data.m_slave_type != m_slave_type ||
data.m_contact_count != m_contact_count) {
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;
}
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);
}
QString ElementData::typeToString(ElementData::Type type)
{
switch (type) {
case ElementData::Simple :
return QString("simple");
case ElementData::NextReport :
return QString ("next_report");
case ElementData::PreviousReport :
return QString("previous_report");
case ElementData::Master :
return QString("master");
case ElementData::Slave :
return QString("slave");
case ElementData::Terminale :
return QString("terminal");
default:
qDebug() << "ElementData::typeToString : type don't exist"
<< "return failsafe value 'simple'";
return QString("simple");
}
}
ElementData::Type ElementData::typeFromString(const QString &string)
{
if (string == "simple") {
return ElementData::Simple;
} else if (string == "next_report") {
return ElementData::NextReport;
} else if (string == "previous_report") {
return ElementData::PreviousReport;
} else if (string == "master") {
return ElementData::Master;
} else if (string == "slave") {
return ElementData::Slave;
} else if (string == "terminal") {
return ElementData::Terminale;
}
//Return simple if nothing match
qDebug() << "ElementData::typeFromString : string "
<< string
<< " don't exist, return failsafe value 'simple";
return ElementData::Simple;
}
QString ElementData::masterTypeToString(ElementData::MasterType type)
{
switch (type) {
case ElementData::Coil:
return QString ("coil");
case ElementData::Protection:
return QString ("protection");
case ElementData::Commutator:
return QString ("commutator");
}
}
ElementData::MasterType ElementData::masterTypeFromString(const QString &string)
{
if (string == "coil") {
return ElementData::Coil;
} else if (string == "protection") {
return ElementData::Protection;
} else if (string == "commutator") {
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:
return QString ("simple");
case ElementData::Power:
return QString ("power");
case ElementData::DelayOn:
return QString("delayOn");
case ElementData::DelayOff:
return QString("delayOff");
case ElementData::delayOnOff:
return QString("delayOnOff");
}
}
ElementData::SlaveType ElementData::slaveTypeFromString(const QString &string)
{
if (string == "simple") {
return ElementData::SSimple;
} else if (string == "power") {
return ElementData::Power;
} else if (string == "delayOn") {
return ElementData::DelayOn;
} else if (string == "delayOff") {
return ElementData::DelayOff;
} else if (string == "delayOnOff") {
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:
return QString("NO");
case NC:
return QString("NC");
case SW:
return QString("SW");
}
}
ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
{
if (string == "NO") {
return ElementData::NO;
} else if (string == "NC") {
return ElementData::NC;
} else if (string == "SW") {
return ElementData::SW;
}
qDebug() << "ElementData::slaveStateFromString : string : "
<< string
<< " don't exist, return failsafe value 'NO'";
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("diode");
}
}
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::Terminale)
{
auto xml_kind = xml_element.firstChildElement("kindInformations");
for (const auto &dom_elmt : QETXML::findInDomElement(xml_kind, "kindInformation"))
{
if (!dom_elmt.hasAttribute("name")) {
continue;
}
auto name = dom_elmt.attribute("name");
if (m_type == ElementData::Master &&
name == "type") {
m_master_type = masterTypeFromString(dom_elmt.text());
}
else if (m_type == ElementData::Slave ) {
if (name == "type") {
m_slave_type = slaveTypeFromString(dom_elmt.text());
} else if (name == "state") {
m_slave_state = slaveStateFromString(dom_elmt.text());
} else if (name == "number") {
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

@@ -0,0 +1,135 @@
/*
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/>.
*/
#ifndef ELEMENTDATA_H
#define ELEMENTDATA_H
#include "propertiesinterface.h"
#include "../diagramcontext.h"
#include "../NameList/nameslist.h"
/**
* @brief The ElementData class
* WARNING
* This class inherit from PropertiesInterface but
* only fromXml is actually reimplemented.
*/
class ElementData : public PropertiesInterface
{
Q_GADGET
public:
enum Type {
Simple = 1,
NextReport = 2,
PreviousReport = 4,
AllReport = 6,
Master = 8,
Slave = 16,
Terminale = 32};
Q_ENUM(Type)
enum MasterType {
Coil,
Protection,
Commutator
};
Q_ENUM(MasterType)
enum SlaveType {
SSimple,
Power,
DelayOn,
DelayOff,
delayOnOff
};
Q_ENUM(SlaveType)
enum SlaveState {
NO,
NC,
SW
};
Q_ENUM(SlaveState)
enum TerminalType {
TTGeneric,
Fuse,
Sectional,
Diode
};
Q_ENUM(TerminalType)
enum TerminalFunction {
TFGeneric,
Phase,
Neutral,
PE
};
Q_ENUM(TerminalFunction)
ElementData() {}
~ElementData() override {}
void toSettings(QSettings &settings, const QString prefix = QString()) const override;
void fromSettings(const QSettings &settings, const QString prefix = QString()) override;
QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override;
QDomElement kindInfoToXml(QDomDocument &document);
bool operator==(const ElementData &data) const;
bool operator!=(const ElementData &data) const;
static QString typeToString(ElementData::Type type);
static ElementData::Type typeFromString(const QString &string);
static QString masterTypeToString(ElementData::MasterType type);
static ElementData::MasterType masterTypeFromString(const QString &string);
static QString slaveTypeToString (ElementData::SlaveType type);
static ElementData::SlaveType slaveTypeFromString(const QString &string);
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;
QString m_drawing_information;
private:
void kindInfoFromXml(const QDomElement &xml_element);
};
#endif // ELEMENTDATA_H

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify

View File

@@ -1,6 +1,24 @@
/*
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 "terminaldata.h"
#include <QGraphicsObject>
#include <QDebug>
TerminalData::TerminalData():
PropertiesInterface()
@@ -44,8 +62,8 @@ void TerminalData::setParent(QGraphicsObject* parent)
void TerminalData::toSettings(QSettings &settings, const QString &prefix) const
{
Q_UNUSED(settings);
Q_UNUSED(prefix);
Q_UNUSED(settings)
Q_UNUSED(prefix)
}
/**
@@ -58,8 +76,8 @@ void TerminalData::toSettings(QSettings &settings, const QString &prefix) const
*/
void TerminalData::fromSettings(QSettings &settings, const QString& prefix)
{
Q_UNUSED(settings);
Q_UNUSED(prefix);
Q_UNUSED(settings)
Q_UNUSED(prefix)
}
/**
@@ -78,8 +96,6 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
{
QDomElement xml_element = xml_document.createElement("terminaldata");
// write the position of the terminal
// Write name and number to XML
// 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
@@ -87,6 +103,7 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
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)));
xml_element.appendChild(createXmlProperty(xml_document, "type", typeToString(m_type));
return(xml_element);
}
@@ -135,6 +152,11 @@ bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
// read the orientation of the terminal
// lit l'orientation de la borne
m_orientation = orientationFromString(o);
QStrint type;
if (propertyString(xml_element, "type", &type))
return false;
m_type = typeFromString(type);
return true;
}
@@ -142,9 +164,10 @@ bool TerminalData::valideXml(const QDomElement& xml_element) {
if (propertyDouble(xml_element, "x"))
return false;
if (propertyDouble(xml_element, "y"))
if (propertyString(xml_element, "type"))
return false;
// legacy elements do not have an uuid
// if (propertyUuid(xml_element, "uuid"))
// return false;
@@ -156,3 +179,41 @@ bool TerminalData::valideXml(const QDomElement& xml_element) {
return false;
return true;
}
/**
* @brief TerminalData::typeToString
* @param type
* @return type into a QString
*/
QString TerminalData::typeToString(TerminalData::Type type)
{
switch (type) {
case Generic:
return QString("Generic");
case Inner :
return QString("Inner");
case Outer :
return QString("Outer");
}
}
/**
* @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;
} else if (string == "Inner") {
return TerminalData::Inner;
} else if (string == "Outer") {
return TerminalData::Outer;
} else {
qDebug() << "TerminalData::typeFromString, argument string is invalid"
" failsafe type 'TerminalData::Generic' is returned";
return TerminalData::Generic;
}
}

View File

@@ -1,11 +1,28 @@
/*
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/>.
*/
#ifndef TERMINALDATA_H
#define TERMINALDATA_H
#include "../qet.h"
#include "propertiesinterface.h"
#include "qet.h"
#include <QUuid>
#include <QPointF>
#include <QUuid>
class QGraphicsObject;
@@ -18,10 +35,19 @@ class QGraphicsObject;
*/
class TerminalData : public PropertiesInterface
{
Q_GADGET
public:
enum Type {
Generic,
Inner,
Outer
};
Q_ENUM(Type)
TerminalData();
TerminalData(QGraphicsObject* parent);
~TerminalData();
~TerminalData() override;
void init();
@@ -35,6 +61,11 @@ class TerminalData : public PropertiesInterface
static bool valideXml(const QDomElement &xml_element);
static QString typeToString(TerminalData::Type type);
static TerminalData::Type typeFromString(const QString &string);
// must be public, because this class is a private member
// of PartTerminal/Terminal and they must access this data
public:
/**
@brief m_orientation
@@ -80,6 +111,7 @@ class TerminalData : public PropertiesInterface
PartTerminal and Terminal have access to it.
*/
QPointF m_pos{0,0};
TerminalData::Type m_type = TerminalData::Generic;
private:
QGraphicsObject* q{nullptr};
};

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
@@ -15,11 +15,12 @@
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QMetaEnum>
#include <QHash>
#include "xrefproperties.h"
#include "qetapp.h"
#include "../qetapp.h"
#include <QHash>
#include <QMetaEnum>
/**
@brief XRefProperties::XRefProperties

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2020 The QElectroTech Team
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify