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 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 11:09:27 +13:00
parent b411a08340
commit 2ea279cc2b
+19 -3
View File
@@ -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<ConductorSegmentProfile *> &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<ConductorSegmentProfile *, qreal> segments_lengths;