]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_AISShape.cxx
Salome HOME
INT PAL 0052631: Line width property does not affect Shading with edges display mode
[modules/geom.git] / src / OBJECT / GEOM_AISShape.cxx
1 // Copyright (C) 2007-2015  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       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     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         aMatAspect.SetAmbient( 0.5 );
169         aMatAspect.SetDiffuse( 0.5 );
170         aMatAspect.SetEmissive( 0.5 );
171         aMatAspect.SetShininess(0.5 );
172         aMatAspect.SetSpecular( 0.5 );
173         
174         myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
175         myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
176   }
177 }
178
179 GEOM_AISShape::~GEOM_AISShape()
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   // AKL: use old behavior to avoid keeping object's wireframe
219   //      if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos') 
220   //      calling popup menu over(!) the shape in OCC viewer.
221   anIC->SetToHilightSelected( false );
222
223   bool anIsField = !myFieldStepData.isEmpty();
224   bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
225   bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
226
227 #if OCC_VERSION_LARGE > 0x06070200
228   if (isShowVertices())
229     myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
230 #endif
231
232   //   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
233   bool isTopLev = isTopLevel() && switchTopLevel();
234   switch (aMode) {
235     case Wireframe:
236     case CustomHighlight:
237     {
238       if(isTopLev) {
239               SetColor(topLevelColor());
240               Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
241               anAspect->SetColor( topLevelColor() );
242               Attributes()->SetWireAspect( anAspect );
243       }
244       if( !isTopLev && anIsColorField && myFieldDimension == 1 )
245         drawField( aPrs, false, aMode == CustomHighlight );
246       else
247         StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);      
248       break;
249     }
250     case Shading:
251     {
252       shadingMode(aPresentationManager, aPrs, aMode);
253       break;
254     }
255     case ShadingWithEdges:
256     {
257       shadingMode(aPresentationManager, aPrs, Shading);
258       if( anIsColorField && myFieldDimension == 1 )
259         drawField( aPrs );
260       else
261         myDrawer->SetFaceBoundaryDraw( Standard_True );
262       break;
263     }
264     case TexturedShape:
265     {
266       if(!isTopLev)
267 #ifdef USE_TEXTURED_SHAPE
268         AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
269 #else
270         AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
271 #endif
272       else 
273         shadingMode(aPresentationManager, aPrs, Shading);
274       break;
275     }
276   }
277   if (isShowVectors())
278   {
279     const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
280     TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
281     for ( ; Exp.More(); Exp.Next() ) {
282       TopoDS_Vertex aV1, aV2;
283       TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
284       if ( !isVector )
285         // draw curve direction (issue 0021087)
286         anEdgeE.Orientation( TopAbs_FORWARD );
287
288       if ( anEdgeE.IsNull() ) continue;
289
290       TopExp::Vertices(anEdgeE, aV1, aV2);
291       gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
292       gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
293
294       double fp,lp;
295       gp_Vec aDirVec;
296       Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
297
298       if ( C.IsNull() ) continue;
299
300       if ( anEdgeE.Orientation() == TopAbs_FORWARD )
301         C->D1(lp, aP2, aDirVec);
302       else {
303         C->D1(fp, aP1, aDirVec);
304         aP2 = aP1;
305       }
306
307       GeomAdaptor_Curve aAdC;
308       aAdC.Load(C, fp, lp);
309       Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); 
310      
311       if (aDist > gp::Resolution()) {
312         gp_Dir aDir;
313         if ( anEdgeE.Orientation() == TopAbs_FORWARD )
314           aDir = aDirVec;
315         else
316           aDir = -aDirVec;
317
318         Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
319       }
320     }
321   }
322
323   // draw color field on vertices
324   if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
325     drawField( aPrs );
326
327   // draw text field
328   if( anIsTextField )
329     drawField( aPrs, true );
330
331   if( isShowName() )
332     drawName( aPrs );
333
334   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
335 }
336
337 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
338 {
339   myShadingColor = aCol;
340 }
341
342 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
343 {
344   myEdgesInShadingColor = aCol;
345 }
346
347 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, 
348                                        const Standard_Boolean aHighlight )
349 {
350   Handle(AIS_InteractiveObject) anObj = this;
351   Handle(AIS_InteractiveContext) anIC = GetContext();
352   if ( anIC.IsNull() || !anIC->HasOpenedContext() ) 
353     return;
354
355   Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
356   anIC->SetAutomaticHilight( false );
357
358   anIC->ClearSelected( false );
359
360   if ( aHighlight ) {
361     SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
362
363     // Get entity owners for all activated selection modes
364     getEntityOwners( anObj, anIC, anAllMap );
365
366     // Convert <aIndexMap> into the map of owners to highlight/unhighlight
367     indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
368
369
370     for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
371       anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
372   }
373
374   anIC->SetAutomaticHilight( isAutoHilight );
375   anIC->HilightSelected( false );
376 }
377
378 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
379 {
380   myDisplayVectors = isDisplayed;
381 }
382
383 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
384 {
385   myDisplayVertices = isDisplayed;
386 }
387
388 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
389 {
390   myDisplayName = isDisplayed;
391 }
392
393 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
394                                 const Handle(Prs3d_Presentation)& aPrs,
395                                 const Standard_Integer aMode)
396 {
397   myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
398
399   Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
400   aMatAspect.SetTransparency(Transparency());
401   Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
402   Graphic3d_MaterialAspect currentBackMaterial  = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
403   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
404   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial  );
405
406   if( isTopLevel() && switchTopLevel() )
407     myDrawer->ShadingAspect()->SetColor( topLevelColor() );
408   else { 
409     if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
410       myDrawer->ShadingAspect()->SetColor(myShadingColor);
411     else
412       myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
413   }
414
415   bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
416   if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
417   {
418     drawField( aPrs );
419   }
420   else
421   {
422     // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
423     //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
424 #ifdef USE_TEXTURED_SHAPE
425     AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
426 #else
427     AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
428 #endif
429   }
430 }
431
432 Standard_Boolean GEOM_AISShape::isTopLevel() {
433   return myTopLevel;
434 }
435
436 void GEOM_AISShape::setTopLevel(Standard_Boolean f) {
437   if(f) {
438     if(f != myTopLevel)
439       myPrevDisplayMode = DisplayMode();
440     Standard_Integer dm;
441     switch(topLevelDisplayMode()) {
442       case TopKeepCurrent :      dm = myPrevDisplayMode; break;
443       case TopWireFrame :        dm = Wireframe;         break;     
444       case TopShadingWithEdges : dm = ShadingWithEdges;  break;
445       default :                  dm = Shading;           break;
446     }
447     SetDisplayMode(dm);
448   } else {
449     if(f != myTopLevel)
450       SetDisplayMode(myPrevDisplayMode);
451   }
452   myTopLevel = f;
453 }
454
455 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode) {
456   myPrevDisplayMode = mode;
457 }
458
459 Quantity_Color GEOM_AISShape::topLevelColor() {
460   return myTopLevelColor;
461 }
462
463 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c) {
464   myTopLevelColor = c;
465 }
466
467 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode() {
468   return myTopLevelDm;
469 }
470 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm) {
471   myTopLevelDm = dm;
472 }
473
474 Standard_Boolean GEOM_AISShape::switchTopLevel() {
475   return myTopLevelDm != TopShowAdditionalWActor;
476 }
477
478 Standard_Boolean GEOM_AISShape::toActivate() {
479   return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
480 }
481
482 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
483                                       const int theFieldDimension,
484                                       const QList<QVariant>& theFieldStepData,
485                                       const TCollection_AsciiString& theFieldStepName,
486                                       const double theFieldStepRangeMin,
487                                       const double theFieldStepRangeMax )
488 {
489   myFieldDataType = theFieldDataType;
490   myFieldDimension = theFieldDimension;
491   myFieldStepData = theFieldStepData;
492   myFieldStepName = theFieldStepName;
493   myFieldStepRangeMin = theFieldStepRangeMin;
494   myFieldStepRangeMax = theFieldStepRangeMax;
495 }
496
497 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
498                                       int& theFieldDimension,
499                                       QList<QVariant>& theFieldStepData,
500                                       TCollection_AsciiString& theFieldStepName,
501                                       double& theFieldStepRangeMin,
502                                       double& theFieldStepRangeMax ) const
503 {
504   theFieldDataType = myFieldDataType;
505   theFieldDimension = myFieldDimension;
506   theFieldStepData = myFieldStepData;
507   theFieldStepName = myFieldStepName;
508   theFieldStepRangeMin = myFieldStepRangeMin;
509   theFieldStepRangeMax = myFieldStepRangeMax;
510 }
511
512 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
513                                const bool theIsString,
514                                const bool theIsHighlight )
515 {
516   if( myFieldStepData.isEmpty() )
517     return;
518
519   QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
520
521   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
522   switch( myFieldDimension )
523   {
524     case 0: aShapeType = TopAbs_VERTEX; break;
525     case 1: aShapeType = TopAbs_EDGE; break;
526     case 2: aShapeType = TopAbs_FACE; break;
527     case 3: aShapeType = TopAbs_SOLID; break;
528     case -1: aShapeType = TopAbs_VERTEX; break;
529   }
530
531   TopTools_IndexedMapOfShape aShapeMap;
532   TopExp::MapShapes( myshape, aShapeMap );
533
534   TColStd_IndexedMapOfInteger anIndexMap;
535
536   TopExp_Explorer anExp;
537   for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
538   {
539     TopoDS_Shape aSubShape = anExp.Current();
540     if( !aSubShape.IsNull() )
541     {
542       Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
543       if( anIndexMap.Contains( aSubShapeIndex ) )
544         continue;
545
546       anIndexMap.Add( aSubShapeIndex );
547
548       Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
549
550       QColor aQColor;
551       QString aString;
552       if( aFieldStepDataIter.hasNext() )
553       {
554         const QVariant& aVariant = aFieldStepDataIter.next();
555         if( theIsString )
556           aString = aVariant.toString();
557         else
558           aQColor = aVariant.value<QColor>();
559       }
560       else
561         break;
562
563       if( theIsString )
564       {
565         gp_Pnt aCenter;
566         if( computeMassCenter( aSubShape, aCenter ) )
567         {
568           Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
569
570           Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
571           anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
572           aGroup->SetPrimitivesAspect( anAspectText3d );
573
574           aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
575         }
576       }
577       else
578       {
579         Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
580         if( myFieldDimension == 0 )
581         {
582           TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
583           if( !aVertexShape.IsNull() )
584           {
585             gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
586
587             Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
588             anAspectMarker3d->SetColor( aColor );
589             anAspectMarker3d->SetType( Aspect_TOM_POINT );
590             anAspectMarker3d->SetScale( 10.0 );
591             aGroup->SetPrimitivesAspect( anAspectMarker3d );
592
593             Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
594             anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
595
596             aGroup->AddPrimitiveArray( anArray );
597           }
598         }
599         else if( myFieldDimension == 1 )
600         {
601           myDrawer->WireAspect()->SetColor( aColor );
602           if( theIsHighlight )
603             myDrawer->WireAspect()->SetWidth( myOwnWidth );
604           else
605             myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
606           StdPrs_WFDeflectionShape::Add( thePrs, aSubShape, myDrawer );
607         }
608         else if( myFieldDimension == 2 ||
609                  myFieldDimension == 3 ||
610                  myFieldDimension == -1 )
611         {
612           myDrawer->ShadingAspect()->SetColor( aColor );
613           StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
614         }
615       }
616     }
617   }
618 }
619
620 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
621 {
622   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
623
624   gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
625   gp_Pnt aCenter = anAx3.Location();
626
627   Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
628
629   Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
630   anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
631   aGroup->SetPrimitivesAspect( anAspectText3d );
632
633   const char* aName = getIO()->getName();
634   aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
635 }
636
637 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
638                                                    gp_Pnt& theCenter )
639 {
640   Standard_Real aX = 0, aY = 0, aZ = 0;
641   Standard_Integer aNbPoints = 0;
642
643   TopExp_Explorer anExp;
644   for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
645   {
646     TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
647     if( !aVertex.IsNull() )
648     {
649       gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
650       aX += aPnt.X();
651       aY += aPnt.Y();
652       aZ += aPnt.Z();
653       aNbPoints++;
654     }
655   }
656
657   if( aNbPoints == 0 )
658     return Standard_False;
659
660   theCenter.SetCoord( aX / (Standard_Real)aNbPoints,
661                       aY / (Standard_Real)aNbPoints,
662                       aZ / (Standard_Real)aNbPoints );
663   return Standard_True;
664 }