+ check returned mdi view to be of the requested type

This commit is contained in:
wmayer 2015-09-16 16:15:19 +02:00
parent b9797ec92a
commit 739e643f2f
5 changed files with 53 additions and 49 deletions

View File

@ -1287,19 +1287,6 @@ Gui::MDIView* Document::getEditingViewOfViewProvider(Gui::ViewProvider* vp) cons
return 0;
}
std::list<MDIView*> Document::getViewsOfViewProvider(Gui::ViewProvider* vp) const
{
std::list<MDIView*> views;
std::list<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
for (std::list<MDIView*>::const_iterator it = mdis.begin(); it != mdis.end(); ++it) {
View3DInventor* view = static_cast<View3DInventor*>(*it);
if (view->getViewer()->hasViewProvider(vp))
views.push_back(*it);
}
return views;
}
//--------------------------------------------------------------------------
// UNDO REDO transaction handling
//--------------------------------------------------------------------------

View File

@ -150,7 +150,6 @@ public:
Gui::MDIView* getActiveView(void) const;
Gui::MDIView* getEditingViewOfViewProvider(Gui::ViewProvider*) const;
Gui::MDIView* getViewOfViewProvider(Gui::ViewProvider*) const;
std::list<MDIView*> getViewsOfViewProvider(Gui::ViewProvider*) const;
/// Create a new view
void createView(const Base::Type& typeId);
/** send messages to the active view

View File

@ -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<MDIView*> views = pGuiDoc->getViewsOfViewProvider(const_cast<ViewProviderDocumentObject*>(this));
// is the active window a 3d view and does it contain this view provider
std::list<MDIView*>::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<ViewProviderDocumentObject*>(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<ViewProviderDocumentObject*>(this));
if (!mdi) {
mdi = pGuiDoc->getViewOfViewProvider(const_cast<ViewProviderDocumentObject*>(this));
}
return mdi;
}
SoNode* ViewProviderDocumentObject::findFrontRootOfType(const SoType& type) const
{
// first get the document this object is part of and get its GUI counterpart

View File

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

View File

@ -1327,8 +1327,10 @@ Base::Vector3d ViewProviderSketch::seekConstraintPosition(const Base::Vector3d &
const SoNode *constraint)
{
assert(edit);
Gui::View3DInventor* mdi = qobject_cast<Gui::View3DInventor*>(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<Gui::View3DInventor *>(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<Gui::View3DInventor*>(this->getEditingView());
Gui::MDIView *mdi = this->getActiveView();
Gui::View3DInventor *view = qobject_cast<Gui::View3DInventor*>(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<Gui::View3DInventor*>(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<Gui::View3DInventor *>(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<Gui::View3DInventor*>(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<Gui::View3DInventor *>(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<Gui::View3DInventor*>(this->getEditingView());
if (mdi) {
mdi->getViewer()->redraw();
Gui::MDIView *mdi = this->getActiveView();
if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
static_cast<Gui::View3DInventor *>(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();
}
}
}