From 61376ef135bec07a334be1d8ec99b3c858920d2c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 1 May 2016 15:44:02 +0200 Subject: [PATCH] + improve whitespaces + fix sequence protocol and fix crash --- src/Gui/Application.cpp | 1 + src/Gui/Application.h | 3 +-- src/Gui/ApplicationPy.cpp | 7 +++---- src/Gui/SplitView3DInventor.cpp | 32 ++++++++++++++++++++------------ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 9b5549d58..b414ad14b 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -439,6 +439,7 @@ Application::Application(bool GUIenabled) PythonStdin ::init_type(); View3DInventorPy ::init_type(); View3DInventorViewerPy ::init_type(); + AbstractSplitViewPy ::init_type(); d = new ApplicationP; diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 031cf4dd7..2f7a06d41 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -241,11 +241,10 @@ public: PYFUNCDEF_S(sDoCommand); PYFUNCDEF_S(sDoCommandGui); PYFUNCDEF_S(sAddModule); - + PYFUNCDEF_S(sShowDownloads); PYFUNCDEF_S(sShowPreferences); - PYFUNCDEF_S(sCreateViewer); static PyMethodDef Methods[]; diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index f37875fdd..23adf1c33 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -171,8 +171,8 @@ PyMethodDef Application::Methods[] = { "showPreferences([string,int]) -> None\n\n" "Shows the preferences window. If string and int are provided, the given page index in the given group is shown."}, {"createViewer", (PyCFunction) Application::sCreateViewer,1, - "createViewer([int]) -> View3DInventor/SplitView3DInventor\n\n" - "shows and returns a viewer. If the integer argument is given and > 1: -> splitViewer"}, + "createViewer([int]) -> View3DInventor/SplitView3DInventor\n\n" + "shows and returns a viewer. If the integer argument is given and > 1: -> splitViewer"}, {NULL, NULL} /* Sentinel */ }; @@ -1114,7 +1114,6 @@ PyObject* Application::sShowPreferences(PyObject * /*self*/, PyObject *args,PyOb return Py_None; } - PyObject* Application::sCreateViewer(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { @@ -1138,4 +1137,4 @@ PyObject* Application::sCreateViewer(PyObject * /*self*/, PyObject *args,PyObjec } } return Py_None; -} \ No newline at end of file +} diff --git a/src/Gui/SplitView3DInventor.cpp b/src/Gui/SplitView3DInventor.cpp index a1e7ff560..30077bdbb 100644 --- a/src/Gui/SplitView3DInventor.cpp +++ b/src/Gui/SplitView3DInventor.cpp @@ -374,11 +374,6 @@ void AbstractSplitView::setOverrideCursor(const QCursor& aCursor) PyObject *AbstractSplitView::getPyObject(void) { - static bool init = false; - if (!init) { - init = true; - AbstractSplitViewPy::init_type(); - } if (!_viewerPy) _viewerPy = new AbstractSplitViewPy(this); Py_INCREF(_viewerPy); @@ -392,7 +387,7 @@ void AbstractSplitView::setPyObject(PyObject *) int AbstractSplitView::getSize() { - return _viewer.size(); + return static_cast(_viewer.size()); } // ------------------------------------------------------ @@ -428,7 +423,7 @@ AbstractSplitViewPy::~AbstractSplitViewPy() void AbstractSplitViewPy::testExistence() { - if (!(_view and _view->getViewer(0))) + if (!(_view && _view->getViewer(0))) throw Py::Exception("Object already deleted"); } @@ -447,6 +442,7 @@ Py::Object AbstractSplitViewPy::fitAll(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewFit", 0); } @@ -467,6 +463,7 @@ Py::Object AbstractSplitViewPy::viewBottom(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewBottom", 0); } @@ -488,6 +485,7 @@ Py::Object AbstractSplitViewPy::viewFront(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewFront", 0); } @@ -509,6 +507,7 @@ Py::Object AbstractSplitViewPy::viewLeft(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewLeft", 0); } @@ -530,6 +529,7 @@ Py::Object AbstractSplitViewPy::viewRear(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewRear", 0); } @@ -551,6 +551,7 @@ Py::Object AbstractSplitViewPy::viewRight(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewRight", 0); } @@ -572,6 +573,7 @@ Py::Object AbstractSplitViewPy::viewTop(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewTop", 0); } @@ -593,6 +595,7 @@ Py::Object AbstractSplitViewPy::viewAxometric(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); testExistence(); + try { _view->onMsg("ViewAxo", 0); } @@ -615,8 +618,12 @@ Py::Object AbstractSplitViewPy::getViewer(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "i", &viewIndex)) throw Py::Exception(); testExistence(); + try { - return Py::Object(_view->getViewer(viewIndex)->getPyObject()); + Gui::View3DInventorViewer* view = _view->getViewer(viewIndex); + if (!view) + throw Py::IndexError("Index out of range"); + return Py::Object(view->getPyObject()); } catch (const Base::Exception& e) { throw Py::Exception(e.what()); @@ -634,14 +641,15 @@ Py::Object AbstractSplitViewPy::getViewer(const Py::Tuple& args) Py::Object AbstractSplitViewPy::sequence_item(ssize_t viewIndex) { testExistence(); - if (viewIndex >= _view->getSize() or viewIndex < 0) - throw Py::Exception("Index out of range"); + if (viewIndex >= _view->getSize() || viewIndex < 0) + throw Py::IndexError("Index out of range"); PyObject* viewer = _view->getViewer(viewIndex)->getPyObject(); return Py::Object(viewer); } int AbstractSplitViewPy::sequence_length() { + testExistence(); return _view->getSize(); } @@ -658,6 +666,7 @@ Py::Object AbstractSplitViewPy::close(const Py::Tuple& args) return Py::None(); } + // ------------------------------------------------------ TYPESYSTEM_SOURCE_ABSTRACT(Gui::SplitView3DInventor, Gui::AbstractSplitView); @@ -695,8 +704,7 @@ SplitView3DInventor::SplitView3DInventor(int views, Gui::Document* pcDocument, Q case View3DInventorViewer::None: default: break; - } - + } QSplitter* mainSplitter=0; // minimal 2 views