From 2ea279cc2b921d7bab849a221ebf86c40f9ead50 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Tue, 29 Sep 2026 11:09:27 +1300 Subject: [PATCH] Fix bugtracker #105: straight wire drawn diagonally after a move updateConductorPath() fits a stored profile to the new terminal positions by sharing the horizontal difference over the profile's horizontal segments and the vertical one over its vertical segments. When a profile has no segment of non-zero length along an axis, the difference along that axis was dropped and the last point joined the terminal diagonally. On save that diagonal was written as one axis-aligned segment, so on reopen pathFromXml() found the lengths incoherent and rerouted the wire. Every straight wire with a stored path hits this after a reload, as a zero-length segment is saved as horizontal. Moving one end at a right angle to the wire, in the direction that keeps its path type, showed it. Generate a new path in that case, as is already done when there is no profile for the path type. Co-Authored-By: Claude Opus 5.5 --- sources/qetgraphicsitem/conductor.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index f97fb97ec..4eb9009bc 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -228,9 +228,6 @@ void Conductor::segmentsToPath() @param o2 Orientation de la borne 2 */ void Conductor::updateConductorPath(const QPointF &p1, Qet::Orientation o1, const QPointF &p2, Qet::Orientation o2) { - Q_UNUSED(o1); - Q_UNUSED(o2); - ConductorProfile &conductor_profile = conductor_profiles[currentPathType()]; Q_ASSERT_X(conductor_profile.segmentsCount(QET::Both) > 1, "Conductor::priv_modifieConductor", "pas de points a modifier"); @@ -252,6 +249,25 @@ void Conductor::updateConductorPath(const QPointF &p1, Qet::Orientation o1, cons qreal h_diff = (qAbs(new_rect.width()) - qAbs(profile_width) ) * getSign(profile_width); qreal v_diff = (qAbs(new_rect.height()) - qAbs(profile_height)) * getSign(profile_height); + // A profile with no segment of non-zero length along an axis has nowhere + // to put a difference along that axis: it would be dropped and the last + // point would join the terminal diagonally. Every straight conductor + // loaded from a file is like this, as a zero-length segment is saved as + // horizontal (bugtracker #105). Generate a new path instead, as when + // there is no profile for this path type. + const auto can_absorb = [](qreal diff, const QList &segments_list) { + if (qAbs(diff) <= 0.01) return(true); + for (ConductorSegmentProfile *csp : segments_list) { + if (csp -> length) return(true); + } + return(false); + }; + if (!can_absorb(h_diff, conductor_profile.horizontalSegments()) || + !can_absorb(v_diff, conductor_profile.verticalSegments())) { + generateConductorPath(p1, o1, p2, o2); + return; + } + // applique les differences aux segments // apply the differences to the segments QMultiHash segments_lengths;