0025576: Visualization - implement AIS_ConnectedInteractive::AcceptDisplayMode()
[occt.git] / src / AIS / AIS_Trihedron.cxx
CommitLineData
b311480e 1// Created on: 1995-10-09
2// Created by: Arnaud BOUZY/Odile Olivier
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
42cf5bc1 17
18#include <AIS_Axis.hxx>
19#include <AIS_InteractiveContext.hxx>
20#include <AIS_InteractiveObject.hxx>
21#include <AIS_Plane.hxx>
22#include <AIS_Point.hxx>
23#include <AIS_Trihedron.hxx>
24#include <Aspect_TypeOfLine.hxx>
7fd59977 25#include <DsgPrs_DatumPrs.hxx>
7fd59977 26#include <Geom_Axis2Placement.hxx>
42cf5bc1 27#include <Geom_CartesianPoint.hxx>
7fd59977 28#include <Geom_Line.hxx>
7fd59977 29#include <Geom_Plane.hxx>
42cf5bc1 30#include <Geom_Point.hxx>
31#include <Geom_Transformation.hxx>
7fd59977 32#include <gp_Ax1.hxx>
33#include <gp_Ax2.hxx>
42cf5bc1 34#include <gp_Dir.hxx>
7fd59977 35#include <gp_Pnt.hxx>
42cf5bc1 36#include <gp_Trsf.hxx>
7fd59977 37#include <gp_Vec.hxx>
42cf5bc1 38#include <Graphic3d_AspectFillArea3d.hxx>
39#include <Graphic3d_AspectLine3d.hxx>
40#include <Graphic3d_MaterialAspect.hxx>
41#include <Graphic3d_Structure.hxx>
42#include <Prs3d_ArrowAspect.hxx>
43#include <Prs3d_DatumAspect.hxx>
7fd59977 44#include <Prs3d_Drawer.hxx>
45#include <Prs3d_LineAspect.hxx>
42cf5bc1 46#include <Prs3d_Presentation.hxx>
47#include <Prs3d_Projector.hxx>
7fd59977 48#include <Prs3d_TextAspect.hxx>
42cf5bc1 49#include <Quantity_Color.hxx>
7fd59977 50#include <Select3D_SensitiveBox.hxx>
42cf5bc1 51#include <Select3D_SensitivePoint.hxx>
52#include <Select3D_SensitiveSegment.hxx>
7fd59977 53#include <Select3D_SensitiveTriangle.hxx>
42cf5bc1 54#include <SelectBasics_EntityOwner.hxx>
55#include <SelectMgr_EntityOwner.hxx>
56#include <Standard_Type.hxx>
7fd59977 57#include <TColgp_Array1OfPnt.hxx>
42cf5bc1 58#include <UnitsAPI.hxx>
7fd59977 59
92efcf78 60IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron,AIS_InteractiveObject)
61
7fd59977 62//=======================================================================
63//function : AIS_Trihedron
64//purpose :
65//=======================================================================
66AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
046a1c9d 67myComponent (aComponent),
68myHasOwnSize (Standard_False),
69myHasOwnTextColor (Standard_False),
70myHasOwnArrowColor (Standard_False)
71{
72 LoadSubObjects();
73}
7fd59977 74
75//=======================================================================
76//function : SetComponent
77//purpose :
78//=======================================================================
79
80void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
81{
82 myComponent = aComponent;
29d43f9c
A
83
84 // Remove from current context and nullify objects to update
85 Handle(AIS_InteractiveContext) anAISContext = GetContext();
86 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
87 Standard_Integer anIdx;
88 for (anIdx = 0; anIdx < 7; anIdx++)
89 {
90 // Deselect object
91 if (hasContext)
92 {
93 if (anAISContext->IsSelected (myShapes[anIdx]))
94 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
95
96 anAISContext->Remove (myShapes[anIdx], Standard_False);
97 }
98 myShapes[anIdx].Nullify();
99 }
100
7fd59977 101 LoadSubObjects();
102}
103
29d43f9c
A
104//=======================================================================
105//function : SetLocation
106//purpose :
107//=======================================================================
108
0717ddc1 109void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation)
29d43f9c
A
110{
111 // Update location to the subshapes
112 Standard_Integer anIdx;
113 for (anIdx = 0; anIdx < 7; anIdx++)
0717ddc1 114 myShapes[anIdx]->SetLocalTransformation (theTransformation);
29d43f9c 115
0717ddc1 116 AIS_InteractiveObject::SetLocalTransformation (theTransformation);
29d43f9c 117}
7fd59977 118
119//=======================================================================
120//function : SetSize
121//purpose :
122//=======================================================================
123void AIS_Trihedron::SetSize(const Standard_Real aValue)
124{
125 myHasOwnSize = Standard_True;
6262338c 126 if(!myDrawer->HasOwnDatumAspect()){
7fd59977 127 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
128 myDrawer->SetDatumAspect(DA);
129 }
130
131 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
132
133 for(Standard_Integer i=4;i<=6;i++)
5b111128 134 Handle(AIS_Plane)::DownCast (myShapes[i])->SetSize(aValue);
7fd59977 135
136 Update();
137 UpdateSelection();
138}
139
140
141
142//=======================================================================
143//function : UnsetSize
81bba717 144//purpose : if the object has 1 color, the default size of the
145// drawer is reproduced, otherwise DatumAspect becomes null
7fd59977 146//=======================================================================
147
148void AIS_Trihedron::UnsetSize()
149{
150 if(!myHasOwnSize) return;
151
152 myHasOwnSize = Standard_False;
153 if(hasOwnColor){
6262338c 154 const Handle(Prs3d_DatumAspect) DA =
155 myDrawer->HasLink() ? myDrawer->Link()->DatumAspect() : new Prs3d_DatumAspect();
7fd59977 156 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
157 DA->SecondAxisLength(),
158 DA->ThirdAxisLength());
159 }
160 else
6262338c 161 {
162 myDrawer->SetDatumAspect (Handle(Prs3d_DatumAspect)());
163 }
7fd59977 164 Update();
165 UpdateSelection();
166
167}
168
169//=======================================================================
170//function : Size
171//purpose :
172//=======================================================================
173
174Standard_Real AIS_Trihedron::Size() const
175{
6262338c 176 return myDrawer->DatumAspect()->FirstAxisLength();
7fd59977 177}
178
179//=======================================================================
180//function : XAxis
181//purpose :
182//=======================================================================
183Handle(AIS_Axis) AIS_Trihedron::XAxis() const
184{
185 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
046a1c9d 186 if (anAxis.IsNull())
187 {
188 anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
189 }
7fd59977 190 return anAxis;
191}
192
193//=======================================================================
194//function : YAxis
195//purpose :
196//=======================================================================
197Handle(AIS_Axis) AIS_Trihedron::YAxis() const
198{
199 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
046a1c9d 200 if (anAxis.IsNull())
201 {
202 anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
203 }
204
7fd59977 205 return anAxis;
206}
207
208//=======================================================================
209//function : Axis
210//purpose :
211//=======================================================================
212Handle(AIS_Axis) AIS_Trihedron::Axis() const
213{
214 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
046a1c9d 215 if (anAxis.IsNull())
216 {
217 anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
218 }
7fd59977 219 return anAxis;
220}
221
222//=======================================================================
223//function : Position
224//purpose :
225//=======================================================================
226Handle(AIS_Point) AIS_Trihedron::Position() const
227{
228 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
229 if (aPt.IsNull()) {
230 gp_Pnt aPnt = myComponent->Ax2().Location();
231 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
232 aPt = new AIS_Point (aPoint);
233 }
234 return aPt;
235}
236
237//=======================================================================
238//function : XYPlane
239//purpose :
240//=======================================================================
241Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
242{
243 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
244 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
245 return aPl;
246}
247
248//=======================================================================
249//function : XZPlane
250//purpose :
251//=======================================================================
252Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
253{
254 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
255 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
256 return aPl;
257}
258
259//=======================================================================
260//function : YZPlane
261//purpose :
262//=======================================================================
263Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
264{
265 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
266 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
267 return aPl;
268}
269
270//=======================================================================
271//function : Compute
272//purpose :
273//=======================================================================
274void AIS_Trihedron::Compute(
275 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
276 const Handle(Prs3d_Presentation)& aPresentation,
277 const Standard_Integer aMode)
278{
279 aPresentation->Clear();
280
7fd59977 281 aPresentation->SetInfiniteState (Standard_True);
282 switch(aMode){
283 case 0:
284 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
285 break;
286 case 1:
287 break;
288 case 2:
289 break;
290 }
291}
292
293//=======================================================================
294//function : Compute
295//purpose :
296//=======================================================================
297
857ffd5e 298void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
299 const Handle(Geom_Transformation)& aTransformation,
300 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 301{
857ffd5e 302// Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 303 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
304}
305
306//=======================================================================
307//function : ComputeSelection
308//purpose :
309//=======================================================================
310
311void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
312 const Standard_Integer aMode)
313{
81bba717 314 // retrieve the tops of the trihedron.
29d43f9c 315 Standard_Integer Prior, anIdx;
7fd59977 316 Handle(SelectMgr_EntityOwner) eown;
317 TColgp_Array1OfPnt PP(1,4),PO(1,4);
318 ExtremityPoints(PP);
29d43f9c
A
319
320 // remove shapes from active selections
321 Handle(AIS_InteractiveContext) anAISContext = GetContext();
322 if (!anAISContext.IsNull())
323 for (anIdx = 0; anIdx < 7; anIdx++)
324 {
325 // Deselect object
326 if (anAISContext->IsSelected (myShapes[anIdx]))
327 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
328
329 anAISContext->Remove (myShapes[anIdx], Standard_False);
330 }
331
7fd59977 332 switch (aMode) {
333 case 0:
81bba717 334 { // complete triedron only 1 owner : this... priority 5 (same as faces)
7fd59977 335 Prior = 5;
336 eown = new SelectMgr_EntityOwner(this,Prior);
337 for (Standard_Integer i=1; i<=3;i++)
338 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
339 break;
340 }
341 case 1:
81bba717 342 { //origin :
7fd59977 343 Prior = 8;
543a9964 344 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
345 eown= new SelectMgr_EntityOwner(anObj,Prior);
7fd59977 346
347 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
29d43f9c
A
348 // If the trihedron's shapes display and selection modes are the same
349 // the shapes are still displayed after selection, so we need to
350 // use different presentation and hide it by nullifying
351 if (!anAISContext.IsNull())
352 {
353 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
354 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
355 }
356
7fd59977 357 break;
358 }
359 case 2:
81bba717 360 { //axes ... priority 7
7fd59977 361 Prior = 7;
362 for (Standard_Integer i=1; i<=3;i++){
543a9964 363 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
364 eown= new SelectMgr_EntityOwner(anObj,Prior);
7fd59977 365 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
366
367 }
29d43f9c
A
368
369 // If the trihedron's shapes display and selection modes are the same
370 // the shapes are still displayed after selection, so we need to
371 // use different presentation and hide it by nullifying
372 AIS_TypeOfAxis anAxisType;
373 if (!anAISContext.IsNull())
374 for (anIdx = 1; anIdx <= 3; anIdx++)
375 {
376 // update AIS_Axis for selection
377 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
6262338c 378 Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes();
29d43f9c 379 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
046a1c9d 380 aDrawer->SetDatumAspect (aDatum);
29d43f9c
A
381 anAxisType = anAxis->TypeOfAxis();
382 anAxis->SetAxis2Placement (myComponent, anAxisType);
383
384 // display
385 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
386 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
387 }
388
7fd59977 389 break;
390 }
391
392 case 3:
81bba717 393 { // main planes priority 6
7fd59977 394// PO(1) = PP(1);
395// PO(4) = PP(1);
396 Prior =5;
397
398
543a9964 399 const Handle(SelectMgr_SelectableObject)& anObj4 = myShapes[4]; // to avoid ambiguity
400 eown= new SelectMgr_EntityOwner(anObj4,Prior);
7fd59977 401// PO(2) = PP(2);PO(3) = PP(3);
402 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
403
543a9964 404 const Handle(SelectMgr_SelectableObject)& anObj5 = myShapes[5]; // to avoid ambiguity
405 eown= new SelectMgr_EntityOwner(anObj5,Prior);
7fd59977 406// PO(2) = PP(3);PO(3) = PP(4);
407 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
408
543a9964 409 const Handle(SelectMgr_SelectableObject)& anObj6 = myShapes[6]; // to avoid ambiguity
410 eown= new SelectMgr_EntityOwner(anObj6,Prior);
7fd59977 411// PO(2) = PP(4);PO(3) = PP(2);
412 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
413
29d43f9c
A
414 // If the trihedron's shapes display and selection modes are the same
415 // the shapes are still displayed after selection, so we need to
416 // use different presentation and hide it by nullifying
417 if (!anAISContext.IsNull())
418 for (anIdx = 4; anIdx < 7; anIdx++)
419 {
420 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
421 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
422 }
7fd59977 423 }
424 }
425
426}
427
428//=======================================================================
429//function : SetColor
430//purpose :
431//=======================================================================
432
433void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
7fd59977 434{
435 SetColor(Quantity_Color(aCol));
436}
437
438void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
7fd59977 439{
440 hasOwnColor=Standard_True;
441 myOwnColor = aCol;
442
6262338c 443 if(!myDrawer->HasOwnDatumAspect()){
7fd59977 444 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
445
446 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
447 myDrawer->DatumAspect()->SecondAxisLength(),
448 myDrawer->DatumAspect()->ThirdAxisLength());
449 myDrawer->SetDatumAspect(DA);
450 }
451 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
452 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
453 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
454
455}
456
457//=======================================================================
458//function : SetTextColor
459//purpose :
460//=======================================================================
461
7fd59977 462void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
463{
464 myHasOwnTextColor = Standard_True;
465 myOwnTextColor = aCol;
466
6262338c 467 if(!myDrawer->HasOwnDatumAspect()){
7fd59977 468 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
469
470 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
471 myDrawer->DatumAspect()->SecondAxisLength(),
472 myDrawer->DatumAspect()->ThirdAxisLength());
473 myDrawer->SetDatumAspect(DA);
474 }
475 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
476 aspect->SetColor(aCol);
477 myDrawer->SetTextAspect(aspect);
478}
479
480void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
481{
482 myHasOwnArrowColor = Standard_True;
483 myOwnArrowColor = aCol;
484
6262338c 485 if(!myDrawer->HasOwnDatumAspect()){
7fd59977 486 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
487
488 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
489 myDrawer->DatumAspect()->SecondAxisLength(),
490 myDrawer->DatumAspect()->ThirdAxisLength());
491 myDrawer->SetDatumAspect(DA);
492 }
493 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
494 aspect->SetColor(aCol);
495 myDrawer->SetArrowAspect(aspect);
496}
497
498//=======================================================================
499Standard_Boolean AIS_Trihedron::HasTextColor() const {
500
501 return myHasOwnTextColor;
502}
503
504//=======================================================================
505Quantity_NameOfColor AIS_Trihedron::TextColor() const {
506
507 return myOwnTextColor;
508}
509
510//=======================================================================
511Standard_Boolean AIS_Trihedron::HasArrowColor() const {
512
513 return myHasOwnArrowColor;
514}
515
516//=======================================================================
517Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
518
519 return myOwnArrowColor;
520}
7fd59977 521
7fd59977 522
523//=======================================================================
524//function : Compute
525//purpose : to avoid warning
526//=======================================================================
527void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
528 const Handle(Prs3d_Presentation)&)
529{
530}
531//=======================================================================
532//function : Type
533//purpose :
534//=======================================================================
535
536AIS_KindOfInteractive AIS_Trihedron::Type() const
537{return AIS_KOI_Datum;}
538
539
540//=======================================================================
541//function : Signature
542//purpose :
543//=======================================================================
544
545 Standard_Integer AIS_Trihedron::Signature() const
546{return 3;}
547
548//=======================================================================
549//function : ExtremityPoints
550//purpose : to avoid warning
551//=======================================================================
552void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
553{
554 gp_Ax2 theax(myComponent->Ax2());
555 PP(1) = theax.Location();
556
557 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
558 gp_Vec vec = theax.XDirection();
559 vec *= len;
560 PP(2) = PP(1).Translated(vec);
561
562 len = myDrawer->DatumAspect()->SecondAxisLength();
563 vec = theax.YDirection();
564 vec *= len;
565 PP(3) = PP(1).Translated(vec);
566
567 len = myDrawer->DatumAspect()->ThirdAxisLength();
568 vec = theax.Direction();
569 vec *= len;
570 PP(4) = PP(1).Translated(vec);
571}
572
573//=======================================================================
574//function : AcceptDisplayMode
575//purpose :
576//=======================================================================
577
578 Standard_Boolean AIS_Trihedron::
579AcceptDisplayMode(const Standard_Integer aMode) const
580{return aMode == 0;}
581
582
583
584//=======================================================================
585//function : UnsetColor
586//purpose :
587//=======================================================================
588
589void AIS_Trihedron::UnsetColor()
590{
591 hasOwnColor=Standard_False;
592 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
593 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
594 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
595 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
7fd59977 596 if( HasTextColor() ) {
597 SetTextColor(myOwnColor.Name());
598 myHasOwnTextColor = Standard_False;
599 }
600 if( HasArrowColor() ) {
601 SetArrowColor(myOwnColor.Name());
602 myHasOwnArrowColor = Standard_False;
603 }
7fd59977 604
605}
606
607//=======================================================================
608//function : UnsetWitdth
609//purpose :
610//=======================================================================
611
612void AIS_Trihedron::UnsetWidth()
613{
614 myOwnWidth =0.0;
615 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
616 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
617 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
618
619}
620void AIS_Trihedron::LoadSubObjects()
621{
622 myShapes[0] = Position();
623 myShapes[1] = XAxis();
624 myShapes[2] = YAxis();
625 myShapes[3] = Axis();
626 myShapes[4] = XYPlane();
627 myShapes[5] = XZPlane();
628 myShapes[6] = YZPlane();
629}
630
631//=======================================================================
632//function : SetContext
633//purpose :
634//=======================================================================
635
636void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
637{
638// Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
da0e82aa 639
640 if( Ctx.IsNull())
641 {
642 Standard_Integer anIdx;
643 for (anIdx = 0; anIdx < 7; anIdx++)
644 {
645 myShapes[anIdx]->SetContext(Ctx);
646 }
647 AIS_InteractiveObject::SetContext (Ctx);
648 return;
649 }
29d43f9c
A
650 // Remove subobjects from current context
651 Handle(AIS_InteractiveContext) anAISContext = GetContext();
da0e82aa 652
29d43f9c
A
653 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
654 Standard_Integer anIdx;
655 for (anIdx = 0; anIdx < 7; anIdx++)
656 {
657 // Deselect object
658 if (hasContext)
659 {
660 if (anAISContext->IsSelected (myShapes[anIdx]))
661 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
662
663 anAISContext->Remove (myShapes[anIdx], Standard_False);
664 }
665 myShapes[anIdx].Nullify();
666 }
da0e82aa 667
29d43f9c 668 AIS_InteractiveObject::SetContext (Ctx);
7fd59977 669 LoadSubObjects();
670 for(Standard_Integer i= 0;i<=6;i++)
29d43f9c 671 myShapes[i]->SetContext (Ctx);
7fd59977 672}