diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 81c0a7d0d..ed58b9f62 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -968,6 +968,19 @@ std::list Document::getMDIViews() const return views; } +std::list Document::getMDIViewsOfType(const Base::Type& typeId) const +{ + std::list views; + for (std::list::const_iterator it = d->baseViews.begin(); + it != d->baseViews.end(); ++it) { + MDIView* view = dynamic_cast(*it); + if (view && view->isDerivedFrom(typeId)) + views.push_back(view); + } + + return views; +} + /// send messages to the active view bool Document::sendMsgToViews(const char* pMsg) { diff --git a/src/Gui/Document.h b/src/Gui/Document.h index 55053c8d5..9382c33bd 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -140,6 +140,8 @@ public: void onRelabel(void); /// returns a list of all attached MDI views std::list getMDIViews() const; + /// returns a list of all MDI views of a certain type + std::list getMDIViewsOfType(const Base::Type& typeId) const; //@} /** @name View provider handling */ diff --git a/src/Gui/DocumentPy.xml b/src/Gui/DocumentPy.xml index e73893f10..75ac71a54 100644 --- a/src/Gui/DocumentPy.xml +++ b/src/Gui/DocumentPy.xml @@ -68,6 +68,16 @@ deprecated -- use ActiveView + + + Return a list if mdi views of a given type + + + + + Send a message to all views of the document + + The active object of the document diff --git a/src/Gui/DocumentPyImp.cpp b/src/Gui/DocumentPyImp.cpp index bc05a0e21..4d30e7cc5 100644 --- a/src/Gui/DocumentPyImp.cpp +++ b/src/Gui/DocumentPyImp.cpp @@ -201,6 +201,39 @@ PyObject* DocumentPy::activeView(PyObject *args) } PY_CATCH; } +PyObject* DocumentPy::mdiViewsOfType(PyObject *args) +{ + char* sType; + if (!PyArg_ParseTuple(args, "s", &sType)) // convert args: Python->C + return NULL; // NULL triggers exception + + Base::Type type = Base::Type::fromName(sType); + if (type == Base::Type::badType()) { + PyErr_Format(PyExc_Exception, "'%s' is not a valid type", sType); + return NULL; + } + + PY_TRY { + std::list views = getDocumentPtr()->getMDIViewsOfType(type); + Py::List list; + for (std::list::iterator it = views.begin(); it != views.end(); ++it) + list.append(Py::asObject((*it)->getPyObject())); + return Py::new_reference_to(list); + } PY_CATCH; +} + +PyObject* DocumentPy::sendMsgToViews(PyObject *args) +{ + char* msg; + if (!PyArg_ParseTuple(args, "s", &msg)) // convert args: Python->C + return NULL; // NULL triggers exception + + PY_TRY { + getDocumentPtr()->sendMsgToViews(msg); + Py_Return; + } PY_CATCH; +} + Py::Object DocumentPy::getActiveObject(void) const { App::DocumentObject *object = getDocumentPtr()->getDocument()->getActiveObject(); diff --git a/src/Mod/Drawing/Gui/DrawingView.cpp b/src/Mod/Drawing/Gui/DrawingView.cpp index 7ae3574d2..6e9923a51 100644 --- a/src/Mod/Drawing/Gui/DrawingView.cpp +++ b/src/Mod/Drawing/Gui/DrawingView.cpp @@ -57,6 +57,7 @@ #include "DrawingView.h" #include #include +#include #include #include @@ -434,4 +435,9 @@ void DrawingView::viewAll() m_view->fitInView(m_view->scene()->sceneRect(), Qt::KeepAspectRatio); } +PyObject* DrawingView::getPyObject() +{ + Py_Return; +} + #include "moc_DrawingView.cpp" diff --git a/src/Mod/Drawing/Gui/DrawingView.h b/src/Mod/Drawing/Gui/DrawingView.h index c7f161396..47f8ee852 100644 --- a/src/Mod/Drawing/Gui/DrawingView.h +++ b/src/Mod/Drawing/Gui/DrawingView.h @@ -93,6 +93,7 @@ public: void printPdf(); void printPreview(); void print(QPrinter* printer); + PyObject* getPyObject(); protected: void contextMenuEvent(QContextMenuEvent *event); diff --git a/src/Mod/Part/App/TopoShapeShellPyImp.cpp b/src/Mod/Part/App/TopoShapeShellPyImp.cpp index e50d82ada..fc186b0ce 100644 --- a/src/Mod/Part/App/TopoShapeShellPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeShellPyImp.cpp @@ -100,6 +100,9 @@ int TopoShapeShellPy::PyInit(PyObject* args, PyObject* /*kwd*/) shape = sewShell.ApplySewing(shell); } + if (shape.IsNull()) + Standard_Failure::Raise("Shape is null"); + if (shape.ShapeType() != TopAbs_SHELL) Standard_Failure::Raise("Shape is not a shell"); } diff --git a/src/Mod/Start/StartPage/LoadDrawingExample.py b/src/Mod/Start/StartPage/LoadDrawingExample.py index 654a71f82..5067e60cf 100644 --- a/src/Mod/Start/StartPage/LoadDrawingExample.py +++ b/src/Mod/Start/StartPage/LoadDrawingExample.py @@ -1,5 +1,5 @@ import FreeCAD,FreeCADGui FreeCADGui.activateWorkbench("DrawingWorkbench") FreeCAD.open(FreeCAD.getResourceDir()+"examples/DrawingExample.FCStd") -FreeCADGui.SendMsgToActiveView("ViewFit") -FreeCADGui.activeDocument().activeView().viewAxometric() +FreeCADGui.activeDocument().sendMsgToViews("ViewFit") +FreeCADGui.activeDocument().sendMsgToViews("ViewAxo")