Backport version. Sketcher: Fixed mapping error when attempting to create a sketch inside a group. (#19215)

* Sketcher mapping error fix

Fixed an issue in the Sketcher where attempting to create a sketch while a group is selected caused a mapping error. Now, when a sketch is created with a group selected, the sketch will be placed inside the group.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Joona <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Joona Okkonen
2025-01-24 08:04:20 -06:00
committed by GitHub
co-authored by Joona pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent 1e55e402ae
commit 7dca20f979
+26 -2
View File
@@ -163,8 +163,23 @@ void CmdSketcherNewSketch::activated(int iMsg)
{
Q_UNUSED(iMsg);
Attacher::eMapMode mapmode = Attacher::mmDeactivated;
std::string groupName;
bool bAttach = false;
if (Gui::Selection().hasSelection()) {
bool groupSelected = false;
if (Gui::Selection().countObjectsOfType(App::DocumentObjectGroup::getClassTypeId()) > 0) {
auto selection = Gui::Selection().getSelection();
if (selection.size() > 1) {
Gui::TranslatedUserWarning(
getActiveGuiDocument(),
QObject::tr("Invalid selection"),
QObject::tr("Too many objects selected"));
return;
}
groupName = selection[0].FeatName;
groupSelected = true;
}
else if (Gui::Selection().hasSelection()) {
Attacher::SuggestResult::eSuggestResult msgid = Attacher::SuggestResult::srOK;
QString msg_str;
std::vector<Attacher::eMapMode> validModes;
@@ -270,9 +285,18 @@ void CmdSketcherNewSketch::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Sketch");
openCommand(QT_TRANSLATE_NOOP("Command", "Create a new sketch"));
doCommand(Doc,
if (groupSelected) {
doCommand(Doc,
"App.activeDocument().getObject('%s').addObject(App.activeDocument().addObject('Sketcher::SketchObject', '%s'))",
groupName.c_str(),
FeatName.c_str());
}
else {
doCommand(Doc,
"App.activeDocument().addObject('Sketcher::SketchObject', '%s')",
FeatName.c_str());
}
doCommand(Doc,
"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f, %f, %f), "
"App.Rotation(%f, %f, %f, %f))",