Gui: [skip ci] add method to Python binding of ViewProviderExtension to ignore overlay icon
This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#endif
|
||||
|
||||
#include "ViewProviderExtension.h"
|
||||
//#include "ViewProviderExtensionPy.h"
|
||||
#include "ViewProviderExtensionPy.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
|
||||
//update data of extended opject
|
||||
virtual void extensionUpdateData(const App::Property*);
|
||||
virtual PyObject* getExtensionPyObject();
|
||||
|
||||
void setIgnoreOverlayIcon(bool on) {
|
||||
m_ignoreOverlayIcon = on;
|
||||
|
||||
28
src/Gui/ViewProviderExtensionPy.xml
Normal file
28
src/Gui/ViewProviderExtensionPy.xml
Normal file
@@ -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
src/Gui/ViewProviderExtensionPyImp.cpp
Normal file
91
src/Gui/ViewProviderExtensionPyImp.cpp
Normal file
@@ -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;
|
||||
}
|
||||
@@ -37,6 +37,7 @@ class ViewProviderTube:
|
||||
''' 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 '''
|
||||
|
||||
Reference in New Issue
Block a user