From a75c955d32e5a3af1b9b91a3e65fdfa68baeaf78 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 21 Jun 2019 13:47:33 +0800 Subject: [PATCH] ViewProvider/ViewProviderExtension: various new APIs Some of these new APIs are not strictly needed for Link to work, but good to have. Summary of the API changes: * getModeSwitch/getTransformNode() exposes view provider mode switch and transformation coin3D node, required by ViewProviderLink to override placement and visibility. * canAddToSceneGraph() inform 3D viewer whether to add the root node to scenegraph. Some object only exists as a child of some coordinate system. Not adding them can simplify scenegraph and visibility management. * showInTree() inform tree view whether to show the corresponding tree item. * getDefaultMode() to expose the current active mode regardless of the view provider's visibility * (can)DropObjectEx() superseds (can)DropObject() with additional support of subname reference, which makes it easy to support linking to sub-objects. One of the use case is cross coordinate system linking. * getDropPrefix() is used to tell tree view where the object is dropped into. A non empty return means the object is actually dropped into a sub-object. For example, Assembly3 container puts all dropped object into its child container PartGroup. * canDragAndDropObject() is used to inform tree view whether the object dropped need to be dragged out of its original parent, which usually does not make sure for Link type object. * beforeDelete() will be called by Gui::Document when either the object itself is being deleted or when the document is being destoried. * is/setLinkVisibility() allows to show/hide a link to this object. This may be used during editing, to prevent showing editing geometry in multiple places. * update() is made a virtual function, it will be overridden by ViewProviderDocumentObject in future patch. * startEditing() now becomes virtual, and return a ViewProvider that actually handles the editing. This is for future Link type object to forward editing request * covert(), convenience function to convert between Coin3D and FC matrix ViewProviderExtension also gains many relavant extension point of the new API. There is also the new extensionModeSwitchChange() for notifying mode switch changes ViewProviderPy exposes several method/attribute for the new API as well. --- src/Gui/ViewProvider.cpp | 128 ++++++++++++++++--- src/Gui/ViewProvider.h | 101 +++++++++++++-- src/Gui/ViewProviderExtension.h | 25 +++- src/Gui/ViewProviderPy.xml | 80 ++++++++++++ src/Gui/ViewProviderPyImp.cpp | 209 +++++++++++++++++++++++++++++++- 5 files changed, 504 insertions(+), 39 deletions(-) diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index b9478f9472..b98987c974 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -41,6 +41,7 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include #include +#include #include #include @@ -107,11 +108,13 @@ ViewProvider::~ViewProvider() pcAnnotation->unref(); } -bool ViewProvider::startEditing(int ModNum) +ViewProvider *ViewProvider::startEditing(int ModNum) { - bool ok = setEdit(ModNum); - if (ok) _iEditMode = ModNum; - return ok; + if(setEdit(ModNum)) { + _iEditMode = ModNum; + return this; + } + return 0; } int ViewProvider::getEditingMode() const @@ -298,7 +301,7 @@ void ViewProvider::setTransformation(const SbMatrix &rcMatrix) pcTransform->setMatrix(rcMatrix); } -SbMatrix ViewProvider::convert(const Base::Matrix4D &rcMatrix) const +SbMatrix ViewProvider::convert(const Base::Matrix4D &rcMatrix) { double dMtrx[16]; rcMatrix.getGLMatrix(dMtrx); @@ -308,6 +311,15 @@ SbMatrix ViewProvider::convert(const Base::Matrix4D &rcMatrix) const dMtrx[12],dMtrx[13],dMtrx[14], dMtrx[15]); } +Base::Matrix4D ViewProvider::convert(const SbMatrix &smat) +{ + Base::Matrix4D mat; + for(int i=0;i<4;++i) + for(int j=0;j<4;++j) + mat[i][j] = smat[j][i]; + return mat; +} + void ViewProvider::addDisplayMaskMode(SoNode *node, const char* type) { _sDisplayMaskModes[type] = pcModeSwitch->getNumChildren(); @@ -381,11 +393,16 @@ std::string ViewProvider::getActiveDisplayMode(void) const void ViewProvider::hide(void) { - pcModeSwitch->whichChild = -1; + auto exts = getExtensionsDerivedFromType(); + + if(pcModeSwitch->whichChild.getValue() >= 0) { + pcModeSwitch->whichChild = -1; + for(auto ext : exts) + ext->extensionModeSwitchChange(); + } //tell extensions that we hide - auto vector = getExtensionsDerivedFromType(); - for (Gui::ViewProviderExtension* ext : vector) + for (Gui::ViewProviderExtension* ext : exts) ext->extensionHide(); } @@ -429,6 +446,10 @@ void ViewProvider::setOverrideMode(const std::string &mode) } if (pcModeSwitch->whichChild.getValue() != -1) setModeSwitch(); + else { + for(auto ext : getExtensionsDerivedFromType()) + ext->extensionModeSwitchChange(); + } } const string ViewProvider::getOverrideMode() { @@ -442,16 +463,28 @@ void ViewProvider::setModeSwitch() pcModeSwitch->whichChild = _iActualMode; else if (viewOverrideMode < pcModeSwitch->getNumChildren()) pcModeSwitch->whichChild = viewOverrideMode; + else + return; + for(auto ext : getExtensionsDerivedFromType()) + ext->extensionModeSwitchChange(); } void ViewProvider::setDefaultMode(int val) { _iActualMode = val; + for(auto ext : getExtensionsDerivedFromType()) + ext->extensionModeSwitchChange(); +} + +int ViewProvider::getDefaultMode() const { + return viewOverrideMode>=0?viewOverrideMode:_iActualMode; } void ViewProvider::onChanged(const App::Property* prop) { Application::Instance->signalChangedObject(*this, *prop); + + App::TransactionalObject::onChanged(prop); } std::string ViewProvider::toString() const @@ -716,8 +749,18 @@ bool ViewProvider::canDropObjects() const { return false; } -void ViewProvider::dropObject(App::DocumentObject* obj) -{ +bool ViewProvider::canDragAndDropObject(App::DocumentObject* obj) const { + + auto vector = getExtensionsDerivedFromType(); + for(Gui::ViewProviderExtension* ext : vector){ + if(!ext->extensionCanDragAndDropObject(obj)) + return false; + } + + return true; +} + +void ViewProvider::dropObject(App::DocumentObject* obj) { auto vector = getExtensionsDerivedFromType(); for (Gui::ViewProviderExtension* ext : vector) { if (ext->extensionCanDropObject(obj)) { @@ -729,24 +772,52 @@ void ViewProvider::dropObject(App::DocumentObject* obj) throw Base::RuntimeError("ViewProvider::dropObject: no extension for dropping given object available."); } -void ViewProvider::replaceObject(App::DocumentObject* oldValue, App::DocumentObject* newValue) +bool ViewProvider::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements) const +{ + auto vector = getExtensionsDerivedFromType(); + for(Gui::ViewProviderExtension* ext : vector){ + if(ext->extensionCanDropObjectEx(obj,owner,subname, elements)) + return true; + } + return canDropObject(obj); +} + +std::string ViewProvider::dropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements) +{ + auto vector = getExtensionsDerivedFromType(); + for(Gui::ViewProviderExtension* ext : vector) { + if(ext->extensionCanDropObjectEx(obj, owner, subname, elements)) + return ext->extensionDropObjectEx(obj, owner, subname, elements); + } + dropObject(obj); + return std::string(); +} + +int ViewProvider::replaceObject(App::DocumentObject* oldValue, App::DocumentObject* newValue) { auto vector = getExtensionsDerivedFromType(); for (Gui::ViewProviderExtension* ext : vector) { if (ext->extensionCanDropObject(newValue)) { - ext->extensionReplaceObject(oldValue, newValue); - return; + int ret = ext->extensionReplaceObject(oldValue, newValue); + if(ret>=0) + return !!ret; } } - - throw Base::RuntimeError("ViewProvider::dropObject: no extension for dropping given object available."); + return -1; } -void ViewProvider::Restore(Base::XMLReader& reader) -{ - setStatus(Gui::isRestoring, true); +void ViewProvider::Restore(Base::XMLReader& reader) { + // Because some PropertyLists type properties are stored in a separate file, + // and is thus restored outside this function. So we rely on Gui::Document + // to set the isRestoring flags for us. + // + // setStatus(Gui::isRestoring, true); + TransactionalObject::Restore(reader); - setStatus(Gui::isRestoring, false); + + // setStatus(Gui::isRestoring, false); } void ViewProvider::updateData(const App::Property* prop) @@ -812,3 +883,22 @@ std::vector< App::DocumentObject* > ViewProvider::claimChildren3D(void) const } return vec; } + +void ViewProvider::beforeDelete() { + auto vector = getExtensionsDerivedFromType(); + for(Gui::ViewProviderExtension* ext : vector) + ext->extensionBeforeDelete(); +} + +bool ViewProvider::isLinkVisible() const { + auto ext = getExtensionByType(true); + if(!ext) + return true; + return ext->isLinkVisible(); +} + +void ViewProvider::setLinkVisible(bool visible) { + auto ext = getExtensionByType(true); + if(ext) + ext->setLinkVisible(visible); +} diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 2bf274ec2a..a525778534 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -33,6 +33,7 @@ #include #include +#include #include class SbVec2s; @@ -69,6 +70,7 @@ namespace Gui { class View3DInventorViewer; class ViewProviderPy; class ObjectItem; +class MDIView; enum ViewStatus { UpdateData = 0, @@ -119,6 +121,9 @@ public: // returns the root node of the Provider (3D) virtual SoSeparator* getRoot(void){return pcRoot;} + // return the mode switch node of the Provider (3D) + SoSwitch *getModeSwitch(void){return pcModeSwitch;} + SoTransform *getTransformNode(){return pcTransform;} // returns the root for the Annotations. SoSeparator* getAnnotation(void); // returns the root node of the Provider (3D) @@ -127,6 +132,9 @@ public: virtual SoGroup* getChildRoot(void) const; // returns the root node of the Provider (3D) virtual SoSeparator* getBackRoot(void) const; + ///Indicate whether to be added to scene graph or not + virtual bool canAddToSceneGraph() const {return true;} + /** deliver the children belonging to this object * this method is used to deliver the objects to * the 3DView which should be grouped under its @@ -155,6 +163,7 @@ public: (void)Element; return std::vector(); } + /** * Get called if the object is about to get deleted. * Here you can delete other objects, switch their visibility or prevent the deletion of the object. @@ -162,6 +171,12 @@ public: * @return true if the deletion is approved by the view provider. */ virtual bool onDelete(const std::vector &subNames); + /** Called before deletion + * + * Unlike onDelete(), this function is guaranteed to be called before + * deletion, either by Document::remObject(), or on document deletion. + */ + virtual void beforeDelete(); /** * @brief Asks the view provider if the given object that is part of its * outlist can be removed from there without breaking it. @@ -204,23 +219,79 @@ public: virtual bool canDragObjects() const; /** Check whether the object can be removed from the view provider by drag and drop */ virtual bool canDragObject(App::DocumentObject*) const; - /** Tell the tree view if this object should appear there */ - virtual bool showInTree() const - { - return true; - } /** Remove a child from the view provider by drag and drop */ virtual void dragObject(App::DocumentObject*); - /** Check whether objects can be added to the view provider by drag and drop */ + /** Check whether objects can be added to the view provider by drag and drop or drop only */ virtual bool canDropObjects() const; - /** Check whether the object can be dropped to the view provider by drag and drop */ + /** Check whether the object can be dropped to the view provider by drag and drop or drop only*/ virtual bool canDropObject(App::DocumentObject*) const; + /** Return false to force drop only operation for a given object*/ + virtual bool canDragAndDropObject(App::DocumentObject*) const; /** Add an object to the view provider by drag and drop */ virtual void dropObject(App::DocumentObject*); - /** Replace an object to the view provider by drag and drop */ - virtual void replaceObject(App::DocumentObject*, App::DocumentObject*); + /** Query object dropping with full quanlified name + * + * Tree view now calls this function instead of canDropObject(), and may + * query for objects from other document. The default implementation + * (actually in ViewProviderDocumentObject) inhibites cross document + * dropping, and calls canDropObject(obj) for the rest. Override this + * function to enable cross document linking. + * + * @param obj: the object being dropped + * + * @param owner: the (grand)parent object of the dropping object. Maybe + * null. This may not be the top parent object, as tree view will try to + * find a parent of the dropping object realtive to this object to avoid + * cyclic dependency + * + * @param subname: subname reference to the dropping object + * + * @param elements: non-object sub-elements, e.g. Faces, Edges, selected + * when the object is being dropped + * + * @return Return whether the dropping action is allowed. + * */ + virtual bool canDropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements) const; + + /// return a subname referencing the sub-object holding the dropped objects + virtual std::string getDropPrefix() const { return std::string(); } + + /** Add an object with full quanlified name to the view provider by drag and drop + * + * @param obj: the object being dropped + * + * @param owner: the (grand)parent object of the dropping object. Maybe + * null. This may not be the top parent object, as tree view will try to + * find a parent of the dropping object realtive to this object to avoid + * cyclic dependency + * + * @param subname: subname reference to the dropping object + * + * @param elements: non-object sub-elements, e.g. Faces, Edges, selected + * when the object is being dropped + * + * @return Optionally returns a subname reference locating the dropped + * object, which may or may not be the actual dropped object, e.g. it may be + * a link. + */ + virtual std::string dropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements); + /** Replace an object to the view provider by drag and drop + * + * @param oldObj: object to be replaced + * @param newObj: object to replace with + * + * @return Returns 0 if not found, 1 if succeed, -1 if not supported + */ + virtual int replaceObject(App::DocumentObject *oldObj, App::DocumentObject *newObj); //@} + /** Tell the tree view if this object should apear there */ + virtual bool showInTree() const { return true; } + /** Tell the tree view to remove children items from the tree root*/ + virtual bool canRemoveChildrenFromRoot() const {return true;} + /** @name Signals of the view provider */ //@{ /// signal on icon change @@ -237,7 +308,7 @@ public: * update. E.g. only the view attribute has changed, or * the data has manipulated. */ - void update(const App::Property*); + virtual void update(const App::Property*); virtual void updateData(const App::Property*); bool isUpdatesEnabled () const; void setUpdatesEnabled (bool enable); @@ -268,6 +339,8 @@ public: virtual bool isShow(void) const; void setVisible(bool); bool isVisible() const; + void setLinkVisible(bool); + bool isLinkVisible() const; /// Overrides the display mode with mode. virtual void setOverrideMode(const std::string &mode); const std::string getOverrideMode(); @@ -293,7 +366,7 @@ protected: int getEditingMode() const; public: - bool startEditing(int ModNum = 0); + virtual ViewProvider *startEditing(int ModNum=0); bool isEditing() const; void finishEditing(); /// adjust viewer settings when editing a view provider @@ -333,9 +406,12 @@ public: /// set the viewing transformation of the provider virtual void setTransformation(const Base::Matrix4D &rcMatrix); virtual void setTransformation(const SbMatrix &rcMatrix); - SbMatrix convert(const Base::Matrix4D &rcMatrix) const; + static SbMatrix convert(const Base::Matrix4D &rcMatrix); + static Base::Matrix4D convert(const SbMatrix &sbMat); //@} + virtual MDIView *getMDIView() {return 0;} + public: // this method is called by the viewer when the ViewProvider is in edit static void eventCallback(void * ud, SoEventCallback * node); @@ -363,6 +439,7 @@ public: /// Returns a list of added display mask modes std::vector getDisplayMaskModes() const; void setDefaultMode(int); + int getDefaultMode() const; //@} protected: diff --git a/src/Gui/ViewProviderExtension.h b/src/Gui/ViewProviderExtension.h index 003f133c70..abc1e98323 100644 --- a/src/Gui/ViewProviderExtension.h +++ b/src/Gui/ViewProviderExtension.h @@ -53,8 +53,9 @@ public: return std::vector(); } virtual bool extensionOnDelete(const std::vector &){ return true;} - - virtual std::vector extensionClaimChildren(void) const { + virtual void extensionBeforeDelete(){} + + virtual std::vector extensionClaimChildren(void) const { return std::vector(); } virtual bool extensionCanDragObjects() const { return false; } @@ -62,18 +63,30 @@ public: virtual void extensionDragObject(App::DocumentObject*) { } virtual bool extensionCanDropObjects() const { return false; } virtual bool extensionCanDropObject(App::DocumentObject*) const { return true; } + virtual bool extensionCanDragAndDropObject(App::DocumentObject*) const { return true; } virtual void extensionDropObject(App::DocumentObject*) { } - virtual void extensionReplaceObject(App::DocumentObject* /*oldValue*/, App::DocumentObject* /*newValue*/) { } + virtual bool extensionCanDropObjectEx(App::DocumentObject *, App::DocumentObject *, + const char *, const std::vector &) const + { return false; } + virtual std::string extensionDropObjectEx(App::DocumentObject *obj, App::DocumentObject *, + const char *, const std::vector &) + { extensionDropObject(obj); return std::string(); } + + virtual int extensionReplaceObject(App::DocumentObject* /*oldValue*/, App::DocumentObject* /*newValue*/) + { return -1; } /// Hides the view provider virtual void extensionHide(void) { } /// Shows the view provider virtual void extensionShow(void) { } + virtual void extensionModeSwitchChange(void) { } + virtual SoSeparator* extensionGetFrontRoot(void) const {return nullptr;} virtual SoGroup* extensionGetChildRoot(void) const {return nullptr;} virtual SoSeparator* extensionGetBackRoot(void) const {return nullptr;} virtual void extensionAttach(App::DocumentObject* ) { } + virtual void extensionReattach(App::DocumentObject* ) { } virtual void extensionSetDisplayMode(const char* ) { } virtual std::vector extensionGetDisplayModes(void) const {return std::vector();} @@ -82,6 +95,12 @@ public: virtual QIcon extensionMergeOverlayIcons(const QIcon & orig) const {return orig;} + virtual void extensionStartRestoring() {} + virtual void extensionFinishRestoring() {} + + virtual bool extensionGetElementPicked(const SoPickedPoint *, std::string &) const {return false;} + virtual bool extensionGetDetailPath(const char *, SoFullPath *, SoDetail *&) const {return false;} + private: //Gui::ViewProviderDocumentObject* m_viewBase = nullptr; }; diff --git a/src/Gui/ViewProviderPy.xml b/src/Gui/ViewProviderPy.xml index 1da524c702..19656034c0 100644 --- a/src/Gui/ViewProviderPy.xml +++ b/src/Gui/ViewProviderPy.xml @@ -50,6 +50,51 @@ Check if the object is visible + + + canDragObject(obj=None): check whether the child object can be removed by dragging + + + + + dragObject(obj): remove a child object by dropping + + + + + + canDropObject(obj=None,owner=None,subname=None) + check whether the child object can be added by dropping + + + + + + dropObject(obj,owner=None,subname=None): add a child object by dropping + + + + + +canDragAndDropObject(obj) +Check whether the child object can be removed from other parent and added here by drag and drop + + + + + + +replaceObject(oldObj, newObj) -> Int: replace a child object + +Returns 1 if succeed, 0 if not found, -1 if not supported + + + + + + Trigger double clicking the corresponding tree item of this view object + + Add a new display mode to the view provider @@ -75,6 +120,11 @@ Returns list of objects that are to be grouped in tree under this object. + + + Trigger icon changed signal + + A pivy Separator to add a custom scene graph to this ViewProvider @@ -93,11 +143,41 @@ + + + A pivy SoSwitch for the display mode switch of this ViewProvider + + + + + + Get/Set the default display mode in turns of coin node index + + + Represents the whole ViewProvider as an Inventor string. + + + Tells the tree view whether to remvoe the children item from root or not + + + + + + Get/set visiblities of all links to this view object + + + + + + Subname referecing the sub-object for holding dropped object + + + diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index 009b5db440..d31dd64c76 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -32,19 +32,26 @@ #include #include #include +#include +#include #include "ViewProvider.h" #include "WidgetFactory.h" +#include + // inclusion of the generated files (generated out of ViewProviderPy2.xml) #include #include +#include +#include #include #include #include #include #include #include +#include using namespace Gui; @@ -148,6 +155,137 @@ PyObject* ViewProviderPy::isVisible(PyObject *args) } PY_CATCH; } +PyObject* ViewProviderPy::canDragObject(PyObject *args) +{ + PyObject *obj = Py_None; + if (!PyArg_ParseTuple(args, "|O", &obj)) + return NULL; + PY_TRY { + bool ret; + if(obj == Py_None) + ret = getViewProviderPtr()->canDragObjects(); + else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) { + PyErr_SetString(PyExc_TypeError, "exepcting a type of DocumentObject"); + return 0; + }else + ret = getViewProviderPtr()->canDragObject( + static_cast(obj)->getDocumentObjectPtr()); + return Py::new_reference_to(Py::Boolean(ret)); + } PY_CATCH; +} + +PyObject* ViewProviderPy::canDropObject(PyObject *args) +{ + PyObject *obj = Py_None; + PyObject *owner = Py_None; + PyObject *pyElements = Py_None; + const char *subname = 0; + if (!PyArg_ParseTuple(args, "|OOsO", &obj,&owner,&subname,&pyElements)) + return NULL; + PY_TRY { + bool ret; + if(obj == Py_None) + ret = getViewProviderPtr()->canDropObjects(); + else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) { + PyErr_SetString(PyExc_TypeError, "exepcting 'obj' to be of type DocumentObject"); + return 0; + } + auto pcObject = static_cast(obj)->getDocumentObjectPtr(); + App::DocumentObject *pcOwner = 0; + if(owner!=Py_None) { + if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) { + PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject"); + return NULL; + } + pcOwner = static_cast(owner)->getDocumentObjectPtr(); + } + App::PropertyStringList elements; + if(pyElements!=Py_None) { + try { + elements.setPyObject(pyElements); + }catch(...) { + PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings"); + return 0; + } + } + ret = getViewProviderPtr()->canDropObjectEx(pcObject,pcOwner,subname,elements.getValues()); + return Py::new_reference_to(Py::Boolean(ret)); + } PY_CATCH; +} + +PyObject* ViewProviderPy::canDragAndDropObject(PyObject *args) +{ + PyObject *obj; + if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj)) + return NULL; + PY_TRY { + bool ret = getViewProviderPtr()->canDragAndDropObject( + static_cast(obj)->getDocumentObjectPtr()); + return Py::new_reference_to(Py::Boolean(ret)); + } PY_CATCH; +} + +PyObject* ViewProviderPy::dropObject(PyObject *args) +{ + PyObject *obj; + PyObject *owner = Py_None; + PyObject *pyElements = Py_None; + const char *subname = 0; + if (!PyArg_ParseTuple(args, "O!|OsO", &App::DocumentObjectPy::Type,&obj,&owner,&subname,&pyElements)) + return NULL; + PY_TRY { + App::DocumentObject *pcOwner = 0; + if(owner!=Py_None) { + if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) { + PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject"); + return NULL; + } + pcOwner = static_cast(owner)->getDocumentObjectPtr(); + } + App::PropertyStringList elements; + if(pyElements!=Py_None) { + try { + elements.setPyObject(pyElements); + }catch(...) { + PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings"); + return 0; + } + } + auto ret = getViewProviderPtr()->dropObjectEx( + static_cast(obj)->getDocumentObjectPtr(), + pcOwner, subname,elements.getValues()); + return Py::new_reference_to(Py::String(ret)); + } PY_CATCH; +} + +PyObject* ViewProviderPy::dragObject(PyObject *args) +{ + PyObject *obj; + if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj)) + return NULL; + PY_TRY { + getViewProviderPtr()->dragObject( + static_cast(obj)->getDocumentObjectPtr()); + Py_Return; + } PY_CATCH; +} + +PyObject* ViewProviderPy::replaceObject(PyObject *args) +{ + PyObject *oldObj; + PyObject *newObj; + if (!PyArg_ParseTuple(args, "O!O!", + &App::DocumentObjectPy::Type,&oldObj, + &App::DocumentObjectPy::Type,&newObj)) + return NULL; + PY_TRY { + int ret = getViewProviderPtr()->replaceObject( + static_cast(oldObj)->getDocumentObjectPtr(), + static_cast(newObj)->getDocumentObjectPtr()); + return Py::new_reference_to(Py::Int(ret)); + } PY_CATCH; +} + PyObject* ViewProviderPy::addDisplayMode(PyObject * args) { char* mode; @@ -157,7 +295,7 @@ PyObject* ViewProviderPy::addDisplayMode(PyObject * args) void* ptr = 0; try { - Base::Interpreter().convertSWIGPointerObj("pivy.coin","SoNode *", obj, &ptr, 0); + Base::Interpreter().convertSWIGPointerObj("pivy.coin","_p_SoNode", obj, &ptr, 0); } catch (const Base::Exception& e) { PyErr_SetString(PyExc_RuntimeError, e.what()); @@ -239,6 +377,22 @@ PyObject* ViewProviderPy::claimChildren(PyObject* args) return Py::new_reference_to(ret); } +PyObject *ViewProviderPy::signalChangeIcon(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + getViewProviderPtr()->signalChangeIcon(); + Py_Return; +} + +PyObject *ViewProviderPy::doubleClicked(PyObject *args) { + if(!PyArg_ParseTuple(args, "")) + return 0; + PY_TRY { + return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->doubleClicked())); + }PY_CATCH; +} + PyObject *ViewProviderPy::getCustomAttributes(const char* attr) const { // search for dynamic property @@ -273,8 +427,8 @@ int ViewProviderPy::setCustomAttributes(const char* attr, PyObject* value) Py::Object ViewProviderPy::getAnnotation(void) const { try { - SoNode* node = getViewProviderPtr()->getAnnotation(); - PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoSeparator *", node, 1); + auto node = getViewProviderPtr()->getAnnotation(); + PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoSeparator", node, 1); node->ref(); return Py::Object(Ptr, true); } @@ -291,8 +445,8 @@ void ViewProviderPy::setAnnotation(Py::Object) Py::Object ViewProviderPy::getRootNode(void) const { try { - SoNode* node = getViewProviderPtr()->getRoot(); - PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","SoSeparator *", node, 1); + SoSeparator* node = getViewProviderPtr()->getRoot(); + PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","_p_SoSeparator", node, 1); node->ref(); return Py::Object(Ptr, true); } @@ -306,6 +460,24 @@ void ViewProviderPy::setRootNode(Py::Object) } +Py::Object ViewProviderPy::getSwitchNode(void) const +{ + try { + SoSwitch* node = getViewProviderPtr()->getModeSwitch(); + PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","_p_SoSwitch", node, 1); + node->ref(); + return Py::Object(Ptr, true); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + +void ViewProviderPy::setSwitchNode(Py::Object) +{ + +} + static char * buffer; static size_t buffer_size = 0; @@ -355,3 +527,30 @@ Py::Object ViewProviderPy::getIcon(void) const return wrap.fromQIcon(new QIcon(icon)); #endif } + +Py::Int ViewProviderPy::getDefaultMode(void) const +{ + return Py::Int((long)getViewProviderPtr()->getDefaultMode()); +} + +void ViewProviderPy::setDefaultMode(Py::Int arg) +{ + return getViewProviderPtr()->setDefaultMode(arg); +} + +Py::Boolean ViewProviderPy::getCanRemoveChildrenFromRoot() const +{ + return Py::Boolean(getViewProviderPtr()->canRemoveChildrenFromRoot()); +} + +Py::Boolean ViewProviderPy::getLinkVisibility() const { + return Py::Boolean(getViewProviderPtr()->isLinkVisible()); +} + +void ViewProviderPy::setLinkVisibility(Py::Boolean arg) { + getViewProviderPtr()->setLinkVisible(arg); +} + +Py::String ViewProviderPy::getDropPrefix() const { + return Py::String(getViewProviderPtr()->getDropPrefix()); +}