Integration of OCCT 6.5.0 from SVN
[occt.git] / src / SelectMgr / SelectMgr_SelectableObject.cxx
1 // Copyright:   Matra-Datavision 1995
2 // File:        SelectMgr_SelectableObject.cxx
3 // Created:     Mon Feb 20 17:40:49 1995
4 // Author:      Mister rmi
5 //              <rmi>
6
7
8
9 #include <Standard_NotImplemented.hxx>
10
11 #include <SelectMgr_SelectableObject.ixx>
12 #include <Standard_NoSuchObject.hxx>
13 #include <SelectMgr_Selection.hxx>
14 #include <Select3D_SensitiveEntity.hxx>
15 #include <SelectBasics_EntityOwner.hxx>
16 #include <SelectMgr_EntityOwner.hxx>
17 #include <PrsMgr_PresentationManager3d.hxx>
18
19 #include <gp_Pnt.hxx>
20
21 static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
22                                 const Handle (SelectMgr_Selection)& theSel)
23 {
24   Standard_Integer ifound=0;
25   for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
26     {if(theSel == seq.Value(i)) ifound=i;}
27   return ifound;
28
29
30
31
32 //==================================================
33 // Function: 
34 // Purpose :
35 //==================================================
36
37 SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
38 {
39   myAutoHilight = Standard_True;
40 }
41
42
43 //==================================================
44 // Function: 
45 // Purpose :
46 //==================================================
47
48 Standard_Boolean SelectMgr_SelectableObject
49 ::HasSelection(const Standard_Integer aMode) const
50 {
51   Standard_Boolean Found=Standard_False;
52   for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
53     { if(((myselections.Value(I))->Mode())==aMode) 
54         return Standard_True;
55     }
56   return Standard_False;
57 }
58
59 //==================================================
60 // Function: UpdateSelection
61 // Purpose :
62 //==================================================
63 void SelectMgr_SelectableObject::UpdateSelection()
64 {
65   for (Standard_Integer I=1;I<=myselections.Length();I++)
66     {
67       UpdateSelection(myselections.ChangeValue(I)->Mode());
68     }
69 }
70
71 Standard_Integer  SelectMgr_SelectableObject::NbPossibleSelection() const
72 {return 0;}
73
74 //==================================================
75 // Function: UpdateSelection
76 // Purpose :
77 //==================================================
78 void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
79 {
80   for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
81     if (myselections.Value(i)->Mode() == aMode) {
82       myselections(i)->Clear();
83       ComputeSelection(myselections(i),aMode);
84       myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
85       return;
86     }
87   }
88   Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
89   ComputeSelection(S,aMode);
90   S->UpdateStatus(SelectMgr_TOU_Partial);
91   
92   myselections.Append(S);
93   
94 }
95
96 //==================================================
97 // Function: ClearSelections
98 // Purpose :
99 //==================================================
100 void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
101 {
102   for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
103     myselections.Value(i)->Clear();
104     if(update)
105       myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
106   }
107 }
108
109
110 //==================================================
111 // Function: Selection
112 // Purpose :
113 //==================================================
114
115 const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
116 ::Selection(const Standard_Integer aMode) const
117 {
118   static Handle(SelectMgr_Selection) bidsel;
119   Standard_Boolean Found = Standard_False;
120   Standard_Integer Rank=0;
121   for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
122     {
123       if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
124                                                   Rank=i;}}
125   return myselections.Value(Rank);
126 }
127
128
129 //==================================================
130 // Function: AddSelection
131 // Purpose :
132 //==================================================
133
134 void SelectMgr_SelectableObject
135 ::AddSelection(const Handle(SelectMgr_Selection)& aSel,
136                const Standard_Integer aMode)
137 {
138   if(aSel->IsEmpty()){
139     ComputeSelection(aSel,aMode);
140     aSel->UpdateStatus(SelectMgr_TOU_Partial);
141   }
142   if(HasSelection(aMode))
143     {
144       const Handle(SelectMgr_Selection)& temp= Selection(aMode);
145       Standard_Integer I = Search(myselections,temp);
146       if(I!=0) myselections.Remove(I);
147     }
148   myselections.Append(aSel);
149   
150 }
151
152
153
154 //=======================================================================
155 //function : ReSetLocation
156 //purpose  : 
157 //=======================================================================
158 void SelectMgr_SelectableObject::ResetLocation() 
159 {
160   TopLoc_Location aLoc;
161
162
163   // les selections
164   Handle(Select3D_SensitiveEntity) SE;
165   for(Init();More();Next()){
166     const Handle(SelectMgr_Selection) & Sel =  CurrentSelection();
167     for(Sel->Init();Sel->More();Sel->Next()){
168       SE =  *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
169       if(!SE.IsNull()){
170         if(SE->HasLocation())
171           if( SE->Location()==myLocation){
172             SE->ResetLocation();
173             const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
174             (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
175           else{
176             const TopLoc_Location& iniloc =SE->Location();
177             SE->SetLocation(iniloc*myLocation.Inverted());
178             const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
179             (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
180         
181       }
182     }
183     Sel->UpdateStatus(SelectMgr_TOU_None);
184   }
185
186   PrsMgr_PresentableObject::ResetLocation();
187 }
188
189
190 //=======================================================================
191 //function : UpdateLocation
192 //purpose  : 
193 //=======================================================================
194 void SelectMgr_SelectableObject::UpdateLocation() 
195 {
196   
197   Handle(Select3D_SensitiveEntity) SE;
198   for(Init();More();Next()){
199     const Handle(SelectMgr_Selection) & Sel =  CurrentSelection();
200     Sel->UpdateStatus(SelectMgr_TOU_Partial);
201   }
202   PrsMgr_PresentableObject::UpdateLocation();
203
204 }
205
206
207 //=======================================================================
208 //function : UpdateLocation
209 //purpose  : 
210 //=======================================================================
211 void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
212 {
213   Handle(Select3D_SensitiveEntity) SE;
214   if(myLocation.IsIdentity()) return;
215   for(Sel->Init();Sel->More();Sel->Next()){
216     SE =  *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
217     if(!SE.IsNull()){
218       SE->UpdateLocation(myLocation);
219     }
220   }
221 }
222
223 //=======================================================================
224 //function : HilightSelected
225 //purpose  : 
226 //=======================================================================
227 void SelectMgr_SelectableObject::HilightSelected 
228   ( const Handle(PrsMgr_PresentationManager3d)&,
229     const SelectMgr_SequenceOfOwner&)
230 {
231   Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
232 }
233
234 //=======================================================================
235 //function : ClearSelected
236 //purpose  : 
237 //=======================================================================
238 void SelectMgr_SelectableObject::ClearSelected ()
239 {
240   //Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
241   if( !mySelectionPrs.IsNull() )
242     mySelectionPrs->Clear();  
243 }
244
245 //=======================================================================
246 //function : HilightOwnerWithColor
247 //purpose  : 
248 //=======================================================================
249 void SelectMgr_SelectableObject::HilightOwnerWithColor 
250   ( const Handle(PrsMgr_PresentationManager3d)&,
251     const Quantity_NameOfColor,
252     const Handle(SelectMgr_EntityOwner)&)
253 {
254   Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
255 }
256
257 //=======================================================================
258 //function : MaxFaceNodes
259 //purpose  : 
260 //=======================================================================
261 Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
262 {
263   return myAutoHilight;
264 }
265
266 //=======================================================================
267 //function : MaxFaceNodes
268 //purpose  : 
269 //=======================================================================
270 void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
271 {
272   myAutoHilight = newAutoHilight;
273 }
274
275 //=======================================================================
276 //function : GetHilightPresentation
277 //purpose  : 
278 //=======================================================================
279 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
280 {
281   if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
282     {
283       myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
284       myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(), 
285                                          GetTransformPersistencePoint() );
286     }
287
288   return myHilightPrs;
289 }
290
291
292 //=======================================================================
293 //function : GetSelectPresentation
294 //purpose  : 
295 //=======================================================================
296 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
297 {
298   if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
299     mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
300     mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(), 
301                                              GetTransformPersistencePoint() );
302   }
303   return mySelectionPrs;
304 }
305