Files
qelectrotech-source-mirror/sources/autoNum/assignvariables.h
T
Kellermorph bf9b34398d Add cable management: drawing, cores, numbering, cross-references and cable list
Cables are drawn line objects (toolbar button next to the auto
break/reconnect button, click-move-click, right click cancels), not
components. The type comes from a CSV catalog following the material
list pattern (designation, cores, core colours, editable through the
entry dialog with "Nouvelle entrée" / "Modifier l'entrée").

Each core is bound to the wire its colour label stands on, and the
cable reference is generated per core and written into the Conductor
entry via Conductor::setCableReference(label, cable uuid, slot). The
conductor entry is where it has to live because the terminal strip
plan (Klemmenplan) consumes it in the next step.

Numbering: "Cables" rule under Programmeinstellungen/Neues
Projekt/Nummerierung auto (mirrored in project properties), literal
"W" fallback without a rule, French gate dialog when no rule exists,
Nummerierung menu with the renumber dialog (preferred axis, per-folio
counter, rule and counter state written back, hand-typed names ask,
whole-project scope).

Also included: label block and under-line texts with per-text font and
alignment plus the material-list cell margins, free-core placement and
right-click removal, claim questions for wires of other cables,
multi-selection drag as one undo step, type change with confirmation,
cross-references for type "Cable" (%f-%l%c, own font, clickable links
in exported PDFs), report propagation of the cable definition,
Listes menu (table of contents, material list, terminal strip manager,
terminal generator plugin, cable list), cable list with freely
selectable columns (installation/localisation of cable, start and end,
Blatt start/end, length, used cores...), CSV export dialog with column
pick and preview in the Projekt menu, script API (addTable kind
"cable_list", exportCableList) and a unit test for the type catalog.
2026-10-08 15:56:00 +02:00

151 lines
5.5 KiB
C++

/*
Copyright 2006-2026 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 ASSIGNVARIABLES_H
#define ASSIGNVARIABLES_H
#include "../diagramcontext.h"
#include "../diagramposition.h"
#include "numerotationcontext.h"
#include <QPointF>
#include <QString>
#include <QStringList>
class Conductor;
class Diagram;
class Element;
class ElementsLocation;
namespace autonum
{
class sequentialNumbers
{
public:
sequentialNumbers();
sequentialNumbers(const sequentialNumbers &other);
~sequentialNumbers();
sequentialNumbers &operator= (const sequentialNumbers &other);
bool operator== (const sequentialNumbers &other) const;
bool operator!= (const sequentialNumbers &other) const;
QDomElement toXml(QDomDocument &document, const QString& tag_name = QString("sequentialNumbers")) const;
void fromXml(const QDomElement &element);
void clear();
QStringList unit;
/// Values of the cyclic (modulo) parts, referenced by %seqw_N.
QStringList wrap;
QStringList unit_folio;
QStringList ten;
QStringList ten_folio;
QStringList hundred;
QStringList hundred_folio;
QStringList alpha;
};
/**
@brief The FormulaContext struct
Everything a formula's variables are read from: the folio it is on
and, for an element's or a conductor's formula, that item.
AssignVariables::formulaToLabel() fills one from a built folio; the
project database fills one from the project's file.
*/
struct FormulaContext
{
/// border_and_titleblock.folio(), folioIndex(), folioTotal()...
QString folio;
int folio_index = 0;
int folio_total = 0;
QString plant;
QString locmach;
/// the title block's additional fields and the project's properties
DiagramContext title_block_fields;
DiagramContext project_properties;
/// an element's grid cell (%c, %l) and prefix
bool has_element = false;
DiagramPosition element_position;
QString element_prefix;
/// a conductor's %wf, %wv, %wc and %ws
bool has_conductor = false;
QString wire_function;
QString wire_tension_protocol;
QString wire_color;
QString wire_section;
};
/**
@brief The AssignVariables class
This class assign variable of a formula string.
Return the final string used to be displayed from a formula string.
*/
class AssignVariables
{
public:
static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr, const Conductor *cndr = nullptr);
static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, const FormulaContext &context);
static QString replaceVariable (const QString &formula, const DiagramContext &dc);
static QString genericXref (const Element *element);
private:
AssignVariables(const QString& formula, const sequentialNumbers& seqStruct, const FormulaContext &context);
void assignTitleBlockVar();
void assignProjectVar();
void assignSequence();
const FormulaContext &m_context;
QString m_arg_formula;
QString m_assigned_label;
sequentialNumbers m_seq_struct;
};
void setSequentialToList(QStringList &list, NumerotationContext &nc, const QString& type);
void setFolioSequentialToHash(QStringList &list, QHash<QString, QStringList> &hash, const QString& autoNumName);
void setSequential(const QString& label, autonum::sequentialNumbers &seqStruct, NumerotationContext &context, Diagram *diagram, const QString& hashKey);
QString numerotationContextToFormula(const NumerotationContext &nc);
/**
Put back every part of a numbering rule whose counter belongs to
one single folio -- "Chiffre 1 - Folio" and its two longer forms
-- to the beginning that folio is numbered from, which is the
initial value written into the rule itself. The parts which count
over the whole project are left exactly as they are: a folio
starts again, the project does not.
@param nc the rule to read
@return the same rule, with its folio-bound counters restarted
*/
NumerotationContext resetFolioCounters(const NumerotationContext &nc);
/**
Set every part of a numbering rule which counts back to its very
first value, so that numbering starts at the beginning again --
which is what numbering a whole project over has to do, whatever
the last number handed out happened to be. A part which counts
from an initial value of its own goes back to that value, a plain
number goes back to 1, a cyclic one to 0 and an alphabetic one to
"a". The parts which do not count -- a fixed text, the number of
the folio, the plant -- are left exactly as they are: they say
what a number is made of, they are not the part which goes on.
@param nc the rule to read
@return the same rule, with its counters at their beginning
*/
NumerotationContext resetContextCounters(const NumerotationContext &nc);
QString elementPrefixForLocation(const ElementsLocation &location);
}
Q_DECLARE_METATYPE(autonum::sequentialNumbers)
#endif // ASSIGNVARIABLES_H