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