23
#include "PreCompiled.h"
28
#include <App/Application.h>
29
#include <Base/Console.h>
30
#include <Gui/Action.h>
31
#include <Gui/Application.h>
32
#include <Gui/BitmapFactory.h>
33
#include <Gui/CommandT.h>
34
#include <Gui/Document.h>
35
#include <Gui/MainWindow.h>
36
#include <Gui/Notifications.h>
37
#include <Gui/Selection.h>
38
#include <Gui/SelectionObject.h>
40
#include "DrawSketchHandler.h"
41
#include "ViewProviderSketch.h"
43
#include <Mod/Part/App/Geometry.h>
44
#include <Mod/Sketcher/App/SketchObject.h>
50
using namespace SketcherGui;
51
using namespace Sketcher;
53
bool isSketcherVirtualSpaceActive(Gui::Document* doc, bool actsOnSelection)
58
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
59
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode()
60
== ViewProviderSketch::STATUS_NONE) {
61
if (!actsOnSelection) {
64
else if (Gui::Selection().countObjectsOfType(
65
Sketcher::SketchObject::getClassTypeId())
75
void ActivateVirtualSpaceHandler(Gui::Document* doc, DrawSketchHandler* handler)
77
std::unique_ptr<DrawSketchHandler> ptr(handler);
80
&& doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
81
SketcherGui::ViewProviderSketch* vp =
82
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
84
vp->activateHandler(std::move(ptr));
90
DEF_STD_CMD_A(CmdSketcherSwitchVirtualSpace)
92
CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace()
93
: Command("Sketcher_SwitchVirtualSpace")
95
sAppModule = "Sketcher";
97
sMenuText = QT_TR_NOOP("Switch virtual space");
99
QT_TR_NOOP("Switches the selected constraints or the view to the other virtual space");
100
sWhatsThis = "Sketcher_SwitchVirtualSpace";
101
sStatusTip = sToolTipText;
102
sPixmap = "Sketcher_SwitchVirtualSpace";
107
void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
110
bool modeChange = true;
112
std::vector<Gui::SelectionObject> selection;
114
if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) {
116
selection = getSelection().getSelectionEx();
119
if (selection.size() != 1
120
|| !selection[0].isObjectTypeOf(Sketcher::SketchObject::getClassTypeId())) {
121
Gui::TranslatedUserWarning(getActiveGuiDocument(),
122
QObject::tr("Wrong selection"),
123
QObject::tr("Select constraint(s) from the sketch."));
128
const std::vector<std::string>& SubNames = selection[0].getSubNames();
129
if (SubNames.empty()) {
130
Gui::TranslatedUserWarning(getActiveGuiDocument(),
131
QObject::tr("Wrong selection"),
132
QObject::tr("Select constraint(s) from the sketch."));
136
for (std::vector<std::string>::const_iterator it = SubNames.begin(); it != SubNames.end();
139
if (it->size() > 10 && it->substr(0, 10) == "Constraint") {
146
Gui::Document* doc = getActiveGuiDocument();
148
SketcherGui::ViewProviderSketch* vp =
149
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
150
vp->setIsShownVirtualSpace(!vp->getIsShownVirtualSpace());
155
const std::vector<std::string>& SubNames = selection[0].getSubNames();
156
if (SubNames.empty()) {
157
Gui::TranslatedUserWarning(getActiveGuiDocument(),
158
QObject::tr("Wrong selection"),
159
QObject::tr("Select constraint(s) from the sketch."));
164
SketcherGui::ViewProviderSketch* sketchgui =
165
static_cast<SketcherGui::ViewProviderSketch*>(getActiveGuiDocument()->getInEdit());
166
Sketcher::SketchObject* Obj = sketchgui->getSketchObject();
169
openCommand(QT_TRANSLATE_NOOP("Command", "Toggle constraints to the other virtual space"));
171
int successful = SubNames.size();
173
for (std::vector<std::string>::const_iterator it = SubNames.begin(); it != SubNames.end();
176
if (it->size() > 10 && it->substr(0, 10) == "Constraint") {
177
int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it);
178
Gui::Command::openCommand(
179
QT_TRANSLATE_NOOP("Command", "Update constraint's virtual space"));
181
Gui::cmdAppObjectArgs(Obj, "toggleVirtualSpace(%d)", ConstrId);
183
catch (const Base::Exception&) {
189
if (successful > 0) {
197
tryAutoRecompute(Obj);
198
getSelection().clearSelection();
202
bool CmdSketcherSwitchVirtualSpace::isActive()
204
return isSketcherVirtualSpaceActive(getActiveGuiDocument(), false);
207
void CreateSketcherCommandsVirtualSpace()
209
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
211
rcCmdMgr.addCommand(new CmdSketcherSwitchVirtualSpace());