0027060: Visualization issue with TopoDS_Vertex after call of AIS_Shape::SetColor()
[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
7fd59977 17
42cf5bc1 18#include <AIS_GraphicTool.hxx>
19#include <AIS_InteractiveContext.hxx>
20#include <AIS_Shape.hxx>
21#include <Aspect_TypeOfLine.hxx>
7fd59977 22#include <Bnd_Box.hxx>
23#include <BRep_Builder.hxx>
7fd59977 24#include <BRepBndLib.hxx>
42cf5bc1 25#include <BRepTools.hxx>
26#include <BRepTools_ShapeSet.hxx>
27#include <Geom_Transformation.hxx>
28#include <gp_Pnt.hxx>
29#include <Graphic3d_ArrayOfPolylines.hxx>
30#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 31#include <Graphic3d_AspectLine3d.hxx>
7fd59977 32#include <Graphic3d_AspectMarker3d.hxx>
42cf5bc1 33#include <Graphic3d_AspectText3d.hxx>
34#include <Graphic3d_Group.hxx>
7fd59977 35#include <Graphic3d_MaterialAspect.hxx>
48cc825e 36#include <Graphic3d_SequenceOfGroup.hxx>
42cf5bc1 37#include <Graphic3d_Structure.hxx>
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>
42cf5bc1 45#include <Prs3d_Projector.hxx>
7fd59977 46#include <Prs3d_Root.hxx>
47#include <Prs3d_ShadingAspect.hxx>
5ad8c033 48#include <StdPrs_BndBox.hxx>
49#include <StdPrs_ToolTriangulatedShape.hxx>
7fd59977 50#include <PrsMgr_ModedPresentation.hxx>
42cf5bc1 51#include <Quantity_Color.hxx>
52#include <Select3D_SensitiveBox.hxx>
7fd59977 53#include <Select3D_SensitiveEntity.hxx>
42cf5bc1 54#include <Standard_ErrorHandler.hxx>
55#include <Standard_Failure.hxx>
56#include <Standard_Type.hxx>
57#include <StdPrs_HLRPolyShape.hxx>
58#include <StdPrs_HLRShape.hxx>
59#include <StdPrs_ShadedShape.hxx>
42cf5bc1 60#include <StdPrs_WFShape.hxx>
7fd59977 61#include <StdSelect.hxx>
7fd59977 62#include <StdSelect_BRepOwner.hxx>
42cf5bc1 63#include <StdSelect_BRepSelectionTool.hxx>
7fd59977 64#include <StdSelect_DisplayMode.hxx>
42cf5bc1 65#include <TColStd_ListIteratorOfListOfInteger.hxx>
66#include <TopExp.hxx>
67#include <TopExp_Explorer.hxx>
7fd59977 68#include <TopoDS_Iterator.hxx>
42cf5bc1 69#include <TopoDS_Shape.hxx>
7fd59977 70
92efcf78 71IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
72
7fd59977 73static Standard_Boolean myFirstCompute;
74
7fd59977 75static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
76{
77 TColStd_ListIteratorOfListOfInteger It(LL);
78 for(;It.More();It.Next()){
79 if(It.Value()==aMode)
80 return Standard_True;}
81 return Standard_False;
82}
83
84//==================================================
85// Function:
86// Purpose :
87//==================================================
88
89AIS_Shape::
90AIS_Shape(const TopoDS_Shape& shap):
91AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
7fd59977 92myInitAng(0.)
93{
6262338c 94 Set (shap);
7fd59977 95 myFirstCompute = Standard_True;
96 SetHilightMode(0);
97 myDrawer->SetShadingAspectGlobal(Standard_False);
98}
99
100//=======================================================================
101//function : Type
102//purpose :
103//=======================================================================
104AIS_KindOfInteractive AIS_Shape::Type() const
105{return AIS_KOI_Shape;}
106
107
108//=======================================================================
109//function : Signature
110//purpose :
111//=======================================================================
112Standard_Integer AIS_Shape::Signature() const
113{return 0;}
114
115//=======================================================================
116//function : AcceptShapeDecomposition
117//purpose :
118//=======================================================================
119Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
120{return Standard_True;}
121
122//=======================================================================
123//function : Compute
124//purpose :
125//=======================================================================
126void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3c34883c
O
127 const Handle(Prs3d_Presentation)& aPrs,
128 const Standard_Integer aMode)
7fd59977 129{
130 aPrs->Clear();
131 if(myshape.IsNull()) return;
132
133 // wire,edge,vertex -> pas de HLR + priorite display superieure
134 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
135 if(TheType>4 && TheType<8) {
136 aPrs->SetVisual(Graphic3d_TOS_ALL);
137 aPrs->SetDisplayPriority(TheType+2);
138 }
139 // Shape vide -> Assemblage vide.
140 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 141 TopoDS_Iterator anExplor (myshape);
a10fa819 142
7fd59977 143 if (!anExplor.More()) {
144 return;
145 }
146 }
a10fa819 147
5ad8c033 148 if (IsInfinite())
149 {
150 aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
7fd59977 151 }
5ad8c033 152
153 switch (aMode)
154 {
155 case AIS_WireFrame:
156 {
157 try
158 {
159 OCC_CATCH_SIGNALS
160 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
161 }
162 catch (Standard_Failure)
163 {
164 #ifdef OCCT_DEBUG
165 cout << "AIS_Shape::Compute() failed" << endl;
166 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
167 #endif
168 // presentation of the bounding box is calculated
169 // Compute(aPresentationManager,aPrs,2);
170 }
171 break;
172 }
173 case AIS_Shaded:
7fd59977 174 {
4c513386 175 if (myDrawer->IsAutoTriangulation())
ad3217cd 176 {
4c513386 177 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
178 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
179 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
180 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
181 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
182 {
183 BRepTools::Clean (myshape);
184 }
bbf847ad 185 }
ad3217cd 186
5ad8c033 187 if ((Standard_Integer) myshape.ShapeType() > 4)
188 {
189 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
190 }
191 else
192 {
193 myDrawer->SetShadingAspectGlobal (Standard_False);
194 if (IsInfinite())
195 {
196 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
197 }
198 else
199 {
200 try
201 {
202 OCC_CATCH_SIGNALS
203 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
204 }
205 catch (Standard_Failure)
3c34883c 206 {
5ad8c033 207 #ifdef OCCT_DEBUG
208 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
209 #endif
210 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
3c34883c
O
211 }
212 }
7fd59977 213 }
5ad8c033 214 Standard_Real aTransparency = Transparency() ;
215 if (aTransparency > 0.0)
216 {
217 SetTransparency (aTransparency);
7fd59977 218 }
7fd59977 219 break;
220 }
5ad8c033 221
222 // Bounding box.
223 case 2:
7fd59977 224 {
5ad8c033 225 if (IsInfinite())
226 {
227 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
228 }
229 else
230 {
231 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
232 }
7fd59977 233 }
5ad8c033 234 }
235
236 // Recompute hidden line presentation (if necessary).
237 aPrs->ReCompute();
7fd59977 238}
239
7fd59977 240//=======================================================================
241//function : Compute
242//purpose : Hidden Line Removal
243//=======================================================================
244void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c 245 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 246{
247 Compute(aProjector,aPresentation,myshape);
248}
249
250//=======================================================================
251//function : Compute
252//purpose :
253//=======================================================================
254
255void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c
O
256 const Handle(Geom_Transformation)& TheTrsf,
257 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 258{
259 const TopLoc_Location& loc = myshape.Location();
260 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
261 Compute(aProjector,aPresentation,shbis);
262}
263
264//=======================================================================
265//function : Compute
266//purpose :
267//=======================================================================
268
269void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c
O
270 const Handle(Prs3d_Presentation)& aPresentation,
271 const TopoDS_Shape& SH)
7fd59977 272{
273 if (SH.ShapeType() == TopAbs_COMPOUND) {
7fd59977 274 TopoDS_Iterator anExplor (SH);
a10fa819 275
7fd59977 276 if (!anExplor.More()) // Shape vide -> Assemblage vide.
277 return;
278 }
a10fa819 279
7fd59977 280 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
6262338c 281 if (defdrawer->DrawHiddenLine())
7fd59977 282 {myDrawer->EnableDrawHiddenLine();}
283 else {myDrawer->DisableDrawHiddenLine();}
a10fa819 284
7fd59977 285 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
286 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
287
4c513386 288 if (myDrawer->IsAutoTriangulation())
289 {
290 // coefficients for calculation
291 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
292 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
293 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
294 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
295 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
296 {
7fd59977 297 BRepTools::Clean(SH);
298 }
4c513386 299 }
7fd59977 300
301 {
302 try {
303 OCC_CATCH_SIGNALS
0a768f56 304 switch (TypeOfHLR()) {
305 case Prs3d_TOH_Algo:
306 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
307 break;
308 case Prs3d_TOH_PolyAlgo:
309 default:
310 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
311 break;
312 }
7fd59977 313 }
314 catch (Standard_Failure) {
0797d9d3 315#ifdef OCCT_DEBUG
7fd59977 316 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
317#endif
318 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
319 }
320 }
321
7fd59977 322 defdrawer->SetTypeOfDeflection (prevdef);
323}
324
325//=======================================================================
326//function : SelectionType
327//purpose : gives the type according to the Index of Selection Mode
328//=======================================================================
329
330TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
331{
332 switch(aMode){
333 case 1:
334 return TopAbs_VERTEX;
335 case 2:
336 return TopAbs_EDGE;
337 case 3:
338 return TopAbs_WIRE;
339 case 4:
340 return TopAbs_FACE;
341 case 5:
342 return TopAbs_SHELL;
343 case 6:
344 return TopAbs_SOLID;
345 case 7:
346 return TopAbs_COMPSOLID;
347 case 8:
348 return TopAbs_COMPOUND;
349 case 0:
350 default:
351 return TopAbs_SHAPE;
352 }
353
354}
355//=======================================================================
356//function : SelectionType
357//purpose : gives the SelectionMode according to the Type od Decomposition...
358//=======================================================================
359Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
360{
361 switch(aType){
362 case TopAbs_VERTEX:
363 return 1;
364 case TopAbs_EDGE:
365 return 2;
366 case TopAbs_WIRE:
367 return 3;
368 case TopAbs_FACE:
369 return 4;
370 case TopAbs_SHELL:
371 return 5;
372 case TopAbs_SOLID:
373 return 6;
374 case TopAbs_COMPSOLID:
375 return 7;
376 case TopAbs_COMPOUND:
377 return 8;
378 case TopAbs_SHAPE:
379 default:
380 return 0;
381 }
382}
383
384
385//=======================================================================
386//function : ComputeSelection
387//purpose :
388//=======================================================================
389
390void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
3c34883c 391 const Standard_Integer aMode)
7fd59977 392{
393 if(myshape.IsNull()) return;
394 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 395 TopoDS_Iterator anExplor (myshape);
a10fa819 396
81bba717 397 if (!anExplor.More()) // empty Shape -> empty Assembly.
7fd59977 398 return;
399 }
400
401 static TopAbs_ShapeEnum TypOfSel;
402 TypOfSel = AIS_Shape::SelectionType(aMode);
403 TopoDS_Shape shape = myshape;
7fd59977 404
81bba717 405// POP protection against crash in low layers
7fd59977 406
9dba391d 407 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
7fd59977 408 try {
409 OCC_CATCH_SIGNALS
410 StdSelect_BRepSelectionTool::Load(aSelection,
411 this,
412 shape,
413 TypOfSel,
414 aDeflection,
3c34883c 415 myDrawer->HLRAngle(),
4c513386 416 myDrawer->IsAutoTriangulation());
7fd59977 417 } catch ( Standard_Failure ) {
418// cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
419 if ( aMode == 0 ) {
53a70197 420 aSelection->Clear();
7fd59977 421 Bnd_Box B = BoundingBox();
422 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
423 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
424 aSelection->Add(aSensitiveBox);
425 }
426 }
427
428 // insert the drawer in the BrepOwners for hilight...
429 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
430}
431
7fd59977 432Quantity_NameOfColor AIS_Shape::Color() const {
433Quantity_Color aColor;
434 Color(aColor);
435 return aColor.Name();
436}
437
438void AIS_Shape::Color( Quantity_Color& aColor ) const {
439 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
440}
441
442Graphic3d_NameOfMaterial AIS_Shape::Material() const {
443 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
444}
445
446Standard_Real AIS_Shape::Transparency() const {
447 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
448}
7fd59977 449
450//=======================================================================
451//function : SetColor
452//purpose :
453//=======================================================================
454
455void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
7fd59977 456{
457 SetColor(Quantity_Color(aCol));
458}
459
5cbef0fe 460//=======================================================================
ad3217cd 461//function : setColor
462//purpose :
5cbef0fe
S
463//=======================================================================
464
6262338c 465void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
466 const Quantity_Color& theColor) const
7fd59977 467{
6262338c 468 if (!theDrawer->HasOwnShadingAspect())
ad3217cd 469 {
470 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6262338c 471 if (theDrawer->HasLink())
472 {
473 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
474 }
7fd59977 475 }
6262338c 476 if (!theDrawer->HasOwnLineAspect())
ad3217cd 477 {
478 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
6262338c 479 if (theDrawer->HasLink())
480 {
481 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
482 }
ad3217cd 483 }
6262338c 484 if (!theDrawer->HasOwnWireAspect())
ad3217cd 485 {
486 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
6262338c 487 if (theDrawer->HasLink())
488 {
489 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
490 }
ad3217cd 491 }
6262338c 492 if (!theDrawer->HasOwnPointAspect())
ad3217cd 493 {
7d835040 494 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
6262338c 495 if (theDrawer->HasLink())
496 {
497 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
498 }
ad3217cd 499 }
8a5dfb38 500 if (!theDrawer->HasOwnFreeBoundaryAspect())
501 {
502 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
503 if (theDrawer->HasLink())
504 {
505 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
506 }
507 }
508 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
509 {
510 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
511 if (theDrawer->HasLink())
512 {
513 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
514 }
515 }
516 if (!theDrawer->HasOwnSeenLineAspect())
517 {
518 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
519 if (theDrawer->HasLink())
520 {
521 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
522 }
523 }
ad3217cd 524
525 // override color
526 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
527 theDrawer->SetShadingAspectGlobal (Standard_False);
528 theDrawer->LineAspect()->SetColor (theColor);
529 theDrawer->WireAspect()->SetColor (theColor);
530 theDrawer->PointAspect()->SetColor (theColor);
8a5dfb38 531 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
532 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
533 theDrawer->SeenLineAspect()->SetColor (theColor);
ad3217cd 534}
a10fa819 535
ad3217cd 536//=======================================================================
537//function : SetColor
538//purpose :
539//=======================================================================
7fd59977 540
ad3217cd 541void AIS_Shape::SetColor (const Quantity_Color& theColor)
542{
543 setColor (myDrawer, theColor);
544 myOwnColor = theColor;
545 hasOwnColor = Standard_True;
7fd59977 546
48cc825e 547 // modify shading presentation without re-computation
548 const PrsMgr_Presentations& aPrsList = Presentations();
549 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
550 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
551 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
552 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 553 {
48cc825e 554 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
555 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 556 {
48cc825e 557 continue;
558 }
559
560 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
561
562 // Set aspects for presentation
563 aPrs->SetPrimitivesAspect (anAreaAspect);
564 aPrs->SetPrimitivesAspect (aLineAspect);
565 aPrs->SetPrimitivesAspect (aPointAspect);
566
567 // Go through all groups to change color for all primitives
568 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
569 {
570 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
571
a10fa819
A
572 // Check if aspect of given type is set for the group,
573 // because setting aspect for group with no already set aspect
574 // can lead to loss of presentation data
48cc825e 575 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
ad3217cd 576 {
48cc825e 577 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
ad3217cd 578 }
48cc825e 579 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
ad3217cd 580 {
48cc825e 581 aGroup->SetGroupPrimitivesAspect (aLineAspect);
ad3217cd 582 }
48cc825e 583 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
ad3217cd 584 {
48cc825e 585 aGroup->SetGroupPrimitivesAspect (aPointAspect);
ad3217cd 586 }
a10fa819 587 }
7fd59977 588 }
589
ad3217cd 590 LoadRecomputable (AIS_WireFrame);
591 LoadRecomputable (2);
7fd59977 592}
5cbef0fe 593
7fd59977 594//=======================================================================
595//function : UnsetColor
ad3217cd 596//purpose :
7fd59977 597//=======================================================================
598
599void AIS_Shape::UnsetColor()
600{
ad3217cd 601 if (!HasColor())
5cbef0fe
S
602 {
603 myToRecomputeModes.Clear();
604 return;
605 }
7fd59977 606 hasOwnColor = Standard_False;
607
ad3217cd 608 if (!HasWidth())
609 {
610 Handle(Prs3d_LineAspect) anEmptyAsp;
611 myDrawer->SetLineAspect (anEmptyAsp);
612 myDrawer->SetWireAspect (anEmptyAsp);
613 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
614 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
615 myDrawer->SetSeenLineAspect (anEmptyAsp);
616 }
617 else
618 {
6262338c 619 Quantity_Color aColor = Quantity_NOC_YELLOW;
620 if (myDrawer->HasLink())
621 {
622 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
623 }
ad3217cd 624 myDrawer->LineAspect()->SetColor (aColor);
6262338c 625 aColor = Quantity_NOC_RED;
626 if (myDrawer->HasLink())
627 {
628 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
629 }
ad3217cd 630 myDrawer->WireAspect()->SetColor (aColor);
6262338c 631 aColor = Quantity_NOC_GREEN;
632 if (myDrawer->HasLink())
633 {
634 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
635 }
ad3217cd 636 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
6262338c 637 aColor = Quantity_NOC_YELLOW;
638 if (myDrawer->HasLink())
639 {
640 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
641 }
ad3217cd 642 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
6262338c 643 if (myDrawer->HasLink())
644 {
645 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
646 }
ad3217cd 647 myDrawer->SeenLineAspect()->SetColor (aColor);
648 }
649
650 if (HasMaterial()
651 || IsTransparent())
652 {
6262338c 653 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
654 Graphic3d_MaterialAspect mat = aDefaultMat;
655 if (HasMaterial() || myDrawer->HasLink())
656 {
657 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
658 }
ad3217cd 659 if (HasMaterial())
660 {
6262338c 661 Quantity_Color aColor = aDefaultMat.AmbientColor();
662 if (myDrawer->HasLink())
663 {
4e2914a6 664 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
6262338c 665 }
ad3217cd 666 mat.SetColor (aColor);
5cbef0fe 667 }
ad3217cd 668 if (IsTransparent())
669 {
670 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
671 mat.SetTransparency (aTransp);
5cbef0fe 672 }
ad3217cd 673 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
5cbef0fe 674 }
ad3217cd 675 else
676 {
677 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
5cbef0fe 678 }
ad3217cd 679 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
5cbef0fe 680
48cc825e 681 // modify shading presentation without re-computation
682 const PrsMgr_Presentations& aPrsList = Presentations();
683 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
684 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
685 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 686 {
48cc825e 687 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
688 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 689 {
48cc825e 690 continue;
691 }
692
693 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
694
695 aPrs->SetPrimitivesAspect (anAreaAsp);
696 aPrs->SetPrimitivesAspect (aLineAsp);
697
698 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
699 {
700 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
701
702 // Check if aspect of given type is set for the group,
a10fa819
A
703 // because setting aspect for group with no already set aspect
704 // can lead to loss of presentation data
ad3217cd 705 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
706 {
707 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
708 }
709 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
710 {
711 aGroup->SetGroupPrimitivesAspect (aLineAsp);
712 }
7fd59977 713 }
5cbef0fe 714 }
48cc825e 715
ad3217cd 716 LoadRecomputable (AIS_WireFrame);
717 LoadRecomputable (2);
718}
719
720//=======================================================================
721//function : setWidth
722//purpose :
723//=======================================================================
724
6262338c 725void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
726 const Standard_Real theLineWidth) const
ad3217cd 727{
6262338c 728 if (!theDrawer->HasOwnLineAspect())
ad3217cd 729 {
730 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
6262338c 731 if (theDrawer->HasLink())
732 {
733 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
734 }
ad3217cd 735 }
6262338c 736 if (!theDrawer->HasOwnWireAspect())
ad3217cd 737 {
738 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
6262338c 739 if (theDrawer->HasLink())
740 {
741 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
742 }
ad3217cd 743 }
8a5dfb38 744 if (!theDrawer->HasOwnFreeBoundaryAspect())
745 {
746 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
747 if (theDrawer->HasLink())
748 {
749 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
750 }
751 }
752 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
753 {
754 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
755 if (theDrawer->HasLink())
756 {
757 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
758 }
759 }
760 if (!theDrawer->HasOwnSeenLineAspect())
761 {
762 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
763 if (theDrawer->HasLink())
764 {
765 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
766 }
767 }
ad3217cd 768
769 // override width
770 theDrawer->LineAspect()->SetWidth (theLineWidth);
771 theDrawer->WireAspect()->SetWidth (theLineWidth);
8a5dfb38 772 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
773 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
774 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
7fd59977 775}
776
7fd59977 777//=======================================================================
778//function : SetWidth
779//purpose :
780//=======================================================================
781
ad3217cd 782void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
7fd59977 783{
ad3217cd 784 setWidth (myDrawer, theLineWidth);
785 myOwnWidth = theLineWidth;
786 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
787 LoadRecomputable (2); // and the bounding box...
7fd59977 788}
789
790//=======================================================================
791//function : UnsetWidth
ad3217cd 792//purpose :
7fd59977 793//=======================================================================
794
795void AIS_Shape::UnsetWidth()
796{
ad3217cd 797 if (myOwnWidth == 0.0)
5cbef0fe
S
798 {
799 myToRecomputeModes.Clear();
800 return;
801 }
5cbef0fe 802
ad3217cd 803 myOwnWidth = 0.0;
804
805 Handle(Prs3d_LineAspect) anEmptyAsp;
5cbef0fe 806
ad3217cd 807 if (!HasColor())
808 {
809 myDrawer->SetLineAspect (anEmptyAsp);
810 myDrawer->SetWireAspect (anEmptyAsp);
811 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
812 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
813 myDrawer->SetSeenLineAspect (anEmptyAsp);
7fd59977 814 }
ad3217cd 815 else
816 {
6262338c 817 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
818 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
819 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
820 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
821 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
822 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
823 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
824 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
825 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
826 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
7fd59977 827 }
ad3217cd 828 LoadRecomputable (AIS_WireFrame);
7fd59977 829}
830
e0608a8d 831//=======================================================================
832//function : setMaterial
833//purpose :
834//=======================================================================
835
6262338c 836void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
e0608a8d 837 const Graphic3d_MaterialAspect& theMaterial,
838 const Standard_Boolean theToKeepColor,
839 const Standard_Boolean theToKeepTransp) const
840{
841 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
842 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
6262338c 843 if (!theDrawer->HasOwnShadingAspect())
e0608a8d 844 {
845 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6262338c 846 if (theDrawer->HasLink())
847 {
848 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
849 }
e0608a8d 850 }
851 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
852
853 if (theToKeepColor)
854 {
855 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
856 }
857 if (theToKeepTransp)
858 {
859 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
860 }
861}
862
7fd59977 863//=======================================================================
864//function : SetMaterial
865//purpose :
866//=======================================================================
5cbef0fe 867
7fd59977 868void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
869{
a10fa819 870 SetMaterial(Graphic3d_MaterialAspect(aMat));
7fd59977 871}
5cbef0fe 872
7fd59977 873//=======================================================================
874//function : SetMaterial
ad3217cd 875//purpose :
7fd59977 876//=======================================================================
5cbef0fe 877
ad3217cd 878void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
7fd59977 879{
e0608a8d 880 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
7fd59977 881 hasOwnMaterial = Standard_True;
5cbef0fe 882
48cc825e 883 // modify shading presentation without re-computation
884 const PrsMgr_Presentations& aPrsList = Presentations();
885 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
886 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 887 {
48cc825e 888 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
889 if (aPrsModed.Mode() != AIS_Shaded)
af324faa 890 {
48cc825e 891 continue;
892 }
893
894 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
895 aPrs->SetPrimitivesAspect (anAreaAsp);
896 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
897 {
898 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
899
a10fa819
A
900 // Check if aspect of given type is set for the group,
901 // because setting aspect for group with no already set aspect
902 // can lead to loss of presentation data
ad3217cd 903 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
904 {
905 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
906 }
5cbef0fe 907 }
7fd59977 908 }
48cc825e 909
910 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
911 myToRecomputeModes.Clear();
7fd59977 912}
ad3217cd 913
7fd59977 914//=======================================================================
915//function : UnsetMaterial
ad3217cd 916//purpose :
7fd59977 917//=======================================================================
5cbef0fe 918
7fd59977 919void AIS_Shape::UnsetMaterial()
920{
ad3217cd 921 if (!HasMaterial())
922 {
923 return;
924 }
5cbef0fe 925
ad3217cd 926 if (HasColor()
927 || IsTransparent())
928 {
6262338c 929 if(myDrawer->HasLink())
930 {
931 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
932 myCurrentFacingModel);
933 }
ad3217cd 934 if (HasColor())
935 {
936 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
937 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
7fd59977 938 }
ad3217cd 939 }
940 else
941 {
942 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
7fd59977 943 }
944 hasOwnMaterial = Standard_False;
ad3217cd 945
48cc825e 946 // modify shading presentation without re-computation
947 const PrsMgr_Presentations& aPrsList = Presentations();
948 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
949 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 950 {
48cc825e 951 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
952 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 953 {
48cc825e 954 continue;
955 }
956
957 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
958 aPrs->SetPrimitivesAspect (anAreaAsp);
959 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
960 {
961 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 962 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
963 {
964 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
965 }
7fd59977 966 }
967 }
48cc825e 968
ad3217cd 969 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
7fd59977 970 myToRecomputeModes.Clear();
7fd59977 971}
5cbef0fe 972
7fd59977 973//=======================================================================
ad3217cd 974//function : setTransparency
975//purpose :
7fd59977 976//=======================================================================
977
6262338c 978void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
979 const Standard_Real theValue) const
7fd59977 980{
6262338c 981 if (!theDrawer->HasOwnShadingAspect())
ad3217cd 982 {
983 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6262338c 984 if (theDrawer->HasLink())
985 {
986 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
987 }
7fd59977 988 }
5cbef0fe 989
ad3217cd 990 // override transparency
991 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
992}
993
994//=======================================================================
995//function : SetTransparency
996//purpose :
997//=======================================================================
998
999void AIS_Shape::SetTransparency (const Standard_Real theValue)
1000{
1001 setTransparency (myDrawer, theValue);
1002 myTransparency = theValue;
1003
48cc825e 1004 // modify shading presentation without re-computation
1005 const PrsMgr_Presentations& aPrsList = Presentations();
1006 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1007 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 1008 {
48cc825e 1009 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1010 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 1011 {
48cc825e 1012 continue;
1013 }
1014
1015 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1016 aPrs->SetPrimitivesAspect (anAreaAsp);
1017 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1018 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1019 {
1020 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 1021 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1022 {
1023 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1024 }
7fd59977 1025 }
1026 }
48cc825e 1027
ad3217cd 1028 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
5cbef0fe 1029 myToRecomputeModes.Clear();
7fd59977 1030}
1031
1032//=======================================================================
1033//function : UnsetTransparency
ad3217cd 1034//purpose :
7fd59977 1035//=======================================================================
5cbef0fe 1036
7fd59977 1037void AIS_Shape::UnsetTransparency()
1038{
7fd59977 1039 myTransparency = 0.0;
6262338c 1040 if (!myDrawer->HasOwnShadingAspect())
ad3217cd 1041 {
1042 return;
1043 }
1044 else if (HasColor() || HasMaterial())
1045 {
1046 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1047 }
1048 else
1049 {
1050 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1051 }
5cbef0fe 1052
48cc825e 1053 // modify shading presentation without re-computation
1054 const PrsMgr_Presentations& aPrsList = Presentations();
1055 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1056 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
ad3217cd 1057 {
48cc825e 1058 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1059 if (aPrsModed.Mode() != AIS_Shaded)
ad3217cd 1060 {
48cc825e 1061 continue;
1062 }
1063
1064 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1065 aPrs->SetPrimitivesAspect (anAreaAsp);
1066 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1067 {
1068 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
ad3217cd 1069 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1070 {
1071 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1072 }
7fd59977 1073 }
48cc825e 1074 aPrs->ResetDisplayPriority();
7fd59977 1075 }
48cc825e 1076
ad3217cd 1077 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
5cbef0fe 1078 myToRecomputeModes.Clear();
7fd59977 1079}
1080
5cbef0fe
S
1081//=======================================================================
1082//function : LoadRecomputable
1083//purpose :
1084//=======================================================================
7fd59977 1085
1086void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1087{
5cbef0fe 1088 myRecomputeEveryPrs = Standard_False;
7fd59977 1089 if(!IsInList(myToRecomputeModes,TheMode))
1090 myToRecomputeModes.Append(TheMode);
1091}
1092
7fd59977 1093//=======================================================================
1094//function : BoundingBox
1095//purpose :
1096//=======================================================================
1097
1098const Bnd_Box& AIS_Shape::BoundingBox()
1099{
1100 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 1101 TopoDS_Iterator anExplor (myshape);
a10fa819 1102
81bba717 1103 if (!anExplor.More()) { // empty Shape -> empty Assembly.
a10fa819 1104 myBB.SetVoid();
7fd59977 1105 return myBB;
1106 }
1107 }
1108
1109 if(myCompBB) {
1110 BRepBndLib::AddClose(myshape, myBB);
a10fa819 1111 myCompBB = Standard_False;
7fd59977 1112 }
1113 return myBB;
1114}
1115
1116//*****
1117//***** Reset
1118//=======================================================================
1119//function : SetOwnDeviationCoefficient
1120//purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1121// returns Standard_True if it change
1122//=======================================================================
1123
1124Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1125{
6262338c 1126 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
7fd59977 1127 if(itSet) myDrawer->SetDeviationCoefficient();
1128 return itSet;
7fd59977 1129}
1130
7fd59977 1131//=======================================================================
1132//function : SetHLROwnDeviationCoefficient
1133//purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1134// returns Standard_True if it change
1135//=======================================================================
1136
1137Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1138{
6262338c 1139 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
7fd59977 1140 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1141 return itSet;
1142
1143}
1144
1145//=======================================================================
1146//function : SetOwnDeviationAngle
1147//purpose : resets myhasOwnDeviationAngle to Standard_False and
1148// returns Standard_True if it change
1149//=======================================================================
1150
1151Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1152{
6262338c 1153 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
7fd59977 1154 if(itSet) myDrawer->SetDeviationAngle();
1155 return itSet;
1156
1157}
1158
1159//=======================================================================
1160//function : SetOwnHLRDeviationAngle
1161//purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1162// returns Standard_True if it change
1163//=======================================================================
1164
1165Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1166{
6262338c 1167 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
7fd59977 1168 if(itSet) myDrawer->SetHLRAngle();
1169 return itSet;
1170
1171}
1172//***** SetOwn
1173//=======================================================================
1174//function : SetOwnDeviationCoefficient
1175//purpose :
1176//=======================================================================
1177
1178void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1179{
1180 myDrawer->SetDeviationCoefficient( aCoefficient );
1181 SetToUpdate(0) ; // WireFrame
1182 SetToUpdate(1) ; // Shadding
1183}
1184
1185//=======================================================================
1186//function : SetOwnHLRDeviationCoefficient
1187//purpose :
1188//=======================================================================
1189
1190void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1191{
1192 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1193
1194}
1195
1196//=======================================================================
1197//function : SetOwnDeviationAngle
1198//purpose :
1199//=======================================================================
1200
1201void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1202{
1203
1204 myDrawer->SetDeviationAngle(anAngle );
1205 SetToUpdate(0) ; // WireFrame
1206}
1207//=======================================================================
1208//function : SetOwnDeviationAngle
1209//purpose :
1210//=======================================================================
1211
1212void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1213{
1214 Standard_Real OutAngl,OutDefl;
1215 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1216 SetOwnDeviationAngle(anAngle) ;
7fd59977 1217 SetOwnDeviationCoefficient(OutDefl) ;
1218 myInitAng = anAngle;
1219 SetToUpdate(0);
1220 SetToUpdate(1);
1221}
1222
1223//=======================================================================
1224//function : UserAngle
1225//purpose :
1226//=======================================================================
1227
1228Standard_Real AIS_Shape::UserAngle() const
1229{
1230 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1231}
1232
1233
1234//=======================================================================
1235//function : SetHLRAngleAndDeviation
1236//purpose :
1237//=======================================================================
1238
1239void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1240{
1241 Standard_Real OutAngl,OutDefl;
1242 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1243 SetOwnHLRDeviationAngle( OutAngl );
1244 SetOwnHLRDeviationCoefficient(OutDefl);
1245
1246}
1247//=======================================================================
1248//function : SetOwnHLRDeviationAngle
1249//purpose :
1250//=======================================================================
1251
1252void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1253{
1254 myDrawer->SetHLRAngle( anAngle );
1255}
1256
1257//***** GetOwn
1258//=======================================================================
1259//function : OwnDeviationCoefficient
1260//purpose :
1261//=======================================================================
1262
1263Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1264 Standard_Real & aPreviousCoefficient ) const
7fd59977 1265{
1266 aCoefficient = myDrawer->DeviationCoefficient();
1267 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
6262338c 1268 return myDrawer->HasOwnDeviationCoefficient() ;
7fd59977 1269}
1270
1271//=======================================================================
1272//function : OwnHLRDeviationCoefficient
1273//purpose :
1274//=======================================================================
1275
1276Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1277 Standard_Real & aPreviousCoefficient ) const
7fd59977 1278{
1279 aCoefficient = myDrawer->HLRDeviationCoefficient();
1280 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
6262338c 1281 return myDrawer->HasOwnHLRDeviationCoefficient();
7fd59977 1282
1283}
1284
1285//=======================================================================
1286//function : OwnDeviationAngle
1287//purpose :
1288//=======================================================================
1289
1290Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
3c34883c 1291 Standard_Real & aPreviousAngle ) const
7fd59977 1292{
1293 anAngle = myDrawer->DeviationAngle();
1294 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
6262338c 1295 return myDrawer->HasOwnDeviationAngle();
7fd59977 1296}
1297
1298//=======================================================================
1299//function : OwnHLRDeviationAngle
1300//purpose :
1301//=======================================================================
1302
1303Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
3c34883c 1304 Standard_Real & aPreviousAngle ) const
7fd59977 1305{
1306 anAngle = myDrawer->HLRAngle();
1307 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
6262338c 1308 return myDrawer->HasOwnHLRDeviationAngle();
7fd59977 1309}