Skip to content

Commit

Permalink
Gui: support in-place editing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
realthunder authored and wwmayer committed Aug 17, 2019
1 parent aa3e81f commit 00bcef0
Show file tree
Hide file tree
Showing 29 changed files with 1,449 additions and 942 deletions.
21 changes: 21 additions & 0 deletions src/Gui/Application.cpp
Expand Up @@ -142,6 +142,7 @@ struct ApplicationP
{
ApplicationP() :
activeDocument(0L),
editDocument(0L),
isClosing(false),
startingUp(true)
{
Expand All @@ -158,6 +159,7 @@ struct ApplicationP
std::map<const App::Document*, Gui::Document*> documents;
/// Active document
Gui::Document* activeDocument;
Gui::Document* editDocument;
MacroManager* macroMngr;
/// List of all registered views
std::list<Gui::BaseView*> passive;
Expand Down Expand Up @@ -863,6 +865,25 @@ Gui::Document* Application::activeDocument(void) const
return d->activeDocument;
}

Gui::Document* Application::editDocument(void) const
{
return d->editDocument;
}

Gui::MDIView* Application::editViewOfNode(SoNode *node) const
{
return d->editDocument?d->editDocument->getViewOfNode(node):0;
}

void Application::setEditDocument(Gui::Document *doc) {
if(!doc)
d->editDocument = 0;
for(auto &v : d->documents)
v.second->_resetEdit();
d->editDocument = doc;
getMainWindow()->updateActions();
}

void Application::setActiveDocument(Gui::Document* pcDocument)
{
if (d->activeDocument == pcDocument)
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/Application.h
Expand Up @@ -146,6 +146,11 @@ class GuiExport Application
Gui::Document* activeDocument(void) const;
/// Set the active document
void setActiveDocument(Gui::Document* pcDocument);
/// Getter for the editing document
Gui::Document* editDocument(void) const;
Gui::MDIView* editViewOfNode(SoNode *node) const;
/// Set editing document, which will reset editing of all other document
void setEditDocument(Gui::Document* pcDocument);
/** Retrieves a pointer to the Gui::Document whose App::Document has the name \a name.
* If no such document exists 0 is returned.
*/
Expand Down Expand Up @@ -250,6 +255,7 @@ class GuiExport Application
static PyObject* sActiveView (PyObject *self,PyObject *args);
static PyObject* sActivateView (PyObject *self,PyObject *args);
static PyObject* sGetDocument (PyObject *self,PyObject *args);
static PyObject* sEditDocument (PyObject *self,PyObject *args);

static PyObject* sDoCommand (PyObject *self,PyObject *args);
static PyObject* sDoCommandGui (PyObject *self,PyObject *args);
Expand Down
17 changes: 17 additions & 0 deletions src/Gui/ApplicationPy.cpp
Expand Up @@ -165,6 +165,9 @@ PyMethodDef Application::Methods[] = {
{"activateView", (PyCFunction)Application::sActivateView, METH_VARARGS,
"activateView(type)\n\n"
"Activate a view of the given type of the active document"},
{"editDocument", (PyCFunction)Application::sEditDocument, METH_VARARGS,
"editDocument() -> object or None\n\n"
"Return the current editing document or None if no one exists" },
{"getDocument", (PyCFunction) Application::sGetDocument, METH_VARARGS,
"getDocument(string) -> object\n\n"
"Get a document by its name"},
Expand Down Expand Up @@ -203,6 +206,20 @@ PyMethodDef Application::Methods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

PyObject* Gui::Application::sEditDocument(PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception

Document *pcDoc = Instance->editDocument();
if (pcDoc) {
return pcDoc->getPyObject();
}
else {
Py_Return;
}
}

PyObject* Gui::Application::sActiveDocument(PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
Expand Down

0 comments on commit 00bcef0

Please sign in to comment.