From 16e950ed7b177d8073585641d22d1166f41777fa Mon Sep 17 00:00:00 2001 From: marioalexis Date: Sun, 8 May 2022 02:38:07 -0300 Subject: [PATCH 1/9] Gui: Clean up code in ViewProviderPyImp.cpp --- src/Gui/ViewProviderPy.xml | 4 +- src/Gui/ViewProviderPyImp.cpp | 201 ++++++++++++++++++++-------------- 2 files changed, 118 insertions(+), 87 deletions(-) diff --git a/src/Gui/ViewProviderPy.xml b/src/Gui/ViewProviderPy.xml index 24261bb863..72ad9c3f5d 100644 --- a/src/Gui/ViewProviderPy.xml +++ b/src/Gui/ViewProviderPy.xml @@ -69,14 +69,14 @@ dragObject(obj) - + check whether the child object can be added by dropping canDropObject(obj=None,owner=None,subname=None) - + add a child object by dropping dropObject(obj,owner=None,subname=None) diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index a7c94f3869..757ae7aeb5 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -36,7 +36,7 @@ #include "PythonWrapper.h" #include "SoFCDB.h" -// inclusion of the generated files (generated out of ViewProviderPy2.xml) +// inclusion of the generated files (generated out of ViewProviderPy.xml) #include #include #include @@ -128,88 +128,97 @@ PyObject* ViewProviderPy::show(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { getViewProviderPtr()->show(); Py_Return; - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::hide(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { getViewProviderPtr()->hide(); Py_Return; - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::isVisible(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { - return Py_BuildValue("O", (getViewProviderPtr()->isShow() ? Py_True : Py_False)); - } PY_CATCH; + return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->isShow())); + } + PY_CATCH; } PyObject* ViewProviderPy::canDragObject(PyObject *args) { - PyObject *obj = Py_None; - if (!PyArg_ParseTuple(args, "|O", &obj)) + PyObject *obj = nullptr; + if (!PyArg_ParseTuple(args, "|O!", &App::DocumentObjectPy::Type, &obj)) return nullptr; + PY_TRY { bool ret; - if(obj == Py_None) + if (!obj) ret = getViewProviderPtr()->canDragObjects(); - else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) { - PyErr_SetString(PyExc_TypeError, "exepcting a type of DocumentObject"); - return nullptr; - }else + else ret = getViewProviderPtr()->canDragObject( static_cast(obj)->getDocumentObjectPtr()); + return Py::new_reference_to(Py::Boolean(ret)); - } PY_CATCH; + } + PY_CATCH; } -PyObject* ViewProviderPy::canDropObject(PyObject *args) +PyObject* ViewProviderPy::canDropObject(PyObject *args, PyObject *kw) { - PyObject *obj = Py_None; - PyObject *owner = Py_None; - PyObject *pyElements = Py_None; + PyObject *obj = nullptr; + PyObject *owner = nullptr; + PyObject *pyElements = nullptr; const char *subname = nullptr; - if (!PyArg_ParseTuple(args, "|OOsO", &obj,&owner,&subname,&pyElements)) + static char* kwlist[] = {"obj","owner","subname","elem",nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "|O!O!sO", kwlist, + &App::DocumentObjectPy::Type,&obj, &App::DocumentObjectPy::Type, &owner, + &subname, &pyElements)) return nullptr; + 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"); + App::DocumentObject* pcObject; + App::DocumentObject* pcOwner = nullptr; + App::PropertyStringList elements; + if (!obj && (owner || pyElements || subname)) { + PyErr_SetString(PyExc_ValueError, "'obj' must be specified if 'owner', 'subname' or 'elem' is given"); return nullptr; } - auto pcObject = static_cast(obj)->getDocumentObjectPtr(); - App::DocumentObject *pcOwner = nullptr; - if(owner!=Py_None) { - if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) { - PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject"); - return nullptr; - } - pcOwner = static_cast(owner)->getDocumentObjectPtr(); + if(!obj) { + ret = getViewProviderPtr()->canDropObjects(); + return Py::new_reference_to(Py::Boolean(ret)); } - App::PropertyStringList elements; - if(pyElements!=Py_None) { + pcObject = static_cast(obj)->getDocumentObjectPtr(); + if (owner) + pcOwner = static_cast(owner)->getDocumentObjectPtr(); + if (pyElements) { try { elements.setPyObject(pyElements); } catch(...) { - PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings"); + PyErr_SetString(PyExc_TypeError, "'elem' must be a sequence of strings"); return nullptr; } } ret = getViewProviderPtr()->canDropObjectEx(pcObject,pcOwner,subname,elements.getValues()); return Py::new_reference_to(Py::Boolean(ret)); - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::canDragAndDropObject(PyObject *args) @@ -217,44 +226,46 @@ PyObject* ViewProviderPy::canDragAndDropObject(PyObject *args) PyObject *obj; if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj)) return nullptr; + PY_TRY { bool ret = getViewProviderPtr()->canDragAndDropObject( static_cast(obj)->getDocumentObjectPtr()); return Py::new_reference_to(Py::Boolean(ret)); - } PY_CATCH; + } + PY_CATCH; } -PyObject* ViewProviderPy::dropObject(PyObject *args) +PyObject* ViewProviderPy::dropObject(PyObject *args, PyObject *kw) { PyObject *obj; - PyObject *owner = Py_None; - PyObject *pyElements = Py_None; + PyObject *owner = nullptr; + PyObject *pyElements = nullptr; const char *subname = nullptr; - if (!PyArg_ParseTuple(args, "O!|OsO", &App::DocumentObjectPy::Type,&obj,&owner,&subname,&pyElements)) + static char* kwlist[] = {"obj","owner","subname","elem",nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|O!sO", kwlist, + &App::DocumentObjectPy::Type,&obj, &App::DocumentObjectPy::Type, &owner, + &subname, &pyElements)) return nullptr; + PY_TRY { + auto pcObject = static_cast(obj)->getDocumentObjectPtr(); App::DocumentObject *pcOwner = nullptr; - if(owner!=Py_None) { - if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) { - PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject"); - return nullptr; - } - pcOwner = static_cast(owner)->getDocumentObjectPtr(); - } App::PropertyStringList elements; - if(pyElements!=Py_None) { + if (owner) + pcOwner = static_cast(owner)->getDocumentObjectPtr(); + if (pyElements) { try { elements.setPyObject(pyElements); - }catch(...) { - PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings"); + } + catch(...) { + PyErr_SetString(PyExc_TypeError, "'elem' must be a sequence of strings"); return nullptr; } } - auto ret = getViewProviderPtr()->dropObjectEx( - static_cast(obj)->getDocumentObjectPtr(), - pcOwner, subname,elements.getValues()); + auto ret = getViewProviderPtr()->dropObjectEx(pcObject,pcOwner, subname,elements.getValues()); return Py::new_reference_to(Py::String(ret)); - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::dragObject(PyObject *args) @@ -262,11 +273,13 @@ PyObject* ViewProviderPy::dragObject(PyObject *args) PyObject *obj; if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj)) return nullptr; + PY_TRY { getViewProviderPtr()->dragObject( static_cast(obj)->getDocumentObjectPtr()); Py_Return; - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::replaceObject(PyObject *args) @@ -277,12 +290,14 @@ PyObject* ViewProviderPy::replaceObject(PyObject *args) &App::DocumentObjectPy::Type,&oldObj, &App::DocumentObjectPy::Type,&newObj)) return nullptr; + PY_TRY { int ret = getViewProviderPtr()->replaceObject( static_cast(oldObj)->getDocumentObjectPtr(), static_cast(newObj)->getDocumentObjectPtr()); return Py::new_reference_to(Py::Int(ret)); - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::addDisplayMode(PyObject * args) @@ -305,13 +320,15 @@ PyObject* ViewProviderPy::addDisplayMode(PyObject * args) SoNode* node = reinterpret_cast(ptr); getViewProviderPtr()->addDisplayMaskMode(node,mode); Py_Return; - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::listDisplayModes(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { std::vector modes = getViewProviderPtr()->getDisplayModes(); PyObject* pyList = PyList_New(modes.size()); @@ -323,17 +340,20 @@ PyObject* ViewProviderPy::listDisplayModes(PyObject *args) } return pyList; - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::toString(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { std::string buffer = getViewProviderPtr()->toString(); return Py::new_reference_to(Py::String(buffer)); - } PY_CATCH; + } + PY_CATCH; } PyObject* ViewProviderPy::setTransformation(PyObject *args) @@ -346,13 +366,14 @@ PyObject* ViewProviderPy::setTransformation(PyObject *args) Py_Return; } PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!",&(Base::PlacementPy::Type),&p)) { Base::PlacementPy* plc = static_cast(p); getViewProviderPtr()->setTransformation(plc->getPlacementPtr()->toMatrix()); Py_Return; } - PyErr_SetString(PyExc_TypeError, "Either set matrix or placement to set transformation"); + PyErr_SetString(PyExc_TypeError, "The transformation must be a Base.Matrix or a Base.Placement"); return nullptr; } @@ -376,7 +397,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) { PyObject *value = Py_None; PyObject *clear = Py_False; - if (!PyArg_ParseTuple(args, "|OO",&value,&clear)) + if (!PyArg_ParseTuple(args, "|OO!",&value,&PyBool_Type,&clear)) return nullptr; std::vector values; @@ -392,12 +413,13 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) } values.resize(nSize); for (Py_ssize_t i = 0; i < nSize; ++i) { - if(value) item = PySequence_GetItem(value, i); + if(value) + item = PySequence_GetItem(value, i); if (PyUnicode_Check(item)) { values[i] = PyUnicode_AsUTF8(item); } else { - std::string error = std::string("type must be str or unicode"); + std::string error = std::string("type must be str"); error += " not, "; error += item->ob_type->tp_name; throw Base::TypeError(error); @@ -405,7 +427,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) } } - Py::Int ret(getViewProviderPtr()->partialRender(values,PyObject_IsTrue(clear))); + Py::Int ret(getViewProviderPtr()->partialRender(values, PyObject_IsTrue(clear) ? true : false)); return Py::new_reference_to(ret); } @@ -453,14 +475,17 @@ PyObject* ViewProviderPy::getElementPicked(PyObject* args) PyObject *obj; if (!PyArg_ParseTuple(args, "O",&obj)) return nullptr; + void *ptr = nullptr; Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0); SoPickedPoint *pp = reinterpret_cast(ptr); if(!pp) - throw Base::TypeError("type must be of coin.SoPickedPoint"); + throw Base::TypeError("type must be coin.SoPickedPoint"); + std::string name; if(!getViewProviderPtr()->getElementPicked(pp,name)) Py_Return; + return Py::new_reference_to(Py::String(name)); } @@ -469,22 +494,21 @@ PyObject* ViewProviderPy::getDetailPath(PyObject* args) const char *sub; PyObject *path; PyObject *append = Py_True; - if (!PyArg_ParseTuple(args, "sO|O",&sub,&path,&append)) + if (!PyArg_ParseTuple(args, "sO|O!",&sub,&path,&PyBool_Type,&append)) return nullptr; + void *ptr = nullptr; Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0); SoPath *pPath = reinterpret_cast(ptr); if(!pPath) - throw Base::TypeError("type must be of coin.SoPath"); + throw Base::TypeError("'path' must be a coin.SoPath"); SoDetail *det = nullptr; - if(!getViewProviderPtr()->getDetailPath( - sub,static_cast(pPath),PyObject_IsTrue(append),det)) - { - if(det) delete det; + if(!getViewProviderPtr()->getDetailPath(sub,static_cast(pPath),append,det)) { + delete det; Py_Return; } if(!det) - return Py::new_reference_to(Py::True()); + Py_Return; return Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoDetail", (void*)det, 0); } @@ -492,6 +516,7 @@ PyObject *ViewProviderPy::signalChangeIcon(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; + getViewProviderPtr()->signalChangeIcon(); Py_Return; } @@ -500,24 +525,27 @@ PyObject *ViewProviderPy::getBoundingBox(PyObject *args) { PyObject *transform=Py_True; PyObject *pyView = nullptr; const char *subname = nullptr; - if (!PyArg_ParseTuple(args, "|sOO!", &subname,&transform,View3DInventorPy::type_object(),&pyView)) + if (!PyArg_ParseTuple(args, "|sO!O!", &subname,&PyBool_Type,&transform,View3DInventorPy::type_object(),&pyView)) return nullptr; + PY_TRY { View3DInventor *view = nullptr; if(pyView) view = static_cast(pyView)->getView3DIventorPtr(); auto bbox = getViewProviderPtr()->getBoundingBox(subname,PyObject_IsTrue(transform),view); - Py::Object ret(new Base::BoundBoxPy(new Base::BoundBox3d(bbox))); - return Py::new_reference_to(ret); - } PY_CATCH; + return new Base::BoundBoxPy(new Base::BoundBox3d(bbox)); + } + PY_CATCH; } PyObject *ViewProviderPy::doubleClicked(PyObject *args) { if(!PyArg_ParseTuple(args, "")) return nullptr; + PY_TRY { return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->doubleClicked())); - }PY_CATCH; + } + PY_CATCH; } PyObject *ViewProviderPy::getCustomAttributes(const char* attr) const @@ -551,7 +579,7 @@ int ViewProviderPy::setCustomAttributes(const char* attr, PyObject* value) } } -Py::Object ViewProviderPy::getAnnotation(void) const +Py::Object ViewProviderPy::getAnnotation() const { try { auto node = getViewProviderPtr()->getAnnotation(); @@ -569,7 +597,7 @@ void ViewProviderPy::setAnnotation(Py::Object) } -Py::Object ViewProviderPy::getRootNode(void) const +Py::Object ViewProviderPy::getRootNode() const { try { SoSeparator* node = getViewProviderPtr()->getRoot(); @@ -587,7 +615,7 @@ void ViewProviderPy::setRootNode(Py::Object) } -Py::Object ViewProviderPy::getSwitchNode(void) const +Py::Object ViewProviderPy::getSwitchNode() const { try { SoSwitch* node = getViewProviderPtr()->getModeSwitch(); @@ -605,13 +633,13 @@ void ViewProviderPy::setSwitchNode(Py::Object) } -Py::String ViewProviderPy::getIV(void) const +Py::String ViewProviderPy::getIV() const { std::string buf = Gui::SoFCDB::writeNodesToString(getViewProviderPtr()->getRoot()); return Py::String(buf); } -Py::Object ViewProviderPy::getIcon(void) const +Py::Object ViewProviderPy::getIcon() const { #if 0 QByteArray ba; @@ -628,7 +656,7 @@ Py::Object ViewProviderPy::getIcon(void) const #endif } -Py::Int ViewProviderPy::getDefaultMode(void) const +Py::Int ViewProviderPy::getDefaultMode() const { return Py::Int((long)getViewProviderPtr()->getDefaultMode()); } @@ -643,14 +671,17 @@ Py::Boolean ViewProviderPy::getCanRemoveChildrenFromRoot() const return Py::Boolean(getViewProviderPtr()->canRemoveChildrenFromRoot()); } -Py::Boolean ViewProviderPy::getLinkVisibility() const { +Py::Boolean ViewProviderPy::getLinkVisibility() const +{ return Py::Boolean(getViewProviderPtr()->isLinkVisible()); } -void ViewProviderPy::setLinkVisibility(Py::Boolean arg) { +void ViewProviderPy::setLinkVisibility(Py::Boolean arg) +{ getViewProviderPtr()->setLinkVisible(arg); } -Py::String ViewProviderPy::getDropPrefix() const { +Py::String ViewProviderPy::getDropPrefix() const +{ return Py::String(getViewProviderPtr()->getDropPrefix()); } From a1d31ebd9e28407b2f32cbff99c1b1dc403c6498 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Sun, 8 May 2022 02:39:24 -0300 Subject: [PATCH 2/9] Gui: Improve docstrings in ViewProviderPy.xml --- src/Gui/ViewProviderPy.xml | 191 ++++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 90 deletions(-) diff --git a/src/Gui/ViewProviderPy.xml b/src/Gui/ViewProviderPy.xml index 72ad9c3f5d..58c7558417 100644 --- a/src/Gui/ViewProviderPy.xml +++ b/src/Gui/ViewProviderPy.xml @@ -15,213 +15,224 @@ - Add a generic property. -addProperty(string, string) --- -The first argument specifies the type, the second the name of the property. - + addProperty(type, name, group, doc, attr=0, ro=False, hd=False) -> ViewProvider\n +Add a generic property.\n +type : str\n Property type. +name : str\n Property name. Optional. +group : str\n Property group. Optional. +attr : int\n Property attributes. +ro : bool\n Read only property. +hd : bool\n Hidden property. - Remove a generic property. -removeProperty(string) --- -Note, you can only remove user-defined properties, not built-in ones. - + removeProperty(name) -> bool\n +Remove a generic property. +Only user-defined properties can be removed, not built-in ones.\n +name : str\n Property name. - A list of supported property types - + supportedProperties() -> list\n +A list of supported property types. - Show the object - + show() -> None\n +Show the object. - Hide the object - + show() -> None\n +Hide the object. - Check if the object is visible - + isVisible() -> bool\n +Check if the object is visible. - check whether the child object can be removed by dragging -canDragObject(obj=None) - + canDragObject(obj) -> bool\n +Check whether the child object can be removed by dragging. +If 'obj' is not given, check without filter by any particular object.\n +obj : App.DocumentObject\n Object to be dragged. Optional. - remove a child object by dropping -dragObject(obj) - + dragObject(obj) -> None\n +Remove a child object by dropping.\n +obj : App.DocumentObject\n Object to be dragged. - check whether the child object can be added by dropping -canDropObject(obj=None,owner=None,subname=None) - + canDropObject(obj, owner, subname, elem) -> bool\n +Check whether the child object can be added by dropping. +If 'obj' is not given, check without filter by any particular object.\n +obj : App.DocumentObject\n Object to be dropped. Optional. +owner : App.DocumentObject\n Parent object of the dropping object. Optional. +subname : str\n Subname reference to the dropping object. Optional. +elem : sequence of str\n Non-objects subelements selected when the object is + being dropped. Optional. - add a child object by dropping -dropObject(obj,owner=None,subname=None) + dropObject(obj, owner, subname, elem) -> str\n +Add a child object by dropping.\n +obj : App.DocumentObject\n Object to be dropped. +owner : App.DocumentObject\n Parent object of the dropping object. Optional. +subname : str\n Subname reference to the dropping object. Optional. +elem : sequence of str\n Non-objects subelements selected when the object is + being dropped. Optional. - Check whether the child object can be removed from other parent and added here by drag and drop -canDragAndDropObject(obj) - + canDragAndDropObject(obj) -> bool\n +Check whether the child object can be removed from +other parent and added here by drag and drop.\n +obj : App.DocumentObject\n Object to be dragged and dropped. - replace a child object -replaceObject(oldObj, newObj) -> Int --- -Returns 1 if succeeded, 0 if not found, -1 if not supported - + replaceObject(oldObj, newObj) -> int\n +Replace a child object. +Returns 1 if succeeded, 0 if not found, -1 if not supported.\n +oldObj : App.DocumentObject\n Old object. +newObj : App.DocumentObject\n New object. - Trigger double clicking the corresponding tree item of this view object - + doubleClicked() -> bool\n +Trigger double clicking the corresponding tree item of this view object. - Add a new display mode to the view provider - + addDisplayMode(obj, mode) -> None\n +Add a new display mode to the view provider.\n +obj : coin.SoNode\n Display mode. +mode : str\n Name of the display mode. - Show a list of all display modes - + listDisplayModes() -> list\n +Show a list of all display modes. - Return a string representation of the Inventor node - + toString() -> str\n +Return a string representation of the Inventor node. - Set a transformation on the Inventor node - + setTransformation(trans) -> None\n +Set a transformation on the Inventor node.\n +trans : Base.Placement, Base.Matrix - Returns list of objects that are to be grouped in tree under this object. - + claimChildren() -> list\n +Returns list of objects that are to be grouped in tree under this object. - render only part of the object -partialRender(sub=None,clear=False) --- -sub: string or list of string refer to the subelement. If it is None then reset the partial rendering. -clear: true to add, or false to remove the subelement(s) for rendering. - + partialRender(sub=None, clear=False) -> int\n +Render only part of the object.\n +sub: None, str, sequence of str\n Refer to the subelement. If it is None then reset the partial rendering. +clear: bool\n True to add, or False to remove the subelement(s) for rendering. - -getElementColors(elementName=None) -> dict(elementName:color) - + getElementColors(elementName) -> dict\n +Get a dictionary of the form {elementName : (r,g,b,a)}. +If no element name is given a dictionary with all the elements is returned.\n +elementName : str\n Name of the element. Optional. - -setElementColors(colors): set element colors --- -colors: color dictionary of type elementName:(r,g,b,a) - + setElementColors(colors) -> None\n +Set element colors.\n +colors: dict\n Color dictionary of the form {elementName:(r,g,b,a)}. - return the picked subelement -getElementPicked(pickPoint) - + getElementPicked(pickPoint) -> str\n +Return the picked subelement.\n +pickPoint : coin.SoPickedPoint - return Coin detail and path of an subelement -getDetailPath(subname,path,append=True) --- -subelement: dot separated string reference to the sub element -pPath: output coin path leading to the returned element detail -append: If true, path will be first appended with the root node and the mode -switch node of this view provider. - + getDetailPath(subelement, path, append=True) -> coin.SoDetail or None\n +Return Coin detail and path of an subelement.\n +subname: str\n Dot separated string reference to the sub element. +pPath: coin.SoPath\n Output coin path leading to the returned element detail. +append: bool\n If True, path will be first appended with the root node and the mode + switch node of this view provider. - Trigger icon changed signal + signalChangeIcon() -> None\n +Trigger icon changed signal. - obtain the bounding box of this view object -getBoundingBox(subname=None, transform=True, view=None) --- -subname: the optional subname referring a sub-object -transform: whether to apply the transformation matrix of this view provider -view: the MDIView, default to active view - + getBoundingBox(subName, transform=True, view) -> Base.BoundBox\n +Obtain the bounding box of this view object.\n +subName : str\n Name referring a sub-object. Optional. +transform: bool\n Whether to apply the transformation matrix of this view provider. +view: View3DInventorPy\n Default to active view. Optional. - A pivy Separator to add a custom scenegraph to this ViewProvider + A pivy Separator to add a custom scenegraph to this ViewProvider. - The icon of this ViewProvider + The icon of this ViewProvider. - A pivy Separator with the root of this ViewProvider + A pivy Separator with the root of this ViewProvider. - A pivy SoSwitch for the display mode switch of this ViewProvider + A pivy SoSwitch for the display mode switch of this ViewProvider. - Get/Set the default display mode in turns of coin node index + Get/Set the default display mode in turns of coin node index. @@ -233,19 +244,19 @@ view: the MDIView, default to active view - Tells the tree view whether to remove the children item from root or not + Tells the tree view whether to remove the children item from root or not. - Get/set visibilities of all links to this view object + Get/set visibilities of all links to this view object. - Subname referecing the sub-object for holding dropped object + Subname referecing the sub-object for holding dropped object. From bd17a5cef42fb119569da94d072fe1a80bd54549 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 10 May 2022 14:00:12 +0200 Subject: [PATCH 3/9] Part: [skip ci] unit tests for PR #6850 --- src/Mod/Part/TestPartGui.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Mod/Part/TestPartGui.py b/src/Mod/Part/TestPartGui.py index 95c03cb8e8..7f6b09a906 100644 --- a/src/Mod/Part/TestPartGui.py +++ b/src/Mod/Part/TestPartGui.py @@ -41,3 +41,21 @@ import FreeCAD, FreeCADGui, os, sys, unittest, Part, PartGui # def tearDown(self): # #closing doc # FreeCAD.closeDocument("PartGuiTest") +class PartGuiViewProviderTestCases(unittest.TestCase): + def setUp(self): + self.Doc = FreeCAD.newDocument("PartGuiTest") + + def testCanDropObject(self): + # https://github.com/FreeCAD/FreeCAD/pull/6850 + box = self.Doc.addObject("Part::Box", "Box") + with self.assertRaises(TypeError): + box.ViewObject.canDragObject(None) + with self.assertRaises(TypeError): + box.ViewObject.canDropObject(None) + box.ViewObject.canDropObject() + with self.assertRaises(TypeError): + box.ViewObject.dropObject(box, None) + + def tearDown(self): + #closing doc + FreeCAD.closeDocument("PartGuiTest") From 1ef0f8001b42468ee2dd9f9868e93f6f8161750e Mon Sep 17 00:00:00 2001 From: luz paz Date: Tue, 10 May 2022 19:40:09 -0400 Subject: [PATCH 4/9] FEM: [Crowdin] fix typo in ElectrostaticPotential.ui tooltip Fixes https://github.com/FreeCAD/FreeCAD-translations/issues/143 --- src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui b/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui index df07d359ea..a611733367 100644 --- a/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui +++ b/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui @@ -156,7 +156,7 @@ - Counter of the body (or face) with a capcitance + Counter of the body (or face) with a capacitance 1 From 9e388ab0a84e41ddb18c4c2c1cede76e09ba00e9 Mon Sep 17 00:00:00 2001 From: Oliver Oxtoby Date: Wed, 11 May 2022 08:09:46 +0200 Subject: [PATCH 5/9] Base: Remove extraneous bracket from string representation of kinematic viscosity units in MKS schema --- src/Base/UnitsSchemaMKS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Base/UnitsSchemaMKS.cpp b/src/Base/UnitsSchemaMKS.cpp index 795b7afc54..7e51015fed 100644 --- a/src/Base/UnitsSchemaMKS.cpp +++ b/src/Base/UnitsSchemaMKS.cpp @@ -456,7 +456,7 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q factor = 0.001; } else if (unit == Unit::KinematicViscosity) { - unitString = QString::fromLatin1("m^2/s)"); + unitString = QString::fromLatin1("m^2/s"); factor = 1e6; } else { From 2a5c875c6fd61ad69a7ba14aadf37752d30c27b6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 11 May 2022 10:03:53 +0200 Subject: [PATCH 6/9] Part: LGTM: Multiplication result may overflow 'int' before it is converted to 'unsigned int'. --- src/Mod/Part/App/Geometry.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 3ad008d1f2..ae5ca04031 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -4369,8 +4369,10 @@ unsigned int GeomBezierSurface::getMemSize (void) const { unsigned int size = sizeof(Geom_BezierSurface); if (!mySurface.IsNull()) { - size += mySurface->NbUPoles() * mySurface->NbVPoles() * sizeof(gp_Pnt); - size += mySurface->NbUPoles() * mySurface->NbVPoles() * sizeof(Standard_Real); + unsigned int poles = mySurface->NbUPoles(); + poles *= mySurface->NbVPoles(); + size += poles * sizeof(gp_Pnt); + size += poles * sizeof(Standard_Real); } return size; } @@ -4448,8 +4450,10 @@ unsigned int GeomBSplineSurface::getMemSize (void) const size += mySurface->NbUKnots() * sizeof(Standard_Integer); size += mySurface->NbVKnots() * sizeof(Standard_Real); size += mySurface->NbVKnots() * sizeof(Standard_Integer); - size += mySurface->NbUPoles() * mySurface->NbVPoles() * sizeof(gp_Pnt); - size += mySurface->NbUPoles() * mySurface->NbVPoles() * sizeof(Standard_Real); + unsigned int poles = mySurface->NbUPoles(); + poles *= mySurface->NbVPoles(); + size += poles * sizeof(gp_Pnt); + size += poles * sizeof(Standard_Real); } return size; } From 22a00cffdaad836813c42014bca2a22a2e0ce53e Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Tue, 10 May 2022 14:16:58 -0400 Subject: [PATCH 7/9] [TD]fix extra undo on TaskCenterLine cancel --- src/Mod/TechDraw/Gui/TaskCenterLine.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp index d1f9a10cbc..03b29a6466 100644 --- a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp @@ -477,8 +477,6 @@ bool TaskCenterLine::accept() bool TaskCenterLine::reject() { - Gui::Command::abortCommand(); - Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); if (!doc) return false; From f6935580de43c55f89c023b468257bb6242a713b Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Tue, 10 May 2022 18:17:15 -0400 Subject: [PATCH 8/9] [TD]use PyArg_ParseTuple type check - replace PyObject_TypeCheck with O! in PyArg_ParseTuple --- src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp | 79 ++++++++++------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp index 85dd5f9acb..3e4b4d59a1 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp @@ -116,6 +116,7 @@ private: Base::Console().Error("%s\n", str.c_str()); throw Py::RuntimeError(str); } + return Py::None(); //only here to prevent warning re no return value } //! hook for FC Gui export function @@ -325,7 +326,7 @@ private: { PyObject *viewPy = nullptr; PyObject *qgiPy = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "OO", &viewPy, &qgiPy)) { + if (!PyArg_ParseTuple(args.ptr(), "O!O", &(TechDraw::DrawViewPy::Type), &viewPy, &qgiPy)) { throw Py::TypeError("expected (view, item)"); } @@ -333,28 +334,23 @@ private: App::DocumentObject* obj = nullptr; Gui::ViewProvider* vp = nullptr; QGIView* qgiv = nullptr; - if (PyObject_TypeCheck(viewPy, &(TechDraw::DrawViewPy::Type))) { - obj = static_cast(viewPy)->getDocumentObjectPtr(); - vp = Gui::Application::Instance->getViewProvider(obj); - if (vp) { - TechDrawGui::ViewProviderDrawingView* vpdv = - dynamic_cast(vp); - if (vpdv) { - qgiv = vpdv->getQView(); - if (qgiv != nullptr) { - Gui::PythonWrapper wrap; - if (!wrap.loadCoreModule() || - !wrap.loadGuiModule() || - !wrap.loadWidgetsModule()) { - PyErr_SetString(PyExc_RuntimeError, "Failed to load Python wrapper for Qt"); - return Py::None(); - } - QGraphicsItem* item = wrap.toQGraphicsItem(qgiPy); - if (item != nullptr) { - qgiv->addArbitraryItem(item); - } + obj = static_cast(viewPy)->getDocumentObjectPtr(); + vp = Gui::Application::Instance->getViewProvider(obj); + if (vp) { + TechDrawGui::ViewProviderDrawingView* vpdv = + dynamic_cast(vp); + if (vpdv) { + qgiv = vpdv->getQView(); + if (qgiv != nullptr) { + Gui::PythonWrapper wrap; + if (!wrap.loadGuiModule()) { + throw Py::RuntimeError("Failed to load Python wrapper for Qt::Gui"); + } + QGraphicsItem* item = wrap.toQGraphicsItem(qgiPy); + if (item != nullptr) { + qgiv->addArbitraryItem(item); } - } + } } } } @@ -373,7 +369,7 @@ private: { PyObject *viewPy = nullptr; PyObject *qgiPy = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "OO", &viewPy, &qgiPy)) { + if (!PyArg_ParseTuple(args.ptr(), "O!O", &(TechDraw::DrawViewPy::Type), &viewPy, &qgiPy)) { throw Py::TypeError("expected (view, item)"); } @@ -381,28 +377,23 @@ private: App::DocumentObject* obj = nullptr; Gui::ViewProvider* vp = nullptr; QGIView* qgiv = nullptr; - if (PyObject_TypeCheck(viewPy, &(TechDraw::DrawViewPy::Type))) { - obj = static_cast(viewPy)->getDocumentObjectPtr(); - vp = Gui::Application::Instance->getViewProvider(obj); - if (vp) { - TechDrawGui::ViewProviderDrawingView* vpdv = - dynamic_cast(vp); - if (vpdv) { - qgiv = vpdv->getQView(); - if (qgiv != nullptr) { - Gui::PythonWrapper wrap; - if (!wrap.loadCoreModule() || - !wrap.loadGuiModule() || - !wrap.loadWidgetsModule()) { - PyErr_SetString(PyExc_RuntimeError, "Failed to load Python wrapper for Qt"); - return Py::None(); - } - QGraphicsObject* item = wrap.toQGraphicsObject(qgiPy); - if (item != nullptr) { - qgiv->addArbitraryItem(item); - } + obj = static_cast(viewPy)->getDocumentObjectPtr(); + vp = Gui::Application::Instance->getViewProvider(obj); + if (vp) { + TechDrawGui::ViewProviderDrawingView* vpdv = + dynamic_cast(vp); + if (vpdv) { + qgiv = vpdv->getQView(); + if (qgiv != nullptr) { + Gui::PythonWrapper wrap; + if (!wrap.loadGuiModule()) { + throw Py::RuntimeError("Failed to load Python wrapper for Qt::Gui"); } - } + QGraphicsObject* item = wrap.toQGraphicsObject(qgiPy); + if (item != nullptr) { + qgiv->addArbitraryItem(item); + } + } } } } From 64cfee2a4ff8fcc003bbf4e1a4443a7504600ada Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Tue, 10 May 2022 19:06:54 -0400 Subject: [PATCH 9/9] [TD]allow more room for section name - section title label too short for translations of GD&T --- src/Mod/TechDraw/Gui/TaskCustomizeFormat.ui | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.ui b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.ui index 00ec0ec697..3e3e7daacd 100644 --- a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.ui +++ b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.ui @@ -7,7 +7,7 @@ 0 0 489 - 601 + 611 @@ -26,15 +26,15 @@ Format Symbols + + + + GD&T + + + - - - - GD&T - - - @@ -236,7 +236,7 @@ - + @@ -401,7 +401,7 @@ - + @@ -493,7 +493,7 @@ - + (Arc) Second @@ -513,7 +513,7 @@ - + @@ -678,7 +678,7 @@ - + Small phi @@ -698,7 +698,7 @@ - + @@ -712,7 +712,7 @@ - + Preview: @@ -726,7 +726,7 @@ - +