]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_AISShape.cxx
Salome HOME
Synchronize adm files
[modules/geom.git] / src / OBJECT / GEOM_AISShape.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  GEOM OBJECT : interactive object for Geometry entities visualization
24 //  File   : GEOM_AISShape.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27
28 /*!
29   \class GEOM_AISShape GEOM_AISShape.hxx
30   \brief ....
31 */
32
33 #include "GEOM_AISShape.ixx"
34 #include "SALOME_InteractiveObject.hxx"
35 #include "GEOM_AISVector.hxx"
36
37 // Open CASCADE Includes
38 #include <AIS_Drawer.hxx>
39 #include <AIS_InteractiveContext.hxx>
40
41 #include <BRep_Tool.hxx>
42
43 #include <GCPnts_AbscissaPoint.hxx>
44 #include <GeomAdaptor_Curve.hxx>
45 #include <gp_Pnt.hxx>
46 #include <gp_Dir.hxx>
47 #include <gp_Vec.hxx>
48 #include <Graphic3d_AspectFillArea3d.hxx>
49 #include <Graphic3d_AspectLine3d.hxx>
50 #include <Graphic3d_AspectMarker3d.hxx>
51 #include <Graphic3d_AspectText3d.hxx>
52
53 #include <Prs3d_ShadingAspect.hxx>
54 #include <Prs3d_Arrow.hxx>
55 #include <Prs3d_IsoAspect.hxx>
56
57 #include <SelectBasics_SensitiveEntity.hxx>
58 #include <SelectMgr_EntityOwner.hxx>
59 #include <StdSelect_BRepOwner.hxx>
60 #include <SelectMgr_IndexedMapOfOwner.hxx>
61 #include <SelectMgr_Selection.hxx>
62 #include <StdSelect_DisplayMode.hxx>
63 #include <StdPrs_ShadedShape.hxx>
64 #include <StdPrs_WFDeflectionShape.hxx>
65
66 #include <TColStd_IndexedMapOfInteger.hxx>
67 #include <TColStd_ListIteratorOfListOfInteger.hxx>
68 #include <TColStd_ListOfInteger.hxx>
69 #include <TopExp.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <TopTools_IndexedMapOfShape.hxx>
72 #include <TopExp.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <TopoDS.hxx>
75 #include <TopoDS_Edge.hxx>
76 #include <TopoDS_Shape.hxx>
77 #include <TopoDS_Vertex.hxx>
78
79 #include <TColStd_SequenceOfInteger.hxx>
80
81 #include <V3d_View.hxx>
82
83 #include <SalomeApp_Tools.h>
84
85 #include <SUIT_Session.h>
86 #include <SUIT_ResourceMgr.h>
87
88 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
89 Quantity_Color GEOM_AISShape::myTopLevelColor;
90
91
92 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
93                              const Handle(AIS_InteractiveContext)& theIC,
94                              SelectMgr_IndexedMapOfOwner& theMap )
95 {
96   if ( theObj.IsNull() || theIC.IsNull() )
97     return;
98
99   TColStd_ListOfInteger modes;
100   theIC->ActivatedModes( theObj, modes );
101
102   TColStd_ListIteratorOfListOfInteger itr( modes );
103   for (; itr.More(); itr.Next() ) {
104     int m = itr.Value();
105     if ( !theObj->HasSelection( m ) )
106       continue;
107
108     Handle(SelectMgr_Selection) sel = theObj->Selection( m );
109
110     for ( sel->Init(); sel->More(); sel->Next() ) {
111       Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
112       if ( entity.IsNull() )
113         continue;
114
115       Handle(SelectMgr_EntityOwner) owner =
116         Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
117       if ( !owner.IsNull() )
118         theMap.Add( owner );
119     }
120   }
121 }
122
123 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
124                              const TopoDS_Shape& aMainShape,
125                              const SelectMgr_IndexedMapOfOwner& anAllMap, 
126                              SelectMgr_IndexedMapOfOwner& aToHiliteMap )
127 {
128   TopTools_IndexedMapOfShape aMapOfShapes;
129   TopExp::MapShapes(aMainShape, aMapOfShapes);
130
131   for  ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
132     Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
133     if ( anOwner.IsNull() || !anOwner->HasShape() )
134       continue;
135
136     const TopoDS_Shape& aSubShape = anOwner->Shape();
137     Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
138     if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
139       continue;
140     
141     if ( !aToHiliteMap.Contains( anOwner ) )
142       aToHiliteMap.Add( anOwner );
143   }
144 }
145
146 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
147                              const Standard_CString aName)
148   : SALOME_AISShape(shape),
149     myName(aName),
150     myDisplayVectors(false),
151     myFieldDataType(GEOM::FDT_Double),
152     myFieldDimension(0),
153     myFieldStepRangeMin(0),
154     myFieldStepRangeMax(0)
155 {
156   //rnv: Commented to avoid bug with local selection 
157   //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
158
159   myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
160   myPrevDisplayMode = 0;
161
162   myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
163
164   myTopLevel = Standard_False;
165   Graphic3d_MaterialAspect aMatAspect;
166   if ( !HasMaterial() ) {
167         aMatAspect.SetAmbient( 0.5 );
168         aMatAspect.SetDiffuse( 0.5 );
169         aMatAspect.SetEmissive( 0.5 );
170         aMatAspect.SetShininess(0.5 );
171         aMatAspect.SetSpecular( 0.5 );
172         
173         myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
174         myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
175   }
176 }
177
178 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
179   SetOwner( io );
180 }
181
182 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
183   Handle(SALOME_InteractiveObject) IO;
184   if ( !GetOwner().IsNull() )
185     IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
186   return IO;
187 }
188
189 Standard_Boolean GEOM_AISShape::hasIO(){
190   return !getIO().IsNull();
191 }
192
193 void GEOM_AISShape::setName(const Standard_CString aName)
194 {
195   myName = aName;
196
197   Handle(SALOME_InteractiveObject) IO = getIO();
198   if ( !IO.IsNull() )
199     IO->setName(aName);
200 }
201
202 Standard_CString GEOM_AISShape::getName(){
203   return myName.ToCString();
204 }
205
206 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
207                             const Handle(Prs3d_Presentation)& aPrs,
208                             const Standard_Integer aMode)
209 {  
210   if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
211
212   Handle(AIS_InteractiveContext) anIC = GetContext();
213
214   bool anIsField = !myFieldStepData.isEmpty();
215   bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
216   bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
217
218   //   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
219   bool isTopLev = isTopLevel() && switchTopLevel();
220   switch (aMode) {
221     case 0://StdSelect_DM_Wireframe: 
222     case CustomHighlight:
223     {
224       if(isTopLev) {
225               SetColor(topLevelColor());
226               Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
227               anAspect->SetColor( topLevelColor() );
228               Attributes()->SetWireAspect( anAspect );
229       }
230       if( !isTopLev && anIsColorField && myFieldDimension == 1 )
231         drawField( aPrs, false, aMode == CustomHighlight );
232       else
233         StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);      
234       break;
235     }
236     case 1://StdSelect_DM_Shading:
237     {
238       shadingMode(aPresentationManager, aPrs, aMode);
239       break;
240     }
241     case 2: { //ShadingWithEdges
242       //Shaded faces
243       shadingMode(aPresentationManager, aPrs, AIS_Shaded);
244       myDrawer->SetFaceBoundaryDraw( Standard_True );
245       Handle(Prs3d_LineAspect) aBoundaryAspect =
246         new Prs3d_LineAspect ( myEdgesInShadingColor, Aspect_TOL_SOLID, myOwnWidth );
247       myDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
248       break;
249     }
250     case 3: //StdSelect_DM_HLR:
251     {
252       if(!isTopLev)
253               AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
254       else 
255               shadingMode(aPresentationManager, aPrs, AIS_Shaded);
256       break;
257     }
258   }
259   if (isShowVectors())
260   {
261     const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
262     TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
263     for ( ; Exp.More(); Exp.Next() ) {
264       TopoDS_Vertex aV1, aV2;
265       TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
266       if ( !isVector )
267         // draw curve direction (issue 0021087)
268         anEdgeE.Orientation( TopAbs_FORWARD );
269
270       if ( anEdgeE.IsNull() ) continue;
271
272       TopExp::Vertices(anEdgeE, aV1, aV2);
273       gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
274       gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
275
276       double fp,lp;
277       gp_Vec aDirVec;
278       Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
279
280       if ( C.IsNull() ) continue;
281
282       if ( anEdgeE.Orientation() == TopAbs_FORWARD )
283         C->D1(lp, aP2, aDirVec);
284       else {
285         C->D1(fp, aP1, aDirVec);
286         aP2 = aP1;
287       }
288
289       GeomAdaptor_Curve aAdC;
290       aAdC.Load(C, fp, lp);
291       Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); 
292      
293       if (aDist > gp::Resolution()) {
294         gp_Dir aDir;
295         if ( anEdgeE.Orientation() == TopAbs_FORWARD )
296           aDir = aDirVec;
297         else
298           aDir = -aDirVec;
299
300         Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
301       }
302     }
303   }
304
305   // draw color field on vertices
306   if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
307     drawField( aPrs );
308
309   // draw text field
310   if( anIsTextField )
311     drawField( aPrs, true );
312
313   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
314 }
315
316 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
317 {
318   myShadingColor = aCol;
319 }
320
321 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
322 {
323   myEdgesInShadingColor = aCol;
324 }
325
326 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, 
327                                        const Standard_Boolean aHighlight )
328 {
329   Handle(AIS_InteractiveObject) anObj = this;
330   Handle(AIS_InteractiveContext) anIC = GetContext();
331   if ( anIC.IsNull() || !anIC->HasOpenedContext() ) 
332     return;
333
334   Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
335   anIC->SetAutomaticHilight( false );
336
337   anIC->ClearSelected( false );
338
339   if ( aHighlight ) {
340     SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
341
342     // Get entity owners for all activated selection modes
343     getEntityOwners( anObj, anIC, anAllMap );
344
345     // Convert <aIndexMap> into the map of owners to highlight/unhighlight
346     indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
347
348
349     for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
350       anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
351   }
352
353   anIC->SetAutomaticHilight( isAutoHilight );
354   anIC->HilightSelected( false );
355 }
356
357 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
358 {
359   myDisplayVectors = isDisplayed;
360 }
361
362 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
363                                 const Handle(Prs3d_Presentation)& aPrs,
364                                 const Standard_Integer aMode)
365 {
366   myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
367
368   Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
369   aMatAspect.SetTransparency(Transparency());
370   Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
371   Graphic3d_MaterialAspect currentBackMaterial  = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
372   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
373   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial  );
374
375   if( isTopLevel() && switchTopLevel() )
376     myDrawer->ShadingAspect()->SetColor( topLevelColor() );
377   else { 
378     if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
379       myDrawer->ShadingAspect()->SetColor(myShadingColor);
380     else
381       myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
382   }
383
384   bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
385   if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
386   {
387     drawField( aPrs );
388   }
389   else
390   {
391     // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
392     //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
393     AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
394   }
395 }
396
397 Standard_Boolean GEOM_AISShape::isTopLevel() {
398   return myTopLevel;
399 }
400
401 void GEOM_AISShape::setTopLevel(Standard_Boolean f) {
402   if(f) {
403     if(f != myTopLevel)
404       myPrevDisplayMode = DisplayMode();
405     Standard_Integer dm;
406     switch(topLevelDisplayMode()) {
407       case TopKeepCurrent : dm = myPrevDisplayMode; break;
408       case TopWireFrame : dm = AIS_WireFrame; break;     
409       case TopShadingWithEdges : dm = ShadingWithEdges; break;
410       default : dm = AIS_Shaded; break;
411     }
412     SetDisplayMode(dm);
413   } else {
414     if(f != myTopLevel)
415       SetDisplayMode(myPrevDisplayMode);
416   }
417   myTopLevel = f;
418 }
419
420 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode) {
421   myPrevDisplayMode = mode;
422 }
423
424 Quantity_Color GEOM_AISShape::topLevelColor() {
425   return myTopLevelColor;
426 }
427
428 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c) {
429   myTopLevelColor = c;
430 }
431
432 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode() {
433   return myTopLevelDm;
434 }
435 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm) {
436   myTopLevelDm = dm;
437 }
438
439 Standard_Boolean GEOM_AISShape::switchTopLevel() {
440         return myTopLevelDm != TopShowAdditionalWActor;
441 }
442
443 Standard_Boolean GEOM_AISShape::toActivate() {
444         return Standard_True;
445 }
446
447 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
448                                       const int theFieldDimension,
449                                       const QList<QVariant>& theFieldStepData,
450                                       const TCollection_AsciiString& theFieldStepName,
451                                       const double theFieldStepRangeMin,
452                                       const double theFieldStepRangeMax )
453 {
454   myFieldDataType = theFieldDataType;
455   myFieldDimension = theFieldDimension;
456   myFieldStepData = theFieldStepData;
457   myFieldStepName = theFieldStepName;
458   myFieldStepRangeMin = theFieldStepRangeMin;
459   myFieldStepRangeMax = theFieldStepRangeMax;
460 }
461
462 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
463                                       int& theFieldDimension,
464                                       QList<QVariant>& theFieldStepData,
465                                       TCollection_AsciiString& theFieldStepName,
466                                       double& theFieldStepRangeMin,
467                                       double& theFieldStepRangeMax ) const
468 {
469   theFieldDataType = myFieldDataType;
470   theFieldDimension = myFieldDimension;
471   theFieldStepData = myFieldStepData;
472   theFieldStepName = myFieldStepName;
473   theFieldStepRangeMin = myFieldStepRangeMin;
474   theFieldStepRangeMax = myFieldStepRangeMax;
475 }
476
477 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
478                                const bool theIsString,
479                                const bool theIsHighlight )
480 {
481   if( myFieldStepData.isEmpty() )
482     return;
483
484   QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
485
486   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
487   switch( myFieldDimension )
488   {
489     case 0: aShapeType = TopAbs_VERTEX; break;
490     case 1: aShapeType = TopAbs_EDGE; break;
491     case 2: aShapeType = TopAbs_FACE; break;
492     case 3: aShapeType = TopAbs_SOLID; break;
493     case -1: aShapeType = TopAbs_VERTEX; break;
494   }
495
496   TopTools_IndexedMapOfShape aShapeMap;
497   TopExp::MapShapes( myshape, aShapeMap );
498
499   TColStd_IndexedMapOfInteger anIndexMap;
500
501   TopExp_Explorer anExp;
502   for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
503   {
504     TopoDS_Shape aSubShape = anExp.Current();
505     if( !aSubShape.IsNull() )
506     {
507       Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
508       if( anIndexMap.Contains( aSubShapeIndex ) )
509         continue;
510
511       anIndexMap.Add( aSubShapeIndex );
512
513       Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
514
515       QColor aQColor;
516       QString aString;
517       if( aFieldStepDataIter.hasNext() )
518       {
519         const QVariant& aVariant = aFieldStepDataIter.next();
520         if( theIsString )
521           aString = aVariant.toString();
522         else
523           aQColor = aVariant.value<QColor>();
524       }
525       else
526         break;
527
528       if( theIsString )
529       {
530         gp_Pnt aCenter;
531         if( computeMassCenter( aSubShape, aCenter ) )
532         {
533           Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
534
535           Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
536           anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
537           aGroup->SetPrimitivesAspect( anAspectText3d );
538
539           aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
540         }
541       }
542       else
543       {
544         Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
545         if( myFieldDimension == 0 )
546         {
547           TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
548           if( !aVertexShape.IsNull() )
549           {
550             gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
551
552             Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
553             anAspectMarker3d->SetColor( aColor );
554             anAspectMarker3d->SetType( Aspect_TOM_POINT );
555             anAspectMarker3d->SetScale( 10.0 );
556             aGroup->SetPrimitivesAspect( anAspectMarker3d );
557
558             Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
559             anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
560
561             aGroup->AddPrimitiveArray( anArray );
562           }
563         }
564         else if( myFieldDimension == 1 )
565         {
566           myDrawer->WireAspect()->SetColor( aColor );
567           if( theIsHighlight )
568             myDrawer->WireAspect()->SetWidth( myOwnWidth );
569           else
570             myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
571           StdPrs_WFDeflectionShape::Add( thePrs, aSubShape, myDrawer );
572         }
573         else if( myFieldDimension == 2 ||
574                  myFieldDimension == 3 ||
575                  myFieldDimension == -1 )
576         {
577           myDrawer->ShadingAspect()->SetColor( aColor );
578           StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
579         }
580       }
581     }
582   }
583 }
584
585 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
586                                                    gp_Pnt& theCenter )
587 {
588   Standard_Real aX = 0, aY = 0, aZ = 0;
589   Standard_Integer aNbPoints = 0;
590
591   TopExp_Explorer anExp;
592   for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
593   {
594     TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
595     if( !aVertex.IsNull() )
596     {
597       gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
598       aX += aPnt.X();
599       aY += aPnt.Y();
600       aZ += aPnt.Z();
601       aNbPoints++;
602     }
603   }
604
605   if( aNbPoints == 0 )
606     return Standard_False;
607
608   theCenter.SetCoord( aX / (Standard_Real)aNbPoints,
609                       aY / (Standard_Real)aNbPoints,
610                       aZ / (Standard_Real)aNbPoints );
611   return Standard_True;
612 }