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 | |
7fd59977 | 17 | |
7f917335 | 18 | #include <Aspect_TypeOfMarker.hxx> |
42cf5bc1 | 19 | #include <Bnd_Box.hxx> |
20 | #include <gp_Pnt.hxx> | |
7f917335 | 21 | #include <Graphic3d_AspectLine3d.hxx> |
22 | #include <Graphic3d_AspectMarker3d.hxx> | |
42cf5bc1 | 23 | #include <Prs3d_Drawer.hxx> |
24 | #include <Prs3d_LineAspect.hxx> | |
25 | #include <Prs3d_PlaneAspect.hxx> | |
26 | #include <Prs3d_PointAspect.hxx> | |
27 | #include <Prs3d_Presentation.hxx> | |
69ff08ff | 28 | #include <PrsMgr_PresentableObjectPointer.hxx> |
42cf5bc1 | 29 | #include <PrsMgr_PresentationManager3d.hxx> |
30 | #include <Select3D_SensitiveEntity.hxx> | |
31 | #include <SelectBasics_EntityOwner.hxx> | |
32 | #include <SelectMgr_EntityOwner.hxx> | |
c04c30b3 | 33 | #include <SelectMgr_IndexedMapOfOwner.hxx> |
42cf5bc1 | 34 | #include <SelectMgr_SelectableObject.hxx> |
35 | #include <SelectMgr_Selection.hxx> | |
36 | #include <SelectMgr_SelectionManager.hxx> | |
37 | #include <Standard_NoSuchObject.hxx> | |
38 | #include <Standard_NotImplemented.hxx> | |
39 | #include <Standard_Type.hxx> | |
0717ddc1 | 40 | #include <TopLoc_Location.hxx> |
7fd59977 | 41 | |
92efcf78 | 42 | IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectableObject,PrsMgr_PresentableObject) |
43 | ||
7fd59977 | 44 | static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq, |
45 | const Handle (SelectMgr_Selection)& theSel) | |
46 | { | |
47 | Standard_Integer ifound=0; | |
48 | for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++) | |
49 | {if(theSel == seq.Value(i)) ifound=i;} | |
50 | return ifound; | |
51 | } | |
52 | ||
53 | ||
54 | ||
55 | //================================================== | |
56 | // Function: | |
57 | // Purpose : | |
58 | //================================================== | |
59 | ||
c3282ec1 | 60 | SelectMgr_SelectableObject::SelectMgr_SelectableObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
61 | : PrsMgr_PresentableObject (aTypeOfPresentation3d), | |
6262338c | 62 | myDrawer (new Prs3d_Drawer()), |
7f917335 | 63 | myHilightDrawer (new Prs3d_Drawer()), |
f751596e | 64 | myAssemblyOwner (NULL), |
c3282ec1 | 65 | myAutoHilight (Standard_True), |
66 | myGlobalSelMode (0) | |
7f917335 | 67 | { |
68 | InitDefaultHilightAttributes (myHilightDrawer); | |
69 | myHilightDrawer->Link (myDrawer); | |
70 | } | |
7fd59977 | 71 | |
4c0d97ac | 72 | //================================================== |
73 | // Function: Destructor | |
74 | // Purpose : Clears all selections of the object | |
75 | //================================================== | |
76 | SelectMgr_SelectableObject::~SelectMgr_SelectableObject() | |
77 | { | |
78 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx) | |
79 | { | |
80 | myselections.Value (aSelIdx)->Clear(); | |
81 | } | |
82 | } | |
7fd59977 | 83 | |
84 | //================================================== | |
7411850a | 85 | // Function: HasSelection |
7fd59977 | 86 | // Purpose : |
87 | //================================================== | |
7411850a | 88 | Standard_Boolean SelectMgr_SelectableObject::HasSelection (const Standard_Integer theMode) const |
7fd59977 | 89 | { |
7411850a | 90 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx) |
91 | { | |
92 | if (((myselections.Value (aSelIdx))->Mode()) == theMode) | |
93 | return Standard_True; | |
94 | } | |
7fd59977 | 95 | return Standard_False; |
96 | } | |
97 | ||
98 | //================================================== | |
f751596e | 99 | // Function: RecomputePrimitives |
100 | // Purpose : IMPORTANT: Do not use this method to update | |
101 | // selection primitives except implementing custom | |
102 | // selection manager! This method does not take | |
103 | // into account necessary BVH updates, but may | |
104 | // invalidate the pointers it refers to. | |
105 | // TO UPDATE SELECTION properly from outside classes, | |
106 | // use method UpdateSelection. | |
7fd59977 | 107 | //================================================== |
f751596e | 108 | void SelectMgr_SelectableObject::RecomputePrimitives() |
7fd59977 | 109 | { |
f751596e | 110 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); aSelIdx++) |
7fd59977 | 111 | { |
f751596e | 112 | RecomputePrimitives (myselections.ChangeValue (aSelIdx)->Mode()); |
7fd59977 | 113 | } |
114 | } | |
115 | ||
7fd59977 | 116 | //================================================== |
f751596e | 117 | // Function: RecomputePrimitives |
118 | // Purpose : IMPORTANT: Do not use this method to update | |
119 | // selection primitives except implementing custom | |
120 | // selection manager! This method does not take | |
121 | // into account necessary BVH updates, but may | |
122 | // invalidate the pointers it refers to. | |
123 | // TO UPDATE SELECTION properly from outside classes, | |
124 | // use method UpdateSelection. | |
7fd59977 | 125 | //================================================== |
f751596e | 126 | void SelectMgr_SelectableObject::RecomputePrimitives (const Standard_Integer theMode) |
7fd59977 | 127 | { |
69ff08ff | 128 | Handle(PrsMgr_PresentableObject) aPrsParent (Parent()); |
129 | Handle(SelectMgr_SelectableObject) aSelParent = Handle(SelectMgr_SelectableObject)::DownCast (aPrsParent); | |
130 | ||
f751596e | 131 | for (Standard_Integer aSelIdx =1; aSelIdx <= myselections.Length(); aSelIdx++ ) |
132 | { | |
133 | if (myselections.Value (aSelIdx)->Mode() == theMode) | |
134 | { | |
135 | myselections (aSelIdx)->Clear(); | |
136 | ComputeSelection (myselections (aSelIdx), theMode); | |
137 | myselections (aSelIdx)->UpdateStatus (SelectMgr_TOU_Partial); | |
138 | myselections (aSelIdx)->UpdateBVHStatus (SelectMgr_TBU_Renew); | |
69ff08ff | 139 | if (theMode == 0 && ! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) |
f751596e | 140 | { |
69ff08ff | 141 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), theMode); |
f751596e | 142 | } |
7fd59977 | 143 | return; |
144 | } | |
145 | } | |
f751596e | 146 | |
147 | Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode); | |
148 | ComputeSelection (aNewSel, theMode); | |
149 | ||
69ff08ff | 150 | if (theMode == 0 && ! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) |
f751596e | 151 | { |
69ff08ff | 152 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), theMode); |
f751596e | 153 | } |
154 | ||
155 | aNewSel->UpdateStatus (SelectMgr_TOU_Partial); | |
156 | aNewSel->UpdateBVHStatus (SelectMgr_TBU_Add); | |
157 | ||
158 | myselections.Append (aNewSel); | |
7fd59977 | 159 | } |
160 | ||
161 | //================================================== | |
162 | // Function: ClearSelections | |
163 | // Purpose : | |
164 | //================================================== | |
165 | void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update) | |
166 | { | |
167 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { | |
168 | myselections.Value(i)->Clear(); | |
f751596e | 169 | myselections.Value (i)->UpdateBVHStatus (SelectMgr_TBU_Remove); |
7fd59977 | 170 | if(update) |
f751596e | 171 | { |
7fd59977 | 172 | myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full); |
f751596e | 173 | } |
7fd59977 | 174 | } |
175 | } | |
176 | ||
177 | ||
178 | //================================================== | |
179 | // Function: Selection | |
180 | // Purpose : | |
181 | //================================================== | |
182 | ||
183 | const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject | |
184 | ::Selection(const Standard_Integer aMode) const | |
185 | { | |
186 | static Handle(SelectMgr_Selection) bidsel; | |
187 | Standard_Boolean Found = Standard_False; | |
188 | Standard_Integer Rank=0; | |
189 | for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++) | |
190 | { | |
191 | if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True; | |
192 | Rank=i;}} | |
193 | return myselections.Value(Rank); | |
194 | } | |
195 | ||
196 | ||
197 | //================================================== | |
198 | // Function: AddSelection | |
199 | // Purpose : | |
200 | //================================================== | |
201 | ||
202 | void SelectMgr_SelectableObject | |
203 | ::AddSelection(const Handle(SelectMgr_Selection)& aSel, | |
204 | const Standard_Integer aMode) | |
205 | { | |
f751596e | 206 | Standard_Boolean isReplaced = Standard_False; |
207 | if(aSel->IsEmpty()) | |
208 | { | |
209 | ComputeSelection(aSel, aMode); | |
7fd59977 | 210 | aSel->UpdateStatus(SelectMgr_TOU_Partial); |
f751596e | 211 | aSel->UpdateBVHStatus (SelectMgr_TBU_Add); |
7fd59977 | 212 | } |
f751596e | 213 | if (HasSelection(aMode)) |
214 | { | |
215 | const Handle(SelectMgr_Selection)& temp= Selection(aMode); | |
216 | Standard_Integer I = Search(myselections,temp); | |
217 | if(I!=0) | |
7fd59977 | 218 | { |
f751596e | 219 | myselections.Remove(I); |
220 | isReplaced = Standard_True; | |
7fd59977 | 221 | } |
f751596e | 222 | } |
223 | ||
7fd59977 | 224 | myselections.Append(aSel); |
f751596e | 225 | if (isReplaced) |
226 | { | |
227 | myselections.Last()->UpdateBVHStatus (SelectMgr_TBU_Renew); | |
228 | } | |
229 | ||
69ff08ff | 230 | if (aMode == 0) |
f751596e | 231 | { |
69ff08ff | 232 | Handle(PrsMgr_PresentableObject) aPrsParent (Parent()); |
233 | Handle(SelectMgr_SelectableObject) aSelParent = Handle(SelectMgr_SelectableObject)::DownCast (aPrsParent); | |
234 | if (! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) | |
235 | { | |
236 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), aMode); | |
237 | } | |
f751596e | 238 | } |
7fd59977 | 239 | } |
240 | ||
241 | ||
242 | ||
243 | //======================================================================= | |
0717ddc1 | 244 | //function : ReSetTransformation |
7fd59977 | 245 | //purpose : |
246 | //======================================================================= | |
0717ddc1 | 247 | void SelectMgr_SelectableObject::ResetTransformation() |
7fd59977 | 248 | { |
f751596e | 249 | for (Init(); More(); Next()) |
250 | { | |
251 | const Handle(SelectMgr_Selection) & aSel = CurrentSelection(); | |
252 | for (aSel->Init(); aSel->More(); aSel->Next()) | |
253 | { | |
254 | aSel->UpdateStatus(SelectMgr_TOU_Partial); | |
255 | aSel->UpdateBVHStatus (SelectMgr_TBU_None); | |
7fd59977 | 256 | } |
7fd59977 | 257 | } |
258 | ||
0717ddc1 | 259 | PrsMgr_PresentableObject::ResetTransformation(); |
7fd59977 | 260 | } |
261 | ||
7fd59977 | 262 | //======================================================================= |
0717ddc1 | 263 | //function : UpdateTransformation |
7fd59977 | 264 | //purpose : |
265 | //======================================================================= | |
825aa485 | 266 | void SelectMgr_SelectableObject::UpdateTransformation() |
7fd59977 | 267 | { |
825aa485 | 268 | for (Init(); More(); Next()) |
269 | { | |
270 | CurrentSelection()->UpdateStatus (SelectMgr_TOU_Partial); | |
7fd59977 | 271 | } |
7fd59977 | 272 | |
825aa485 | 273 | PrsMgr_PresentableObject::UpdateTransformation(); |
7fd59977 | 274 | } |
275 | ||
7fd59977 | 276 | //======================================================================= |
0717ddc1 | 277 | //function : UpdateTransformation |
7fd59977 | 278 | //purpose : |
279 | //======================================================================= | |
913a4c4a | 280 | void SelectMgr_SelectableObject::UpdateTransformations(const Handle(SelectMgr_Selection)& Sel) |
7fd59977 | 281 | { |
0717ddc1 | 282 | TopLoc_Location aSelfLocation (Transformation()); |
7fd59977 | 283 | Handle(Select3D_SensitiveEntity) SE; |
0717ddc1 | 284 | if(aSelfLocation.IsIdentity()) return; |
7fd59977 | 285 | for(Sel->Init();Sel->More();Sel->Next()){ |
f751596e | 286 | SE = Handle(Select3D_SensitiveEntity)::DownCast (Sel->Sensitive()->BaseSensitive()); |
7fd59977 | 287 | if(!SE.IsNull()){ |
29d43f9c A |
288 | const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId(); |
289 | Handle(SelectMgr_EntityOwner) aMgrEO = | |
290 | Handle(SelectMgr_EntityOwner)::DownCast (aEOwner); | |
291 | if (!aMgrEO.IsNull()) | |
0717ddc1 | 292 | aMgrEO->SetLocation (aSelfLocation); |
7fd59977 | 293 | } |
294 | } | |
295 | } | |
296 | ||
297 | //======================================================================= | |
298 | //function : HilightSelected | |
299 | //purpose : | |
300 | //======================================================================= | |
301 | void SelectMgr_SelectableObject::HilightSelected | |
302 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
303 | const SelectMgr_SequenceOfOwner&) | |
304 | { | |
305 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected"); | |
306 | } | |
307 | ||
308 | //======================================================================= | |
309 | //function : ClearSelected | |
310 | //purpose : | |
311 | //======================================================================= | |
312 | void SelectMgr_SelectableObject::ClearSelected () | |
313 | { | |
7fd59977 | 314 | if( !mySelectionPrs.IsNull() ) |
2b442de5 | 315 | mySelectionPrs->Clear(); |
7fd59977 | 316 | } |
317 | ||
318 | //======================================================================= | |
319 | //function : HilightOwnerWithColor | |
320 | //purpose : | |
321 | //======================================================================= | |
322 | void SelectMgr_SelectableObject::HilightOwnerWithColor | |
323 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
324 | const Quantity_NameOfColor, | |
325 | const Handle(SelectMgr_EntityOwner)&) | |
326 | { | |
327 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor"); | |
328 | } | |
329 | ||
330 | //======================================================================= | |
331 | //function : MaxFaceNodes | |
332 | //purpose : | |
333 | //======================================================================= | |
334 | Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const | |
335 | { | |
336 | return myAutoHilight; | |
337 | } | |
338 | ||
339 | //======================================================================= | |
340 | //function : MaxFaceNodes | |
341 | //purpose : | |
342 | //======================================================================= | |
343 | void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight ) | |
344 | { | |
345 | myAutoHilight = newAutoHilight; | |
346 | } | |
347 | ||
348 | //======================================================================= | |
349 | //function : GetHilightPresentation | |
350 | //purpose : | |
351 | //======================================================================= | |
352 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
353 | { | |
354 | if( myHilightPrs.IsNull() && !TheMgr.IsNull() ) | |
355 | { | |
356 | myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
357 | myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
358 | GetTransformPersistencePoint() ); | |
359 | } | |
360 | ||
361 | return myHilightPrs; | |
362 | } | |
363 | ||
364 | ||
365 | //======================================================================= | |
366 | //function : GetSelectPresentation | |
367 | //purpose : | |
368 | //======================================================================= | |
369 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
370 | { | |
371 | if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) { | |
372 | mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
373 | mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
374 | GetTransformPersistencePoint() ); | |
375 | } | |
376 | return mySelectionPrs; | |
377 | } | |
378 | ||
59f45b7c | 379 | //======================================================================= |
380 | //function : SetZLayer | |
381 | //purpose : | |
382 | //======================================================================= | |
a1954302 | 383 | void SelectMgr_SelectableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c | 384 | { |
59f45b7c | 385 | // update own presentations |
a1954302 | 386 | PrsMgr_PresentableObject::SetZLayer (theLayerId); |
59f45b7c | 387 | |
388 | // update selection presentations | |
389 | if (!mySelectionPrs.IsNull()) | |
390 | mySelectionPrs->SetZLayer (theLayerId); | |
391 | ||
392 | if (!myHilightPrs.IsNull()) | |
393 | myHilightPrs->SetZLayer (theLayerId); | |
394 | ||
395 | // update all entity owner presentations | |
396 | for (Init (); More () ;Next ()) | |
397 | { | |
398 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); | |
399 | for (aSel->Init (); aSel->More (); aSel->Next ()) | |
400 | { | |
401 | Handle(Select3D_SensitiveEntity) aEntity = | |
f751596e | 402 | Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive()->BaseSensitive()); |
59f45b7c | 403 | if (!aEntity.IsNull()) |
404 | { | |
405 | Handle(SelectMgr_EntityOwner) aOwner = | |
406 | Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId()); | |
407 | if (!aOwner.IsNull()) | |
a1954302 | 408 | aOwner->SetZLayer (theLayerId); |
59f45b7c | 409 | } |
410 | } | |
411 | } | |
412 | } | |
6262338c | 413 | |
f751596e | 414 | //======================================================================= |
415 | //function : UpdateSelection | |
416 | //purpose : Sets update status FULL to selections of the object. Must be | |
417 | // used as the only method of UpdateSelection from outer classes | |
418 | // to prevent BVH structures from being outdated. | |
419 | //======================================================================= | |
420 | void SelectMgr_SelectableObject::UpdateSelection (const Standard_Integer theMode) | |
421 | { | |
422 | if (theMode == -1) | |
423 | { | |
424 | for (Init(); More(); Next()) | |
425 | { | |
426 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); | |
427 | aSel->UpdateStatus (SelectMgr_TOU_Full); | |
428 | } | |
429 | ||
430 | return; | |
431 | } | |
432 | ||
433 | for (Init(); More(); Next()) | |
434 | { | |
435 | if (CurrentSelection()->Mode() == theMode) | |
436 | { | |
437 | CurrentSelection()->UpdateStatus (SelectMgr_TOU_Full); | |
438 | return; | |
439 | } | |
440 | } | |
441 | } | |
442 | ||
6262338c | 443 | //======================================================================= |
444 | //function : SetAttributes | |
445 | //purpose : | |
446 | //======================================================================= | |
447 | void SelectMgr_SelectableObject::SetAttributes (const Handle(Prs3d_Drawer)& theDrawer) | |
448 | { | |
449 | myDrawer = theDrawer; | |
450 | } | |
451 | ||
452 | //======================================================================= | |
453 | //function : UnsetAttributes | |
454 | //purpose : | |
455 | //======================================================================= | |
456 | void SelectMgr_SelectableObject::UnsetAttributes() | |
457 | { | |
458 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); | |
459 | if (myDrawer->HasLink()) | |
460 | { | |
461 | aDrawer->Link (myDrawer->Link()); | |
462 | } | |
463 | myDrawer = aDrawer; | |
464 | } | |
465 | ||
7f917335 | 466 | //======================================================================= |
467 | //function : SetHilightAttributes | |
468 | //purpose : | |
469 | //======================================================================= | |
470 | void SelectMgr_SelectableObject::SetHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer) | |
471 | { | |
472 | myHilightDrawer = theDrawer; | |
473 | } | |
474 | ||
475 | //======================================================================= | |
476 | //function : UnsetAttributes | |
477 | //purpose : | |
478 | //======================================================================= | |
479 | void SelectMgr_SelectableObject::UnsetHilightAttributes() | |
480 | { | |
481 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); | |
482 | InitDefaultHilightAttributes (aDrawer); | |
483 | aDrawer->Link (myDrawer); | |
484 | myHilightDrawer = aDrawer; | |
485 | } | |
486 | ||
487 | //======================================================================= | |
488 | //function : InitDefaultHilightAttributes | |
489 | //purpose : | |
490 | //======================================================================= | |
491 | void SelectMgr_SelectableObject::InitDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer) | |
492 | { | |
493 | if (!theDrawer->HasOwnPointAspect()) | |
494 | { | |
495 | theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0)); | |
496 | if (theDrawer->HasLink()) | |
497 | { | |
498 | *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect(); | |
499 | } | |
500 | } | |
501 | if (!theDrawer->HasOwnLineAspect()) | |
502 | { | |
503 | theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
504 | if (theDrawer->HasLink()) | |
505 | { | |
506 | *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); | |
507 | } | |
508 | } | |
509 | if (!theDrawer->HasOwnWireAspect()) | |
510 | { | |
511 | theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
512 | if (theDrawer->HasLink()) | |
513 | { | |
514 | *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); | |
515 | } | |
516 | } | |
517 | if (!theDrawer->HasOwnPlaneAspect()) | |
518 | { | |
519 | theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect()); | |
520 | if (theDrawer->HasLink()) | |
521 | { | |
522 | *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect(); | |
523 | } | |
524 | } | |
525 | if (!theDrawer->HasOwnFreeBoundaryAspect()) | |
526 | { | |
527 | theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
528 | if (theDrawer->HasLink()) | |
529 | { | |
530 | *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect(); | |
531 | } | |
532 | } | |
533 | if (!theDrawer->HasOwnUnFreeBoundaryAspect()) | |
534 | { | |
535 | theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); | |
536 | if (theDrawer->HasLink()) | |
537 | { | |
538 | *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect(); | |
539 | } | |
540 | } | |
541 | ||
542 | theDrawer->WireAspect()->SetWidth(2.); | |
543 | theDrawer->LineAspect()->SetWidth(2.); | |
544 | theDrawer->PlaneAspect()->EdgesAspect()->SetWidth(2.); | |
545 | theDrawer->FreeBoundaryAspect()->SetWidth(2.); | |
546 | theDrawer->UnFreeBoundaryAspect()->SetWidth(2.); | |
547 | theDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_POINT); | |
548 | theDrawer->PointAspect()->SetScale(2.); | |
549 | ||
550 | // By default the hilight drawer has absolute type of deflection. | |
551 | // It is supposed that absolute deflection is taken from Link(). | |
552 | // It is necessary to use for all sub-shapes identical coefficient | |
553 | // computed in ::Compute() call for whole shape and stored in base drawer. | |
554 | theDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); | |
555 | } | |
f751596e | 556 | |
557 | //======================================================================= | |
558 | //function : SetAssemblyOwner | |
559 | //purpose : Sets common entity owner for assembly sensitive object entities | |
560 | //======================================================================= | |
561 | void SelectMgr_SelectableObject::SetAssemblyOwner (const Handle(SelectMgr_EntityOwner)& theOwner, | |
562 | const Standard_Integer theMode) | |
563 | { | |
564 | if (theMode == -1) | |
565 | { | |
566 | for (Standard_Integer aModeIter = 1; aModeIter <= myselections.Length(); ++aModeIter) | |
567 | { | |
568 | Handle(SelectMgr_Selection)& aSel = myselections.ChangeValue (aModeIter); | |
569 | for (aSel->Init(); aSel->More(); aSel->Next()) | |
570 | { | |
571 | aSel->Sensitive()->BaseSensitive()->Set (theOwner); | |
572 | } | |
573 | } | |
574 | ||
575 | return; | |
576 | } | |
577 | ||
578 | if (!HasSelection (theMode)) | |
579 | return; | |
580 | ||
581 | for (Standard_Integer aModeIter = 1; aModeIter <= myselections.Length(); ++aModeIter) | |
582 | { | |
583 | if (myselections.Value (aModeIter)->Mode() == theMode) | |
584 | { | |
585 | Handle(SelectMgr_Selection)& aSel = myselections.ChangeValue (aModeIter); | |
586 | for (aSel->Init(); aSel->More(); aSel->Next()) | |
587 | { | |
588 | aSel->Sensitive()->BaseSensitive()->Set (theOwner); | |
589 | } | |
590 | return; | |
591 | } | |
592 | } | |
593 | } | |
594 | ||
595 | //======================================================================= | |
596 | //function : GetAssemblyOwner | |
597 | //purpose : Returns common entity owner if it is an assembly | |
598 | //======================================================================= | |
599 | const Handle(SelectMgr_EntityOwner)& SelectMgr_SelectableObject::GetAssemblyOwner() const | |
600 | { | |
601 | return myAssemblyOwner; | |
602 | } | |
b586500b | 603 | |
604 | //======================================================================= | |
605 | //function : BndBoxOfSelected | |
606 | //purpose : Returns a bounding box of sensitive entities with the owners given | |
607 | // if they are a part of activated selection | |
608 | //======================================================================= | |
609 | Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (Handle(SelectMgr_IndexedMapOfOwner)& theOwners) | |
610 | { | |
611 | Bnd_Box aBnd; | |
612 | ||
613 | if (theOwners->IsEmpty()) | |
614 | return aBnd; | |
615 | ||
616 | for (Init(); More(); Next()) | |
617 | { | |
618 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); | |
619 | if (aSel->GetSelectionState() != SelectMgr_SOS_Activated) | |
620 | continue; | |
621 | ||
622 | for (aSel->Init(); aSel->More(); aSel->Next()) | |
623 | { | |
624 | const Handle(SelectMgr_EntityOwner) anOwner = | |
625 | Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId()); | |
626 | if (theOwners->Contains (anOwner)) | |
627 | { | |
628 | Select3D_BndBox3d aBox = aSel->Sensitive()->BaseSensitive()->BoundingBox(); | |
629 | Bnd_Box aTmpBnd; | |
630 | aTmpBnd.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), | |
631 | aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); | |
632 | aBnd.Add (aTmpBnd); | |
633 | ||
634 | Standard_Integer anOwnerIdx = theOwners->FindIndex (anOwner); | |
635 | if (theOwners->Size() != anOwnerIdx) | |
636 | { | |
637 | theOwners->Swap (anOwnerIdx, theOwners->Size()); | |
638 | } | |
639 | theOwners->RemoveLast(); | |
640 | ||
641 | if (theOwners->IsEmpty()) | |
642 | return aBnd; | |
643 | } | |
644 | } | |
645 | } | |
646 | ||
647 | return aBnd; | |
648 | } | |
c3282ec1 | 649 | |
650 | //======================================================================= | |
651 | //function : GlobalSelOwner | |
652 | //purpose : Returns entity owner corresponding to selection of the object as a whole | |
653 | //======================================================================= | |
654 | Handle(SelectMgr_EntityOwner) SelectMgr_SelectableObject::GlobalSelOwner() const | |
655 | { | |
656 | Handle(SelectMgr_EntityOwner) anOwner; | |
657 | ||
658 | if (!HasSelection (myGlobalSelMode)) | |
659 | return anOwner; | |
660 | ||
661 | const Handle(SelectMgr_Selection)& aGlobalSel = Selection (myGlobalSelMode); | |
662 | if (aGlobalSel->IsEmpty()) | |
663 | return anOwner; | |
664 | ||
665 | aGlobalSel->Init(); | |
666 | anOwner = | |
667 | Handle(SelectMgr_EntityOwner)::DownCast (aGlobalSel->Sensitive()->BaseSensitive()->OwnerId()); | |
668 | ||
669 | return anOwner; | |
670 | } |