From dbfb81dc47c56dea7fccd72e76b1e5797b91510f Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 13 May 2018 12:10:28 +0200 Subject: [PATCH] Sketcher: Section Command enabling the clipping planes --- src/Mod/Sketcher/Gui/Command.cpp | 37 ++++++++++++++++++++++++++++++ src/Mod/Sketcher/Gui/Workbench.cpp | 1 + 2 files changed, 38 insertions(+) diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 820382ecd0..42cc05d0a9 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -852,6 +852,42 @@ bool CmdSketcherMergeSketches::isActive(void) return (hasActiveDocument() && !Gui::Control().activeDialog()); } +// Acknowledgement of idea and original python macro goes to SpritKopf: +// https://github.com/Spritkopf/freecad-macros/blob/master/clip-sketch/clip_sketch.FCMacro +// https://forum.freecadweb.org/viewtopic.php?p=231481#p231085 +DEF_STD_CMD_A(CmdSketcherViewSection); + +CmdSketcherViewSection::CmdSketcherViewSection() +: Command("Sketcher_ViewSection") +{ + sAppModule = "Sketcher"; + sGroup = QT_TR_NOOP("Sketcher"); + sMenuText = QT_TR_NOOP("View section"); + sToolTipText = QT_TR_NOOP("Switches between section and full view"); + sWhatsThis = "Sketcher_ViewSection"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_ViewSection"; + eType = 0; +} + +void CmdSketcherViewSection::activated(int iMsg) +{ + Q_UNUSED(iMsg); + doCommand(Doc,"ActiveSketch.ViewObject.TempoVis.sketchClipPlane(ActiveSketch)"); +} + +bool CmdSketcherViewSection::isActive(void) +{ + Gui::Document *doc = getActiveGuiDocument(); + if (doc) { + // checks if a Sketch Viewprovider is in Edit and is in no special mode + SketcherGui::ViewProviderSketch* vp = dynamic_cast(doc->getInEdit()); + if (vp /*&& vp->getSketchMode() == ViewProviderSketch::STATUS_NONE*/) + return true; + } + return false; +} + void CreateSketcherCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -865,4 +901,5 @@ void CreateSketcherCommands(void) rcCmdMgr.addCommand(new CmdSketcherValidateSketch()); rcCmdMgr.addCommand(new CmdSketcherMirrorSketch()); rcCmdMgr.addCommand(new CmdSketcherMergeSketches()); + rcCmdMgr.addCommand(new CmdSketcherViewSection()); } diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 19caacd358..f2b36db8b0 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -347,6 +347,7 @@ inline void Sketcher_addWorkbenchSketchActions(T& sketch){ << "Sketcher_EditSketch" << "Sketcher_LeaveSketch" << "Sketcher_ViewSketch" + << "Sketcher_ViewSection" << "Sketcher_MapSketch"; SketcherAddWorkspaceSketchExtra( sketch ); }