mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 06:34:13 +02:00
Work out formula labels and wire texts from the file, with the folios' code
The first fill from the document stored the label and wire text saved in the file. QElectroTech saves what it last worked out, not what the formula gives now: K%total-%id saved as K1-1 on a 3-folio project is K3-1 on the folios, and the same for a wire's formula. So the document fill disagreed with the folio fill on any file whose folios had been added or moved. AssignVariables now works from a FormulaContext: the folio's number, index, total, plant, location, title-block and project variables, and the element's grid cell and prefix or the wire's four properties. The Diagram overload fills one from a built folio, the database fills one from the file, and both call the same evaluation. Also brought in line with Diagram::fromXml(): an element Element::valideXml() rejects is skipped with its wires; a folio where two elements number their terminals alike (Element::fromXml() refuses one, by geometry), a frozen formula wire text, and the older sequential-number attributes are left to the folios. Each folio's border now starts from the defaults a new Diagram has, not the previous folio's values. tst_databasefromdocument: formulasAreWorkedOut (every variable kind, stale saved values), unbuiltElementIsLeftOut, clashingTerminalIdsFallBack. Each fails with its fix removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -220,12 +220,56 @@ namespace autonum
|
||||
Diagram *diagram,
|
||||
const Element *elmt,
|
||||
const Conductor *cndr)
|
||||
{
|
||||
if (!diagram) {
|
||||
return formula;
|
||||
}
|
||||
|
||||
FormulaContext context;
|
||||
const BorderTitleBlock &border = diagram->border_and_titleblock;
|
||||
context.folio = border.folio();
|
||||
context.folio_index = diagram->folioIndex();
|
||||
context.folio_total = border.folioTotal();
|
||||
context.plant = border.plant();
|
||||
context.locmach = border.locmach();
|
||||
context.title_block_fields = border.additionalFields();
|
||||
context.project_properties = diagram->project()->projectProperties();
|
||||
if (elmt)
|
||||
{
|
||||
context.has_element = true;
|
||||
context.element_position = diagram->convertPosition(elmt->scenePos());
|
||||
context.element_prefix = elmt->getPrefix();
|
||||
}
|
||||
if (cndr)
|
||||
{
|
||||
context.has_conductor = true;
|
||||
context.wire_function = cndr->properties().m_function;
|
||||
context.wire_tension_protocol = cndr->properties().m_tension_protocol;
|
||||
context.wire_color = cndr->properties().m_wire_color;
|
||||
context.wire_section = cndr->properties().m_wire_section;
|
||||
}
|
||||
return formulaToLabel(std::move(formula), seqStruct, context);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief AssignVariables::formulaToLabel
|
||||
Return the formula with its variables assigned from @p context,
|
||||
which describes a folio and the element or conductor the formula
|
||||
belongs to without needing either to be built.
|
||||
@param formula - the formula to work
|
||||
@param seqStruct - struct where is stocked int values
|
||||
(struct is passed as a reference
|
||||
and modified by this static method)
|
||||
@param context - what the variables are read from
|
||||
@return the string with variable assigned.
|
||||
*/
|
||||
QString AssignVariables::formulaToLabel(QString formula,
|
||||
sequentialNumbers &seqStruct,
|
||||
const FormulaContext &context)
|
||||
{
|
||||
AssignVariables av(std::move(formula),
|
||||
seqStruct,
|
||||
diagram,
|
||||
elmt,
|
||||
cndr);
|
||||
context);
|
||||
seqStruct = av.m_seq_struct;
|
||||
return av.m_assigned_label;
|
||||
}
|
||||
@@ -347,76 +391,54 @@ namespace autonum
|
||||
|
||||
AssignVariables::AssignVariables(const QString& formula,
|
||||
const sequentialNumbers& seqStruct,
|
||||
Diagram *diagram,
|
||||
const Element *elmt,
|
||||
const Conductor *cndr):
|
||||
m_diagram(diagram),
|
||||
const FormulaContext &context):
|
||||
m_context(context),
|
||||
m_arg_formula(formula),
|
||||
m_assigned_label(formula),
|
||||
m_seq_struct(seqStruct),
|
||||
m_element(elmt),
|
||||
m_conductor(cndr)
|
||||
m_seq_struct(seqStruct)
|
||||
{
|
||||
if (m_diagram)
|
||||
m_assigned_label.replace("%F", m_context.folio);
|
||||
m_assigned_label.replace("%f",
|
||||
QString::number(m_context.folio_index+1));
|
||||
m_assigned_label.replace("%id",
|
||||
QString::number(m_context.folio_index+1));
|
||||
m_assigned_label.replace("%total",
|
||||
QString::number(m_context.folio_total));
|
||||
m_assigned_label.replace("%M", m_context.plant);
|
||||
m_assigned_label.replace("%LM", m_context.locmach);
|
||||
|
||||
QSettings settings;
|
||||
if (m_context.has_element)
|
||||
{
|
||||
m_assigned_label.replace("%F",
|
||||
m_diagram
|
||||
-> border_and_titleblock
|
||||
.folio());
|
||||
m_assigned_label.replace("%f",
|
||||
QString::number(
|
||||
m_diagram
|
||||
->folioIndex()+1));
|
||||
m_assigned_label.replace("%id",
|
||||
QString::number(
|
||||
m_diagram
|
||||
->folioIndex()+1));
|
||||
m_assigned_label.replace("%total",
|
||||
QString::number(
|
||||
m_diagram
|
||||
->border_and_titleblock
|
||||
.folioTotal()));
|
||||
m_assigned_label.replace("%M",
|
||||
m_diagram
|
||||
-> border_and_titleblock
|
||||
.plant());
|
||||
m_assigned_label.replace("%LM",
|
||||
m_diagram
|
||||
-> border_and_titleblock
|
||||
.locmach());
|
||||
|
||||
QSettings settings;
|
||||
if (m_element)
|
||||
{
|
||||
if (settings.value("border-columns_0", true).toBool()){
|
||||
m_assigned_label.replace("%c", QString::number(m_diagram->convertPosition(m_element->scenePos()).number() - 1));
|
||||
}else{
|
||||
m_assigned_label.replace("%c", QString::number(m_diagram->convertPosition(m_element->scenePos()).number()));
|
||||
}
|
||||
m_assigned_label.replace("%l", m_diagram->convertPosition(m_element->scenePos()).letter());
|
||||
m_assigned_label.replace("%prefix", m_element->getPrefix());
|
||||
if (settings.value("border-columns_0", true).toBool()){
|
||||
m_assigned_label.replace("%c", QString::number(m_context.element_position.number() - 1));
|
||||
}else{
|
||||
m_assigned_label.replace("%c", QString::number(m_context.element_position.number()));
|
||||
}
|
||||
|
||||
if (m_conductor)
|
||||
{
|
||||
m_assigned_label.replace("%wf", cndr->properties().m_function);
|
||||
m_assigned_label.replace("%wv", cndr->properties().m_tension_protocol);
|
||||
m_assigned_label.replace("%wc", cndr->properties().m_wire_color);
|
||||
m_assigned_label.replace("%ws", cndr->properties().m_wire_section);
|
||||
}
|
||||
|
||||
assignTitleBlockVar();
|
||||
assignProjectVar();
|
||||
assignSequence();
|
||||
m_assigned_label.replace("%l", m_context.element_position.letter());
|
||||
m_assigned_label.replace("%prefix", m_context.element_prefix);
|
||||
}
|
||||
|
||||
if (m_context.has_conductor)
|
||||
{
|
||||
m_assigned_label.replace("%wf", m_context.wire_function);
|
||||
m_assigned_label.replace("%wv", m_context.wire_tension_protocol);
|
||||
m_assigned_label.replace("%wc", m_context.wire_color);
|
||||
m_assigned_label.replace("%ws", m_context.wire_section);
|
||||
}
|
||||
|
||||
assignTitleBlockVar();
|
||||
assignProjectVar();
|
||||
assignSequence();
|
||||
}
|
||||
|
||||
void AssignVariables::assignTitleBlockVar()
|
||||
{
|
||||
for (int i = 0; i < m_diagram->border_and_titleblock.additionalFields().count(); i++)
|
||||
DiagramContext fields = m_context.title_block_fields;
|
||||
for (int i = 0; i < fields.count(); i++)
|
||||
{
|
||||
QString folio_variable = m_diagram->border_and_titleblock.additionalFields().keys().at(i);
|
||||
QVariant folio_value = m_diagram->border_and_titleblock.additionalFields().operator [](folio_variable);
|
||||
QString folio_variable = fields.keys().at(i);
|
||||
QVariant folio_value = fields[folio_variable];
|
||||
|
||||
if (m_assigned_label.contains(folio_variable)) {
|
||||
m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
|
||||
@@ -427,10 +449,11 @@ namespace autonum
|
||||
|
||||
void AssignVariables::assignProjectVar()
|
||||
{
|
||||
for (int i = 0; i < m_diagram->project()->projectProperties().count(); i++)
|
||||
DiagramContext properties = m_context.project_properties;
|
||||
for (int i = 0; i < properties.count(); i++)
|
||||
{
|
||||
QString folio_variable = m_diagram->project()->projectProperties().keys().at(i);
|
||||
QVariant folio_value = m_diagram->project()->projectProperties().operator [](folio_variable);
|
||||
QString folio_variable = properties.keys().at(i);
|
||||
QVariant folio_value = properties[folio_variable];
|
||||
|
||||
if (m_assigned_label.contains(folio_variable)) {
|
||||
m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
|
||||
|
||||
Reference in New Issue
Block a user