Salome HOME
Merge V9_dev branch into master
[modules/geom.git] / src / OBJECT / GEOM_AISShape.cxx
1 // Copyright (C) 2007-2016  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 <GEOMUtils.hxx>
32
33 // Open CASCADE Includes
34 #include <AIS_InteractiveContext.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <Graphic3d_ArrayOfPoints.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_AspectText3d.hxx>
44 #include <Prs3d.hxx>
45 #include <Prs3d_Arrow.hxx>
46 #include <Prs3d_IsoAspect.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <SelectBasics_SensitiveEntity.hxx>
49 #include <SelectMgr_EntityOwner.hxx>
50 #include <SelectMgr_IndexedMapOfOwner.hxx>
51 #include <SelectMgr_Selection.hxx>
52 #include <StdPrs_ShadedShape.hxx>
53 #include <StdPrs_ToolTriangulatedShape.hxx>
54 #include <StdSelect_BRepOwner.hxx>
55 #include <StdSelect_DisplayMode.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TopExp.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <TopoDS.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <V3d_View.hxx>
67 #include <gp_Dir.hxx>
68 #include <gp_Pnt.hxx>
69 #include <gp_Vec.hxx>
70 #include <Prs3d_VertexDrawMode.hxx>
71 #include <StdPrs_WFShape.hxx>
72
73 #include <SalomeApp_Tools.h>
74 #include <SUIT_Session.h>
75 #include <SUIT_ResourceMgr.h>
76
77 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
78
79 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
80 Quantity_Color GEOM_AISShape::myTopLevelColor;
81
82
83 static void getEntityOwners( const Handle(AIS_InteractiveObject)&  theObj,
84                              const Handle(AIS_InteractiveContext)& theIC,
85                              SelectMgr_IndexedMapOfOwner&          theMap )
86 {
87   if ( theObj.IsNull() || theIC.IsNull() )
88     return;
89
90   TColStd_ListOfInteger modes;
91   theIC->ActivatedModes( theObj, modes );
92
93   TColStd_ListIteratorOfListOfInteger itr( modes );
94   for (; itr.More(); itr.Next() ) {
95     int m = itr.Value();
96     if ( !theObj->HasSelection( m ) )
97       continue;
98
99     Handle(SelectMgr_Selection) sel = theObj->Selection( m );
100
101     for ( sel->Init(); sel->More(); sel->Next() ) {
102       const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
103       if( aHSenEntity.IsNull() )
104         continue;
105
106       Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
107       if ( entity.IsNull() )
108         continue;
109       Handle(SelectMgr_EntityOwner) owner =
110         Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
111       if ( !owner.IsNull() )
112         theMap.Add( owner );
113     }
114   }
115 }
116
117 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
118                              const TopoDS_Shape&                aMainShape,
119                              const SelectMgr_IndexedMapOfOwner& anAllMap,
120                              SelectMgr_IndexedMapOfOwner&       aToHiliteMap )
121 {
122   TopTools_IndexedMapOfShape aMapOfShapes;
123   TopExp::MapShapes(aMainShape, aMapOfShapes);
124
125   for  ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
126     Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
127     if ( anOwner.IsNull() || !anOwner->HasShape() )
128       continue;
129
130     const TopoDS_Shape& aSubShape = anOwner->Shape();
131     Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
132     if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
133       continue;
134
135     if ( !aToHiliteMap.Contains( anOwner ) )
136       aToHiliteMap.Add( anOwner );
137   }
138 }
139
140 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape&    shape,
141                              const Standard_CString aName)
142   : SALOME_AISShape(shape),
143     myName(aName),
144     myDisplayVectors(false),
145     myDisplayVertices(false),
146     myFieldDataType(GEOM::FDT_Double),
147     myFieldDimension(0),
148     myFieldStepRangeMin(0),
149     myFieldStepRangeMax(0)
150 {
151   //rnv: Commented to avoid bug with local selection
152   //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
153
154   myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
155   myPrevDisplayMode = 0;
156
157   myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
158
159   myTopLevel = Standard_False;
160   Graphic3d_MaterialAspect aMatAspect;
161   if ( !HasMaterial() ) {
162     aMatAspect.SetAmbient( 0.5 );
163     aMatAspect.SetDiffuse( 0.5 );
164     aMatAspect.SetEmissive( 0.5 );
165     aMatAspect.SetShininess(0.5 );
166     aMatAspect.SetSpecular( 0.5 );
167
168     myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
169     myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
170   }
171 }
172
173 GEOM_AISShape::~GEOM_AISShape()
174 {
175 }
176
177 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
178 {
179   SetOwner( io );
180 }
181
182 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
183 {
184   Handle(SALOME_InteractiveObject) IO;
185   if ( !GetOwner().IsNull() )
186     IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
187   return IO;
188 }
189
190 Standard_Boolean GEOM_AISShape::hasIO()
191 {
192   return !getIO().IsNull();
193 }
194
195 void GEOM_AISShape::setName(const Standard_CString aName)
196 {
197   myName = aName;
198
199   Handle(SALOME_InteractiveObject) IO = getIO();
200   if ( !IO.IsNull() )
201     IO->setName(aName);
202 }
203
204 Standard_CString GEOM_AISShape::getName()
205 {
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 (isShowVertices())
226     myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
227
228   //   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
229   bool isTopLev = isTopLevel() && switchTopLevel();
230   switch (aMode) {
231     case Wireframe:
232     // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
233     {
234       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
235
236       // After this call if type of deflection is relative
237       // computed deflection coefficient is stored as absolute.
238       Prs3d::GetDeflection (myshape, myDrawer);
239     }
240     // End 0023271
241     case CustomHighlight:
242     {
243       if(isTopLev) {
244               SetColor(topLevelColor());
245               Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
246               anAspect->SetColor( topLevelColor() );
247               Attributes()->SetWireAspect( anAspect );
248       }
249       if( !isTopLev && anIsColorField && myFieldDimension == 1 )
250         drawField( aPrs, false, aMode == CustomHighlight );
251       else
252         StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
253       break;
254     }
255     case Shading:
256     {
257       shadingMode(aPresentationManager, aPrs, aMode);
258       break;
259     }
260     case ShadingWithEdges:
261     {
262       myDrawer->SetFaceBoundaryDraw( Standard_True );
263       shadingMode(aPresentationManager, aPrs, Shading);
264       if( anIsColorField && myFieldDimension == 1 ) {
265         myDrawer->SetFaceBoundaryDraw( Standard_False );
266         drawField( aPrs );
267       }
268       break;
269     }
270     case TexturedShape:
271     {
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   if( isShowName() )
331     drawName( aPrs );
332
333   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
334 }
335
336 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
337 {
338   myShadingColor = aCol;
339 }
340
341 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
342 {
343   myEdgesInShadingColor = aCol;
344 }
345
346 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
347 {
348   myLabelColor = aCol;
349 }
350
351 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, 
352                                        const Standard_Boolean             aHighlight )
353 {
354   Handle(AIS_InteractiveObject) anObj = this;
355   Handle(AIS_InteractiveContext) anIC = GetContext();
356   if ( anIC.IsNull() || !anIC->HasOpenedContext() ) 
357     return;
358
359   Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
360   anIC->SetAutomaticHilight( false );
361
362   anIC->ClearSelected( false );
363
364   if ( aHighlight ) {
365     SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
366
367     // Get entity owners for all activated selection modes
368     getEntityOwners( anObj, anIC, anAllMap );
369
370     // Convert <aIndexMap> into the map of owners to highlight/unhighlight
371     indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
372
373
374     for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
375       anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
376   }
377
378   anIC->SetAutomaticHilight( isAutoHilight );
379   anIC->HilightSelected( false );
380 }
381
382 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
383 {
384   myDisplayVectors = isDisplayed;
385 }
386
387 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
388 {
389   myDisplayVertices = isDisplayed;
390 }
391
392 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
393 {
394   myDisplayName = isDisplayed;
395 }
396
397 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
398                                 const Handle(Prs3d_Presentation)&           aPrs,
399                                 const Standard_Integer                      aMode)
400 {
401   myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
402
403   Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
404   aMatAspect.SetTransparency(Transparency());
405   Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
406   Graphic3d_MaterialAspect currentBackMaterial  = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
407   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
408   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial  );
409
410   if( isTopLevel() && switchTopLevel() )
411     myDrawer->ShadingAspect()->SetColor( topLevelColor() );
412   else {
413     if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
414       myDrawer->ShadingAspect()->SetColor(myShadingColor);
415     else
416       myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
417   }
418
419   bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
420   if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
421   {
422     drawField( aPrs );
423   }
424   else
425   {
426     // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
427     //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
428     SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
429   }
430 }
431
432 Standard_Boolean GEOM_AISShape::isTopLevel()
433 {
434   return myTopLevel;
435 }
436
437 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
438 {
439   if(f) {
440     if(f != myTopLevel)
441       myPrevDisplayMode = DisplayMode();
442     Standard_Integer dm;
443     switch(topLevelDisplayMode()) {
444       case TopWireFrame :        dm = Wireframe;         break;
445       case TopShading :          dm = Shading;           break;
446       case TopShadingWithEdges : dm = ShadingWithEdges;  break;
447       default :                  dm = myPrevDisplayMode; break;
448     }
449     SetDisplayMode(dm);
450   } else {
451     if(f != myTopLevel)
452       SetDisplayMode(myPrevDisplayMode);
453   }
454   myTopLevel = f;
455 }
456
457 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
458 {
459   myPrevDisplayMode = mode;
460 }
461
462 Quantity_Color GEOM_AISShape::topLevelColor()
463 {
464   return myTopLevelColor;
465 }
466
467 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
468 {
469   myTopLevelColor = c;
470 }
471
472 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
473 {
474   return myTopLevelDm;
475 }
476
477 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
478 {
479   myTopLevelDm = dm;
480 }
481
482 Standard_Boolean GEOM_AISShape::switchTopLevel()
483 {
484   return myTopLevelDm != TopShowAdditionalWActor;
485 }
486
487 Standard_Boolean GEOM_AISShape::toActivate()
488 {
489   return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
490 }
491
492 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type    theFieldDataType,
493                                       const int                      theFieldDimension,
494                                       const QList<QVariant>&         theFieldStepData,
495                                       const TCollection_AsciiString& theFieldStepName,
496                                       const double                   theFieldStepRangeMin,
497                                       const double                   theFieldStepRangeMax )
498 {
499   myFieldDataType     = theFieldDataType;
500   myFieldDimension    = theFieldDimension;
501   myFieldStepData     = theFieldStepData;
502   myFieldStepName     = theFieldStepName;
503   myFieldStepRangeMin = theFieldStepRangeMin;
504   myFieldStepRangeMax = theFieldStepRangeMax;
505 }
506
507 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type&   theFieldDataType,
508                                       int&                     theFieldDimension,
509                                       QList<QVariant>&         theFieldStepData,
510                                       TCollection_AsciiString& theFieldStepName,
511                                       double&                  theFieldStepRangeMin,
512                                       double&                  theFieldStepRangeMax ) const
513 {
514   theFieldDataType     = myFieldDataType;
515   theFieldDimension    = myFieldDimension;
516   theFieldStepData     = myFieldStepData;
517   theFieldStepName     = myFieldStepName;
518   theFieldStepRangeMin = myFieldStepRangeMin;
519   theFieldStepRangeMax = myFieldStepRangeMax;
520 }
521
522 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
523                                const bool                        theIsString,
524                                const bool                        theIsHighlight )
525 {
526   if( myFieldStepData.isEmpty() )
527     return;
528
529   QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
530
531   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
532   switch( myFieldDimension )
533   {
534     case 0:  aShapeType = TopAbs_VERTEX; break;
535     case 1:  aShapeType = TopAbs_EDGE; break;
536     case 2:  aShapeType = TopAbs_FACE; break;
537     case 3:  aShapeType = TopAbs_SOLID; break;
538     case -1: aShapeType = TopAbs_VERTEX; break;
539   }
540
541   TopTools_IndexedMapOfShape aShapeMap;
542   TopExp::MapShapes( myshape, aShapeMap );
543
544   TColStd_IndexedMapOfInteger anIndexMap;
545
546   TopExp_Explorer anExp;
547   for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
548   {
549     TopoDS_Shape aSubShape = anExp.Current();
550     if( !aSubShape.IsNull() )
551     {
552       Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
553       if( anIndexMap.Contains( aSubShapeIndex ) )
554         continue;
555
556       anIndexMap.Add( aSubShapeIndex );
557
558       Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
559
560       QColor aQColor;
561       QString aString;
562       if( aFieldStepDataIter.hasNext() )
563       {
564         const QVariant& aVariant = aFieldStepDataIter.next();
565         if( theIsString )
566           aString = aVariant.toString();
567         else
568           aQColor = aVariant.value<QColor>();
569       }
570       else
571         break;
572
573       if( theIsString )
574       {
575         gp_Pnt aCenter;
576         if( computeMassCenter( aSubShape, aCenter ) )
577         {
578           Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
579
580           Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
581           anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
582           anAspectText3d->SetColor( myLabelColor );
583           aGroup->SetPrimitivesAspect( anAspectText3d );
584
585           aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
586         }
587       }
588       else
589       {
590         Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
591         SetCustomColor( aSubShape, aColor );
592         if( myFieldDimension == 0 )
593         {
594           TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
595           if( !aVertexShape.IsNull() )
596           {
597             gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
598
599             Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
600             anAspectMarker3d->SetColor( aColor );
601             anAspectMarker3d->SetType( Aspect_TOM_POINT );
602             anAspectMarker3d->SetScale( 10.0 );
603             aGroup->SetPrimitivesAspect( anAspectMarker3d );
604
605             Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
606             anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
607
608             aGroup->AddPrimitiveArray( anArray );
609           }
610         }
611         else if( myFieldDimension == 1 )
612         {
613           myDrawer->WireAspect()->SetColor( aColor );
614           if( theIsHighlight )
615             myDrawer->WireAspect()->SetWidth( myOwnWidth );
616           else
617             myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
618           /*
619           StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
620           */
621         }
622         else if( myFieldDimension == 2 ||
623                  myFieldDimension == 3 ||
624                  myFieldDimension == -1 )
625         {
626           //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
627           //anAspect->SetColor( aColor );
628           //myDrawer->SetShadingAspect( anAspect );
629           //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
630         }
631       }
632     }
633   }
634
635   SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
636                             thePrs, AIS_Shaded );
637 }
638
639 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
640 {
641   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
642
643   gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
644   gp_Pnt aCenter = anAx3.Location();
645
646   Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
647
648   Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
649   anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
650   anAspectText3d->SetColor( myLabelColor );
651   aGroup->SetPrimitivesAspect( anAspectText3d );
652
653   const char* aName = getIO()->getName();
654   aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
655 }
656
657 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
658                                                    gp_Pnt&             theCenter )
659 {
660   theCenter.SetCoord( 0,0,0 );
661   Standard_Integer aNbPoints = 0;
662
663   if ( theShape.ShapeType() == TopAbs_EDGE )
664   {
665     double f,l;
666     Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
667     if ( !curve.IsNull() )
668     {
669       theCenter = curve->Value( 0.5 * ( f + l ));
670       aNbPoints = 1;
671     }
672   }
673   else if ( theShape.ShapeType() == TopAbs_FACE )
674   {
675     const TopoDS_Face& F = TopoDS::Face( theShape );
676     BRepAdaptor_Surface surface( F );
677
678     TopLoc_Location L;
679     Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
680     if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
681     {
682       gp_XY C( 0, 0 );
683       double A = 0;
684       const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
685       const Poly_Array1OfTriangle&  trias = triangulation->Triangles();
686       Standard_Integer n1,n2,n3;
687       for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
688       {
689         trias( iT ).Get( n1,n2,n3 );
690         const gp_Pnt2d& uv1 = uvArray( n1 );
691         const gp_Pnt2d& uv2 = uvArray( n2 );
692         const gp_Pnt2d& uv3 = uvArray( n3 );
693         double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
694                               ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
695         C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
696         A += a;
697       }
698       if ( A > std::numeric_limits<double>::min() )
699       {
700         C /= A;
701         theCenter = surface.Value( C.X(), C.Y() );
702         aNbPoints = 1;
703       }
704     }
705     if ( aNbPoints == 0 )
706     {
707       theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
708                                  0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
709     }
710     aNbPoints = 1;
711   }
712
713   if ( aNbPoints == 0 )
714   {
715     TopExp_Explorer anExp;
716     for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
717     {
718       TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
719       if( !aVertex.IsNull() )
720       {
721         gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
722         theCenter.ChangeCoord() += aPnt.XYZ();
723         aNbPoints++;
724       }
725     }
726   }
727
728   if ( aNbPoints > 0 )
729     theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;
730
731   return aNbPoints;
732 }