0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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 #include <AIS_Shape.hxx>
18
19 #include <AIS_GraphicTool.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <BRep_Builder.hxx>
23 #include <BRepBndLib.hxx>
24 #include <BRepTools.hxx>
25 #include <BRepTools_ShapeSet.hxx>
26 #include <gp_Pnt.hxx>
27 #include <Graphic3d_ArrayOfPolylines.hxx>
28 #include <Graphic3d_AspectFillArea3d.hxx>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Graphic3d_AspectMarker3d.hxx>
31 #include <Graphic3d_AspectText3d.hxx>
32 #include <Graphic3d_Group.hxx>
33 #include <Graphic3d_MaterialAspect.hxx>
34 #include <Graphic3d_SequenceOfGroup.hxx>
35 #include <Graphic3d_Structure.hxx>
36 #include <Message.hxx>
37 #include <Message_Messenger.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_Root.hxx>
46 #include <Prs3d_ShadingAspect.hxx>
47 #include <Prs3d_BndBox.hxx>
48 #include <StdPrs_ToolTriangulatedShape.hxx>
49 #include <Quantity_Color.hxx>
50 #include <Select3D_SensitiveBox.hxx>
51 #include <Select3D_SensitiveEntity.hxx>
52 #include <Standard_ErrorHandler.hxx>
53 #include <Standard_Failure.hxx>
54 #include <Standard_Type.hxx>
55 #include <StdPrs_HLRPolyShape.hxx>
56 #include <StdPrs_HLRShape.hxx>
57 #include <StdPrs_ShadedShape.hxx>
58 #include <StdPrs_WFShape.hxx>
59 #include <StdSelect.hxx>
60 #include <StdSelect_BRepOwner.hxx>
61 #include <StdSelect_BRepSelectionTool.hxx>
62 #include <TColStd_ListIteratorOfListOfInteger.hxx>
63 #include <TopExp.hxx>
64
65 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
66
67 // Auxiliary macros
68 #define replaceAspectWithDef(theMap, theAspect) \
69   if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
70   { \
71     theMap.Bind (myDrawer->theAspect()->Aspect(), myDrawer->Link()->theAspect()->Aspect()); \
72   }
73
74 // Auxiliary macros for replaceWithNewOwnAspects()
75 #define replaceAspectWithOwn(theMap, theAspect) \
76   if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
77   { \
78     theMap.Bind (myDrawer->Link()->theAspect()->Aspect(), myDrawer->theAspect()->Aspect()); \
79   }
80
81 //=======================================================================
82 //function : replaceWithNewOwnAspects
83 //purpose  :
84 //=======================================================================
85 void AIS_Shape::replaceWithNewOwnAspects()
86 {
87   Graphic3d_MapOfAspectsToAspects aReplaceMap;
88
89   replaceAspectWithOwn (aReplaceMap, ShadingAspect);
90   replaceAspectWithOwn (aReplaceMap, LineAspect);
91   replaceAspectWithOwn (aReplaceMap, WireAspect);
92   replaceAspectWithOwn (aReplaceMap, FreeBoundaryAspect);
93   replaceAspectWithOwn (aReplaceMap, UnFreeBoundaryAspect);
94   replaceAspectWithOwn (aReplaceMap, SeenLineAspect);
95   replaceAspectWithOwn (aReplaceMap, FaceBoundaryAspect);
96   replaceAspectWithOwn (aReplaceMap, PointAspect);
97
98   replaceAspects (aReplaceMap);
99 }
100
101 //==================================================
102 // Function: AIS_Shape
103 // Purpose :
104 //==================================================
105 AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
106 : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
107   myshape (theShape),
108   myUVOrigin(0.0, 0.0),
109   myUVRepeat(1.0, 1.0),
110   myUVScale (1.0, 1.0),
111   myInitAng (0.0),
112   myCompBB (Standard_True)
113 {
114   //
115 }
116
117 //=======================================================================
118 //function : Compute
119 //purpose  : 
120 //=======================================================================
121 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
122                         const Handle(Prs3d_Presentation)& aPrs,
123                         const Standard_Integer theMode)
124 {  
125   if(myshape.IsNull()) return;
126
127   // wire,edge,vertex -> pas de HLR + priorite display superieure
128   Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
129   if(TheType>4 && TheType<8) {
130     aPrs->SetVisual(Graphic3d_TOS_ALL);
131     aPrs->SetDisplayPriority(TheType+2);
132   }
133   // Shape vide -> Assemblage vide.
134   if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
135   {
136     return;
137   }
138
139   if (IsInfinite())
140   {
141     aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
142   }
143
144   switch (theMode)
145   {
146     case AIS_WireFrame:
147     {
148       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
149       try
150       {
151         OCC_CATCH_SIGNALS
152         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
153       }
154       catch (Standard_Failure const& anException)
155       {
156         Message::DefaultMessenger()->Send (TCollection_AsciiString()
157                                          + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
158                                          + anException.GetMessageString() + ")", Message_Fail);
159       }
160       break;
161     }
162     case AIS_Shaded:
163     {
164       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
165       if ((Standard_Integer) myshape.ShapeType() > 4)
166       {
167         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
168       }
169       else
170       {
171         if (IsInfinite())
172         {
173           StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
174         }
175         else
176         {
177           try
178           {
179             OCC_CATCH_SIGNALS
180             StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
181                                      myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
182                                  && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
183                                      myUVOrigin, myUVRepeat, myUVScale);
184           }
185           catch (Standard_Failure const& anException)
186           {
187             Message::DefaultMessenger()->Send (TCollection_AsciiString()
188                                                + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
189                                                + anException.GetMessageString() + ")", Message_Fail);
190             StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
191           }
192         }
193       }
194       Standard_Real aTransparency = Transparency() ;
195       if (aTransparency > 0.0)
196       {
197         SetTransparency (aTransparency);
198       }
199       break;
200     }
201
202     // Bounding box.
203     case 2:
204     {
205       if (IsInfinite())
206       {
207         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
208       }
209       else
210       {
211         Prs3d_BndBox::Add (aPrs, BoundingBox(), myDrawer);
212       }
213     }
214   }
215
216   // Recompute hidden line presentation (if necessary).
217   aPrs->ReCompute();
218 }
219
220 //=======================================================================
221 //function : computeHlrPresentation
222 //purpose  :
223 //=======================================================================
224 void AIS_Shape::computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
225                                         const Handle(Prs3d_Presentation)& thePrs,
226                                         const TopoDS_Shape& theShape,
227                                         const Handle(Prs3d_Drawer)& theDrawer)
228 {
229   if (theShape.IsNull())
230   {
231     return;
232   }
233
234   switch (theShape.ShapeType())
235   {
236     case TopAbs_VERTEX:
237     case TopAbs_EDGE:
238     case TopAbs_WIRE:
239     {
240       thePrs->SetDisplayPriority (4);
241       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
242       return;
243     }
244     case TopAbs_COMPOUND:
245     {
246       if (theShape.NbChildren() == 0)
247       {
248         return;
249       }
250       break;
251     }
252     default:
253     {
254       break;
255     }
256   }
257
258   const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
259   if (aDefDrawer->DrawHiddenLine())
260   {
261     theDrawer->EnableDrawHiddenLine();
262   }
263   else
264   {
265     theDrawer->DisableDrawHiddenLine();
266   }
267
268   const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
269   aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
270   if (theDrawer->IsAutoTriangulation())
271   {
272     StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
273   }
274
275   {
276     try
277     {
278       OCC_CATCH_SIGNALS
279       switch (theDrawer->TypeOfHLR())
280       {
281         case Prs3d_TOH_Algo:
282         {
283           StdPrs_HLRShape aBuilder;
284           aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
285           break;
286         }
287         case Prs3d_TOH_PolyAlgo:
288         case Prs3d_TOH_NotSet:
289         {
290           StdPrs_HLRPolyShape aBuilder;
291           aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
292           break;
293         }
294       }
295     }
296     catch (Standard_Failure const& anException)
297     {
298       Message::DefaultMessenger()->Send (TCollection_AsciiString()
299                                        + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
300                                        + anException.GetMessageString() + ")", Message_Fail);
301       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
302     }
303   }
304
305   aDefDrawer->SetTypeOfDeflection (aPrevDef);
306 }
307
308 //=======================================================================
309 //function : ComputeSelection
310 //purpose  : 
311 //=======================================================================
312
313 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
314                                               const Standard_Integer aMode)
315 {
316   if(myshape.IsNull()) return;
317   if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
318   {
319     // empty Shape -> empty Assembly.
320     return;
321   }
322
323   TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
324   TopoDS_Shape shape = myshape;
325
326 // POP protection against crash in low layers
327
328   Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection(shape, myDrawer);
329   try
330   {
331     OCC_CATCH_SIGNALS
332     StdSelect_BRepSelectionTool::Load(aSelection,
333                                       this,
334                                       shape,
335                                       TypOfSel,
336                                       aDeflection,
337                                       myDrawer->DeviationAngle(),
338                                       myDrawer->IsAutoTriangulation());
339   }
340   catch (Standard_Failure const& anException)
341   {
342     Message::DefaultMessenger()->Send (TCollection_AsciiString()
343                                        + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
344                                        + anException.GetMessageString() + ")", Message_Fail);
345     if (aMode == 0)
346     {
347       aSelection->Clear();
348       Bnd_Box B = BoundingBox();
349       Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
350       Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
351       aSelection->Add(aSensitiveBox);
352     }
353   }
354
355   // insert the drawer in the BrepOwners for hilight...
356   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
357 }
358
359 void AIS_Shape::Color( Quantity_Color& aColor ) const {
360   aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
361 }
362
363 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
364   return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
365 }
366
367 Standard_Real AIS_Shape::Transparency() const {
368   return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
369 }
370
371 //=======================================================================
372 //function : setColor
373 //purpose  :
374 //=======================================================================
375
376 bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
377                           const Quantity_Color&       theColor) const
378 {
379   bool toRecompute = false;
380   toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
381   toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
382   toRecompute = theDrawer->SetupOwnPointAspect() || toRecompute;
383
384   // override color
385   theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
386   theDrawer->LineAspect()->SetColor (theColor);
387   theDrawer->WireAspect()->SetColor (theColor);
388   theDrawer->PointAspect()->SetColor (theColor);
389   theDrawer->FreeBoundaryAspect()->SetColor (theColor);
390   theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
391   theDrawer->SeenLineAspect()->SetColor (theColor);
392   theDrawer->FaceBoundaryAspect()->SetColor (theColor);
393   return toRecompute;
394 }
395
396 //=======================================================================
397 //function : SetColor
398 //purpose  :
399 //=======================================================================
400
401 void AIS_Shape::SetColor (const Quantity_Color& theColor)
402 {
403   const bool toRecompute = setColor (myDrawer, theColor);
404   myDrawer->SetColor (theColor);
405   hasOwnColor = Standard_True;
406
407   if (!toRecompute
408    || !myDrawer->HasLink())
409   {
410     SynchronizeAspects();
411   }
412   else
413   {
414     replaceWithNewOwnAspects();
415   }
416   recomputeComputed();
417 }
418
419 //=======================================================================
420 //function : UnsetColor
421 //purpose  :
422 //=======================================================================
423
424 void AIS_Shape::UnsetColor()
425 {
426   if (!HasColor())
427   {
428     return;
429   }
430
431   hasOwnColor = Standard_False;
432   myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
433
434   Graphic3d_MapOfAspectsToAspects aReplaceMap;
435   if (!HasWidth())
436   {
437     replaceAspectWithDef (aReplaceMap, LineAspect);
438     replaceAspectWithDef (aReplaceMap, WireAspect);
439     replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
440     replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
441     replaceAspectWithDef (aReplaceMap, SeenLineAspect);
442     replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
443     myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
444     myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
445     myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
446     myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
447     myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
448     myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
449   }
450   else
451   {
452     Quantity_Color aColor = Quantity_NOC_YELLOW;
453     if (myDrawer->HasLink())
454     {
455       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line,   aColor);
456     }
457     myDrawer->LineAspect()->SetColor (aColor);
458     aColor = Quantity_NOC_RED;
459     if (myDrawer->HasLink())
460     {
461       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire,   aColor);
462     }
463     myDrawer->WireAspect()->SetColor (aColor);
464     aColor = Quantity_NOC_GREEN;
465     if (myDrawer->HasLink())
466     {
467       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free,   aColor);
468     }
469     myDrawer->FreeBoundaryAspect()->SetColor (aColor);
470     aColor = Quantity_NOC_YELLOW;
471     if (myDrawer->HasLink())
472     {
473       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
474     }
475     myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
476     if (myDrawer->HasLink())
477     {
478       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen,   aColor);
479     }
480     myDrawer->SeenLineAspect()->SetColor (aColor);
481     aColor = Quantity_NOC_BLACK;
482     if (myDrawer->HasLink())
483     {
484       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
485     }
486     myDrawer->FaceBoundaryAspect()->SetColor (aColor);
487   }
488
489   if (!myDrawer->HasOwnShadingAspect())
490   {
491     //
492   }
493   else if (HasMaterial()
494         || IsTransparent()
495         || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
496   {
497     const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
498     Graphic3d_MaterialAspect mat = aDefaultMat;
499     Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
500     if (myDrawer->HasLink())
501     {
502       anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
503       anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
504     }
505     if (HasMaterial() || myDrawer->HasLink())
506     {
507       const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
508       mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
509           ? aSrcAspect->FrontMaterial()
510           : aSrcAspect->BackMaterial();
511     }
512     if (HasMaterial())
513     {
514       const Quantity_Color aColor = myDrawer->HasLink()
515                                   ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
516                                   : aDefaultMat.AmbientColor();
517       mat.SetColor (aColor);
518     }
519     if (IsTransparent())
520     {
521       Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
522       mat.SetTransparency (Standard_ShortReal(aTransp));
523     }
524     myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
525     myDrawer->ShadingAspect()->Aspect()->SetInteriorColor    (anInteriorColors[0]);
526     myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
527   }
528   else
529   {
530     replaceAspectWithDef (aReplaceMap, ShadingAspect);
531     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
532   }
533   if (myDrawer->HasOwnPointAspect())
534   {
535     replaceAspectWithDef (aReplaceMap, PointAspect);
536     myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
537   }
538   replaceAspects (aReplaceMap);
539   SynchronizeAspects();
540   recomputeComputed();
541 }
542
543 //=======================================================================
544 //function : setWidth
545 //purpose  :
546 //=======================================================================
547
548 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
549                           const Standard_Real         theLineWidth) const
550 {
551   bool toRecompute = theDrawer->SetOwnLineAspects();
552
553   // override width
554   theDrawer->LineAspect()->SetWidth (theLineWidth);
555   theDrawer->WireAspect()->SetWidth (theLineWidth);
556   theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
557   theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
558   theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
559   theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
560   return toRecompute;
561 }
562
563 //=======================================================================
564 //function : SetWidth
565 //purpose  : 
566 //=======================================================================
567
568 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
569 {
570   myOwnWidth = (Standard_ShortReal )theLineWidth;
571
572   if (!setWidth (myDrawer, theLineWidth)
573    || !myDrawer->HasLink())
574   {
575     SynchronizeAspects();
576   }
577   else
578   {
579     replaceWithNewOwnAspects();
580   }
581   recomputeComputed();
582 }
583
584 //=======================================================================
585 //function : UnsetWidth
586 //purpose  :
587 //=======================================================================
588
589 void AIS_Shape::UnsetWidth()
590 {
591   if (myOwnWidth == 0.0f)
592   {
593     return;
594   }
595
596   myOwnWidth = 0.0f;
597   if (!HasColor())
598   {
599     Graphic3d_MapOfAspectsToAspects aReplaceMap;
600     replaceAspectWithDef (aReplaceMap, LineAspect);
601     replaceAspectWithDef (aReplaceMap, WireAspect);
602     replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
603     replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
604     replaceAspectWithDef (aReplaceMap, SeenLineAspect);
605     replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
606     myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
607     myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
608     myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
609     myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
610     myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
611     myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
612     replaceAspects (aReplaceMap);
613   }
614   else
615   {
616     myDrawer->LineAspect()          ->SetWidth (myDrawer->HasLink() ?
617       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
618     myDrawer->WireAspect()          ->SetWidth (myDrawer->HasLink() ?
619       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
620     myDrawer->FreeBoundaryAspect()  ->SetWidth (myDrawer->HasLink() ?
621       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
622     myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
623       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
624     myDrawer->SeenLineAspect()      ->SetWidth (myDrawer->HasLink() ?
625       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
626     myDrawer->FaceBoundaryAspect()      ->SetWidth (myDrawer->HasLink() ?
627       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
628     SynchronizeAspects();
629   }
630   recomputeComputed();
631 }
632
633 //=======================================================================
634 //function : setMaterial
635 //purpose  :
636 //=======================================================================
637
638 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
639                              const Graphic3d_MaterialAspect& theMaterial,
640                              const Standard_Boolean          theToKeepColor,
641                              const Standard_Boolean          theToKeepTransp) const
642 {
643   const Quantity_Color aColor  = theDrawer->ShadingAspect()->Color (myCurrentFacingModel);
644   const Standard_Real  aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
645   theDrawer->SetupOwnShadingAspect();
646   theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
647
648   if (theToKeepColor)
649   {
650     theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
651   }
652   if (theToKeepTransp)
653   {
654     theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
655   }
656 }
657
658 //=======================================================================
659 //function : SetMaterial
660 //purpose  :
661 //=======================================================================
662
663 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
664 {
665   const bool toRecompute = !myDrawer->HasOwnShadingAspect();
666   setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
667   hasOwnMaterial = Standard_True;
668
669   if (!toRecompute
670    || !myDrawer->HasLink())
671   {
672     SynchronizeAspects();
673   }
674   else
675   {
676     replaceWithNewOwnAspects();
677   }
678 }
679
680 //=======================================================================
681 //function : UnsetMaterial
682 //purpose  :
683 //=======================================================================
684
685 void AIS_Shape::UnsetMaterial()
686 {
687   if (!HasMaterial())
688   {
689     return;
690   }
691
692   if (!myDrawer->HasOwnShadingAspect())
693   {
694     //
695   }
696   else if (HasColor()
697         || IsTransparent()
698         || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
699   {
700     if(myDrawer->HasLink())
701     {
702       myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
703                                               myCurrentFacingModel);
704     }
705     if (HasColor())
706     {
707       myDrawer->ShadingAspect()->SetColor        (myDrawer->Color(),        myCurrentFacingModel);
708       myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
709     }
710     SynchronizeAspects();
711   }
712   else
713   {
714     Graphic3d_MapOfAspectsToAspects aReplaceMap;
715     replaceAspectWithDef (aReplaceMap, ShadingAspect);
716     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
717     replaceAspects (aReplaceMap);
718   }
719 }
720
721 //=======================================================================
722 //function : setTransparency
723 //purpose  :
724 //=======================================================================
725
726 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
727                                  const Standard_Real         theValue) const
728 {
729   theDrawer->SetupOwnShadingAspect();
730   // override transparency
731   theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
732 }
733
734 //=======================================================================
735 //function : SetTransparency
736 //purpose  :
737 //=======================================================================
738
739 void AIS_Shape::SetTransparency (const Standard_Real theValue)
740 {
741   const bool toRecompute = !myDrawer->HasOwnShadingAspect();
742   setTransparency (myDrawer, theValue);
743   myDrawer->SetTransparency ((Standard_ShortReal )theValue);
744
745   if (!toRecompute
746    || !myDrawer->HasLink())
747   {
748     SynchronizeAspects();
749   }
750   else
751   {
752     replaceWithNewOwnAspects();
753   }
754 }
755
756 //=======================================================================
757 //function : UnsetTransparency
758 //purpose  :
759 //=======================================================================
760
761 void AIS_Shape::UnsetTransparency()
762 {
763   myDrawer->SetTransparency (0.0f);
764   if (!myDrawer->HasOwnShadingAspect())
765   {
766     return;
767   }
768   else if (HasColor()
769         || HasMaterial()
770         || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
771   {
772     myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
773     SynchronizeAspects();
774   }
775   else
776   {
777     Graphic3d_MapOfAspectsToAspects aReplaceMap;
778     replaceAspectWithDef (aReplaceMap, ShadingAspect);
779     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
780     replaceAspects (aReplaceMap);
781   }
782 }
783
784 //=======================================================================
785 //function : BoundingBox
786 //purpose  : 
787 //=======================================================================
788
789 const Bnd_Box& AIS_Shape::BoundingBox()  
790 {
791   if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
792   {
793     // empty Shape  -> empty Assembly.
794     myBB.SetVoid ();
795     return myBB;
796   }
797
798   if(myCompBB) {
799     BRepBndLib::Add (myshape, myBB, false);
800     myCompBB = Standard_False;
801   }
802   return myBB;
803 }
804
805 //*****
806 //***** Reset
807 //=======================================================================
808 //function : SetOwnDeviationCoefficient
809 //purpose  : resets myhasOwnDeviationCoefficient to Standard_False and
810 //           returns Standard_True if it change
811 //=======================================================================
812
813 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
814 {
815   Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
816   if(itSet)  myDrawer->SetDeviationCoefficient();
817   return itSet;
818 }
819
820 //=======================================================================
821 //function : SetOwnDeviationAngle
822 //purpose  : resets myhasOwnDeviationAngle to Standard_False and
823 //           returns Standard_True if it change
824 //=======================================================================
825
826 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
827 {
828   Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
829   if(itSet)  myDrawer->SetDeviationAngle();
830   return itSet;
831
832 }
833
834 //=======================================================================
835 //function : SetOwnDeviationCoefficient
836 //purpose  : 
837 //=======================================================================
838
839 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real  aCoefficient )
840 {
841   myDrawer->SetDeviationCoefficient( aCoefficient );
842   SetToUpdate();
843 }
844
845 //=======================================================================
846 //function : SetOwnDeviationAngle
847 //purpose  : 
848 //=======================================================================
849
850 void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
851 {
852   myDrawer->SetDeviationAngle (theAngle);
853   SetToUpdate (AIS_WireFrame);
854 }
855 //=======================================================================
856 //function : SetOwnDeviationAngle
857 //purpose  : 
858 //=======================================================================
859
860 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real  anAngle )
861 {
862   Standard_Real OutAngl,OutDefl;
863   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
864   SetOwnDeviationAngle(anAngle) ;
865   SetOwnDeviationCoefficient(OutDefl) ;
866   myInitAng = anAngle;
867   SetToUpdate();
868 }
869
870 //=======================================================================
871 //function : UserAngle
872 //purpose  : 
873 //=======================================================================
874
875 Standard_Real AIS_Shape::UserAngle() const
876 {
877   return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
878 }
879
880 //=======================================================================
881 //function : OwnDeviationCoefficient
882 //purpose  : 
883 //=======================================================================
884
885 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real &  aCoefficient,
886                                                       Standard_Real & aPreviousCoefficient ) const
887 {
888   aCoefficient = myDrawer->DeviationCoefficient();
889   aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
890   return myDrawer->HasOwnDeviationCoefficient() ;
891 }
892
893 //=======================================================================
894 //function : OwnDeviationAngle
895 //purpose  : 
896 //=======================================================================
897
898 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real &  anAngle,
899                                                 Standard_Real & aPreviousAngle ) const
900 {
901   anAngle = myDrawer->DeviationAngle();
902   aPreviousAngle = myDrawer->PreviousDeviationAngle (); 
903   return myDrawer->HasOwnDeviationAngle();
904 }
905
906 //=======================================================================
907 //function : DumpJson
908 //purpose  : 
909 //=======================================================================
910 void AIS_Shape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
911 {
912   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
913   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
914
915   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myshape)
916   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBB)
917
918   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInitAng)
919   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCompBB)
920 }