Gui: Application/Document/MainWindow changes following App namespace
Application: * signalNewDocument, check the extra argument, isMainDoc, the decide whether to create view of the new document. This is so that external linked document can be opened in background without crowding the tab list. * slotDeleteDocument, calls Document::beforeDelete() * slotActiveDocument, creates view if none, because external document is now opened without view. * onLastWindowClosed(), switch to next active document, and creates view if none. * send(Has)MsgToFocusView(), new API to send message to the active view in focus. This is to solve the ambiguity of things like pressing delete key, copy, paste handling when the active new is not in focus. For example, when spread sheet view is active, delete/copy/paste handling should be different when the focus on the spread sheet view or focus on tree view. * tryClose(), delegate to MainWindow for close confirmation * reopen(), new API to reload a partial document in full Document/DocumentP: * _CoinMap, new internal map for quick access view provider from its root node. * slotNewObject, modified to support view provider override from App::FeaturePython, through new API DocumentObject::getViewProviderNameOverride(). * slotDeletedObject/slotTransactionRemove, improve handling of geo group children rebuild * slotSkipRecompute, add special handling of document with skip recompute. Some command cannot work when skip recompute is active. For example, sketcher command will check if recompute is successful on many commands, and will undo if not. New 'PartialCompute' flag is added to allow recompute only the editing object and all its dependencies if 'SkipRecompute' is active. * slotTouchedObject, new signal handling of manually touched object. * setModified(), do nothing if already modified. This is a critical performance improvement, because marking tab window as modified turns out to be a relatively expensive operation, and will cause massive slow down if calling it on every property change. * getViewProviderByPathFromHead/getViewProvidersByPath(), new APIs to obtain view provider(s) from coin SoPath. * save/saveAll/saveCopy, modified to support external document saving. * Save/RestoreDocFile(), save and restore tree item recursive expansion status. * slotFinishRestoreObject(), handle new signal signalFinishRestoreObject(), unifies postprocessing in restore and import operation. * createView/setActiveView(), add support of delayed view creations * canClose(), delegate to MainWindows to ask for confirmation * undo/redo(), support grouped transaction undo/redo. Transactions may be grouped by the same transaction ID if they are triggered by a single operation but involves objects from multiple documents. * toggleInSceneGraph(), new API to add or remove root node from or to scenegraph without deleting the view object. MainWindow: * Update command status using a single shot timer instead of periodical one. * Improve message display is status bar. Give error and warning message higher priority (using QStatusBar::showMessage()) than normal status message (using actionLabel), reversed from original implementation. * confirmSave(), new API to check for modification, and ask user to save the document before closing. The confirmation dialog allows user to apply the answer to all document for convenience. * saveAll(), new API to save all document with correct ordering in case of external linking. * createMimeDataFromSelection/insertFromMimeData(), support copy paste object with external linking. A new dialog DlgObjectSelection is used to let user select exactly which object to export. CommandDoc/CommandWindow: * Related changes to object delete, document import, export, and save.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <App/Document.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "MergeDocuments.h"
|
||||
#include "ViewProviderExtern.h"
|
||||
@@ -41,6 +42,7 @@
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include "Tree.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
#include "ViewProviderDocumentObjectPy.h"
|
||||
#include "ViewProviderPy.h"
|
||||
#include "ViewProviderDocumentObjectPy.h"
|
||||
|
||||
@@ -103,38 +105,42 @@ PyObject* DocumentPy::setEdit(PyObject *args)
|
||||
{
|
||||
char *psFeatStr;
|
||||
int mod = 0;
|
||||
char *subname = 0;
|
||||
ViewProvider *vp = 0;
|
||||
App::DocumentObject *obj = 0;
|
||||
|
||||
// by name
|
||||
if (PyArg_ParseTuple(args, "s|i;Name of the object to edit has to be given!", &psFeatStr,&mod)) {
|
||||
App::DocumentObject * obj = getDocumentPtr()->getDocument()->getObject(psFeatStr);
|
||||
if (PyArg_ParseTuple(args, "s|is;Name of the object to edit has to be given!", &psFeatStr,&mod,&subname)) {
|
||||
obj = getDocumentPtr()->getDocument()->getObject(psFeatStr);
|
||||
if (!obj) {
|
||||
PyErr_Format(Base::BaseExceptionFreeCADError, "No such object found in document: '%s'", psFeatStr);
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
PyErr_Clear();
|
||||
PyObject *pyObj;
|
||||
if(!PyArg_ParseTuple(args, "O|is", &pyObj,&mod,&subname))
|
||||
return 0;
|
||||
|
||||
bool ok = getDocumentPtr()->setEdit(getDocumentPtr()->getViewProvider(obj),mod);
|
||||
return PyBool_FromLong(ok ? 1 : 0);
|
||||
if(PyObject_TypeCheck(pyObj,&App::DocumentObjectPy::Type))
|
||||
obj = static_cast<App::DocumentObjectPy*>(pyObj)->getDocumentObjectPtr();
|
||||
else if(PyObject_TypeCheck(pyObj,&ViewProviderPy::Type))
|
||||
vp = static_cast<ViewProviderPy*>(pyObj)->getViewProviderPtr();
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,"Expect the first argument to be string|DocObject|ViewObject");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// by document object
|
||||
PyErr_Clear();
|
||||
PyObject *docObj;
|
||||
if (PyArg_ParseTuple(args, "O!|i", &(App::DocumentObjectPy::Type), &docObj,&mod)) {
|
||||
App::DocumentObject * obj = static_cast<App::DocumentObjectPy*>(docObj)->getDocumentObjectPtr();
|
||||
bool ok = getDocumentPtr()->setEdit(getDocumentPtr()->getViewProvider(obj),mod);
|
||||
return PyBool_FromLong(ok ? 1 : 0);
|
||||
if(!vp) {
|
||||
if(!obj || !obj->getNameInDocument() || !(vp=Application::Instance->getViewProvider(obj))) {
|
||||
PyErr_SetString(PyExc_ValueError,"Invalid document object");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// by view provider
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args, "O!|i", &(Gui::ViewProviderPy::Type), &docObj,&mod)) {
|
||||
Gui::ViewProvider * view = static_cast<Gui::ViewProviderPy*>(docObj)->getViewProviderPtr();
|
||||
bool ok = getDocumentPtr()->setEdit(view,mod);
|
||||
return PyBool_FromLong(ok ? 1 : 0);
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Either string, document object or view provider expected.");
|
||||
return 0;
|
||||
bool ok = getDocumentPtr()->setEdit(vp,mod,subname);
|
||||
return PyBool_FromLong(ok ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::getInEdit(PyObject *args)
|
||||
@@ -289,22 +295,32 @@ PyObject* DocumentPy::mergeProject(PyObject *args)
|
||||
PyObject* DocumentPy::toggleTreeItem(PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
const char *subname=0;
|
||||
int mod = 0;
|
||||
if (PyArg_ParseTuple(args,"O!|i",&(App::DocumentObjectPy::Type), &object,&mod)) {
|
||||
if (PyArg_ParseTuple(args,"O!|is",&(App::DocumentObjectPy::Type), &object,&mod,&subname)) {
|
||||
App::DocumentObject* Object = static_cast<App::DocumentObjectPy*>(object)->getDocumentObjectPtr();
|
||||
// Should be set!
|
||||
assert(Object);
|
||||
|
||||
App::DocumentObject *parent = 0;
|
||||
if(subname) {
|
||||
auto sobj = Object->getSubObject(subname);
|
||||
if(!sobj)
|
||||
throw Py::RuntimeError("Sub-object not found");
|
||||
parent = Object;
|
||||
Object = sobj;
|
||||
}
|
||||
|
||||
// get the gui document of the Assembly Item
|
||||
//ActiveAppDoc = Item->getDocument();
|
||||
//ActiveGuiDoc = Gui::Application::Instance->getDocument(getDocumentPtr());
|
||||
Gui::ViewProviderDocumentObject* ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (getDocumentPtr()->getViewProvider(Object));
|
||||
assert(ActiveVp);
|
||||
switch(mod) {
|
||||
case 0: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ToggleItem); break;
|
||||
case 1: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::CollapseItem); break;
|
||||
case 2: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ExpandItem); break;
|
||||
case 3: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ExpandPath); break;
|
||||
case 0: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ToggleItem,parent,subname); break;
|
||||
case 1: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::CollapseItem,parent,subname); break;
|
||||
case 2: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ExpandItem,parent,subname); break;
|
||||
case 3: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ExpandPath,parent,subname); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -324,6 +340,16 @@ PyObject* DocumentPy::scrollToTreeItem(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::toggleInSceneGraph(PyObject *args) {
|
||||
PyObject *view;
|
||||
if (!PyArg_ParseTuple(args,"O!",&(Gui::ViewProviderPy::Type), &view))
|
||||
return 0;
|
||||
|
||||
Gui::ViewProvider* vp = static_cast<ViewProviderPy*>(view)->getViewProviderPtr();
|
||||
getDocumentPtr()->toggleInSceneGraph(vp);
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
Py::Object DocumentPy::getActiveObject(void) const
|
||||
{
|
||||
App::DocumentObject *object = getDocumentPtr()->getDocument()->getActiveObject();
|
||||
@@ -367,6 +393,49 @@ Py::Object DocumentPy::getDocument(void) const
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object DocumentPy::getEditingTransform(void) const {
|
||||
return Py::Object(new Base::MatrixPy(new Base::Matrix4D(
|
||||
getDocumentPtr()->getEditingTransform())));
|
||||
}
|
||||
|
||||
void DocumentPy::setEditingTransform(Py::Object arg) {
|
||||
if(!PyObject_TypeCheck(arg.ptr(),&Base::MatrixPy::Type))
|
||||
throw Py::TypeError("Expecting type of matrix");
|
||||
getDocumentPtr()->setEditingTransform(
|
||||
*static_cast<Base::MatrixPy*>(arg.ptr())->getMatrixPtr());
|
||||
}
|
||||
|
||||
Py::Object DocumentPy::getInEditInfo(void) const {
|
||||
ViewProviderDocumentObject *vp = 0;
|
||||
std::string subname,subelement;
|
||||
int mode = 0;
|
||||
getDocumentPtr()->getInEdit(&vp,&subname,&mode,&subelement);
|
||||
if(!vp || !vp->getObject() || !vp->getObject()->getNameInDocument())
|
||||
return Py::None();
|
||||
return Py::TupleN(Py::Object(vp->getObject()->getPyObject(),true),
|
||||
Py::String(subname),Py::String(subelement),Py::Int(mode));
|
||||
}
|
||||
|
||||
void DocumentPy::setInEditInfo(Py::Object arg) {
|
||||
PyObject *pyobj = 0;
|
||||
const char *subname = 0;
|
||||
if (!PyArg_ParseTuple(arg.ptr(), "O!s",
|
||||
&Gui::ViewProviderDocumentObjectPy::Type, &pyobj,&subname))
|
||||
throw Py::Exception();
|
||||
getDocumentPtr()->setInEdit(static_cast<ViewProviderDocumentObjectPy*>(
|
||||
pyobj)->getViewProviderDocumentObjectPtr(),subname);
|
||||
}
|
||||
|
||||
Py::Int DocumentPy::getEditMode(void) const {
|
||||
int mode = -1;
|
||||
getDocumentPtr()->getInEdit(0,0,&mode);
|
||||
return Py::Int(mode);
|
||||
}
|
||||
|
||||
Py::Boolean DocumentPy::getTransacting() const {
|
||||
return Py::Boolean(getDocumentPtr()->isPerformingTransaction());
|
||||
}
|
||||
|
||||
Py::Boolean DocumentPy::getModified(void) const
|
||||
{
|
||||
return Py::Boolean(getDocumentPtr()->isModified());
|
||||
|
||||
Reference in New Issue
Block a user