Salome HOME
0dea71969d205eae4c7bcfd8e3a8a43005d74148
[modules/geom.git] / src / OBJECT / GEOM_AISShape.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /*!
24   \class GEOM_AISShape GEOM_AISShape.hxx
25   \brief ....
26 */
27
28 #include "GEOM_AISShape.hxx"
29 #include "GEOM_AISVector.hxx"
30
31 #include <GEOMUtils.hxx>
32
33 // Open CASCADE Includes
34 #include <AIS_InteractiveContext.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <gp_Dir.hxx>
40 #include <gp_Pnt.hxx>
41 #include <gp_Vec.hxx>
42 #include <Graphic3d_ArrayOfPoints.hxx>
43 #include <Graphic3d_AspectFillArea3d.hxx>
44 #include <Graphic3d_AspectLine3d.hxx>
45 #include <Graphic3d_AspectMarker3d.hxx>
46 #include <Graphic3d_AspectText3d.hxx>
47 #include <Prs3d.hxx>
48 #include <Prs3d_Arrow.hxx>
49 #include <Prs3d_IsoAspect.hxx>
50 #include <Prs3d_ShadingAspect.hxx>
51 #include <Prs3d_VertexDrawMode.hxx>
52 #include <SelectBasics_SensitiveEntity.hxx>
53 #include <SelectMgr_EntityOwner.hxx>
54 #include <SelectMgr_IndexedMapOfOwner.hxx>
55 #include <SelectMgr_Selection.hxx>
56 #include <StdPrs_ShadedShape.hxx>
57 #include <StdPrs_ToolTriangulatedShape.hxx>
58 #include <StdPrs_WFShape.hxx>
59 #include <StdSelect_BRepOwner.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <TColStd_ListOfInteger.hxx>
63 #include <TopExp.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
66 #include <TopoDS.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <TopoDS_Vertex.hxx>
70 #include <V3d_View.hxx>
71
72 #include <Basics_OCCTVersion.hxx>
73 #if OCC_VERSION_LARGE >= 0x070400ff
74 #include <Graphic3d_Text.hxx>
75 #else
76 #include <StdSelect_DisplayMode.hxx>
77 #endif
78
79 #include <SalomeApp_Tools.h>
80 #include <SUIT_Session.h>
81 #include <SUIT_ResourceMgr.h>
82
83 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
84
85 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
86 Quantity_Color GEOM_AISShape::myTopLevelColor;
87
88
89 static void getEntityOwners( const Handle(AIS_InteractiveObject)&  theObj,
90                              const Handle(AIS_InteractiveContext)& theIC,
91                              SelectMgr_IndexedMapOfOwner&          theMap )
92 {
93   if ( theObj.IsNull() || theIC.IsNull() )
94     return;
95
96   TColStd_ListOfInteger modes;
97   theIC->ActivatedModes( theObj, modes );
98
99   TColStd_ListIteratorOfListOfInteger itr( modes );
100   for (; itr.More(); itr.Next() ) {
101     int m = itr.Value();
102     if ( !theObj->HasSelection( m ) )
103       continue;
104
105     Handle(SelectMgr_Selection) sel = theObj->Selection( m );
106     const NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>& selected = sel->Entities();
107     for ( NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator selIter( selected );
108           selIter.More(); selIter.Next() ) {
109       const Handle(SelectMgr_SensitiveEntity) aHSenEntity = selIter.Value();
110       if( aHSenEntity.IsNull() )
111         continue;
112
113       Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
114       if ( entity.IsNull() )
115         continue;
116       const Handle(SelectMgr_EntityOwner)& owner = 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     myDisplayVertices(false),
152     myFieldDataType(GEOM::FDT_Double),
153     myFieldDimension(0),
154     myFieldStepRangeMin(0),
155     myFieldStepRangeMax(0)
156 {
157   //rnv: Commented to avoid bug with local selection
158   //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
159
160   myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
161   myPrevDisplayMode = 0;
162
163   myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
164
165   myTopLevel = Standard_False;
166   Graphic3d_MaterialAspect aMatAspect;
167   if ( !HasMaterial() ) {
168 #if OCC_VERSION_LARGE >= 0x07040000
169     aMatAspect.SetAmbientColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
170     aMatAspect.SetDiffuseColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
171     aMatAspect.SetEmissiveColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
172     aMatAspect.SetSpecularColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
173 #else
174     aMatAspect.SetAmbient( 0.5 );
175     aMatAspect.SetDiffuse( 0.5 );
176     aMatAspect.SetEmissive( 0.5 );
177     aMatAspect.SetSpecular( 0.5 );
178 #endif
179     aMatAspect.SetShininess(0.5 );
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 {
191   SetOwner( io );
192 }
193
194 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
195 {
196   Handle(SALOME_InteractiveObject) IO;
197   if ( !GetOwner().IsNull() )
198     IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
199   return IO;
200 }
201
202 Standard_Boolean GEOM_AISShape::hasIO()
203 {
204   return !getIO().IsNull();
205 }
206
207 void GEOM_AISShape::setName(const Standard_CString aName)
208 {
209   myName = aName;
210
211   Handle(SALOME_InteractiveObject) IO = getIO();
212   if ( !IO.IsNull() )
213     IO->setName(aName);
214 }
215
216 Standard_CString GEOM_AISShape::getName()
217 {
218   return myName.ToCString();
219 }
220
221 Standard_Boolean GEOM_AISShape::AcceptDisplayMode(const Standard_Integer theMode) const
222 {
223   return theMode >= Wireframe && theMode <= CustomHighlight;
224 }
225
226 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
227                             const Handle(Prs3d_Presentation)&           aPrs,
228                             const Standard_Integer                      aMode)
229
230   if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
231
232   Handle(AIS_InteractiveContext) anIC = GetContext();
233   // AKL: use old behavior to avoid keeping object's wireframe
234   //      if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos') 
235   //      calling popup menu over(!) the shape in OCC viewer.
236   anIC->SetToHilightSelected( false );
237
238   bool anIsField = !myFieldStepData.isEmpty();
239   bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
240   bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
241
242   if (isShowVertices())
243     myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
244
245   //   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
246   bool isTopLev = isTopLevel() && switchTopLevel();
247   switch (aMode) {
248     case Wireframe:
249     // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
250     {
251       StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
252
253 #if OCC_VERSION_LARGE <= 0x07040000
254       // After this call if type of deflection is relative
255       // computed deflection coefficient is stored as absolute.
256       Prs3d::GetDeflection (myshape, myDrawer);
257 #endif
258     } // fall through!
259     // End 0023271
260     case CustomHighlight:
261     {
262       if(isTopLev) {
263               SetColor(topLevelColor());
264               Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
265               anAspect->SetColor( topLevelColor() );
266               Attributes()->SetWireAspect( anAspect );
267       }
268       if( !isTopLev && anIsColorField && myFieldDimension == 1 )
269         drawField( aPrs, false, aMode == CustomHighlight );
270       else
271         StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
272       break;
273     }
274     case Shading:
275     {
276       shadingMode(aPresentationManager, aPrs, aMode);
277       break;
278     }
279     case ShadingWithEdges:
280     {
281       myDrawer->SetFaceBoundaryDraw( Standard_True );
282       shadingMode(aPresentationManager, aPrs, Shading);
283       if( anIsColorField && myFieldDimension == 1 ) {
284         myDrawer->SetFaceBoundaryDraw( Standard_False );
285         drawField( aPrs );
286       }
287       break;
288     }
289     case TexturedShape:
290     {
291       shadingMode(aPresentationManager, aPrs, Shading);
292       break;
293     }
294   }
295   if (isShowVectors())
296   {
297     const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
298     TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
299     for ( ; Exp.More(); Exp.Next() ) {
300       TopoDS_Vertex aV1, aV2;
301       TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
302       if ( !isVector )
303         // draw curve direction (issue 0021087)
304         anEdgeE.Orientation( TopAbs_FORWARD );
305
306       if ( anEdgeE.IsNull() ) continue;
307
308       TopExp::Vertices(anEdgeE, aV1, aV2);
309       gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
310       gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
311
312       double fp,lp;
313       gp_Vec aDirVec;
314       Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
315
316       if ( C.IsNull() ) continue;
317
318       if ( anEdgeE.Orientation() == TopAbs_FORWARD )
319         C->D1(lp, aP2, aDirVec);
320       else {
321         C->D1(fp, aP1, aDirVec);
322         aP2 = aP1;
323       }
324
325       GeomAdaptor_Curve aAdC;
326       aAdC.Load(C, fp, lp);
327       Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); 
328      
329       if (aDist > gp::Resolution()) {
330         gp_Dir aDir;
331         if ( anEdgeE.Orientation() == TopAbs_FORWARD )
332           aDir = aDirVec;
333         else
334           aDir = -aDirVec;
335
336         Prs3d_Arrow::Draw(aPrs->CurrentGroup(), aP2, aDir, M_PI/180.*5., aDist/10.);
337       }
338     }
339   }
340
341   // draw color field on vertices
342   if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
343     drawField( aPrs );
344
345   // draw text field
346   if( anIsTextField )
347     drawField( aPrs, true );
348
349   if( isShowName() )
350     drawName( aPrs );
351
352   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
353 }
354
355 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
356 {
357   myShadingColor = aCol;
358 }
359
360 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
361 {
362   myEdgesInShadingColor = aCol;
363 }
364
365 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
366 {
367   myLabelColor = aCol;
368 }
369
370 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, 
371                                        const Standard_Boolean             aHighlight )
372 {
373   Handle(AIS_InteractiveObject) anObj = this;
374   Handle(AIS_InteractiveContext) anIC = GetContext();
375   if ( anIC.IsNull() ) 
376     return;
377
378   Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
379   anIC->SetAutomaticHilight( false );
380
381   anIC->ClearSelected( false );
382
383   if ( aHighlight ) {
384     SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
385
386     // Get entity owners for all activated selection modes
387     getEntityOwners( anObj, anIC, anAllMap );
388
389     // Convert <aIndexMap> into the map of owners to highlight/unhighlight
390     indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
391
392
393     for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
394       anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
395   }
396
397   anIC->SetAutomaticHilight( isAutoHilight );
398   anIC->HilightSelected( false );
399 }
400
401 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
402 {
403   myDisplayVectors = isDisplayed;
404 }
405
406 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
407 {
408   myDisplayVertices = isDisplayed;
409 }
410
411 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
412 {
413   myDisplayName = isDisplayed;
414 }
415
416 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
417                                 const Handle(Prs3d_Presentation)&           aPrs,
418                                 const Standard_Integer                      aMode)
419 {
420   myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
421
422   Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
423   aMatAspect.SetTransparency(Transparency());
424   Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
425   Graphic3d_MaterialAspect currentBackMaterial  = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
426   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
427   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial  );
428
429   if( isTopLevel() && switchTopLevel() )
430     myDrawer->ShadingAspect()->SetColor( topLevelColor() );
431   else {
432     if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
433       myDrawer->ShadingAspect()->SetColor(myShadingColor);
434     else
435       myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
436   }
437
438   bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
439   if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
440   {
441     drawField( aPrs );
442   }
443   else
444   {
445     // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
446     //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
447     SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
448   }
449 }
450
451 Standard_Boolean GEOM_AISShape::isTopLevel()
452 {
453   return myTopLevel;
454 }
455
456 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
457 {
458   if(f) {
459     if(f != myTopLevel)
460       myPrevDisplayMode = DisplayMode();
461     Standard_Integer dm;
462     switch(topLevelDisplayMode()) {
463       case TopWireFrame :        dm = Wireframe;         break;
464       case TopShading :          dm = Shading;           break;
465       case TopShadingWithEdges : dm = ShadingWithEdges;  break;
466       default :                  dm = myPrevDisplayMode; break;
467     }
468     SetDisplayMode(dm);
469   } else {
470     if(f != myTopLevel)
471       SetDisplayMode(myPrevDisplayMode);
472   }
473   myTopLevel = f;
474 }
475
476 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
477 {
478   myPrevDisplayMode = mode;
479 }
480
481 Quantity_Color GEOM_AISShape::topLevelColor()
482 {
483   return myTopLevelColor;
484 }
485
486 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
487 {
488   myTopLevelColor = c;
489 }
490
491 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
492 {
493   return myTopLevelDm;
494 }
495
496 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
497 {
498   myTopLevelDm = dm;
499 }
500
501 Standard_Boolean GEOM_AISShape::switchTopLevel()
502 {
503   return myTopLevelDm != TopShowAdditionalWActor;
504 }
505
506 Standard_Boolean GEOM_AISShape::toActivate()
507 {
508   return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
509 }
510
511 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type    theFieldDataType,
512                                       const int                      theFieldDimension,
513                                       const QList<QVariant>&         theFieldStepData,
514                                       const TCollection_AsciiString& theFieldStepName,
515                                       const double                   theFieldStepRangeMin,
516                                       const double                   theFieldStepRangeMax )
517 {
518   myFieldDataType     = theFieldDataType;
519   myFieldDimension    = theFieldDimension;
520   myFieldStepData     = theFieldStepData;
521   myFieldStepName     = theFieldStepName;
522   myFieldStepRangeMin = theFieldStepRangeMin;
523   myFieldStepRangeMax = theFieldStepRangeMax;
524 }
525
526 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type&   theFieldDataType,
527                                       int&                     theFieldDimension,
528                                       QList<QVariant>&         theFieldStepData,
529                                       TCollection_AsciiString& theFieldStepName,
530                                       double&                  theFieldStepRangeMin,
531                                       double&                  theFieldStepRangeMax ) const
532 {
533   theFieldDataType     = myFieldDataType;
534   theFieldDimension    = myFieldDimension;
535   theFieldStepData     = myFieldStepData;
536   theFieldStepName     = myFieldStepName;
537   theFieldStepRangeMin = myFieldStepRangeMin;
538   theFieldStepRangeMax = myFieldStepRangeMax;
539 }
540
541 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
542                                const bool                        theIsString,
543                                const bool                        theIsHighlight )
544 {
545   if( myFieldStepData.isEmpty() )
546     return;
547
548   QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
549
550   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
551   switch( myFieldDimension )
552   {
553     case 0:  aShapeType = TopAbs_VERTEX; break;
554     case 1:  aShapeType = TopAbs_EDGE; break;
555     case 2:  aShapeType = TopAbs_FACE; break;
556     case 3:  aShapeType = TopAbs_SOLID; break;
557     case -1: aShapeType = TopAbs_VERTEX; break;
558   }
559
560   TopTools_IndexedMapOfShape aShapeMap;
561   TopExp::MapShapes( myshape, aShapeMap );
562
563   TColStd_IndexedMapOfInteger anIndexMap;
564
565   TopExp_Explorer anExp;
566   for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
567   {
568     TopoDS_Shape aSubShape = anExp.Current();
569     if( !aSubShape.IsNull() )
570     {
571       Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
572       if( anIndexMap.Contains( aSubShapeIndex ) )
573         continue;
574
575       anIndexMap.Add( aSubShapeIndex );
576
577       Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
578
579       QColor aQColor;
580       QString aString;
581       if( aFieldStepDataIter.hasNext() )
582       {
583         const QVariant& aVariant = aFieldStepDataIter.next();
584         if( theIsString )
585           aString = aVariant.toString();
586         else
587           aQColor = aVariant.value<QColor>();
588       }
589       else
590         break;
591
592       if( theIsString )
593       {
594         gp_Pnt aCenter;
595         if( computeMassCenter( aSubShape, aCenter ) )
596         {
597           Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
598           anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
599           anAspectText3d->SetColor( myLabelColor );
600           aGroup->SetPrimitivesAspect( anAspectText3d );
601
602 #if OCC_VERSION_LARGE >= 0x070400ff
603           Handle(Graphic3d_Text) aText = new Graphic3d_Text (14.);
604           aText->SetText (aString.toUtf8().constData());
605           aText->SetPosition (aCenter);
606           aGroup->AddText (aText);
607 #else
608           Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
609           aGroup->Text( aString.toUtf8().constData(), aVertex, 14 ); // deprecated API, to be removed (see above)
610 #endif
611         }
612       }
613       else
614       {
615         Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
616         SetCustomColor( aSubShape, aColor );
617         if( myFieldDimension == 0 )
618         {
619           TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
620           if( !aVertexShape.IsNull() )
621           {
622             gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
623
624             Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
625             anAspectMarker3d->SetColor( aColor );
626             anAspectMarker3d->SetType( Aspect_TOM_POINT );
627             anAspectMarker3d->SetScale( 10.0 );
628             aGroup->SetPrimitivesAspect( anAspectMarker3d );
629
630             Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
631             anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
632
633             aGroup->AddPrimitiveArray( anArray );
634           }
635         }
636         else if( myFieldDimension == 1 )
637         {
638           myDrawer->WireAspect()->SetColor( aColor );
639           if( theIsHighlight )
640             myDrawer->WireAspect()->SetWidth( myOwnWidth );
641           else
642             myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
643           /*
644           StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
645           */
646         }
647         else if( myFieldDimension == 2 ||
648                  myFieldDimension == 3 ||
649                  myFieldDimension == -1 )
650         {
651           //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
652           //anAspect->SetColor( aColor );
653           //myDrawer->SetShadingAspect( anAspect );
654           //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
655         }
656       }
657     }
658   }
659
660   SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
661                             thePrs, AIS_Shaded );
662 }
663
664 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
665 {
666   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
667
668   gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
669   gp_Pnt aCenter = anAx3.Location();
670
671   Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
672   anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
673   anAspectText3d->SetColor( myLabelColor );
674   aGroup->SetPrimitivesAspect( anAspectText3d );
675
676   const char* aName = getIO()->getName();
677 #if OCC_VERSION_LARGE >= 0x070400ff
678   Handle(Graphic3d_Text) aText = new Graphic3d_Text (16.);
679   aText->SetText (aName);
680   aText->SetPosition (aCenter);
681   aGroup->AddText(aText);
682 #else
683   Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
684   aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 ); // deprecated API, to be removed (see above)
685 #endif
686 }
687
688 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
689                                                    gp_Pnt&             theCenter )
690 {
691   theCenter.SetCoord( 0,0,0 );
692   Standard_Integer aNbPoints = 0;
693
694   if ( theShape.ShapeType() == TopAbs_EDGE )
695   {
696     double f,l;
697     Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
698     if ( !curve.IsNull() )
699     {
700       theCenter = curve->Value( 0.5 * ( f + l ));
701       aNbPoints = 1;
702     }
703   }
704   else if ( theShape.ShapeType() == TopAbs_FACE )
705   {
706     const TopoDS_Face& F = TopoDS::Face( theShape );
707     BRepAdaptor_Surface surface( F );
708
709     TopLoc_Location L;
710     Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
711     if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
712     {
713       gp_XY C( 0, 0 );
714       double A = 0;
715       Standard_Integer n1,n2,n3;
716       for ( int iT = 1; iT <= triangulation->NbTriangles(); ++iT )
717       {
718         triangulation->Triangle( iT ).Get( n1,n2,n3 );
719         const gp_Pnt2d& uv1 = triangulation->UVNode( n1 );
720         const gp_Pnt2d& uv2 = triangulation->UVNode( n2 );
721         const gp_Pnt2d& uv3 = triangulation->UVNode( n3 );
722         double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
723                               ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
724         C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
725         A += a;
726       }
727       if ( A > std::numeric_limits<double>::min() )
728       {
729         C /= A;
730         theCenter = surface.Value( C.X(), C.Y() );
731         aNbPoints = 1;
732       }
733     }
734     if ( aNbPoints == 0 )
735     {
736       theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
737                                  0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
738     }
739     aNbPoints = 1;
740   }
741
742   if ( aNbPoints == 0 )
743   {
744     TopExp_Explorer anExp;
745     for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
746     {
747       TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
748       if( !aVertex.IsNull() )
749       {
750         gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
751         theCenter.ChangeCoord() += aPnt.XYZ();
752         aNbPoints++;
753       }
754     }
755   }
756
757   if ( aNbPoints > 0 )
758     theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;
759
760   return aNbPoints;
761 }