diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index ede57f85ba..dfb574aca2 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -254,6 +254,7 @@ generate_from_xml(LinkViewPy) generate_from_xml(ViewProviderLinkPy) generate_from_xml(AxisOriginPy) generate_from_xml(CommandPy) +generate_from_xml(NavigationStylePy) generate_from_py(FreeCADGuiInit GuiInitScript.h) @@ -887,6 +888,7 @@ SET(View3D_CPP_SRCS Multisample.cpp MouseSelection.cpp NavigationStyle.cpp + NavigationStylePyImp.cpp InventorNavigationStyle.cpp CADNavigationStyle.cpp RevitNavigationStyle.cpp @@ -920,6 +922,7 @@ SET(View3D_SRCS Multisample.h MouseSelection.h NavigationStyle.h + NavigationStylePy.xml GestureNavigationStyle.h SplitView3DInventor.h View.h diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 8c4beb319a..406c58357f 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -39,9 +39,11 @@ # include #endif +#include #include #include "NavigationStyle.h" +#include "NavigationStylePy.h" #include "Application.h" #include "Inventor/SoMouseWheelEvent.h" #include "MenuManager.h" @@ -178,7 +180,7 @@ const Base::Type& NavigationStyleEvent::style() const TYPESYSTEM_SOURCE_ABSTRACT(Gui::NavigationStyle,Base::BaseClass) -NavigationStyle::NavigationStyle() : viewer(nullptr), mouseSelection(nullptr) +NavigationStyle::NavigationStyle() : viewer(nullptr), mouseSelection(nullptr), pythonObject(nullptr) { this->rotationCenterMode = NavigationStyle::RotationCenterMode::ScenePointAtCursor | NavigationStyle::RotationCenterMode::FocalPointAtCursor; @@ -189,6 +191,12 @@ NavigationStyle::~NavigationStyle() { finalize(); delete this->animator; + + if (pythonObject) { + Base::PyGILStateLocker lock; + Py_DECREF(pythonObject); + pythonObject = nullptr; + } } NavigationStyle& NavigationStyle::operator = (const NavigationStyle& ns) @@ -1793,6 +1801,15 @@ void NavigationStyle::openPopupMenu(const SbVec2s& position) contextMenu->popup(QCursor::pos()); } +PyObject* NavigationStyle::getPyObject() +{ + if (!pythonObject) + pythonObject = new NavigationStylePy(this); + + Py_INCREF(pythonObject); + return pythonObject; +} + // ---------------------------------------------------------------------------------- TYPESYSTEM_SOURCE_ABSTRACT(Gui::UserNavigationStyle,Gui::NavigationStyle) diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index ffe1806138..d8136b5706 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -189,6 +189,8 @@ public: SbVec3f getRotationCenter(SbBool&) const; + PyObject *getPyObject() override; + protected: void initialize(); void finalize(); @@ -279,6 +281,8 @@ protected: SbSphereSheetProjector * spinprojector; //@} + PyObject* pythonObject; + private: friend class NavigationAnimator; diff --git a/src/Gui/NavigationStylePy.xml b/src/Gui/NavigationStylePy.xml new file mode 100644 index 0000000000..7506701f88 --- /dev/null +++ b/src/Gui/NavigationStylePy.xml @@ -0,0 +1,18 @@ + + + + + + This is the base class for navigation styles + + + + diff --git a/src/Gui/NavigationStylePyImp.cpp b/src/Gui/NavigationStylePyImp.cpp new file mode 100644 index 0000000000..df0f1c573c --- /dev/null +++ b/src/Gui/NavigationStylePyImp.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** + * * + * 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" + +// inclusion of the generated files (generated out of NavigationStylePy.xml) +#include "NavigationStylePy.h" +#include "NavigationStylePy.cpp" + + +using namespace Gui; + +/** @class NavigationStylePy + * The NavigationStyle Python class provides additional methods for manipulation of + * navigation style objects. + * @see NavigationStyle + */ + +// returns a string which represent the object e.g. when printed in python +std::string NavigationStylePy::representation() const +{ + return {""}; +} + +PyObject* NavigationStylePy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int NavigationStylePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Gui/View3DViewerPy.cpp b/src/Gui/View3DViewerPy.cpp index f8026a1236..bbc96195cf 100644 --- a/src/Gui/View3DViewerPy.cpp +++ b/src/Gui/View3DViewerPy.cpp @@ -31,6 +31,7 @@ #include #include "PythonWrapper.h" +#include "NavigationStyle.h" #include "View3DViewerPy.h" #include "View3DInventorViewer.h" @@ -103,6 +104,10 @@ void View3DInventorViewerPy::init_type() add_varargs_method("setNaviCubeCorner", &View3DInventorViewerPy::setNaviCubeCorner, "setNaviCubeCorner(int): sets the corner where to show the navi cube:\n" "0=top left, 1=top right, 2=bottom left, 3=bottom right"); + + add_varargs_method("getNavigationStyle",&View3DInventorViewerPy::getNavigationStyle, + "getNavigationStyle() -> NavigationStyle\n" "Returns the current viewer navigation style class.\n" + ); } View3DInventorViewerPy::View3DInventorViewerPy(View3DInventorViewer *vi) @@ -603,3 +608,15 @@ Py::Object View3DInventorViewerPy::setNaviCubeCorner(const Py::Tuple& args) _viewer->setNaviCubeCorner(pos); return Py::None(); } + +Py::Object View3DInventorViewerPy::getNavigationStyle(const Py::Tuple& args) +{ + if (!PyArg_ParseTuple(args.ptr(), "")) + throw Py::Exception(); + + NavigationStyle* navigationStyle = _viewer->navigationStyle(); + if (navigationStyle) { + return Py::asObject(navigationStyle->getPyObject()); + } + return Py::None(); +} \ No newline at end of file diff --git a/src/Gui/View3DViewerPy.h b/src/Gui/View3DViewerPy.h index 160f58d8b7..9e53d36dca 100644 --- a/src/Gui/View3DViewerPy.h +++ b/src/Gui/View3DViewerPy.h @@ -79,6 +79,7 @@ public: Py::Object isEnabledNaviCube(const Py::Tuple& args); Py::Object setNaviCubeCorner(const Py::Tuple& args); + Py::Object getNavigationStyle(const Py::Tuple&); private: using method_varargs_handler = PyObject* (*)(PyObject *_self, PyObject *_args);