DocumentObjectGroupPyImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include "DocumentObjectGroup.h"
00027 #include "Document.h"
00028
00029
00030 #include "DocumentObjectGroupPy.h"
00031 #include "DocumentObjectGroupPy.cpp"
00032
00033 using namespace App;
00034
00035
00036 std::string DocumentObjectGroupPy::representation(void) const
00037 {
00038 return std::string("<group object>");
00039 }
00040
00041 PyObject* DocumentObjectGroupPy::newObject(PyObject *args)
00042 {
00043 char *sType,*sName=0;
00044 if (!PyArg_ParseTuple(args, "s|s", &sType,&sName))
00045 return NULL;
00046
00047 DocumentObject *object = getDocumentObjectGroupPtr()->addObject(sType, sName);
00048 if ( object ) {
00049 return object->getPyObject();
00050 }
00051 else {
00052 PyErr_Format(PyExc_Exception, "Cannot create object of type '%s'", sType);
00053 return NULL;
00054 }
00055 }
00056
00057 PyObject* DocumentObjectGroupPy::addObject(PyObject *args)
00058 {
00059 PyObject *object;
00060 if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object))
00061 return NULL;
00062
00063 DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
00064 if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
00065 PyErr_SetString(PyExc_Exception, "Cannot add an invalid object");
00066 return NULL;
00067 }
00068 if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
00069 PyErr_SetString(PyExc_Exception, "Cannot add an object from another document to this group");
00070 return NULL;
00071 }
00072 if (docObj->getDocumentObjectPtr() == this->getDocumentObjectGroupPtr()) {
00073 PyErr_SetString(PyExc_Exception, "Cannot add a group object to itself");
00074 return NULL;
00075 }
00076 if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(DocumentObjectGroup::getClassTypeId())) {
00077 App::DocumentObjectGroup* docGrp = static_cast<DocumentObjectGroup*>(docObj->getDocumentObjectPtr());
00078 if (this->getDocumentObjectGroupPtr()->isChildOf(docGrp)) {
00079 PyErr_SetString(PyExc_Exception, "Cannot add a group object to a child group");
00080 return NULL;
00081 }
00082 }
00083
00084 getDocumentObjectGroupPtr()->addObject(docObj->getDocumentObjectPtr());
00085 Py_Return;
00086 }
00087
00088 PyObject* DocumentObjectGroupPy::removeObject(PyObject *args)
00089 {
00090 PyObject *object;
00091 if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object))
00092 return NULL;
00093
00094 DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
00095 if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
00096 PyErr_SetString(PyExc_Exception, "Cannot remove an invalid object");
00097 return NULL;
00098 }
00099 if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
00100 PyErr_SetString(PyExc_Exception, "Cannot remove an object from another document from this group");
00101 return NULL;
00102 }
00103
00104 getDocumentObjectGroupPtr()->removeObject(docObj->getDocumentObjectPtr());
00105 Py_Return;
00106 }
00107
00108 PyObject* DocumentObjectGroupPy::removeObjectsFromDocument(PyObject *args)
00109 {
00110 if (!PyArg_ParseTuple(args, ""))
00111 return NULL;
00112
00113 getDocumentObjectGroupPtr()->removeObjectsFromDocument();
00114 Py_Return;
00115 }
00116
00117 PyObject* DocumentObjectGroupPy::getObject(PyObject *args)
00118 {
00119 char* pcName;
00120 if (!PyArg_ParseTuple(args, "s", &pcName))
00121 return NULL;
00122
00123 DocumentObject* obj = getDocumentObjectGroupPtr()->getObject(pcName);
00124 if ( obj ) {
00125 return obj->getPyObject();
00126 } else {
00127 Py_Return;
00128 }
00129 }
00130
00131 PyObject* DocumentObjectGroupPy::hasObject(PyObject *args)
00132 {
00133 PyObject *object;
00134 if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object))
00135 return NULL;
00136
00137 DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object);
00138 if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) {
00139 PyErr_SetString(PyExc_Exception, "Cannot check an invalid object");
00140 return NULL;
00141 }
00142 if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
00143 PyErr_SetString(PyExc_Exception, "Cannot check an object from another document with this group");
00144 return NULL;
00145 }
00146
00147 if (getDocumentObjectGroupPtr()->hasObject(docObj->getDocumentObjectPtr())) {
00148 Py_INCREF(Py_True);
00149 return Py_True;
00150 }
00151 else {
00152 Py_INCREF(Py_False);
00153 return Py_False;
00154 }
00155 }
00156
00157 PyObject *DocumentObjectGroupPy::getCustomAttributes(const char* ) const
00158 {
00159 return 0;
00160 }
00161
00162 int DocumentObjectGroupPy::setCustomAttributes(const char* , PyObject* )
00163 {
00164 return 0;
00165 }
00166