0026978: VIS - Interactive selection is insensitive to swept shell
[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 <Geom_Transformation.hxx>
27 #include <gp_Pnt.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <Graphic3d_AspectLine3d.hxx>
31 #include <Graphic3d_AspectMarker3d.hxx>
32 #include <Graphic3d_AspectText3d.hxx>
33 #include <Graphic3d_Group.hxx>
34 #include <Graphic3d_MaterialAspect.hxx>
35 #include <Graphic3d_SequenceOfGroup.hxx>
36 #include <Graphic3d_Structure.hxx>
37 #include <Message.hxx>
38 #include <Message_Messenger.hxx>
39 #include <HLRBRep.hxx>
40 #include <OSD_Timer.hxx>
41 #include <Precision.hxx>
42 #include <Prs3d.hxx>
43 #include <Prs3d_Drawer.hxx>
44 #include <Prs3d_IsoAspect.hxx>
45 #include <Prs3d_Presentation.hxx>
46 #include <Prs3d_Projector.hxx>
47 #include <Prs3d_Root.hxx>
48 #include <Prs3d_ShadingAspect.hxx>
49 #include <StdPrs_BndBox.hxx>
50 #include <StdPrs_ToolTriangulatedShape.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
68 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
69
70 // Auxiliary macros
71 #define replaceAspectWithDef(theMap, theAspect) \
72   if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
73   { \
74     theMap.Bind (myDrawer->theAspect()->Aspect(), myDrawer->Link()->theAspect()->Aspect()); \
75   }
76
77 // Auxiliary macros for replaceWithNewOwnAspects()
78 #define replaceAspectWithOwn(theMap, theAspect) \
79   if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
80   { \
81     theMap.Bind (myDrawer->Link()->theAspect()->Aspect(), myDrawer->theAspect()->Aspect()); \
82   }
83
84 //=======================================================================
85 //function : replaceWithNewOwnAspects
86 //purpose  :
87 //=======================================================================
88 void AIS_Shape::replaceWithNewOwnAspects()
89 {
90   Graphic3d_MapOfAspectsToAspects aReplaceMap;
91
92   replaceAspectWithOwn (aReplaceMap, ShadingAspect);
93   replaceAspectWithOwn (aReplaceMap, LineAspect);
94   replaceAspectWithOwn (aReplaceMap, WireAspect);
95   replaceAspectWithOwn (aReplaceMap, FreeBoundaryAspect);
96   replaceAspectWithOwn (aReplaceMap, UnFreeBoundaryAspect);
97   replaceAspectWithOwn (aReplaceMap, SeenLineAspect);
98   replaceAspectWithOwn (aReplaceMap, FaceBoundaryAspect);
99   replaceAspectWithOwn (aReplaceMap, PointAspect);
100
101   replaceAspects (aReplaceMap);
102 }
103
104 //==================================================
105 // Function: AIS_Shape
106 // Purpose :
107 //==================================================
108 AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
109 : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
110   myshape (theShape),
111   myUVOrigin(0.0, 0.0),
112   myUVRepeat(1.0, 1.0),
113   myUVScale (1.0, 1.0),
114   myInitAng (0.0),
115   myCompBB (Standard_True)
116 {
117   //
118 }
119
120 //=======================================================================
121 //function : Compute
122 //purpose  : 
123 //=======================================================================
124 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
125                         const Handle(Prs3d_Presentation)& aPrs,
126                         const Standard_Integer theMode)
127 {  
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 && myshape.NbChildren() == 0)
138   {
139     return;
140   }
141
142   if (IsInfinite())
143   {
144     aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
145   }
146
147   switch (theMode)
148   {
149     case AIS_WireFrame:
150     {
151       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
152       try
153       {
154         OCC_CATCH_SIGNALS
155         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
156       }
157       catch (Standard_Failure const& anException)
158       {
159         Message::DefaultMessenger()->Send (TCollection_AsciiString()
160                                          + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
161                                          + anException.GetMessageString() + ")", Message_Fail);
162       }
163       break;
164     }
165     case AIS_Shaded:
166     {
167       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
168       if ((Standard_Integer) myshape.ShapeType() > 4)
169       {
170         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
171       }
172       else
173       {
174         if (IsInfinite())
175         {
176           StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
177         }
178         else
179         {
180           try
181           {
182             OCC_CATCH_SIGNALS
183             StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
184                                      myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
185                                  && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
186                                      myUVOrigin, myUVRepeat, myUVScale);
187           }
188           catch (Standard_Failure const& anException)
189           {
190             Message::DefaultMessenger()->Send (TCollection_AsciiString()
191                                                + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
192                                                + anException.GetMessageString() + ")", Message_Fail);
193             StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
194           }
195         }
196       }
197       Standard_Real aTransparency = Transparency() ;
198       if (aTransparency > 0.0)
199       {
200         SetTransparency (aTransparency);
201       }
202       break;
203     }
204
205     // Bounding box.
206     case 2:
207     {
208       if (IsInfinite())
209       {
210         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
211       }
212       else
213       {
214         StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
215       }
216     }
217   }
218
219   // Recompute hidden line presentation (if necessary).
220   aPrs->ReCompute();
221 }
222
223 //=======================================================================
224 //function : computeHlrPresentation
225 //purpose  :
226 //=======================================================================
227 void AIS_Shape::computeHlrPresentation (const Handle(Prs3d_Projector)& theProjector,
228                                         const Handle(Prs3d_Presentation)& thePrs,
229                                         const TopoDS_Shape& theShape,
230                                         const Handle(Prs3d_Drawer)& theDrawer)
231 {
232   if (theShape.IsNull())
233   {
234     return;
235   }
236
237   switch (theShape.ShapeType())
238   {
239     case TopAbs_VERTEX:
240     case TopAbs_EDGE:
241     case TopAbs_WIRE:
242     {
243       thePrs->SetDisplayPriority (4);
244       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
245       return;
246     }
247     case TopAbs_COMPOUND:
248     {
249       if (theShape.NbChildren() == 0)
250       {
251         return;
252       }
253       break;
254     }
255     default:
256     {
257       break;
258     }
259   }
260
261   const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
262   if (aDefDrawer->DrawHiddenLine())
263   {
264     theDrawer->EnableDrawHiddenLine();
265   }
266   else
267   {
268     theDrawer->DisableDrawHiddenLine();
269   }
270
271   const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
272   aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
273   if (theDrawer->IsAutoTriangulation())
274   {
275     StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
276   }
277
278   {
279     try
280     {
281       OCC_CATCH_SIGNALS
282       switch (theDrawer->TypeOfHLR())
283       {
284         case Prs3d_TOH_Algo:
285           StdPrs_HLRShape::Add (thePrs, theShape, theDrawer, theProjector);
286           break;
287         case Prs3d_TOH_PolyAlgo:
288         default:
289           StdPrs_HLRPolyShape::Add (thePrs, theShape, theDrawer, theProjector);
290           break;
291       }
292     }
293     catch (Standard_Failure const& anException)
294     {
295       Message::DefaultMessenger()->Send (TCollection_AsciiString()
296                                        + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
297                                        + anException.GetMessageString() + ")", Message_Fail);
298       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
299     }
300   }
301
302   aDefDrawer->SetTypeOfDeflection (aPrevDef);
303 }
304
305 //=======================================================================
306 //function : ComputeSelection
307 //purpose  : 
308 //=======================================================================
309
310 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
311                                               const Standard_Integer aMode)
312 {
313   if(myshape.IsNull()) return;
314   if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
315   {
316     // empty Shape -> empty Assembly.
317     return;
318   }
319
320   TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
321   TopoDS_Shape shape = myshape;
322
323 // POP protection against crash in low layers
324
325   Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
326   try
327   {
328     OCC_CATCH_SIGNALS
329     StdSelect_BRepSelectionTool::Load(aSelection,
330                                       this,
331                                       shape,
332                                       TypOfSel,
333                                       aDeflection,
334                                       myDrawer->HLRAngle(),
335                                       myDrawer->IsAutoTriangulation());
336   }
337   catch (Standard_Failure const& anException)
338   {
339     Message::DefaultMessenger()->Send (TCollection_AsciiString()
340                                        + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
341                                        + anException.GetMessageString() + ")", Message_Fail);
342     if (aMode == 0)
343     {
344       aSelection->Clear();
345       Bnd_Box B = BoundingBox();
346       Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
347       Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
348       aSelection->Add(aSensitiveBox);
349     }
350   }
351
352   // insert the drawer in the BrepOwners for hilight...
353   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
354 }
355
356 void AIS_Shape::Color( Quantity_Color& aColor ) const {
357   aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
358 }
359
360 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
361   return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
362 }
363
364 Standard_Real AIS_Shape::Transparency() const {
365   return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
366 }
367
368 //=======================================================================
369 //function : setColor
370 //purpose  :
371 //=======================================================================
372
373 bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
374                           const Quantity_Color&       theColor) const
375 {
376   bool toRecompute = false;
377   toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
378   toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
379   toRecompute = theDrawer->SetupOwnPointAspect() || toRecompute;
380
381   // override color
382   theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
383   theDrawer->LineAspect()->SetColor (theColor);
384   theDrawer->WireAspect()->SetColor (theColor);
385   theDrawer->PointAspect()->SetColor (theColor);
386   theDrawer->FreeBoundaryAspect()->SetColor (theColor);
387   theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
388   theDrawer->SeenLineAspect()->SetColor (theColor);
389   theDrawer->FaceBoundaryAspect()->SetColor (theColor);
390   return toRecompute;
391 }
392
393 //=======================================================================
394 //function : SetColor
395 //purpose  :
396 //=======================================================================
397
398 void AIS_Shape::SetColor (const Quantity_Color& theColor)
399 {
400   const bool toRecompute = setColor (myDrawer, theColor);
401   myDrawer->SetColor (theColor);
402   hasOwnColor = Standard_True;
403
404   if (!toRecompute
405    || !myDrawer->HasLink())
406   {
407     SynchronizeAspects();
408   }
409   else
410   {
411     replaceWithNewOwnAspects();
412   }
413   recomputeComputed();
414 }
415
416 //=======================================================================
417 //function : UnsetColor
418 //purpose  :
419 //=======================================================================
420
421 void AIS_Shape::UnsetColor()
422 {
423   if (!HasColor())
424   {
425     return;
426   }
427
428   hasOwnColor = Standard_False;
429   myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
430
431   Graphic3d_MapOfAspectsToAspects aReplaceMap;
432   if (!HasWidth())
433   {
434     replaceAspectWithDef (aReplaceMap, LineAspect);
435     replaceAspectWithDef (aReplaceMap, WireAspect);
436     replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
437     replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
438     replaceAspectWithDef (aReplaceMap, SeenLineAspect);
439     replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
440     myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
441     myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
442     myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
443     myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
444     myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
445     myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
446   }
447   else
448   {
449     Quantity_Color aColor = Quantity_NOC_YELLOW;
450     if (myDrawer->HasLink())
451     {
452       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line,   aColor);
453     }
454     myDrawer->LineAspect()->SetColor (aColor);
455     aColor = Quantity_NOC_RED;
456     if (myDrawer->HasLink())
457     {
458       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire,   aColor);
459     }
460     myDrawer->WireAspect()->SetColor (aColor);
461     aColor = Quantity_NOC_GREEN;
462     if (myDrawer->HasLink())
463     {
464       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free,   aColor);
465     }
466     myDrawer->FreeBoundaryAspect()->SetColor (aColor);
467     aColor = Quantity_NOC_YELLOW;
468     if (myDrawer->HasLink())
469     {
470       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
471     }
472     myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
473     if (myDrawer->HasLink())
474     {
475       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen,   aColor);
476     }
477     myDrawer->SeenLineAspect()->SetColor (aColor);
478     aColor = Quantity_NOC_BLACK;
479     if (myDrawer->HasLink())
480     {
481       AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
482     }
483     myDrawer->FaceBoundaryAspect()->SetColor (aColor);
484   }
485
486   if (!myDrawer->HasOwnShadingAspect())
487   {
488     //
489   }
490   else if (HasMaterial()
491         || IsTransparent()
492         || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
493   {
494     const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
495     Graphic3d_MaterialAspect mat = aDefaultMat;
496     Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
497     if (myDrawer->HasLink())
498     {
499       anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
500       anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
501     }
502     if (HasMaterial() || myDrawer->HasLink())
503     {
504       const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
505       mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
506           ? aSrcAspect->FrontMaterial()
507           : aSrcAspect->BackMaterial();
508     }
509     if (HasMaterial())
510     {
511       const Quantity_Color aColor = myDrawer->HasLink()
512                                   ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
513                                   : aDefaultMat.AmbientColor();
514       mat.SetColor (aColor);
515     }
516     if (IsTransparent())
517     {
518       Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
519       mat.SetTransparency (Standard_ShortReal(aTransp));
520     }
521     myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
522     myDrawer->ShadingAspect()->Aspect()->SetInteriorColor    (anInteriorColors[0]);
523     myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
524   }
525   else
526   {
527     replaceAspectWithDef (aReplaceMap, ShadingAspect);
528     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
529   }
530   if (myDrawer->HasOwnPointAspect())
531   {
532     replaceAspectWithDef (aReplaceMap, PointAspect);
533     myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
534   }
535   replaceAspects (aReplaceMap);
536   SynchronizeAspects();
537   recomputeComputed();
538 }
539
540 //=======================================================================
541 //function : setWidth
542 //purpose  :
543 //=======================================================================
544
545 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
546                           const Standard_Real         theLineWidth) const
547 {
548   bool toRecompute = theDrawer->SetOwnLineAspects();
549
550   // override width
551   theDrawer->LineAspect()->SetWidth (theLineWidth);
552   theDrawer->WireAspect()->SetWidth (theLineWidth);
553   theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
554   theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
555   theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
556   theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
557   return toRecompute;
558 }
559
560 //=======================================================================
561 //function : SetWidth
562 //purpose  : 
563 //=======================================================================
564
565 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
566 {
567   myOwnWidth = (Standard_ShortReal )theLineWidth;
568
569   if (!setWidth (myDrawer, theLineWidth)
570    || !myDrawer->HasLink())
571   {
572     SynchronizeAspects();
573   }
574   else
575   {
576     replaceWithNewOwnAspects();
577   }
578   recomputeComputed();
579 }
580
581 //=======================================================================
582 //function : UnsetWidth
583 //purpose  :
584 //=======================================================================
585
586 void AIS_Shape::UnsetWidth()
587 {
588   if (myOwnWidth == 0.0f)
589   {
590     return;
591   }
592
593   myOwnWidth = 0.0f;
594   if (!HasColor())
595   {
596     Graphic3d_MapOfAspectsToAspects aReplaceMap;
597     replaceAspectWithDef (aReplaceMap, LineAspect);
598     replaceAspectWithDef (aReplaceMap, WireAspect);
599     replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
600     replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
601     replaceAspectWithDef (aReplaceMap, SeenLineAspect);
602     replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
603     myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
604     myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
605     myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
606     myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
607     myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
608     myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
609     replaceAspects (aReplaceMap);
610   }
611   else
612   {
613     myDrawer->LineAspect()          ->SetWidth (myDrawer->HasLink() ?
614       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
615     myDrawer->WireAspect()          ->SetWidth (myDrawer->HasLink() ?
616       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
617     myDrawer->FreeBoundaryAspect()  ->SetWidth (myDrawer->HasLink() ?
618       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
619     myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
620       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
621     myDrawer->SeenLineAspect()      ->SetWidth (myDrawer->HasLink() ?
622       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
623     myDrawer->FaceBoundaryAspect()      ->SetWidth (myDrawer->HasLink() ?
624       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
625     SynchronizeAspects();
626   }
627   recomputeComputed();
628 }
629
630 //=======================================================================
631 //function : setMaterial
632 //purpose  :
633 //=======================================================================
634
635 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
636                              const Graphic3d_MaterialAspect& theMaterial,
637                              const Standard_Boolean          theToKeepColor,
638                              const Standard_Boolean          theToKeepTransp) const
639 {
640   const Quantity_Color aColor  = theDrawer->ShadingAspect()->Material     (myCurrentFacingModel).Color();
641   const Standard_Real  aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
642   theDrawer->SetupOwnShadingAspect();
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 : SetHLROwnDeviationCoefficient
819 //purpose  : resets myhasOwnHLRDeviationCoefficient to Standard_False and
820 //           returns Standard_True if it change
821 //=======================================================================
822
823 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
824 {
825   Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
826   if(itSet)  myDrawer->SetHLRDeviationCoefficient();
827   return itSet;
828
829 }
830
831 //=======================================================================
832 //function : SetOwnDeviationAngle
833 //purpose  : resets myhasOwnDeviationAngle to Standard_False and
834 //           returns Standard_True if it change
835 //=======================================================================
836
837 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
838 {
839   Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
840   if(itSet)  myDrawer->SetDeviationAngle();
841   return itSet;
842
843 }
844
845 //=======================================================================
846 //function : SetOwnHLRDeviationAngle
847 //purpose  : resets myhasOwnHLRDeviationAngle to Standard_False and
848 //           returns Standard_True if it change
849 //=======================================================================
850
851 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
852 {
853   Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
854   if(itSet)  myDrawer->SetHLRAngle();
855   return itSet;
856
857 }
858 //***** SetOwn
859 //=======================================================================
860 //function : SetOwnDeviationCoefficient
861 //purpose  : 
862 //=======================================================================
863
864 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real  aCoefficient )
865 {
866   myDrawer->SetDeviationCoefficient( aCoefficient );
867   SetToUpdate();
868 }
869
870 //=======================================================================
871 //function : SetOwnHLRDeviationCoefficient
872 //purpose  : 
873 //=======================================================================
874
875 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real  aCoefficient )
876 {
877   myDrawer->SetHLRDeviationCoefficient( aCoefficient );
878   
879 }
880
881 //=======================================================================
882 //function : SetOwnDeviationAngle
883 //purpose  : 
884 //=======================================================================
885
886 void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
887 {
888   myDrawer->SetDeviationAngle (theAngle);
889   SetToUpdate (AIS_WireFrame);
890 }
891 //=======================================================================
892 //function : SetOwnDeviationAngle
893 //purpose  : 
894 //=======================================================================
895
896 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real  anAngle )
897 {
898   Standard_Real OutAngl,OutDefl;
899   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
900   SetOwnDeviationAngle(anAngle) ;
901   SetOwnDeviationCoefficient(OutDefl) ;
902   myInitAng = anAngle;
903   SetToUpdate();
904 }
905
906 //=======================================================================
907 //function : UserAngle
908 //purpose  : 
909 //=======================================================================
910
911 Standard_Real AIS_Shape::UserAngle() const
912 {
913   return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
914 }
915
916
917 //=======================================================================
918 //function : SetHLRAngleAndDeviation
919 //purpose  : 
920 //=======================================================================
921
922 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real  anAngle )
923 {
924   Standard_Real OutAngl,OutDefl;
925   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
926   SetOwnHLRDeviationAngle( OutAngl );
927   SetOwnHLRDeviationCoefficient(OutDefl);
928
929 }
930 //=======================================================================
931 //function : SetOwnHLRDeviationAngle
932 //purpose  : 
933 //=======================================================================
934
935 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real  anAngle )
936 {
937   myDrawer->SetHLRAngle( anAngle );
938 }
939
940 //***** GetOwn
941 //=======================================================================
942 //function : OwnDeviationCoefficient
943 //purpose  : 
944 //=======================================================================
945
946 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real &  aCoefficient,
947                                                       Standard_Real & aPreviousCoefficient ) const
948 {
949   aCoefficient = myDrawer->DeviationCoefficient();
950   aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
951   return myDrawer->HasOwnDeviationCoefficient() ;
952 }
953
954 //=======================================================================
955 //function : OwnHLRDeviationCoefficient
956 //purpose  : 
957 //=======================================================================
958
959 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
960                                                          Standard_Real & aPreviousCoefficient ) const
961 {
962   aCoefficient = myDrawer->HLRDeviationCoefficient();
963   aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
964   return myDrawer->HasOwnHLRDeviationCoefficient();
965
966 }
967
968 //=======================================================================
969 //function : OwnDeviationAngle
970 //purpose  : 
971 //=======================================================================
972
973 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real &  anAngle,
974                                                 Standard_Real & aPreviousAngle ) const
975 {
976   anAngle = myDrawer->DeviationAngle();
977   aPreviousAngle = myDrawer->PreviousDeviationAngle (); 
978   return myDrawer->HasOwnDeviationAngle();
979 }
980
981 //=======================================================================
982 //function : OwnHLRDeviationAngle
983 //purpose  : 
984 //=======================================================================
985
986 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real &  anAngle,
987                                                    Standard_Real & aPreviousAngle ) const
988 {
989   anAngle = myDrawer->HLRAngle();
990   aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); 
991   return myDrawer->HasOwnHLRDeviationAngle();
992 }