0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / src / AIS / AIS_Shape.cxx
1 // Created on: 1996-12-20
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-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_GraphicTool.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <Bnd_Box.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_ShapeSet.hxx>
27 #include <Geom_Transformation.hxx>
28 #include <gp_Pnt.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_AspectText3d.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <Graphic3d_SequenceOfGroup.hxx>
37 #include <Graphic3d_Structure.hxx>
38 #include <HLRBRep.hxx>
39 #include <OSD_Timer.hxx>
40 #include <Precision.hxx>
41 #include <Prs3d.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Prs3d_Projector.hxx>
46 #include <Prs3d_Root.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <StdPrs_BndBox.hxx>
49 #include <StdPrs_ToolTriangulatedShape.hxx>
50 #include <PrsMgr_ModedPresentation.hxx>
51 #include <Quantity_Color.hxx>
52 #include <Select3D_SensitiveBox.hxx>
53 #include <Select3D_SensitiveEntity.hxx>
54 #include <Standard_ErrorHandler.hxx>
55 #include <Standard_Failure.hxx>
56 #include <Standard_Type.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
58 #include <StdPrs_HLRShape.hxx>
59 #include <StdPrs_ShadedShape.hxx>
60 #include <StdPrs_WFShape.hxx>
61 #include <StdSelect.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_DisplayMode.hxx>
65 #include <TColStd_ListIteratorOfListOfInteger.hxx>
66 #include <TopExp.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopoDS_Shape.hxx>
70
71 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
72
73 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
74 {
75   TColStd_ListIteratorOfListOfInteger It(LL);
76   for(;It.More();It.Next()){
77     if(It.Value()==aMode) 
78       return Standard_True;}
79   return Standard_False;
80 }
81
82 //==================================================
83 // Function: 
84 // Purpose :
85 //==================================================
86
87 AIS_Shape::
88 AIS_Shape(const TopoDS_Shape& shap):
89 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
90 myInitAng(0.)
91 {
92   Set (shap);
93   SetHilightMode(0);
94   myDrawer->SetShadingAspectGlobal(Standard_False);
95 }
96
97 //=======================================================================
98 //function : Type
99 //purpose  : 
100 //=======================================================================
101 AIS_KindOfInteractive AIS_Shape::Type() const 
102 {return AIS_KOI_Shape;}
103
104
105 //=======================================================================
106 //function : Signature
107 //purpose  : 
108 //=======================================================================
109 Standard_Integer AIS_Shape::Signature() const 
110 {return 0;}
111
112 //=======================================================================
113 //function : AcceptShapeDecomposition
114 //purpose  : 
115 //=======================================================================
116 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const 
117 {return Standard_True;}
118
119 //=======================================================================
120 //function : Compute
121 //purpose  : 
122 //=======================================================================
123 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
124                         const Handle(Prs3d_Presentation)& aPrs,
125                         const Standard_Integer aMode)
126 {  
127   aPrs->Clear();
128   if(myshape.IsNull()) return;
129
130   // wire,edge,vertex -> pas de HLR + priorite display superieure
131   Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
132   if(TheType>4 && TheType<8) {
133     aPrs->SetVisual(Graphic3d_TOS_ALL);
134     aPrs->SetDisplayPriority(TheType+2);
135   }
136   // Shape vide -> Assemblage vide.
137   if (myshape.ShapeType() == TopAbs_COMPOUND) {
138     TopoDS_Iterator anExplor (myshape);
139
140     if (!anExplor.More()) {
141       return;
142     }
143   }
144
145   if (IsInfinite())
146   {
147     aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
148   }
149
150   switch (aMode)
151   {
152     case AIS_WireFrame:
153     {
154       try
155       {
156         OCC_CATCH_SIGNALS
157         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
158       }
159       catch (Standard_Failure)
160       {
161       #ifdef OCCT_DEBUG
162         cout << "AIS_Shape::Compute() failed" << endl;
163         cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
164       #endif
165         // presentation of the bounding box is calculated
166         //      Compute(aPresentationManager,aPrs,2);
167       }
168       break;
169     }
170     case AIS_Shaded:
171     {
172       if (myDrawer->IsAutoTriangulation())
173       {
174         Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
175         Standard_Boolean isOwnDeviationAngle       = OwnDeviationAngle      (anAngleNew, anAnglePrev);
176         Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew,  aCoeffPrev);
177         if ((isOwnDeviationAngle       && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
178          || (isOwnDeviationCoefficient && Abs (aCoeffNew  - aCoeffPrev)  > Precision::Confusion()))
179         {
180           BRepTools::Clean (myshape);
181         }
182       }
183
184       if ((Standard_Integer) myshape.ShapeType() > 4)
185       {
186         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
187       }
188       else
189       {
190         myDrawer->SetShadingAspectGlobal (Standard_False);
191         if (IsInfinite())
192         {
193           StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
194         }
195         else
196         {
197           try
198           {
199             OCC_CATCH_SIGNALS
200             StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
201           }
202           catch (Standard_Failure)
203           {
204           #ifdef OCCT_DEBUG
205             cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
206           #endif
207             StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
208           }
209         }
210       }
211       Standard_Real aTransparency = Transparency() ;
212       if (aTransparency > 0.0)
213       {
214         SetTransparency (aTransparency);
215       }
216       break;
217     }
218
219     // Bounding box.
220     case 2:
221     {
222       if (IsInfinite())
223       {
224         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
225       }
226       else
227       {
228         StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
229       }
230     }
231   }
232
233   // Recompute hidden line presentation (if necessary).
234   aPrs->ReCompute();
235 }
236
237 //=======================================================================
238 //function : Compute
239 //purpose  : Hidden Line Removal
240 //=======================================================================
241 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
242                         const Handle(Prs3d_Presentation)& aPresentation)
243 {
244   Compute(aProjector,aPresentation,myshape);
245 }
246
247 //=======================================================================
248 //function : Compute
249 //purpose  : 
250 //=======================================================================
251
252 void AIS_Shape::Compute(const Handle(Prs3d_Projector)&     aProjector,
253                         const Handle(Geom_Transformation)& TheTrsf,
254                         const Handle(Prs3d_Presentation)&  aPresentation)
255 {
256   const TopLoc_Location& loc = myshape.Location();
257   TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
258   Compute(aProjector,aPresentation,shbis);
259 }
260
261 //=======================================================================
262 //function : Compute
263 //purpose  : 
264 //=======================================================================
265
266 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
267                         const Handle(Prs3d_Presentation)& aPresentation,
268                         const TopoDS_Shape& SH)
269 {
270   if (SH.ShapeType() == TopAbs_COMPOUND) {
271     TopoDS_Iterator anExplor (SH);
272
273     if (!anExplor.More()) // Shape vide -> Assemblage vide.
274       return;
275   }
276
277   Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
278   if (defdrawer->DrawHiddenLine())
279     {myDrawer->EnableDrawHiddenLine();}
280   else {myDrawer->DisableDrawHiddenLine();}
281
282   Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
283   defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
284
285   if (myDrawer->IsAutoTriangulation())
286   {
287     // coefficients for calculation
288     Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
289     Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
290     Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
291     if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
292         ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
293     {
294       BRepTools::Clean(SH);
295     }
296   }
297   
298   {
299     try {
300       OCC_CATCH_SIGNALS
301       switch (TypeOfHLR()) {
302         case Prs3d_TOH_Algo:
303           StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
304           break;
305         case Prs3d_TOH_PolyAlgo:
306         default:
307           StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
308           break;
309       }
310     }
311     catch (Standard_Failure) {
312 #ifdef OCCT_DEBUG
313       cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
314 #endif
315       StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
316     }
317   }
318
319   defdrawer->SetTypeOfDeflection (prevdef);
320 }
321
322 //=======================================================================
323 //function : SelectionType
324 //purpose  : gives the type according to the Index of Selection Mode
325 //=======================================================================
326
327 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
328 {
329   switch(aMode){
330   case 1:
331     return TopAbs_VERTEX;
332   case 2:
333     return TopAbs_EDGE;
334   case 3:
335     return TopAbs_WIRE;
336   case 4:
337     return TopAbs_FACE;
338   case 5:
339     return TopAbs_SHELL;
340   case 6:
341     return TopAbs_SOLID;
342   case 7:
343     return TopAbs_COMPSOLID;
344   case 8:
345     return TopAbs_COMPOUND;
346   case 0:
347   default:
348     return TopAbs_SHAPE;
349   }
350   
351 }
352 //=======================================================================
353 //function : SelectionType
354 //purpose  : gives the SelectionMode according to the Type od Decomposition...
355 //=======================================================================
356 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
357 {
358   switch(aType){
359   case TopAbs_VERTEX:
360     return 1;
361   case TopAbs_EDGE:
362     return 2;
363   case TopAbs_WIRE:
364     return 3;
365   case  TopAbs_FACE:
366     return 4;
367   case TopAbs_SHELL:
368     return 5;
369   case TopAbs_SOLID:
370     return 6;
371   case TopAbs_COMPSOLID:
372     return 7;
373   case TopAbs_COMPOUND:
374     return 8;
375   case TopAbs_SHAPE:
376   default:
377     return 0;
378   }
379 }
380
381
382 //=======================================================================
383 //function : ComputeSelection
384 //purpose  : 
385 //=======================================================================
386
387 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
388                                               const Standard_Integer aMode)
389 {
390   if(myshape.IsNull()) return;
391   if (myshape.ShapeType() == TopAbs_COMPOUND) {
392     TopoDS_Iterator anExplor (myshape);
393
394     if (!anExplor.More()) // empty Shape -> empty Assembly.
395       return;
396   }
397
398   TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
399   TopoDS_Shape shape = myshape;
400
401 // POP protection against crash in low layers
402
403   Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
404   try {  
405     OCC_CATCH_SIGNALS
406     StdSelect_BRepSelectionTool::Load(aSelection,
407                                       this,
408                                       shape,
409                                       TypOfSel,
410                                       aDeflection,
411                                       myDrawer->HLRAngle(),
412                                       myDrawer->IsAutoTriangulation());
413   } catch ( Standard_Failure ) {
414 //    cout << "a Shape should be incorrect : A Selection on the Bnd  is activated   "<<endl;
415     if ( aMode == 0 ) {
416       aSelection->Clear();
417       Bnd_Box B = BoundingBox();
418       Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
419       Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
420       aSelection->Add(aSensitiveBox);
421     }
422   }
423
424   // insert the drawer in the BrepOwners for hilight...
425   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
426 }
427
428 Quantity_NameOfColor AIS_Shape::Color() const {
429 Quantity_Color aColor;
430   Color(aColor);
431   return aColor.Name();
432 }
433
434 void AIS_Shape::Color( Quantity_Color& aColor ) const {
435   aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
436 }
437
438 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
439   return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
440 }
441
442 Standard_Real AIS_Shape::Transparency() const {
443   return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
444 }
445
446 //=======================================================================
447 //function : SetColor
448 //purpose  : 
449 //=======================================================================
450
451 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
452 {
453   SetColor(Quantity_Color(aCol));
454 }
455
456 //=======================================================================
457 //function : setColor
458 //purpose  :
459 //=======================================================================
460
461 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
462                           const Quantity_Color&       theColor) const
463 {
464   if (!theDrawer->HasOwnShadingAspect())
465   {
466     theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
467     if (theDrawer->HasLink())
468     {
469       *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
470     }
471   }
472   if (!theDrawer->HasOwnLineAspect())
473   {
474     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
475     if (theDrawer->HasLink())
476     {
477       *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
478     }
479   }
480   if (!theDrawer->HasOwnWireAspect())
481   {
482     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
483     if (theDrawer->HasLink())
484     {
485       *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
486     }
487   }
488   if (!theDrawer->HasOwnPointAspect())
489   {
490     theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
491     if (theDrawer->HasLink())
492     {
493       *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
494     }
495   }
496   if (!theDrawer->HasOwnFreeBoundaryAspect())
497   {
498     theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
499     if (theDrawer->HasLink())
500     {
501       *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
502     }
503   }
504   if (!theDrawer->HasOwnUnFreeBoundaryAspect())
505   {
506     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
507     if (theDrawer->HasLink())
508     {
509       *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
510     }
511   }
512   if (!theDrawer->HasOwnSeenLineAspect())
513   {
514     theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
515     if (theDrawer->HasLink())
516     {
517       *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
518     }
519   }
520
521   // override color
522   theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
523   theDrawer->SetShadingAspectGlobal (Standard_False);
524   theDrawer->LineAspect()->SetColor (theColor);
525   theDrawer->WireAspect()->SetColor (theColor);
526   theDrawer->PointAspect()->SetColor (theColor);
527   theDrawer->FreeBoundaryAspect()->SetColor (theColor);
528   theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
529   theDrawer->SeenLineAspect()->SetColor (theColor);
530 }
531
532 //=======================================================================
533 //function : SetColor
534 //purpose  :
535 //=======================================================================
536
537 void AIS_Shape::SetColor (const Quantity_Color& theColor)
538 {
539   setColor (myDrawer, theColor);
540   myOwnColor  = theColor;
541   hasOwnColor = Standard_True;
542
543   // modify shading presentation without re-computation
544   const PrsMgr_Presentations&        aPrsList     = Presentations();
545   Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
546   Handle(Graphic3d_AspectLine3d)     aLineAspect  = myDrawer->LineAspect()->Aspect();
547   Handle(Graphic3d_AspectMarker3d)   aPointAspect = myDrawer->PointAspect()->Aspect();
548   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
549   {
550     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
551     if (aPrsModed.Mode() != AIS_Shaded)
552     {
553       continue;
554     }
555
556     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
557
558     // Set aspects for presentation
559     aPrs->SetPrimitivesAspect (anAreaAspect);
560     aPrs->SetPrimitivesAspect (aLineAspect);
561     aPrs->SetPrimitivesAspect (aPointAspect);
562
563     // Go through all groups to change color for all primitives
564     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
565     {
566       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
567
568       // Check if aspect of given type is set for the group, 
569       // because setting aspect for group with no already set aspect
570       // can lead to loss of presentation data
571       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
572       {
573         aGroup->SetGroupPrimitivesAspect (anAreaAspect);
574       }
575       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
576       {
577         aGroup->SetGroupPrimitivesAspect (aLineAspect);
578       }
579       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
580       {
581         aGroup->SetGroupPrimitivesAspect (aPointAspect);
582       }
583     }
584   }
585
586   LoadRecomputable (AIS_WireFrame);
587   LoadRecomputable (2);
588 }
589
590 //=======================================================================
591 //function : UnsetColor
592 //purpose  :
593 //=======================================================================
594
595 void AIS_Shape::UnsetColor()
596 {
597   if (!HasColor())
598   {
599     myToRecomputeModes.Clear();
600     return;
601   }
602   hasOwnColor = Standard_False;
603
604   if (!HasWidth())
605   {
606     Handle(Prs3d_LineAspect) anEmptyAsp;
607     myDrawer->SetLineAspect          (anEmptyAsp);
608     myDrawer->SetWireAspect          (anEmptyAsp);
609     myDrawer->SetFreeBoundaryAspect  (anEmptyAsp);
610     myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
611     myDrawer->SetSeenLineAspect      (anEmptyAsp);
612   }
613   else
614   {
615     Quantity_Color aColor = Quantity_NOC_YELLOW;
616     if (myDrawer->HasLink())
617     {
618       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line,   aColor);
619     }
620     myDrawer->LineAspect()->SetColor (aColor);
621     aColor = Quantity_NOC_RED;
622     if (myDrawer->HasLink())
623     {
624       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire,   aColor);
625     }
626     myDrawer->WireAspect()->SetColor (aColor);
627     aColor = Quantity_NOC_GREEN;
628     if (myDrawer->HasLink())
629     {
630       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free,   aColor);
631     }
632     myDrawer->FreeBoundaryAspect()->SetColor (aColor);
633     aColor = Quantity_NOC_YELLOW;
634     if (myDrawer->HasLink())
635     {
636       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
637     }
638     myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
639     if (myDrawer->HasLink())
640     {
641       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen,   aColor);
642     }
643     myDrawer->SeenLineAspect()->SetColor (aColor);
644   }
645
646   if (HasMaterial()
647    || IsTransparent())
648   {
649     Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
650     Graphic3d_MaterialAspect mat = aDefaultMat;
651     if (HasMaterial() || myDrawer->HasLink())
652     {
653       mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
654     }
655     if (HasMaterial())
656     {
657       Quantity_Color aColor = aDefaultMat.AmbientColor();
658       if (myDrawer->HasLink())
659       {
660         aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
661       }
662       mat.SetColor (aColor);
663     }
664     if (IsTransparent())
665     {
666       Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
667       mat.SetTransparency (aTransp);
668     }
669     myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
670   }
671   else
672   {
673     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
674   }
675   myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
676
677   // modify shading presentation without re-computation
678   const PrsMgr_Presentations&        aPrsList  = Presentations();
679   Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
680   Handle(Graphic3d_AspectLine3d)     aLineAsp  = myDrawer->Link()->LineAspect()->Aspect();
681   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
682   {
683     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
684     if (aPrsModed.Mode() != AIS_Shaded)
685     {
686       continue;
687     }
688
689     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
690
691     aPrs->SetPrimitivesAspect (anAreaAsp);
692     aPrs->SetPrimitivesAspect (aLineAsp);
693
694     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
695     {
696       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
697
698       // Check if aspect of given type is set for the group,
699       // because setting aspect for group with no already set aspect
700       // can lead to loss of presentation data
701       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
702       {
703         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
704       }
705       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
706       {
707         aGroup->SetGroupPrimitivesAspect (aLineAsp);
708       }
709     }
710   }
711
712   LoadRecomputable (AIS_WireFrame);
713   LoadRecomputable (2);
714 }
715
716 //=======================================================================
717 //function : setWidth
718 //purpose  :
719 //=======================================================================
720
721 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
722                           const Standard_Real         theLineWidth) const
723 {
724   if (!theDrawer->HasOwnLineAspect())
725   {
726     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
727     if (theDrawer->HasLink())
728     {
729       *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
730     }
731   }
732   if (!theDrawer->HasOwnWireAspect())
733   {
734     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
735     if (theDrawer->HasLink())
736     {
737       *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
738     }
739   }
740   if (!theDrawer->HasOwnFreeBoundaryAspect())
741   {
742     theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
743     if (theDrawer->HasLink())
744     {
745       *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
746     }
747   }
748   if (!theDrawer->HasOwnUnFreeBoundaryAspect())
749   {
750     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
751     if (theDrawer->HasLink())
752     {
753       *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
754     }
755   }
756   if (!theDrawer->HasOwnSeenLineAspect())
757   {
758     theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
759     if (theDrawer->HasLink())
760     {
761       *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
762     }
763   }
764
765   // override width
766   theDrawer->LineAspect()->SetWidth (theLineWidth);
767   theDrawer->WireAspect()->SetWidth (theLineWidth);
768   theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
769   theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
770   theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
771 }
772
773 //=======================================================================
774 //function : SetWidth
775 //purpose  : 
776 //=======================================================================
777
778 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
779 {
780   setWidth (myDrawer, theLineWidth);
781   myOwnWidth = theLineWidth;
782   LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
783   LoadRecomputable (2);             // and the bounding box...
784 }
785
786 //=======================================================================
787 //function : UnsetWidth
788 //purpose  :
789 //=======================================================================
790
791 void AIS_Shape::UnsetWidth()
792 {
793   if (myOwnWidth == 0.0)
794   {
795     myToRecomputeModes.Clear();
796     return;
797   }
798
799   myOwnWidth = 0.0;
800
801   Handle(Prs3d_LineAspect) anEmptyAsp;
802
803   if (!HasColor())
804   {
805     myDrawer->SetLineAspect          (anEmptyAsp);
806     myDrawer->SetWireAspect          (anEmptyAsp);
807     myDrawer->SetFreeBoundaryAspect  (anEmptyAsp);
808     myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
809     myDrawer->SetSeenLineAspect      (anEmptyAsp);
810   }
811   else
812   {
813     myDrawer->LineAspect()          ->SetWidth (myDrawer->HasLink() ?
814       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
815     myDrawer->WireAspect()          ->SetWidth (myDrawer->HasLink() ?
816       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
817     myDrawer->FreeBoundaryAspect()  ->SetWidth (myDrawer->HasLink() ?
818       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
819     myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
820       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
821     myDrawer->SeenLineAspect()      ->SetWidth (myDrawer->HasLink() ?
822       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
823   }
824   LoadRecomputable (AIS_WireFrame);
825 }
826
827 //=======================================================================
828 //function : setMaterial
829 //purpose  :
830 //=======================================================================
831
832 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
833                              const Graphic3d_MaterialAspect& theMaterial,
834                              const Standard_Boolean          theToKeepColor,
835                              const Standard_Boolean          theToKeepTransp) const
836 {
837   const Quantity_Color aColor  = theDrawer->ShadingAspect()->Material     (myCurrentFacingModel).Color();
838   const Standard_Real  aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
839   if (!theDrawer->HasOwnShadingAspect())
840   {
841     theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
842     if (theDrawer->HasLink())
843     {
844       *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
845     }
846   }
847   theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
848
849   if (theToKeepColor)
850   {
851     theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
852   }
853   if (theToKeepTransp)
854   {
855     theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
856   }
857 }
858
859 //=======================================================================
860 //function : SetMaterial
861 //purpose  : 
862 //=======================================================================
863
864 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
865 {
866   SetMaterial(Graphic3d_MaterialAspect(aMat));
867 }
868
869 //=======================================================================
870 //function : SetMaterial
871 //purpose  :
872 //=======================================================================
873
874 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
875 {
876   setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
877   hasOwnMaterial = Standard_True;
878
879   // modify shading presentation without re-computation
880   const PrsMgr_Presentations&        aPrsList  = Presentations();
881   Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
882   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
883   {
884     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
885     if (aPrsModed.Mode() != AIS_Shaded)
886     {
887       continue;
888     }
889
890     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
891     aPrs->SetPrimitivesAspect (anAreaAsp);
892     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
893     {
894       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
895
896       // Check if aspect of given type is set for the group, 
897       // because setting aspect for group with no already set aspect
898       // can lead to loss of presentation data
899       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
900       {
901         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
902       }
903     }
904   }
905
906   myRecomputeEveryPrs = Standard_False; // no mode to recalculate  :only viewer update
907   myToRecomputeModes.Clear();
908 }
909
910 //=======================================================================
911 //function : UnsetMaterial
912 //purpose  :
913 //=======================================================================
914
915 void AIS_Shape::UnsetMaterial()
916 {
917   if (!HasMaterial())
918   {
919     return;
920   }
921
922   if (HasColor()
923    || IsTransparent())
924   {
925     if(myDrawer->HasLink())
926     {
927       myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
928                                               myCurrentFacingModel);
929     }
930     if (HasColor())
931     {
932       myDrawer->ShadingAspect()->SetColor        (myOwnColor,     myCurrentFacingModel);
933       myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
934     }
935   }
936   else
937   {
938     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
939   }
940   hasOwnMaterial = Standard_False;
941
942   // modify shading presentation without re-computation
943   const PrsMgr_Presentations&        aPrsList  = Presentations();
944   Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
945   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
946   {
947     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
948     if (aPrsModed.Mode() != AIS_Shaded)
949     {
950       continue;
951     }
952
953     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
954     aPrs->SetPrimitivesAspect (anAreaAsp);
955     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
956     {
957       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
958       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
959       {
960         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
961       }
962     }
963   }
964
965   myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
966   myToRecomputeModes.Clear();  
967 }
968
969 //=======================================================================
970 //function : setTransparency
971 //purpose  :
972 //=======================================================================
973
974 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
975                                  const Standard_Real         theValue) const
976 {
977   if (!theDrawer->HasOwnShadingAspect())
978   {
979     theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
980     if (theDrawer->HasLink())
981     {
982       *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
983     }
984   }
985
986   // override transparency
987   theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
988 }
989
990 //=======================================================================
991 //function : SetTransparency
992 //purpose  :
993 //=======================================================================
994
995 void AIS_Shape::SetTransparency (const Standard_Real theValue)
996 {
997   setTransparency (myDrawer, theValue);
998   myTransparency = theValue;
999
1000   // modify shading presentation without re-computation
1001   const PrsMgr_Presentations&        aPrsList  = Presentations();
1002   Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1003   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1004   {
1005     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1006     if (aPrsModed.Mode() != AIS_Shaded)
1007     {
1008       continue;
1009     }
1010
1011     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1012     aPrs->SetPrimitivesAspect (anAreaAsp);
1013     aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1014     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1015     {
1016       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1017       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1018       {
1019         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1020       }
1021     }
1022   }
1023
1024   myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1025   myToRecomputeModes.Clear();
1026 }
1027
1028 //=======================================================================
1029 //function : UnsetTransparency
1030 //purpose  :
1031 //=======================================================================
1032
1033 void AIS_Shape::UnsetTransparency()
1034 {
1035   myTransparency = 0.0;
1036   if (!myDrawer->HasOwnShadingAspect())
1037   {
1038     return;
1039   }
1040   else if (HasColor() || HasMaterial())
1041   {
1042     myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1043   }
1044   else
1045   {
1046     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1047   }
1048
1049   // modify shading presentation without re-computation
1050   const PrsMgr_Presentations&        aPrsList  = Presentations();
1051   Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1052   for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1053   {
1054     const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1055     if (aPrsModed.Mode() != AIS_Shaded)
1056     {
1057       continue;
1058     }
1059
1060     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1061     aPrs->SetPrimitivesAspect (anAreaAsp);
1062     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1063     {
1064       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1065       if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1066       {
1067         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1068       }
1069     }
1070     aPrs->ResetDisplayPriority();
1071   }
1072
1073   myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1074   myToRecomputeModes.Clear();
1075 }
1076
1077 //=======================================================================
1078 //function : LoadRecomputable
1079 //purpose  : 
1080 //=======================================================================
1081
1082 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1083 {
1084   myRecomputeEveryPrs = Standard_False;
1085   if(!IsInList(myToRecomputeModes,TheMode))
1086     myToRecomputeModes.Append(TheMode);
1087 }
1088
1089 //=======================================================================
1090 //function : BoundingBox
1091 //purpose  : 
1092 //=======================================================================
1093
1094 const Bnd_Box& AIS_Shape::BoundingBox()  
1095 {
1096   if (myshape.ShapeType() == TopAbs_COMPOUND) {
1097     TopoDS_Iterator anExplor (myshape);
1098
1099     if (!anExplor.More()) { // empty Shape  -> empty Assembly.
1100       myBB.SetVoid();
1101       return myBB;
1102     }
1103   }
1104
1105   if(myCompBB) {
1106     BRepBndLib::AddClose(myshape, myBB);
1107     myCompBB = Standard_False;
1108   }
1109   return myBB;
1110 }
1111
1112 //*****
1113 //***** Reset
1114 //=======================================================================
1115 //function : SetOwnDeviationCoefficient
1116 //purpose  : resets myhasOwnDeviationCoefficient to Standard_False and
1117 //           returns Standard_True if it change
1118 //=======================================================================
1119
1120 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1121 {
1122   Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1123   if(itSet)  myDrawer->SetDeviationCoefficient();
1124   return itSet;
1125 }
1126
1127 //=======================================================================
1128 //function : SetHLROwnDeviationCoefficient
1129 //purpose  : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1130 //           returns Standard_True if it change
1131 //=======================================================================
1132
1133 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1134 {
1135   Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1136   if(itSet)  myDrawer->SetHLRDeviationCoefficient();
1137   return itSet;
1138
1139 }
1140
1141 //=======================================================================
1142 //function : SetOwnDeviationAngle
1143 //purpose  : resets myhasOwnDeviationAngle to Standard_False and
1144 //           returns Standard_True if it change
1145 //=======================================================================
1146
1147 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1148 {
1149   Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1150   if(itSet)  myDrawer->SetDeviationAngle();
1151   return itSet;
1152
1153 }
1154
1155 //=======================================================================
1156 //function : SetOwnHLRDeviationAngle
1157 //purpose  : resets myhasOwnHLRDeviationAngle to Standard_False and
1158 //           returns Standard_True if it change
1159 //=======================================================================
1160
1161 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1162 {
1163   Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1164   if(itSet)  myDrawer->SetHLRAngle();
1165   return itSet;
1166
1167 }
1168 //***** SetOwn
1169 //=======================================================================
1170 //function : SetOwnDeviationCoefficient
1171 //purpose  : 
1172 //=======================================================================
1173
1174 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real  aCoefficient )
1175 {
1176   myDrawer->SetDeviationCoefficient( aCoefficient );
1177   SetToUpdate(0) ; // WireFrame
1178   SetToUpdate(1) ; // Shadding
1179 }
1180
1181 //=======================================================================
1182 //function : SetOwnHLRDeviationCoefficient
1183 //purpose  : 
1184 //=======================================================================
1185
1186 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real  aCoefficient )
1187 {
1188   myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1189   
1190 }
1191
1192 //=======================================================================
1193 //function : SetOwnDeviationAngle
1194 //purpose  : 
1195 //=======================================================================
1196
1197 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real  anAngle )
1198 {
1199
1200   myDrawer->SetDeviationAngle(anAngle );
1201   SetToUpdate(0) ;   // WireFrame
1202 }
1203 //=======================================================================
1204 //function : SetOwnDeviationAngle
1205 //purpose  : 
1206 //=======================================================================
1207
1208 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real  anAngle )
1209 {
1210   Standard_Real OutAngl,OutDefl;
1211   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1212   SetOwnDeviationAngle(anAngle) ;
1213   SetOwnDeviationCoefficient(OutDefl) ;
1214   myInitAng = anAngle;
1215   SetToUpdate(0);
1216   SetToUpdate(1);
1217 }
1218
1219 //=======================================================================
1220 //function : UserAngle
1221 //purpose  : 
1222 //=======================================================================
1223
1224 Standard_Real AIS_Shape::UserAngle() const
1225 {
1226   return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1227 }
1228
1229
1230 //=======================================================================
1231 //function : SetHLRAngleAndDeviation
1232 //purpose  : 
1233 //=======================================================================
1234
1235 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real  anAngle )
1236 {
1237   Standard_Real OutAngl,OutDefl;
1238   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1239   SetOwnHLRDeviationAngle( OutAngl );
1240   SetOwnHLRDeviationCoefficient(OutDefl);
1241
1242 }
1243 //=======================================================================
1244 //function : SetOwnHLRDeviationAngle
1245 //purpose  : 
1246 //=======================================================================
1247
1248 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real  anAngle )
1249 {
1250   myDrawer->SetHLRAngle( anAngle );
1251 }
1252
1253 //***** GetOwn
1254 //=======================================================================
1255 //function : OwnDeviationCoefficient
1256 //purpose  : 
1257 //=======================================================================
1258
1259 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real &  aCoefficient,
1260                                                       Standard_Real & aPreviousCoefficient ) const
1261 {
1262   aCoefficient = myDrawer->DeviationCoefficient();
1263   aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1264   return myDrawer->HasOwnDeviationCoefficient() ;
1265 }
1266
1267 //=======================================================================
1268 //function : OwnHLRDeviationCoefficient
1269 //purpose  : 
1270 //=======================================================================
1271
1272 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1273                                                          Standard_Real & aPreviousCoefficient ) const
1274 {
1275   aCoefficient = myDrawer->HLRDeviationCoefficient();
1276   aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1277   return myDrawer->HasOwnHLRDeviationCoefficient();
1278
1279 }
1280
1281 //=======================================================================
1282 //function : OwnDeviationAngle
1283 //purpose  : 
1284 //=======================================================================
1285
1286 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real &  anAngle,
1287                                                 Standard_Real & aPreviousAngle ) const
1288 {
1289   anAngle = myDrawer->DeviationAngle();
1290   aPreviousAngle = myDrawer->PreviousDeviationAngle (); 
1291   return myDrawer->HasOwnDeviationAngle();
1292 }
1293
1294 //=======================================================================
1295 //function : OwnHLRDeviationAngle
1296 //purpose  : 
1297 //=======================================================================
1298
1299 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real &  anAngle,
1300                                                    Standard_Real & aPreviousAngle ) const
1301 {
1302   anAngle = myDrawer->HLRAngle();
1303   aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); 
1304   return myDrawer->HasOwnHLRDeviationAngle();
1305 }