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