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