0023934: Compiler warnings in MS VC++ 10
[occt.git] / src / SelectMgr / SelectMgr_SelectableObject.cxx
CommitLineData
b311480e 1// Created on: 1995-02-20
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23
24#include <Standard_NotImplemented.hxx>
25
26#include <SelectMgr_SelectableObject.ixx>
27#include <Standard_NoSuchObject.hxx>
28#include <SelectMgr_Selection.hxx>
29#include <Select3D_SensitiveEntity.hxx>
30#include <SelectBasics_EntityOwner.hxx>
31#include <SelectMgr_EntityOwner.hxx>
32#include <PrsMgr_PresentationManager3d.hxx>
33
34#include <gp_Pnt.hxx>
35
36static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
37 const Handle (SelectMgr_Selection)& theSel)
38{
39 Standard_Integer ifound=0;
40 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
41 {if(theSel == seq.Value(i)) ifound=i;}
42 return ifound;
43}
44
45
46
47//==================================================
48// Function:
49// Purpose :
50//==================================================
51
52SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
53{
54 myAutoHilight = Standard_True;
55}
56
57
58//==================================================
59// Function:
60// Purpose :
61//==================================================
62
63Standard_Boolean SelectMgr_SelectableObject
64::HasSelection(const Standard_Integer aMode) const
65{
66 Standard_Boolean Found=Standard_False;
67 for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
68 { if(((myselections.Value(I))->Mode())==aMode)
69 return Standard_True;
70 }
71 return Standard_False;
72}
73
74//==================================================
75// Function: UpdateSelection
76// Purpose :
77//==================================================
78void SelectMgr_SelectableObject::UpdateSelection()
79{
80 for (Standard_Integer I=1;I<=myselections.Length();I++)
81 {
82 UpdateSelection(myselections.ChangeValue(I)->Mode());
83 }
84}
85
86Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const
87{return 0;}
88
89//==================================================
90// Function: UpdateSelection
91// Purpose :
92//==================================================
93void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
94{
95 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
96 if (myselections.Value(i)->Mode() == aMode) {
97 myselections(i)->Clear();
98 ComputeSelection(myselections(i),aMode);
99 myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
100 return;
101 }
102 }
103 Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
104 ComputeSelection(S,aMode);
105 S->UpdateStatus(SelectMgr_TOU_Partial);
106
107 myselections.Append(S);
108
109}
110
111//==================================================
112// Function: ClearSelections
113// Purpose :
114//==================================================
115void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
116{
117 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
118 myselections.Value(i)->Clear();
119 if(update)
120 myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
121 }
122}
123
124
125//==================================================
126// Function: Selection
127// Purpose :
128//==================================================
129
130const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
131::Selection(const Standard_Integer aMode) const
132{
133 static Handle(SelectMgr_Selection) bidsel;
134 Standard_Boolean Found = Standard_False;
135 Standard_Integer Rank=0;
136 for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
137 {
138 if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
139 Rank=i;}}
140 return myselections.Value(Rank);
141}
142
143
144//==================================================
145// Function: AddSelection
146// Purpose :
147//==================================================
148
149void SelectMgr_SelectableObject
150::AddSelection(const Handle(SelectMgr_Selection)& aSel,
151 const Standard_Integer aMode)
152{
153 if(aSel->IsEmpty()){
154 ComputeSelection(aSel,aMode);
155 aSel->UpdateStatus(SelectMgr_TOU_Partial);
156 }
157 if(HasSelection(aMode))
158 {
159 const Handle(SelectMgr_Selection)& temp= Selection(aMode);
160 Standard_Integer I = Search(myselections,temp);
161 if(I!=0) myselections.Remove(I);
162 }
163 myselections.Append(aSel);
164
165}
166
167
168
169//=======================================================================
170//function : ReSetLocation
171//purpose :
172//=======================================================================
173void SelectMgr_SelectableObject::ResetLocation()
174{
175 TopLoc_Location aLoc;
176
177
178 // les selections
179 Handle(Select3D_SensitiveEntity) SE;
180 for(Init();More();Next()){
181 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
182 for(Sel->Init();Sel->More();Sel->Next()){
183 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
184 if(!SE.IsNull()){
185 if(SE->HasLocation())
186 if( SE->Location()==myLocation){
187 SE->ResetLocation();
188 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
189 (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
190 else{
191 const TopLoc_Location& iniloc =SE->Location();
192 SE->SetLocation(iniloc*myLocation.Inverted());
193 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
194 (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
195
196 }
197 }
198 Sel->UpdateStatus(SelectMgr_TOU_None);
199 }
200
201 PrsMgr_PresentableObject::ResetLocation();
202}
203
204
205//=======================================================================
206//function : UpdateLocation
207//purpose :
208//=======================================================================
209void SelectMgr_SelectableObject::UpdateLocation()
210{
211
212 Handle(Select3D_SensitiveEntity) SE;
213 for(Init();More();Next()){
214 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
215 Sel->UpdateStatus(SelectMgr_TOU_Partial);
216 }
217 PrsMgr_PresentableObject::UpdateLocation();
218
219}
220
221
222//=======================================================================
223//function : UpdateLocation
224//purpose :
225//=======================================================================
226void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
227{
228 Handle(Select3D_SensitiveEntity) SE;
229 if(myLocation.IsIdentity()) return;
230 for(Sel->Init();Sel->More();Sel->Next()){
231 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
232 if(!SE.IsNull()){
233 SE->UpdateLocation(myLocation);
29d43f9c
A
234 const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId();
235 Handle(SelectMgr_EntityOwner) aMgrEO =
236 Handle(SelectMgr_EntityOwner)::DownCast (aEOwner);
237 if (!aMgrEO.IsNull())
238 aMgrEO->SetLocation (myLocation);
7fd59977 239 }
240 }
241}
242
243//=======================================================================
244//function : HilightSelected
245//purpose :
246//=======================================================================
247void SelectMgr_SelectableObject::HilightSelected
248 ( const Handle(PrsMgr_PresentationManager3d)&,
249 const SelectMgr_SequenceOfOwner&)
250{
251 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
252}
253
254//=======================================================================
255//function : ClearSelected
256//purpose :
257//=======================================================================
258void SelectMgr_SelectableObject::ClearSelected ()
259{
7fd59977 260 if( !mySelectionPrs.IsNull() )
2b442de5 261 mySelectionPrs->Clear();
7fd59977 262}
263
264//=======================================================================
265//function : HilightOwnerWithColor
266//purpose :
267//=======================================================================
268void SelectMgr_SelectableObject::HilightOwnerWithColor
269 ( const Handle(PrsMgr_PresentationManager3d)&,
270 const Quantity_NameOfColor,
271 const Handle(SelectMgr_EntityOwner)&)
272{
273 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
274}
275
276//=======================================================================
277//function : MaxFaceNodes
278//purpose :
279//=======================================================================
280Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
281{
282 return myAutoHilight;
283}
284
285//=======================================================================
286//function : MaxFaceNodes
287//purpose :
288//=======================================================================
289void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
290{
291 myAutoHilight = newAutoHilight;
292}
293
294//=======================================================================
295//function : GetHilightPresentation
296//purpose :
297//=======================================================================
298Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
299{
300 if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
301 {
302 myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
303 myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(),
304 GetTransformPersistencePoint() );
305 }
306
307 return myHilightPrs;
308}
309
310
311//=======================================================================
312//function : GetSelectPresentation
313//purpose :
314//=======================================================================
315Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
316{
317 if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
318 mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
319 mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(),
320 GetTransformPersistencePoint() );
321 }
322 return mySelectionPrs;
323}
324
59f45b7c 325//=======================================================================
326//function : SetZLayer
327//purpose :
328//=======================================================================
329void SelectMgr_SelectableObject::SetZLayer
330 (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
331 const Standard_Integer theLayerId)
332{
333 if (thePrsMgr.IsNull())
334 return;
335
336 // update own presentations
337 PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId);
338
339 // update selection presentations
340 if (!mySelectionPrs.IsNull())
341 mySelectionPrs->SetZLayer (theLayerId);
342
343 if (!myHilightPrs.IsNull())
344 myHilightPrs->SetZLayer (theLayerId);
345
346 // update all entity owner presentations
347 for (Init (); More () ;Next ())
348 {
349 const Handle(SelectMgr_Selection)& aSel = CurrentSelection();
350 for (aSel->Init (); aSel->More (); aSel->Next ())
351 {
352 Handle(Select3D_SensitiveEntity) aEntity =
353 Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive());
354 if (!aEntity.IsNull())
355 {
356 Handle(SelectMgr_EntityOwner) aOwner =
357 Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId());
358 if (!aOwner.IsNull())
359 aOwner->SetZLayer (thePrsMgr, theLayerId);
360 }
361 }
362 }
363}