0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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
02974a19 15#include <AIS_Selection.hxx>
7fd59977 16
7fd59977 17#include <AIS_InteractiveObject.hxx>
7fd59977 18
02974a19 19IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection, Standard_Transient)
92efcf78 20
02974a19 21namespace
22{
23 static const Standard_Integer THE_MaxSizeOfResult = 100000;
24}
7fd59977 25
7fd59977 26//=======================================================================
27//function : AIS_Selection
02974a19 28//purpose :
7fd59977 29//=======================================================================
02974a19 30AIS_Selection::AIS_Selection()
7fd59977 31{
02974a19 32 // for maximum performance on medium selections (< 100000 objects)
33 myResultMap.ReSize (THE_MaxSizeOfResult);
7fd59977 34}
35
36//=======================================================================
02974a19 37//function : Clear
38//purpose :
7fd59977 39//=======================================================================
02974a19 40void AIS_Selection::Clear()
7fd59977 41{
8d2c79f4 42 for (AIS_NListOfEntityOwner::Iterator aSelIter (Objects()); aSelIter.More(); aSelIter.Next())
43 {
44 const Handle(SelectMgr_EntityOwner) anObject = aSelIter.Value();
45 anObject->SetSelected (Standard_False);
46 }
016e5959 47 myresult.Clear();
48 myResultMap.Clear();
b5cce1ab 49 myIterator = AIS_NListOfEntityOwner::Iterator();
7fd59977 50}
51
52//=======================================================================
7fd59977 53//function : Select
02974a19 54//purpose :
7fd59977 55//=======================================================================
02974a19 56AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theObject)
7fd59977 57{
02974a19 58 if (theObject.IsNull()
59 || !theObject->HasSelectable())
60 {
61 return AIS_SS_NotDone;
62 }
63
64 if (!myResultMap.IsBound (theObject))
65 {
66 AIS_NListOfEntityOwner::Iterator aListIter;
67 myresult.Append (theObject, aListIter);
68 myResultMap.Bind (theObject, aListIter);
8d2c79f4 69 theObject->SetSelected (Standard_True);
02974a19 70 return AIS_SS_Added;
71 }
72
73 AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theObject);
74 if (myIterator == aListIter)
75 {
76 if (myIterator.More())
7fd59977 77 {
02974a19 78 myIterator.Next();
7fd59977 79 }
80 else
02974a19 81 {
82 myIterator = AIS_NListOfEntityOwner::Iterator();
83 }
7fd59977 84 }
7fd59977 85
02974a19 86 // In the mode of advanced mesh selection only one owner is created for all selection modes.
87 // It is necessary to check the current detected entity
88 // and remove the owner from map only if the detected entity is the same as previous selected (IsForcedHilight call)
89 if (theObject->IsForcedHilight())
90 {
91 return AIS_SS_Added;
92 }
7fd59977 93
02974a19 94 myresult.Remove (aListIter);
95 myResultMap.UnBind (theObject);
8d2c79f4 96 theObject->SetSelected (Standard_False);
7fd59977 97
02974a19 98 // update list iterator for next object in <myresult> list if any
99 if (aListIter.More())
100 {
101 const Handle(SelectMgr_EntityOwner)& aNextObject = aListIter.Value();
102 if (myResultMap.IsBound (aNextObject))
103 {
104 myResultMap (aNextObject) = aListIter;
105 }
106 else
107 {
108 myResultMap.Bind (aNextObject, aListIter);
109 }
110 }
111 return AIS_SS_Removed;
7fd59977 112}
113
7fd59977 114//=======================================================================
02974a19 115//function : AddSelect
116//purpose :
7fd59977 117//=======================================================================
02974a19 118AIS_SelectStatus AIS_Selection::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
016e5959 119{
02974a19 120 if (theObject.IsNull()
121 || !theObject->HasSelectable()
122 || myResultMap.IsBound (theObject))
123 {
124 return AIS_SS_NotDone;
125 }
7fd59977 126
02974a19 127 AIS_NListOfEntityOwner::Iterator aListIter;
128 myresult.Append (theObject, aListIter);
129 myResultMap.Bind (theObject, aListIter);
8d2c79f4 130 theObject->SetSelected (Standard_True);
02974a19 131 return AIS_SS_Added;
7fd59977 132}