0030470: Modeling Algorithms - Invalid result of offset operation in mode "Complete...
[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>
26#include <Geom_Transformation.hxx>
27#include <gp_Pnt.hxx>
28#include <Graphic3d_ArrayOfPolylines.hxx>
29#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 30#include <Graphic3d_AspectLine3d.hxx>
7fd59977 31#include <Graphic3d_AspectMarker3d.hxx>
42cf5bc1 32#include <Graphic3d_AspectText3d.hxx>
33#include <Graphic3d_Group.hxx>
7fd59977 34#include <Graphic3d_MaterialAspect.hxx>
48cc825e 35#include <Graphic3d_SequenceOfGroup.hxx>
42cf5bc1 36#include <Graphic3d_Structure.hxx>
c7ba4578 37#include <Message.hxx>
38#include <Message_Messenger.hxx>
42cf5bc1 39#include <HLRBRep.hxx>
40#include <OSD_Timer.hxx>
41#include <Precision.hxx>
9dba391d 42#include <Prs3d.hxx>
42cf5bc1 43#include <Prs3d_Drawer.hxx>
44#include <Prs3d_IsoAspect.hxx>
7fd59977 45#include <Prs3d_Presentation.hxx>
42cf5bc1 46#include <Prs3d_Projector.hxx>
7fd59977 47#include <Prs3d_Root.hxx>
48#include <Prs3d_ShadingAspect.hxx>
5ad8c033 49#include <StdPrs_BndBox.hxx>
50#include <StdPrs_ToolTriangulatedShape.hxx>
7fd59977 51#include <PrsMgr_ModedPresentation.hxx>
42cf5bc1 52#include <Quantity_Color.hxx>
53#include <Select3D_SensitiveBox.hxx>
7fd59977 54#include <Select3D_SensitiveEntity.hxx>
42cf5bc1 55#include <Standard_ErrorHandler.hxx>
56#include <Standard_Failure.hxx>
57#include <Standard_Type.hxx>
58#include <StdPrs_HLRPolyShape.hxx>
59#include <StdPrs_HLRShape.hxx>
60#include <StdPrs_ShadedShape.hxx>
42cf5bc1 61#include <StdPrs_WFShape.hxx>
7fd59977 62#include <StdSelect.hxx>
7fd59977 63#include <StdSelect_BRepOwner.hxx>
42cf5bc1 64#include <StdSelect_BRepSelectionTool.hxx>
7fd59977 65#include <StdSelect_DisplayMode.hxx>
42cf5bc1 66#include <TColStd_ListIteratorOfListOfInteger.hxx>
67#include <TopExp.hxx>
7fd59977 68
92efcf78 69IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
70
7fd59977 71static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
72{
73 TColStd_ListIteratorOfListOfInteger It(LL);
74 for(;It.More();It.Next()){
75 if(It.Value()==aMode)
76 return Standard_True;}
77 return Standard_False;
78}
79
80//==================================================
a6dee93d 81// Function: AIS_Shape
7fd59977 82// Purpose :
83//==================================================
a6dee93d 84AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
85: AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
86 myshape (theShape),
87 myUVOrigin(0.0, 0.0),
88 myUVRepeat(1.0, 1.0),
89 myUVScale (1.0, 1.0),
90 myInitAng (0.0),
91 myCompBB (Standard_True)
7fd59977 92{
a6dee93d 93 //
7fd59977 94}
95
96//=======================================================================
7fd59977 97//function : Compute
98//purpose :
99//=======================================================================
100void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3c34883c 101 const Handle(Prs3d_Presentation)& aPrs,
83b0f13a 102 const Standard_Integer theMode)
7fd59977 103{
7fd59977 104 if(myshape.IsNull()) return;
105
106 // wire,edge,vertex -> pas de HLR + priorite display superieure
107 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
108 if(TheType>4 && TheType<8) {
109 aPrs->SetVisual(Graphic3d_TOS_ALL);
110 aPrs->SetDisplayPriority(TheType+2);
111 }
112 // Shape vide -> Assemblage vide.
b2d1851c 113 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
114 {
115 return;
7fd59977 116 }
a10fa819 117
5ad8c033 118 if (IsInfinite())
119 {
83b0f13a 120 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
7fd59977 121 }
5ad8c033 122
83b0f13a 123 switch (theMode)
5ad8c033 124 {
125 case AIS_WireFrame:
126 {
83b0f13a 127 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
5ad8c033 128 try
129 {
130 OCC_CATCH_SIGNALS
131 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
132 }
c7ba4578 133 catch (Standard_Failure const& anException)
5ad8c033 134 {
c7ba4578 135 Message::DefaultMessenger()->Send (TCollection_AsciiString()
136 + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
137 + anException.GetMessageString() + ")", Message_Fail);
5ad8c033 138 }
139 break;
140 }
141 case AIS_Shaded:
7fd59977 142 {
83b0f13a 143 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
5ad8c033 144 if ((Standard_Integer) myshape.ShapeType() > 4)
145 {
146 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
147 }
148 else
149 {
5ad8c033 150 if (IsInfinite())
151 {
152 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
153 }
154 else
155 {
156 try
157 {
158 OCC_CATCH_SIGNALS
a6dee93d 159 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
160 myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
161 && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
162 myUVOrigin, myUVRepeat, myUVScale);
5ad8c033 163 }
c7ba4578 164 catch (Standard_Failure const& anException)
3c34883c 165 {
c7ba4578 166 Message::DefaultMessenger()->Send (TCollection_AsciiString()
167 + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
168 + anException.GetMessageString() + ")", Message_Fail);
5ad8c033 169 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
3c34883c
O
170 }
171 }
7fd59977 172 }
5ad8c033 173 Standard_Real aTransparency = Transparency() ;
174 if (aTransparency > 0.0)
175 {
176 SetTransparency (aTransparency);
7fd59977 177 }
7fd59977 178 break;
179 }
5ad8c033 180
181 // Bounding box.
182 case 2:
7fd59977 183 {
5ad8c033 184 if (IsInfinite())
185 {
186 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
187 }
188 else
189 {
190 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
191 }
7fd59977 192 }
5ad8c033 193 }
194
195 // Recompute hidden line presentation (if necessary).
196 aPrs->ReCompute();
7fd59977 197}
198
199//=======================================================================
c7ba4578 200//function : computeHlrPresentation
201//purpose :
7fd59977 202//=======================================================================
c7ba4578 203void AIS_Shape::computeHlrPresentation (const Handle(Prs3d_Projector)& theProjector,
204 const Handle(Prs3d_Presentation)& thePrs,
205 const TopoDS_Shape& theShape,
206 const Handle(Prs3d_Drawer)& theDrawer)
7fd59977 207{
c7ba4578 208 if (theShape.IsNull())
209 {
210 return;
211 }
a10fa819 212
c7ba4578 213 switch (theShape.ShapeType())
214 {
215 case TopAbs_VERTEX:
216 case TopAbs_EDGE:
217 case TopAbs_WIRE:
218 {
219 thePrs->SetDisplayPriority (4);
220 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
7fd59977 221 return;
c7ba4578 222 }
223 case TopAbs_COMPOUND:
224 {
b2d1851c 225 if (theShape.NbChildren() == 0)
c7ba4578 226 {
227 return;
228 }
229 break;
230 }
231 default:
232 {
233 break;
234 }
7fd59977 235 }
a10fa819 236
c7ba4578 237 const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
238 if (aDefDrawer->DrawHiddenLine())
239 {
240 theDrawer->EnableDrawHiddenLine();
241 }
242 else
243 {
244 theDrawer->DisableDrawHiddenLine();
245 }
7fd59977 246
c7ba4578 247 const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
248 aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
249 if (theDrawer->IsAutoTriangulation())
4c513386 250 {
c7ba4578 251 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
4c513386 252 }
c7ba4578 253
7fd59977 254 {
c7ba4578 255 try
256 {
7fd59977 257 OCC_CATCH_SIGNALS
c7ba4578 258 switch (theDrawer->TypeOfHLR())
259 {
0a768f56 260 case Prs3d_TOH_Algo:
c7ba4578 261 StdPrs_HLRShape::Add (thePrs, theShape, theDrawer, theProjector);
0a768f56 262 break;
263 case Prs3d_TOH_PolyAlgo:
264 default:
c7ba4578 265 StdPrs_HLRPolyShape::Add (thePrs, theShape, theDrawer, theProjector);
0a768f56 266 break;
267 }
7fd59977 268 }
c7ba4578 269 catch (Standard_Failure const& anException)
270 {
271 Message::DefaultMessenger()->Send (TCollection_AsciiString()
272 + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
273 + anException.GetMessageString() + ")", Message_Fail);
274 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
7fd59977 275 }
276 }
277
c7ba4578 278 aDefDrawer->SetTypeOfDeflection (aPrevDef);
7fd59977 279}
280
281//=======================================================================
7fd59977 282//function : ComputeSelection
283//purpose :
284//=======================================================================
285
286void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
3c34883c 287 const Standard_Integer aMode)
7fd59977 288{
289 if(myshape.IsNull()) return;
b2d1851c 290 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
291 {
292 // empty Shape -> empty Assembly.
293 return;
7fd59977 294 }
295
016e5959 296 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
7fd59977 297 TopoDS_Shape shape = myshape;
7fd59977 298
81bba717 299// POP protection against crash in low layers
7fd59977 300
9dba391d 301 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
c7ba4578 302 try
303 {
7fd59977 304 OCC_CATCH_SIGNALS
305 StdSelect_BRepSelectionTool::Load(aSelection,
306 this,
307 shape,
308 TypOfSel,
309 aDeflection,
3c34883c 310 myDrawer->HLRAngle(),
4c513386 311 myDrawer->IsAutoTriangulation());
c7ba4578 312 }
313 catch (Standard_Failure const& anException)
314 {
315 Message::DefaultMessenger()->Send (TCollection_AsciiString()
316 + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
317 + anException.GetMessageString() + ")", Message_Fail);
318 if (aMode == 0)
319 {
53a70197 320 aSelection->Clear();
7fd59977 321 Bnd_Box B = BoundingBox();
322 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
323 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
324 aSelection->Add(aSensitiveBox);
325 }
326 }
327
328 // insert the drawer in the BrepOwners for hilight...
329 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
330}
331
7fd59977 332void AIS_Shape::Color( Quantity_Color& aColor ) const {
333 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
334}
335
336Graphic3d_NameOfMaterial AIS_Shape::Material() const {
337 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
338}
339
340Standard_Real AIS_Shape::Transparency() const {
341 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
342}
7fd59977 343
344//=======================================================================
ad3217cd 345//function : setColor
346//purpose :
5cbef0fe
S
347//=======================================================================
348
7604a153 349bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
6262338c 350 const Quantity_Color& theColor) const
7fd59977 351{
7604a153 352 bool toRecompute = false;
2a332745 353 toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
354 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
355
356 if (theDrawer->SetupOwnPointAspect())
7604a153 357 {
358 toRecompute = true;
7604a153 359 }
ad3217cd 360
361 // override color
362 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
ad3217cd 363 theDrawer->LineAspect()->SetColor (theColor);
364 theDrawer->WireAspect()->SetColor (theColor);
365 theDrawer->PointAspect()->SetColor (theColor);
8a5dfb38 366 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
367 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
368 theDrawer->SeenLineAspect()->SetColor (theColor);
7604a153 369 theDrawer->FaceBoundaryAspect()->SetColor (theColor);
370 return toRecompute;
ad3217cd 371}
a10fa819 372
ad3217cd 373//=======================================================================
374//function : SetColor
375//purpose :
376//=======================================================================
7fd59977 377
ad3217cd 378void AIS_Shape::SetColor (const Quantity_Color& theColor)
379{
7604a153 380 const bool toRecompute = setColor (myDrawer, theColor);
f838dac4 381 myDrawer->SetColor (theColor);
ad3217cd 382 hasOwnColor = Standard_True;
7604a153 383 if (!toRecompute)
384 {
385 myToRecomputeModes.Clear();
386 myRecomputeEveryPrs = false;
387 SynchronizeAspects();
388 return;
389 }
7fd59977 390
48cc825e 391 // modify shading presentation without re-computation
392 const PrsMgr_Presentations& aPrsList = Presentations();
393 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
394 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
395 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
396 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 397 {
48cc825e 398 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
399 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 400 {
48cc825e 401 continue;
402 }
403
404 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
48cc825e 405 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
406 {
407 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
408
a10fa819
A
409 // Check if aspect of given type is set for the group,
410 // because setting aspect for group with no already set aspect
411 // can lead to loss of presentation data
48cc825e 412 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
ad3217cd 413 {
48cc825e 414 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
ad3217cd 415 }
48cc825e 416 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
ad3217cd 417 {
48cc825e 418 aGroup->SetGroupPrimitivesAspect (aLineAspect);
ad3217cd 419 }
48cc825e 420 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
ad3217cd 421 {
48cc825e 422 aGroup->SetGroupPrimitivesAspect (aPointAspect);
ad3217cd 423 }
a10fa819 424 }
7fd59977 425 }
426
ad3217cd 427 LoadRecomputable (AIS_WireFrame);
428 LoadRecomputable (2);
7fd59977 429}
5cbef0fe 430
7fd59977 431//=======================================================================
432//function : UnsetColor
ad3217cd 433//purpose :
7fd59977 434//=======================================================================
435
436void AIS_Shape::UnsetColor()
437{
ad3217cd 438 if (!HasColor())
5cbef0fe
S
439 {
440 myToRecomputeModes.Clear();
7604a153 441 myRecomputeEveryPrs = false;
5cbef0fe
S
442 return;
443 }
7604a153 444
7fd59977 445 hasOwnColor = Standard_False;
a6dee93d 446 myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
7fd59977 447
ad3217cd 448 if (!HasWidth())
449 {
450 Handle(Prs3d_LineAspect) anEmptyAsp;
451 myDrawer->SetLineAspect (anEmptyAsp);
452 myDrawer->SetWireAspect (anEmptyAsp);
453 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
454 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
455 myDrawer->SetSeenLineAspect (anEmptyAsp);
7604a153 456 myDrawer->SetFaceBoundaryAspect (anEmptyAsp);
ad3217cd 457 }
458 else
459 {
6262338c 460 Quantity_Color aColor = Quantity_NOC_YELLOW;
461 if (myDrawer->HasLink())
462 {
463 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
464 }
ad3217cd 465 myDrawer->LineAspect()->SetColor (aColor);
6262338c 466 aColor = Quantity_NOC_RED;
467 if (myDrawer->HasLink())
468 {
469 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
470 }
ad3217cd 471 myDrawer->WireAspect()->SetColor (aColor);
6262338c 472 aColor = Quantity_NOC_GREEN;
473 if (myDrawer->HasLink())
474 {
475 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
476 }
ad3217cd 477 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
6262338c 478 aColor = Quantity_NOC_YELLOW;
479 if (myDrawer->HasLink())
480 {
481 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
482 }
ad3217cd 483 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
6262338c 484 if (myDrawer->HasLink())
485 {
486 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
487 }
ad3217cd 488 myDrawer->SeenLineAspect()->SetColor (aColor);
7604a153 489 aColor = Quantity_NOC_BLACK;
490 if (myDrawer->HasLink())
491 {
492 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
493 }
494 myDrawer->FaceBoundaryAspect()->SetColor (aColor);
ad3217cd 495 }
496
a6dee93d 497 if (!myDrawer->HasOwnShadingAspect())
498 {
499 //
500 }
501 else if (HasMaterial()
502 || IsTransparent()
503 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
ad3217cd 504 {
a6dee93d 505 const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
6262338c 506 Graphic3d_MaterialAspect mat = aDefaultMat;
a6dee93d 507 Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
508 if (myDrawer->HasLink())
509 {
510 anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
511 anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
512 }
6262338c 513 if (HasMaterial() || myDrawer->HasLink())
514 {
a6dee93d 515 const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
516 mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
517 ? aSrcAspect->FrontMaterial()
518 : aSrcAspect->BackMaterial();
6262338c 519 }
ad3217cd 520 if (HasMaterial())
521 {
a6dee93d 522 const Quantity_Color aColor = myDrawer->HasLink()
523 ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
524 : aDefaultMat.AmbientColor();
ad3217cd 525 mat.SetColor (aColor);
5cbef0fe 526 }
ad3217cd 527 if (IsTransparent())
528 {
529 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
4e1bc39a 530 mat.SetTransparency (Standard_ShortReal(aTransp));
5cbef0fe 531 }
a6dee93d 532 myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
533 myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]);
534 myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
5cbef0fe 535 }
ad3217cd 536 else
537 {
538 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
5cbef0fe 539 }
ad3217cd 540 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
7604a153 541 myRecomputeEveryPrs = true;
ad3217cd 542}
543
544//=======================================================================
545//function : setWidth
546//purpose :
547//=======================================================================
548
7604a153 549bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
6262338c 550 const Standard_Real theLineWidth) const
ad3217cd 551{
2a332745 552 bool toRecompute = theDrawer->SetOwnLineAspects();
ad3217cd 553
554 // override width
555 theDrawer->LineAspect()->SetWidth (theLineWidth);
556 theDrawer->WireAspect()->SetWidth (theLineWidth);
8a5dfb38 557 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
558 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
559 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
7604a153 560 theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
561 return toRecompute;
7fd59977 562}
563
7fd59977 564//=======================================================================
565//function : SetWidth
566//purpose :
567//=======================================================================
568
ad3217cd 569void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
7fd59977 570{
ad3217cd 571 myOwnWidth = theLineWidth;
7604a153 572 if (setWidth (myDrawer, theLineWidth))
573 {
574 myRecomputeEveryPrs = true;
575 }
576 else
577 {
578 myRecomputeEveryPrs = false;
579 myToRecomputeModes.Clear();
580 SynchronizeAspects();
581 }
7fd59977 582}
583
584//=======================================================================
585//function : UnsetWidth
ad3217cd 586//purpose :
7fd59977 587//=======================================================================
588
589void AIS_Shape::UnsetWidth()
590{
ad3217cd 591 if (myOwnWidth == 0.0)
5cbef0fe
S
592 {
593 myToRecomputeModes.Clear();
7604a153 594 myRecomputeEveryPrs = false;
5cbef0fe
S
595 return;
596 }
5cbef0fe 597
ad3217cd 598 myOwnWidth = 0.0;
ad3217cd 599 if (!HasColor())
600 {
7604a153 601 const Handle(Prs3d_LineAspect) anEmptyAsp;
ad3217cd 602 myDrawer->SetLineAspect (anEmptyAsp);
603 myDrawer->SetWireAspect (anEmptyAsp);
604 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
605 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
606 myDrawer->SetSeenLineAspect (anEmptyAsp);
7604a153 607 myDrawer->SetFaceBoundaryAspect (anEmptyAsp);
608 myRecomputeEveryPrs = true;
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();
625 myToRecomputeModes.Clear();
626 myRecomputeEveryPrs = false;
7fd59977 627 }
7fd59977 628}
629
7fd59977 630//=======================================================================
e0608a8d 631//function : setMaterial
632//purpose :
633//=======================================================================
634
6262338c 635void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
e0608a8d 636 const Graphic3d_MaterialAspect& theMaterial,
637 const Standard_Boolean theToKeepColor,
638 const Standard_Boolean theToKeepTransp) const
639{
640 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
641 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
2a332745 642 theDrawer->SetupOwnShadingAspect();
e0608a8d 643 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
644
645 if (theToKeepColor)
646 {
647 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
648 }
649 if (theToKeepTransp)
650 {
651 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
652 }
653}
654
655//=======================================================================
7fd59977 656//function : SetMaterial
ad3217cd 657//purpose :
7fd59977 658//=======================================================================
5cbef0fe 659
ad3217cd 660void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
7fd59977 661{
e0608a8d 662 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
7fd59977 663 hasOwnMaterial = Standard_True;
5cbef0fe 664
48cc825e 665 // modify shading presentation without re-computation
666 const PrsMgr_Presentations& aPrsList = Presentations();
667 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
668 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 669 {
48cc825e 670 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
671 if (aPrsModed.Mode() != AIS_Shaded)
af324faa 672 {
48cc825e 673 continue;
674 }
675
676 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
48cc825e 677 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
678 {
679 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
680
a10fa819
A
681 // Check if aspect of given type is set for the group,
682 // because setting aspect for group with no already set aspect
683 // can lead to loss of presentation data
ad3217cd 684 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
685 {
686 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
687 }
5cbef0fe 688 }
7fd59977 689 }
48cc825e 690
691 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
692 myToRecomputeModes.Clear();
7fd59977 693}
ad3217cd 694
7fd59977 695//=======================================================================
696//function : UnsetMaterial
ad3217cd 697//purpose :
7fd59977 698//=======================================================================
5cbef0fe 699
7fd59977 700void AIS_Shape::UnsetMaterial()
701{
ad3217cd 702 if (!HasMaterial())
703 {
704 return;
705 }
5cbef0fe 706
a6dee93d 707 if (!myDrawer->HasOwnShadingAspect())
708 {
709 //
710 }
711 else if (HasColor()
712 || IsTransparent()
713 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
ad3217cd 714 {
6262338c 715 if(myDrawer->HasLink())
716 {
717 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
718 myCurrentFacingModel);
719 }
ad3217cd 720 if (HasColor())
721 {
f838dac4 722 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
723 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
7fd59977 724 }
ad3217cd 725 }
726 else
727 {
728 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
7fd59977 729 }
730 hasOwnMaterial = Standard_False;
ad3217cd 731
48cc825e 732 // modify shading presentation without re-computation
733 const PrsMgr_Presentations& aPrsList = Presentations();
734 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
735 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 736 {
48cc825e 737 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
738 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 739 {
48cc825e 740 continue;
741 }
742
743 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
48cc825e 744 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
745 {
746 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 747 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
748 {
749 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
750 }
7fd59977 751 }
752 }
48cc825e 753
ad3217cd 754 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
7fd59977 755 myToRecomputeModes.Clear();
7fd59977 756}
5cbef0fe 757
7fd59977 758//=======================================================================
ad3217cd 759//function : setTransparency
760//purpose :
7fd59977 761//=======================================================================
762
6262338c 763void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
764 const Standard_Real theValue) const
7fd59977 765{
2a332745 766 theDrawer->SetupOwnShadingAspect();
ad3217cd 767 // override transparency
768 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
769}
770
771//=======================================================================
772//function : SetTransparency
773//purpose :
774//=======================================================================
775
776void AIS_Shape::SetTransparency (const Standard_Real theValue)
777{
778 setTransparency (myDrawer, theValue);
f838dac4 779 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
ad3217cd 780
48cc825e 781 // modify shading presentation without re-computation
782 const PrsMgr_Presentations& aPrsList = Presentations();
783 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
784 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 785 {
48cc825e 786 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
787 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 788 {
48cc825e 789 continue;
790 }
791
792 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
48cc825e 793 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
794 {
795 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 796 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
797 {
798 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
799 }
7fd59977 800 }
801 }
48cc825e 802
ad3217cd 803 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
5cbef0fe 804 myToRecomputeModes.Clear();
7fd59977 805}
806
807//=======================================================================
808//function : UnsetTransparency
ad3217cd 809//purpose :
7fd59977 810//=======================================================================
5cbef0fe 811
7fd59977 812void AIS_Shape::UnsetTransparency()
813{
f838dac4 814 myDrawer->SetTransparency (0.0f);
6262338c 815 if (!myDrawer->HasOwnShadingAspect())
ad3217cd 816 {
817 return;
818 }
a6dee93d 819 else if (HasColor()
820 || HasMaterial()
821 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
ad3217cd 822 {
823 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
824 }
825 else
826 {
827 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
828 }
5cbef0fe 829
48cc825e 830 // modify shading presentation without re-computation
831 const PrsMgr_Presentations& aPrsList = Presentations();
832 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
833 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 834 {
48cc825e 835 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
836 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 837 {
48cc825e 838 continue;
839 }
840
841 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
48cc825e 842 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
843 {
844 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 845 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
846 {
847 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
848 }
7fd59977 849 }
850 }
48cc825e 851
ad3217cd 852 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
5cbef0fe 853 myToRecomputeModes.Clear();
7fd59977 854}
855
5cbef0fe
S
856//=======================================================================
857//function : LoadRecomputable
858//purpose :
859//=======================================================================
7fd59977 860
861void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
862{
5cbef0fe 863 myRecomputeEveryPrs = Standard_False;
7fd59977 864 if(!IsInList(myToRecomputeModes,TheMode))
865 myToRecomputeModes.Append(TheMode);
866}
867
7fd59977 868//=======================================================================
869//function : BoundingBox
870//purpose :
871//=======================================================================
872
873const Bnd_Box& AIS_Shape::BoundingBox()
874{
b2d1851c 875 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
876 {
877 // empty Shape -> empty Assembly.
878 myBB.SetVoid ();
879 return myBB;
7fd59977 880 }
881
882 if(myCompBB) {
883 BRepBndLib::AddClose(myshape, myBB);
a10fa819 884 myCompBB = Standard_False;
7fd59977 885 }
886 return myBB;
887}
888
889//*****
890//***** Reset
891//=======================================================================
892//function : SetOwnDeviationCoefficient
893//purpose : resets myhasOwnDeviationCoefficient to Standard_False and
894// returns Standard_True if it change
895//=======================================================================
896
897Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
898{
6262338c 899 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
7fd59977 900 if(itSet) myDrawer->SetDeviationCoefficient();
901 return itSet;
7fd59977 902}
903
7fd59977 904//=======================================================================
905//function : SetHLROwnDeviationCoefficient
906//purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
907// returns Standard_True if it change
908//=======================================================================
909
910Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
911{
6262338c 912 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
7fd59977 913 if(itSet) myDrawer->SetHLRDeviationCoefficient();
914 return itSet;
915
916}
917
918//=======================================================================
919//function : SetOwnDeviationAngle
920//purpose : resets myhasOwnDeviationAngle to Standard_False and
921// returns Standard_True if it change
922//=======================================================================
923
924Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
925{
6262338c 926 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
7fd59977 927 if(itSet) myDrawer->SetDeviationAngle();
928 return itSet;
929
930}
931
932//=======================================================================
933//function : SetOwnHLRDeviationAngle
934//purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
935// returns Standard_True if it change
936//=======================================================================
937
938Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
939{
6262338c 940 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
7fd59977 941 if(itSet) myDrawer->SetHLRAngle();
942 return itSet;
943
944}
945//***** SetOwn
946//=======================================================================
947//function : SetOwnDeviationCoefficient
948//purpose :
949//=======================================================================
950
951void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
952{
953 myDrawer->SetDeviationCoefficient( aCoefficient );
954 SetToUpdate(0) ; // WireFrame
955 SetToUpdate(1) ; // Shadding
956}
957
958//=======================================================================
959//function : SetOwnHLRDeviationCoefficient
960//purpose :
961//=======================================================================
962
963void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
964{
965 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
966
967}
968
969//=======================================================================
970//function : SetOwnDeviationAngle
971//purpose :
972//=======================================================================
973
974void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
975{
976
977 myDrawer->SetDeviationAngle(anAngle );
978 SetToUpdate(0) ; // WireFrame
979}
980//=======================================================================
981//function : SetOwnDeviationAngle
982//purpose :
983//=======================================================================
984
985void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
986{
987 Standard_Real OutAngl,OutDefl;
988 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
989 SetOwnDeviationAngle(anAngle) ;
7fd59977 990 SetOwnDeviationCoefficient(OutDefl) ;
991 myInitAng = anAngle;
992 SetToUpdate(0);
993 SetToUpdate(1);
994}
995
996//=======================================================================
997//function : UserAngle
998//purpose :
999//=======================================================================
1000
1001Standard_Real AIS_Shape::UserAngle() const
1002{
1003 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1004}
1005
1006
1007//=======================================================================
1008//function : SetHLRAngleAndDeviation
1009//purpose :
1010//=======================================================================
1011
1012void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1013{
1014 Standard_Real OutAngl,OutDefl;
1015 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1016 SetOwnHLRDeviationAngle( OutAngl );
1017 SetOwnHLRDeviationCoefficient(OutDefl);
1018
1019}
1020//=======================================================================
1021//function : SetOwnHLRDeviationAngle
1022//purpose :
1023//=======================================================================
1024
1025void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1026{
1027 myDrawer->SetHLRAngle( anAngle );
1028}
1029
1030//***** GetOwn
1031//=======================================================================
1032//function : OwnDeviationCoefficient
1033//purpose :
1034//=======================================================================
1035
1036Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1037 Standard_Real & aPreviousCoefficient ) const
7fd59977 1038{
1039 aCoefficient = myDrawer->DeviationCoefficient();
1040 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
6262338c 1041 return myDrawer->HasOwnDeviationCoefficient() ;
7fd59977 1042}
1043
1044//=======================================================================
1045//function : OwnHLRDeviationCoefficient
1046//purpose :
1047//=======================================================================
1048
1049Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1050 Standard_Real & aPreviousCoefficient ) const
7fd59977 1051{
1052 aCoefficient = myDrawer->HLRDeviationCoefficient();
1053 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
6262338c 1054 return myDrawer->HasOwnHLRDeviationCoefficient();
7fd59977 1055
1056}
1057
1058//=======================================================================
1059//function : OwnDeviationAngle
1060//purpose :
1061//=======================================================================
1062
1063Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
3c34883c 1064 Standard_Real & aPreviousAngle ) const
7fd59977 1065{
1066 anAngle = myDrawer->DeviationAngle();
1067 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
6262338c 1068 return myDrawer->HasOwnDeviationAngle();
7fd59977 1069}
1070
1071//=======================================================================
1072//function : OwnHLRDeviationAngle
1073//purpose :
1074//=======================================================================
1075
1076Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
3c34883c 1077 Standard_Real & aPreviousAngle ) const
7fd59977 1078{
1079 anAngle = myDrawer->HLRAngle();
1080 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
6262338c 1081 return myDrawer->HasOwnHLRDeviationAngle();
7fd59977 1082}