App: [skip ci] add class PropertyListT
This commit is contained in:
@@ -248,10 +248,8 @@ const std::string &DocumentObjectT::getPropertyName() const {
|
||||
std::string DocumentObjectT::getPropertyPython() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "FreeCAD.getDocument('" << document
|
||||
<< "').getObject('" << object
|
||||
<< "')";
|
||||
if(property.size())
|
||||
str << getObjectPython();
|
||||
if (property.size())
|
||||
str << '.' << property;
|
||||
return str.str();
|
||||
}
|
||||
@@ -400,6 +398,99 @@ std::vector<App::DocumentObject*> SubObjectT::getSubObjectList() const {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
PropertyListT::PropertyListT()
|
||||
: toPython("None")
|
||||
{
|
||||
}
|
||||
|
||||
PropertyListT::PropertyListT(DocumentObject *obj)
|
||||
: PropertyListT()
|
||||
{
|
||||
if (obj) {
|
||||
std::ostringstream str;
|
||||
DocumentObjectT objT(obj);
|
||||
str << objT.getObjectPython();
|
||||
|
||||
toPython = str.str();
|
||||
}
|
||||
}
|
||||
|
||||
PropertyListT::PropertyListT(DocumentObject *obj, const std::vector<std::string>& subNames)
|
||||
: PropertyListT()
|
||||
{
|
||||
if (obj) {
|
||||
std::ostringstream str;
|
||||
DocumentObjectT objT(obj);
|
||||
str << "(" << objT.getObjectPython() << ",[";
|
||||
for(const auto& it : subNames)
|
||||
str << "'" << it << "',";
|
||||
str << "])";
|
||||
|
||||
toPython = str.str();
|
||||
}
|
||||
}
|
||||
|
||||
PropertyListT::PropertyListT(const std::vector<DocumentObject*>& objs)
|
||||
: PropertyListT()
|
||||
{
|
||||
if (!objs.empty()) {
|
||||
std::stringstream str;
|
||||
str << "[";
|
||||
for (std::size_t i = 0; i < objs.size(); i++) {
|
||||
if (i > 0)
|
||||
str << ", ";
|
||||
|
||||
App::DocumentObject* obj = objs[i];
|
||||
if (obj) {
|
||||
DocumentObjectT objT(obj);
|
||||
str << objT.getObjectPython();
|
||||
}
|
||||
else {
|
||||
str << "None";
|
||||
}
|
||||
}
|
||||
|
||||
str << "]";
|
||||
}
|
||||
}
|
||||
|
||||
PropertyListT::PropertyListT(const std::vector<DocumentObject*>& objs, const std::vector<std::string>& subNames)
|
||||
: PropertyListT()
|
||||
{
|
||||
if (!objs.empty() && objs.size() == subNames.size()) {
|
||||
std::stringstream str;
|
||||
str << "[";
|
||||
for (std::size_t i = 0; i < subNames.size(); i++) {
|
||||
if (i>0)
|
||||
str << ",(";
|
||||
else
|
||||
str << "(";
|
||||
|
||||
App::DocumentObject* obj = objs[i];
|
||||
if (obj) {
|
||||
DocumentObjectT objT(obj);
|
||||
str << objT.getObjectPython();
|
||||
}
|
||||
else {
|
||||
str << "None";
|
||||
}
|
||||
|
||||
str << ",";
|
||||
str << "'" << subNames[i] << "'";
|
||||
str << ")";
|
||||
}
|
||||
|
||||
str << "]";
|
||||
}
|
||||
}
|
||||
|
||||
std::string PropertyListT::getPropertyPython() const
|
||||
{
|
||||
return toPython;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class DocumentWeakPtrT::Private {
|
||||
public:
|
||||
Private(App::Document* doc) : _document(doc) {
|
||||
|
||||
@@ -211,6 +211,34 @@ private:
|
||||
std::string subname;
|
||||
};
|
||||
|
||||
/**
|
||||
* The PropertyListT class is a helper class to create Python statements for proprty links.
|
||||
*/
|
||||
class AppExport PropertyListT
|
||||
{
|
||||
public:
|
||||
/*! Constructor */
|
||||
PropertyListT();
|
||||
|
||||
/*! Constructor */
|
||||
PropertyListT(DocumentObject *obj);
|
||||
|
||||
/*! Constructor */
|
||||
PropertyListT(DocumentObject *obj, const std::vector<std::string>& subNames);
|
||||
|
||||
/*! Constructor */
|
||||
PropertyListT(const std::vector<DocumentObject*>& objs);
|
||||
|
||||
/*! Constructor */
|
||||
PropertyListT(const std::vector<DocumentObject*>& objs, const std::vector<std::string>& subNames);
|
||||
|
||||
/*! Get the property as Python command. */
|
||||
std::string getPropertyPython() const;
|
||||
|
||||
private:
|
||||
std::string toPython;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The DocumentWeakPtrT class
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user