Commit 8d824747 authored by Jan Möbius's avatar Jan Möbius

Basic PythonInterface for plugin move

parent 81d616f7
......@@ -4,10 +4,11 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/TSplineMesh)
add_definitions (-DENABLE_TSPLINEMESH_SUPPORT)
endif ()
openflipper_plugin ( TYPES PLANE POLYMESH TRIANGLEMESH
openflipper_plugin ( PYTHONINTERFACE
TYPES PLANE POLYMESH TRIANGLEMESH
OPTDEPS OpenVolumeMesh
OPT_TYPES POLYLINE SKELETON HEXAHEDRALMESH POLYHEDRALMESH TETRAHEDRALMESH
TRANSLATION_LANGUAGES de_DE
TRANSLATION_LANGUAGES de_DE
INSTALLDATA Icons VsiMetadata )
......@@ -745,6 +745,7 @@ void MovePlugin::setManipMode (QtTranslationManipulatorNode::ManipulatorMode _mo
//------------------------------------------------------------------------------
/** \brief Hide context menu entry when right clicking on node other than manipulator node
*
* @param _nodeId Identifier of node that has been clicked
......
......@@ -39,10 +39,7 @@
* *
\*===========================================================================*/
#ifndef MOVEPLUGIN_HH
#define MOVEPLUGIN_HH
#pragma once
#include <QObject>
#include <QMenuBar>
......@@ -58,6 +55,7 @@
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/PythonInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
......@@ -80,7 +78,7 @@
/** Plugin for moving objects and selections
*/
class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, BackupInterface, LoggingInterface, ScriptInterface,ToolbarInterface, ContextMenuInterface, LoadSaveInterface, RPCInterface
class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, BackupInterface, LoggingInterface, ScriptInterface,ToolbarInterface, PythonInterface, ContextMenuInterface, LoadSaveInterface, RPCInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
......@@ -95,6 +93,7 @@ class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface,
Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(RPCInterface)
Q_INTERFACES(PythonInterface)
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Move")
......@@ -618,4 +617,3 @@ public slots :
bool transformedSelected_;
};
#endif //MOVEPLUGIN_HH
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
#include <MovePlugin.hh>
#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
#include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
namespace py = pybind11;
PYBIND11_EMBEDDED_MODULE(Move, m) {
QObject* pluginPointer = getPluginPointer("Move");
if (!pluginPointer) {
std::cerr << "Error Getting plugin pointer for Plugin-Move" << std::endl;
return;
}
MovePlugin* plugin = qobject_cast<MovePlugin*>(pluginPointer);
if (!plugin) {
std::cerr << "Error converting plugin pointer for Plugin-Move" << std::endl;
return;
}
// Export our core. Make sure that the c++ worlds core object is not deleted if
// the python side gets deleted!!
py::class_< MovePlugin,std::unique_ptr<MovePlugin, py::nodelete> > move(m, "move");
// On the c++ side we will just return the existing core instance
// and prevent the system to recreate a new core as we need
// to work on the existing one.
move.def(py::init([plugin]() { return plugin; }));
move.def("moveToOrigin", &MovePlugin::slotMoveToOrigin,
QCoreApplication::translate("PythonDocMove","Move all target Meshes cog to the origin").toLatin1().data() );
move.def("unifyBoundingBoxDiagonal", &MovePlugin::slotUnifyBoundingBoxDiagonal,
QCoreApplication::translate("PythonDocMove","Unify bounding box diagonal of all target meshes").toLatin1().data() );
move.def("unifyBoundingBoxLongestAxis", &MovePlugin::slotUnifyBoundingBoxLongestAxis,
QCoreApplication::translate("PythonDocMove","Scale bounding box of all target meshes such that longest axis has unit size (keeps aspect ratio)").toLatin1().data() );
move.def("unifyBoundingBoxAllAxis", &MovePlugin::slotUnifyBoundingBoxAllAxis,
QCoreApplication::translate("PythonDocMove","Scale bounding box of all target meshes such that all axis have unit size").toLatin1().data() );
move.def("translate", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translate),
QCoreApplication::translate("PythonDocMove","Translate object by given vector.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
// /// translate given vertices by a vector
// void translate( int _objectId , IdList _vHandles, Vector _vector );
move.def("translateVertexSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateVertexSelection),
QCoreApplication::translate("PythonDocMove","Translate current vertex selection of an object by given vector.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
move.def("translateFaceSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateFaceSelection),
QCoreApplication::translate("PythonDocMove","Translate current face selection of an object by given vector.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
move.def("translateEdgeSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateEdgeSelection),
QCoreApplication::translate("PythonDocMove","Translate current edge selection of an object by given vector.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
//
// /// transform an Object by a given matrix
// void transform( int _objectId , Matrix4x4 _matrix );
//
// /// transform given vertices by a matrix
// void transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix );
// /// transform current selection of an Object by a given matrix
// bool transformVertexSelection( int _objectId , Matrix4x4 _matrix );
//
// /// transform current selection of an Object by a given matrix
// bool transformFaceSelection( int _objectId , Matrix4x4 _matrix );
//
// /// transform current selection of an Object by a given matrix
// bool transformEdgeSelection( int _objectId , Matrix4x4 _matrix );
//
// /// transform current selection of an Object by a given matrix
// bool transformCellSelection( int _objectId , Matrix4x4 _matrix );
//
// /// Transform handle region using the given transformation matrix
// void transformHandleRegion(int _objectId, Matrix4x4 _matrix);
//
move.def("setManipulatorPosition", &MovePlugin::setManipulatorPosition,
QCoreApplication::translate("PythonDocMove","Set the position of the manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","3D position").toLatin1().data()) );
move.def("manipulatorPosition", &MovePlugin::manipulatorPosition,
QCoreApplication::translate("PythonDocMove","Get the position of the manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
move.def("setManipulatorDirection", &MovePlugin::setManipulatorDirection,
QCoreApplication::translate("PythonDocMove","Set the direction of the manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","X-Axis direction").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Y-Axis direction").toLatin1().data()));
move.def("manipulatorDirectionX", &MovePlugin::manipulatorDirectionX,
QCoreApplication::translate("PythonDocMove","Get the x-direction of an object's manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
move.def("manipulatorDirectionY", &MovePlugin::manipulatorDirectionY,
QCoreApplication::translate("PythonDocMove","Get the y-direction of an object's manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
move.def("manipulatorDirectionZ", &MovePlugin::manipulatorDirectionZ,
QCoreApplication::translate("PythonDocMove","Get the z-direction of an object's manipulator.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
move.def("objectRenderingMatrixIdentity", &MovePlugin::objectRenderingMatrixIdentity,
QCoreApplication::translate("PythonDocMove","Resets the objects rendering matrix to identity.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
move.def("objectRenderingMatrixScale", &MovePlugin::objectRenderingMatrixScale,
QCoreApplication::translate("PythonDocMove","Adds a scaling factor to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","scaling factor").toLatin1().data()) );
move.def("objectRenderingMatrixTranslate", &MovePlugin::objectRenderingMatrixTranslate,
QCoreApplication::translate("PythonDocMove","Adds a translation to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
move.def("objectRenderingMatrixRotate", &MovePlugin::objectRenderingMatrixRotate,
QCoreApplication::translate("PythonDocMove","Adds a rotation to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Rotation axis").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocMove","Rotation angle").toLatin1().data()) );
// /** \brief Gets the Object Matrix in the scenegraph
// *
// * The object itself is not modified b< this matrix. Only the transformation matrix applied to the object
// * coordinates before rendering gets modified.
// *
// * @param _objectId Id of the object to modify
// * @return Current Matrix of the object
// */
// Matrix4x4 getObjectRenderingMatrix(int _objectId);
//
// emit setSlotDescription("translate(int,idList,Vector)",tr("Translate vertices by given vector."),
// QString(tr("objectId,VertexHandles,Vector")).split(","),
// QString(tr("ID of an object, List of vertex handles, translation vector")).split(","));
//
// emit setSlotDescription("transformHandleRegion(int,Matrix4x4)",tr("Transform handle region using the specified matrix."),
// QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transform(int,Matrix4x4)",tr("transform object by given matrix."),
// QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transform(int,IdList,Matrix4x4)",tr("transform vertices by given matrix."),
// QString(tr("objectId,VertexHandles,Matrix")).split(","),
// QString(tr("ID of an object, List of vertex handles, transformation matrix")).split(","));
//
// emit setSlotDescription("transformSelection(int,Matrix4x4)",tr("transform current selection of an object by given matrix."),
// QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transformCellSelection(int,Matrix4x4)",tr("transform selected cells by given matrix."),
// QString(tr("objectId,Matrix")).split(","),
// QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transformVertexSelection(int,Matrix4x4)",tr("transform selected vertices by given matrix."),
// QString(tr("objectId,Matrix")).split(","),
// QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transformFaceSelection(int,Matrix4x4)",tr("transform selected faces by given matrix."),
// QString(tr("objectId,Matrix")).split(","),
// QString(tr("ID of an object, transformation matrix")).split(","));
//
// emit setSlotDescription("transformEdgeSelection(int,Matrix4x4)",tr("transform selected edges by given matrix."),
// QString(tr("objectId,Matrix")).split(","),
// QString(tr("ID of an object, transformation matrix")).split(","));
//
//
// emit setSlotDescription("getObjectRenderingMatrix(int)",tr("Returns the current object transformation matrix from the scenegraph."),
// QStringList(tr("objectId").split(";")), QStringList(tr("ID of an object").split(";")));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment