mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +01:00
WIP
This commit is contained in:
@@ -907,6 +907,7 @@ Terminal* findTerminal(int conductor_index, QDomElement& f, QHash<int, Terminal
|
|||||||
} else
|
} else
|
||||||
return table_adr_id.value(id_p1);
|
return table_adr_id.value(id_p1);
|
||||||
}
|
}
|
||||||
|
qDebug() << "Diagram::findTerminal(): No terminal found.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1026,7 +1027,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
}
|
}
|
||||||
|
|
||||||
int state = 0;
|
int state = 0;
|
||||||
Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state);
|
Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); // read element definition!
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state);
|
QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state);
|
||||||
@@ -1085,7 +1086,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements);
|
Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements);
|
||||||
Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements);
|
Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements);
|
||||||
|
|
||||||
if (p1 && p2 && p1 != p2)
|
if (p1 && p2 && p1 != p2) // why the condition for unequal is required?
|
||||||
{
|
{
|
||||||
Conductor *c = new Conductor(p1, p2);
|
Conductor *c = new Conductor(p1, p2);
|
||||||
if (c->isValid())
|
if (c->isValid())
|
||||||
@@ -1096,6 +1097,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
delete c;
|
delete c;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Diagramm::fromXML(): No matching terminals found.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
|||||||
CustomElementGraphicPart(editor, parent)
|
CustomElementGraphicPart(editor, parent)
|
||||||
{
|
{
|
||||||
d = new TerminalData(this);
|
d = new TerminalData(this);
|
||||||
|
d->m_name = tr("terminal");
|
||||||
d->m_orientation = Qet::North;
|
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
|
d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
||||||
updateSecondPoint();
|
updateSecondPoint();
|
||||||
|
|||||||
@@ -212,9 +212,9 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
|
|||||||
bool ok;
|
bool ok;
|
||||||
bool tmp = attr.toInt(&ok);
|
bool tmp = attr.toInt(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
if (attr == "true")
|
if (attr == "true" || attr == "1")
|
||||||
tmp = true;
|
tmp = true;
|
||||||
else if (attr == "false")
|
else if (attr == "false" || attr == "0")
|
||||||
tmp = false;
|
tmp = false;
|
||||||
else {
|
else {
|
||||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
|
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ void TerminalData::fromSettings(const QSettings& settings, const QString&)
|
|||||||
|
|
||||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||||
{
|
{
|
||||||
QDomElement xml_element = xml_document.createElement("terminal");
|
QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||||
|
|
||||||
xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x()));
|
xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x()));
|
||||||
xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y()));
|
xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y()));
|
||||||
|
|||||||
@@ -1106,8 +1106,6 @@ bool Conductor::pathFromXml(const QDomElement &e) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool isHorizontal = false;
|
bool isHorizontal = false;
|
||||||
if (propertyBool(current_segment, "orientation", &isHorizontal) == PropertyFlags::NoValidConversion) {
|
|
||||||
// legacy
|
|
||||||
QString orientation;
|
QString orientation;
|
||||||
if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) {
|
if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) {
|
||||||
if (orientation == "horizontal")
|
if (orientation == "horizontal")
|
||||||
@@ -1116,7 +1114,6 @@ bool Conductor::pathFromXml(const QDomElement &e) {
|
|||||||
qDebug() << "PathFromXML failed";
|
qDebug() << "PathFromXML failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isHorizontal) {
|
if (isHorizontal) {
|
||||||
segments_x << segment_length;
|
segments_x << segment_length;
|
||||||
|
|||||||
@@ -574,13 +574,11 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
|
|||||||
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!TerminalData::valideXml(dom_element))
|
if (!Terminal::valideXml(dom_element))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
TerminalData* data = new TerminalData();
|
Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this);
|
||||||
data->fromXml(dom_element);
|
new_terminal->fromXml(dom_element);
|
||||||
|
|
||||||
Terminal *new_terminal = new Terminal(data, this);
|
|
||||||
m_terminals << new_terminal;
|
m_terminals << new_terminal;
|
||||||
|
|
||||||
//Sort from top to bottom and left to rigth
|
//Sort from top to bottom and left to rigth
|
||||||
@@ -653,7 +651,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
||||||
bool terminal_trouvee = false;
|
bool terminal_trouvee = false;
|
||||||
foreach(QDomElement qde, liste_terminals) {
|
foreach(QDomElement qde, liste_terminals) {
|
||||||
if (p -> fromXml(qde)) {
|
if (p -> fromXml(qde)) { // TODO: is there validXML enough? Because the Terminal was already read in the ElementCreation function
|
||||||
qDebug() << "Matching Terminal found.";
|
qDebug() << "Matching Terminal found.";
|
||||||
priv_id_adr.insert(qde.attribute("id").toInt(), p);
|
priv_id_adr.insert(qde.attribute("id").toInt(), p);
|
||||||
terminal_trouvee = true;
|
terminal_trouvee = true;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
|
|||||||
// Number of terminal
|
// Number of terminal
|
||||||
number_terminal_ = std::move(number);
|
number_terminal_ = std::move(number);
|
||||||
// Name of terminal
|
// Name of terminal
|
||||||
name_terminal_ = std::move(name);
|
d->m_name = std::move(name);
|
||||||
name_terminal_hidden = hiddenName;
|
name_terminal_hidden = hiddenName;
|
||||||
// par defaut : pas de conducteur
|
// par defaut : pas de conducteur
|
||||||
|
|
||||||
@@ -193,10 +193,18 @@ void Terminal::setNumber(QString number) {
|
|||||||
@param name
|
@param name
|
||||||
*/
|
*/
|
||||||
void Terminal::setName(QString name, bool hiddenName) {
|
void Terminal::setName(QString name, bool hiddenName) {
|
||||||
name_terminal_ = std::move(name);
|
d->m_name = std::move(name);
|
||||||
name_terminal_hidden = hiddenName;
|
name_terminal_hidden = hiddenName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Terminal::name
|
||||||
|
@return the name of terminal.
|
||||||
|
*/
|
||||||
|
inline QString Terminal::name() const {
|
||||||
|
return(d->m_name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Terminal::addConductor
|
@brief Terminal::addConductor
|
||||||
Add a conductor to this terminal
|
Add a conductor to this terminal
|
||||||
@@ -715,13 +723,17 @@ QList<Conductor *> Terminal::conductors() const {
|
|||||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||||
QDomElement qdo = doc.createElement("terminal");
|
QDomElement qdo = doc.createElement("terminal");
|
||||||
|
|
||||||
qdo.appendChild(createXmlProperty(doc, "x", dock_elmt_.x()));
|
|
||||||
qdo.appendChild(createXmlProperty(doc, "y", dock_elmt_.y()));
|
|
||||||
qdo.appendChild(createXmlProperty(doc, "orientation", orientationToString(d->m_orientation)));
|
|
||||||
qdo.appendChild(createXmlProperty(doc, "number", number_terminal_));
|
qdo.appendChild(createXmlProperty(doc, "number", number_terminal_));
|
||||||
qdo.appendChild(createXmlProperty(doc, "name", name_terminal_));
|
|
||||||
qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden));
|
qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden));
|
||||||
|
|
||||||
|
// store terminal data too!
|
||||||
|
|
||||||
|
// Do not store terminal data in its own child
|
||||||
|
QDomElement terminalDataElement = d->toXml(doc);
|
||||||
|
for (int i=0; i < terminalDataElement.childNodes().length(); i++) {
|
||||||
|
qdo.appendChild(terminalDataElement.childNodes().at(i));
|
||||||
|
}
|
||||||
|
|
||||||
return(qdo);
|
return(qdo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,32 +743,17 @@ QDomElement Terminal::toXml(QDomDocument &doc) const {
|
|||||||
@param terminal Le QDomElement a analyser
|
@param terminal Le QDomElement a analyser
|
||||||
@return true si le QDomElement passe en parametre est une borne, false sinon
|
@return true si le QDomElement passe en parametre est une borne, false sinon
|
||||||
*/
|
*/
|
||||||
bool Terminal::valideXml(QDomElement &terminal) {
|
bool Terminal::valideXml(const QDomElement &terminal) {
|
||||||
if (terminal.tagName() != "terminal") return(false);
|
if (terminal.tagName() != "terminal") return(false);
|
||||||
|
|
||||||
if (propertyString(terminal, "number"))
|
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
|
||||||
return false;
|
// if (propertyString(terminal, "number"))
|
||||||
|
// return false;
|
||||||
|
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
|
||||||
|
// if (propertyBool(terminal, "nameHidden"))
|
||||||
|
// return false;
|
||||||
|
|
||||||
if (propertyString(terminal, "name"))
|
if (!TerminalData::valideXml(terminal))
|
||||||
return false;
|
|
||||||
|
|
||||||
if (propertyBool(terminal, "nameHidden"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (propertyDouble(terminal, "x"))
|
|
||||||
return false;
|
|
||||||
if (propertyDouble(terminal, "y"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QString o;
|
|
||||||
if (propertyString(terminal, "orientation", &o))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Qet::Orientation terminal_or = orientationFromString(o);
|
|
||||||
if (terminal_or != Qet::North
|
|
||||||
&& terminal_or != Qet::South
|
|
||||||
&& terminal_or != Qet::East
|
|
||||||
&& terminal_or != Qet::West)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// a ce stade, la borne est syntaxiquement correcte
|
// a ce stade, la borne est syntaxiquement correcte
|
||||||
@@ -772,30 +769,15 @@ bool Terminal::valideXml(QDomElement &terminal) {
|
|||||||
(memes coordonnes, meme orientation), false sinon
|
(memes coordonnes, meme orientation), false sinon
|
||||||
*/
|
*/
|
||||||
bool Terminal::fromXml(const QDomElement &terminal) {
|
bool Terminal::fromXml(const QDomElement &terminal) {
|
||||||
if (propertyString(terminal, "number", &number_terminal_))
|
propertyString(terminal, "number", &number_terminal_);
|
||||||
|
|
||||||
|
propertyBool(terminal, "nameHidden", &name_terminal_hidden);
|
||||||
|
|
||||||
|
if(!d->fromXml(terminal))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (propertyString(terminal, "name", &name_terminal_))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (propertyBool(terminal, "nameHidden", &name_terminal_hidden))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
double x, y;
|
|
||||||
if (propertyDouble(terminal, "x", &x))
|
|
||||||
return false;
|
|
||||||
if (propertyDouble(terminal, "y", &y))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QString o;
|
|
||||||
if (propertyString(terminal, "orientation", &o))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!qFuzzyCompare(x, dock_elmt_.x()) ||
|
|
||||||
!qFuzzyCompare(y, dock_elmt_.y()) ||
|
|
||||||
orientationFromString(o) != d->m_orientation)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
init(number_terminal_, d->m_name, name_terminal_hidden); // initialize dock_elmt_. This must be done after Terminal data is initialized
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
|
|||||||
bool canBeLinkedTo(Terminal *);
|
bool canBeLinkedTo(Terminal *);
|
||||||
|
|
||||||
// methods related to XML import/export
|
// methods related to XML import/export
|
||||||
static bool valideXml(QDomElement &);
|
static bool valideXml(const QDomElement &);
|
||||||
bool fromXml (const QDomElement &) override;
|
bool fromXml (const QDomElement &) override;
|
||||||
QDomElement toXml (QDomDocument &) const override;
|
QDomElement toXml (QDomDocument &) const override;
|
||||||
|
|
||||||
@@ -148,9 +148,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
|
|||||||
QColor hovered_color_{Terminal::hovered_color_};
|
QColor hovered_color_{Terminal::hovered_color_};
|
||||||
/// Number of Terminal
|
/// Number of Terminal
|
||||||
QString number_terminal_;
|
QString number_terminal_;
|
||||||
/// Name of Terminal
|
bool name_terminal_hidden{true};
|
||||||
QString name_terminal_;
|
|
||||||
bool name_terminal_hidden;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(QString number, QString name, bool hiddenName);
|
void init(QString number, QString name, bool hiddenName);
|
||||||
@@ -174,14 +172,6 @@ inline QString Terminal::number() const {
|
|||||||
return(number_terminal_);
|
return(number_terminal_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Terminal::name
|
|
||||||
@return the name of terminal.
|
|
||||||
*/
|
|
||||||
inline QString Terminal::name() const {
|
|
||||||
return(name_terminal_);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
|
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
|
||||||
const bool all_diagram = true);
|
const bool all_diagram = true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user