Salome HOME
f75b7a6b7a0bfbeff1d0b86834be9c862071656e
[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   // AKL: use old behavior to avoid keeping object's wireframe
220   //      if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos') 
221   //      calling popup menu over(!) the shape in OCC viewer.
222   anIC->SetToHilightSelected( false );
223
224   bool anIsField = !myFieldStepData.isEmpty();
225   bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
226   bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
227
228 #if OCC_VERSION_LARGE > 0x06070200
229   if (isShowVertices())
230     myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
231 #endif
232
233   //   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
234   bool isTopLev = isTopLevel() && switchTopLevel();
235   switch (aMode) {
236     case 0://StdSelect_DM_Wireframe: 
237     case CustomHighlight:
238     {
239       if(isTopLev) {
240               SetColor(topLevelColor());
241               Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
242               anAspect->SetColor( topLevelColor() );
243               Attributes()->SetWireAspect( anAspect );
244       }
245       if( !isTopLev && anIsColorField && myFieldDimension == 1 )
246         drawField( aPrs, false, aMode == CustomHighlight );
247       else
248         StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);      
249       break;
250     }
251     case 1://StdSelect_DM_Shading:
252     {
253       shadingMode(aPresentationManager, aPrs, aMode);
254       break;
255     }
256     case 2: { //ShadingWithEdges
257       //Shaded faces
258       shadingMode(aPresentationManager, aPrs, AIS_Shaded);
259       myDrawer->SetFaceBoundaryDraw( Standard_True );
260       Handle(Prs3d_LineAspect) aBoundaryAspect =
261         new Prs3d_LineAspect ( myEdgesInShadingColor, Aspect_TOL_SOLID, myOwnWidth );
262       myDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
263       break;
264     }
265     case 3: //StdSelect_DM_HLR:
266     {
267       if(!isTopLev)
268               AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
269       else 
270               shadingMode(aPresentationManager, aPrs, AIS_Shaded);
271       break;
272     }
273   }
274   if (isShowVectors())
275   {
276     const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
277     TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
278     for ( ; Exp.More(); Exp.Next() ) {
279       TopoDS_Vertex aV1, aV2;
280       TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
281       if ( !isVector )
282         // draw curve direction (issue 0021087)
283         anEdgeE.Orientation( TopAbs_FORWARD );
284
285       if ( anEdgeE.IsNull() ) continue;
286
287       TopExp::Vertices(anEdgeE, aV1, aV2);
288       gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
289       gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
290
291       double fp,lp;
292       gp_Vec aDirVec;
293       Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
294
295       if ( C.IsNull() ) continue;
296
297       if ( anEdgeE.Orientation() == TopAbs_FORWARD )
298         C->D1(lp, aP2, aDirVec);
299       else {
300         C->D1(fp, aP1, aDirVec);
301         aP2 = aP1;
302       }
303
304       GeomAdaptor_Curve aAdC;
305       aAdC.Load(C, fp, lp);
306       Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); 
307      
308       if (aDist > gp::Resolution()) {
309         gp_Dir aDir;
310         if ( anEdgeE.Orientation() == TopAbs_FORWARD )
311           aDir = aDirVec;
312         else
313           aDir = -aDirVec;
314
315         Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
316       }
317     }
318   }
319
320   // draw color field on vertices
321   if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
322     drawField( aPrs );
323
324   // draw text field
325   if( anIsTextField )
326     drawField( aPrs, true );
327
328   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
329 }
330
331 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
332 {
333   myShadingColor = aCol;
334 }
335
336 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
337 {
338   myEdgesInShadingColor = aCol;
339 }
340
341 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, 
342                                        const Standard_Boolean aHighlight )
343 {
344   Handle(AIS_InteractiveObject) anObj = this;
345   Handle(AIS_InteractiveContext) anIC = GetContext();
346   if ( anIC.IsNull() || !anIC->HasOpenedContext() ) 
347     return;
348
349   Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
350   anIC->SetAutomaticHilight( false );
351
352   anIC->ClearSelected( false );
353
354   if ( aHighlight ) {
355     SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
356
357     // Get entity owners for all activated selection modes
358     getEntityOwners( anObj, anIC, anAllMap );
359
360     // Convert <aIndexMap> into the map of owners to highlight/unhighlight
361     indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
362
363
364     for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
365       anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
366   }
367
368   anIC->SetAutomaticHilight( isAutoHilight );
369   anIC->HilightSelected( false );
370 }
371
372 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
373 {
374   myDisplayVectors = isDisplayed;
375 }
376
377 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
378 {
379   myDisplayVertices = isDisplayed;
380 }
381
382 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
383                                 const Handle(Prs3d_Presentation)& aPrs,
384                                 const Standard_Integer aMode)
385 {
386   myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
387
388   Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
389   aMatAspect.SetTransparency(Transparency());
390   Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
391   Graphic3d_MaterialAspect currentBackMaterial  = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
392   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
393   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial  );
394
395   if( isTopLevel() && switchTopLevel() )
396     myDrawer->ShadingAspect()->SetColor( topLevelColor() );
397   else { 
398     if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
399       myDrawer->ShadingAspect()->SetColor(myShadingColor);
400     else
401       myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
402   }
403
404   bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
405   if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
406   {
407     drawField( aPrs );
408   }
409   else
410   {
411     // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
412     //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
413     AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
414   }
415 }
416
417 Standard_Boolean GEOM_AISShape::isTopLevel() {
418   return myTopLevel;
419 }
420
421 void GEOM_AISShape::setTopLevel(Standard_Boolean f) {
422   if(f) {
423     if(f != myTopLevel)
424       myPrevDisplayMode = DisplayMode();
425     Standard_Integer dm;
426     switch(topLevelDisplayMode()) {
427       case TopKeepCurrent : dm = myPrevDisplayMode; break;
428       case TopWireFrame : dm = AIS_WireFrame; break;     
429       case TopShadingWithEdges : dm = ShadingWithEdges; break;
430       default : dm = AIS_Shaded; break;
431     }
432     SetDisplayMode(dm);
433   } else {
434     if(f != myTopLevel)
435       SetDisplayMode(myPrevDisplayMode);
436   }
437   myTopLevel = f;
438 }
439
440 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode) {
441   myPrevDisplayMode = mode;
442 }
443
444 Quantity_Color GEOM_AISShape::topLevelColor() {
445   return myTopLevelColor;
446 }
447
448 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c) {
449   myTopLevelColor = c;
450 }
451
452 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode() {
453   return myTopLevelDm;
454 }
455 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm) {
456   myTopLevelDm = dm;
457 }
458
459 Standard_Boolean GEOM_AISShape::switchTopLevel() {
460   return myTopLevelDm != TopShowAdditionalWActor;
461 }
462
463 Standard_Boolean GEOM_AISShape::toActivate() {
464   return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
465 }
466
467 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
468                                       const int theFieldDimension,
469                                       const QList<QVariant>& theFieldStepData,
470                                       const TCollection_AsciiString& theFieldStepName,
471                                       const double theFieldStepRangeMin,
472                                       const double theFieldStepRangeMax )
473 {
474   myFieldDataType = theFieldDataType;
475   myFieldDimension = theFieldDimension;
476   myFieldStepData = theFieldStepData;
477   myFieldStepName = theFieldStepName;
478   myFieldStepRangeMin = theFieldStepRangeMin;
479   myFieldStepRangeMax = theFieldStepRangeMax;
480 }
481
482 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
483                                       int& theFieldDimension,
484                                       QList<QVariant>& theFieldStepData,
485                                       TCollection_AsciiString& theFieldStepName,
486                                       double& theFieldStepRangeMin,
487                                       double& theFieldStepRangeMax ) const
488 {
489   theFieldDataType = myFieldDataType;
490   theFieldDimension = myFieldDimension;
491   theFieldStepData = myFieldStepData;
492   theFieldStepName = myFieldStepName;
493   theFieldStepRangeMin = myFieldStepRangeMin;
494   theFieldStepRangeMax = myFieldStepRangeMax;
495 }
496
497 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
498                                const bool theIsString,
499                                const bool theIsHighlight )
500 {
501   if( myFieldStepData.isEmpty() )
502     return;
503
504   QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
505
506   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
507   switch( myFieldDimension )
508   {
509     case 0: aShapeType = TopAbs_VERTEX; break;
510     case 1: aShapeType = TopAbs_EDGE; break;
511     case 2: aShapeType = TopAbs_FACE; break;
512     case 3: aShapeType = TopAbs_SOLID; break;
513     case -1: aShapeType = TopAbs_VERTEX; break;
514   }
515
516   TopTools_IndexedMapOfShape aShapeMap;
517   TopExp::MapShapes( myshape, aShapeMap );
518
519   TColStd_IndexedMapOfInteger anIndexMap;
520
521   TopExp_Explorer anExp;
522   for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
523   {
524     TopoDS_Shape aSubShape = anExp.Current();
525     if( !aSubShape.IsNull() )
526     {
527       Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
528       if( anIndexMap.Contains( aSubShapeIndex ) )
529         continue;
530
531       anIndexMap.Add( aSubShapeIndex );
532
533       Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
534
535       QColor aQColor;
536       QString aString;
537       if( aFieldStepDataIter.hasNext() )
538       {
539         const QVariant& aVariant = aFieldStepDataIter.next();
540         if( theIsString )
541           aString = aVariant.toString();
542         else
543           aQColor = aVariant.value<QColor>();
544       }
545       else
546         break;
547
548       if( theIsString )
549       {
550         gp_Pnt aCenter;
551         if( computeMassCenter( aSubShape, aCenter ) )
552         {
553           Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
554
555           Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
556           anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
557           aGroup->SetPrimitivesAspect( anAspectText3d );
558
559           aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
560         }
561       }
562       else
563       {
564         Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
565         if( myFieldDimension == 0 )
566         {
567           TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
568           if( !aVertexShape.IsNull() )
569           {
570             gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
571
572             Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
573             anAspectMarker3d->SetColor( aColor );
574             anAspectMarker3d->SetType( Aspect_TOM_POINT );
575             anAspectMarker3d->SetScale( 10.0 );
576             aGroup->SetPrimitivesAspect( anAspectMarker3d );
577
578             Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
579             anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
580
581             aGroup->AddPrimitiveArray( anArray );
582           }
583         }
584         else if( myFieldDimension == 1 )
585         {
586           myDrawer->WireAspect()->SetColor( aColor );
587           if( theIsHighlight )
588             myDrawer->WireAspect()->SetWidth( myOwnWidth );
589           else
590             myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
591           StdPrs_WFDeflectionShape::Add( thePrs, aSubShape, myDrawer );
592         }
593         else if( myFieldDimension == 2 ||
594                  myFieldDimension == 3 ||
595                  myFieldDimension == -1 )
596         {
597           myDrawer->ShadingAspect()->SetColor( aColor );
598           StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
599         }
600       }
601     }
602   }
603 }
604
605 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
606                                                    gp_Pnt& theCenter )
607 {
608   Standard_Real aX = 0, aY = 0, aZ = 0;
609   Standard_Integer aNbPoints = 0;
610
611   TopExp_Explorer anExp;
612   for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
613   {
614     TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
615     if( !aVertex.IsNull() )
616     {
617       gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
618       aX += aPnt.X();
619       aY += aPnt.Y();
620       aZ += aPnt.Z();
621       aNbPoints++;
622     }
623   }
624
625   if( aNbPoints == 0 )
626     return Standard_False;
627
628   theCenter.SetCoord( aX / (Standard_Real)aNbPoints,
629                       aY / (Standard_Real)aNbPoints,
630                       aZ / (Standard_Real)aNbPoints );
631   return Standard_True;
632 }