mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 04:44:13 +02:00
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:
@@ -550,6 +550,8 @@ QStringList LiveServer::allowedCommands()
|
||||
QStringLiteral("diagrameditor.zoom_fit"),
|
||||
QStringLiteral("diagrameditor.zoom_reset"),
|
||||
QStringLiteral("diagrameditor.rotate_selection"),
|
||||
QStringLiteral("diagrameditor.mirror_horizontal"),
|
||||
QStringLiteral("diagrameditor.mirror_vertical"),
|
||||
QStringLiteral("diagrameditor.rotate_texts"),
|
||||
QStringLiteral("diagrameditor.snap_selection_to_grid"),
|
||||
QStringLiteral("diagrameditor.group_selection"),
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
||||
#include "../qetgraphicsitem/independenttextitem.h"
|
||||
#include "../qetgraphicsitem/qetshapeitem.h"
|
||||
#include "../undocommand/mirrorselectioncommand.h"
|
||||
#include "../undocommand/promoteshapecommand.h"
|
||||
#include "../TerminalStrip/UndoCommand/addterminalstripcommand.h"
|
||||
#include "../TerminalStrip/UndoCommand/addterminaltostripcommand.h"
|
||||
@@ -833,6 +834,43 @@ bool QetScriptApi::rotateElement(int folioIndex, const QString &elementUuid, dou
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetScriptApi::mirrorElement
|
||||
Mirror an element in place, as "Miroir horizontal" (left and right
|
||||
swap) or, with @p vertical, "Miroir vertical" (top and bottom swap)
|
||||
do on a selection. Mirroring twice the same way puts it back.
|
||||
@return false if the element is not found or the project is read only
|
||||
*/
|
||||
bool QetScriptApi::mirrorElement(int folioIndex, const QString &elementUuid, bool vertical)
|
||||
{
|
||||
if (m_project && m_project->isReadOnly()) {
|
||||
log(QStringLiteral("qet.mirrorElement: project is read-only"));
|
||||
return false;
|
||||
}
|
||||
Element *element = findElement(folioIndex, elementUuid);
|
||||
if (!element) return false;
|
||||
|
||||
m_project->undoStack()->push(new MirrorSelectionCommand(
|
||||
{element}, vertical ? Qt::Vertical : Qt::Horizontal));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetScriptApi::elementMirror
|
||||
@return the mirrors of the element about its own axes, as saved in the
|
||||
project (Element::setMirror()): "horizontal", "vertical", "both", or ""
|
||||
if it is not mirrored or not found. On a turned element, a horizontal
|
||||
mirror of the folio is a vertical mirror of the element.
|
||||
*/
|
||||
QString QetScriptApi::elementMirror(int folioIndex, const QString &elementUuid) const
|
||||
{
|
||||
const Element *element = findElement(folioIndex, elementUuid);
|
||||
if (!element || !element->isMirrored()) return QString();
|
||||
if (!element->hasVerticalMirror()) return QStringLiteral("horizontal");
|
||||
if (!element->hasHorizontalMirror()) return QStringLiteral("vertical");
|
||||
return QStringLiteral("both");
|
||||
}
|
||||
|
||||
QStringList QetScriptApi::elementUuids(int folioIndex) const
|
||||
{
|
||||
QStringList uuids;
|
||||
|
||||
@@ -398,6 +398,8 @@ class QetScriptApi : public QObject
|
||||
Q_INVOKABLE bool setElementPosition(int folioIndex, const QString &elementUuid, double x, double y);
|
||||
Q_INVOKABLE bool moveElement(int folioIndex, const QString &elementUuid, double dx, double dy);
|
||||
Q_INVOKABLE bool rotateElement(int folioIndex, const QString &elementUuid, double angle);
|
||||
Q_INVOKABLE bool mirrorElement(int folioIndex, const QString &elementUuid, bool vertical = false);
|
||||
Q_INVOKABLE QString elementMirror(int folioIndex, const QString &elementUuid) const;
|
||||
Q_INVOKABLE bool deleteElement(int folioIndex, const QString &elementUuid);
|
||||
|
||||
// -- address what is already there --
|
||||
|
||||
Reference in New Issue
Block a user