From: nds Date: Sat, 12 Sep 2015 08:40:31 +0000 (+0300) Subject: Issue #956 Fatal error as result of action without OCC scene X-Git-Tag: V_1.4.0_beta4~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6ccac2f149c55637e4ed34b0ac203593ae3b0453;p=modules%2Fshaper.git Issue #956 Fatal error as result of action without OCC scene --- diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index c117e8ed0..55abdb503 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -109,9 +109,9 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrs& th Handle(SelectMgr_Filter) aFilter = anIt.Value(); aValid = aFilter->IsOk(anOwner); } - if (!isActivated) - activateFilters(false); } + if (!isActivated) + activateFilters(false); } // removes created owner diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index 17c0574e4..0d2cdaa76 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -191,8 +191,11 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) aResMgr->setValue("Study", "store_positions", false); // Synchronize displayed objects - if (mySelector && mySelector->viewer()) { - Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext(); + Handle(AIS_InteractiveContext) aContext; + if (mySelector && mySelector->viewer()) + aContext = mySelector->viewer()->getAISContext(); + + if (!aContext.IsNull()) { XGUI_Displayer* aDisp = myWorkshop->displayer(); QObjectPtrList aObjList = aDisp->displayedObjects(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 9cb9af831..5713d7dec 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -801,17 +801,16 @@ void PartSet_Module::onViewTransformed(int theTrsfType) // if the operation is panning or rotate or panglobal then do nothing if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4)) return; - ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); + if (aContext.IsNull()) + return; + //Handle(V3d_View) aView = aViewer->activeView(); XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); XGUI_Workshop* aWorkshop = aConnector->workshop(); XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); - if (aContext.IsNull()) - return; - Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer(); Handle(V3d_View) aView; double aScale = 0; @@ -1068,7 +1067,11 @@ void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*) { // z layer is created for all started operations in order to visualize operation AIS presentation // over the object - Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext.IsNull()) + return; + + Handle(V3d_Viewer) aViewer = aContext->CurrentViewer(); if (myVisualLayerId == 0) { if (myVisualLayerId == 0) aViewer->AddZLayer(myVisualLayerId); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 4a84b0cc1..9bccd1ab0 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -373,11 +373,10 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE return; Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); - if (aContext.IsNull()) - return; - // MoveTo in order to highlight current object - aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView()); - + if (!aContext.IsNull()) { + // MoveTo in order to highlight current object + aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView()); + } // Remember highlighted objects for editing ModuleBase_ISelection* aSelect = aWorkshop->selection(); @@ -1100,36 +1099,36 @@ void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature, ModuleBase_IViewer* aViewer = theWorkshop->viewer(); Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); - if (aContext.IsNull()) - return; - XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + if (!aContext.IsNull()) { + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); - std::list aResults = theFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) - { - ResultPtr aResult = *aIt; - AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult); - if (aAISObj.get() == NULL) - continue; - Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + std::list aResults = theFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); - if (anOwner->Selectable() != anAISIO) - continue; - getAttributesOrResults(anOwner, theFeature, theSketch, aResult, - aSelectedAttributes, aSelectedResults); - } - for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { - Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner(); - if (anOwner.IsNull()) + ResultPtr aResult = *aIt; + AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult); + if (aAISObj.get() == NULL) continue; - if (anOwner->Selectable() != anAISIO) - continue; - getAttributesOrResults(anOwner, theFeature, theSketch, aResult, - aSelectedAttributes, aSelectedResults); + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + { + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + if (anOwner->Selectable() != anAISIO) + continue; + getAttributesOrResults(anOwner, theFeature, theSketch, aResult, + aSelectedAttributes, aSelectedResults); + } + for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { + Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner(); + if (anOwner.IsNull()) + continue; + if (anOwner->Selectable() != anAISIO) + continue; + getAttributesOrResults(anOwner, theFeature, theSketch, aResult, + aSelectedAttributes, aSelectedResults); + } } } theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults); @@ -1139,7 +1138,7 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, const FeaturePtr& theSketch, ModuleBase_IWorkshop* theWorkshop, const FeatureToSelectionMap& theSelection, - SelectMgr_IndexedMapOfOwner& anOwnersToSelect) + SelectMgr_IndexedMapOfOwner& theOwnersToSelect) { if (theFeature.get() == NULL) return; @@ -1149,9 +1148,6 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, std::set aSelectedResults = anIt.value().second; ModuleBase_IViewer* aViewer = theWorkshop->viewer(); - Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); - if (aContext.IsNull()) - return; XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); @@ -1166,7 +1162,7 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); if (!anOwner.IsNull()) - anOwnersToSelect.Add(anOwner); + theOwnersToSelect.Add(anOwner); } } @@ -1193,14 +1189,14 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch); if (aPntAttr.get() != NULL && aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) { - anOwnersToSelect.Add(anOwner); + theOwnersToSelect.Add(anOwner); } } else if (aShapeType == TopAbs_EDGE) { bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end(); if (aSelectedResults.find(aResult) != aSelectedResults.end() && - anOwnersToSelect.FindIndex(anOwner) <= 0) - anOwnersToSelect.Add(anOwner); + theOwnersToSelect.FindIndex(anOwner) <= 0) + theOwnersToSelect.Add(anOwner); } } } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3ee0ccdaa..344704de0 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -237,6 +237,7 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return aErased; + AISObjectPtr anObject = myResult2AISObjectMap[theObject]; if (anObject) { Handle(AIS_InteractiveObject) anAIS = anObject->impl(); @@ -280,7 +281,7 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) } Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aAISIO.IsNull() && !aContext.IsNull()) { + if (!aContext.IsNull() && !aAISIO.IsNull()) { // Check that the visualized shape is the same and the redisplay is not necessary // Redisplay of AIS object leads to this object selection compute and the selection // in the browser is lost @@ -342,11 +343,8 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer) arg(anInfoStr). toStdString().c_str()); #endif - if (isVisible(theObject)) { - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return; - + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull() && isVisible(theObject)) { AISObjectPtr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); @@ -371,11 +369,8 @@ void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList, void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes) { - if (!isVisible(theObject)) - return; - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) + if (aContext.IsNull() || !isVisible(theObject)) return; AISObjectPtr aAISObj = getAISObject(theObject); @@ -425,10 +420,8 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL } myActiveSelectionModes = aNewModes; Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return; // Open local context if there is no one - if (!aContext->HasOpenedContext()) + if (aContext.IsNull() || !aContext->HasOpenedContext()) return; //aContext->UseDisplayedObjects(); @@ -457,9 +450,7 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL bool XGUI_Displayer::isActive(ObjectPtr theObject) const { Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return false; - if (!isVisible(theObject)) + if (aContext.IsNull() || !isVisible(theObject)) return false; AISObjectPtr anObj = myResult2AISObjectMap[theObject]; @@ -519,7 +510,7 @@ void XGUI_Displayer::setSelected(const QList& theValues, void XGUI_Displayer::clearSelected() { Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext) { + if (!aContext.IsNull()) { aContext->UnhilightCurrents(false); aContext->ClearSelected(); } @@ -554,14 +545,15 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) void XGUI_Displayer::deactivateTrihedron() const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - - AIS_ListOfInteractive aList; - aContext->DisplayedObjects(aList, true); - AIS_ListIteratorOfListOfInteractive aIt; - for (aIt.Initialize(aList); aIt.More(); aIt.Next()) { - Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value()); - if (!aTrihedron.IsNull()) { - aContext->Deactivate(aTrihedron); + if (!aContext.IsNull()) { + AIS_ListOfInteractive aList; + aContext->DisplayedObjects(aList, true); + AIS_ListIteratorOfListOfInteractive aIt; + for (aIt.Initialize(aList); aIt.More(); aIt.Next()) { + Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value()); + if (!aTrihedron.IsNull()) { + aContext->Deactivate(aTrihedron); + } } } } @@ -569,10 +561,8 @@ void XGUI_Displayer::deactivateTrihedron() const void XGUI_Displayer::openLocalContext() { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (aContext.IsNull()) - return; // Open local context if there is no one - if (!aContext->HasOpenedContext()) { + if (!aContext.IsNull() && !aContext->HasOpenedContext()) { // Preserve selected objects //AIS_ListOfInteractive aAisList; //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) @@ -608,7 +598,7 @@ void XGUI_Displayer::openLocalContext() void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); - if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) { + if (!aContext.IsNull() && aContext->HasOpenedContext()) { // Preserve selected objects //AIS_ListOfInteractive aAisList; //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) @@ -712,34 +702,38 @@ void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode, const bool theUpdateViewer) const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - aContext->Activate(theIO, theMode, theUpdateViewer); + if (!aContext.IsNull()) { + aContext->Activate(theIO, theMode, theUpdateViewer); #ifdef DEBUG_ACTIVATE_AIS - ObjectPtr anObject = getObject(theIO); - anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); - qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); + ObjectPtr anObject = getObject(theIO); + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); #endif + } } void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (theMode == -1) - aContext->Deactivate(theIO); - else - aContext->Deactivate(theIO, theMode); + if (!aContext.IsNull()) { + if (theMode == -1) + aContext->Deactivate(theIO); + else + aContext->Deactivate(theIO, theMode); #ifdef DEBUG_DEACTIVATE_AIS - ObjectPtr anObject = getObject(theIO); - anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); - qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); + ObjectPtr anObject = getObject(theIO); + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); #endif + } } Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) { + if (!aContext.IsNull() && !aContext->HasOpenedContext()) { aContext->OpenLocalContext(); deactivateTrihedron(); aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0); @@ -751,7 +745,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() { Handle(AIS_InteractiveContext) aContext = AISContext(); - if (myAndFilter.IsNull() && !aContext.IsNull()) { + if (!aContext.IsNull() && myAndFilter.IsNull()) { myAndFilter = new SelectMgr_AndFilter(); aContext->AddFilter(myAndFilter); } @@ -763,10 +757,8 @@ bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSele { bool aDisplayed = false; Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return aDisplayed; Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); - if (!anAISIO.IsNull()) { + if (!aContext.IsNull() && !anAISIO.IsNull()) { aContext->Display(anAISIO, 0/*wireframe*/, 0, theUpdateViewer, true, AIS_DS_Displayed); aDisplayed = true; aContext->Deactivate(anAISIO); @@ -790,12 +782,12 @@ bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer) { bool aErased = false; Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return aErased; - Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); - if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) { - aContext->Remove(anAISIO, theUpdateViewer); - aErased = true; + if (!aContext.IsNull()) { + Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); + if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) { + aContext->Remove(anAISIO, theUpdateViewer); + aErased = true; + } } return aErased; } @@ -838,7 +830,7 @@ XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) con void XGUI_Displayer::deactivateSelectionFilters() { Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!myAndFilter.IsNull() && !aContext.IsNull()) { + if (!aContext.IsNull() && !myAndFilter.IsNull()) { bool aFound = false; const SelectMgr_ListOfFilter& aFilters = aContext->Filters(); SelectMgr_ListIteratorOfListOfFilter anIt(aFilters); @@ -859,12 +851,14 @@ void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilte if (aContext.IsNull() || hasSelectionFilter(theFilter)) return; - Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter(); - aCompFilter->Add(theFilter); + Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter(); + if (!aCompositeFilter.IsNull()) { + aCompositeFilter->Add(theFilter); #ifdef DEBUG_SELECTION_FILTERS - int aCount = GetFilter()->StoredFilters().Extent(); - qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str()); + int aCount = aCompositeFilter->StoredFilters().Extent(); + qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str()); #endif + } } void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) @@ -872,13 +866,15 @@ void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFi Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; + Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter(); - if (aCompositeFilter->IsIn(theFilter)) + if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) { aCompositeFilter->Remove(theFilter); #ifdef DEBUG_SELECTION_FILTERS - int aCount = GetFilter()->StoredFilters().Extent(); - qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str()); + int aCount = aCompositeFilter->StoredFilters().Extent(); + qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str()); #endif + } } bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) @@ -894,11 +890,13 @@ bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilte if (theFilter.Access() == aIt.Value().Access()) aFilterFound = true; } - Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter(); - const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters(); - for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) { - if (theFilter.Access() == aIt.Value().Access()) - aFilterFound = true; + Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter(); + if (!aCompositeFilter.IsNull()) { + const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters(); + for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) { + if (theFilter.Access() == aIt.Value().Access()) + aFilterFound = true; + } } return aFilterFound; } @@ -908,7 +906,10 @@ void XGUI_Displayer::removeFilters() Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; - GetFilter()->Clear(); + + Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter(); + if (!aCompositeFilter.IsNull()) + aCompositeFilter->Clear(); } void XGUI_Displayer::showOnly(const QObjectPtrList& theList) diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index a8cd9cc3b..edc113683 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -64,10 +64,7 @@ Handle(AIS_InteractiveObject) XGUI_Selection::getIO(const ModuleBase_ViewerPrs& void XGUI_Selection::getSelectedInViewer(QList& thePresentations) const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (aContext.IsNull()) - return; - - if (aContext->HasOpenedContext()) { + if (!aContext.IsNull() && aContext->HasOpenedContext()) { QList aSelectedIds; // Remember of selected address in order to avoid duplicates for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { ModuleBase_ViewerPrs aPrs; @@ -132,11 +129,13 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs, QList XGUI_Selection::getHighlighted() const { - QList aSelectedIds; // Remember of selected address in order to avoid duplicates QList aPresentations; - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext.IsNull()) + return aPresentations; + + QList aSelectedIds; // Remember of selected address in order to avoid duplicates + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { ModuleBase_ViewerPrs aPrs; Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive(); @@ -195,10 +194,13 @@ QModelIndexList XGUI_Selection::selectedIndexes() const //************************************************************** void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const { - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); theList.Clear(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) - theList.Append(aContext->SelectedInteractive()); + + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (!aContext.IsNull()) { + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + theList.Append(aContext->SelectedInteractive()); + } } //************************************************************** @@ -221,6 +223,9 @@ void XGUI_Selection::selectedShapes(NCollection_List& theList, { theList.Clear(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext.IsNull()) + return; + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { TopoDS_Shape aShape = aContext->SelectedShape(); if (!aShape.IsNull()) { @@ -240,9 +245,10 @@ void XGUI_Selection::selectedShapes(NCollection_List& theList, void XGUI_Selection::selectedOwners(SelectMgr_IndexedMapOfOwner& theSelectedOwners) const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - theSelectedOwners.Add(aContext->SelectedOwner()); + if (!aContext.IsNull()) { + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + theSelectedOwners.Add(aContext->SelectedOwner()); + } } } @@ -251,8 +257,7 @@ void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject SelectMgr_IndexedMapOfOwner& theOwners) const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - - if (theObject.IsNull() || aContext.IsNull()) + if (aContext.IsNull() || theObject.IsNull()) return; TColStd_ListOfInteger aModes; diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 05c86e20e..3a13e3213 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -50,12 +50,14 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the selection()->selectedOwners(aSelectedOwners); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) { - Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i); - if (aSelectedOwners.FindIndex(anOwner) > 0) - continue; + if (!aContext.IsNull()) { + for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i); + if (aSelectedOwners.FindIndex(anOwner) > 0) + continue; - aContext->AddOrRemoveSelected(anOwner, isUpdateViewer); + aContext->AddOrRemoveSelected(anOwner, isUpdateViewer); + } } } @@ -63,6 +65,9 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext.IsNull()) + return; + const SelectMgr_ListOfFilter& aFilters = aContext->Filters(); SelectMgr_IndexedMapOfOwner anOwnersToDeselect; @@ -99,11 +104,13 @@ void XGUI_SelectionMgr::onViewerSelection() { QObjectPtrList aFeatures; Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO); - if (aResult) - aFeatures.append(aResult); + if (!aContext.IsNull()) { + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO); + if (aResult) + aFeatures.append(aResult); + } } bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);