From 51b46e1e37a449d08cae1d7d08f5538573f28bf9 Mon Sep 17 00:00:00 2001 From: jriegel Date: Mon, 22 Sep 2014 13:38:08 +0200 Subject: [PATCH] Assembly: Add GeoFeatureGroup and helpers --- src/App/Application.cpp | 3 + src/App/CMakeLists.txt | 5 + src/App/GeoFeatureGroup.cpp | 197 ++++++++++++++++++++++++ src/App/GeoFeatureGroup.h | 104 +++++++++++++ src/App/GeoFeatureGroupPy.xml | 48 ++++++ src/App/GeoFeatureGroupPyImp.cpp | 148 ++++++++++++++++++ src/App/Part.cpp | 115 +------------- src/App/Part.h | 45 +----- src/App/PartPy.xml | 37 +---- src/App/PartPyImp.cpp | 118 -------------- src/Gui/Application.cpp | 3 + src/Gui/CMakeLists.txt | 2 + src/Gui/ViewProviderGeoFeatureGroup.cpp | 108 +++++++++++++ src/Gui/ViewProviderGeoFeatureGroup.h | 64 ++++++++ src/Gui/ViewProviderPart.cpp | 5 - src/Gui/ViewProviderPart.h | 6 +- src/Mod/Assembly/Gui/Workbench.cpp | 2 +- src/Mod/Assembly/Gui/Workbench.h | 2 +- 18 files changed, 694 insertions(+), 318 deletions(-) create mode 100644 src/App/GeoFeatureGroup.cpp create mode 100644 src/App/GeoFeatureGroup.h create mode 100644 src/App/GeoFeatureGroupPy.xml create mode 100644 src/App/GeoFeatureGroupPyImp.cpp create mode 100644 src/Gui/ViewProviderGeoFeatureGroup.cpp create mode 100644 src/Gui/ViewProviderGeoFeatureGroup.h diff --git a/src/App/Application.cpp b/src/App/Application.cpp index e7e14981e..d58a69507 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -76,6 +76,7 @@ #include #include "GeoFeature.h" +#include "GeoFeatureGroup.h" #include "FeatureTest.h" #include "FeaturePython.h" #include "ComplexGeoData.h" @@ -1113,6 +1114,8 @@ void Application::initTypes(void) // Document classes App ::DocumentObject ::init(); App ::GeoFeature ::init(); + App ::GeoFeatureGroup ::init(); + App ::GeoFeatureGroupPython ::init(); App ::FeatureTest ::init(); App ::FeatureTestException ::init(); App ::FeaturePython ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index a842f026e..68ed618db 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -34,6 +34,7 @@ generate_from_xml(DocumentPy) generate_from_xml(DocumentObjectPy) generate_from_xml(DocumentObjectGroupPy) generate_from_xml(GeoFeaturePy) +generate_from_xml(GeoFeatureGroupPy) generate_from_xml(PartPy) generate_from_xml(ComplexGeoDataPy) @@ -47,6 +48,7 @@ SET(FreeCADApp_XML_SRCS DocumentObjectGroupPy.xml DocumentObjectPy.xml GeoFeaturePy.xml + GeoFeatureGroupPy.xml PartPy.xml DocumentPy.xml PropertyContainerPy.xml @@ -73,6 +75,8 @@ SET(Document_CPP_SRCS FeaturePython.cpp FeatureTest.cpp GeoFeature.cpp + GeoFeatureGroupPyImp.cpp + GeoFeatureGroup.cpp Part.cpp Path.cpp InventorObject.cpp @@ -102,6 +106,7 @@ SET(Document_HPP_SRCS FeaturePythonPyImp.inl FeatureTest.h GeoFeature.h + GeoFeatureGroup.h Part.h Path.h InventorObject.h diff --git a/src/App/GeoFeatureGroup.cpp b/src/App/GeoFeatureGroup.cpp new file mode 100644 index 000000000..0eddc69de --- /dev/null +++ b/src/App/GeoFeatureGroup.cpp @@ -0,0 +1,197 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include "GeoFeatureGroup.h" +#include "GeoFeatureGroupPy.h" +#include "FeaturePythonPyImp.h" + +#define new DEBUG_CLIENTBLOCK +using namespace App; + + +PROPERTY_SOURCE(App::GeoFeatureGroup, App::GeoFeature) + + +//=========================================================================== +// Feature +//=========================================================================== + +GeoFeatureGroup::GeoFeatureGroup(void) +{ + ADD_PROPERTY(Items,(0)); +} + +GeoFeatureGroup::~GeoFeatureGroup(void) +{ +} + +DocumentObject* GeoFeatureGroup::addObject(const char* sType, const char* pObjectName) +{ + DocumentObject* obj = getDocument()->addObject(sType, pObjectName); + if (obj) addObject(obj); + return obj; +} + +void GeoFeatureGroup::addObject(DocumentObject* obj) +{ + if (!hasObject(obj)) { + std::vector grp = Items.getValues(); + grp.push_back(obj); + Items.setValues(grp); + } +} + +void GeoFeatureGroup::removeObject(DocumentObject* obj) +{ + std::vector grp = Items.getValues(); + for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { + if (*it == obj) { + grp.erase(it); + Items.setValues(grp); + break; + } + } +} + +void GeoFeatureGroup::removeObjectsFromDocument() +{ + std::vector grp = Items.getValues(); + for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { + removeObjectFromDocument(*it); + } +} + +void GeoFeatureGroup::removeObjectFromDocument(DocumentObject* obj) +{ + // remove all children + if (obj->getTypeId().isDerivedFrom(GeoFeatureGroup::getClassTypeId())) { + std::vector grp = static_cast(obj)->Items.getValues(); + for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { + // recursive call to remove all subgroups + removeObjectFromDocument(*it); + } + } + + this->getDocument()->remObject(obj->getNameInDocument()); +} + +DocumentObject *GeoFeatureGroup::getObject(const char *Name) const +{ + DocumentObject* obj = getDocument()->getObject(Name); + if (obj && hasObject(obj)) + return obj; + return 0; +} + +bool GeoFeatureGroup::hasObject(const DocumentObject* obj) const +{ + const std::vector& grp = Items.getValues(); + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { + if (*it == obj) + return true; + } + + return false; +} + +bool GeoFeatureGroup::isChildOf(const GeoFeatureGroup* group) const +{ + const std::vector& grp = group->Items.getValues(); + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { + if (*it == this) + return true; + if ((*it)->getTypeId().isDerivedFrom(GeoFeatureGroup::getClassTypeId())) { + if (this->isChildOf(static_cast(*it))) + return true; + } + } + + return false; +} + +std::vector GeoFeatureGroup::getObjects() const +{ + return Items.getValues(); +} + +std::vector GeoFeatureGroup::getObjectsOfType(const Base::Type& typeId) const +{ + std::vector type; + const std::vector& grp = Items.getValues(); + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { + if ( (*it)->getTypeId().isDerivedFrom(typeId)) + type.push_back(*it); + } + + return type; +} + +int GeoFeatureGroup::countObjectsOfType(const Base::Type& typeId) const +{ + int type=0; + const std::vector& grp = Items.getValues(); + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { + if ( (*it)->getTypeId().isDerivedFrom(typeId)) + type++; + } + + return type; +} + + +PyObject *GeoFeatureGroup::getPyObject() +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new GeoFeatureGroupPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python feature --------------------------------------------------------- + + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(App::GeoFeatureGroupPython, App::GeoFeatureGroup) +template<> const char* App::GeoFeatureGroupPython::getViewProviderName(void) const { + return "Gui::ViewProviderGeoFeatureGroupPython"; +} +template<> PyObject* App::GeoFeatureGroupPython::getPyObject(void) { + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new FeaturePythonPyT(this),true); + } + return Py::new_reference_to(PythonObject); +} +/// @endcond + +// explicit template instantiation +template class AppExport FeaturePythonT; +} \ No newline at end of file diff --git a/src/App/GeoFeatureGroup.h b/src/App/GeoFeatureGroup.h new file mode 100644 index 000000000..13c7889cc --- /dev/null +++ b/src/App/GeoFeatureGroup.h @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef APP_GeoFeatureGroup_H +#define APP_GeoFeatureGroup_H + +#include "GeoFeature.h" +#include "PropertyLinks.h" +#include + + +namespace App +{ + + +/** Base class of all geometric document objects. + */ +class AppExport GeoFeatureGroup : public App::GeoFeature +{ + PROPERTY_HEADER(App::GeoFeatureGroup); + +public: + PropertyLinkList Items; + + /// Constructor + GeoFeatureGroup(void); + virtual ~GeoFeatureGroup(); + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "Gui::ViewProviderGeoFeatureGroup"; + } + /** @name Object handling */ + //@{ + /** Adds an object of \a sType with \a pObjectName to the document this group belongs to and + * append it to this group as well. + */ + DocumentObject *addObject(const char* sType, const char* pObjectName); + /* Adds the object \a obj to this group. + */ + void addObject(DocumentObject* obj); + /** Removes an object from this group. + */ + void removeObject(DocumentObject* obj); + /** Removes all children objects from this group and the document. + */ + void removeObjectsFromDocument(); + /** Returns the object of this group with \a Name. If the group doesn't have such an object 0 is returned. + * @note This method might return 0 even if the document this group belongs to contains an object with this name. + */ + DocumentObject *getObject(const char* Name) const; + /** + * Checks whether the object \a obj is GeoFeatureGroup of this group. + */ + bool hasObject(const DocumentObject* obj) const; + /** + * Checks whether this group object is a child (or sub-child) + * of the given group object. + */ + bool isChildOf(const GeoFeatureGroup*) const; + /** Returns a list of all objects this group does have. + */ + std::vector getObjects() const; + /** Returns a list of all objects of \a typeId this group does have. + */ + std::vector getObjectsOfType(const Base::Type& typeId) const; + /** Returns the number of objects of \a typeId this group does have. + */ + int countObjectsOfType(const Base::Type& typeId) const; + //@} + + virtual PyObject *getPyObject(void); + +private: + void removeObjectFromDocument(DocumentObject*); + +}; + +typedef App::FeaturePythonT GeoFeatureGroupPython; + +} //namespace App + + +#endif // APP_GeoFeatureGroup_H diff --git a/src/App/GeoFeatureGroupPy.xml b/src/App/GeoFeatureGroupPy.xml new file mode 100644 index 000000000..dda25a074 --- /dev/null +++ b/src/App/GeoFeatureGroupPy.xml @@ -0,0 +1,48 @@ + + + + + + This class handles document objects in Part + + + + Create and add an object with given type and name to the GeoFeatureGroup + + + + + Add an object to the GeoFeatureGroup + + + + + Remove an object from the GeoFeatureGroup + + + + + Remove all child objects from the GeoFeatureGroup and document + + + + + Return the object with the given name + + + + + Checks if the GeoFeatureGroup has a given object + + + + + diff --git a/src/App/GeoFeatureGroupPyImp.cpp b/src/App/GeoFeatureGroupPyImp.cpp new file mode 100644 index 000000000..36e5e8dfc --- /dev/null +++ b/src/App/GeoFeatureGroupPyImp.cpp @@ -0,0 +1,148 @@ + +#include "PreCompiled.h" + +#include "App/GeoFeatureGroup.h" + +// inclusion of the generated files (generated out of GeoFeatureGroupPy.xml) +#include "GeoFeatureGroupPy.h" +#include "GeoFeatureGroupPy.cpp" + +using namespace App; + +// returns a string which represents the object e.g. when printed in python +std::string GeoFeatureGroupPy::representation(void) const +{ + return std::string(""); +} + + + +PyObject* GeoFeatureGroupPy::newObject(PyObject *args) +{ + char *sType,*sName=0; + if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) // convert args: Python->C + return NULL; + + DocumentObject *object = getGeoFeatureGroupPtr()->addObject(sType, sName); + if ( object ) { + return object->getPyObject(); + } + else { + PyErr_Format(PyExc_Exception, "Cannot create object of type '%s'", sType); + return NULL; + } +} + +PyObject* GeoFeatureGroupPy::addObject(PyObject *args) +{ + PyObject *object; + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObjectPy* docObj = static_cast(object); + if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot add an invalid object"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getDocument() != getGeoFeatureGroupPtr()->getDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot add an object from another document to this GeoFeatureGroup"); + return NULL; + } + if (docObj->getDocumentObjectPtr() == this->getGeoFeatureGroupPtr()) { + PyErr_SetString(PyExc_Exception, "Cannot add a GeoFeatureGroup to itself"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(GeoFeatureGroup::getClassTypeId())) { + PyErr_SetString(PyExc_Exception, "Cannot add a GeoFeatureGroup to a GeoFeatureGroup"); + return NULL; + } + + getGeoFeatureGroupPtr()->addObject(docObj->getDocumentObjectPtr()); + + Py_Return; +} + +PyObject* GeoFeatureGroupPy::removeObject(PyObject *args) +{ + PyObject *object; + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObjectPy* docObj = static_cast(object); + if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot remove an invalid object"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getDocument() != getGeoFeatureGroupPtr()->getDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot remove an object from another document from this group"); + return NULL; + } + + getGeoFeatureGroupPtr()->removeObject(docObj->getDocumentObjectPtr()); + + Py_Return; +} + +PyObject* GeoFeatureGroupPy::removeObjectsFromDocument(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) // convert args: Python->C + return NULL; // NULL triggers exception + + getGeoFeatureGroupPtr()->removeObjectsFromDocument(); + Py_Return; +} + +PyObject* GeoFeatureGroupPy::getObject(PyObject *args) +{ + char* pcName; + if (!PyArg_ParseTuple(args, "s", &pcName)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObject* obj = getGeoFeatureGroupPtr()->getObject(pcName); + if ( obj ) { + return obj->getPyObject(); + } else { + Py_Return; + } +} + +PyObject* GeoFeatureGroupPy::hasObject(PyObject *args) +{ + PyObject *object; + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObjectPy* docObj = static_cast(object); + if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot check an invalid object"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getDocument() != getGeoFeatureGroupPtr()->getDocument()) { + PyErr_SetString(PyExc_Exception, "Cannot check an object from another document with this group"); + return NULL; + } + + if (getGeoFeatureGroupPtr()->hasObject(docObj->getDocumentObjectPtr())) { + Py_INCREF(Py_True); + return Py_True; + } + else { + Py_INCREF(Py_False); + return Py_False; + } +} + + + + +PyObject *GeoFeatureGroupPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int GeoFeatureGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/App/Part.cpp b/src/App/Part.cpp index 2d4b24d66..8854802fd 100644 --- a/src/App/Part.cpp +++ b/src/App/Part.cpp @@ -33,7 +33,7 @@ using namespace App; -PROPERTY_SOURCE(App::Part, App::GeoFeature) +PROPERTY_SOURCE(App::Part, App::GeoFeatureGroup) //=========================================================================== @@ -49,119 +49,6 @@ Part::~Part(void) { } -DocumentObject* Part::addObject(const char* sType, const char* pObjectName) -{ - DocumentObject* obj = getDocument()->addObject(sType, pObjectName); - if (obj) addObject(obj); - return obj; -} - -void Part::addObject(DocumentObject* obj) -{ - if (!hasObject(obj)) { - std::vector grp = Member.getValues(); - grp.push_back(obj); - Member.setValues(grp); - } -} - -void Part::removeObject(DocumentObject* obj) -{ - std::vector grp = Member.getValues(); - for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { - if (*it == obj) { - grp.erase(it); - Member.setValues(grp); - break; - } - } -} - -void Part::removeObjectsFromDocument() -{ - std::vector grp = Member.getValues(); - for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { - removeObjectFromDocument(*it); - } -} - -void Part::removeObjectFromDocument(DocumentObject* obj) -{ - // remove all children - if (obj->getTypeId().isDerivedFrom(Part::getClassTypeId())) { - std::vector grp = static_cast(obj)->Member.getValues(); - for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { - // recursive call to remove all subgroups - removeObjectFromDocument(*it); - } - } - - this->getDocument()->remObject(obj->getNameInDocument()); -} - -DocumentObject *Part::getObject(const char *Name) const -{ - DocumentObject* obj = getDocument()->getObject(Name); - if (obj && hasObject(obj)) - return obj; - return 0; -} - -bool Part::hasObject(const DocumentObject* obj) const -{ - const std::vector& grp = Member.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if (*it == obj) - return true; - } - - return false; -} - -bool Part::isChildOf(const Part* group) const -{ - const std::vector& grp = group->Member.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if (*it == this) - return true; - if ((*it)->getTypeId().isDerivedFrom(Part::getClassTypeId())) { - if (this->isChildOf(static_cast(*it))) - return true; - } - } - - return false; -} - -std::vector Part::getObjects() const -{ - return Member.getValues(); -} - -std::vector Part::getObjectsOfType(const Base::Type& typeId) const -{ - std::vector type; - const std::vector& grp = Member.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if ( (*it)->getTypeId().isDerivedFrom(typeId)) - type.push_back(*it); - } - - return type; -} - -int Part::countObjectsOfType(const Base::Type& typeId) const -{ - int type=0; - const std::vector& grp = Member.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if ( (*it)->getTypeId().isDerivedFrom(typeId)) - type++; - } - - return type; -} - PyObject *Part::getPyObject() { diff --git a/src/App/Part.h b/src/App/Part.h index c2eb2365c..d0637caf9 100644 --- a/src/App/Part.h +++ b/src/App/Part.h @@ -24,7 +24,7 @@ #ifndef APP_Part_H #define APP_Part_H -#include "GeoFeature.h" +#include "GeoFeatureGroup.h" #include "PropertyLinks.h" @@ -35,7 +35,7 @@ namespace App /** Base class of all geometric document objects. */ -class AppExport Part : public App::GeoFeature +class AppExport Part : public App::GeoFeatureGroup { PROPERTY_HEADER(App::Part); @@ -50,49 +50,10 @@ public: virtual const char* getViewProviderName(void) const { return "Gui::ViewProviderPart"; } - /** @name Object handling */ - //@{ - /** Adds an object of \a sType with \a pObjectName to the document this group belongs to and - * append it to this group as well. - */ - DocumentObject *addObject(const char* sType, const char* pObjectName); - /* Adds the object \a obj to this group. - */ - void addObject(DocumentObject* obj); - /** Removes an object from this group. - */ - void removeObject(DocumentObject* obj); - /** Removes all children objects from this group and the document. - */ - void removeObjectsFromDocument(); - /** Returns the object of this group with \a Name. If the group doesn't have such an object 0 is returned. - * @note This method might return 0 even if the document this group belongs to contains an object with this name. - */ - DocumentObject *getObject(const char* Name) const; - /** - * Checks whether the object \a obj is part of this group. - */ - bool hasObject(const DocumentObject* obj) const; - /** - * Checks whether this group object is a child (or sub-child) - * of the given group object. - */ - bool isChildOf(const Part*) const; - /** Returns a list of all objects this group does have. - */ - std::vector getObjects() const; - /** Returns a list of all objects of \a typeId this group does have. - */ - std::vector getObjectsOfType(const Base::Type& typeId) const; - /** Returns the number of objects of \a typeId this group does have. - */ - int countObjectsOfType(const Base::Type& typeId) const; - //@} + virtual PyObject *getPyObject(void); -private: - void removeObjectFromDocument(DocumentObject*); }; diff --git a/src/App/PartPy.xml b/src/App/PartPy.xml index eacb638f5..3772998ef 100644 --- a/src/App/PartPy.xml +++ b/src/App/PartPy.xml @@ -1,48 +1,19 @@ - + This class handles document objects in Part - - - Create and add an object with given type and name to the Part - - - - - Add an object to the Part - - - - - Remove an object from the Part - - - - - Remove all child objects from the Part and document - - - - - Return the object with the given name - - - - - Checks if the Part has a given object - - + diff --git a/src/App/PartPyImp.cpp b/src/App/PartPyImp.cpp index 16509084b..347556199 100644 --- a/src/App/PartPyImp.cpp +++ b/src/App/PartPyImp.cpp @@ -17,124 +17,6 @@ std::string PartPy::representation(void) const -PyObject* PartPy::newObject(PyObject *args) -{ - char *sType,*sName=0; - if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) // convert args: Python->C - return NULL; - - DocumentObject *object = getPartPtr()->addObject(sType, sName); - if ( object ) { - return object->getPyObject(); - } - else { - PyErr_Format(PyExc_Exception, "Cannot create object of type '%s'", sType); - return NULL; - } -} - -PyObject* PartPy::addObject(PyObject *args) -{ - PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObjectPy* docObj = static_cast(object); - if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot add an invalid object"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getDocument() != getPartPtr()->getDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot add an object from another document to this Part"); - return NULL; - } - if (docObj->getDocumentObjectPtr() == this->getPartPtr()) { - PyErr_SetString(PyExc_Exception, "Cannot add a Part to itself"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(Part::getClassTypeId())) { - PyErr_SetString(PyExc_Exception, "Cannot add a Part to a Part"); - return NULL; - } - - Part* part = getPartPtr(); - - part->addObject(docObj->getDocumentObjectPtr()); - Py_Return; -} - -PyObject* PartPy::removeObject(PyObject *args) -{ - PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObjectPy* docObj = static_cast(object); - if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot remove an invalid object"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getDocument() != getPartPtr()->getDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot remove an object from another document from this group"); - return NULL; - } - - Part* part = getPartPtr(); - - - part->removeObject(docObj->getDocumentObjectPtr()); - Py_Return; -} - -PyObject* PartPy::removeObjectsFromDocument(PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception - - getPartPtr()->removeObjectsFromDocument(); - Py_Return; -} - -PyObject* PartPy::getObject(PyObject *args) -{ - char* pcName; - if (!PyArg_ParseTuple(args, "s", &pcName)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObject* obj = getPartPtr()->getObject(pcName); - if ( obj ) { - return obj->getPyObject(); - } else { - Py_Return; - } -} - -PyObject* PartPy::hasObject(PyObject *args) -{ - PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObjectPy* docObj = static_cast(object); - if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot check an invalid object"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getDocument() != getPartPtr()->getDocument()) { - PyErr_SetString(PyExc_Exception, "Cannot check an object from another document with this group"); - return NULL; - } - - if (getPartPtr()->hasObject(docObj->getDocumentObjectPtr())) { - Py_INCREF(Py_True); - return Py_True; - } - else { - Py_INCREF(Py_False); - return Py_False; - } -} - diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index fa411bb4d..5df8be631 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -98,6 +98,7 @@ #include "ViewProviderPythonFeature.h" #include "ViewProviderDocumentObjectGroup.h" #include "ViewProviderGeometryObject.h" +#include "ViewProviderGeoFeatureGroup.h" #include "ViewProviderInventorObject.h" #include "ViewProviderVRMLObject.h" #include "ViewProviderAnnotation.h" @@ -1521,6 +1522,8 @@ void Application::initTypes(void) Gui::ViewProviderDocumentObjectGroup ::init(); Gui::ViewProviderDocumentObjectGroupPython ::init(); Gui::ViewProviderGeometryObject ::init(); + Gui::ViewProviderGeoFeatureGroup ::init(); + Gui::ViewProviderGeoFeatureGroupPython ::init(); Gui::ViewProviderInventorObject ::init(); Gui::ViewProviderVRMLObject ::init(); Gui::ViewProviderAnnotation ::init(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 4f1f10206..7f08a36ff 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -821,6 +821,7 @@ SET(Viewprovider_CPP_SRCS ViewProviderBuilder.cpp ViewProviderPlacement.cpp ViewProviderPlane.cpp + ViewProviderGeoFeatureGroup.cpp ViewProviderPart.cpp ViewProviderMaterialObject.cpp ) @@ -840,6 +841,7 @@ SET(Viewprovider_SRCS ViewProviderBuilder.h ViewProviderPlacement.h ViewProviderPlane.h + ViewProviderGeoFeatureGroup.h ViewProviderPart.h ViewProviderMaterialObject.h ) diff --git a/src/Gui/ViewProviderGeoFeatureGroup.cpp b/src/Gui/ViewProviderGeoFeatureGroup.cpp new file mode 100644 index 000000000..e039931a4 --- /dev/null +++ b/src/Gui/ViewProviderGeoFeatureGroup.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +#endif + +#include +#include + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include "ViewProviderGeoFeatureGroup.h" +#include "Application.h" +#include "Command.h" +#include "BitmapFactory.h" +#include "Document.h" +#include "Tree.h" +#include "View3DInventor.h" +#include "View3DInventorViewer.h" + + +using namespace Gui; + + +PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroup, Gui::ViewProviderGeometryObject) + + +/** + * Creates the view provider for an object group. + */ +ViewProviderGeoFeatureGroup::ViewProviderGeoFeatureGroup() +{ + +} + +ViewProviderGeoFeatureGroup::~ViewProviderGeoFeatureGroup() +{ +} + + + +std::vector ViewProviderGeoFeatureGroup::claimChildren(void)const +{ + return std::vector(static_cast(getObject())->Items.getValues()); +} + +std::vector ViewProviderGeoFeatureGroup::claimChildren3D(void)const +{ + return std::vector(static_cast(getObject())->Items.getValues()); +} + + +bool ViewProviderGeoFeatureGroup::onDelete(const std::vector &) +{ + //Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()" + // ,getObject()->getDocument()->getName(), getObject()->getNameInDocument()); + return true; +} + + + +/** + * Returns the pixmap for the list item. + */ +QIcon ViewProviderGeoFeatureGroup::getIcon() const +{ + QIcon groupIcon; + groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirClosedIcon), + QIcon::Normal, QIcon::Off); + groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirOpenIcon), + QIcon::Normal, QIcon::On); + return groupIcon; +} + + +// Python feature ----------------------------------------------------------------------- + +namespace Gui { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderGeoFeatureGroupPython, Gui::ViewProviderGeoFeatureGroup) +/// @endcond + +// explicit template instantiation +template class GuiExport ViewProviderPythonFeatureT; +} diff --git a/src/Gui/ViewProviderGeoFeatureGroup.h b/src/Gui/ViewProviderGeoFeatureGroup.h new file mode 100644 index 000000000..f1355154b --- /dev/null +++ b/src/Gui/ViewProviderGeoFeatureGroup.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef GUI_VIEWPROVIDER_ViewProviderGeoFeatureGroup_H +#define GUI_VIEWPROVIDER_ViewProviderGeoFeatureGroup_H + + +#include "ViewProviderGeometryObject.h" +#include "ViewProviderPythonFeature.h" + +namespace Gui { + +class GuiExport ViewProviderGeoFeatureGroup : public ViewProviderGeometryObject +{ + PROPERTY_HEADER(Gui::ViewProviderGeoFeatureGroup); + +public: + /// constructor. + ViewProviderGeoFeatureGroup(); + /// destructor. + virtual ~ViewProviderGeoFeatureGroup(); + + virtual std::vector claimChildren(void)const; + virtual std::vector claimChildren3D(void)const; + + + QIcon getIcon(void) const; + + virtual bool onDelete(const std::vector &); + + /// get called if the user hover over a object in the tree + //virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + //virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + + +}; + +typedef ViewProviderPythonFeatureT ViewProviderGeoFeatureGroupPython; + +} // namespace Gui + +#endif // GUI_VIEWPROVIDER_DOCUMENTOBJECTGROUP_H + diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index f952d6b8c..91411de60 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -81,11 +81,6 @@ void ViewProviderPart::updateData(const App::Property* prop) } -std::vector ViewProviderPart::claimChildren(void)const -{ - return std::vector(static_cast(getObject())->Member.getValues()); -} - std::vector ViewProviderPart::getDisplayModes(void) const { // empty diff --git a/src/Gui/ViewProviderPart.h b/src/Gui/ViewProviderPart.h index d8968cea7..ad8ac185d 100644 --- a/src/Gui/ViewProviderPart.h +++ b/src/Gui/ViewProviderPart.h @@ -25,12 +25,12 @@ #define GUI_VIEWPROVIDER_ViewProviderPart_H -#include "ViewProviderGeometryObject.h" +#include "ViewProviderGeoFeatureGroup.h" #include "ViewProviderPythonFeature.h" namespace Gui { -class GuiExport ViewProviderPart : public ViewProviderGeometryObject +class GuiExport ViewProviderPart : public ViewProviderGeoFeatureGroup { PROPERTY_HEADER(Gui::ViewProviderPart); @@ -40,8 +40,6 @@ public: /// destructor. virtual ~ViewProviderPart(); - virtual std::vector claimChildren(void)const; - void attach(App::DocumentObject *pcObject); void updateData(const App::Property*); void Restore(Base::XMLReader &reader); diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index 3cfb74923..c55cbe0e9 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Assembly/Gui/Workbench.h b/src/Mod/Assembly/Gui/Workbench.h index e53a421e2..776de73bc 100644 --- a/src/Mod/Assembly/Gui/Workbench.h +++ b/src/Mod/Assembly/Gui/Workbench.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) * * * * This file is part of the FreeCAD CAx development system. * * *