0000672: Loading Example Drawing extraction crashes at Baseclass.cpp line 115

This commit is contained in:
wmayer 2012-04-16 15:57:10 +02:00
parent 5c3b7725fe
commit 2e3e3f0467
8 changed files with 70 additions and 2 deletions

View File

@ -968,6 +968,19 @@ std::list<MDIView*> Document::getMDIViews() const
return views;
}
std::list<MDIView*> Document::getMDIViewsOfType(const Base::Type& typeId) const
{
std::list<MDIView*> views;
for (std::list<BaseView*>::const_iterator it = d->baseViews.begin();
it != d->baseViews.end(); ++it) {
MDIView* view = dynamic_cast<MDIView*>(*it);
if (view && view->isDerivedFrom(typeId))
views.push_back(view);
}
return views;
}
/// send messages to the active view
bool Document::sendMsgToViews(const char* pMsg)
{

View File

@ -140,6 +140,8 @@ public:
void onRelabel(void);
/// returns a list of all attached MDI views
std::list<MDIView*> getMDIViews() const;
/// returns a list of all MDI views of a certain type
std::list<MDIView*> getMDIViewsOfType(const Base::Type& typeId) const;
//@}
/** @name View provider handling */

View File

@ -68,6 +68,16 @@
<UserDocu>deprecated -- use ActiveView</UserDocu>
</Documentation>
</Methode>
<Methode Name="mdiViewsOfType" Const="true">
<Documentation>
<UserDocu>Return a list if mdi views of a given type</UserDocu>
</Documentation>
</Methode>
<Methode Name="sendMsgToViews">
<Documentation>
<UserDocu>Send a message to all views of the document</UserDocu>
</Documentation>
</Methode>
<Attribute Name="ActiveObject" ReadOnly="false">
<Documentation>
<UserDocu>The active object of the document</UserDocu>

View File

@ -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<Gui::MDIView*> views = getDocumentPtr()->getMDIViewsOfType(type);
Py::List list;
for (std::list<Gui::MDIView*>::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();

View File

@ -57,6 +57,7 @@
#include "DrawingView.h"
#include <Base/Stream.h>
#include <Base/gzstream.h>
#include <Base/PyObjectBase.h>
#include <Gui/FileDialog.h>
#include <Gui/WaitCursor.h>
@ -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"

View File

@ -93,6 +93,7 @@ public:
void printPdf();
void printPreview();
void print(QPrinter* printer);
PyObject* getPyObject();
protected:
void contextMenuEvent(QContextMenuEvent *event);

View File

@ -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");
}

View File

@ -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")