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:
@@ -101,6 +101,9 @@ PyMethodDef Application::Methods[] = {
|
||||
{"addIcon", (PyCFunction) Application::sAddIcon, METH_VARARGS,
|
||||
"addIcon(string, string or list) -> None\n\n"
|
||||
"Add an icon as file name or in XPM format to the system"},
|
||||
{"getIcon", (PyCFunction) Application::sGetIcon, METH_VARARGS,
|
||||
"getIcon(string -> QIcon\n\n"
|
||||
"Get an icon in the system"},
|
||||
{"getMainWindow", (PyCFunction) Application::sGetMainWindow, METH_VARARGS,
|
||||
"getMainWindow() -> QMainWindow\n\n"
|
||||
"Return the main window instance"},
|
||||
@@ -132,11 +135,16 @@ PyMethodDef Application::Methods[] = {
|
||||
{"runCommand", (PyCFunction) Application::sRunCommand, METH_VARARGS,
|
||||
"runCommand(string) -> None\n\n"
|
||||
"Run command with name"},
|
||||
{"isCommandActive", (PyCFunction) Application::sIsCommandActive, METH_VARARGS,
|
||||
"isCommandActive(string) -> Bool\n\n"
|
||||
"Test if a command is active"},
|
||||
{"listCommands", (PyCFunction) Application::sListCommands, METH_VARARGS,
|
||||
"listCommands() -> list of strings\n\n"
|
||||
"Returns a list of all commands known to FreeCAD."},
|
||||
{"SendMsgToActiveView", (PyCFunction) Application::sSendActiveView, METH_VARARGS,
|
||||
"deprecated -- use class View"},
|
||||
{"sendMsgToFocusView", (PyCFunction) Application::sSendFocusView, METH_VARARGS,
|
||||
"send message to the focused view"},
|
||||
{"hide", (PyCFunction) Application::sHide, METH_VARARGS,
|
||||
"deprecated"},
|
||||
{"show", (PyCFunction) Application::sShow, METH_VARARGS,
|
||||
@@ -160,8 +168,8 @@ PyMethodDef Application::Methods[] = {
|
||||
"setActiveDocument(string or App.Document) -> None\n\n"
|
||||
"Activate the specified document"},
|
||||
{"activeView", (PyCFunction)Application::sActiveView, METH_VARARGS,
|
||||
"activeView() -> object or None\n\n"
|
||||
"Return the active view of the active document or None if no one exists"},
|
||||
"activeView(typename=None) -> object or None\n\n"
|
||||
"Return the active view of the active document or None if no one exists" },
|
||||
{"activateView", (PyCFunction)Application::sActivateView, METH_VARARGS,
|
||||
"activateView(type)\n\n"
|
||||
"Activate a view of the given type of the active document"},
|
||||
@@ -200,6 +208,10 @@ PyMethodDef Application::Methods[] = {
|
||||
"removeDocumentObserver() -> None\n\n"
|
||||
"Remove an added document observer."},
|
||||
|
||||
{"reload", (PyCFunction) Application::sReload, METH_VARARGS,
|
||||
"reload(name) -> doc\n\n"
|
||||
"Reload a partial opened document"},
|
||||
|
||||
{"coinRemoveAllChildren", (PyCFunction) Application::sCoinRemoveAllChildren, METH_VARARGS,
|
||||
"Remove all children from a group node"},
|
||||
|
||||
@@ -236,16 +248,37 @@ PyObject* Gui::Application::sActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
PyObject* Gui::Application::sActiveView(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
const char *typeName=0;
|
||||
if (!PyArg_ParseTuple(args, "|s", &typeName))
|
||||
return NULL;
|
||||
|
||||
Gui::MDIView* mdiView = Instance->activeView();
|
||||
if (mdiView) {
|
||||
// already incremented in getPyObject().
|
||||
return mdiView->getPyObject();
|
||||
}
|
||||
PY_TRY {
|
||||
Base::Type type;
|
||||
if(typeName) {
|
||||
type = Base::Type::fromName(typeName);
|
||||
if(type.isBad()) {
|
||||
PyErr_Format(PyExc_TypeError, "Invalid type '%s'", typeName);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
Gui::MDIView* mdiView = Instance->activeView();
|
||||
if (mdiView && (type.isBad() || mdiView->isDerivedFrom(type))) {
|
||||
auto res = Py::asObject(mdiView->getPyObject());
|
||||
if(!res.isNone() || !type.isBad())
|
||||
return Py::new_reference_to(res);
|
||||
}
|
||||
|
||||
if(type.isBad())
|
||||
type = Gui::View3DInventor::getClassTypeId();
|
||||
Instance->activateView(type, true);
|
||||
mdiView = Instance->activeView();
|
||||
if (mdiView)
|
||||
return mdiView->getPyObject();
|
||||
|
||||
Py_Return;
|
||||
|
||||
} PY_CATCH
|
||||
}
|
||||
|
||||
PyObject* Gui::Application::sActivateView(PyObject * /*self*/, PyObject *args)
|
||||
@@ -624,6 +657,28 @@ PyObject* Application::sSendActiveView(PyObject * /*self*/, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* Application::sSendFocusView(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *psCommandStr;
|
||||
PyObject *suppress=Py_False;
|
||||
if (!PyArg_ParseTuple(args, "s|O!",&psCommandStr,&PyBool_Type,&suppress))
|
||||
return NULL;
|
||||
|
||||
const char* ppReturn=0;
|
||||
if (!Instance->sendMsgToFocusView(psCommandStr,&ppReturn)) {
|
||||
if (!PyObject_IsTrue(suppress))
|
||||
Base::Console().Warning("Unknown view command: %s\n",psCommandStr);
|
||||
}
|
||||
|
||||
// Print the return value to the output
|
||||
if (ppReturn) {
|
||||
return Py_BuildValue("s",ppReturn);
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* Application::sGetMainWindow(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
@@ -1042,6 +1097,21 @@ PyObject* Application::sAddIcon(PyObject * /*self*/, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* Application::sGetIcon(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *iconName;
|
||||
if (!PyArg_ParseTuple(args, "s", &iconName))
|
||||
return NULL;
|
||||
|
||||
PythonWrapper wrap;
|
||||
wrap.loadGuiModule();
|
||||
wrap.loadWidgetsModule();
|
||||
auto pixmap = BitmapFactory().pixmap(iconName);
|
||||
if(!pixmap.isNull())
|
||||
return Py::new_reference_to(wrap.fromQIcon(new QIcon(pixmap)));
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sAddCommand(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* pName;
|
||||
@@ -1079,7 +1149,11 @@ PyObject* Application::sAddCommand(PyObject * /*self*/, PyObject *args)
|
||||
group = what[1];
|
||||
}
|
||||
else {
|
||||
group = module;
|
||||
boost::regex rx("/Ext/freecad/(\\w+)/");
|
||||
if (boost::regex_search(file, what, rx))
|
||||
group = what[1];
|
||||
else
|
||||
group = module;
|
||||
}
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
@@ -1131,6 +1205,9 @@ PyObject* Application::sRunCommand(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "s|i", &pName, &item))
|
||||
return NULL;
|
||||
|
||||
Gui::Command::LogDisabler d1;
|
||||
Gui::SelectionLogDisabler d2;
|
||||
|
||||
Command* cmd = Application::Instance->commandManager().getCommandByName(pName);
|
||||
if (cmd) {
|
||||
cmd->invoke(item);
|
||||
@@ -1143,6 +1220,23 @@ PyObject* Application::sRunCommand(PyObject * /*self*/, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* Application::sIsCommandActive(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* pName;
|
||||
if (!PyArg_ParseTuple(args, "s", &pName))
|
||||
return NULL;
|
||||
|
||||
Command* cmd = Application::Instance->commandManager().getCommandByName(pName);
|
||||
if (!cmd) {
|
||||
PyErr_Format(Base::BaseExceptionFreeCADError, "No such command '%s'", pName);
|
||||
return 0;
|
||||
}
|
||||
PY_TRY {
|
||||
return Py::new_reference_to(Py::Boolean(cmd->isActive()));
|
||||
}PY_CATCH;
|
||||
}
|
||||
|
||||
|
||||
PyObject* Application::sListCommands(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
@@ -1168,6 +1262,10 @@ PyObject* Application::sDoCommand(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "s", &sCmd))
|
||||
return NULL;
|
||||
|
||||
Gui::Command::LogDisabler d1;
|
||||
Gui::SelectionLogDisabler d2;
|
||||
|
||||
Gui::Command::printPyCaller();
|
||||
Gui::Application::Instance->macroManager()->addLine(MacroManager::App, sCmd);
|
||||
|
||||
PyObject *module, *dict;
|
||||
@@ -1189,6 +1287,10 @@ PyObject* Application::sDoCommandGui(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "s", &sCmd))
|
||||
return NULL;
|
||||
|
||||
Gui::Command::LogDisabler d1;
|
||||
Gui::SelectionLogDisabler d2;
|
||||
|
||||
Gui::Command::printPyCaller();
|
||||
Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui, sCmd);
|
||||
|
||||
PyObject *module, *dict;
|
||||
@@ -1325,6 +1427,19 @@ PyObject* Application::sGetMarkerIndex(PyObject * /*self*/, PyObject *args)
|
||||
}PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* Application::sReload(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
const char *name;
|
||||
if (!PyArg_ParseTuple(args, "s", &name))
|
||||
return NULL;
|
||||
|
||||
PY_TRY {
|
||||
auto doc = Application::Instance->reopen(App::GetApplication().getDocument(name));
|
||||
if(doc)
|
||||
return doc->getPyObject();
|
||||
}PY_CATCH;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sAddDocObserver(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user