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