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