Sketch: add command to context-menu to change value of constraint

The edit datum dialog is opened by double-clicking on a dimensional constraint in a sketch. However, the double-clicking event doesn't work realiably on
some systems. As a workaround this PR adds the command to the context-menu.

For more details see the forum thread: https://forum.freecad.org/viewtopic.php?t=71137
This commit is contained in:
wmayer
2024-04-03 19:13:59 +02:00
committed by Yorik van Havre
parent 69898555c6
commit 1d2bd837c1
2 changed files with 57 additions and 0 deletions

View File

@@ -9778,6 +9778,59 @@ bool CmdSketcherConstrainSnellsLaw::isActive()
return isCreateConstraintActive(getActiveGuiDocument());
}
// ======================================================================================
DEF_STD_CMD_A(CmdSketcherChangeDimensionConstraint)
CmdSketcherChangeDimensionConstraint::CmdSketcherChangeDimensionConstraint()
: Command("Sketcher_ChangeDimensionConstraint")
{
sAppModule = "Sketcher";
sGroup = "Sketcher";
sMenuText = QT_TR_NOOP("Change value");
sToolTipText = QT_TR_NOOP("Change the value of a dimensional constraint");
sWhatsThis = "Sketcher_ChangeDimensionConstraint";
sStatusTip = sToolTipText;
eType = ForEdit;
}
void CmdSketcherChangeDimensionConstraint::activated(int iMsg)
{
Q_UNUSED(iMsg);
auto getDimConstraint = []() {
std::vector<Gui::SelectionObject> selection{getSelection().getSelectionEx()};
if (selection.size() != 1 || selection[0].getSubNames().size() != 1) {
throw Base::RuntimeError();
}
if (auto sketch = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())) {
std::string subName = selection[0].getSubNames().at(0);
if (subName.size() > 10 && subName.substr(0, 10) == "Constraint") {
int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(subName);
return std::make_tuple(sketch, ConstrId);
}
}
throw Base::RuntimeError();
};
try {
auto value = getDimConstraint();
EditDatumDialog editDatumDialog(std::get<0>(value), std::get<1>(value));
editDatumDialog.exec(false);
}
catch (const Base::RuntimeError&) {
Gui::TranslatedUserWarning(getActiveGuiDocument()->getDocument(),
QObject::tr("Wrong selection"),
QObject::tr("Select one dimensional constraint from the sketch."));
}
}
bool CmdSketcherChangeDimensionConstraint::isActive()
{
return isCommandActive(getActiveGuiDocument());
}
// ======================================================================================
/*** Creation Mode / Toggle to or from Reference ***/
DEF_STD_CMD_AU(CmdSketcherToggleDrivingConstraint)
@@ -10053,6 +10106,7 @@ void CreateSketcherCommandsConstraints()
rcCmdMgr.addCommand(new CmdSketcherConstrainPointOnObject());
rcCmdMgr.addCommand(new CmdSketcherConstrainSymmetric());
rcCmdMgr.addCommand(new CmdSketcherConstrainSnellsLaw());
rcCmdMgr.addCommand(new CmdSketcherChangeDimensionConstraint());
rcCmdMgr.addCommand(new CmdSketcherToggleDrivingConstraint());
rcCmdMgr.addCommand(new CmdSketcherToggleActiveConstraint());
rcCmdMgr.addCommand(new CmdSketcherCompDimensionTools());

View File

@@ -4142,6 +4142,9 @@ void ViewProviderSketch::generateContextMenu()
// context menu if only constraints are selected
else if (selectedConstraints >= 1) {
if (selectedConstraints == 1) {
menu << "Sketcher_ChangeDimensionConstraint";
}
menu << "Sketcher_ToggleDrivingConstraint"
<< "Sketcher_ToggleActiveConstraint"
<< "Sketcher_SelectElementsAssociatedWithConstraints"