MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / sSetActiveDocument

Method sSetActiveDocument

src/Gui/ApplicationPy.cpp:837–880  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

835}
836
837PyObject* Gui::ApplicationPy::sSetActiveDocument(PyObject* /*self*/, PyObject* args)
838{
839 Document* pcDoc = nullptr;
840
841 do {
842 char* pstr = nullptr;
843 if (PyArg_ParseTuple(args, "s", &pstr)) {
844 pcDoc = Application::Instance->getDocument(pstr);
845 if (!pcDoc) {
846 PyErr_Format(PyExc_NameError, "Unknown document '%s'", pstr);
847 return nullptr;
848 }
849 break;
850 }
851
852 PyErr_Clear();
853 PyObject* doc = nullptr;
854 if (PyArg_ParseTuple(args, "O!", &(App::DocumentPy::Type), &doc)) {
855 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
856 pcDoc = Application::Instance->getDocument(
857 static_cast<App::DocumentPy*>(doc)->getDocumentPtr()
858 );
859 if (!pcDoc) {
860 PyErr_Format(PyExc_KeyError, "Unknown document instance");
861 return nullptr;
862 }
863 break;
864 }
865 } while (false);
866
867 if (!pcDoc) {
868 PyErr_SetString(PyExc_TypeError, "Either string or App.Document expected");
869 return nullptr;
870 }
871
872 requirePythonMainThread("FreeCADGui.setActiveDocument");
873
874 if (Application::Instance->activeDocument() != pcDoc) {
875 Gui::MDIView* view = pcDoc->getActiveView();
876 getMainWindow()->setActiveWindow(view);
877 }
878
879 Py_Return;
880}
881
882PyObject* ApplicationPy::sGetDocument(PyObject* /*self*/, PyObject* args)
883{

Callers

nothing calls this directly

Calls 6

requirePythonMainThreadFunction · 0.85
activeDocumentMethod · 0.80
getMainWindowFunction · 0.70
getDocumentMethod · 0.45
getActiveViewMethod · 0.45
setActiveWindowMethod · 0.45

Tested by

no test coverage detected