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