Commits (12)
......@@ -57,6 +57,19 @@
*/
class PythonInterface {
signals :
/** Executes the specified python script string.
*
* @param _script Script to be executed
*/
virtual void executePythonScript(QString _script) {};
/** Opens the python script editor with the specified script
*
* @param _script Script to be displayed
*/
virtual void openPythonScriptInEditor(QString _script) {};
public :
/// Destructor
......
......@@ -1456,6 +1456,20 @@ private slots:
/** @} */
//===========================================================================
/** @name PythonInterface
* @{ */
//===========================================================================
private slots:
// Execute python script
void slotExecutePythonScript( QString _script);
// Open python script editor
void slotOpenPythonScriptInEditor( QString _script);
/** @} */
//===========================================================================
/** @name Scenegraph redraw handling
* @{ */
......
......@@ -95,32 +95,6 @@ class PluginInfo{
contextMenus.clear();
}
PluginInfo( const PluginInfo& _i) :
plugin(_i.plugin),
name(_i.name),
description(_i.description),
version(_i.version),
path(_i.path),
rpcName(_i.rpcName),
errors(_i.errors),
warnings(_i.warnings),
rpcFunctions(_i.rpcFunctions),
slotInfos(_i.slotInfos),
keys(_i.keys),
toolboxWidgets(_i.toolboxWidgets),
headerAreaWidgets(_i.headerAreaWidgets),
toolboxIcons(_i.toolboxIcons),
toolbars(_i.toolbars),
contextMenus(_i.contextMenus),
optionsWidget(_i.optionsWidget),
buildIn(_i.buildIn),
status(_i.status)
{
}
/// Pointer to the loaded plugin (Already casted when loading it)
QObject* plugin;
......
......@@ -1349,7 +1349,6 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic
// Check if the plugin supports Python Interface
PythonInterface* pythonPlugin = qobject_cast< PythonInterface * >(plugin);
if ( pythonPlugin ) {
supported = supported + "PythonInterface ";
......@@ -1357,6 +1356,15 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic
setPluginPointer(basePlugin->name() , currentPluginPointer);
if ( checkSignal(plugin, "executePythonScript(QString)")) {
connect(plugin, SIGNAL(executePythonScript(QString)),
this, SLOT(slotExecutePythonScript(QString)), Qt::DirectConnection);
}
if ( checkSignal(plugin, "openPythonScriptInEditor(QString)")) {
connect(plugin, SIGNAL(openPythonScriptInEditor(QString)),
this, SLOT(slotOpenPythonScriptInEditor(QString)), Qt::DirectConnection);
}
}
#endif
......
......@@ -447,3 +447,13 @@ void Core::executePythonScript(QString _script) {
#endif
}
void Core::slotExecutePythonScript(QString _script) {
executePythonScript(_script);
}
void Core::slotOpenPythonScriptInEditor(QString _script) {
emit scriptLog("Open python editor");
emit scriptLog(_script);
coreWidget_->showPythonScriptInterpreter();
coreWidget_->pythonWidget_->showScript(_script);
}
......@@ -208,6 +208,118 @@ namespace pybind11 { namespace detail {
};
}} // namespace pybind11::detail
/** \page python_scripting_vector_type Vector4 data type used for python scripting
*
* The matrix type Vector4 is mapped to python to handle Vector4 operations.
*
* The integrated conversion can map the C++ Vector4 type to and from a tuple, a list or a numpy array.
* The preferred choice is the numpy array. Tuple and list have to contain 4 elements. A numpy array
* has to have a dimension of 1, with 4 elements.
*
* Creating a matrix in python is the done like in the following example:
* \code
* import numpy as np
*
* vector = np.array([1.0,0.0,0.0,0.0]);
* \endcode
*
* The conversion from C++ to python will always create a numpy array on the python side.
*/
namespace pybind11 { namespace detail {
template <> struct type_caster<Vector4> {
public:
/**
* This macro establishes the name 'str' in
* function signatures and declares a local variable
* 'value' of type QVariant
*/
PYBIND11_TYPE_CASTER(Vector4, _("Vector4"));
/**
* Conversion part 1 (Python->C++): convert a PyObject into a Vector4
* instance or return false upon failure. The second argument
* indicates whether implicit conversions should be applied.
*/
bool load(handle src, bool convert ) {
/* Extract PyObject from handle */
PyObject* source = src.ptr();
if ( PyList_Check(source) ) {
if ( PyList_Size(source) != 4) {
PyErr_SetString(PyExc_RuntimeError, "Vector4 Conversion: List size should be 3!");
throw py::error_already_set();
return false;
}
/* Now try to convert into a C++ int */
value = Vector4(PyFloat_AsDouble(PyList_GetItem(source,0)),PyFloat_AsDouble(PyList_GetItem(source,1)),PyFloat_AsDouble(PyList_GetItem(source,2)),PyFloat_AsDouble(PyList_GetItem(source,3)));
} else if ( PyTuple_Check(source) ) {
if ( PyTuple_Size(source) != 4) {
PyErr_SetString(PyExc_RuntimeError, "Vector Conversion: Tuple size should be 4!");
throw py::error_already_set();
return false;
}
/* Now try to convert into a C++ int */
value = Vector4(PyFloat_AsDouble(PyTuple_GetItem(source,0)),PyFloat_AsDouble(PyTuple_GetItem(source,1)),PyFloat_AsDouble(PyTuple_GetItem(source,2)),PyFloat_AsDouble(PyTuple_GetItem(source,3)));
} else if ( py::cast<py::array>(source) ) {
py::array array = py::cast<py::array>(source);
if ( array.size() != 4) {
PyErr_SetString(PyExc_RuntimeError, "Vector Conversion: Numpy Array size should be 4!");
throw py::error_already_set();
return false;
}
if (!convert && !py::array_t<double>::check_(src)) {
PyErr_SetString(PyExc_RuntimeError, "Vector Conversion: Numpy Array, wrong dtype, conversion disabled");
return false;
}
auto buf = py::array_t<double, py::array::c_style | py::array::forcecast>::ensure(src);
if (!buf) {
PyErr_SetString(PyExc_RuntimeError, "Vector Conversion: Numpy Array, conversion failed.");
return false;
}
if (buf.ndim() != 1 || buf.size() != 4) {
PyErr_SetString(PyExc_RuntimeError, "Vector Conversion: Numpy Array dimension or size error. Dimension should be one, size 4!");
return false;
}
value = Vector4(buf.data());
return true;
} else {
PyErr_SetString(PyExc_RuntimeError, "Vector4 Conversion: Not a list or a tuple or a numpy array.");
throw py::error_already_set();
return false;
}
/* Ensure return code was OK (to avoid out-of-range errors etc) */
return ( !PyErr_Occurred() );
}
/**
* Conversion part 2 (C++ -> Python): convert an Vector4 instance into
* a Python object. The second and third arguments are used to
* indicate the return value policy and parent object (for
* ``return_value_policy::reference_internal``) and are generally
* ignored by implicit casters.
*/
static handle cast(Vector4 src, return_value_policy /* policy */, handle parent ) {
// Create numpy array
py::array a(4, src.data());
return a.release();
}
};
}} // namespace pybind11::detail
/** \page python_scripting_matrix4x4_type Matrix4x4 data type used for python scripting
*
* The matrix type Matrix4x4 is mapped to python to handle matrix operations.
......
......@@ -175,7 +175,7 @@ if ( COMISO_INCLUDE_DIR AND COMISO_CONFIG_INCLUDE_DIR )
if ( COMISO_GUROBI_BUILD_TIME_AVAILABLE )
find_package(GUROBI)
find_package(Gurobi)
if ( NOT GUROBI_FOUND )
message(ERROR "COMISO configured with GUROBI but GUROBI not available")
......
......@@ -42,6 +42,7 @@ else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
else(GTEST_PREFIX)
find_path(_GTEST_INCLUDE_DIR "gtest/gtest.h"
PATHS
~/sw/gtest-1.10.0/include
~/sw/gtest-1.8.0/include
~/sw/gtest-1.7.0/include
~/sw/gtest/include
......@@ -53,6 +54,7 @@ else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
NO_DEFAULT_PATH )
find_library(_GTEST_LIBRARY gtest
PATHS
~/sw/gtest-1.10.0/lib
~/sw/gtest-1.8.0/lib
~/sw/gtest-1.7.0/lib
~/sw/gtest/lib
......@@ -64,6 +66,7 @@ else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
NO_DEFAULT_PATH )
find_library(_GTEST_MAIN_LIBRARY gtest_main
PATHS
~/sw/gtest-1.10.0/lib
~/sw/gtest-1.8.0/lib
~/sw/gtest-1.7.0/lib
~/sw/gtest/lib
......
......@@ -39,6 +39,7 @@ include_directories (
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_BINARY_DIR}
${ADDITIONAL_PLUGINLIB_INCS}
${OPENGL_INCLUDE_DIR}
)
......
Subproject commit 6aebeef8897e4fe8029328f7712647f517c3ef98
Subproject commit c6da50a483a66a9afc7f870a8a97ae64f9dfdbb5
......@@ -152,6 +152,10 @@ void PythonWidget::slotLocalLog(Logtype _type ,QString _logString) {
pythonOutput->append(_logString);
}
void PythonWidget::showScript(QString _script) {
scriptWidget->setPlainText(_script);
}
......
......@@ -57,6 +57,8 @@ class PythonWidget : public QMainWindow, public Ui::PythonWidget
public slots:
void runScript();
void showScript(QString _script);
private slots:
void slotLocalLog(Logtype _type,QString _logString);
......