Skip to content

Commit

Permalink
Sketcher: GUI command to activate/deactivate constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtahiriyo committed Jun 22, 2019
1 parent 7e3fd1a commit 4de857a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/Mod/Sketcher/Gui/CommandConstraints.cpp
Expand Up @@ -7731,6 +7731,88 @@ bool CmdSketcherToggleDrivingConstraint::isActive(void)
return isCreateGeoActive( getActiveGuiDocument() );
}

DEF_STD_CMD_A(CmdSketcherToggleActiveConstraint);

CmdSketcherToggleActiveConstraint::CmdSketcherToggleActiveConstraint()
:Command("Sketcher_ToggleActiveConstraint")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Toggle activate/deactivate constraint");
sToolTipText = QT_TR_NOOP("Toggles activate/deactivate state for selected constraints");
sWhatsThis = "Sketcher_ToggleActiveConstraint";
sStatusTip = sToolTipText;
sPixmap = "Sketcher_ToggleActiveConstraint";
sAccel = "";
eType = ForEdit;
}

void CmdSketcherToggleActiveConstraint::activated(int iMsg)
{
Q_UNUSED(iMsg);

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

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
if (selection.size() != 1 || !selection[0].isObjectTypeOf(Sketcher::SketchObject::getClassTypeId())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select constraint(s) from the sketch."));
return;
}

Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());

// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
if (SubNames.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select constraint(s) from the sketch."));
return;
}

// undo command open
openCommand("Active/Deactivate constraints");

int successful=SubNames.size();

for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){

if (it->size() > 10 && it->substr(0,10) == "Constraint") {
int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it);
try {
// issue the actual commands to toggle
doCommand(Doc,"App.ActiveDocument.%s.toggleActive(%d) ",selection[0].getFeatName(),ConstrId);
}
catch(const Base::Exception&) {
successful--;
}
}
}

if (successful > 0)
commitCommand();
else
abortCommand();

tryAutoRecompute(Obj);

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

bool CmdSketcherToggleActiveConstraint::isActive(void)
{
return isCreateConstraintActive( getActiveGuiDocument() );
}


void CreateSketcherCommandsConstraints(void)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Expand All @@ -7756,4 +7838,5 @@ void CreateSketcherCommandsConstraints(void)
rcCmdMgr.addCommand(new CmdSketcherConstrainSnellsLaw());
rcCmdMgr.addCommand(new CmdSketcherConstrainInternalAlignment());
rcCmdMgr.addCommand(new CmdSketcherToggleDrivingConstraint());
rcCmdMgr.addCommand(new CmdSketcherToggleActiveConstraint());
}

0 comments on commit 4de857a

Please sign in to comment.