Files
qelectrotech-source-mirror/sources/cable/cablemanager.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

114 lines
4.2 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 CABLEMANAGER_H
#define CABLEMANAGER_H
#include <QLineF>
#include <QList>
#include <QPointF>
#include <QUuid>
class Cable;
class Conductor;
class Diagram;
class NumerotationContext;
class QETProject;
/**
@brief One place where a drawn cable line crosses a conductor.
*/
struct CableCrossing
{
Conductor *conductor = nullptr;
/// Scene coordinates of the crossing, where the slash is drawn
QPointF position;
};
/**
@brief The CableManager works out everything which follows from the
cables of a project, so nothing has to be maintained by hand.
It detects which conductors a line about to be drawn crosses, and it
turns the cables back into the cable field of every conductor they
own -- both directions of one single rule: the cable is the only
source of truth.
*/
class CableManager
{
public:
///How far a colour label may stand from where a line crosses
///a wire for that wire to count as the one the label stands
///on: one scene unit, and that is already generous. The grid
///is there to put a label exactly on the crossing, and it
///does: a label drawn on a wire, slid along its own line or
///carried there by a paste lands on that crossing to the
///last decimal. The single unit only soaks up the rounding
///which comes of projecting a label onto its line, and a
///terminal which is a hair off the grid. Anything beyond it
///is beside the wire rather than on it, so a label one
///whole grid step away -- however the grid is set -- gives
///up its entry. One number for every place a label is given
///to a wire: drawing one, dragging one and wiring a copy
///must not disagree about it.
static constexpr qreal bind_tolerance = 1.0;
//Drawing
static QList<CableCrossing> crossedConductors(Diagram *diagram, const QLineF &line);
static bool crossingOf(Diagram *diagram,
const QLineF &line,
Conductor *conductor,
QPointF *result);
static qreal distanceTo(Conductor *conductor, const QPointF &scene_pos);
//Keeping the drawing in step with the cables
static void refreshLabels(QETProject *project);
static void claimConductor(QETProject *project, Conductor *conductor, Cable *new_owner);
//Lookup
static Cable *cableByUuid(QETProject *project, const QUuid &uuid);
static Conductor *conductorByUuid(QETProject *project, const QUuid &uuid);
static QString nextDesignation(QETProject *project, Diagram *diagram);
/**
Work the number of a next cable out of a rule which is
@em not the project's own state but the one @p context
holds: the rule is read as it stands there and what it
hands out is the number, unless some cable already
stands under that number -- which is what happens while
a whole run of cables is numbered one after the other
before any of them has really been added. Then @p
context is stepped on and the rule is read once more.
When the project numbers its cables by no rule at all,
@p context is not read and the plain letter W is handed
out instead: no numbers are invented where none have
been defined.
A caller numbering a run of cables keeps the same @p
context for all of them, so each of them gets a number
of its own; a caller numbering one cable lets it go
again afterwards. The project's own rule is never
moved on here -- that belongs to the moment the cable
comes into being.
*/
static QString nextDesignation(QETProject *project,
Diagram *diagram,
NumerotationContext &context);
};
#endif // CABLEMANAGER_H