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