New element: Line definition

This commit is contained in:
Kellermorph
2026-05-21 20:47:44 +02:00
parent 8c557a7f29
commit f416c2a97e
10 changed files with 520 additions and 391 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -220,7 +220,7 @@ void DynamicTextFieldEditor::fillInfoComboBox()
QStringList strl; QStringList strl;
auto type = elementEditor()->elementScene()->elementData().m_type; auto type = elementEditor()->elementScene()->elementData().m_type;
if(type & ElementData::AllReport) { if((type & ElementData::AllReport) || (type == ElementData::ConductorDefinition)) {
strl = QETInformation::folioReportInfoKeys(); strl = QETInformation::folioReportInfoKeys();
} }
else { else {
@@ -365,7 +365,8 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index) {
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked() void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
{ {
bool isReport = false; bool isReport = false;
if (elementEditor()->elementScene()->elementData().m_type & ElementData::AllReport) { auto type = elementEditor()->elementScene()->elementData().m_type;
if ((type & ElementData::AllReport) || (type == ElementData::ConductorDefinition)) {
isReport = true; isReport = true;
} }

View File

@@ -133,6 +133,7 @@ void ElementPropertiesEditorWidget::setUpInterface()
ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), ElementData::PreviousReport); ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), ElementData::PreviousReport);
ui->m_base_type_cb->addItem (tr("Bornier"), ElementData::Terminal); ui->m_base_type_cb->addItem (tr("Bornier"), ElementData::Terminal);
ui->m_base_type_cb->addItem (tr("Vignette"), ElementData::Thumbnail); ui->m_base_type_cb->addItem (tr("Vignette"), ElementData::Thumbnail);
ui->m_base_type_cb->addItem (tr("Définition de conducteur"), ElementData::ConductorDefinition);
// Slave option // Slave option
ui->m_state_cb->addItem(tr("Normalement ouvert"), ElementData::NO); ui->m_state_cb->addItem(tr("Normalement ouvert"), ElementData::NO);
@@ -188,6 +189,9 @@ void ElementPropertiesEditorWidget::updateTree()
case ElementData::PreviousReport: case ElementData::PreviousReport:
ui->m_tree->setDisabled(true); ui->m_tree->setDisabled(true);
break; break;
case ElementData::ConductorDefinition:
ui->m_tree->setDisabled(true);
break;
case ElementData::Master: case ElementData::Master:
ui->m_tree->setEnabled(true); ui->m_tree->setEnabled(true);
break; break;

View File

@@ -736,40 +736,62 @@ bool QETElementEditor::checkElement()
QList<QETWarning> warnings; QList<QETWarning> warnings;
QList<QETWarning> errors; QList<QETWarning> errors;
// Warning #1: Element haven't got terminal // Warning #1: Element haven't got terminal
// (except for report, because report must have one terminal and this checking is do below) // (except for report and conductor definition, because they must have one terminal and this checking is done below)
if (!m_elmt_scene -> containsTerminals() && if (!m_elmt_scene -> containsTerminals() &&
!(m_elmt_scene->elementData().m_type & ElementData::AllReport)) { !(m_elmt_scene->elementData().m_type & ElementData::AllReport) &&
m_elmt_scene->elementData().m_type != ElementData::ConductorDefinition) {
warnings << qMakePair( warnings << qMakePair(
tr("Absence de borne", "warning title"), tr("Absence de borne", "warning title"),
tr( tr(
"<br>En l'absence de borne, l'élément ne pourra être" "<br>En l'absence de borne, l'élément ne pourra être"
" relié à d'autres éléments par l'intermédiaire de conducteurs.", " relié à d'autres éléments par l'intermédiaire de conducteurs.",
"warning description" "warning description"
) )
); );
} }
// Check folio report element // Check folio report element
if (m_elmt_scene->elementData().m_type & ElementData::AllReport) if (m_elmt_scene->elementData().m_type & ElementData::AllReport)
{ {
int terminal =0; int terminal =0;
for(auto qgi : m_elmt_scene -> items()) { for(auto qgi : m_elmt_scene -> items()) {
if (qgraphicsitem_cast<PartTerminal *>(qgi)) { if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
terminal ++; terminal ++;
}
}
//Error folio report must have only one terminal
if (terminal != 1) {
errors << qMakePair (tr("Absence de borne"),
tr("<br><b>Erreur</b> :"
"<br>Les reports de folio doivent posséder une seul borne."
"<br><b>Solution</b> :"
"<br>Verifier que l'élément ne possède qu'une seul borne"));
} }
} }
//Error folio report must have only one terminal // Check conductor definition element
if (terminal != 1) { if (m_elmt_scene->elementData().m_type == ElementData::ConductorDefinition)
errors << qMakePair (tr("Absence de borne"), {
tr("<br><b>Erreur</b> :" int terminal =0;
"<br>Les reports de folio doivent posséder une seul borne."
"<br><b>Solution</b> :" for(auto qgi : m_elmt_scene -> items()) {
"<br>Verifier que l'élément ne possède qu'une seul borne")); if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
terminal ++;
}
}
// Error: Conductor definition must have exactly one terminal
if (terminal != 1) {
errors << qMakePair (tr("Nombre de bornes incorrect"),
tr("<br><b>Erreur</b> :"
"<br>Les définitions de conducteur ne peuvent posséder qu'une seule borne."
"<br><b>Solution</b> :"
"<br>Vérifier que l'élément ne possède qu'une seule borne"));
}
} }
}
if (!errors.count() && !warnings.count()) { if (!errors.count() && !warnings.count()) {
return(true); return(true);

View File

@@ -45,14 +45,26 @@ QDomElement ElementData::toXml(QDomDocument &xml_element) const {
bool ElementData::fromXml(const QDomElement &xml_element) bool ElementData::fromXml(const QDomElement &xml_element)
{ {
if(xml_element.tagName() != QLatin1String("definition") || if(xml_element.tagName() != QLatin1String("definition") ||
xml_element.attribute(QStringLiteral("type")) != QLatin1String("element")) { xml_element.attribute(QStringLiteral("type")) != QLatin1String("element")) {
return false; return false;
} }
// --- HIER STARTET UNSER DEBUG-BLOCK ---
// Wir holen den String aus der XML und speichern ihn kurz zwischen
QString raw_type_string = xml_element.attribute(QStringLiteral("link_type"), QStringLiteral("simple"));
qDebug() << "\n=== NEUES BAUTEIL WIRD GELADEN ===";
qDebug() << "[XML Parser] Roher 'link_type' String aus der .elmt Datei:" << raw_type_string;
// Jetzt übergeben wir ihn an deine Übersetzungs-Funktion
m_type = typeFromString(raw_type_string);
qDebug() << "[XML Parser] Übersetzter ElementData-Typ:" << typeToString(m_type);
// --- HIER ENDET UNSER DEBUG-BLOCK ---
m_type = typeFromString(xml_element.attribute(QStringLiteral("link_type"), QStringLiteral("simple")));
kindInfoFromXml(xml_element); kindInfoFromXml(xml_element);
m_informations.fromXml(xml_element.firstChildElement(QStringLiteral("elementInformations")), m_informations.fromXml(xml_element.firstChildElement(QStringLiteral("elementInformations")),
QStringLiteral("elementInformation")); QStringLiteral("elementInformation"));
m_names_list.fromXml(xml_element); m_names_list.fromXml(xml_element);
auto xml_draw_info = xml_element.firstChildElement(QStringLiteral("informations")); auto xml_draw_info = xml_element.firstChildElement(QStringLiteral("informations"));
@@ -323,6 +335,8 @@ QString ElementData::typeToString(ElementData::Type type)
return QStringLiteral("terminal"); return QStringLiteral("terminal");
case ElementData::Thumbnail: case ElementData::Thumbnail:
return QStringLiteral("thumbnail"); return QStringLiteral("thumbnail");
case ElementData::ConductorDefinition:
return QStringLiteral("conductor_definition");
default: default:
qDebug() << "ElementData::typeToString : type don't exist" qDebug() << "ElementData::typeToString : type don't exist"
<< "return failsafe value 'simple'"; << "return failsafe value 'simple'";
@@ -346,6 +360,8 @@ ElementData::Type ElementData::typeFromString(const QString &string)
return ElementData::Terminal; return ElementData::Terminal;
} else if (string == QLatin1String("thumbnail")) { } else if (string == QLatin1String("thumbnail")) {
return ElementData::Thumbnail; return ElementData::Thumbnail;
} else if (string == QLatin1String("conductor_definition")) {
return ElementData::ConductorDefinition;
} }
//Return simple if nothing match //Return simple if nothing match

View File

@@ -41,7 +41,8 @@ class ElementData : public PropertiesInterface
Master = 8, Master = 8,
Slave = 16, Slave = 16,
Terminal = 32, Terminal = 32,
Thumbnail = 64}; Thumbnail = 64,
ConductorDefinition = 128};
Q_ENUM(Type) Q_ENUM(Type)
Q_DECLARE_FLAGS(Types, Type) Q_DECLARE_FLAGS(Types, Type)

View File

@@ -302,7 +302,8 @@ void DynamicElementTextItem::refreshLabelConnection()
if ((m_text_from == ElementInfo && m_info_name == "label") || if ((m_text_from == ElementInfo && m_info_name == "label") ||
(m_text_from == CompositeText && m_composite_text.contains("%{label}"))) (m_text_from == CompositeText && m_composite_text.contains("%{label}")))
{ {
if(m_parent_element.data()->linkType() & Element::AllReport) if((m_parent_element.data()->linkType() & Element::AllReport) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition)
{ {
updateReportFormulaConnection(); updateReportFormulaConnection();
updateReportText(); updateReportText();
@@ -418,7 +419,8 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
updateXref(); updateXref();
} }
if (m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport)) //special treatment for report if (m_parent_element && ((m_parent_element.data()->linkType() & Element::AllReport) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition)) //special treatment for report
{ {
if(old_info_name != info_name) if(old_info_name != info_name)
{ {
@@ -472,7 +474,8 @@ void DynamicElementTextItem::setCompositeText(const QString &text)
updateXref(); updateXref();
} }
if (m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport)) //special treatment for report if (m_parent_element && ((m_parent_element.data()->linkType() & Element::AllReport) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition)) //special treatment for report
{ {
/* /*
* May be in some case the old and new composite text both have the var %{label}, * May be in some case the old and new composite text both have the var %{label},
@@ -726,28 +729,29 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch
if(!m_parent_element.data()->linkedElements().isEmpty()) if(!m_parent_element.data()->linkedElements().isEmpty())
masterChanged(); masterChanged();
} }
else if(m_parent_element.data()->linkType() & Element::AllReport) else if((m_parent_element.data()->linkType() & Element::AllReport) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition)
{ {
//Get the report formula, and add connection to keep up to date the formula. //Get the report formula, and add connection to keep up to date the formula.
if (m_parent_element.data()->diagram() && m_parent_element.data()->diagram()->project()) if (m_parent_element.data()->diagram() && m_parent_element.data()->diagram()->project())
{ {
m_report_formula = m_parent_element.data()->diagram()->project()->defaultReportProperties(); m_report_formula = m_parent_element.data()->diagram()->project()->defaultReportProperties();
m_report_formula_con = connect(m_parent_element.data()->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged); m_report_formula_con = connect(m_parent_element.data()->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged);
} }
//Add connection to keep up to date the status of the element linked to the parent folio report of this text. //Add connection to keep up to date the status of the element linked to the parent folio report of this text.
connect(m_parent_element.data(), &Element::linkedElementChanged, this, &DynamicElementTextItem::reportChanged); connect(m_parent_element.data(), &Element::linkedElementChanged, this, &DynamicElementTextItem::reportChanged);
//The parent is already linked, we call reportChanged for init the connection //The parent is already linked, we call reportChanged for init the connection
if(!m_parent_element.data()->linkedElements().isEmpty()) if(!m_parent_element.data()->linkedElements().isEmpty())
reportChanged(); reportChanged();
if(m_parent_element.data()->terminals().size()) if(m_parent_element.data()->terminals().size())
{ {
//Add connection to keep up date the conductors added or removed to the parent folio report element //Add connection to keep up date the conductors added or removed to the parent folio report element
connect(m_parent_element.data()->terminals().first(), &Terminal::conductorWasAdded, this, &DynamicElementTextItem::conductorWasAdded); connect(m_parent_element.data()->terminals().first(), &Terminal::conductorWasAdded, this, &DynamicElementTextItem::conductorWasAdded);
connect(m_parent_element.data()->terminals().first(), &Terminal::conductorWasRemoved, this, &DynamicElementTextItem::conductorWasRemoved); connect(m_parent_element.data()->terminals().first(), &Terminal::conductorWasRemoved, this, &DynamicElementTextItem::conductorWasRemoved);
} }
//Get a conductor in the potential //Get a conductor in the potential
setPotentialConductor(); setPotentialConductor();
} }
else if(m_parent_element.data()->linkType() == Element::Master) else if(m_parent_element.data()->linkType() == Element::Master)
@@ -1027,7 +1031,8 @@ void DynamicElementTextItem::clearFormulaConnection()
void DynamicElementTextItem::updateReportFormulaConnection() void DynamicElementTextItem::updateReportFormulaConnection()
{ {
if(!(m_parent_element.data()->linkType() & Element::AllReport)) if(!(m_parent_element.data()->linkType() & Element::AllReport) &&
m_parent_element.data()->linkType() != Element::ConductorDefinition)
return; return;
removeConnectionForReportFormula(m_report_formula); removeConnectionForReportFormula(m_report_formula);
@@ -1041,7 +1046,8 @@ void DynamicElementTextItem::updateReportFormulaConnection()
*/ */
void DynamicElementTextItem::updateReportText() void DynamicElementTextItem::updateReportText()
{ {
if(!(m_parent_element.data()->linkType() & Element::AllReport)) if(!(m_parent_element.data()->linkType() & Element::AllReport) &&
m_parent_element.data()->linkType() != Element::ConductorDefinition)
return; return;
if (m_text_from == ElementInfo && m_info_name == "label") if (m_text_from == ElementInfo && m_info_name == "label")
@@ -1123,7 +1129,8 @@ void DynamicElementTextItem::conductorWasRemoved(Conductor *conductor)
*/ */
void DynamicElementTextItem::setPotentialConductor() void DynamicElementTextItem::setPotentialConductor()
{ {
if(parentElement() && (parentElement()->linkType() & Element::AllReport)) if(parentElement() && ((parentElement()->linkType() & Element::AllReport) || (parentElement()->linkType() == Element::ConductorDefinition) ||
parentElement()->linkType() == Element::ConductorDefinition))
{ {
if(parentElement()->terminals().isEmpty()) if(parentElement()->terminals().isEmpty())
return; return;
@@ -1156,6 +1163,7 @@ void DynamicElementTextItem::setPotentialConductor()
connect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged); connect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
} }
} }
conductorPropertiesChanged();
} }
else //This text haven't got a parent element, then ther isn't a conductor in the potential else //This text haven't got a parent element, then ther isn't a conductor in the potential
{ {
@@ -1172,7 +1180,8 @@ void DynamicElementTextItem::setPotentialConductor()
*/ */
void DynamicElementTextItem::conductorPropertiesChanged() void DynamicElementTextItem::conductorPropertiesChanged()
{ {
if(m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport)) if(m_parent_element && ((m_parent_element.data()->linkType() & Element::AllReport) || (m_parent_element.data()->linkType() == Element::ConductorDefinition) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition))
{ {
if(m_text_from == ElementInfo) if(m_text_from == ElementInfo)
{ {
@@ -1200,8 +1209,9 @@ void DynamicElementTextItem::conductorPropertiesChanged()
QString DynamicElementTextItem::reportReplacedCompositeText() const QString DynamicElementTextItem::reportReplacedCompositeText() const
{ {
QString string; QString string;
if(m_parent_element.data()->linkType() & Element::AllReport) if((m_parent_element.data()->linkType() & Element::AllReport) || (m_parent_element.data()->linkType() == Element::ConductorDefinition) ||
m_parent_element.data()->linkType() == Element::ConductorDefinition)
{ {
string = m_composite_text; string = m_composite_text;

View File

@@ -36,6 +36,7 @@
#include "../qetxml.h" #include "../qetxml.h"
#include "../qetversion.h" #include "../qetversion.h"
#include "qgraphicsitemutility.h" #include "qgraphicsitemutility.h"
#include <QDebug>
#include <QDomElement> #include <QDomElement>
#include <utility> #include <utility>
@@ -431,6 +432,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_data.fromXml(xml_def_elmt); m_data.fromXml(xml_def_elmt);
setToolTip(name()); setToolTip(name());
QString my_type_str = xml_def_elmt.attribute(QStringLiteral("link_type"), QStringLiteral("simple"));
if (my_type_str == QLatin1String("conductor_definition")) {
m_link_type = Element::ConductorDefinition;
}
//load kind informations //load kind informations
m_kind_informations.fromXml( m_kind_informations.fromXml(
xml_def_elmt.firstChildElement(QStringLiteral("kindInformations")), xml_def_elmt.firstChildElement(QStringLiteral("kindInformations")),
@@ -627,6 +633,9 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
Terminal *new_terminal = new Terminal(data, this); Terminal *new_terminal = new Terminal(data, this);
m_terminals << new_terminal; m_terminals << new_terminal;
connect(new_terminal, &Terminal::conductorWasAdded, this, &Element::updateConductorTexts);
connect(new_terminal, &Terminal::conductorWasRemoved, this, &Element::updateConductorTexts);
//Sort from top to bottom and left to right //Sort from top to bottom and left to right
std::sort(m_terminals.begin(), std::sort(m_terminals.begin(),
m_terminals.end(), m_terminals.end(),
@@ -1288,6 +1297,8 @@ QString Element::linkTypeToString() const
return QStringLiteral("Terminale"); return QStringLiteral("Terminale");
case Thumbnail: case Thumbnail:
return QStringLiteral("Thumbnail"); return QStringLiteral("Thumbnail");
case ConductorDefinition:
return QStringLiteral("ConductorDefinition");
default: default:
return QStringLiteral("Unknown"); return QStringLiteral("Unknown");
} }
@@ -1555,3 +1566,25 @@ ElementsLocation Element::location() const
{ {
return m_location; return m_location;
} }
/**
* @brief Element::updateConductorTexts
*Slot that is triggered when a cable is *
*connected to or disconnected from a terminal on this component.
*/
/**
* @brief Element::updateConductorTexts
*/
void Element::updateConductorTexts()
{
if (m_link_type != Element::ConductorDefinition) {
return;
}
for (DynamicElementTextItem *deti : m_dynamic_text_list) {
if (deti) {
deti->setPotentialConductor();
deti->updateLabel();
}
}
}

View File

@@ -52,14 +52,15 @@ class Element : public QetGraphicsItem
(master, slave, report ect...) (master, slave, report ect...)
*/ */
enum kind { enum kind {
Simple = 1, Simple = 1,
NextReport = 2, NextReport = 2,
PreviousReport = 4, PreviousReport = 4,
AllReport = 6, AllReport = 6,
Master = 8, Master = 8,
Slave = 16, Slave = 16,
Terminale = 32, Terminale = 32,
Thumbnail = 64}; Thumbnail = 64,
ConductorDefinition = 128};
Element(const ElementsLocation &location, Element(const ElementsLocation &location,
QGraphicsItem * = nullptr, QGraphicsItem * = nullptr,
@@ -95,6 +96,8 @@ class Element : public QetGraphicsItem
DynamicElementTextItem *text, DynamicElementTextItem *text,
ElementTextItemGroup *group); ElementTextItemGroup *group);
public slots:
void updateConductorTexts();
public: public:
QList<Terminal *> terminals() const; QList<Terminal *> terminals() const;

View File

@@ -308,6 +308,9 @@ void ElementPropertiesWidget::updateUi()
case Element::Terminale: case Element::Terminale:
m_list_editor << new ElementInfoWidget(m_element, this); m_list_editor << new ElementInfoWidget(m_element, this);
break; break;
case Element::ConductorDefinition:
break;
default: default:
break; break;
} }