// Created on: 1997-01-29 // Created by: Robert COUBLANC // Copyright (c) 1997-1999 Matra Datavision // Copyright (c) 1999-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #define IMP051001 //GG Adds SetZDetected() and ZDetected() methods #include #include #include #include #include #include #include #include #include #include #include //======================================================================= //function : OpenLocalContext //purpose : //======================================================================= Standard_Integer AIS_InteractiveContext:: OpenLocalContext(const Standard_Boolean UseDisplayedObjects, const Standard_Boolean AllowShapeDecomposition, const Standard_Boolean AcceptEraseOfTemporary, const Standard_Boolean /*BothViewers*/) { // the entities eventually detected just before the context was opened are unhighlighted... if(!IsCurrent(myLastPicked)){ if(!myLastPicked.IsNull()){ Standard_Integer HiMod = myLastPicked->HasHilightMode()?myLastPicked->HilightMode():0; myMainPM->Unhighlight(myLastPicked,HiMod); }} if(!mylastmoveview.IsNull()){ if(myCurLocalIndex>0) myLocalContexts(myCurLocalIndex)->UnhilightLastDetected(mylastmoveview); } // entities connected to dynamic selection at neutral point are set to 0. myLastinMain.Nullify(); myLastPicked.Nullify(); myWasLastMain = Standard_True; Standard_Integer untilnow = myCurLocalIndex; myCurLocalIndex = HighestIndex() + 1; Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex, UseDisplayedObjects, AllowShapeDecomposition, AcceptEraseOfTemporary); // the AIS_LocalContext bind itself to myLocalContexts // because procedures performed in AIS_LocalContext constructor // already may access myLocalContexts(myCurLocalIndex) (like methods AIS_LocalContext::IsSelected()). //myLocalContexts.Bind (myCurLocalIndex, NewLocal); NewLocal->MainSelector()->Set ((myLocalContexts.Extent() > 1) ? myLocalContexts (untilnow)->MainSelector()->Projector() : myMainSel->Projector()); NewLocal->MainSelector()->UpdateConversion(); #ifdef DEB cout<<"\tOpen Local Context No "<HasSameProjector(myMainSel->Projector())); myLocalContexts(myCurLocalIndex)->Terminate( updateviewer ); myLocalContexts.UnBind(myCurLocalIndex); myCurLocalIndex = 0; ResetOriginalState(Standard_False); if(updateproj) myMainSel->UpdateConversion(); else{ myMainSel->UpdateSort(); } if(debugmode) cout<<"No More Opened Local Context "<MainSelector(); myLocalContexts(GoodIndex)->Terminate(); myLocalContexts.UnBind(GoodIndex); // the current is closed... if(GoodIndex==myCurLocalIndex){ myCurLocalIndex = HighestIndex(); const Handle(AIS_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex); if (!LocCtx->HasSameProjector (VS->Projector())) { LocCtx->MainSelector()->UpdateConversion(); } } else if(debugmode) cout<<"a No Current Local Context WasClosed"<Update(); } //======================================================================= //function : CloseAllContexts //purpose : //======================================================================= void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer) { while(!myLocalContexts.IsEmpty()){ CloseLocalContext(myCurLocalIndex,Standard_False); } ResetOriginalState(Standard_False); myMainSel->UpdateSort(); if(updateviewer) myMainVwr->Update(); } //======================================================================= //function : IndexOfCurrentLocal //purpose : //======================================================================= Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const { return myCurLocalIndex; } //======================================================================= //function : ClearLocalContext //purpose : //======================================================================= void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode) { if (!HasOpenedContext()) return; myLocalContexts(myCurLocalIndex)->Clear(aMode); } //======================================================================= //function : HighestIndex //purpose : //======================================================================= Standard_Integer AIS_InteractiveContext::HighestIndex() const { AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts); Standard_Integer HiInd = 0; for(;It.More();It.Next()) HiInd = (It.Key()>HiInd) ? It.Key() : HiInd; return HiInd; } //======================================================================= //function : Activate //purpose : //======================================================================= void AIS_InteractiveContext:: Activate(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Integer aMode) { if(!HasOpenedContext()){ if(!myObjects.IsBound(anIObj)) return; const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj); if(STAT->GraphicStatus()==AIS_DS_Displayed) mgrSelector->Activate(anIObj,aMode,myMainSel); STAT ->AddSelectionMode(aMode); } else{ myLocalContexts(myCurLocalIndex)->ActivateMode(anIObj,aMode); } } //======================================================================= //function : LocalSelector //purpose : //======================================================================= Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const { if( !HasOpenedContext() ) return Handle( StdSelect_ViewerSelector3d )(); else return myLocalContexts( myCurLocalIndex )->MainSelector(); } //======================================================================= //function : DeActivate //purpose : //======================================================================= void AIS_InteractiveContext:: Deactivate(const Handle(AIS_InteractiveObject)& anIObj) { if(!HasOpenedContext()){ if(!myObjects.IsBound(anIObj)) return; TColStd_ListIteratorOfListOfInteger ItL; for(ItL.Initialize(myObjects(anIObj)->SelectionModes()); ItL.More(); ItL.Next()){ if(myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed) mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel); } myObjects(anIObj)->ClearSelectionModes(); } else{ const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex); LC->Deactivate(anIObj); } } //======================================================================= //function : Deactivate //purpose : //======================================================================= void AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Integer aMode) { if(!HasOpenedContext()){ if(!myObjects.IsBound(anIObj)) return; const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj); if(STAT->GraphicStatus() == AIS_DS_Displayed) mgrSelector->Deactivate(anIObj,aMode,myMainSel); STAT->RemoveSelectionMode(aMode); } else{ myLocalContexts(myCurLocalIndex)->DeactivateMode(anIObj,aMode); } } //======================================================================= //function : ActivatedModes //purpose : //======================================================================= void AIS_InteractiveContext:: ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj, TColStd_ListOfInteger& theList) const { TColStd_ListIteratorOfListOfInteger ItL; if(!HasOpenedContext()){ if(myObjects.IsBound(anIObj)){ for(ItL.Initialize(myObjects(anIObj)->SelectionModes()); ItL.More(); ItL.Next()) theList.Append(ItL.Value()); } } else{ if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){ for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj)); ItL.More(); ItL.Next()) theList.Append(ItL.Value()); } } } //======================================================================= //function : SetShapeDecomposition //purpose : //======================================================================= void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean StdModeSensitive) { if(!HasOpenedContext()) return; myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive); } //======================================================================= //function : SetTemporaryAttributes //purpose : //======================================================================= void AIS_InteractiveContext:: SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/, const Handle(Prs3d_Drawer)& /*aDrawer*/, const Standard_Boolean /*updateviewer*/) { } //======================================================================= //function : SubIntensityOn //purpose : //======================================================================= void AIS_InteractiveContext:: SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer) { if(!HasOpenedContext()){ if(!myObjects.IsBound(anIObj)) return; const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj); if(GB->IsSubIntensityOn()) return; GB->SubIntensityOn(); Standard_Boolean UpdMain(Standard_False); for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){ if (GB->GraphicStatus()==AIS_DS_Displayed) { myMainPM->Color(anIObj,mySubIntensity,It.Value()); UpdMain = Standard_True; } } if(updateviewer){ if(UpdMain) myMainVwr->Update(); } } else { if(myObjects.IsBound(anIObj)){ const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj); STAT->SubIntensityOn(); TColStd_ListIteratorOfListOfInteger ItL; for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next()) myMainPM->Color(anIObj,mySubIntensity,ItL.Value()); } else myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj); if(updateviewer) myMainVwr->Update(); } } //======================================================================= //function : SubIntensityOff //purpose : //======================================================================= void AIS_InteractiveContext:: SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer) { if(!HasOpenedContext()){ if(!myObjects.IsBound(anIObj)) return; const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj); if(!GB->IsSubIntensityOn()) return; GB->SubIntensityOff(); Standard_Boolean UpdMain(Standard_False); for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){ if(GB->GraphicStatus()==AIS_DS_Displayed) { myMainPM->Unhighlight(anIObj,It.Value()); UpdMain = Standard_True; } } Standard_Integer DM,HM,SM; GetDefModes(anIObj,DM,HM,SM); if(AIS_Selection::IsSelected(anIObj)) myMainPM->Highlight(anIObj,HM); if(updateviewer){ if(UpdMain) myMainVwr->Update(); } } else { if(myObjects.IsBound(anIObj)){ const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj); STAT->SubIntensityOff(); TColStd_ListIteratorOfListOfInteger ItL; for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next()) myMainPM->Unhighlight(anIObj,ItL.Value()); if(STAT->IsHilighted()) Hilight(anIObj); } else myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj); if(IsSelected(anIObj)) Hilight(anIObj); if(updateviewer) myMainVwr->Update(); } } //======================================================================= //function : SubIntensityOn //purpose : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY... //======================================================================= void AIS_InteractiveContext::SubIntensityOn(const Standard_Boolean updateviewer) { if(!HasOpenedContext()) return; AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects); TColStd_ListIteratorOfListOfInteger ItM; for(;It.More();It.Next()){ const Handle(AIS_GlobalStatus)& STAT = It.Value(); if(STAT->GraphicStatus()==AIS_DS_Displayed) { STAT->SubIntensityOn(); for(ItM.Initialize(STAT->DisplayedModes());ItM.More();ItM.Next()) {myMainPM->Color(It.Key(),mySubIntensity,ItM.Value());} } } if(updateviewer) myMainVwr->Update(); } //======================================================================= //function : SubIntensityOff //purpose : //======================================================================= void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer) { if(!HasOpenedContext()) return; AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects); TColStd_ListIteratorOfListOfInteger ItL; for(;It.More();It.Next()){ const Handle(AIS_GlobalStatus)& STAT = It.Value(); if(STAT->IsSubIntensityOn()) STAT->SubIntensityOff(); for(ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next()) myMainPM->Unhighlight(It.Key()); } if(updateviewer) myMainVwr->Update(); } //======================================================================= //function : AddFilter //purpose : //======================================================================= void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->AddFilter(aFilter); else myFilters->Add(aFilter); } //======================================================================= //function : ActivateStandardMode //purpose : //======================================================================= void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation) { if(!HasOpenedContext()) return; myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation); } //======================================================================= //function : DeActivateStandardMode //purpose : //======================================================================= void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation) { if(!HasOpenedContext()) return; myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation); } //======================================================================= //function : RemoveFilter //purpose : //======================================================================= void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter); else myFilters->Remove(aFilter); } //======================================================================= //function : RemoveFilters //purpose : //======================================================================= void AIS_InteractiveContext::RemoveFilters() { if(!HasOpenedContext()) myFilters->Clear(); else myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters); } //======================================================================= //function : ActivatedStandardModes //purpose : //======================================================================= const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const { return myLocalContexts(myCurLocalIndex)->StandardModes(); } //======================================================================= //function : Filters //purpose : //======================================================================= const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const { if(HasOpenedContext()) return myLocalContexts(myCurLocalIndex)->ListOfFilter(); return myFilters->StoredFilters(); } //======================================================================= //function : DisplayActiveAreas //purpose : //======================================================================= void AIS_InteractiveContext::DisplayActiveAreas(const Handle(V3d_View)& aviou) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->DisplayAreas(aviou); else myMainSel->DisplayAreas(aviou); } //======================================================================= //function : ClearActiveAreas //purpose : //======================================================================= void AIS_InteractiveContext::ClearActiveAreas(const Handle(V3d_View)& aviou) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->ClearAreas(aviou); else myMainSel->ClearAreas(aviou); } //======================================================================= //function : DisplayActiveSensitive //purpose : //======================================================================= void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou); else myMainSel->DisplaySensitive(aviou); } //======================================================================= //function : DisplayActiveSensitive //purpose : //======================================================================= void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj, const Handle(V3d_View)& aviou) { TColStd_ListIteratorOfListOfInteger It; Handle(StdSelect_ViewerSelector3d) VS; if(HasOpenedContext()){ const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex); if(!LC->IsIn(anIObj)) return; It.Initialize(LC->SelectionModes(anIObj)); VS = LC->MainSelector(); } else{ if(!myObjects.IsBound(anIObj)) return; It.Initialize(myObjects(anIObj)->SelectionModes()); VS = myMainSel; } for(;It.More();It.Next()){ const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value()); VS->DisplaySensitive(Sel,aviou,Standard_False); } } //======================================================================= //function : DisplayActiveAreas //purpose : //======================================================================= void AIS_InteractiveContext::DisplayActiveAreas(const Handle(AIS_InteractiveObject)& anIObj, const Handle(V3d_View)& aviou) { TColStd_ListIteratorOfListOfInteger It; Handle(StdSelect_ViewerSelector3d) VS; if(HasOpenedContext()){ const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex); if(!LC->IsIn(anIObj)) return; It.Initialize(LC->SelectionModes(anIObj)); VS = LC->MainSelector(); } else{ if(!myObjects.IsBound(anIObj)) return; It.Initialize(myObjects(anIObj)->SelectionModes()); VS = myMainSel; } for(;It.More();It.Next()){ const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value()); VS->DisplayAreas(Sel,aviou,Standard_False); } } //======================================================================= //function : ClearActiveSensitive //purpose : //======================================================================= void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou); else myMainSel->ClearSensitive(aviou); } //======================================================================= //function : SetAutomaticHilight //purpose : //======================================================================= void AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus) { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus); } //======================================================================= //function : AutomaticHilight //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const { if(HasOpenedContext()) return myLocalContexts(myCurLocalIndex)->AutomaticHilight(); return Standard_True; } //======================================================================= //function : UseDisplayedObjects //purpose : //======================================================================= void AIS_InteractiveContext::UseDisplayedObjects() { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->LoadContextObjects(); } //======================================================================= //function : NotUseDisplayedObjects //purpose : //======================================================================= void AIS_InteractiveContext::NotUseDisplayedObjects() { if(HasOpenedContext()) myLocalContexts(myCurLocalIndex)->UnloadContextObjects(); } //======================================================================= //function : PurgeDisplay //purpose : //======================================================================= Standard_Integer AIS_InteractiveContext::PurgeDisplay() { if(HasOpenedContext()) return 0; Standard_Integer NbStr = PurgeViewer(myMainVwr); myMainVwr->Update(); return NbStr; } //======================================================================= //function : PurgeViewer //purpose : //======================================================================= Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr) { const Handle(Graphic3d_StructureManager)& GSM = Vwr->Viewer(); Standard_Integer NbCleared(0); Graphic3d_MapOfStructure SOS; GSM->DisplayedStructures(SOS); Handle(Graphic3d_Structure) G; for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){ G = It.Key(); Standard_Address Add = G->Owner(); if(Add==NULL){ G->Erase(); G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject... NbCleared++; } Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add; if(!myObjects.IsBound(IO)){ G->Erase(); NbCleared++; } } return NbCleared; } //======================================================================= //function : IsImmediateModeOn //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const { if(!HasOpenedContext()) return Standard_False; return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn(); } Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw() { if(HasOpenedContext()) return myLocalContexts(myCurLocalIndex)->BeginImmediateDraw(); return Standard_False; } //======================================================================= //function : ImmediateAdd //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::ImmediateAdd(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Integer AMode) { if(HasOpenedContext()){ return myLocalContexts(myCurLocalIndex)->ImmediateAdd(anIObj,AMode);} return Standard_False; } //======================================================================= //function : ImmediateRemove //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::ImmediateRemove(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Integer aMode) { if(HasOpenedContext()) return myLocalContexts(myCurLocalIndex)->ImmediateRemove(anIObj,aMode); return Standard_False; } //======================================================================= //function : EndImmediateDraw //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Handle(V3d_View)& aView, const Standard_Boolean DoubleBuf) { if(HasOpenedContext()) return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(aView,DoubleBuf); return Standard_False; } //======================================================================= //function : EndImmediateDraw //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Standard_Boolean DoubleBuf) { if(HasOpenedContext()){ Handle(V3d_View) V ; myMainVwr->InitActiveViews(); if(myMainVwr->MoreActiveViews()){ V = myMainVwr->ActiveView(); return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(V,DoubleBuf); } } return Standard_False; } //======================================================================= //function : ResetOriginalState //purpose : //======================================================================= void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer) { Standard_Boolean upd_main(Standard_False); TColStd_ListIteratorOfListOfInteger itl; for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){ const Handle(AIS_InteractiveObject)& iobj = it.Key(); const Handle(AIS_GlobalStatus)& STAT = it.Value(); switch(STAT->GraphicStatus()){ case AIS_DS_Displayed:{ upd_main = Standard_True; // part display... for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next()) myMainPM->Display(iobj,itl.Value()); if(STAT->IsHilighted()){ if(STAT->HilightColor()!=Quantity_NOC_WHITE) HilightWithColor(iobj,STAT->HilightColor(),Standard_False); else Hilight(iobj,Standard_False); } //part selection for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){ if(itl.Value()!=-1) mgrSelector->Activate(iobj,itl.Value(),myMainSel); } break; } case AIS_DS_Erased:{ EraseGlobal(iobj,Standard_False); break; } default: break; } } if(updateviewer){ if(upd_main) myMainVwr->Update(); } } #ifdef IMP051001 //======================================================================= //function : SetZDetection //purpose : //======================================================================= void AIS_InteractiveContext::SetZDetection(const Standard_Boolean aStatus) { myZDetectionFlag = aStatus; } //======================================================================= //function : ZDetection //purpose : //======================================================================= Standard_Boolean AIS_InteractiveContext::ZDetection() const { return myZDetectionFlag; } #endif