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