1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <AIS_InteractiveObject.hxx>
17 #include <AIS_Selection.hxx>
18 #include <SelectMgr_EntityOwner.hxx>
19 #include <Standard_MultiplyDefined.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_Transient.hxx>
22 #include <Standard_Type.hxx>
23 #include <Standard_TypeMismatch.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection,MMgt_TShared)
27 #define MaxSizeOfResult 100000
29 //=======================================================================
30 //function : AIS_Selection
32 //=======================================================================
33 AIS_Selection::AIS_Selection() :
36 myResultMap.ReSize( MaxSizeOfResult ); // for maximum performnace on medium selections ( < 100000 objects )
39 //=======================================================================
42 //=======================================================================
43 void AIS_Selection::Select()
50 //=======================================================================
53 //=======================================================================
54 AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObject)
56 Handle(AIS_InteractiveObject) anAISObj;
57 Handle(SelectMgr_EntityOwner) owner = Handle(SelectMgr_EntityOwner)::DownCast( anObject );
59 anAISObj = Handle(AIS_InteractiveObject)::DownCast( anObject );
60 if ( myResultMap.IsBound( anObject ) ){
61 AIS_NListTransient::Iterator aListIter = myResultMap.Find( anObject );
62 //skt-----------------------------------------------------------------
63 if( myIterator == aListIter ) {
64 if( myIterator.More() )
67 myIterator = AIS_NListTransient::Iterator();
69 //--------------------------------------------------------------------
70 // In the mode of advanced mesh selection only one owner is created
71 // for all selection modes. It is necessary to check the current detected
72 // entity and remove the owner from map only if the detected entity is
73 // the same as previous selected (IsForcedHilight call)
74 if( !anAISObj.IsNull() || ( !owner.IsNull() && !owner->IsForcedHilight() ) )
76 myresult.Remove( aListIter );
77 myResultMap.UnBind( anObject );
79 // update list iterator for next object in <myresult> list if any
80 if ( aListIter.More() ){
81 const Handle(Standard_Transient)& aNextObject = aListIter.Value();
82 if ( myResultMap.IsBound( aNextObject ) )
83 myResultMap( aNextObject ) = aListIter;
85 myResultMap.Bind( aNextObject, aListIter );
87 return AIS_SS_Removed;
93 AIS_NListTransient::Iterator aListIter;
94 myresult.Append( anObject, aListIter );
95 myResultMap.Bind( anObject, aListIter );
99 //=======================================================================
100 //function : AddSelect
101 //purpose : Always add int the selection
102 //=======================================================================
103 AIS_SelectStatus AIS_Selection::AddSelect(const Handle(Standard_Transient)& anObject)
105 if ( myResultMap.IsBound( anObject ) )
106 return AIS_SS_NotDone;
108 AIS_NListTransient::Iterator aListIter;
109 myresult.Append( anObject, aListIter );
110 myResultMap.Bind( anObject, aListIter );
115 //=======================================================================
116 //function : ClearAndSelect
118 //=======================================================================
120 void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject)
127 //=======================================================================
130 //=======================================================================
131 Standard_Integer AIS_Selection::Extent() const
133 return myresult.Extent();
136 //=======================================================================
139 //=======================================================================
140 Handle(Standard_Transient) AIS_Selection::Single()
145 //=======================================================================
146 //function : IsSelected
148 //=======================================================================
149 Standard_Boolean AIS_Selection::IsSelected(const Handle(Standard_Transient)& anObject) const
151 return myResultMap.IsBound( anObject );