Assembly: Add GeoFeatureGroup and helpers

This commit is contained in:
jriegel 2014-09-22 13:38:08 +02:00 committed by Stefan Tröger
parent 0013374818
commit 51b46e1e37
18 changed files with 694 additions and 318 deletions

View File

@ -76,6 +76,7 @@
#include <Base/UnitPy.h>
#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();

View File

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

197
src/App/GeoFeatureGroup.cpp Normal file
View File

@ -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 <App/Document.h>
#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<DocumentObject*> grp = Items.getValues();
grp.push_back(obj);
Items.setValues(grp);
}
}
void GeoFeatureGroup::removeObject(DocumentObject* obj)
{
std::vector<DocumentObject*> grp = Items.getValues();
for (std::vector<DocumentObject*>::iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == obj) {
grp.erase(it);
Items.setValues(grp);
break;
}
}
}
void GeoFeatureGroup::removeObjectsFromDocument()
{
std::vector<DocumentObject*> grp = Items.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*> grp = static_cast<GeoFeatureGroup*>(obj)->Items.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = Items.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = group->Items.getValues();
for (std::vector<DocumentObject*>::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<GeoFeatureGroup*>(*it)))
return true;
}
}
return false;
}
std::vector<DocumentObject*> GeoFeatureGroup::getObjects() const
{
return Items.getValues();
}
std::vector<DocumentObject*> GeoFeatureGroup::getObjectsOfType(const Base::Type& typeId) const
{
std::vector<DocumentObject*> type;
const std::vector<DocumentObject*>& grp = Items.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = Items.getValues();
for (std::vector<DocumentObject*>::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<App::GeoFeatureGroupPy>(this),true);
}
return Py::new_reference_to(PythonObject);
}
/// @endcond
// explicit template instantiation
template class AppExport FeaturePythonT<App::GeoFeatureGroup>;
}

104
src/App/GeoFeatureGroup.h Normal file
View File

@ -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 <App/FeaturePython.h>
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<DocumentObject*> getObjects() const;
/** Returns a list of all objects of \a typeId this group does have.
*/
std::vector<DocumentObject*> 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<GeoFeatureGroup> GeoFeatureGroupPython;
} //namespace App
#endif // APP_GeoFeatureGroup_H

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeoFeaturePy"
Name="GeoFeatureGroupPy"
Twin="GeoFeatureGroup"
TwinPointer="GeoFeatureGroup"
Include="App/GeoFeatureGroup.h"
Namespace="App"
FatherInclude="App/GeoFeaturePy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>This class handles document objects in Part</UserDocu>
</Documentation>
<Methode Name="newObject">
<Documentation>
<UserDocu>Create and add an object with given type and name to the GeoFeatureGroup</UserDocu>
</Documentation>
</Methode>
<Methode Name="addObject">
<Documentation>
<UserDocu>Add an object to the GeoFeatureGroup</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObject">
<Documentation>
<UserDocu>Remove an object from the GeoFeatureGroup</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObjectsFromDocument">
<Documentation>
<UserDocu>Remove all child objects from the GeoFeatureGroup and document</UserDocu>
</Documentation>
</Methode>
<Methode Name="getObject">
<Documentation>
<UserDocu>Return the object with the given name</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasObject">
<Documentation>
<UserDocu>Checks if the GeoFeatureGroup has a given object</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@ -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("<GeoFeatureGroup object>");
}
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<DocumentObjectPy*>(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<DocumentObjectPy*>(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<DocumentObjectPy*>(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;
}

View File

@ -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<DocumentObject*> grp = Member.getValues();
grp.push_back(obj);
Member.setValues(grp);
}
}
void Part::removeObject(DocumentObject* obj)
{
std::vector<DocumentObject*> grp = Member.getValues();
for (std::vector<DocumentObject*>::iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == obj) {
grp.erase(it);
Member.setValues(grp);
break;
}
}
}
void Part::removeObjectsFromDocument()
{
std::vector<DocumentObject*> grp = Member.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*> grp = static_cast<Part*>(obj)->Member.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = Member.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = group->Member.getValues();
for (std::vector<DocumentObject*>::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<Part*>(*it)))
return true;
}
}
return false;
}
std::vector<DocumentObject*> Part::getObjects() const
{
return Member.getValues();
}
std::vector<DocumentObject*> Part::getObjectsOfType(const Base::Type& typeId) const
{
std::vector<DocumentObject*> type;
const std::vector<DocumentObject*>& grp = Member.getValues();
for (std::vector<DocumentObject*>::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<DocumentObject*>& grp = Member.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if ( (*it)->getTypeId().isDerivedFrom(typeId))
type++;
}
return type;
}
PyObject *Part::getPyObject()
{

View File

@ -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<DocumentObject*> getObjects() const;
/** Returns a list of all objects of \a typeId this group does have.
*/
std::vector<DocumentObject*> 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*);
};

View File

@ -1,48 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeoFeaturePy"
Father="GeoFeatureGroupPy"
Name="PartPy"
Twin="Part"
TwinPointer="Part"
Include="App/Part.h"
Namespace="App"
FatherInclude="App/GeoFeaturePy.h"
FatherInclude="App/GeoFeatureGroupPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>This class handles document objects in Part</UserDocu>
</Documentation>
<Methode Name="newObject">
<Documentation>
<UserDocu>Create and add an object with given type and name to the Part</UserDocu>
</Documentation>
</Methode>
<Methode Name="addObject">
<Documentation>
<UserDocu>Add an object to the Part</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObject">
<Documentation>
<UserDocu>Remove an object from the Part</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObjectsFromDocument">
<Documentation>
<UserDocu>Remove all child objects from the Part and document</UserDocu>
</Documentation>
</Methode>
<Methode Name="getObject">
<Documentation>
<UserDocu>Return the object with the given name</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasObject">
<Documentation>
<UserDocu>Checks if the Part has a given object</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@ -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<DocumentObjectPy*>(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<DocumentObjectPy*>(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<DocumentObjectPy*>(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;
}
}

View File

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

View File

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

View File

@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 <QApplication>
# include <QPixmap>
#endif
#include <App/Part.h>
#include <App/Document.h>
/// 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<App::DocumentObject*> ViewProviderGeoFeatureGroup::claimChildren(void)const
{
return std::vector<App::DocumentObject*>(static_cast<App::Part*>(getObject())->Items.getValues());
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroup::claimChildren3D(void)const
{
return std::vector<App::DocumentObject*>(static_cast<App::Part*>(getObject())->Items.getValues());
}
bool ViewProviderGeoFeatureGroup::onDelete(const std::vector<std::string> &)
{
//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<ViewProviderGeoFeatureGroup>;
}

View File

@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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<App::DocumentObject*> claimChildren(void)const;
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
QIcon getIcon(void) const;
virtual bool onDelete(const std::vector<std::string> &);
/// get called if the user hover over a object in the tree
//virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
/// get called if the user drops some objects
//virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
};
typedef ViewProviderPythonFeatureT<ViewProviderGeoFeatureGroup> ViewProviderGeoFeatureGroupPython;
} // namespace Gui
#endif // GUI_VIEWPROVIDER_DOCUMENTOBJECTGROUP_H

View File

@ -81,11 +81,6 @@ void ViewProviderPart::updateData(const App::Property* prop)
}
std::vector<App::DocumentObject*> ViewProviderPart::claimChildren(void)const
{
return std::vector<App::DocumentObject*>(static_cast<App::Part*>(getObject())->Member.getValues());
}
std::vector<std::string> ViewProviderPart::getDisplayModes(void) const
{
// empty

View File

@ -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<App::DocumentObject*> claimChildren(void)const;
void attach(App::DocumentObject *pcObject);
void updateData(const App::Property*);
void Restore(Base::XMLReader &reader);

View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* This file is part of the FreeCAD CAx development system. *
* *

View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* This file is part of the FreeCAD CAx development system. *
* *