Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-02-20 |
2 | // Created by: Mister rmi | |
3 | // Copyright (c) 1995-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | #include <Standard_NotImplemented.hxx> | |
18 | ||
19 | #include <SelectMgr_SelectableObject.ixx> | |
20 | #include <Standard_NoSuchObject.hxx> | |
21 | #include <SelectMgr_Selection.hxx> | |
22 | #include <Select3D_SensitiveEntity.hxx> | |
23 | #include <SelectBasics_EntityOwner.hxx> | |
24 | #include <SelectMgr_EntityOwner.hxx> | |
25 | #include <PrsMgr_PresentationManager3d.hxx> | |
6262338c | 26 | #include <Prs3d_Drawer.hxx> |
7fd59977 | 27 | |
0717ddc1 | 28 | #include <TopLoc_Location.hxx> |
7fd59977 | 29 | #include <gp_Pnt.hxx> |
30 | ||
31 | static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq, | |
32 | const Handle (SelectMgr_Selection)& theSel) | |
33 | { | |
34 | Standard_Integer ifound=0; | |
35 | for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++) | |
36 | {if(theSel == seq.Value(i)) ifound=i;} | |
37 | return ifound; | |
38 | } | |
39 | ||
40 | ||
41 | ||
42 | //================================================== | |
43 | // Function: | |
44 | // Purpose : | |
45 | //================================================== | |
46 | ||
6262338c | 47 | SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d): |
48 | PrsMgr_PresentableObject (aTypeOfPresentation3d), | |
49 | myDrawer (new Prs3d_Drawer()), | |
50 | myAutoHilight (Standard_True) | |
51 | {} | |
7fd59977 | 52 | |
53 | ||
54 | //================================================== | |
55 | // Function: | |
56 | // Purpose : | |
57 | //================================================== | |
58 | ||
59 | Standard_Boolean SelectMgr_SelectableObject | |
60 | ::HasSelection(const Standard_Integer aMode) const | |
61 | { | |
62 | Standard_Boolean Found=Standard_False; | |
63 | for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++) | |
64 | { if(((myselections.Value(I))->Mode())==aMode) | |
65 | return Standard_True; | |
66 | } | |
67 | return Standard_False; | |
68 | } | |
69 | ||
70 | //================================================== | |
71 | // Function: UpdateSelection | |
72 | // Purpose : | |
73 | //================================================== | |
74 | void SelectMgr_SelectableObject::UpdateSelection() | |
75 | { | |
76 | for (Standard_Integer I=1;I<=myselections.Length();I++) | |
77 | { | |
78 | UpdateSelection(myselections.ChangeValue(I)->Mode()); | |
79 | } | |
80 | } | |
81 | ||
82 | Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const | |
83 | {return 0;} | |
84 | ||
85 | //================================================== | |
86 | // Function: UpdateSelection | |
87 | // Purpose : | |
88 | //================================================== | |
89 | void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode) | |
90 | { | |
91 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { | |
92 | if (myselections.Value(i)->Mode() == aMode) { | |
93 | myselections(i)->Clear(); | |
94 | ComputeSelection(myselections(i),aMode); | |
95 | myselections(i)->UpdateStatus(SelectMgr_TOU_Partial); | |
96 | return; | |
97 | } | |
98 | } | |
99 | Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode); | |
100 | ComputeSelection(S,aMode); | |
101 | S->UpdateStatus(SelectMgr_TOU_Partial); | |
102 | ||
103 | myselections.Append(S); | |
104 | ||
105 | } | |
106 | ||
107 | //================================================== | |
108 | // Function: ClearSelections | |
109 | // Purpose : | |
110 | //================================================== | |
111 | void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update) | |
112 | { | |
113 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { | |
114 | myselections.Value(i)->Clear(); | |
115 | if(update) | |
116 | myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full); | |
117 | } | |
118 | } | |
119 | ||
120 | ||
121 | //================================================== | |
122 | // Function: Selection | |
123 | // Purpose : | |
124 | //================================================== | |
125 | ||
126 | const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject | |
127 | ::Selection(const Standard_Integer aMode) const | |
128 | { | |
129 | static Handle(SelectMgr_Selection) bidsel; | |
130 | Standard_Boolean Found = Standard_False; | |
131 | Standard_Integer Rank=0; | |
132 | for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++) | |
133 | { | |
134 | if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True; | |
135 | Rank=i;}} | |
136 | return myselections.Value(Rank); | |
137 | } | |
138 | ||
139 | ||
140 | //================================================== | |
141 | // Function: AddSelection | |
142 | // Purpose : | |
143 | //================================================== | |
144 | ||
145 | void SelectMgr_SelectableObject | |
146 | ::AddSelection(const Handle(SelectMgr_Selection)& aSel, | |
147 | const Standard_Integer aMode) | |
148 | { | |
149 | if(aSel->IsEmpty()){ | |
150 | ComputeSelection(aSel,aMode); | |
151 | aSel->UpdateStatus(SelectMgr_TOU_Partial); | |
152 | } | |
153 | if(HasSelection(aMode)) | |
154 | { | |
155 | const Handle(SelectMgr_Selection)& temp= Selection(aMode); | |
156 | Standard_Integer I = Search(myselections,temp); | |
157 | if(I!=0) myselections.Remove(I); | |
158 | } | |
159 | myselections.Append(aSel); | |
160 | ||
161 | } | |
162 | ||
163 | ||
164 | ||
165 | //======================================================================= | |
0717ddc1 | 166 | //function : ReSetTransformation |
7fd59977 | 167 | //purpose : |
168 | //======================================================================= | |
0717ddc1 | 169 | void SelectMgr_SelectableObject::ResetTransformation() |
7fd59977 | 170 | { |
171 | TopLoc_Location aLoc; | |
172 | ||
0717ddc1 | 173 | TopLoc_Location aSelfLocation (Transformation()); |
7fd59977 | 174 | |
175 | // les selections | |
176 | Handle(Select3D_SensitiveEntity) SE; | |
177 | for(Init();More();Next()){ | |
178 | const Handle(SelectMgr_Selection) & Sel = CurrentSelection(); | |
179 | for(Sel->Init();Sel->More();Sel->Next()){ | |
180 | SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive())); | |
181 | if(!SE.IsNull()){ | |
eafb234b | 182 | if(SE->HasLocation()) { |
0717ddc1 | 183 | if( SE->Location()==aSelfLocation){ |
7fd59977 | 184 | SE->ResetLocation(); |
185 | const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId(); | |
186 | (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();} | |
187 | else{ | |
188 | const TopLoc_Location& iniloc =SE->Location(); | |
0717ddc1 | 189 | SE->SetLocation(iniloc*aSelfLocation.Inverted()); |
7fd59977 | 190 | const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId(); |
191 | (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());} | |
eafb234b | 192 | } |
7fd59977 | 193 | } |
194 | } | |
195 | Sel->UpdateStatus(SelectMgr_TOU_None); | |
196 | } | |
197 | ||
0717ddc1 | 198 | PrsMgr_PresentableObject::ResetTransformation(); |
7fd59977 | 199 | } |
200 | ||
201 | ||
202 | //======================================================================= | |
0717ddc1 | 203 | //function : UpdateTransformation |
7fd59977 | 204 | //purpose : |
205 | //======================================================================= | |
0717ddc1 | 206 | void SelectMgr_SelectableObject::UpdateTransformation() |
7fd59977 | 207 | { |
208 | ||
209 | Handle(Select3D_SensitiveEntity) SE; | |
210 | for(Init();More();Next()){ | |
211 | const Handle(SelectMgr_Selection) & Sel = CurrentSelection(); | |
212 | Sel->UpdateStatus(SelectMgr_TOU_Partial); | |
213 | } | |
0717ddc1 | 214 | PrsMgr_PresentableObject::UpdateTransformation(); |
7fd59977 | 215 | |
216 | } | |
217 | ||
218 | ||
219 | //======================================================================= | |
0717ddc1 | 220 | //function : UpdateTransformation |
7fd59977 | 221 | //purpose : |
222 | //======================================================================= | |
913a4c4a | 223 | void SelectMgr_SelectableObject::UpdateTransformations(const Handle(SelectMgr_Selection)& Sel) |
7fd59977 | 224 | { |
0717ddc1 | 225 | TopLoc_Location aSelfLocation (Transformation()); |
7fd59977 | 226 | Handle(Select3D_SensitiveEntity) SE; |
0717ddc1 | 227 | if(aSelfLocation.IsIdentity()) return; |
7fd59977 | 228 | for(Sel->Init();Sel->More();Sel->Next()){ |
709e97a0 | 229 | SE = Handle(Select3D_SensitiveEntity)::DownCast(Sel->Sensitive()); |
7fd59977 | 230 | if(!SE.IsNull()){ |
0717ddc1 | 231 | SE->UpdateLocation(aSelfLocation); |
29d43f9c A |
232 | const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId(); |
233 | Handle(SelectMgr_EntityOwner) aMgrEO = | |
234 | Handle(SelectMgr_EntityOwner)::DownCast (aEOwner); | |
235 | if (!aMgrEO.IsNull()) | |
0717ddc1 | 236 | aMgrEO->SetLocation (aSelfLocation); |
7fd59977 | 237 | } |
238 | } | |
239 | } | |
240 | ||
241 | //======================================================================= | |
242 | //function : HilightSelected | |
243 | //purpose : | |
244 | //======================================================================= | |
245 | void SelectMgr_SelectableObject::HilightSelected | |
246 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
247 | const SelectMgr_SequenceOfOwner&) | |
248 | { | |
249 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected"); | |
250 | } | |
251 | ||
252 | //======================================================================= | |
253 | //function : ClearSelected | |
254 | //purpose : | |
255 | //======================================================================= | |
256 | void SelectMgr_SelectableObject::ClearSelected () | |
257 | { | |
7fd59977 | 258 | if( !mySelectionPrs.IsNull() ) |
2b442de5 | 259 | mySelectionPrs->Clear(); |
7fd59977 | 260 | } |
261 | ||
262 | //======================================================================= | |
263 | //function : HilightOwnerWithColor | |
264 | //purpose : | |
265 | //======================================================================= | |
266 | void SelectMgr_SelectableObject::HilightOwnerWithColor | |
267 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
268 | const Quantity_NameOfColor, | |
269 | const Handle(SelectMgr_EntityOwner)&) | |
270 | { | |
271 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor"); | |
272 | } | |
273 | ||
274 | //======================================================================= | |
275 | //function : MaxFaceNodes | |
276 | //purpose : | |
277 | //======================================================================= | |
278 | Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const | |
279 | { | |
280 | return myAutoHilight; | |
281 | } | |
282 | ||
283 | //======================================================================= | |
284 | //function : MaxFaceNodes | |
285 | //purpose : | |
286 | //======================================================================= | |
287 | void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight ) | |
288 | { | |
289 | myAutoHilight = newAutoHilight; | |
290 | } | |
291 | ||
292 | //======================================================================= | |
293 | //function : GetHilightPresentation | |
294 | //purpose : | |
295 | //======================================================================= | |
296 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
297 | { | |
298 | if( myHilightPrs.IsNull() && !TheMgr.IsNull() ) | |
299 | { | |
300 | myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
301 | myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
302 | GetTransformPersistencePoint() ); | |
303 | } | |
304 | ||
305 | return myHilightPrs; | |
306 | } | |
307 | ||
308 | ||
309 | //======================================================================= | |
310 | //function : GetSelectPresentation | |
311 | //purpose : | |
312 | //======================================================================= | |
313 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
314 | { | |
315 | if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) { | |
316 | mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
317 | mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
318 | GetTransformPersistencePoint() ); | |
319 | } | |
320 | return mySelectionPrs; | |
321 | } | |
322 | ||
59f45b7c | 323 | //======================================================================= |
324 | //function : SetZLayer | |
325 | //purpose : | |
326 | //======================================================================= | |
a1954302 | 327 | void SelectMgr_SelectableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c | 328 | { |
59f45b7c | 329 | // update own presentations |
a1954302 | 330 | PrsMgr_PresentableObject::SetZLayer (theLayerId); |
59f45b7c | 331 | |
332 | // update selection presentations | |
333 | if (!mySelectionPrs.IsNull()) | |
334 | mySelectionPrs->SetZLayer (theLayerId); | |
335 | ||
336 | if (!myHilightPrs.IsNull()) | |
337 | myHilightPrs->SetZLayer (theLayerId); | |
338 | ||
339 | // update all entity owner presentations | |
340 | for (Init (); More () ;Next ()) | |
341 | { | |
342 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); | |
343 | for (aSel->Init (); aSel->More (); aSel->Next ()) | |
344 | { | |
345 | Handle(Select3D_SensitiveEntity) aEntity = | |
346 | Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive()); | |
347 | if (!aEntity.IsNull()) | |
348 | { | |
349 | Handle(SelectMgr_EntityOwner) aOwner = | |
350 | Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId()); | |
351 | if (!aOwner.IsNull()) | |
a1954302 | 352 | aOwner->SetZLayer (theLayerId); |
59f45b7c | 353 | } |
354 | } | |
355 | } | |
356 | } | |
6262338c | 357 | |
358 | //======================================================================= | |
359 | //function : SetAttributes | |
360 | //purpose : | |
361 | //======================================================================= | |
362 | void SelectMgr_SelectableObject::SetAttributes (const Handle(Prs3d_Drawer)& theDrawer) | |
363 | { | |
364 | myDrawer = theDrawer; | |
365 | } | |
366 | ||
367 | //======================================================================= | |
368 | //function : UnsetAttributes | |
369 | //purpose : | |
370 | //======================================================================= | |
371 | void SelectMgr_SelectableObject::UnsetAttributes() | |
372 | { | |
373 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); | |
374 | if (myDrawer->HasLink()) | |
375 | { | |
376 | aDrawer->Link (myDrawer->Link()); | |
377 | } | |
378 | myDrawer = aDrawer; | |
379 | } | |
380 |