From 93abfc4fa4e8b1c055cdcae23dd9e76f15f815ef Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Wed, 21 Jan 2026 22:41:44 +0100 Subject: [PATCH] Sketch: Forward non-default edit mode to base class. (#27063) Ported from Codeberg commit 66dbf277 Co-authored-by: wwmayer --- src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp | 5 +-- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 10 ++--- .../Gui/CommandSketcherVirtualSpace.cpp | 14 +++---- src/Mod/Sketcher/Gui/Utils.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 37 +++++++++++++++---- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 8 ++-- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index d3e1871dea..257fc23066 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -46,9 +46,8 @@ bool isAlterGeoActive(Gui::Document* doc) { if (doc) { // checks if a Sketch Viewprovider is in Edit - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom()) { - return true; - } + auto vp = dynamic_cast(doc->getInEdit()); + return (vp && vp->isInEditMode()); } return false; diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 1b2c809cff..c01f9b93ef 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -78,12 +78,10 @@ bool isCreateConstraintActive(Gui::Document* doc) { if (doc) { // checks if a Sketch View provider is in Edit and is in no special mode - if (doc->getInEdit() - && doc->getInEdit()->isDerivedFrom()) { - if (static_cast(doc->getInEdit())->getSketchMode() - == ViewProviderSketch::STATUS_NONE) { - if (Gui::Selection().countObjectsOfType() - > 0) { + auto vp = dynamic_cast(doc->getInEdit()); + if (vp && vp->isInEditMode()) { + if (vp->getSketchMode() == ViewProviderSketch::STATUS_NONE) { + if (Gui::Selection().countObjectsOfType() > 0) { return true; } } diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index 32042f44d9..576f8914e9 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -51,13 +51,13 @@ bool isSketcherVirtualSpaceActive(Gui::Document* doc, bool actsOnSelection) { if (doc) { // checks if a Sketch Viewprovider is in Edit and is in no special mode - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom()) { - if (static_cast(doc->getInEdit())->getSketchMode() - == ViewProviderSketch::STATUS_NONE) { + auto vp = dynamic_cast(doc->getInEdit()); + if (vp && vp->isInEditMode()) { + if (vp->getSketchMode() == ViewProviderSketch::STATUS_NONE) { if (!actsOnSelection) { return true; } - else if (Gui::Selection().countObjectsOfType() > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { return true; } } @@ -70,10 +70,8 @@ void ActivateVirtualSpaceHandler(Gui::Document* doc, DrawSketchHandler* handler) { std::unique_ptr ptr(handler); if (doc) { - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom()) { - SketcherGui::ViewProviderSketch* vp = static_cast( - doc->getInEdit() - ); + auto vp = dynamic_cast(doc->getInEdit()); + if (vp && vp->isInEditMode()) { vp->purgeHandler(); vp->activateHandler(std::move(ptr)); } diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index 68c380cee6..18d797bf6c 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -506,7 +506,7 @@ bool SketcherGui::isSketchInEdit(Gui::Document* doc) if (doc) { // checks if a Sketch Viewprovider is in Edit and is in no special mode auto* vp = dynamic_cast(doc->getInEdit()); - return (vp != nullptr); + return (vp != nullptr && vp->isInEditMode()); } return false; } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a3051463e5..1f42f64eae 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -838,6 +838,10 @@ void ViewProviderSketch::setSketchMode(SketchMode mode) bool ViewProviderSketch::keyPressed(bool pressed, int key) { + if (getEditingMode() != ViewProviderSketch::Default) { + return ViewProvider2DObject::keyPressed(pressed, key); + } + switch (key) { case SoKeyboardEvent::ESCAPE: { // make the handler quit but not the edit mode @@ -962,6 +966,9 @@ void ViewProviderSketch::getCoordsOnSketchPlane(const SbVec3f& point, const SbVe bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer) { + if (getEditingMode() != ViewProviderSketch::Default) { + return ViewProvider2DObject::mouseButtonPressed(Button, pressed, cursorPos, viewer); + } assert(isInEditMode()); // Calculate 3d point to the mouse position @@ -1327,11 +1334,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe bool ViewProviderSketch::mouseWheelEvent(int delta, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer) { - assert(isInEditMode()); + if (getEditingMode() != ViewProviderSketch::Default) { + return ViewProvider2DObject::mouseWheelEvent(delta, cursorPos, viewer); + } - Q_UNUSED(delta); - Q_UNUSED(cursorPos); - Q_UNUSED(viewer); + assert(isInEditMode()); editCoinManager->drawConstraintIcons(); @@ -1439,6 +1446,10 @@ void ViewProviderSketch::toggleWireSelelection(int clickedGeoId) bool ViewProviderSketch::mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer) { + if (getEditingMode() != ViewProviderSketch::Default) { + return ViewProvider2DObject::mouseMove(cursorPos, viewer); + } + // maximum radius for mouse moves when selecting a geometry before switching to drag mode const int dragIgnoredDistance = 3; @@ -3398,7 +3409,10 @@ void ViewProviderSketch::setupContextMenu(QMenu* menu, QObject* receiver, const bool ViewProviderSketch::setEdit(int ModNum) { - Q_UNUSED(ModNum) + if (ModNum != ViewProviderSketch::Default) { + return PartGui::ViewProvider2DObject::setEdit(ModNum); + } + // When double-clicking on the item for this sketch the // object unsets and sets its edit mode without closing // the task panel @@ -3704,7 +3718,9 @@ void ViewProviderSketch::UpdateSolverInformation() void ViewProviderSketch::unsetEdit(int ModNum) { - Q_UNUSED(ModNum); + if (ModNum != ViewProviderSketch::Default) { + return PartGui::ViewProvider2DObject::unsetEdit(ModNum); + } setGridEnabled(false); auto gridnode = getGridNode(); @@ -3773,7 +3789,10 @@ void ViewProviderSketch::unsetEdit(int ModNum) void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum) { - Q_UNUSED(ModNum); + if (ModNum != ViewProviderSketch::Default) { + return PartGui::ViewProvider2DObject::setEditViewer(viewer, ModNum); + } + Base::PyGILStateLocker lock; // visibility automation: save camera if (!this->TempoVis.getValue().isNone()) { @@ -3873,6 +3892,10 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer) { + if (getEditingMode() != ViewProviderSketch::Default) { + return PartGui::ViewProvider2DObject::unsetEditViewer(viewer); + } + auto dataPtr = static_cast(cameraSensor.getData()); delete dataPtr; cameraSensor.setData(nullptr); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 5c8fb81387..58e82f2c62 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -581,6 +581,10 @@ public: return Mode; } + /// returns whether the sketch is in edit mode. + bool isInEditMode() const; + //@} + // create right click context menu based on selection in the 3D view void generateContextMenu(); @@ -856,10 +860,6 @@ private: ); void moveAngleConstraint(Sketcher::Constraint*, int constNum, const Base::Vector2d& toPos); - /// returns whether the sketch is in edit mode. - bool isInEditMode() const; - //@} - /** @name signals*/ //@{ /// signals a tool change