0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[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
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>
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 : SetLocation
106 //purpose  : 
107 //=======================================================================
108
109 void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation)
110 {
111   // Update location to the subshapes
112   Standard_Integer anIdx;
113   for (anIdx = 0; anIdx < 7; anIdx++)
114     myShapes[anIdx]->SetLocalTransformation (theTransformation);
115
116   AIS_InteractiveObject::SetLocalTransformation (theTransformation);
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->Clear();
280
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
298 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
299                             const Handle(Geom_Transformation)& aTransformation,
300                             const Handle(Prs3d_Presentation)& aPresentation)
301 {
302 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
303  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
304 }
305
306 //=======================================================================
307 //function : ComputeSelection
308 //purpose  : 
309 //=======================================================================
310
311 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
312                                      const Standard_Integer aMode)
313 {
314   // retrieve the tops of the trihedron.
315   Standard_Integer Prior, anIdx;
316   Handle(SelectMgr_EntityOwner) eown;
317   TColgp_Array1OfPnt PP(1,4),PO(1,4);
318   ExtremityPoints(PP);
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   
332   switch (aMode) {
333   case 0:
334     {   // complete triedron only 1 owner : this... priority 5 (same as faces)
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:
342     {  //origin : 
343       Prior = 8;
344       const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
345       eown= new SelectMgr_EntityOwner(anObj,Prior);
346       
347       aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
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       
357       break;
358     }
359   case 2:
360     {  //axes ... priority 7
361       Prior = 7;
362       for (Standard_Integer i=1; i<=3;i++){
363         const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
364         eown= new SelectMgr_EntityOwner(anObj,Prior);
365         aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
366
367       }
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]);
378           Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes();
379           Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
380           aDrawer->SetDatumAspect (aDatum);
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       
389       break;
390     }
391     
392   case 3:
393     {  // main planes priority 6
394 //      PO(1) = PP(1);
395 //      PO(4) = PP(1);
396       Prior =5;
397       
398       
399       const Handle(SelectMgr_SelectableObject)& anObj4 = myShapes[4]; // to avoid ambiguity
400       eown= new SelectMgr_EntityOwner(anObj4,Prior);
401 //      PO(2) = PP(2);PO(3) = PP(3);
402       aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
403
404       const Handle(SelectMgr_SelectableObject)& anObj5 = myShapes[5]; // to avoid ambiguity
405       eown= new SelectMgr_EntityOwner(anObj5,Prior);
406 //      PO(2) = PP(3);PO(3) = PP(4);
407       aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
408
409       const Handle(SelectMgr_SelectableObject)& anObj6 = myShapes[6]; // to avoid ambiguity
410       eown= new SelectMgr_EntityOwner(anObj6,Prior);
411 //      PO(2) = PP(4);PO(3) = PP(2);
412       aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
413       
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         }
423     }
424   }
425   
426 }
427
428 //=======================================================================
429 //function : SetColor
430 //purpose  : 
431 //=======================================================================
432
433 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
434 {
435   SetColor(Quantity_Color(aCol));
436 }
437
438 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
439 {
440   hasOwnColor=Standard_True;
441   myOwnColor = aCol;
442   
443   if(!myDrawer->HasOwnDatumAspect()){
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
462 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
463 {
464   myHasOwnTextColor = Standard_True;
465   myOwnTextColor = aCol;
466   
467   if(!myDrawer->HasOwnDatumAspect()){
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
480 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
481 {
482   myHasOwnArrowColor = Standard_True;
483   myOwnArrowColor = aCol;
484   
485   if(!myDrawer->HasOwnDatumAspect()){
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 //=======================================================================
499 Standard_Boolean AIS_Trihedron::HasTextColor() const {
500
501   return myHasOwnTextColor;
502 }
503
504 //=======================================================================
505 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
506
507   return myOwnTextColor;
508 }
509
510 //=======================================================================
511 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
512
513   return myHasOwnArrowColor;
514 }
515
516 //=======================================================================
517 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
518
519   return myOwnArrowColor;
520 }
521
522
523 //=======================================================================
524 //function : Compute
525 //purpose  : to avoid warning
526 //=======================================================================
527 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, 
528                                const Handle(Prs3d_Presentation)&)
529 {
530 }
531 //=======================================================================
532 //function : Type
533 //purpose  : 
534 //=======================================================================
535
536 AIS_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 //=======================================================================
552 void  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::
579 AcceptDisplayMode(const Standard_Integer aMode) const
580 {return aMode == 0;}
581
582
583
584 //=======================================================================
585 //function : UnsetColor
586 //purpose  : 
587 //=======================================================================
588
589 void 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);
596   if( HasTextColor() ) {
597     SetTextColor(myOwnColor.Name());
598     myHasOwnTextColor = Standard_False;
599   }
600   if( HasArrowColor() ) {
601     SetArrowColor(myOwnColor.Name());
602     myHasOwnArrowColor = Standard_False;
603   }
604   
605 }
606
607 //=======================================================================
608 //function : UnsetWitdth
609 //purpose  : 
610 //=======================================================================
611
612 void 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 }
620 void 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
636 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
637 {
638 //  Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
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    }
650   // Remove subobjects from current context
651   Handle(AIS_InteractiveContext) anAISContext = GetContext();
652   
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     }
667  
668   AIS_InteractiveObject::SetContext (Ctx);
669   LoadSubObjects();
670   for(Standard_Integer i= 0;i<=6;i++)
671     myShapes[i]->SetContext (Ctx);
672 }