Skip to content

Commit

Permalink
Sketcher: clean up line spacing for VirtualSpace command
Browse files Browse the repository at this point in the history
  • Loading branch information
vocx-fc authored and wwmayer committed Oct 22, 2020
1 parent a291305 commit 7f52d8b
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp
Expand Up @@ -60,26 +60,22 @@ 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(SketcherGui::ViewProviderSketch::getClassTypeId())) {
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())
->getSketchMode() == ViewProviderSketch::STATUS_NONE) {
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode() == ViewProviderSketch::STATUS_NONE) {
if (!actsOnSelection)
return true;
else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0)
return true;
}
}
}

return false;
}

void ActivateVirtualSpaceHandler(Gui::Document *doc,DrawSketchHandler *handler)
void ActivateVirtualSpaceHandler(Gui::Document *doc, DrawSketchHandler *handler)
{
if (doc) {
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom
(SketcherGui::ViewProviderSketch::getClassTypeId())) {

SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*> (doc->getInEdit());
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
vp->purgeHandler();
vp->activateHandler(handler);
}
Expand All @@ -90,7 +86,7 @@ void ActivateVirtualSpaceHandler(Gui::Document *doc,DrawSketchHandler *handler)
DEF_STD_CMD_A(CmdSketcherSwitchVirtualSpace)

CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace()
:Command("Sketcher_SwitchVirtualSpace")
: Command("Sketcher_SwitchVirtualSpace")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
Expand All @@ -106,14 +102,12 @@ CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace()
void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
{
Q_UNUSED(iMsg);
bool modeChange=true;
bool modeChange = true;

std::vector<Gui::SelectionObject> selection;

if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0){
if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) {
// Now we check whether we have a constraint selected or not.

// get the selection
selection = getSelection().getSelectionEx();

// only one sketch with its subelements are allowed to be selected
Expand All @@ -131,22 +125,21 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
return;
}

for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
// see if we have constraints, if we do it is not a mode change, but a toggle.
if (it->size() > 10 && it->substr(0,10) == "Constraint")
modeChange=false;
if (it->size() > 10 && it->substr(0, 10) == "Constraint")
modeChange = false;
}
}

if (modeChange) {
Gui::Document * doc= getActiveGuiDocument();
Gui::Document * doc = getActiveGuiDocument();

SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());

vp->setIsShownVirtualSpace(!vp->getIsShownVirtualSpace());
}
else // toggle the selected constraint(s)
{
// toggle the selected constraint(s)
else {
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
if (SubNames.empty()) {
Expand All @@ -161,17 +154,17 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
// undo command open
openCommand("Toggle constraints to the other virtual space");

int successful=SubNames.size();
int successful = SubNames.size();
// go through the selected subelements
for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
// only handle constraints
if (it->size() > 10 && it->substr(0,10) == "Constraint") {
int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it);
Gui::Command::openCommand("Update constraint's virtual space");
try {
Gui::cmdAppObjectArgs(Obj, "toggleVirtualSpace(%d)", ConstrId);
}
catch(const Base::Exception&) {
catch (const Base::Exception&) {
successful--;
}
}
Expand All @@ -182,16 +175,15 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
else
abortCommand();

// recomputer and clear the selection (convenience)
tryAutoRecompute(Obj);

// clear the selection (convenience)
getSelection().clearSelection();
}
}

bool CmdSketcherSwitchVirtualSpace::isActive(void)
{
return isSketcherVirtualSpaceActive( getActiveGuiDocument(), false );
return isSketcherVirtualSpaceActive(getActiveGuiDocument(), false);
}

void CreateSketcherCommandsVirtualSpace(void)
Expand Down

0 comments on commit 7f52d8b

Please sign in to comment.