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