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