Skip to content

Commit

Permalink
[Sketcher] Create internal geometry after converting to NURBS
Browse files Browse the repository at this point in the history
The control points are needed to edit the converted B-Spline
  • Loading branch information
AjinkyaDahale committed Feb 21, 2022
1 parent f76fb45 commit 2e8198a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp
Expand Up @@ -440,24 +440,35 @@ void CmdSketcherConvertToNURBS::activated(int iMsg)
const std::vector<std::string> &SubNames = selection[0].getSubNames();
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());

// Without this line there are some segfault-like issues on some dragged selections.
// See https://forum.freecadweb.org/viewtopic.php?f=19&p=573388#p573388.
// Possibly some vertices that are deleted after the conversion remain in the selection.
getSelection().clearSelection();

bool nurbsized = false;

openCommand(QT_TRANSLATE_NOOP("Command", "Convert to NURBS"));

for (size_t i=0; i < SubNames.size(); i++) {
std::vector<int> GeoIdList;

for (auto subName : SubNames) {
// only handle edges
if (SubNames[i].size() > 4 && SubNames[i].substr(0,4) == "Edge") {
int GeoId = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1;
Gui::cmdAppObjectArgs(selection[0].getObject(), "convertToNURBS(%d) ", GeoId);
nurbsized = true;
}
else if (SubNames[i].size() > 12 && SubNames[i].substr(0,12) == "ExternalEdge") {
int GeoId = - (std::atoi(SubNames[i].substr(12,4000).c_str()) + 2);
Gui::cmdAppObjectArgs(selection[0].getObject(), "convertToNURBS(%d) ", GeoId);
nurbsized = true;
}
int GeoId;
if (subName.size() > 4 && subName.substr(0,4) == "Edge")
GeoId = std::atoi(subName.substr(4,4000).c_str()) - 1;
else if (subName.size() > 12 && subName.substr(0,12) == "ExternalEdge")
GeoId = - (std::atoi(subName.substr(12,4000).c_str()) + 2);
else
continue;
Gui::cmdAppObjectArgs(selection[0].getObject(), "convertToNURBS(%d) ", GeoId);
GeoIdList.push_back(GeoId);
nurbsized = true;
}

// for creating the poles and knots
for (auto GeoId : GeoIdList)
Gui::cmdAppObjectArgs(selection[0].getObject(), "exposeInternalGeometry(%d)", GeoId);

if (!nurbsized) {
abortCommand();
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
Expand Down

0 comments on commit 2e8198a

Please sign in to comment.