本文整理汇总了C++中DocumentObjectPy::getDocumentObjectPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ DocumentObjectPy::getDocumentObjectPtr方法的具体用法?C++ DocumentObjectPy::getDocumentObjectPtr怎么用?C++ DocumentObjectPy::getDocumentObjectPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentObjectPy
的用法示例。
在下文中一共展示了DocumentObjectPy::getDocumentObjectPtr方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setPyObject
void PropertyLinkSub::setPyObject(PyObject *value)
{
if (PyObject_TypeCheck(value, &(DocumentObjectPy::Type))) {
DocumentObjectPy *pcObject = (DocumentObjectPy*)value;
setValue(pcObject->getDocumentObjectPtr());
}
else if (Py::Object(value).isTuple()) {
Py::Tuple tup(value);
if (PyObject_TypeCheck(tup[0].ptr(), &(DocumentObjectPy::Type))){
DocumentObjectPy *pcObj = (DocumentObjectPy*)tup[0].ptr();
Py::List list(tup[1]);
std::vector<std::string> vals(list.size());
unsigned int i=0;
for(Py::List::iterator it = list.begin();it!=list.end();++it,++i)
vals[i] = Py::String(*it);
setValue(pcObj->getDocumentObjectPtr(),vals);
}
else {
std::string error = std::string("type of first element in tuple must be 'DocumentObject', not ");
error += tup[0].ptr()->ob_type->tp_name;
throw Py::TypeError(error);
}
}
else if(Py_None == value) {
setValue(0);
}
else {
std::string error = std::string("type must be 'DocumentObject', 'NoneType' or ('DocumentObject',['String',]) not ");
error += value->ob_type->tp_name;
throw Py::TypeError(error);
}
}
示例2: hasObject
PyObject* DocumentObjectGroupPy::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(Base::BaseExceptionFreeCADError, "Cannot check an invalid object");
return NULL;
}
if (docObj->getDocumentObjectPtr()->getDocument() != getDocumentObjectGroupPtr()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check an object from another document with this group");
return NULL;
}
if (getDocumentObjectGroupPtr()->hasObject(docObj->getDocumentObjectPtr())) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
示例3: setPyObject
void PropertyLinkSubList::setPyObject(PyObject *value)
{
try { //try PropertyLinkSub syntax
PropertyLinkSub dummy;
dummy.setPyObject(value);
this->setValue(dummy.getValue(), dummy.getSubValues());
}
catch (Base::TypeError) {
if (PyTuple_Check(value) || PyList_Check(value)) {
Py::Sequence list(value);
Py::Sequence::size_type size = list.size();
std::vector<DocumentObject*> values;
values.reserve(size);
std::vector<std::string> SubNames;
SubNames.reserve(size);
for (Py::Sequence::size_type i=0; i<size; i++) {
Py::Object item = list[i];
if (item.isTuple()) {
Py::Tuple tup(item);
if (PyObject_TypeCheck(tup[0].ptr(), &(DocumentObjectPy::Type))){
if (tup[1].isString()) {
DocumentObjectPy *pcObj;
pcObj = static_cast<DocumentObjectPy*>(tup[0].ptr());
values.push_back(pcObj->getDocumentObjectPtr());
SubNames.push_back(Py::String(tup[1]));
}
else if (tup[1].isSequence()) {
Py::Sequence list(tup[1]);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
SubNames.push_back(Py::String(*it));
}
DocumentObjectPy *pcObj;
pcObj = static_cast<DocumentObjectPy*>(tup[0].ptr());
values.insert(values.end(), list.size(), pcObj->getDocumentObjectPtr());
}
}
}
else if (PyObject_TypeCheck(*item, &(DocumentObjectPy::Type))) {
DocumentObjectPy *pcObj;
pcObj = static_cast<DocumentObjectPy*>(*item);
values.push_back(pcObj->getDocumentObjectPtr());
}
else if (item.isString()) {
SubNames.push_back(Py::String(item));
}
}
setValues(values,SubNames);
}
else {
std::string error = std::string("type must be 'DocumentObject' or list of 'DocumentObject', not ");
error += value->ob_type->tp_name;
throw Base::TypeError(error);
}
}
}
示例4: setPyObject
void PropertyLinkSubList::setPyObject(PyObject *value)
{
if (PyTuple_Check(value) || PyList_Check(value)) {
Py::Sequence list(value);
Py::Sequence::size_type size = list.size();
std::vector<DocumentObject*> values;
values.reserve(size);
std::vector<std::string> SubNames;
SubNames.reserve(size);
for (Py::Sequence::size_type i=0; i<size; i++) {
Py::Object item = list[i];
if (item.isTuple()) {
Py::Tuple tup(item);
if (PyObject_TypeCheck(tup[0].ptr(), &(DocumentObjectPy::Type))){
DocumentObjectPy *pcObj;
pcObj = static_cast<DocumentObjectPy*>(tup[0].ptr());
values.push_back(pcObj->getDocumentObjectPtr());
if (Py::Object(tup[1].ptr()).isString()){
SubNames.push_back(Py::String(tup[1].ptr()));
}
}
}
else if (PyObject_TypeCheck(*item, &(DocumentObjectPy::Type))) {
DocumentObjectPy *pcObj;
pcObj = static_cast<DocumentObjectPy*>(*item);
values.push_back(pcObj->getDocumentObjectPtr());
}
else if (item.isString()) {
SubNames.push_back(Py::String(item));
}
}
setValues(values,SubNames);
}
else {
std::string error = std::string("type must be 'DocumentObject' or list of 'DocumentObject', not ");
error += value->ob_type->tp_name;
throw Base::TypeError(error);
}
}
示例5: removeObject
PyObject* DocumentObjectGroupPy::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() != getDocumentObjectGroupPtr()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group");
return NULL;
}
DocumentObjectGroup* grp = getDocumentObjectGroupPtr();
if (grp->getTypeId().isDerivedFrom(App::DocumentObjectGroupPython::getClassTypeId())) {
DocumentObjectGroupPython* grppy = static_cast<DocumentObjectGroupPython*>(grp);
App::Property* proxy = grppy->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("removeObject"))) {
Py::Callable method(vp.getAttr(std::string("removeObject")));
// check which this method belongs to to avoid an infinite recursion
if (method.getAttr(std::string("__self__")) != Py::Object(this)) {
Py::Tuple args(1);
args[0] = Py::Object(object);
method.apply(args);
Py_Return;
}
}
}
}
grp->removeObject(docObj->getDocumentObjectPtr());
Py_Return;
}
示例6: moveObject
PyObject* DocumentPy::moveObject(PyObject *args)
{
PyObject *obj, *rec=Py_False;
if (!PyArg_ParseTuple(args, "O!|O!",&(DocumentObjectPy::Type),&obj,&PyBool_Type,&rec))
return NULL; // NULL triggers exception
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(obj);
DocumentObject* move = getDocumentPtr()->moveObject(docObj->getDocumentObjectPtr(), PyObject_IsTrue(rec) ? true : false);
if (move) {
return move->getPyObject();
}
else {
std::string str("Failed to move the object");
throw Py::Exception(PyExc_Exception,str);
}
}
示例7: copyObject
PyObject* DocumentPy::copyObject(PyObject *args)
{
PyObject *obj, *rec=0;
if (!PyArg_ParseTuple(args, "O!|O!",&(DocumentObjectPy::Type),&obj,&PyBool_Type,&rec))
return NULL; // NULL triggers exception
DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(obj);
DocumentObject* copy = getDocumentPtr()->copyObject(docObj->getDocumentObjectPtr(), rec==Py_True);
if (copy) {
return copy->getPyObject();
}
else {
std::string str("Failed to copy the object");
throw Py::Exception(PyExc_Exception,str);
}
}
示例8: addObject
PyObject* DocumentObjectGroupPy::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() != getDocumentObjectGroupPtr()->getDocument()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group");
return NULL;
}
if (docObj->getDocumentObjectPtr() == this->getDocumentObjectGroupPtr()) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself");
return NULL;
}
if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(DocumentObjectGroup::getClassTypeId())) {
App::DocumentObjectGroup* docGrp = static_cast<DocumentObjectGroup*>(docObj->getDocumentObjectPtr());
if (this->getDocumentObjectGroupPtr()->isChildOf(docGrp)) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to a child group");
return NULL;
}
}
DocumentObjectGroup* grp = getDocumentObjectGroupPtr();
if (grp->getTypeId().isDerivedFrom(App::DocumentObjectGroupPython::getClassTypeId())) {
DocumentObjectGroupPython* grppy = static_cast<DocumentObjectGroupPython*>(grp);
App::Property* proxy = grppy->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("addObject"))) {
Py::Callable method(vp.getAttr(std::string("addObject")));
Py::Tuple args(1);
args[0] = Py::Object(object);
method.apply(args);
Py_Return;
}
}
}
grp->addObject(docObj->getDocumentObjectPtr());
Py_Return;
}