From 8337a7909fb9395a8a931d466b0cee13ea52e5c6 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 5 Apr 2017 17:22:51 -0300 Subject: [PATCH] Added App::PropertyPlacementList --- src/App/Application.cpp | 1 + src/App/PropertyGeo.cpp | 185 ++++++++++++++++++++++++++++++++++++++++ src/App/PropertyGeo.h | 56 ++++++++++++ 3 files changed, 242 insertions(+) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index b15102cc7f..0c54189203 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1209,6 +1209,7 @@ void Application::initTypes(void) App ::PropertyVectorDistance ::init(); App ::PropertyVectorList ::init(); App ::PropertyPlacement ::init(); + App ::PropertyPlacementList ::init(); App ::PropertyPlacementLink ::init(); App ::PropertyGeometry ::init(); App ::PropertyComplexGeoData ::init(); diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 4cb855bc6d..48883789d7 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -674,6 +674,191 @@ void PropertyPlacement::Paste(const Property &from) hasSetValue(); } + +//************************************************************************** +// PropertyPlacementList +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyPlacementList , App::PropertyLists); + +//************************************************************************** +// Construction/Destruction + +PropertyPlacementList::PropertyPlacementList() +{ + +} + +PropertyPlacementList::~PropertyPlacementList() +{ + +} + +//************************************************************************** +// Base class implementer + +void PropertyPlacementList::setSize(int newSize) +{ + _lValueList.resize(newSize); +} + +int PropertyPlacementList::getSize(void) const +{ + return static_cast(_lValueList.size()); +} + +void PropertyPlacementList::setValue(const Base::Placement& lValue) +{ + aboutToSetValue(); + _lValueList.resize(1); + _lValueList[0]=lValue; + hasSetValue(); +} + +void PropertyPlacementList::setValues(const std::vector& values) +{ + aboutToSetValue(); + _lValueList = values; + hasSetValue(); +} + +PyObject *PropertyPlacementList::getPyObject(void) +{ + PyObject* list = PyList_New( getSize() ); + + for (int i = 0;i values; + values.resize(nSize); + + for (Py_ssize_t i=0; i(value); + Base::Placement* val = pcObject->getPlacementPtr(); + setValue(*val); + } + else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) { + PropertyPlacement val; + val.setPyObject( value ); + setValue( val.getValue() ); + } + else { + std::string error = std::string("type must be 'Placement' or list of 'Placement', not "); + error += value->ob_type->tp_name; + throw Base::TypeError(error); + } +} + +void PropertyPlacementList::Save (Base::Writer &writer) const +{ + if (!writer.isForceXML()) { + writer.Stream() << writer.ind() << "" << std::endl; + } +} + +void PropertyPlacementList::Restore(Base::XMLReader &reader) +{ + reader.readElement("PlacementList"); + std::string file (reader.getAttribute("file") ); + + if (!file.empty()) { + // initate a file read + reader.addFile(file.c_str(),this); + } +} + +void PropertyPlacementList::SaveDocFile (Base::Writer &writer) const +{ + Base::OutputStream str(writer.Stream()); + uint32_t uCt = (uint32_t)getSize(); + str << uCt; + if (writer.getFileVersion() > 0) { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + str << it->getPosition().x << it->getPosition().y << it->getPosition().z + << it->getRotation()[0] << it->getRotation()[1] << it->getRotation()[2] << it->getRotation()[3] ; + } + } + else { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + float x = (float)it->getPosition().x; + float y = (float)it->getPosition().y; + float z = (float)it->getPosition().z; + float q0 = (float)it->getRotation()[0]; + float q1 = (float)it->getRotation()[1]; + float q2 = (float)it->getRotation()[2]; + float q3 = (float)it->getRotation()[3]; + str << x << y << z << q0 << q1 << q2 << q3; + } + } +} + +void PropertyPlacementList::RestoreDocFile(Base::Reader &reader) +{ + Base::InputStream str(reader); + uint32_t uCt=0; + str >> uCt; + std::vector values(uCt); + if (reader.getFileVersion() > 0) { + for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + Base::Vector3d pos; + float q0, q1, q2, q3; + str >> pos.x >> pos.y >> pos.z >> q0 >> q1 >> q2 >> q3; + Base::Rotation rot(q0,q1,q2,q3); + it->setPosition(pos); + it->setRotation(rot); + } + } + else { + float x,y,z,q0,q1,q2,q3; + for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + str >> x >> y >> z >> q0 >> q1 >> q2 >> q3; + Base::Vector3d pos(x, y, z); + Base::Rotation rot(q0,q1,q2,q3); + it->setPosition(pos); + it->setRotation(rot); + } + } + setValues(values); +} + +Property *PropertyPlacementList::Copy(void) const +{ + PropertyPlacementList *p= new PropertyPlacementList(); + p->_lValueList = _lValueList; + return p; +} + +void PropertyPlacementList::Paste(const Property &from) +{ + aboutToSetValue(); + _lValueList = dynamic_cast(from)._lValueList; + hasSetValue(); +} + +unsigned int PropertyPlacementList::getMemSize (void) const +{ + return static_cast(_lValueList.size() * sizeof(Base::Vector3d)); +} + + + + //************************************************************************** //************************************************************************** // PropertyPlacement diff --git a/src/App/PropertyGeo.h b/src/App/PropertyGeo.h index a9a67fc24f..7dbaa9a486 100644 --- a/src/App/PropertyGeo.h +++ b/src/App/PropertyGeo.h @@ -318,6 +318,62 @@ public: virtual void Paste(const Property &from); }; + +class AppExport PropertyPlacementList: public PropertyLists +{ + TYPESYSTEM_HEADER(); + +public: + /** + * A property that stores a list of placements + */ + PropertyPlacementList(); + + virtual ~PropertyPlacementList(); + + virtual void setSize(int newSize); + virtual int getSize(void) const; + + /** Sets the property + */ + void setValue(const Base::Placement&); + + /// index operator + const Base::Placement& operator[] (const int idx) const { + return _lValueList.operator[] (idx); + } + + void set1Value (const int idx, const Base::Placement& value) { + _lValueList.operator[] (idx) = value; + } + + void setValues (const std::vector& values); + + void setValue (void){} + + const std::vector &getValues(void) const { + return _lValueList; + } + + virtual PyObject *getPyObject(void); + virtual void setPyObject(PyObject *); + + virtual void Save (Base::Writer &writer) const; + virtual void Restore(Base::XMLReader &reader); + + virtual void SaveDocFile (Base::Writer &writer) const; + virtual void RestoreDocFile(Base::Reader &reader); + + virtual Property *Copy(void) const; + virtual void Paste(const Property &from); + + virtual unsigned int getMemSize (void) const; + +private: + std::vector _lValueList; +}; + + /** The base class for all basic geometry properties. * @author Werner Mayer */