0027664: Incomplete intersection curve from the attached shapes
[occt.git] / src / AIS / AIS_Selection.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15
7fd59977 16#include <AIS_InteractiveObject.hxx>
42cf5bc1 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>
7fd59977 24
92efcf78 25IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection,MMgt_TShared)
26
7fd59977 27#define MaxSizeOfResult 100000
7fd59977 28
7fd59977 29//=======================================================================
30//function : AIS_Selection
31//purpose :
32//=======================================================================
016e5959 33AIS_Selection::AIS_Selection() :
7fd59977 34myNb(0)
35{
7fd59977 36 myResultMap.ReSize( MaxSizeOfResult ); // for maximum performnace on medium selections ( < 100000 objects )
7fd59977 37}
38
7fd59977 39//=======================================================================
40//function : Select
41//purpose :
42//=======================================================================
43void AIS_Selection::Select()
44{
016e5959 45 myNb=0;
46 myresult.Clear();
47 myResultMap.Clear();
7fd59977 48}
49
7fd59977 50//=======================================================================
51//function : Select
52//purpose :
53//=======================================================================
54AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObject)
55{
7fd59977 56 Handle(AIS_InteractiveObject) anAISObj;
57 Handle(SelectMgr_EntityOwner) owner = Handle(SelectMgr_EntityOwner)::DownCast( anObject );
58 if ( owner.IsNull() )
59 anAISObj = Handle(AIS_InteractiveObject)::DownCast( anObject );
016e5959 60 if ( myResultMap.IsBound( anObject ) ){
61 AIS_NListTransient::Iterator aListIter = myResultMap.Find( anObject );
7fd59977 62//skt-----------------------------------------------------------------
016e5959 63 if( myIterator == aListIter ) {
64 if( myIterator.More() )
65 myIterator.Next();
eafb234b 66 else
016e5959 67 myIterator = AIS_NListTransient::Iterator();
eafb234b 68 }
7fd59977 69//--------------------------------------------------------------------
7fd59977 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() ) )
75 {
016e5959 76 myresult.Remove( aListIter );
77 myResultMap.UnBind( anObject );
7fd59977 78
79 // update list iterator for next object in <myresult> list if any
80 if ( aListIter.More() ){
81 const Handle(Standard_Transient)& aNextObject = aListIter.Value();
016e5959 82 if ( myResultMap.IsBound( aNextObject ) )
83 myResultMap( aNextObject ) = aListIter;
7fd59977 84 else
016e5959 85 myResultMap.Bind( aNextObject, aListIter );
7fd59977 86 }
87 return AIS_SS_Removed;
88 }
89 else
90 return AIS_SS_Added;
91 }
92
93 AIS_NListTransient::Iterator aListIter;
016e5959 94 myresult.Append( anObject, aListIter );
95 myResultMap.Bind( anObject, aListIter );
7fd59977 96 return AIS_SS_Added;
7fd59977 97}
98
99//=======================================================================
100//function : AddSelect
101//purpose : Always add int the selection
102//=======================================================================
103AIS_SelectStatus AIS_Selection::AddSelect(const Handle(Standard_Transient)& anObject)
104{
016e5959 105 if ( myResultMap.IsBound( anObject ) )
7fd59977 106 return AIS_SS_NotDone;
107
108 AIS_NListTransient::Iterator aListIter;
016e5959 109 myresult.Append( anObject, aListIter );
110 myResultMap.Bind( anObject, aListIter );
7fd59977 111 return AIS_SS_Added;
112}
113
114
115//=======================================================================
116//function : ClearAndSelect
117//purpose :
118//=======================================================================
119
016e5959 120void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject)
121{
7fd59977 122 Select();
123 Select(anObject);
7fd59977 124}
125
126
127//=======================================================================
128//function : Extent
129//purpose :
130//=======================================================================
016e5959 131Standard_Integer AIS_Selection::Extent() const
132{
133 return myresult.Extent();
7fd59977 134}
135
136//=======================================================================
137//function : Single
138//purpose :
139//=======================================================================
140Handle(Standard_Transient) AIS_Selection::Single()
141{
016e5959 142 Init();
143 return Value();
7fd59977 144}
145//=======================================================================
146//function : IsSelected
147//purpose :
148//=======================================================================
016e5959 149Standard_Boolean AIS_Selection::IsSelected(const Handle(Standard_Transient)& anObject) const
7fd59977 150{
016e5959 151 return myResultMap.IsBound( anObject );
7fd59977 152}
153
7fd59977 154