PartDesign/Gui: rename some fonctions in ReferenceSelection.cpp

e.g. getPythonStr -> buildLinkListPythonStr etc
This commit is contained in:
Alexander Golubev 2015-08-17 10:44:04 +03:00 committed by Stefan Tröger
parent 06139ee8f3
commit c4f094bba4
9 changed files with 85 additions and 46 deletions

View File

@ -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"));

View File

@ -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<std::string>(1,subname);
}
const QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub)
QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub)
{
if (obj == NULL)
return QString::fromAscii("");
@ -162,19 +162,38 @@ const QString getRefStr(const App::DocumentObject* obj, const std::vector<std::s
return QString();
}
const std::string getPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& sub)
std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& 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<std::string>& 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<App::DocumentObject*> objs)
std::string buildLinkListPythonStr(const std::vector<App::DocumentObject*> & objs)
{
if ( objs.empty() ) {
return "None";
}
std::string result("[");
for (std::vector<App::DocumentObject*>::const_iterator o = objs.begin(); o != objs.end(); o++)
@ -184,4 +203,29 @@ const std::string getPythonStr(const std::vector<App::DocumentObject*> objs)
return result;
}
std::string buildLinkSubListPythonStr(const std::vector<App::DocumentObject*> & objs,
const std::vector<std::string>& 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;
}
}

View File

@ -58,12 +58,16 @@ public:
void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg,
App::DocumentObject*& selObj, std::vector<std::string>& selSub);
/// Return reference as string for UI elements (format <obj>:<subelement>
const QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub);
/// Return reference as string for python in the format (<obj>, ["<subelement>",])
const std::string getPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& sub);
QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub);
/// Return reference as string for python in the format (<obj> ["sub1", "sub2", ...])
std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& subs);
/// Return reference as string for python in the format (<obj> ["sub"?])
std::string buildLinkSingleSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& subs);
/// Return reference as string for python in the format [obj1, obj2, ...,]
const std::string getPythonStr(const std::vector<App::DocumentObject*> objs);
std::string buildLinkListPythonStr(const std::vector<App::DocumentObject*> & objs);
/// Returns sub reference list as a python string in the format [(obj1,"sub1"),(obj2,"sub2"),...]
std::string buildLinkSubListPythonStr(const std::vector<App::DocumentObject*> & objs,
const std::vector<std::string>& subs);
} //namespace PartDesignGui
#endif // GUI_ReferenceSelection_H

View File

@ -280,13 +280,18 @@ bool TaskDlgDraftParameters::accept()
{
parameter->showObject();
// Force the user to select a neutral plane
std::vector<std::string> strings;
App::DocumentObject* obj;
TaskDraftParameters* draftparameter = static_cast<TaskDraftParameters*>(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();
}

View File

@ -395,12 +395,9 @@ void TaskLinearPatternParameters::apply()
std::vector<std::string> 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();

View File

@ -322,12 +322,9 @@ bool TaskDlgMirroredParameters::accept()
std::vector<std::string> 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();
}

View File

@ -388,12 +388,9 @@ void TaskPolarPatternParameters::apply()
std::vector<std::string> 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();

View File

@ -389,7 +389,7 @@ void TaskRevolutionParameters::apply()
std::vector<std::string> 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();
}

View File

@ -29,6 +29,7 @@
#endif
#include <App/Part.h>
#include <App/DocumentObjectGroup.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
@ -37,11 +38,12 @@
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Feature.h>
#include <Mod/PartDesign/App/Body.h>
#include "ReferenceSelection.h"
#include "Utils.h"
//===========================================================================
// Helper for Body
//===========================================================================