0023634: Eliminate Polyline and Polygon usage in drawers
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
7fd59977 22#include <AIS_Shape.ixx>
23
24
25#include <Standard_ErrorHandler.hxx>
26#include <OSD_Timer.hxx>
27#include <TColStd_ListIteratorOfListOfInteger.hxx>
28
29#include <Quantity_Color.hxx>
30
31#include <gp_Pnt.hxx>
32#include <Bnd_Box.hxx>
33#include <BRep_Builder.hxx>
34#include <BRepTools_ShapeSet.hxx>
35#include <BRepTools.hxx>
36#include <BRepBndLib.hxx>
37#include <TopExp.hxx>
38#include <TopExp_Explorer.hxx>
39
40#include <Aspect_TypeOfLine.hxx>
41#include <Graphic3d_Structure.hxx>
42#include <Graphic3d_Group.hxx>
43#include <Graphic3d_AspectLine3d.hxx>
44#include <Graphic3d_AspectText3d.hxx>
45#include <Graphic3d_AspectMarker3d.hxx>
46#include <Graphic3d_AspectFillArea3d.hxx>
b8ddfc2f 47#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 48#include <Graphic3d_MaterialAspect.hxx>
49
50#include <Prs3d_Presentation.hxx>
51#include <Prs3d_Root.hxx>
52#include <Prs3d_ShadingAspect.hxx>
53#include <Prs3d_Drawer.hxx>
54#include <Prs3d_IsoAspect.hxx>
55
7fd59977 56#include <StdPrs_WFShape.hxx>
57#include <StdPrs_WFDeflectionShape.hxx>
58#include <StdPrs_ShadedShape.hxx>
59#include <StdPrs_HLRShape.hxx>
60#include <StdPrs_HLRPolyShape.hxx>
61
62#include <PrsMgr_ModedPresentation.hxx>
63
64#include <Select3D_SensitiveEntity.hxx>
65#include <StdSelect.hxx>
66#include <StdSelect_BRepSelectionTool.hxx>
67#include <StdSelect_BRepOwner.hxx>
68#include <StdSelect_DisplayMode.hxx>
69
70#include <AIS_GraphicTool.hxx>
71#include <AIS_InteractiveContext.hxx>
72#include <AIS_Drawer.hxx>
73#include <HLRBRep.hxx>
74#include <Precision.hxx>
75
76#include <Standard_Failure.hxx>
77#include <Standard_ErrorHandler.hxx>
78#include <Select3D_SensitiveBox.hxx>
7fd59977 79#include <TopoDS_Iterator.hxx>
7fd59977 80
81static Standard_Boolean myFirstCompute;
82
83Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape,
3c34883c 84 const Handle(Prs3d_Drawer)& aDrawer)
7fd59977 85{
86 // WARNING: this same piece of code appears several times in Prs3d classes
3c34883c 87 Standard_Real aDeflection = aDrawer->MaximalChordialDeviation();
7fd59977 88 if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) {
89 Bnd_Box B;
3c34883c 90 BRepBndLib::Add(aShape, B, Standard_False);
7fd59977 91 if ( ! B.IsVoid() )
92 {
93 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
94 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
95 aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) *
96 aDrawer->DeviationCoefficient() * 4;
97 }
7fd59977 98 }
7fd59977 99 return aDeflection;
100}
101
102void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs,
3c34883c
O
103 const Bnd_Box& B,
104 const Handle(Prs3d_Drawer)& aDrawer)
7fd59977 105{
b8ddfc2f 106 static const Standard_Integer Indx[][3] =
107 { { 0, 0, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 0, 0, 1 },
108 { 0, 1, 1 }, { 1, 1, 1 }, { 1, 1, 0 }, { 0, 1, 0 },
109 { 0, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 }, { 1, 1, 1 },
110 { 0, 1, 1 }, { 0, 1, 0 }, { 1, 1, 0 }, { 1, 0, 0 } };
111
7fd59977 112 if ( B.IsVoid() )
113 return; // nothing to show
114
b8ddfc2f 115 Standard_Real X[2],Y[2],Z[2];
7fd59977 116 B.Get(X[0], Y[0], Z[0], X[1], Y[1], Z[1]);
7fd59977 117
7fd59977 118 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs);
119 Quantity_Color Q;
120 Aspect_TypeOfLine A;
121 Standard_Real W;
122 aDrawer->LineAspect()->Aspect()->Values(Q,A,W);
7fd59977 123
124 G->SetGroupPrimitivesAspect(new Graphic3d_AspectLine3d(Q,Aspect_TOL_DOTDASH,W));
a10fa819 125
b8ddfc2f 126 Handle(Graphic3d_ArrayOfPolylines) aPolyline = new Graphic3d_ArrayOfPolylines(16);
127 Standard_Integer i(0);
128 for(;i<16;i++)
129 aPolyline->AddVertex(X[Indx[i][0]],Y[Indx[i][1]],Z[Indx[i][2]]);
130 G->AddPrimitiveArray(aPolyline);
7fd59977 131}
3c34883c 132
7fd59977 133static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
134{
135 TColStd_ListIteratorOfListOfInteger It(LL);
136 for(;It.More();It.Next()){
137 if(It.Value()==aMode)
138 return Standard_True;}
139 return Standard_False;
140}
141
142//==================================================
143// Function:
144// Purpose :
145//==================================================
146
147AIS_Shape::
148AIS_Shape(const TopoDS_Shape& shap):
149AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
150myshape(shap),
151myCompBB(Standard_True),
152myInitAng(0.)
153{
154 myFirstCompute = Standard_True;
155 SetHilightMode(0);
156 myDrawer->SetShadingAspectGlobal(Standard_False);
157}
158
159//=======================================================================
160//function : Type
161//purpose :
162//=======================================================================
163AIS_KindOfInteractive AIS_Shape::Type() const
164{return AIS_KOI_Shape;}
165
166
167//=======================================================================
168//function : Signature
169//purpose :
170//=======================================================================
171Standard_Integer AIS_Shape::Signature() const
172{return 0;}
173
174//=======================================================================
175//function : AcceptShapeDecomposition
176//purpose :
177//=======================================================================
178Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
179{return Standard_True;}
180
181//=======================================================================
182//function : Compute
183//purpose :
184//=======================================================================
185void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3c34883c
O
186 const Handle(Prs3d_Presentation)& aPrs,
187 const Standard_Integer aMode)
7fd59977 188{
189 aPrs->Clear();
190 if(myshape.IsNull()) return;
191
192 // wire,edge,vertex -> pas de HLR + priorite display superieure
193 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
194 if(TheType>4 && TheType<8) {
195 aPrs->SetVisual(Graphic3d_TOS_ALL);
196 aPrs->SetDisplayPriority(TheType+2);
197 }
198 // Shape vide -> Assemblage vide.
199 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 200 TopoDS_Iterator anExplor (myshape);
a10fa819 201
7fd59977 202 if (!anExplor.More()) {
203 return;
204 }
205 }
a10fa819 206
81bba717 207 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
7fd59977 208 switch (aMode) {
209 case 0:{
210 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
211 catch (Standard_Failure) {
212#ifdef DEB
213 cout << "AIS_Shape::Compute() failed"<< endl;
214#endif
215 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
81bba717 216// presentation of the bounding box is calculated
7fd59977 217// Compute(aPresentationManager,aPrs,2);
218 }
219 break;
220 }
221 case 1:
222 {
223 Standard_Real prevangle ;
224 Standard_Real newangle ;
225 Standard_Real prevcoeff ;
226 Standard_Real newcoeff ;
227
228
229 if (OwnDeviationAngle(newangle,prevangle) ||
3c34883c
O
230 OwnDeviationCoefficient(newcoeff,prevcoeff))
231 if (Abs (newangle - prevangle) > Precision::Angular() ||
232 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
7fd59977 233#ifdef DEB
3c34883c
O
234 cout << "AIS_Shape : compute"<<endl;
235 cout << "newangl : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
236 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
7fd59977 237#endif
3c34883c
O
238 BRepTools::Clean(myshape);
239 }
7fd59977 240
81bba717 241 //shading only on face...
7fd59977 242 if ((Standard_Integer) myshape.ShapeType()>4)
3c34883c 243 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
7fd59977 244 else {
3c34883c
O
245 myDrawer->SetShadingAspectGlobal(Standard_False);
246 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
247 else {
248 {
249 try {
250 OCC_CATCH_SIGNALS
251 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
252 }
253 catch (Standard_Failure) {
7fd59977 254#ifdef DEB
3c34883c 255 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
7fd59977 256#endif
3c34883c
O
257 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
258 }
259 }
260 }
7fd59977 261 }
7fd59977 262 Standard_Real value = Transparency() ;
263 if( value > 0. ) {
3c34883c 264 SetTransparency( value );
7fd59977 265 }
7fd59977 266 break;
267 }
268 case 2:
269 {
81bba717 270 // bounding box
7fd59977 271 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
272 else DisplayBox(aPrs,BoundingBox(),myDrawer);
273 }
7fd59977 274 } // end switch
275 aPrs->ReCompute(); // for hidden line recomputation if necessary...
7fd59977 276}
277
278//=======================================================================
279//function : Compute
280//purpose :
281//=======================================================================
282
283void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager*/,
3c34883c
O
284 const Handle(Graphic2d_GraphicObject)& /*aGRO*/,
285 const Standard_Integer /*aMode*/)
7fd59977 286{
287}
288
289//=======================================================================
290//function : Compute
291//purpose : Hidden Line Removal
292//=======================================================================
293void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c 294 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 295{
296 Compute(aProjector,aPresentation,myshape);
297}
298
299//=======================================================================
300//function : Compute
301//purpose :
302//=======================================================================
303
304void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c
O
305 const Handle(Geom_Transformation)& TheTrsf,
306 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 307{
308 const TopLoc_Location& loc = myshape.Location();
309 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
310 Compute(aProjector,aPresentation,shbis);
311}
312
313//=======================================================================
314//function : Compute
315//purpose :
316//=======================================================================
317
318void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
3c34883c
O
319 const Handle(Prs3d_Presentation)& aPresentation,
320 const TopoDS_Shape& SH)
7fd59977 321{
322 if (SH.ShapeType() == TopAbs_COMPOUND) {
7fd59977 323 TopoDS_Iterator anExplor (SH);
a10fa819 324
7fd59977 325 if (!anExplor.More()) // Shape vide -> Assemblage vide.
326 return;
327 }
a10fa819 328
7fd59977 329 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
330 if (defdrawer->DrawHiddenLine())
331 {myDrawer->EnableDrawHiddenLine();}
332 else {myDrawer->DisableDrawHiddenLine();}
a10fa819 333
7fd59977 334 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
335 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
336
81bba717 337// coefficients for calculation
7fd59977 338
339 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
340 if (OwnHLRDeviationAngle(newangle,prevangle) || OwnHLRDeviationCoefficient(newcoeff, prevcoeff))
7fd59977 341 if (Abs (newangle - prevangle) > Precision::Angular() ||
3c34883c 342 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
7fd59977 343#ifdef DEB
344 cout << "AIS_Shape : compute"<<endl;
345 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
346 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
347#endif
348 BRepTools::Clean(SH);
349 }
350
351 {
352 try {
353 OCC_CATCH_SIGNALS
354 StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
355 }
356 catch (Standard_Failure) {
357#ifdef DEB
358 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
359#endif
360 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
361 }
362 }
363
7fd59977 364 defdrawer->SetTypeOfDeflection (prevdef);
365}
366
367//=======================================================================
368//function : SelectionType
369//purpose : gives the type according to the Index of Selection Mode
370//=======================================================================
371
372TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
373{
374 switch(aMode){
375 case 1:
376 return TopAbs_VERTEX;
377 case 2:
378 return TopAbs_EDGE;
379 case 3:
380 return TopAbs_WIRE;
381 case 4:
382 return TopAbs_FACE;
383 case 5:
384 return TopAbs_SHELL;
385 case 6:
386 return TopAbs_SOLID;
387 case 7:
388 return TopAbs_COMPSOLID;
389 case 8:
390 return TopAbs_COMPOUND;
391 case 0:
392 default:
393 return TopAbs_SHAPE;
394 }
395
396}
397//=======================================================================
398//function : SelectionType
399//purpose : gives the SelectionMode according to the Type od Decomposition...
400//=======================================================================
401Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
402{
403 switch(aType){
404 case TopAbs_VERTEX:
405 return 1;
406 case TopAbs_EDGE:
407 return 2;
408 case TopAbs_WIRE:
409 return 3;
410 case TopAbs_FACE:
411 return 4;
412 case TopAbs_SHELL:
413 return 5;
414 case TopAbs_SOLID:
415 return 6;
416 case TopAbs_COMPSOLID:
417 return 7;
418 case TopAbs_COMPOUND:
419 return 8;
420 case TopAbs_SHAPE:
421 default:
422 return 0;
423 }
424}
425
426
427//=======================================================================
428//function : ComputeSelection
429//purpose :
430//=======================================================================
431
432void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
3c34883c 433 const Standard_Integer aMode)
7fd59977 434{
435 if(myshape.IsNull()) return;
436 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 437 TopoDS_Iterator anExplor (myshape);
a10fa819 438
81bba717 439 if (!anExplor.More()) // empty Shape -> empty Assembly.
7fd59977 440 return;
441 }
442
443 static TopAbs_ShapeEnum TypOfSel;
444 TypOfSel = AIS_Shape::SelectionType(aMode);
445 TopoDS_Shape shape = myshape;
7fd59977 446 if( HasTransformation() ) {
447 Handle(Geom_Transformation) trsf = Transformation();
448 shape = shape.Located(TopLoc_Location(trsf->Trsf())*shape.Location());
449 }
7fd59977 450
81bba717 451// POP protection against crash in low layers
7fd59977 452
3c34883c 453 Standard_Real aDeflection = GetDeflection(shape, myDrawer);
7fd59977 454 Standard_Boolean autoTriangulation = Standard_True;
455 try {
456 OCC_CATCH_SIGNALS
457 StdSelect_BRepSelectionTool::Load(aSelection,
458 this,
459 shape,
460 TypOfSel,
461 aDeflection,
3c34883c 462 myDrawer->HLRAngle(),
7fd59977 463 autoTriangulation);
464 } catch ( Standard_Failure ) {
465// cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
466 if ( aMode == 0 ) {
467 Bnd_Box B = BoundingBox();
468 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
469 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
470 aSelection->Add(aSensitiveBox);
471 }
472 }
473
474 // insert the drawer in the BrepOwners for hilight...
475 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
476}
477
7fd59977 478Quantity_NameOfColor AIS_Shape::Color() const {
479Quantity_Color aColor;
480 Color(aColor);
481 return aColor.Name();
482}
483
484void AIS_Shape::Color( Quantity_Color& aColor ) const {
485 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
486}
487
488Graphic3d_NameOfMaterial AIS_Shape::Material() const {
489 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
490}
491
492Standard_Real AIS_Shape::Transparency() const {
493 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
494}
7fd59977 495
496//=======================================================================
497//function : SetColor
498//purpose :
499//=======================================================================
500
501void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
7fd59977 502{
503 SetColor(Quantity_Color(aCol));
504}
505
5cbef0fe
S
506//=======================================================================
507//function : SetColor
508//purpose :
509//=======================================================================
510
7fd59977 511void AIS_Shape::SetColor(const Quantity_Color &aCol)
7fd59977 512{
7fd59977 513 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
3c34883c 514 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
7fd59977 515 }
5cbef0fe 516 hasOwnColor = Standard_True;
7fd59977 517
7fd59977 518 myDrawer->ShadingAspect()->SetColor(aCol,myCurrentFacingModel);
5cbef0fe 519 myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
7fd59977 520 myDrawer->SetShadingAspectGlobal(Standard_False);
5cbef0fe 521
a10fa819 522
5cbef0fe 523 const Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
7fd59977 524
525 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
526 myDrawer->SetWireAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
527 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
528 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
529 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
530
81bba717 531 // fast shading modification...
7fd59977 532 if(!GetContext().IsNull()){
533 if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
534 Handle(Prs3d_Presentation) aPresentation =
535 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
536 Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup(aPresentation);
537 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
538 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
539
540 // Set aspects for presentation and for group
541 aPresentation->SetPrimitivesAspect(anAreaAspect);
542 aPresentation->SetPrimitivesAspect(aLineAspect);
543 // Check if aspect of given type is set for the group,
544 // because setting aspect for group with no already set aspect
545 // can lead to loss of presentation data
546 if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
547 aCurGroup->SetGroupPrimitivesAspect(anAreaAspect);
548 if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE))
549 aCurGroup->SetGroupPrimitivesAspect(aLineAspect);
550 }
7fd59977 551 }
552
553 LoadRecomputable(0);
a10fa819 554 LoadRecomputable(2);
7fd59977 555}
5cbef0fe 556
7fd59977 557//=======================================================================
558//function : UnsetColor
559//purpose :
560//=======================================================================
561
562void AIS_Shape::UnsetColor()
563{
5cbef0fe
S
564 if ( !HasColor() )
565 {
566 myToRecomputeModes.Clear();
567 return;
568 }
7fd59977 569 hasOwnColor = Standard_False;
570
571 Handle(Prs3d_LineAspect) NullAsp;
572 Handle(Prs3d_ShadingAspect) NullShA;
573
5cbef0fe 574 if(!HasWidth()) {
7fd59977 575 myDrawer->SetLineAspect(NullAsp);
576 myDrawer->SetWireAspect(NullAsp);
577 myDrawer->SetFreeBoundaryAspect(NullAsp);
578 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
579 myDrawer->SetSeenLineAspect(NullAsp);
580 }
5cbef0fe 581 else {
7fd59977 582 Quantity_Color CC;
583 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
584 myDrawer->LineAspect()->SetColor(CC);
585 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
586 myDrawer->WireAspect()->SetColor(CC);
587 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
588 myDrawer->FreeBoundaryAspect()->SetColor(CC);
589 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
590 myDrawer->UnFreeBoundaryAspect()->SetColor(CC);
591 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
592 myDrawer->SeenLineAspect()->SetColor(CC);
7fd59977 593 }
5cbef0fe
S
594
595 if( HasMaterial() || IsTransparent()) {
596 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
597 if( HasMaterial() ) {
598 Quantity_Color color = myDrawer->Link()->ShadingAspect()->Color(myCurrentFacingModel);
599 mat.SetColor(color);
600 }
601 if( IsTransparent() ) {
602 Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
603 mat.SetTransparency(trans);
604 }
605 myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
606 }
607 else {
7fd59977 608 myDrawer->SetShadingAspect(NullShA);
5cbef0fe
S
609 }
610
7fd59977 611 if(!GetContext().IsNull()){
612 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
613 Handle(Prs3d_Presentation) aPresentation =
614 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
615 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
616
617 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
618 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
619 Quantity_Color CC;
620 AIS_GraphicTool::GetInteriorColor(myDrawer->Link(),CC);
621 anAreaAsp->SetInteriorColor(CC);
622 aPresentation->SetPrimitivesAspect(anAreaAsp);
623 aPresentation->SetPrimitivesAspect(aLineAsp);
624 // Check if aspect of given type is set for the group,
625 // because setting aspect for group with no already set aspect
626 // can lead to loss of presentation data
627 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
628 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
629 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE))
630 aGroup->SetGroupPrimitivesAspect(aLineAsp);
7fd59977 631 }
5cbef0fe 632 }
7fd59977 633 LoadRecomputable(0);
634 LoadRecomputable(2);
7fd59977 635}
636
7fd59977 637//=======================================================================
638//function : SetWidth
639//purpose :
640//=======================================================================
641
642void AIS_Shape::SetWidth(const Standard_Real W)
643{
5cbef0fe 644 if(HasColor() || HasWidth()){
7fd59977 645 myDrawer->LineAspect()->SetWidth(W);
646 myDrawer->WireAspect()->SetWidth(W);
647 myDrawer->FreeBoundaryAspect()->SetWidth(W);
648 myDrawer->UnFreeBoundaryAspect()->SetWidth(W);
649 myDrawer->SeenLineAspect()->SetWidth(W);
650 }
651 else{
7fd59977 652 Quantity_Color CC;
653 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
654 myDrawer->SetLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
655 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
656 myDrawer->SetWireAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
657 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
658 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
659 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
660 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
661 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
662 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
7fd59977 663 }
664 myOwnWidth = W;
81bba717 665 LoadRecomputable(0); // means that it is necessary to recompute only the wireframe....
666 LoadRecomputable(2); // and the bounding box...
7fd59977 667}
668
669//=======================================================================
670//function : UnsetWidth
671//purpose :
672//=======================================================================
673
674void AIS_Shape::UnsetWidth()
675{
5cbef0fe
S
676 if(myOwnWidth == 0.0)
677 {
678 myToRecomputeModes.Clear();
679 return;
680 }
7fd59977 681 myOwnWidth=0.0;
5cbef0fe 682
7fd59977 683 Handle(Prs3d_LineAspect) NullAsp;
5cbef0fe 684
7fd59977 685 if(!HasColor()){
686 myDrawer->SetLineAspect(NullAsp);
687 myDrawer->SetWireAspect(NullAsp);
688 myDrawer->SetFreeBoundaryAspect(NullAsp);
689 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
690 myDrawer->SetSeenLineAspect(NullAsp);
691 }
692 else{
693 myDrawer->LineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line));
694 myDrawer->WireAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Wire));
695 myDrawer->FreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Free));
696 myDrawer->UnFreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_UnFree));
697 myDrawer->SeenLineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Seen));
698 }
699 LoadRecomputable(0);
700}
701
7fd59977 702//=======================================================================
703//function : SetMaterial
704//purpose :
705//=======================================================================
5cbef0fe 706
7fd59977 707void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
708{
a10fa819 709 SetMaterial(Graphic3d_MaterialAspect(aMat));
7fd59977 710}
5cbef0fe 711
7fd59977 712//=======================================================================
713//function : SetMaterial
714//purpose :
715//=======================================================================
5cbef0fe 716
7fd59977 717void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat)
718{
7fd59977 719 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
3c34883c 720 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
7fd59977 721 }
7fd59977 722 hasOwnMaterial = Standard_True;
5cbef0fe
S
723
724 myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
725 myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
726
7fd59977 727 if(!GetContext().IsNull()){
5cbef0fe 728 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
729 Handle(Prs3d_Presentation) aPresentation =
730 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
731 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
732
733 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
734 aPresentation->SetPrimitivesAspect(anAreaAsp);
735 // Check if aspect of given type is set for the group,
736 // because setting aspect for group with no already set aspect
737 // can lead to loss of presentation data
738 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
739 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
5cbef0fe 740 }
a10fa819
A
741 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
742 myToRecomputeModes.Clear();
7fd59977 743 }
7fd59977 744}
7fd59977 745//=======================================================================
746//function : UnsetMaterial
747//purpose :
748//=======================================================================
5cbef0fe 749
7fd59977 750void AIS_Shape::UnsetMaterial()
751{
7fd59977 752 if( !HasMaterial() ) return;
5cbef0fe 753
7fd59977 754 if( HasColor() || IsTransparent()) {
755 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link());
756 if( HasColor() ) {
3c34883c 757 Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
7fd59977 758 mat.SetColor(color);
759 }
760 if( IsTransparent() ) {
3c34883c 761 Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
7fd59977 762 mat.SetTransparency(trans);
763 }
764 myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
765 } else {
766 Handle(Prs3d_ShadingAspect) SA;
767 myDrawer->SetShadingAspect(SA);
768 }
769 hasOwnMaterial = Standard_False;
5cbef0fe 770 if(!GetContext().IsNull()){
7fd59977 771 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
772 Handle(Prs3d_Presentation) aPresentation =
773 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
774 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
775 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
776 aPresentation->SetPrimitivesAspect(anAreaAsp);
777 // Check if aspect of given type is set for the group,
778 // because setting aspect for group with no already set aspect
779 // can lead to loss of presentation data
780 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
781 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
7fd59977 782 }
783 }
81bba717 784 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
7fd59977 785 myToRecomputeModes.Clear();
7fd59977 786}
5cbef0fe 787
7fd59977 788//=======================================================================
789//function : SetTransparency
790//purpose :
791//=======================================================================
792
793void AIS_Shape::SetTransparency(const Standard_Real AValue)
794{
5cbef0fe
S
795 if ( !HasColor() && !HasMaterial() ) {
796 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
7fd59977 797 }
798 myDrawer->ShadingAspect()->SetTransparency(AValue,myCurrentFacingModel);
799 myTransparency = AValue;
5cbef0fe 800
7fd59977 801 if(!GetContext().IsNull()){
802 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
803 Handle(Prs3d_Presentation) aPresentation =
804 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
805 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
806 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
807 aPresentation->SetPrimitivesAspect(anAreaAsp);
808 //force highest priority for transparent objects
809 aPresentation->SetDisplayPriority(10);
810 // Check if aspect of given type is set for the group,
811 // because setting aspect for group with no already set aspect
812 // can lead to loss of presentation data
813 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
814 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
7fd59977 815 }
816 }
81bba717 817 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
5cbef0fe 818 myToRecomputeModes.Clear();
7fd59977 819}
820
821//=======================================================================
822//function : UnsetTransparency
823//purpose :
824//=======================================================================
5cbef0fe 825
7fd59977 826void AIS_Shape::UnsetTransparency()
827{
5cbef0fe 828 if( HasColor() || HasMaterial() ) {
7fd59977 829 myDrawer->ShadingAspect()->SetTransparency(0.0,myCurrentFacingModel);
830 } else {
831 Handle(Prs3d_ShadingAspect) SA;
832 myDrawer->SetShadingAspect(SA);
833 }
a10fa819 834
7fd59977 835 myTransparency = 0.0;
5cbef0fe 836
7fd59977 837 if(!GetContext().IsNull()){
7fd59977 838 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
a10fa819
A
839 Handle(Prs3d_Presentation) aPresentation =
840 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
841 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
842 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
843 aPresentation->SetPrimitivesAspect(anAreaAsp);
844 // Check if aspect of given type is set for the group,
845 // because setting aspect for group with no already set aspect
846 // can lead to loss of presentation data
847 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
848 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
849
850 aPresentation->ResetDisplayPriority();
7fd59977 851 }
852 }
81bba717 853 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
5cbef0fe 854 myToRecomputeModes.Clear();
7fd59977 855}
856
5cbef0fe
S
857//=======================================================================
858//function : LoadRecomputable
859//purpose :
860//=======================================================================
7fd59977 861
862void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
863{
5cbef0fe 864 myRecomputeEveryPrs = Standard_False;
7fd59977 865 if(!IsInList(myToRecomputeModes,TheMode))
866 myToRecomputeModes.Append(TheMode);
867}
868
7fd59977 869//=======================================================================
870//function : BoundingBox
871//purpose :
872//=======================================================================
873
874const Bnd_Box& AIS_Shape::BoundingBox()
875{
876 if (myshape.ShapeType() == TopAbs_COMPOUND) {
7fd59977 877 TopoDS_Iterator anExplor (myshape);
a10fa819 878
81bba717 879 if (!anExplor.More()) { // empty Shape -> empty Assembly.
a10fa819 880 myBB.SetVoid();
7fd59977 881 return myBB;
882 }
883 }
884
885 if(myCompBB) {
886 BRepBndLib::AddClose(myshape, myBB);
a10fa819 887 myCompBB = Standard_False;
7fd59977 888 }
889 return myBB;
890}
891
892//*****
893//***** Reset
894//=======================================================================
895//function : SetOwnDeviationCoefficient
896//purpose : resets myhasOwnDeviationCoefficient to Standard_False and
897// returns Standard_True if it change
898//=======================================================================
899
900Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
901{
902 Standard_Boolean itSet = myDrawer->IsOwnDeviationCoefficient();
903 if(itSet) myDrawer->SetDeviationCoefficient();
904 return itSet;
7fd59977 905}
906
7fd59977 907//=======================================================================
908//function : SetHLROwnDeviationCoefficient
909//purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
910// returns Standard_True if it change
911//=======================================================================
912
913Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
914{
915 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationCoefficient();
916 if(itSet) myDrawer->SetHLRDeviationCoefficient();
917 return itSet;
918
919}
920
921//=======================================================================
922//function : SetOwnDeviationAngle
923//purpose : resets myhasOwnDeviationAngle to Standard_False and
924// returns Standard_True if it change
925//=======================================================================
926
927Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
928{
929 Standard_Boolean itSet = myDrawer->IsOwnDeviationAngle();
930 if(itSet) myDrawer->SetDeviationAngle();
931 return itSet;
932
933}
934
935//=======================================================================
936//function : SetOwnHLRDeviationAngle
937//purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
938// returns Standard_True if it change
939//=======================================================================
940
941Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
942{
943 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationAngle();
944 if(itSet) myDrawer->SetHLRAngle();
945 return itSet;
946
947}
948//***** SetOwn
949//=======================================================================
950//function : SetOwnDeviationCoefficient
951//purpose :
952//=======================================================================
953
954void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
955{
956 myDrawer->SetDeviationCoefficient( aCoefficient );
957 SetToUpdate(0) ; // WireFrame
958 SetToUpdate(1) ; // Shadding
959}
960
961//=======================================================================
962//function : SetOwnHLRDeviationCoefficient
963//purpose :
964//=======================================================================
965
966void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
967{
968 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
969
970}
971
972//=======================================================================
973//function : SetOwnDeviationAngle
974//purpose :
975//=======================================================================
976
977void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
978{
979
980 myDrawer->SetDeviationAngle(anAngle );
981 SetToUpdate(0) ; // WireFrame
982}
983//=======================================================================
984//function : SetOwnDeviationAngle
985//purpose :
986//=======================================================================
987
988void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
989{
990 Standard_Real OutAngl,OutDefl;
991 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
992 SetOwnDeviationAngle(anAngle) ;
7fd59977 993 SetOwnDeviationCoefficient(OutDefl) ;
994 myInitAng = anAngle;
995 SetToUpdate(0);
996 SetToUpdate(1);
997}
998
999//=======================================================================
1000//function : UserAngle
1001//purpose :
1002//=======================================================================
1003
1004Standard_Real AIS_Shape::UserAngle() const
1005{
1006 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1007}
1008
1009
1010//=======================================================================
1011//function : SetHLRAngleAndDeviation
1012//purpose :
1013//=======================================================================
1014
1015void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1016{
1017 Standard_Real OutAngl,OutDefl;
1018 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1019 SetOwnHLRDeviationAngle( OutAngl );
1020 SetOwnHLRDeviationCoefficient(OutDefl);
1021
1022}
1023//=======================================================================
1024//function : SetOwnHLRDeviationAngle
1025//purpose :
1026//=======================================================================
1027
1028void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1029{
1030 myDrawer->SetHLRAngle( anAngle );
1031}
1032
1033//***** GetOwn
1034//=======================================================================
1035//function : OwnDeviationCoefficient
1036//purpose :
1037//=======================================================================
1038
1039Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1040 Standard_Real & aPreviousCoefficient ) const
7fd59977 1041{
1042 aCoefficient = myDrawer->DeviationCoefficient();
1043 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1044 return myDrawer->IsOwnDeviationCoefficient() ;
1045}
1046
1047//=======================================================================
1048//function : OwnHLRDeviationCoefficient
1049//purpose :
1050//=======================================================================
1051
1052Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
3c34883c 1053 Standard_Real & aPreviousCoefficient ) const
7fd59977 1054{
1055 aCoefficient = myDrawer->HLRDeviationCoefficient();
1056 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1057 return myDrawer->IsOwnHLRDeviationCoefficient();
1058
1059}
1060
1061//=======================================================================
1062//function : OwnDeviationAngle
1063//purpose :
1064//=======================================================================
1065
1066Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
3c34883c 1067 Standard_Real & aPreviousAngle ) const
7fd59977 1068{
1069 anAngle = myDrawer->DeviationAngle();
1070 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1071 return myDrawer->IsOwnDeviationAngle();
1072}
1073
1074//=======================================================================
1075//function : OwnHLRDeviationAngle
1076//purpose :
1077//=======================================================================
1078
1079Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
3c34883c 1080 Standard_Real & aPreviousAngle ) const
7fd59977 1081{
1082 anAngle = myDrawer->HLRAngle();
1083 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1084 return myDrawer->IsOwnHLRDeviationAngle();
7fd59977 1085}