diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 11c2445c3..294e67f47 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1693,7 +1693,7 @@ void CmdPartDesignBoolean::activated(int iMsg) bodies.push_back(j->getObject()); } } - bodyString = PartDesignGui::getPythonStr(bodies); + bodyString = PartDesignGui::buildLinkListPythonStr(bodies); } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No body selected"), QObject::tr("Please select a body for the boolean operation")); diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index cd505b263..8de49949d 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -61,7 +61,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c if (plane && (pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()))) // Note: It is assumed that a Part has exactly 3 App::Plane objects at the root of the feature tree return true; - + if (edge && (pObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()))) return true; @@ -82,7 +82,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c return false; } - // Handle selection of geometry elements + // Handle selection of geometry elements if (!sSubName || sSubName[0] == '\0') return false; if (!allowOtherBody) { @@ -148,7 +148,7 @@ void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::Selec selSub = std::vector(1,subname); } -const QString getRefStr(const App::DocumentObject* obj, const std::vector& sub) +QString getRefStr(const App::DocumentObject* obj, const std::vector& sub) { if (obj == NULL) return QString::fromAscii(""); @@ -162,19 +162,38 @@ const QString getRefStr(const App::DocumentObject* obj, const std::vector& sub) +std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector& subs) +{ + if ( obj == NULL) + return "None"; + + std::string result("["); + + for (const auto & sub : subs) + result += "\"" + sub + "\","; + result += "]"; + + return result; +} + +std::string buildLinkSingleSubPythonStr(const App::DocumentObject* obj, + const std::vector& subs) { if (obj == NULL) - return ""; + return "None"; if (PartDesign::Feature::isDatum(obj)) return std::string("(App.ActiveDocument.") + obj->getNameInDocument() + ", [\"\"])"; else - return std::string("(App.ActiveDocument.") + obj->getNameInDocument() + ", [\"" + sub.front() + "\"])"; + return std::string("(App.ActiveDocument.") + obj->getNameInDocument() + ", [\"" + subs.front() + "\"])"; } -const std::string getPythonStr(const std::vector objs) +std::string buildLinkListPythonStr(const std::vector & objs) { + if ( objs.empty() ) { + return "None"; + } + std::string result("["); for (std::vector::const_iterator o = objs.begin(); o != objs.end(); o++) @@ -184,4 +203,29 @@ const std::string getPythonStr(const std::vector objs) return result; } +std::string buildLinkSubListPythonStr(const std::vector & objs, + const std::vector& subs) +{ + if ( objs.empty() ) { + return "None"; + } + + std::string result("["); + + assert (objs.size () == subs.size () ); + + for (size_t i=0, objs_sz=objs.size(); i < objs_sz; i++) { + if (objs[i] ) { + result += '('; + result += std::string("App.activeDocument().").append( objs[i]->getNameInDocument () ); + result += ",\""; + result += subs[i]; + result += "\"),"; + } + } + + result += "]"; + + return result; +} } diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.h b/src/Mod/PartDesign/Gui/ReferenceSelection.h index 7c719e4b8..f67da450d 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.h +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.h @@ -58,12 +58,16 @@ public: void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg, App::DocumentObject*& selObj, std::vector& selSub); /// Return reference as string for UI elements (format : -const QString getRefStr(const App::DocumentObject* obj, const std::vector& sub); -/// Return reference as string for python in the format (, ["",]) -const std::string getPythonStr(const App::DocumentObject* obj, const std::vector& sub); +QString getRefStr(const App::DocumentObject* obj, const std::vector& sub); +/// Return reference as string for python in the format ( ["sub1", "sub2", ...]) +std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector& subs); +/// Return reference as string for python in the format ( ["sub"?]) +std::string buildLinkSingleSubPythonStr(const App::DocumentObject* obj, const std::vector& subs); /// Return reference as string for python in the format [obj1, obj2, ...,] -const std::string getPythonStr(const std::vector objs); - +std::string buildLinkListPythonStr(const std::vector & objs); +/// Returns sub reference list as a python string in the format [(obj1,"sub1"),(obj2,"sub2"),...] +std::string buildLinkSubListPythonStr(const std::vector & objs, + const std::vector& subs); } //namespace PartDesignGui #endif // GUI_ReferenceSelection_H diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index 2f39ec0d0..796dba6b9 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -280,13 +280,18 @@ bool TaskDlgDraftParameters::accept() { parameter->showObject(); - // Force the user to select a neutral plane std::vector strings; App::DocumentObject* obj; TaskDraftParameters* draftparameter = static_cast(parameter); + draftparameter->getPlane(obj, strings); - std::string neutralPlane = getPythonStr(obj, strings); - if (neutralPlane.empty()) { + std::string neutralPlane = buildLinkSingleSubPythonStr(obj, strings); + + draftparameter->getLine(obj, strings); + std::string pullDirection = buildLinkSingleSubPythonStr(obj, strings); + + // Force the user to select a neutral plane + if (neutralPlane.empty() || neutralPlane == "None") { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"), QObject::tr("Please select a plane or an edge plus a pull direction")); return false; @@ -296,16 +301,8 @@ bool TaskDlgDraftParameters::accept() Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed()); - if (!neutralPlane.empty()) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str()); - } else - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str()); - draftparameter->getLine(obj, strings); - std::string pullDirection = getPythonStr(obj, strings); - if (!pullDirection.empty()) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str()); - } else - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str()); return TaskDlgDressUpParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index b400092fa..12d80f779 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -395,12 +395,9 @@ void TaskLinearPatternParameters::apply() std::vector directions; App::DocumentObject* obj; getDirection(obj, directions); - std::string direction = getPythonStr(obj, directions); - if (!direction.empty() && obj) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), direction.c_str()); - } else { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str()); - } + std::string direction = buildLinkSingleSubPythonStr(obj, directions); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), direction.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse()); ui->spinLength->apply(); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index 2c6513ed0..af02a53d6 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -322,12 +322,9 @@ bool TaskDlgMirroredParameters::accept() std::vector mirrorPlanes; App::DocumentObject* obj; mirrorParameter->getMirrorPlane(obj, mirrorPlanes); - std::string mirrorPlane = getPythonStr(obj, mirrorPlanes); - if (!mirrorPlane.empty() && obj) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str()); - } else { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str()); - } + std::string mirrorPlane = buildLinkSingleSubPythonStr(obj, mirrorPlanes); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str()); return TaskDlgTransformedParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index e7d30d536..639ce87c8 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -388,12 +388,9 @@ void TaskPolarPatternParameters::apply() std::vector axes; App::DocumentObject* obj; getAxis(obj, axes); - std::string axis = getPythonStr(obj, axes); - if (!axis.empty() && obj) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), axis.c_str()); - } else { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str()); - } + std::string axis = buildLinkSingleSubPythonStr(obj, axes); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), axis.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse()); ui->polarAngle->apply(); ui->spinOccurrences->apply(); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 4a99e0791..36ccf091c 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -389,7 +389,7 @@ void TaskRevolutionParameters::apply() std::vector sub; App::DocumentObject* obj; getReferenceAxis(obj, sub); - std::string axis = getPythonStr(obj, sub); + std::string axis = buildLinkSingleSubPythonStr(obj, sub); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0); @@ -418,6 +418,7 @@ TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters() bool TaskDlgRevolutionParameters::accept() { parameter->apply(); + return TaskDlgSketchBasedParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index d6a65482e..eca7d6358 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -29,6 +29,7 @@ #endif #include +#include #include #include #include @@ -37,11 +38,12 @@ #include +#include #include +#include "ReferenceSelection.h" #include "Utils.h" - //=========================================================================== // Helper for Body //===========================================================================