Gui: support in-place editing
The link support means that an object can now appear in more than one places, and even inside a document different from its own. This patch adds support for in-place editing, meaning that the object can be edited at correct place regardless where it is. See [here](https://git.io/fjPIk) for more info about the relavent APIs. This patch includes two example of modifications to support in-place editing. One is the ViewProviderDragger, which simply adds the dragger node to editing root node by calling View3DInventorViewer::setupEditingRoot(dragger). The other much more complex one is ViewProviderSketch which calls setupEditingRoot(0) to transfer all its children node into editing root. ViewProviderSketch also includes various modifications to command invocation, because we can no longer assume the active document is the owner of the editing object. This patch also includes necessary modification of the 'Show' module to support in-place editing.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/MatrixPy.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
|
||||
using namespace Gui;
|
||||
@@ -75,6 +76,14 @@ void View3DInventorViewerPy::init_type()
|
||||
"getPickRadius(): returns radius of confusion in pixels for picking objects on screen (selection).");
|
||||
add_varargs_method("setPickRadius", &View3DInventorViewerPy::setPickRadius,
|
||||
"setPickRadius(new_radius): sets radius of confusion in pixels for picking objects on screen (selection).");
|
||||
add_varargs_method("setupEditingRoot", &View3DInventorViewerPy::setupEditingRoot,
|
||||
"setupEditingRoot(matrix=None): setup the editing ViewProvider's root node.\n"
|
||||
"All child coin nodes of the current editing ViewProvider will be transferred to\n"
|
||||
"an internal editing node of this viewer, with a new transformation node specified\n"
|
||||
"by 'matrix'. All ViewProviderLink to the editing ViewProvider will be temperary\n"
|
||||
"hidden. Call resetEditingRoot() to restore everything back to normal");
|
||||
add_varargs_method("resetEditingRoot", &View3DInventorViewerPy::resetEditingRoot,
|
||||
"resetEditingRoot(updateLinks=True): restore the editing ViewProvider's root node");
|
||||
add_varargs_method("setBackgroundColor", &View3DInventorViewerPy::setBackgroundColor,
|
||||
"setBackgroundColor(r,g,b): sets the background color of the current viewer.");
|
||||
add_varargs_method("setRedirectToSceneGraph", &View3DInventorViewerPy::setRedirectToSceneGraph,
|
||||
@@ -365,6 +374,60 @@ Py::Object View3DInventorViewerPy::setPickRadius(const Py::Tuple& args)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorViewerPy::setupEditingRoot(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *pynode = Py_None;
|
||||
PyObject *pymat = Py_None;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|OO!", &pynode,&Base::MatrixPy::Type,&pymat)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
Base::Matrix4D *mat = 0;
|
||||
if(pymat != Py_None)
|
||||
mat = static_cast<Base::MatrixPy*>(pymat)->getMatrixPtr();
|
||||
|
||||
try {
|
||||
SoNode *node = 0;
|
||||
if(pynode!=Py_None) {
|
||||
void* ptr = 0;
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", pynode, &ptr, 0);
|
||||
node = reinterpret_cast<SoNode*>(ptr);
|
||||
}
|
||||
_viewer->setupEditingRoot(node,mat);
|
||||
return Py::None();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,e.what());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
catch(...) {
|
||||
throw Py::RuntimeError("Unknown C++ exception");
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorViewerPy::resetEditingRoot(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *updateLinks = Py_True;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|O", &updateLinks)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
try {
|
||||
_viewer->resetEditingRoot(PyObject_IsTrue(updateLinks));
|
||||
return Py::None();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,e.what());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
catch(...) {
|
||||
throw Py::RuntimeError("Unknown C++ exception");
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorViewerPy::setBackgroundColor(const Py::Tuple& args)
|
||||
{
|
||||
float r,g,b = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user