From ea10dfd85dcff2c3e286ecbf1ab7700cb0d0f3e9 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 13 Nov 2021 15:15:37 -0500 Subject: [PATCH] [PD] Allow sketch point profile in selection-based loft workflow --- src/Mod/PartDesign/Gui/Command.cpp | 40 ++++++++++++++----- src/Mod/PartDesign/Gui/TaskLoftParameters.cpp | 3 ++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 144e9a0494..ec5d49db68 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1004,18 +1004,32 @@ void prepareProfileBased(PartDesign::Body *pcActiveBody, Gui::Command* cmd, cons auto Feat = pcActiveBody->getDocument()->getObject(FeatName.c_str()); auto objCmd = Gui::Command::getObjectCmd(feature); - if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId()) || subs.empty()) { - FCMD_OBJ_CMD(Feat,"Profile = " << objCmd); - } - else { - std::ostringstream ss; - for (auto &s : subs) - ss << "'" << s << "',"; - FCMD_OBJ_CMD(Feat,"Profile = (" << objCmd << ", [" << ss.str() << "])"); - } - //for additive and subtractive lofts allow the user to preselect the sections + auto runProfileCmd = + [=]() { + FCMD_OBJ_CMD(Feat,"Profile = " << objCmd); + }; + + auto runProfileCmdWithSubs = + [=]() { + std::ostringstream ss; + for (auto &s : subs) + ss << "'" << s << "',"; + FCMD_OBJ_CMD(Feat,"Profile = (" << objCmd << ", [" << ss.str() << "])"); + }; + if (which.compare("AdditiveLoft") == 0 || which.compare("SubtractiveLoft") == 0) { + // for additive and subtractive lofts set subvalues even for sketches + // when a vertex is first selected + auto subName = subs.empty() ? "" : subs.front(); + + if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId()) && + !(subName.size() > 6 && subName.substr(0,6) == "Vertex")) + runProfileCmd(); + else + runProfileCmdWithSubs(); + + // for additive and subtractive lofts allow the user to preselect the sections std::vector selection = cmd->getSelection().getSelectionEx(); if (selection.size() > 1) { //treat additional selected objects as sections for (std::vector::size_type ii = 1; ii < selection.size(); ii++) { @@ -1028,6 +1042,12 @@ void prepareProfileBased(PartDesign::Body *pcActiveBody, Gui::Command* cmd, cons } } } + else { + if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId()) || subs.empty()) + runProfileCmd(); + else + runProfileCmdWithSubs(); + } // for additive and subtractive pipes allow the user to preselect the spines if (which.compare("AdditivePipe") == 0 || which.compare("SubtractivePipe") == 0) { diff --git a/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp b/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp index db0d0d65fe..9511e0fb20 100644 --- a/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp @@ -105,6 +105,7 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj if (profile) { Gui::Application::Instance->showViewProvider(profile); + // TODO: if it is a single vertex of a sketch, use that subshape's name QString label = make2DLabel(profile, loft->Profile.getSubValues()); ui->profileBaseEdit->setText(label); } @@ -112,6 +113,7 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj for (auto &subSet : loft->Sections.getSubListValues()) { Gui::Application::Instance->showViewProvider(subSet.first); + // TODO: if it is a single vertex of a sketch, use that subshape's name QString label = make2DLabel(subSet.first, subSet.second); QListWidgetItem* item = new QListWidgetItem(); item->setText(label); @@ -152,6 +154,7 @@ void TaskLoftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) App::Document* document = App::GetApplication().getDocument(msg.pDocName); App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; if (object) { + // TODO: if it is a single vertex of a sketch, use that subshape's name QString label = make2DLabel(object, {msg.pSubName}); if (selectionMode == refProfile) { ui->profileBaseEdit->setText(label);