Skip to content

Commit

Permalink
Gui: [skip ci] add method to Python binding of ViewProviderExtension …
Browse files Browse the repository at this point in the history
…to ignore overlay icon
  • Loading branch information
wwmayer committed Nov 22, 2020
1 parent d0e5a28 commit 5a9da45
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -224,6 +224,7 @@ generate_from_xml(DocumentPy)
generate_from_xml(PythonWorkbenchPy)
generate_from_xml(ViewProviderPy)
generate_from_xml(ViewProviderDocumentObjectPy)
generate_from_xml(ViewProviderExtensionPy)
generate_from_xml(WorkbenchPy)
generate_from_xml(SelectionObjectPy)
generate_from_xml(LinkViewPy)
Expand All @@ -237,6 +238,7 @@ generate_from_py(FreeCADGuiInit GuiInitScript.h)
SET(FreeCADGui_XML_SRCS
ViewProviderDocumentObjectPy.xml
ViewProviderPy.xml
ViewProviderExtensionPy.xml
PythonWorkbenchPy.xml
WorkbenchPy.xml
SelectionObjectPy.xml
Expand Down Expand Up @@ -1004,6 +1006,7 @@ SOURCE_GROUP("Quarter" FILES ${Quarter_SRCS})
SET(Viewprovider_CPP_SRCS
ViewProvider.cpp
ViewProviderExtension.cpp
ViewProviderExtensionPyImp.cpp
ViewProviderGroupExtension.cpp
ViewProviderGeoFeatureGroupExtension.cpp
ViewProviderOriginGroupExtension.cpp
Expand Down
12 changes: 11 additions & 1 deletion src/Gui/ViewProviderExtension.cpp
Expand Up @@ -29,7 +29,7 @@
#endif

#include "ViewProviderExtension.h"
//#include "ViewProviderExtensionPy.h"
#include "ViewProviderExtensionPy.h"

using namespace Gui;

Expand Down Expand Up @@ -61,6 +61,16 @@ void ViewProviderExtension::extensionUpdateData(const App::Property*) {

}

PyObject* ViewProviderExtension::getExtensionPyObject(void) {

if (ExtensionPythonObject.is(Py::_None())){
// ref counter is set to 1
auto ext = new ViewProviderExtensionPy(this);
ExtensionPythonObject = Py::asObject(ext);
}
return Py::new_reference_to(ExtensionPythonObject);
}

namespace Gui {
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderExtensionPython, Gui::ViewProviderExtension)

Expand Down
1 change: 1 addition & 0 deletions src/Gui/ViewProviderExtension.h
Expand Up @@ -93,6 +93,7 @@ class GuiExport ViewProviderExtension : public App::Extension

//update data of extended opject
virtual void extensionUpdateData(const App::Property*);
virtual PyObject* getExtensionPyObject();

void setIgnoreOverlayIcon(bool on) {
m_ignoreOverlayIcon = on;
Expand Down
28 changes: 28 additions & 0 deletions src/Gui/ViewProviderExtensionPy.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ExtensionPy"
Name="ViewProviderExtensionPy"
TwinPointer="ViewProviderExtension"
Twin="ViewProviderExtension"
Include="Gui/ViewProviderExtension.h"
Namespace="Gui"
FatherInclude="App/ExtensionPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer[at]users.sourceforge.net" />
<UserDocu>Base class for all view provider extensions</UserDocu>
</Documentation>
<Methode Name="setIgnoreOverlayIcon">
<Documentation>
<UserDocu>Ignore the overlay icon of an extension</UserDocu>
</Documentation>
</Methode>
<Methode Name="ignoreOverlayIcon" Const="true">
<Documentation>
<UserDocu>Ignore the overlay icon of an extension</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>
91 changes: 91 additions & 0 deletions src/Gui/ViewProviderExtensionPyImp.cpp
@@ -0,0 +1,91 @@
/***************************************************************************
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
# include <sstream>
#endif

// inclution of the generated files (generated out of PropertyContainerPy.xml)
#include "ViewProviderExtensionPy.h"
#include "ViewProviderExtensionPy.cpp"

using namespace Gui;

// returns a string which represent the object e.g. when printed in python
std::string ViewProviderExtensionPy::representation(void) const
{
return std::string("<view provider extension>");
}

PyObject* ViewProviderExtensionPy::setIgnoreOverlayIcon(PyObject *args)
{
PyObject* ignore;
const char* name = nullptr;
if (!PyArg_ParseTuple(args, "O!s", &PyBool_Type, &ignore, &name))
return nullptr;

ViewProviderExtension* ext = getViewProviderExtensionPtr();
if (name) {
Base::Type type = Base::Type::fromName(name);
ext = dynamic_cast<ViewProviderExtension*>(ext->getExtendedContainer()->getExtension(type, true, true));
if (!ext) {
PyErr_SetString(PyExc_NameError, "no such extension");
return nullptr;
}
}

ext->setIgnoreOverlayIcon(PyObject_IsTrue(ignore) ? true : false);
Py_Return;
}

PyObject* ViewProviderExtensionPy::ignoreOverlayIcon(PyObject *args)
{
const char* name = nullptr;
if (!PyArg_ParseTuple(args, "s", &name))
return nullptr;

ViewProviderExtension* ext = getViewProviderExtensionPtr();
if (name) {
Base::Type type = Base::Type::fromName(name);
ext = dynamic_cast<ViewProviderExtension*>(ext->getExtendedContainer()->getExtension(type, true, true));
if (!ext) {
PyErr_SetString(PyExc_NameError, "no such extension");
return nullptr;
}
}

bool ignore = ext->ignoreOverlayIcon();
return Py_BuildValue("O", (ignore ? Py_True : Py_False));
}

PyObject *ViewProviderExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}

int ViewProviderExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject * /*obj*/)
{
return 0;
}
1 change: 1 addition & 0 deletions src/Mod/Part/BasicShapes/ViewProviderShapes.py
Expand Up @@ -37,6 +37,7 @@ def __init__(self, obj):
''' Set this object to the proxy object of the actual view provider '''
obj.Proxy = self
obj.addExtension("PartGui::ViewProviderAttachExtensionPython", self)
obj.setIgnoreOverlayIcon(True, "PartGui::ViewProviderAttachExtensionPython")

def attach(self, obj):
''' Setup the scene sub-graph of the view provider, this method is mandatory '''
Expand Down

0 comments on commit 5a9da45

Please sign in to comment.