Extensions: bring files in correct order

This commit is contained in:
Stefan Tröger 2016-06-02 07:00:57 +02:00 committed by wmayer
parent a8d0accdad
commit c47c34edff
21 changed files with 576 additions and 274 deletions

View File

@ -98,8 +98,8 @@
#include "Annotation.h"
#include "MeasureDistance.h"
#include "Placement.h"
#include "GeoFeatureGroup.h"
#include "OriginGroup.h"
#include "GeoFeatureGroupExtension.h"
#include "OriginGroupExtension.h"
#include "Part.h"
#include "OriginFeature.h"
#include "Origin.h"

View File

@ -59,8 +59,8 @@ generate_from_xml(DocumentObjectExtensionPy)
generate_from_xml(GroupExtensionPy)
generate_from_xml(DocumentObjectGroupPy)
generate_from_xml(GeoFeaturePy)
#generate_from_xml(GeoFeatureGroupPy)
#generate_from_xml(OriginGroupPy)
generate_from_xml(GeoFeatureGroupExtensionPy)
generate_from_xml(OriginGroupExtensionPy)
generate_from_xml(PartPy)
generate_from_xml(ComplexGeoDataPy)
@ -78,8 +78,8 @@ SET(FreeCADApp_XML_SRCS
DocumentObjectGroupPy.xml
DocumentObjectPy.xml
GeoFeaturePy.xml
# GeoFeatureGroupPy.xml
# OriginGroupPy.xml
GeoFeatureGroupExtensionPy.xml
OriginGroupExtensionPy.xml
PartPy.xml
DocumentPy.xml
PropertyContainerPy.xml
@ -98,6 +98,7 @@ SET(Document_CPP_SRCS
DocumentObjectExtension.cpp
DocumentObjectExtensionPyImp.cpp
ExtensionContainerPyImp.cpp
GroupExtension.cpp
GroupExtensionPyImp.cpp
DocumentObjectFileIncluded.cpp
DocumentObjectGroup.cpp
@ -111,10 +112,10 @@ SET(Document_CPP_SRCS
FeaturePython.cpp
FeatureTest.cpp
GeoFeature.cpp
# GeoFeatureGroupPyImp.cpp
GeoFeatureGroup.cpp
# OriginGroupPyImp.cpp
OriginGroup.cpp
GeoFeatureGroupExtensionPyImp.cpp
GeoFeatureGroupExtension.cpp
OriginGroupExtensionPyImp.cpp
OriginGroupExtension.cpp
PartPyImp.cpp
Part.cpp
Origin.cpp
@ -136,6 +137,7 @@ SET(Document_HPP_SRCS
Document.h
DocumentObject.h
Extension.h
GroupExtension.h
DocumentObjectExtension.h
DocumentObjectFileIncluded.h
DocumentObjectGroup.h
@ -149,8 +151,8 @@ SET(Document_HPP_SRCS
FeaturePythonPyImp.inl
FeatureTest.h
GeoFeature.h
GeoFeatureGroup.h
OriginGroup.h
GeoFeatureGroupExtension.h
OriginGroupExtension.h
Part.h
Origin.h
Path.h

View File

@ -28,169 +28,11 @@
#include "DocumentObjectGroup.h"
#include "DocumentObjectGroupPy.h"
#include "GroupExtensionPy.h"
#include "Document.h"
#include "FeaturePythonPyImp.h"
using namespace App;
PROPERTY_SOURCE(App::GroupExtension, App::DocumentObjectExtension)
GroupExtension::GroupExtension()
{
initExtension(GroupExtension::getClassTypeId());
ADD_PROPERTY_TYPE(Group,(0),"Base",(App::PropertyType)(Prop_Output),"List of referenced objects");
}
GroupExtension::~GroupExtension()
{
}
DocumentObject* GroupExtension::addObject(const char* sType, const char* pObjectName)
{
DocumentObject* obj = getExtendedObject()->getDocument()->addObject(sType, pObjectName);
if (obj) addObject(obj);
return obj;
}
void GroupExtension::addObject(DocumentObject* obj)
{
if (!hasObject(obj)) {
std::vector<DocumentObject*> grp = Group.getValues();
grp.push_back(obj);
Group.setValues(grp);
}
}
void GroupExtension::removeObject(DocumentObject* obj)
{
const std::vector<DocumentObject*> & grp = Group.getValues();
std::vector<DocumentObject*> newGrp;
std::remove_copy (grp.begin(), grp.end(), std::back_inserter (newGrp), obj);
if (grp.size() != newGrp.size()) {
Group.setValues (newGrp);
}
}
void GroupExtension::removeObjectsFromDocument()
{
const std::vector<DocumentObject*> & grp = Group.getValues();
// Use set so iterate on each linked object exactly one time (in case of multiple links to the same document)
std::set<DocumentObject*> grpSet (grp.begin(), grp.end());
for (std::set<DocumentObject*>::iterator it = grpSet.begin(); it != grpSet.end(); ++it) {
removeObjectFromDocument(*it);
}
}
void GroupExtension::removeObjectFromDocument(DocumentObject* obj)
{
// remove all children
if (obj->hasExtension(GroupExtension::getClassTypeId())) {
GroupExtension *grp = static_cast<GroupExtension*>(obj->getExtension(GroupExtension::getClassTypeId()));
// recursive call to remove all subgroups
grp->removeObjectsFromDocument();
}
getExtendedObject()->getDocument()->remObject(obj->getNameInDocument());
}
DocumentObject *GroupExtension::getObject(const char *Name) const
{
DocumentObject* obj = getExtendedObject()->getDocument()->getObject(Name);
if (obj && hasObject(obj))
return obj;
return 0;
}
bool GroupExtension::hasObject(const DocumentObject* obj, bool recursive) const
{
const std::vector<DocumentObject*>& grp = Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == obj) {
return true;
} else if ( recursive && (*it)->hasExtension(GroupExtension::getClassTypeId()) ) {
App::GroupExtension *subGroup = static_cast<App::GroupExtension *> ((*it)->getExtension(GroupExtension::getClassTypeId()));
if (subGroup->hasObject (obj, recursive)) {
return true;
}
}
}
return false;
}
bool GroupExtension::isChildOf(const GroupExtension* group) const
{
const std::vector<DocumentObject*>& grp = group->Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == getExtendedObject())
return true;
if ((*it)->hasExtension(GroupExtension::getClassTypeId())) {
if (this->isChildOf(static_cast<GroupExtension*>((*it)->getExtension(GroupExtension::getClassTypeId()))))
return true;
}
}
return false;
}
std::vector<DocumentObject*> GroupExtension::getObjects() const
{
return Group.getValues();
}
std::vector<DocumentObject*> GroupExtension::getObjectsOfType(const Base::Type& typeId) const
{
std::vector<DocumentObject*> type;
const std::vector<DocumentObject*>& grp = Group.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 GroupExtension::countObjectsOfType(const Base::Type& typeId) const
{
int type=0;
const std::vector<DocumentObject*>& grp = Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if ( (*it)->getTypeId().isDerivedFrom(typeId))
type++;
}
return type;
}
DocumentObject* GroupExtension::getGroupOfObject(const DocumentObject* obj)
{
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType(GroupExtension::getClassTypeId());
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
GroupExtension* grp = (GroupExtension*)(*it);
if (grp->hasObject(obj))
return *it;
}
return 0;
}
PyObject* GroupExtension::getExtensionPyObject(void) {
if (ExtensionPythonObject.is(Py::_None())){
// ref counter is set to 1
auto grp = new GroupExtensionPy(this);
ExtensionPythonObject = Py::Object(grp,true);
}
return Py::new_reference_to(ExtensionPythonObject);
}
PROPERTY_SOURCE_WITH_EXTENSIONS(App::DocumentObjectGroup, App::DocumentObject, (App::GroupExtension))
DocumentObjectGroup::DocumentObjectGroup(void): DocumentObject(), GroupExtension() {
@ -215,7 +57,6 @@ PyObject *DocumentObjectGroup::getPyObject()
// Python feature ---------------------------------------------------------
namespace App {
PROPERTY_SOURCE_TEMPLATE(App::GroupExtensionPython, App::GroupExtension)
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(App::DocumentObjectGroupPython, App::DocumentObjectGroup)

View File

@ -27,81 +27,13 @@
#include "FeaturePython.h"
#include "DocumentObject.h"
#include "PropertyLinks.h"
#include "DocumentObjectExtension.h"
#include "GroupExtension.h"
#include <vector>
namespace App
{
class DocumentObjectGroup;
class GroupExtensionPy;
class AppExport GroupExtension : public DocumentObjectExtension
{
PROPERTY_HEADER(App::GroupExtension);
public:
/// Constructor
GroupExtension(void);
virtual ~GroupExtension();
/** @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.
* @param obj the object to check for.
* @param recursive if true check also if the obj is child of some sub group (default is false).
*/
bool hasObject(const DocumentObject* obj, bool recursive=false) const;
/**
* Checks whether this group object is a child (or sub-child)
* of the given group object.
*/
bool isChildOf(const GroupExtension*) 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;
/** Returns the object group of the document which the given object \a obj is part of.
* In case this object is not part of a group 0 is returned.
*/
static DocumentObject* getGroupOfObject(const DocumentObject* obj);
//@}
virtual PyObject* getExtensionPyObject(void);
/// Properties
PropertyLinkList Group;
private:
void removeObjectFromDocument(DocumentObject*);
};
//no virtual functions to override, simple derivative is enough
typedef App::ExtensionPython<App::GroupExtension> GroupExtensionPython;
class DocumentObjectGroup : public DocumentObject, public GroupExtension {
PROPERTY_HEADER_WITH_EXTENSIONS(App::DocumentObjectGroup);

View File

@ -29,7 +29,7 @@
#include <App/Document.h>
#include "GeoFeatureGroup.h"
#include "GeoFeatureGroupExtension.h"
//#include "GeoFeatureGroupPy.h"
//#include "FeaturePythonPyImp.h"

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectGroupPy"
Name="GeoFeatureGroupPy"
Twin="GeoFeatureGroup"
TwinPointer="GeoFeatureGroup"
Include="App/GeoFeatureGroup.h"
Father="GroupExtensionPy"
Name="GeoFeatureGroupExtensionPy"
Twin="GeoFeatureGroupExtension"
TwinPointer="GeoFeatureGroupExtension"
Include="App/GeoFeatureGroupExtension.h"
Namespace="App"
FatherInclude="App/DocumentObjectGroupPy.h"
FatherNamespace="App">
FatherInclude="App/GroupExtensionPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>This class handles placeable group of document objects</UserDocu>

View File

@ -24,27 +24,27 @@
#include "PreCompiled.h"
#include "App/GeoFeatureGroup.h"
#include "App/GeoFeatureGroupExtension.h"
// inclusion of the generated files (generated out of GeoFeatureGroupPy.xml)
#include "GeoFeatureGroupPy.h"
#include "GeoFeatureGroupPy.cpp"
// inclusion of the generated files (generated out of GeoFeatureGroupExtensionPy.xml)
#include "GeoFeatureGroupExtensionPy.h"
#include "GeoFeatureGroupExtensionPy.cpp"
using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string GeoFeatureGroupPy::representation(void) const
std::string GeoFeatureGroupExtensionPy::representation(void) const
{
return std::string("<GeoFeatureGroup object>");
}
PyObject *GeoFeatureGroupPy::getCustomAttributes(const char* /*attr*/) const
PyObject *GeoFeatureGroupExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GeoFeatureGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
int GeoFeatureGroupExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

193
src/App/GroupExtension.cpp Normal file
View File

@ -0,0 +1,193 @@
/***************************************************************************
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.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_
#endif
#include "DocumentObjectGroup.h"
#include "DocumentObjectGroupPy.h"
#include "GroupExtensionPy.h"
#include "Document.h"
#include "FeaturePythonPyImp.h"
using namespace App;
PROPERTY_SOURCE(App::GroupExtension, App::DocumentObjectExtension)
GroupExtension::GroupExtension()
{
initExtension(GroupExtension::getClassTypeId());
ADD_PROPERTY_TYPE(Group,(0),"Base",(App::PropertyType)(Prop_Output),"List of referenced objects");
}
GroupExtension::~GroupExtension()
{
}
DocumentObject* GroupExtension::addObject(const char* sType, const char* pObjectName)
{
DocumentObject* obj = getExtendedObject()->getDocument()->addObject(sType, pObjectName);
if (obj) addObject(obj);
return obj;
}
void GroupExtension::addObject(DocumentObject* obj)
{
if (!hasObject(obj)) {
std::vector<DocumentObject*> grp = Group.getValues();
grp.push_back(obj);
Group.setValues(grp);
}
}
void GroupExtension::removeObject(DocumentObject* obj)
{
const std::vector<DocumentObject*> & grp = Group.getValues();
std::vector<DocumentObject*> newGrp;
std::remove_copy (grp.begin(), grp.end(), std::back_inserter (newGrp), obj);
if (grp.size() != newGrp.size()) {
Group.setValues (newGrp);
}
}
void GroupExtension::removeObjectsFromDocument()
{
const std::vector<DocumentObject*> & grp = Group.getValues();
// Use set so iterate on each linked object exactly one time (in case of multiple links to the same document)
std::set<DocumentObject*> grpSet (grp.begin(), grp.end());
for (std::set<DocumentObject*>::iterator it = grpSet.begin(); it != grpSet.end(); ++it) {
removeObjectFromDocument(*it);
}
}
void GroupExtension::removeObjectFromDocument(DocumentObject* obj)
{
// remove all children
if (obj->hasExtension(GroupExtension::getClassTypeId())) {
GroupExtension *grp = static_cast<GroupExtension*>(obj->getExtension(GroupExtension::getClassTypeId()));
// recursive call to remove all subgroups
grp->removeObjectsFromDocument();
}
getExtendedObject()->getDocument()->remObject(obj->getNameInDocument());
}
DocumentObject *GroupExtension::getObject(const char *Name) const
{
DocumentObject* obj = getExtendedObject()->getDocument()->getObject(Name);
if (obj && hasObject(obj))
return obj;
return 0;
}
bool GroupExtension::hasObject(const DocumentObject* obj, bool recursive) const
{
const std::vector<DocumentObject*>& grp = Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == obj) {
return true;
} else if ( recursive && (*it)->hasExtension(GroupExtension::getClassTypeId()) ) {
App::GroupExtension *subGroup = static_cast<App::GroupExtension *> ((*it)->getExtension(GroupExtension::getClassTypeId()));
if (subGroup->hasObject (obj, recursive)) {
return true;
}
}
}
return false;
}
bool GroupExtension::isChildOf(const GroupExtension* group) const
{
const std::vector<DocumentObject*>& grp = group->Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if (*it == getExtendedObject())
return true;
if ((*it)->hasExtension(GroupExtension::getClassTypeId())) {
if (this->isChildOf(static_cast<GroupExtension*>((*it)->getExtension(GroupExtension::getClassTypeId()))))
return true;
}
}
return false;
}
std::vector<DocumentObject*> GroupExtension::getObjects() const
{
return Group.getValues();
}
std::vector<DocumentObject*> GroupExtension::getObjectsOfType(const Base::Type& typeId) const
{
std::vector<DocumentObject*> type;
const std::vector<DocumentObject*>& grp = Group.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 GroupExtension::countObjectsOfType(const Base::Type& typeId) const
{
int type=0;
const std::vector<DocumentObject*>& grp = Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
if ( (*it)->getTypeId().isDerivedFrom(typeId))
type++;
}
return type;
}
DocumentObject* GroupExtension::getGroupOfObject(const DocumentObject* obj)
{
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType(GroupExtension::getClassTypeId());
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
GroupExtension* grp = (GroupExtension*)(*it);
if (grp->hasObject(obj))
return *it;
}
return 0;
}
PyObject* GroupExtension::getExtensionPyObject(void) {
if (ExtensionPythonObject.is(Py::_None())){
// ref counter is set to 1
auto grp = new GroupExtensionPy(this);
ExtensionPythonObject = Py::Object(grp,true);
}
return Py::new_reference_to(ExtensionPythonObject);
}

105
src/App/GroupExtension.h Normal file
View File

@ -0,0 +1,105 @@
/***************************************************************************
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.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 APP_GROUPEXTENSION_H
#define APP_GROUPEXTENSION_H
#include "FeaturePython.h"
#include "DocumentObject.h"
#include "PropertyLinks.h"
#include "DocumentObjectExtension.h"
#include <vector>
namespace App
{
class DocumentObjectGroup;
class GroupExtensionPy;
class AppExport GroupExtension : public DocumentObjectExtension
{
PROPERTY_HEADER(App::GroupExtension);
public:
/// Constructor
GroupExtension(void);
virtual ~GroupExtension();
/** @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.
* @param obj the object to check for.
* @param recursive if true check also if the obj is child of some sub group (default is false).
*/
bool hasObject(const DocumentObject* obj, bool recursive=false) const;
/**
* Checks whether this group object is a child (or sub-child)
* of the given group object.
*/
bool isChildOf(const GroupExtension*) 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;
/** Returns the object group of the document which the given object \a obj is part of.
* In case this object is not part of a group 0 is returned.
*/
static DocumentObject* getGroupOfObject(const DocumentObject* obj);
//@}
virtual PyObject* getExtensionPyObject(void);
/// Properties
PropertyLinkList Group;
private:
void removeObjectFromDocument(DocumentObject*);
};
} //namespace App
#endif // APP_GROUPEXTENSION_H

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectExtensionPy"
Name="GroupExtensionPy"
Twin="GroupExtension"
TwinPointer="GroupExtension"
Include="App/DocumentObjectGroup.h"
Namespace="App"
FatherInclude="App/DocumentObjectExtensionPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Extension class which allows grouping of document objects</UserDocu>
</Documentation>
<Methode Name="newObject">
<Documentation>
<UserDocu>Create and add an object with given type and name to the group</UserDocu>
</Documentation>
</Methode>
<Methode Name="addObject">
<Documentation>
<UserDocu>Add an object to the group</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObject">
<Documentation>
<UserDocu>Remove an object from the group</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeObjectsFromDocument">
<Documentation>
<UserDocu>Remove all child objects from the group 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>hasObject(obj, recursive=false)
Checks if the group has a given object
@param obj the object to check for.
@param recursive if true check also if the obj is child of some sub group (default is false).
</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,177 @@
/***************************************************************************
* Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.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"
#include "DocumentObjectGroup.h"
#include "Document.h"
#include <CXX/Objects.hxx>
// inclusion of the generated files (generated out of GroupExtensionPy.xml)
#include "GroupExtensionPy.h"
#include "GroupExtensionPy.cpp"
#include "DocumentObjectPy.h"
using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string GroupExtensionPy::representation(void) const
{
return std::string("<group extension object>");
}
PyObject* GroupExtensionPy::newObject(PyObject *args)
{
char *sType,*sName=0;
if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) // convert args: Python->C
return NULL;
DocumentObject *object = getGroupExtensionPtr()->addObject(sType, sName);
if ( object ) {
return object->getPyObject();
}
else {
PyErr_Format(Base::BaseExceptionFreeCADError, "Cannot create object of type '%s'", sType);
return NULL;
}
}
PyObject* GroupExtensionPy::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(Base::BaseExceptionFreeCADError, "Cannot add an invalid object");
return NULL;
}
if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group");
return NULL;
}
if (docObj->getDocumentObjectPtr() == this->getGroupExtensionPtr()->getExtendedObject()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself");
return NULL;
}
if (docObj->getDocumentObjectPtr()->hasExtension(GroupExtension::getClassTypeId())) {
App::GroupExtension* docGrp = docObj->getDocumentObjectPtr()->getExtensionByType<GroupExtension>();
if (docGrp->hasObject(getGroupExtensionPtr()->getExtendedObject())) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to a child group");
return NULL;
}
}
GroupExtension* grp = getGroupExtensionPtr();
grp->addObject(docObj->getDocumentObjectPtr());
Py_Return;
}
PyObject* GroupExtensionPy::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(Base::BaseExceptionFreeCADError, "Cannot remove an invalid object");
return NULL;
}
if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group");
return NULL;
}
GroupExtension* grp = getGroupExtensionPtr();
grp->removeObject(docObj->getDocumentObjectPtr());
Py_Return;
}
PyObject* GroupExtensionPy::removeObjectsFromDocument(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
getGroupExtensionPtr()->removeObjectsFromDocument();
Py_Return;
}
PyObject* GroupExtensionPy::getObject(PyObject *args)
{
char* pcName;
if (!PyArg_ParseTuple(args, "s", &pcName)) // convert args: Python->C
return NULL; // NULL triggers exception
DocumentObject* obj = getGroupExtensionPtr()->getObject(pcName);
if ( obj ) {
return obj->getPyObject();
} else {
Py_Return;
}
}
PyObject* GroupExtensionPy::hasObject(PyObject *args)
{
PyObject *object;
PyObject *recursivePy = 0;
int recursive = 0;
if (!PyArg_ParseTuple(args, "O!|O", &(DocumentObjectPy::Type), &object, &recursivePy))
return NULL; // NULL triggers exception
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check an invalid object");
return NULL;
}
if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check an object from another document with this group");
return NULL;
}
if (recursivePy) {
recursive = PyObject_IsTrue(recursivePy);
if ( recursive == -1) {
// Note: shouldn't happen
PyErr_SetString(PyExc_ValueError, "The recursive parameter should be of boolean type");
return 0;
}
}
bool v = getGroupExtensionPtr()->hasObject(docObj->getDocumentObjectPtr(), recursive);
return PyBool_FromLong(v ? 1 : 0);
}
PyObject *GroupExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GroupExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -21,7 +21,7 @@
***************************************************************************/
#include "PreCompiled.h"
#include "OriginGroup.h"
#include "OriginGroupExtension.h"
#ifndef _PreComp_
#endif

View File

@ -23,7 +23,7 @@
#ifndef ORIGINGROUP_H_QHTU73IF
#define ORIGINGROUP_H_QHTU73IF
#include "GeoFeatureGroup.h"
#include "GeoFeatureGroupExtension.h"
#include "PropertyLinks.h"
namespace App {

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeoFeatureGroupPy"
Name="OriginGroupPy"
Twin="OriginGroup"
TwinPointer="OriginGroup"
Include="App/OriginGroup.h"
Father="GeoFeatureGroupExtensionPy"
Name="OriginGroupExtensionPy"
Twin="OriginGroupExtension"
TwinPointer="OriginGroupExtension"
Include="App/OriginGroupExtension.h"
Namespace="App"
FatherInclude="App/GeoFeatureGroupPy.h"
FatherInclude="App/GeoFeatureGroupExtensionPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Alexander Golubev" EMail="fatzer2@gmail.com" />

View File

@ -23,16 +23,16 @@
#include "PreCompiled.h"
#include "App/OriginGroup.h"
#include "App/OriginGroupExtension.h"
// inclusion of the generated files (generated out of OriginGroupPy.xml)
#include "OriginGroupPy.h"
#include "OriginGroupPy.cpp"
#include "OriginGroupExtensionPy.h"
#include "OriginGroupExtensionPy.cpp"
using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string OriginGroupPy::representation(void) const
std::string OriginGroupExtensionPy::representation(void) const
{
return std::string("<OriginGroup object>");
}
@ -43,12 +43,12 @@ std::string OriginGroupPy::representation(void) const
PyObject *OriginGroupPy::getCustomAttributes(const char* /*attr*/) const
PyObject *OriginGroupExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int OriginGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
int OriginGroupExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -24,7 +24,7 @@
#ifndef APP_Part_H
#define APP_Part_H
#include "OriginGroup.h"
#include "OriginGroupExtension.h"
#include "PropertyLinks.h"

View File

@ -28,7 +28,7 @@
# include <Inventor/nodes/SoGroup.h>
#endif
#include <App/GeoFeatureGroup.h>
#include <App/GeoFeatureGroupExtension.h>
#include "ViewProviderGeoFeatureGroup.h"

View File

@ -29,7 +29,7 @@
#endif
#include <Base/Console.h>
#include <App/OriginGroup.h>
#include <App/OriginGroupExtension.h>
#include <App/Origin.h>
#include "Application.h"

View File

@ -32,7 +32,7 @@
#endif
#include <App/OriginFeature.h>
#include <App/GeoFeatureGroup.h>
#include <App/GeoFeatureGroupExtension.h>
#include <App/Origin.h>
#include <App/Part.h>
#include <Gui/Application.h>

View File

@ -53,7 +53,7 @@
#endif
#include <App/DocumentObjectGroup.h>
#include <App/GeoFeatureGroup.h>
#include <App/GeoFeatureGroupExtension.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Application.h>