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