mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-12 07:04:12 +02:00
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.
This commit is contained in:
+40
-18
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "pdf_links.h"
|
||||
|
||||
#include "cable/cablepart.h"
|
||||
#include "diagram.h"
|
||||
#include "qetgraphicsitem/crossrefitem.h"
|
||||
#include "qetgraphicsitem/dynamicelementtextitem.h"
|
||||
@@ -50,10 +51,13 @@ void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||
const QRectF &pageBounds = geom.pageBounds;
|
||||
|
||||
// Compute, in PDF points on its OWN page, the rectangle to frame for a
|
||||
// target element (used as a /FitR destination so the link zooms onto it).
|
||||
auto destRectPdf = [&](Element *tgt) -> QRectF {
|
||||
Diagram *dg = tgt ? tgt->diagram() : nullptr;
|
||||
if (!dg) return QRectF();
|
||||
// target (used as a /FitR destination so the link zooms onto it).
|
||||
// The target is given as a rectangle in the scene of @p dg, since what
|
||||
// is pointed at is not always an element: a cable section is a plain
|
||||
// drawn line somewhere on another folio.
|
||||
auto frameRectPdf = [&](Diagram *dg, const QRectF &targetScene) -> QRectF {
|
||||
if (!dg || targetScene.width() <= 0.0 || targetScene.height() <= 0.0)
|
||||
return QRectF();
|
||||
const QRectF srcT = geom.sourceRectOf(dg);
|
||||
if (srcT.width() <= 0.0 || srcT.height() <= 0.0) return QRectF();
|
||||
const qreal sT = qMin(target.width() / srcT.width(),
|
||||
@@ -63,35 +67,38 @@ void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||
fitT.scale(sT, sT);
|
||||
fitT.translate(-srcT.x(), -srcT.y());
|
||||
|
||||
QRectF elemScene = tgt->mapRectToScene(tgt->boundingRect());
|
||||
// Frame the element with a little context, and enforce a minimum
|
||||
// Frame the target with a little context, and enforce a minimum
|
||||
// framed size so tiny contacts don't zoom in extremely.
|
||||
QRectF framed = targetScene;
|
||||
const qreal pad = 25.0;
|
||||
elemScene.adjust(-pad, -pad, pad, pad);
|
||||
framed.adjust(-pad, -pad, pad, pad);
|
||||
const qreal minSide = 160.0;
|
||||
if (elemScene.width() < minSide)
|
||||
elemScene.adjust(-(minSide - elemScene.width()) / 2.0, 0,
|
||||
(minSide - elemScene.width()) / 2.0, 0);
|
||||
if (elemScene.height() < minSide)
|
||||
elemScene.adjust(0, -(minSide - elemScene.height()) / 2.0,
|
||||
0, (minSide - elemScene.height()) / 2.0);
|
||||
if (framed.width() < minSide)
|
||||
framed.adjust(-(minSide - framed.width()) / 2.0, 0,
|
||||
(minSide - framed.width()) / 2.0, 0);
|
||||
if (framed.height() < minSide)
|
||||
framed.adjust(0, -(minSide - framed.height()) / 2.0,
|
||||
0, (minSide - framed.height()) / 2.0);
|
||||
|
||||
const QRectF devT = fitT.mapRect(elemScene);
|
||||
const QRectF devT = fitT.mapRect(framed);
|
||||
const QPointF a = geom.devToPdf(devT.topLeft());
|
||||
const QPointF b = geom.devToPdf(devT.bottomRight());
|
||||
return QRectF(QPointF(qMin(a.x(), b.x()), qMin(a.y(), b.y())),
|
||||
QPointF(qMax(a.x(), b.x()), qMax(a.y(), b.y())));
|
||||
};
|
||||
|
||||
auto injectLink = [&](const QRectF &sceneRect, Element *targetElmt) {
|
||||
if (!targetElmt || !targetElmt->diagram()) return;
|
||||
const int targetPage = pageMap.value(targetElmt->diagram(), -1);
|
||||
// One clickable link: @p sceneRect on THIS folio leads to
|
||||
// @p targetDiagram, framed around @p targetScene over there.
|
||||
auto injectLinkTo = [&](const QRectF &sceneRect, Diagram *targetDiagram,
|
||||
const QRectF &targetScene) {
|
||||
if (!targetDiagram) return;
|
||||
const int targetPage = pageMap.value(targetDiagram, -1);
|
||||
if (targetPage < 1) return;
|
||||
const QRectF devRect = fit.mapRect(sceneRect);
|
||||
if (!devRect.isValid() || !pageBounds.intersects(devRect)) return;
|
||||
|
||||
QString frag = QString("page=%1").arg(targetPage);
|
||||
const QRectF d = destRectPdf(targetElmt); // /FitR L_B_R_T
|
||||
const QRectF d = frameRectPdf(targetDiagram, targetScene); // /FitR L_B_R_T
|
||||
if (d.isValid())
|
||||
frag += QString("&fitr=%1_%2_%3_%4")
|
||||
.arg(qRound(d.left())).arg(qRound(d.top()))
|
||||
@@ -102,6 +109,12 @@ void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||
engine->drawHyperlink(devRect, url);
|
||||
};
|
||||
|
||||
auto injectLink = [&](const QRectF &sceneRect, Element *targetElmt) {
|
||||
if (!targetElmt || !targetElmt->diagram()) return;
|
||||
injectLinkTo(sceneRect, targetElmt->diagram(),
|
||||
targetElmt->mapRectToScene(targetElmt->boundingRect()));
|
||||
};
|
||||
|
||||
for (auto *item : diagram->items()) {
|
||||
|
||||
// --- CrossRefItem links ---
|
||||
@@ -117,6 +130,15 @@ void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- Cable cross-reference links (the lines under a cable which
|
||||
// name the folio it goes on to) ---
|
||||
if (auto *cable = dynamic_cast<CablePart*>(item)) {
|
||||
for (const CablePart::PdfRef &ref : cable->pdfRefs()) {
|
||||
injectLinkTo(ref.here, ref.diagram, ref.there);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- Folio report links (DynamicElementTextItem) ---
|
||||
if (auto *deti = dynamic_cast<DynamicElementTextItem*>(item)) {
|
||||
Element *parent = deti->parentElement();
|
||||
|
||||
Reference in New Issue
Block a user