diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 0e1657722..d00965cb5 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1287,19 +1287,6 @@ Gui::MDIView* Document::getEditingViewOfViewProvider(Gui::ViewProvider* vp) cons return 0; } -std::list Document::getViewsOfViewProvider(Gui::ViewProvider* vp) const -{ - std::list views; - std::list mdis = getMDIViewsOfType(View3DInventor::getClassTypeId()); - for (std::list::const_iterator it = mdis.begin(); it != mdis.end(); ++it) { - View3DInventor* view = static_cast(*it); - if (view->getViewer()->hasViewProvider(vp)) - views.push_back(*it); - } - - return views; -} - //-------------------------------------------------------------------------- // UNDO REDO transaction handling //-------------------------------------------------------------------------- diff --git a/src/Gui/Document.h b/src/Gui/Document.h index dc96a7df1..0648fcb63 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -150,7 +150,6 @@ public: Gui::MDIView* getActiveView(void) const; Gui::MDIView* getEditingViewOfViewProvider(Gui::ViewProvider*) const; Gui::MDIView* getViewOfViewProvider(Gui::ViewProvider*) const; - std::list getViewsOfViewProvider(Gui::ViewProvider*) const; /// Create a new view void createView(const Base::Type& typeId); /** send messages to the active view diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index b0085b8e1..a5700d4ac 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -161,20 +161,7 @@ Gui::MDIView* ViewProviderDocumentObject::getActiveView() const { App::Document* pAppDoc = pcObject->getDocument(); Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc); - - MDIView* active = getMainWindow()->activeWindow(); - std::list views = pGuiDoc->getViewsOfViewProvider(const_cast(this)); - - // is the active window a 3d view and does it contain this view provider - std::list::iterator it = std::find(views.begin(), views.end(), active); - if (it != views.end()) - return *it; - // if there is a 3d view containing this view provider return the first one - else if (!views.empty()) - return views.front(); - // no 3d view found containing this view provider - else - return 0; + return pGuiDoc->getActiveView(); } Gui::MDIView* ViewProviderDocumentObject::getEditingView() const @@ -184,6 +171,19 @@ Gui::MDIView* ViewProviderDocumentObject::getEditingView() const return pGuiDoc->getEditingViewOfViewProvider(const_cast(this)); } +Gui::MDIView* ViewProviderDocumentObject::getInventorView() const +{ + App::Document* pAppDoc = pcObject->getDocument(); + Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc); + + Gui::MDIView* mdi = pGuiDoc->getEditingViewOfViewProvider(const_cast(this)); + if (!mdi) { + mdi = pGuiDoc->getViewOfViewProvider(const_cast(this)); + } + + return mdi; +} + SoNode* ViewProviderDocumentObject::findFrontRootOfType(const SoType& type) const { // first get the document this object is part of and get its GUI counterpart diff --git a/src/Gui/ViewProviderDocumentObject.h b/src/Gui/ViewProviderDocumentObject.h index 165d4eef3..2845eb1ff 100644 --- a/src/Gui/ViewProviderDocumentObject.h +++ b/src/Gui/ViewProviderDocumentObject.h @@ -90,10 +90,24 @@ public: //@} protected: - /// Get the active mdi view of a view provider + /*! Get the active mdi view of the document this view provider is part of. + @note The returned mdi view doesn't need to be a 3d view but can be e.g. + an image view, an SVG view or something else. + */ Gui::MDIView* getActiveView() const; - /// Get the editing mdi view of a view provider in edit mode + /*! Get the mdi view of the document this view provider is part of and + that is in editing mode. + @note In case there is no mdi view in editing mode 0 is returned. + If a value different to 0 is returned it is guaranteed to be a 3d view. + */ Gui::MDIView* getEditingView() const; + /*! Get any mdi view of the document this view provider is part of. + In case there is an mdi view in editing mode that contains this + view provider that mdi view is returned. Otherwise any other + 3d view that contains this view provider is returned. + If a value different to 0 is returned it is guaranteed to be a 3d view. + */ + Gui::MDIView* getInventorView() const; /// Gets called by the container whenever a property has been changed virtual void onChanged(const App::Property* prop); /** Searches in all view providers that are attached to an object that diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 0b0f18913..5721d5b80 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1327,8 +1327,10 @@ Base::Vector3d ViewProviderSketch::seekConstraintPosition(const Base::Vector3d & const SoNode *constraint) { assert(edit); - Gui::View3DInventor* mdi = qobject_cast(this->getEditingView()); - Gui::View3DInventorViewer *viewer = mdi->getViewer(); + Gui::MDIView *mdi = this->getEditingView(); + if (!(mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId()))) + return Base::Vector3d(0, 0, 0); + Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); @@ -1814,7 +1816,8 @@ SbVec3s ViewProviderSketch::getDisplayedSize(const SoImage *iconPtr) const void ViewProviderSketch::centerSelection() { - Gui::View3DInventor* view = qobject_cast(this->getEditingView()); + Gui::MDIView *mdi = this->getActiveView(); + Gui::View3DInventor *view = qobject_cast(mdi); if (!view || !edit) return; @@ -2551,10 +2554,13 @@ void ViewProviderSketch::drawConstraintIcons() SbVec3f pos0(startingpoint.x,startingpoint.y,startingpoint.z); SbVec3f pos1(endpoint.x,endpoint.y,endpoint.z); - Gui::View3DInventor* mdi = qobject_cast(this->getEditingView()); - Gui::View3DInventorViewer *viewer = mdi->getViewer(); + Gui::MDIView *mdi = this->getEditingView(); + if (!(mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId()))) + return; + Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); SoCamera* pCam = viewer->getSoRenderManager()->getCamera(); - if (!pCam) return; + if (!pCam) + return; try { SbViewVolume vol = pCam->getViewVolume(); @@ -2918,9 +2924,9 @@ void ViewProviderSketch::drawTypicalConstraintIcon(const constrIconQueueItem &i) float ViewProviderSketch::getScaleFactor() { - Gui::View3DInventor* mdi = qobject_cast(this->getEditingView()); - if (mdi) { - Gui::View3DInventorViewer *viewer = mdi->getViewer(); + Gui::MDIView *mdi = this->getEditingView(); + if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { + Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); return viewer->getSoRenderManager()->getCamera()->getViewVolume(viewer->getSoRenderManager()->getCamera()->aspectRatio.getValue()).getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / 3; } else { @@ -3914,10 +3920,9 @@ Restart: } } - // Get Bounding box dimensions for Datum text - Gui::View3DInventor* mdi = qobject_cast(this->getEditingView()); - if (mdi) { - mdi->getViewer()->redraw(); + Gui::MDIView *mdi = this->getActiveView(); + if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { + static_cast(mdi)->getViewer()->redraw(); } } @@ -4117,18 +4122,17 @@ void ViewProviderSketch::updateData(const App::Property *prop) // Because a solve is mandatory to any addition (at least to update the DoF of the solver), // only when the solver geometry is the same in number than the sketch geometry an update // should trigger a redraw. This reduces even more the number of redraws per insertion of geometry - - // solver information is also updated when no matching geometry, so that if a solving fails - // this failed solving info is presented to the user - UpdateSolverInformation(); // just update the solver window with the last SketchObject solving information - + + // solver information is also updated when no matching geometry, so that if a solving fails + // this failed solving info is presented to the user + UpdateSolverInformation(); // just update the solver window with the last SketchObject solving information + if(getSketchObject()->getExternalGeometryCount()+getSketchObject()->getHighestCurveIndex() + 1 == getSketchObject()->getSolvedSketch().getGeometrySize()) { draw(false); signalConstraintsChanged(); signalElementsChanged(); - } } }