1
/***************************************************************************
2
* Copyright (c) 2007 Werner Mayer <wmayer@users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
#include "DocumentObjectGroup.h"
29
// inclusion of the generated files (generated out of DocumentObjectGroupPy.xml)
30
#include "DocumentObjectGroupPy.h"
31
#include "DocumentObjectGroupPy.cpp"
35
// returns a string which represent the object e.g. when printed in python
36
const char *DocumentObjectGroupPy::representation(void) const
38
return "<group object>";
41
PyObject* DocumentObjectGroupPy::newObject(PyObject *args)
44
if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) // convert args: Python->C
47
DocumentObject *object = getDocumentObjectGroupPtr()->addObject(sType, sName);
49
return object->getPyObject();
52
PyErr_Format(PyExc_Exception, "Cannot create object of type '%s'", sType);
57
PyObject* DocumentObjectGroupPy::addObject(PyObject *args)
60
if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C
61
return NULL; // NULL triggers exception
63
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
64
if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
65
PyErr_SetString(PyExc_Exception, "Cannot add an invalid object");
68
if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
69
PyErr_SetString(PyExc_Exception, "Cannot add an object from another document to this group");
72
if (docObj->getDocumentObjectPtr() == this->getDocumentObjectGroupPtr()) {
73
PyErr_SetString(PyExc_Exception, "Cannot add a group object to itself");
76
if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(DocumentObjectGroup::getClassTypeId())) {
77
App::DocumentObjectGroup* docGrp = static_cast<DocumentObjectGroup*>(docObj->getDocumentObjectPtr());
78
if (this->getDocumentObjectGroupPtr()->isChildOf(docGrp)) {
79
PyErr_SetString(PyExc_Exception, "Cannot add a group object to a child group");
84
getDocumentObjectGroupPtr()->addObject(docObj->getDocumentObjectPtr());
88
PyObject* DocumentObjectGroupPy::removeObject(PyObject *args)
91
if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C
92
return NULL; // NULL triggers exception
94
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
95
if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
96
PyErr_SetString(PyExc_Exception, "Cannot remove an invalid object");
99
if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
100
PyErr_SetString(PyExc_Exception, "Cannot remove an object from another document from this group");
104
getDocumentObjectGroupPtr()->removeObject(docObj->getDocumentObjectPtr());
108
PyObject* DocumentObjectGroupPy::removeObjectsFromDocument(PyObject *args)
110
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
111
return NULL; // NULL triggers exception
113
getDocumentObjectGroupPtr()->removeObjectsFromDocument();
117
PyObject* DocumentObjectGroupPy::getObject(PyObject *args)
120
if (!PyArg_ParseTuple(args, "s", &pcName)) // convert args: Python->C
121
return NULL; // NULL triggers exception
123
DocumentObject* obj = getDocumentObjectGroupPtr()->getObject(pcName);
125
return obj->getPyObject();
131
PyObject* DocumentObjectGroupPy::hasObject(PyObject *args)
134
if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C
135
return NULL; // NULL triggers exception
137
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
138
if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
139
PyErr_SetString(PyExc_Exception, "Cannot check an invalid object");
142
if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
143
PyErr_SetString(PyExc_Exception, "Cannot check an object from another document with this group");
147
if (getDocumentObjectGroupPtr()->hasObject(docObj->getDocumentObjectPtr())) {
157
PyObject *DocumentObjectGroupPy::getCustomAttributes(const char* /*attr*/) const
162
int DocumentObjectGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)