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