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