Add horizontal and vertical mirror for symbols on a folio (#1335)

Edit > "Miroir horizontal" (M) and "Miroir vertical" (F), also in the
folio's right-click menu, mirror the selected symbols in place. The keys
are the ones the element editor uses for the same two actions.

An element keeps two mirrors about its own axes, applied before its
rotation, and saves them as mirror="horizontal|vertical|both" on its
<element> (written only when set, so other projects save byte for byte
as before). On a symbol turned by 90 or 270 degrees, a mirror of the
folio is the other mirror of the symbol itself, so the rotation never
changes: a label kept upright does not swing round, and "Pivoter" still
turns a mirrored symbol clockwise.

- Terminals face the mirrored way (Terminal::orientation()), so wires
  follow.
- The symbol stays where it was: its centre is kept, on the grid, since
  the hotspot is often a corner.
- Texts read normally. The element's texts, text groups and cross
  reference are mirrored a second time about the centre of their own box
  (Element::keepReadable()), and ElementPictureFactory draws the texts
  of the symbol itself the same way, in a cached picture per mirror.
  Groups and cross references held at the bottom of the folio stay
  centred under their element.
- DXF export mirrors the symbol's lines, arcs and texts.
- Scripting: qet.mirrorElement(folio, uuid, vertical) and
  qet.elementMirror(folio, uuid); live mode may run both menu commands;
  the MCP server gets a mirror_element op and qet_diff reports mirrors.

Not done: the parts of a PLC table drawn at run time
(Element::drawPlcTable()) are not kept readable on a mirrored PLC; the
project database has no column for it, as it has none for the rotation.

Test: tst_scriptmirror mirrors a symbol through --run, checks every
terminal's side and facing, the round trip, undo, a save and reload,
and a symbol turned by 90 degrees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 11:01:27 +13:00
parent 0708338bce
commit a5b5d49b98
21 changed files with 923 additions and 33 deletions
+9 -2
View File
@@ -118,13 +118,20 @@ Qet::Orientation Terminal::orientation() const
// orientations actuelle et par defaut de l'element
// current and default element orientations
int ori_cur = elt -> orientation();
if (ori_cur == 0) return(d->m_orientation);
// The mirrors of an element are about its own axes, before it is
// rotated (Element::setMirror()): a horizontal one swaps east and
// west, a vertical one north and south
Qet::Orientation ori_elmt = d->m_orientation;
if (Qet::isHorizontal(ori_elmt) ? elt -> hasHorizontalMirror()
: elt -> hasVerticalMirror())
ori_elmt = (Qet::Orientation)((ori_elmt + 2) % 4);
if (ori_cur == 0) return(ori_elmt);
else {
// calcul l'angle de rotation implique par l'orientation de l'element parent
// angle de rotation de la borne sur la scene, divise par 90
// calculates the angle of rotation implied by the orientation of the parent
// element angle of rotation of the terminal on the scene, divided by 90
int angle = ori_cur + d->m_orientation;
int angle = ori_cur + ori_elmt;
while (angle >= 4) angle -= 4;
return((Qet::Orientation)angle);
}