Sketcher: Delete all geometry menu command (in sketcher tools)

This commit is contained in:
Abdullah Tahiri
2017-11-05 19:03:39 +01:00
committed by wmayer
parent 6210b602de
commit 1ec828936c
2 changed files with 68 additions and 1 deletions

View File

@@ -1732,6 +1732,71 @@ bool CmdSketcherRectangularArray::isActive(void)
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
}
// Select Origin
DEF_STD_CMD_A(CmdSketcherDeleteAllGeometry);
CmdSketcherDeleteAllGeometry::CmdSketcherDeleteAllGeometry()
:Command("Sketcher_DeleteAllGeometry")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Delete All Geometry");
sToolTipText = QT_TR_NOOP("Deletes all the geometry and constraints but external geometry");
sWhatsThis = "Sketcher_DeleteAllGeometry";
sStatusTip = sToolTipText;
sPixmap = "Sketcher_Element_SelectionTypeInvalid";
sAccel = "";
eType = ForEdit;
}
void CmdSketcherDeleteAllGeometry::activated(int iMsg)
{
Q_UNUSED(iMsg);
int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Delete All Geometry"),
QObject::tr("Are you really sure you want to delete all the geometry and constraints?"),
QMessageBox::Yes, QMessageBox::Cancel);
// use an equality constraint
if (ret == QMessageBox::Yes) {
Gui::Document * doc= getActiveGuiDocument();
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
Sketcher::SketchObject* Obj= vp->getSketchObject();
try {
Gui::Command::openCommand("Delete All Geometry");
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.deleteAllGeometry()",
Obj->getNameInDocument());
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
Base::Console().Error("Failed to delete All Geometry: %s\n", e.what());
Gui::Command::abortCommand();
}
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
bool autoRecompute = hGrp->GetBool("AutoRecompute",false);
if(autoRecompute)
Gui::Command::updateActive();
else
Obj->solve();
}
else if (ret == QMessageBox::Cancel) {
// do nothing
return;
}
}
bool CmdSketcherDeleteAllGeometry::isActive(void)
{
return isSketcherAcceleratorActive( getActiveGuiDocument(), false );
}
void CreateSketcherCommandsConstraintAccel(void)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
@@ -1751,4 +1816,5 @@ void CreateSketcherCommandsConstraintAccel(void)
rcCmdMgr.addCommand(new CmdSketcherClone());
rcCmdMgr.addCommand(new CmdSketcherCompCopy());
rcCmdMgr.addCommand(new CmdSketcherRectangularArray());
rcCmdMgr.addCommand(new CmdSketcherDeleteAllGeometry());
}

View File

@@ -266,7 +266,8 @@ inline void SketcherAddWorkbenchTools<Gui::MenuItem>(Gui::MenuItem& consaccel){
<< "Sketcher_Symmetry"
<< "Sketcher_Clone"
<< "Sketcher_Copy"
<< "Sketcher_RectangularArray";
<< "Sketcher_RectangularArray"
<< "Sketcher_DeleteAllGeometry";
}
template <>
inline void SketcherAddWorkbenchTools<Gui::ToolBarItem>(Gui::ToolBarItem& consaccel){