Gui: Bind NavigationStyle to Python.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -39,9 +39,11 @@
|
||||
# include <QMenu>
|
||||
#endif
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Application.h>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
18
src/Gui/NavigationStylePy.xml
Normal file
18
src/Gui/NavigationStylePy.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="BaseClassPy"
|
||||
Name="NavigationStylePy"
|
||||
Twin="NavigationStyle"
|
||||
TwinPointer="NavigationStyle"
|
||||
Include="Gui/NavigationStyle.h"
|
||||
Namespace="Gui"
|
||||
FatherInclude="Base/BaseClassPy.h"
|
||||
FatherNamespace="Base">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>This is the base class for navigation styles</UserDocu>
|
||||
</Documentation>
|
||||
<CustomAttributes />
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
51
src/Gui/NavigationStylePyImp.cpp
Normal file
51
src/Gui/NavigationStylePyImp.cpp
Normal file
@@ -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 {"<NavigationStyle object>"};
|
||||
}
|
||||
|
||||
PyObject* NavigationStylePy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int NavigationStylePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <Base/MatrixPy.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user