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