From 1ee6dcf75e73ad9b63569b98a87e9d7d8b115bcc Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 4 Mar 2017 20:46:55 +0300 Subject: [PATCH] PartPesign: Py: expose some methods of ViewProvider * setBodyMode(bool) * makeTemporaryVisible(bool) --- src/Mod/PartDesign/Gui/CMakeLists.txt | 12 ++++ src/Mod/PartDesign/Gui/ViewProvider.cpp | 9 +++ src/Mod/PartDesign/Gui/ViewProvider.h | 2 + src/Mod/PartDesign/Gui/ViewProviderPy.xml | 33 +++++++++ src/Mod/PartDesign/Gui/ViewProviderPyImp.cpp | 74 ++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 src/Mod/PartDesign/Gui/ViewProviderPy.xml create mode 100644 src/Mod/PartDesign/Gui/ViewProviderPyImp.cpp diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index af384cc76..03b37fa31 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -18,6 +18,9 @@ include_directories( ) link_directories(${OCC_LIBRARY_DIR}) +generate_from_xml(ViewProviderPy) + + set(PartDesignGui_LIBS PartDesign SketcherGui @@ -252,6 +255,14 @@ SET(PartDesignGuiModule_SRCS ) SOURCE_GROUP("Module" FILES ${PartDesignGuiModule_SRCS}) + +SET(Python_SRCS + ViewProviderPy.xml + ViewProviderPyImp.cpp +) +SOURCE_GROUP("Python" FILES ${Python_SRCS}) + + SET(PartDesignGui_Scripts InitGui.py TestPartDesignGui.py @@ -263,6 +274,7 @@ SET(PartDesignGui_SRCS ${PartDesignGuiModule_SRCS} ${PartDesignGuiTaskDlgs_SRCS} ${PartDesignGuiViewProvider_SRCS} + ${Python_SRCS} ) add_library(PartDesignGui SHARED ${PartDesignGui_SRCS}) diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index 641954e6b..166a51707 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -40,6 +40,7 @@ #include "TaskFeatureParameters.h" #include "ViewProvider.h" +#include "ViewProviderPy.h" using namespace PartDesignGui; @@ -252,6 +253,14 @@ void ViewProvider::makeTemporaryVisible(bool onoff) Gui::ViewProvider::hide(); } +PyObject* ViewProvider::getPyObject() +{ + if (!pyViewObject) + pyViewObject = new ViewProviderPy(this); + pyViewObject->IncRef(); + return pyViewObject; +} + namespace Gui { /// @cond DOXERR diff --git a/src/Mod/PartDesign/Gui/ViewProvider.h b/src/Mod/PartDesign/Gui/ViewProvider.h index 7a128402e..6abf52067 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.h +++ b/src/Mod/PartDesign/Gui/ViewProvider.h @@ -60,6 +60,8 @@ public: //document and properties. void makeTemporaryVisible(bool); + virtual PyObject* getPyObject(void); + protected: virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); diff --git a/src/Mod/PartDesign/Gui/ViewProviderPy.xml b/src/Mod/PartDesign/Gui/ViewProviderPy.xml new file mode 100644 index 000000000..ff5b2104f --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderPy.xml @@ -0,0 +1,33 @@ + + + + + + This is the father of all PartDesign ViewProvider classes + + + +setBodyMode(bool): body mode means that the object is part of a body +and that the body is used to set the visual properties, not the features. Hence +setting body mode to true will hide most viewprovider properties. + + + + +makeTemporaryVisible(bool): makes this viewprovider visible in the +scene graph without changing any properties, not the visibility one and also not +the display mode. This can be used to show the shape of this viewprovider from +other viewproviders without doing anything to the document and properties. + + + + + diff --git a/src/Mod/PartDesign/Gui/ViewProviderPyImp.cpp b/src/Mod/PartDesign/Gui/ViewProviderPyImp.cpp new file mode 100644 index 000000000..4c31c59cc --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderPyImp.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2017 Victor Titov (DeepSOIC) * + * * + * 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" + +#include "ViewProvider.h" + +// inclusion of the generated files (generated out of ViewProviderPy.xml) +#include "ViewProviderPy.h" +#include "ViewProviderPy.cpp" + +using namespace PartDesignGui; + +// returns a string which represent the object e.g. when printed in python +std::string ViewProviderPy::representation(void) const +{ + return std::string(""); +} + +PyObject *ViewProviderPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ViewProviderPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} + +PyObject* ViewProviderPy::setBodyMode(PyObject* args) +{ + PartDesignGui::ViewProvider* base = getViewProviderPtr(); + + PyObject* b_mode; + if(PyArg_ParseTuple(args, "O!", &PyBool_Type, &b_mode)){ + base->setBodyMode(PyObject_IsTrue(b_mode)); + return Py::new_reference_to(Py::None()); + }; + + return nullptr; //error +} + +PyObject* ViewProviderPy::makeTemporaryVisible(PyObject* args) +{ + PartDesignGui::ViewProvider* base = getViewProviderPtr(); + + PyObject* b_vis; + if(PyArg_ParseTuple(args, "O!", &PyBool_Type, &b_vis)){ + base->makeTemporaryVisible(PyObject_IsTrue(b_vis)); + return Py::new_reference_to(Py::None()); + }; + + return nullptr; //error +}