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