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