App: [skip ci] add class PropertyListT

This commit is contained in:
wmayer
2021-03-29 00:47:38 +02:00
parent ca83354bf9
commit 53de0c4720
2 changed files with 123 additions and 4 deletions

View File

@@ -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) {