Salome HOME
Take into account merge of branch 'asl/hydro_porting_741' in GUI module.
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.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 GEOMGUI : GUI for Geometry component
24 // File   : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
30
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
39
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
48
49 #include <GEOMUtils.hxx>
50
51 #include <Material_Model.h>
52
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
58
59 #include <Basics_OCCTVersion.hxx>
60
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
67
68 #include <SALOME_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
71
72 #include <SOCC_Prs.h>
73 #include <SOCC_ViewModel.h>
74
75 #include <SVTK_Prs.h>
76 #include <SVTK_ViewModel.h>
77
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80 #include <OCCViewer_Utilities.h>
81
82 // OCCT Includes
83 #include <AIS_Drawer.hxx>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
112
113 #include <Prs3d_ShadingAspect.hxx>
114
115 #include <BRepMesh_IncrementalMesh.hxx>
116
117 // VTK Includes
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
120
121 // CORBA Headers
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
123
124 #include <GEOMImpl_Types.hxx>
125
126 #include <TColStd_HArray1OfByte.hxx>
127
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
134
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
137
138 // Pixmap caching support
139 namespace
140 {
141   typedef NCollection_Map<Handle(GEOM_AISShape)>                    SetOfAISShapes;
142   typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
143   typedef QMap<QString, Handle(Image_PixMap)>                       PixmapCacheMap;
144
145   static inline PixmapUsageMap& getPixmapUsageMap()
146   {
147     static PixmapUsageMap aMap;
148     return aMap;
149   }
150
151   static inline PixmapCacheMap& getPixmapCacheMap()
152   {
153     static PixmapCacheMap aMap;
154     return aMap;
155   }
156
157   //===========================================================================
158   // Function : getDefaultTexture
159   // Purpose  : Get default texture
160   //===========================================================================
161   static inline Handle(Image_PixMap) getDefaultTexture()
162   {
163     static Handle(Image_PixMap) aPixmap;
164     if ( aPixmap.IsNull() ) {
165       QPixmap px(":images/default_texture.png");
166       if ( !px.isNull() )
167         aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
168     }
169     return aPixmap;
170   }
171
172   //===========================================================================
173   // Function : cacheTextureFor
174   // Purpose  : Load and cache image for the specified presentation.
175   //===========================================================================
176   static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
177                                                       const Handle(GEOM_AISShape)& theShape )
178   {
179     if ( thePath.isEmpty() )
180       return NULL;
181
182     PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
183     PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
184
185     Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
186     if ( !aPixmap.IsNull() ) {
187       // point that the texture is used by the presentation
188       if ( !aPixmapUsersMap.IsBound( aPixmap ) )
189         aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
190
191       aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
192
193       return aPixmap;
194     }
195
196     // convert texture to compatible image format
197     QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
198     if ( anImage.isNull() )
199       return NULL;
200
201     aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
202
203     aPixmapCacheMap.insert( thePath, aPixmap );
204
205     if ( !aPixmapUsersMap.IsBound( aPixmap ) )
206       aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
207
208     aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
209
210     return aPixmap;
211   }
212
213   //===========================================================================
214   // Function : releaseTextures
215   // Purpose  : Releases cached textures found for the specified presentation.
216   //===========================================================================
217   static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
218   {
219     const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
220
221     AIS_ListOfInteractive aListOfIO;
222
223     anOccPrs->GetObjects( aListOfIO );
224
225     AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
226
227     PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
228     PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
229
230     for ( ; aIterateIO.More(); aIterateIO.Next() )
231     {
232       Handle(GEOM_AISShape) aAISShape =
233         Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
234
235       if ( aAISShape.IsNull() )
236         continue;
237
238       const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
239       if ( aPixmap.IsNull() )
240         continue;
241
242       if ( !aPixmapUsersMap.IsBound( aPixmap ) )
243         continue;
244
245       SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
246
247       aUsersShapes.Remove( aAISShape );
248
249       if ( aUsersShapes.IsEmpty() ) {
250         aPixmapUsersMap.UnBind( aPixmap );
251         aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
252       }
253     }
254   }
255 }
256
257 //================================================================
258 // Function : getActiveStudy
259 // Purpose  : Get active study, returns 0 if no open study frame
260 //================================================================
261 static inline SalomeApp_Study* getActiveStudy()
262 {
263   SUIT_Session* session = SUIT_Session::session();
264   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
265   if ( app )
266     return ( SalomeApp_Study* )app->activeStudy();
267   return 0;
268 }
269
270 static inline int getViewManagerId( SALOME_View* theViewFrame) {
271   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
272   SUIT_ViewManager* aViewMgr = 0;
273   if (aModel != 0)
274     aViewMgr = aModel->getViewManager();
275   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
276 }
277
278 //================================================================
279 // Function : getTopAbsMode
280 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
281 //            one from GEOMImpl_Types.h
282 //================================================================
283 static inline int getTopAbsMode( const int implType )
284 {
285   switch ( implType )
286   {
287     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
288     case GEOM_SOLID     : return TopAbs_SOLID;
289     case GEOM_SHELL     : return TopAbs_SHELL;
290     case GEOM_FACE      : return TopAbs_FACE;
291     case GEOM_WIRE      : return TopAbs_WIRE;
292     case GEOM_EDGE      : return TopAbs_EDGE;
293     case GEOM_POINT     : return TopAbs_VERTEX;
294     default             : return -1;
295   }
296 }
297
298 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
299 {
300   if ( shape.IsNull() )
301     return TopAbs_SHAPE;
302
303   int ret = shape.ShapeType();
304
305   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
306     TopoDS_Iterator it(shape, Standard_True, Standard_False);
307     for (; it.More(); it.Next()) {
308       TopoDS_Shape sub_shape = it.Value();
309       if ( sub_shape.IsNull() ) continue;
310       int stype = getMinMaxShapeType( sub_shape, ismin );
311       if ( stype == TopAbs_SHAPE ) continue;
312       if ( ismin && stype > ret )
313         ret = stype;
314       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
315         ret = stype;
316     }
317   }
318
319   return ret;
320 }
321
322 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
323 {
324   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
325 }
326
327 //================================================================
328 // Function : getFilter
329 // Purpose  : Get filter corresponding to the type of object
330 //            from GEOMImpl_Types.h
331 //================================================================
332 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
333 {
334   SUIT_SelectionFilter* aFilter;
335
336   int aTopAbsMode = getTopAbsMode( theMode );
337   if ( aTopAbsMode != -1 )
338     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
339   else
340     switch ( theMode )
341       {
342       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
343       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
344
345       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
346       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
347       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
348       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
349       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
350       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
351
352       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
353
354       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
355       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
356
357       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
358       }
359
360   return aFilter;
361 }
362
363 //================================================================
364 // Function : getComplexFilter
365 // Purpose  : Get compound filter corresponding to the type of
366 //            object from GEOMImpl_Types.h
367 //================================================================
368 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
369 {
370   GEOM_CompoundFilter* aFilter;
371
372   if(aSubShapes != NULL ) {
373     aFilter = new GEOM_CompoundFilter(getStudy());
374     QList<int> aTopAbsTypes;
375     QList<int>::const_iterator it;
376     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
377       int topAbsMode = getTopAbsMode(*it);
378       if(topAbsMode != -1 )
379         aTopAbsTypes.append(topAbsMode);
380     }
381     aFilter->addSubTypes(aTopAbsTypes);
382   }
383
384   return aFilter;
385 }
386
387 //================================================================
388 // Function : getEntry
389 // Purpose  :
390 //================================================================
391 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
392 {
393   SUIT_Session* session = SUIT_Session::session();
394   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
395   if ( app )
396   {
397     CORBA::String_var IOR = app->orb()->object_to_string( object );
398     if ( strcmp(IOR.in(), "") != 0 )
399     {
400       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
401       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
402       if ( SO )
403         return SO->GetID();
404     }
405   }
406   return "";
407 }
408
409 //================================================================
410 // Function : getName
411 // Purpose  :
412 //================================================================
413 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
414 {
415   SUIT_Session* session = SUIT_Session::session();
416   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
417   if ( app )
418   {
419     CORBA::String_var IOR = app->orb()->object_to_string( object );
420     if ( strcmp(IOR.in(), "") != 0 )
421     {
422       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
423       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
424
425       _PTR(GenericAttribute) anAttr;
426
427       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
428       {
429         _PTR(AttributeName) aNameAttr( anAttr );
430         return aNameAttr->Value();
431       }
432     }
433   }
434
435   return "";
436 }
437
438 //=================================================================
439 /*!
440  *  GEOM_Displayer::GEOM_Displayer
441  *  Constructor
442  */
443 //=================================================================
444 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
445 {
446   if( st )
447     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
448   else
449     myApp = 0;
450
451   /* Shading Color */
452   SUIT_Session* session = SUIT_Session::session();
453   SUIT_ResourceMgr* resMgr = session->resourceMgr();
454
455   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
456   myShadingColor = SalomeApp_Tools::color( col );
457
458   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
459   myHasDisplayMode = false;
460
461   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
462   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
463   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
464   
465   myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
466   myHasTransparency = false;
467
468   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
469   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
470   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
471
472   myColor = -1;
473   // This color is used for shape displaying. If it is equal -1 then
474   // default color is used.
475   myTexture = "";
476
477   myWidth = -1;
478   myType = -1;
479   myToActivate = true;
480   // This parameter is used for activisation/deactivisation of objects to be displayed
481
482   // Activate parallel vizualisation only for testing purpose
483   // and if the corresponding env variable is set to 1
484   char* parallel_visu = getenv("PARALLEL_VISU");
485   if (parallel_visu && atoi(parallel_visu))
486   {
487     MESSAGE("Parallel visualisation on");
488     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
489   }
490
491   myViewFrame = 0;
492
493   myFieldDataType = GEOM::FDT_Double;
494   myFieldDimension = 0;
495   myFieldStepRangeMin = 0;
496   myFieldStepRangeMax = 0;
497 }
498
499 //=================================================================
500 /*!
501  *  GEOM_Displayer::~GEOM_Displayer
502  *  Destructor
503  */
504 //=================================================================
505 GEOM_Displayer::~GEOM_Displayer()
506 {
507 }
508
509 //=================================================================
510 /*!
511  *  GEOM_Displayer::Display
512  *  Display interactive object in the current viewer
513  */
514 //=================================================================
515 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
516                              const bool updateViewer,
517                              SALOME_View* theViewFrame )
518 {
519   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
520   if ( vf )
521   {
522     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
523
524     if ( prs )
525     {
526       vf->BeforeDisplay( this, prs );
527       vf->Display( prs );
528       vf->AfterDisplay( this, prs );
529
530       if ( updateViewer )
531         vf->Repaint();
532
533       int aMgrId = getViewManagerId(vf);
534       SalomeApp_Study* aStudy = getStudy();
535       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
536
537       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
538
539       delete prs;  // delete presentation because displayer is its owner
540     }
541   }
542 }
543
544 //=================================================================
545 /*!
546  *  GEOM_Displayer::Display
547  *  This overloaded Display() method can be useful for operations
548  *  not using dialog boxes.
549  */
550 //=================================================================
551 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
552 {
553   if ( theObj->_is_nil() )
554     return;
555
556   std::string entry = getEntry( theObj );
557   if ( entry != "" ) {
558     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
559             updateViewer);
560   }
561 }
562
563 //=================================================================
564 /*!
565  *  GEOM_Displayer::Erase
566  *  Erase interactive object in the current viewer
567  */
568 //=================================================================
569 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
570                             const bool forced,
571                             const bool updateViewer,
572                             SALOME_View* theViewFrame )
573 {
574   if ( theIO.IsNull() )
575     return;
576
577   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
578
579   if ( vf ) {
580     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
581     if ( prs ) {
582       vf->BeforeErase( this, prs );
583       vf->Erase( prs, forced );
584       vf->AfterErase( this, prs );
585       if ( updateViewer )
586         vf->Repaint();
587       delete prs;  // delete presentation because displayer is its owner
588
589       int aMgrId = getViewManagerId(vf);
590       SalomeApp_Study* aStudy = getStudy();
591       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
592
593       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
594     }
595   }
596 }
597
598 //=================================================================
599 /*!
600  *  GEOM_Displayer::Erase
601  *  Erase geometry object in the current viewer
602  */
603 //=================================================================
604 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
605                             const bool forced,
606                             const bool updateViewer,
607                             SALOME_View* theViewFrame)
608 {
609   std::string entry = getEntry( theObj );
610   if ( entry != "" )
611   {
612     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
613           forced, updateViewer, theViewFrame);
614   }
615 }
616
617 //=================================================================
618 /*!
619  *  GEOM_Displayer::Redisplay
620  *  Redisplay (erase and then display again) interactive object
621  *  in the current viewer
622  */
623 //=================================================================
624 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
625                                 const bool updateViewer,
626                                 const bool checkActiveViewer )
627 {
628   // Remove the object permanently (<forced> == true)
629   SUIT_Session* ses = SUIT_Session::session();
630   SUIT_Application* app = ses->activeApplication();
631   if ( app )
632   {
633     SUIT_Desktop* desk = app->desktop();
634     QList<SUIT_ViewWindow*> wnds = desk->windows();
635     SUIT_ViewWindow* wnd;
636     QListIterator<SUIT_ViewWindow*> it( wnds );
637     while ( it.hasNext() && (wnd = it.next()) )
638     {
639       SUIT_ViewManager* vman = wnd->getViewManager();
640       if ( vman )
641       {
642         SUIT_ViewModel* vmodel = vman->getViewModel();
643         if ( vmodel )
644         {
645           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
646           if ( view )
647           {
648             if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
649             {
650               Redisplay( theIO, updateViewer, view );
651             }
652           }
653         }
654       }
655     }
656   }
657 }
658
659 //=================================================================
660 /*!
661  *  GEOM_Displayer::Redisplay
662  *  Redisplay (erase and then display again) interactive object
663  *  in the specified view
664  */
665 //=================================================================
666 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
667                                 const bool theUpdateViewer,
668                                 SALOME_View* theViewFrame )
669 {
670   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
671   if ( !vf )
672   {
673     return;
674   }
675
676   Erase( theIO, true, false, theViewFrame );
677   Display( theIO, theUpdateViewer, theViewFrame );
678 }
679
680 //=================================================================
681 /*!
682  *  GEOM_Displayer::Display
683  *  Calls Display() method for each object in the given list
684  */
685 //=================================================================
686 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
687 {
688   SALOME_ListIteratorOfListIO Iter( theIOList );
689   for ( ; Iter.More(); Iter.Next() ) {
690     Display( Iter.Value(), false );
691   }
692   if ( updateViewer )
693     UpdateViewer();
694 }
695
696 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
697 {
698   // VSR: this method can be improved in future:
699   // to improve performance, the default values from resource manager should be cached in the displayer
700   return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
701 }
702
703 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
704 {
705   // VSR: this method can be improved in future:
706   // to improve performance, the default values from resource manager should be cached in the displayer
707   return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
708 }
709
710 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
711 {
712   // check that shape is not null
713   if ( AISShape.IsNull() ) return;
714   
715   // check that study is active
716   SalomeApp_Study* study = getStudy();
717   if ( !study ) return;
718
719   if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
720        !TopoDS_Iterator(myShape).More() )
721     return; // NPAL15983 (Bug when displaying empty groups)
722
723   // set interactive object
724
725   Handle( SALOME_InteractiveObject ) anIO;
726
727   if ( !myIO.IsNull() ) {
728     AISShape->setIO( myIO );
729     AISShape->SetOwner( myIO );
730     anIO = myIO;
731   }
732   else if ( !myName.empty() ) {
733     // workaround to allow selection of temporary objects
734     static int tempId = 0;
735     anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
736     AISShape->setIO( anIO );
737     AISShape->SetOwner( anIO );
738   }
739
740   // flag:  only vertex or compound of vertices is processed (specific handling)
741   bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
742   // presentation study entry (empty for temporary objects like preview)
743   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
744   // flag: temporary object
745   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
746   // currently active view window's ID (-1 if no active view)
747   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
748
749   // get presentation properties
750   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
751
752   // Temporary staff: vertex must be infinite for correct visualization
753   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
754
755   // set material
756   Material_Model material;
757   // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
758   if( !HasColor() )
759     material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
760   // - set front material properties
761   AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
762   AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
763   // - set back material properties
764   AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
765   AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
766   // - switch to default (both sides) facing mode
767   AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
768
769   // set colors
770
771   // - shading color
772   if ( HasColor()  ) {
773     // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
774     // we set it to the shape not taking into account material properties
775     AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
776   }
777   else if ( !material.isPhysical() ) {
778     // shading color from properties is used only for non-physical materials
779     AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
780   }
781
782   // - wireframe color
783   Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
784   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
785                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
786   AISShape->Attributes()->SetLineAspect( anAspect );
787   
788   // - unfree boundaries color
789   anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
790   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
791                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
792   AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
793   
794   // - free boundaries color
795   anAspect = AISShape->Attributes()->FreeBoundaryAspect();
796   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
797                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
798   AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
799   
800   // - standalone edges color
801   anAspect = AISShape->Attributes()->WireAspect();
802   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
803                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
804   AISShape->Attributes()->SetWireAspect( anAspect );
805   
806   // - color for edges in shading+edges mode
807   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
808
809   // set display mode
810   AISShape->SetDisplayMode( HasDisplayMode() ? 
811                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
812                             GetDisplayMode() :
813                             // display mode from properties
814                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
815
816   // - face boundaries color
817   if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
818     AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
819   anAspect = AISShape->Attributes()->FaceBoundaryAspect();
820   anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
821   AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
822
823   // set display vectors flag
824   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
825
826   // set display vertices flag
827   bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
828   AISShape->SetDisplayVertices( isVerticesMode );
829
830   // set transparency
831   if( HasTransparency() ) {
832     AISShape->SetTransparency( GetTransparency() );
833   } else {
834     AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
835   }
836
837   // set iso properties
838   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
839   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
840   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
841   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
842   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
843   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
844   uIsoAspect->SetColor( isosColor );
845   uIsoAspect->SetWidth( isosWidth );
846   uIsoAspect->SetNumber( uIsos );
847   vIsoAspect->SetColor( isosColor );
848   vIsoAspect->SetWidth( isosWidth );
849   vIsoAspect->SetNumber( vIsos );
850   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
851   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
852
853   // set deflection coefficient
854   // ... to avoid to small values of the coefficient, its lower value is limited 
855   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
856
857   // set texture
858   QString aImagePath;
859   if ( HasTexture() ) {
860     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
861     aImagePath = GetTexture().c_str();
862     if ( ! entry.isEmpty() ) {
863       // check that study is active
864       SalomeApp_Study* study = getActiveStudy();
865       if ( study ) {
866         // Store the texture in object properties for next displays
867         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
868         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
869         
870         // Update propeties map
871         propMap = getObjectProperties( study, entry, myViewFrame );
872       }
873     }
874   }
875   else {
876     aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
877   }
878
879   Handle(Image_PixMap) aPixmap;
880   if ( !aImagePath.isEmpty() )
881     aPixmap = cacheTextureFor( aImagePath, AISShape );
882   else
883     aPixmap = getDefaultTexture();
884
885   // apply image to shape
886   if ( !aPixmap.IsNull() ) {
887     AISShape->SetTexturePixMap( aPixmap );
888     AISShape->SetTextureMapOn();
889     AISShape->DisableTextureModulate();
890   }
891   else {
892     AISShape->SetTextureMapOff();
893   }
894
895   // set line width
896   AISShape->SetWidth( HasWidth() ?
897                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
898                       GetWidth() :
899                       // libe width from properties
900                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
901
902   // set top-level flag
903   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
904
905   // set point marker (for vertex / compound of vertices only)
906   if ( onlyVertex || isVerticesMode ) {
907     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
908     if ( aList.size() == 2 ) {
909       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
910       int aTypeOfMarker = aList[0].toInt();
911       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
912       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
913       anAspect->SetScale( aScaleOfMarker );
914       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
915       anAspect->SetColor( HasColor() ? 
916                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
917                           (Quantity_NameOfColor)GetColor() : 
918                           // color from properties
919                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
920       AISShape->Attributes()->SetPointAspect( anAspect );
921     }
922     else if ( aList.size() == 1 ) {
923       // custom marker string contains "IdOfTexture"
924       int textureId = aList[0].toInt();
925       Standard_Integer aWidth, aHeight;
926       Handle(TColStd_HArray1OfByte) aTexture =
927         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
928       if ( !aTexture.IsNull() ) {
929         Handle(Prs3d_PointAspect) aTextureAspect =
930           new Prs3d_PointAspect( HasColor() ? 
931                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
932                                  (Quantity_NameOfColor)GetColor() : 
933                                  // color from properties 
934                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
935                                  aWidth, aHeight,
936                                  aTexture );
937         AISShape->Attributes()->SetPointAspect( aTextureAspect );
938       }
939     }
940   }
941
942   // set field step data
943   AISShape->setFieldStepInfo( myFieldDataType,
944                               myFieldDimension,
945                               myFieldStepData,
946                               myFieldStepName,
947                               myFieldStepRangeMin,
948                               myFieldStepRangeMax );
949
950   if ( create && !isTemporary && aMgrId != -1 ) {
951     // set properties to the study
952     study->setObjectPropMap( aMgrId, entry, propMap );
953   }
954
955   // AISShape->SetName(???); ??? necessary to set name ???
956 }
957
958 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
959 {
960   // check that actor is not null
961   if ( !actor ) return;
962   
963   // check that study is active
964   SalomeApp_Study* study = getStudy();
965   if ( !study ) return;
966
967   // set interactive object
968
969   Handle( SALOME_InteractiveObject ) anIO;
970
971   if ( !myIO.IsNull() ) {
972     actor->setIO( myIO );
973     anIO = myIO;
974   }
975   else if ( !myName.empty() ) {
976     // workaround to allow selection of temporary objects
977     static int tempId = 0;
978     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
979     actor->setIO( anIO );
980   }
981
982   // presentation study entry (empty for temporary objects like preview)
983   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
984   // flag: temporary object
985   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
986   // currently active view window's ID (-1 if no active view)
987   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
988
989   // get presentation properties
990   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
991   QColor c;
992
993   /////////////////////////////////////////////////////////////////////////
994   // VSR: for VTK viewer currently deflection coefficient is hardcoded
995   //      due to performance problem
996   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
997   /////////////////////////////////////////////////////////////////////////
998   if ( !actor->getTopo().IsSame( myShape ) )
999     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1000
1001   // set material
1002   Material_Model material;
1003   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1004   std::vector<vtkProperty*> mprops;
1005   mprops.push_back( material.getMaterialVTKProperty( true ) );
1006   mprops.push_back( material.getMaterialVTKProperty( false) );
1007   actor->SetMaterial( mprops );
1008
1009   // set iso-lines properties
1010
1011   // - set number of iso-lines
1012   int nbIsos[2]= { 1, 1 };
1013   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1014   nbIsos[0] = isos[0].toInt();
1015   nbIsos[1] = isos[1].toInt();
1016   actor->SetNbIsos( nbIsos );
1017
1018   // - set iso-lines width
1019   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1020
1021   // - set iso-lines color
1022   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1023   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1024
1025   // set colors
1026
1027   if ( HasColor()  ) {
1028     // - same color for all sub-actors
1029     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1030     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1031   }
1032   else {
1033     // shading color (for non-physical materials)
1034     if ( !material.isPhysical() ) {
1035       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1036       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1037       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1038     }
1039
1040     // - standalone edge color
1041     c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1042     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1043
1044     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1045     // - shared edges color ???
1046     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1047
1048     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1049     // - free edges color ???
1050     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1051
1052     // - point color
1053     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1054     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1055   }
1056
1057   // - color for edges in shading+edges mode
1058   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1059   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1060
1061   // set opacity
1062   if( HasTransparency() ) {
1063     actor->SetOpacity( 1.0 - GetTransparency() );
1064   } else {
1065     actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1066   }
1067
1068   // set line width
1069   actor->SetWidth( HasWidth() ?
1070                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1071                    GetWidth() :
1072                    // libe width from properties
1073                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1074   
1075   // set display vectors flag
1076   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1077
1078   // set display vertices flag
1079   actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1080
1081   // set display mode
1082   int displayMode = HasDisplayMode() ? 
1083     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
1084     GetDisplayMode() :
1085     // display mode from properties
1086     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1087
1088   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1089   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1090   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1091   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1092
1093   if ( displayMode == 2 )
1094       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1095       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1096     displayMode++;
1097   actor->setDisplayMode( displayMode );
1098
1099   if ( myToActivate )
1100     actor->PickableOn();
1101   else
1102     actor->PickableOff();
1103
1104   if ( create && !isTemporary && aMgrId != -1 ) {
1105     // set properties to the study
1106     study->setObjectPropMap( aMgrId, entry, propMap );
1107   }
1108 }
1109
1110 //=================================================================
1111 /*!
1112  *  GEOM_Displayer::updateDimensions
1113  *  Creates or renews dimension presentation for the IO.
1114  */
1115 //=================================================================
1116 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1117                                        SALOME_OCCPrs* thePrs,
1118                                        const gp_Ax3& theShapeLCS )
1119 {
1120   SalomeApp_Study* aStudy = getStudy();
1121   if ( !aStudy )
1122   {
1123     return;
1124   }
1125
1126   if ( theIO.IsNull() )
1127   {
1128     return;
1129   }
1130
1131   SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1132
1133   AIS_ListOfInteractive aListOfIO;
1134
1135   anOccPrs->GetObjects( aListOfIO );
1136
1137   AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1138
1139   // remove outdated presentations of dimensions
1140   for ( ; aIterateIO.More(); aIterateIO.Next() )
1141   {
1142     const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1143     if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1144     {
1145       continue;
1146     }
1147
1148     aListOfIO.Remove( aIterateIO );
1149
1150     if ( !aIterateIO.More() )
1151     {
1152       break;
1153     }
1154   }
1155
1156   // prepare dimension styling
1157   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1158
1159   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1160   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1161   double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1162   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1163   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1164   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1165   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1166
1167   // restore dimension presentation from saved attribute or property data
1168   AIS_ListOfInteractive aRestoredDimensions;
1169
1170   QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1171                                                   theIO->getEntry(),
1172                                                   GEOM::propertyName( GEOM::Dimensions ),
1173                                                   QVariant() );
1174
1175   GEOMGUI_DimensionProperty aRecords;
1176
1177   if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1178   {
1179     aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1180   }
1181   else
1182   {
1183     aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1184   }
1185   
1186   // create up-to-date dimension presentations
1187   for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1188   {
1189     if ( !aRecords.IsVisible( aPrsIt ) )
1190     {
1191       continue;
1192     }
1193
1194     // init dimension by type
1195     Handle(AIS_Dimension) aPrs;
1196     switch( aRecords.GetType( aPrsIt ) )
1197     {
1198       case GEOMGUI_DimensionProperty::DimensionType_Length :
1199       {
1200         Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1201         aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1202         aPrs = aLength;
1203         break;
1204       }
1205
1206       case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1207       {
1208         Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1209         aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1210         aPrs = aDiam;
1211         break;
1212       }
1213
1214       case GEOMGUI_DimensionProperty::DimensionType_Angle :
1215       {
1216         Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1217         aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1218         aPrs = anAng;
1219         break;
1220       }
1221     }
1222
1223     aPrs->SetOwner( theIO );
1224
1225     Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1226
1227     Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1228
1229     aStyle->SetCommonColor( aColor );
1230     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1231     aStyle->MakeText3d( Standard_True );
1232     aStyle->MakeTextShaded( Standard_True );
1233     aStyle->SetExtensionSize( aFontHeight * 0.5 );
1234     aStyle->TextAspect()->SetHeight( aFontHeight );
1235     aStyle->ArrowAspect()->SetLength( anArrowLength );
1236     aStyle->LineAspect()->SetWidth( aLineWidth );
1237     aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1238     aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1239     aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1240     aPrs->SetDimensionAspect( aStyle );
1241     aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1242     aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1243     aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1244
1245     if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1246     {
1247       // show degree symbol for dimension instead of label "deg"
1248       if ( aUnitsAngle == "deg" )
1249       {
1250         aPrs->SetSpecialSymbol(0xB0);
1251         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1252         aStyle->MakeUnitsDisplayed(Standard_False);
1253       }
1254       else
1255       {
1256         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1257         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1258       }
1259     }
1260     else
1261     {
1262       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1263     }
1264
1265     aListOfIO.Append( aPrs );
1266   }
1267
1268   // update presentation
1269   anOccPrs->Clear();
1270
1271   for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1272   {
1273     anOccPrs->AddObject( aIterateIO.Value() );
1274   }
1275 }
1276
1277 //=================================================================
1278 /*!
1279  *  GEOM_Displayer::Erase
1280  *  Calls Erase() method for each object in the given list
1281  */
1282 //=================================================================
1283 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1284                             const bool forced,
1285                             const bool updateViewer )
1286 {
1287   SALOME_ListIteratorOfListIO Iter( theIOList );
1288   for ( ; Iter.More(); Iter.Next() )
1289     Erase( Iter.Value(), forced, false );
1290
1291   if ( updateViewer )
1292     UpdateViewer();
1293 }
1294
1295 //=================================================================
1296 /*!
1297  *  GEOM_Displayer::Redisplay
1298  *  Calls Redisplay() method for each object in the given list
1299  */
1300 //=================================================================
1301 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1302                                 const bool updateViewer,
1303                                 const bool checkActiveViewer )
1304 {
1305   SALOME_ListIteratorOfListIO Iter( theIOList );
1306   for ( ; Iter.More(); Iter.Next() )
1307     Redisplay( Iter.Value(), false, checkActiveViewer );
1308
1309   if ( updateViewer )
1310     UpdateViewer();
1311 }
1312
1313 //=================================================================
1314 /*!
1315  *  GEOM_Displayer::Redisplay
1316  *  Calls Redisplay() method for each object in the given list
1317  */
1318 //=================================================================
1319 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1320                                 const bool theUpdateViewer,
1321                                 SALOME_View* theViewFrame )
1322 {
1323   SALOME_ListIteratorOfListIO anIter( theIOList );
1324   for ( ; anIter.More(); anIter.Next() )
1325   {
1326     Redisplay( anIter.Value(), false, theViewFrame );
1327   }
1328
1329   if ( theUpdateViewer )
1330   {
1331     UpdateViewer();
1332   }
1333 }
1334
1335 //=================================================================
1336 /*!
1337  *  GEOM_Displayer::Update
1338  *  Update OCC presentaion
1339  *  [ Reimplemented from SALOME_Displayer ]
1340  */
1341 //=================================================================
1342 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1343 {
1344   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1345   SalomeApp_Study* study = getStudy();
1346
1347   if ( !occPrs || myShape.IsNull() || !study )
1348     return;
1349
1350   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1351   {
1352     // 
1353     // specific processing for local coordinate system presentation
1354     // 
1355
1356     TopoDS_Face aFace = TopoDS::Face( myShape );
1357     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1358     if ( !aPlane.IsNull() )
1359     {
1360       gp_Ax3 aPos = aPlane->Pln().Position();
1361       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1362
1363       Handle(GEOM_AISTrihedron) aTrh;
1364
1365       if ( occPrs->IsNull() )
1366       {
1367         // new presentation is being created
1368         aTrh = new GEOM_AISTrihedron( aPlc );
1369         occPrs->AddObject( aTrh );
1370       }
1371       else
1372       {
1373         // presentation is being updated
1374         AIS_ListOfInteractive aList;
1375         occPrs->GetObjects( aList );
1376         AIS_ListIteratorOfListOfInteractive anIter( aList );
1377         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1378           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1379         }
1380       }
1381         
1382       if ( !aTrh.IsNull() ) {
1383         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1384         if ( HasColor() )
1385           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1386         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1387         if ( HasWidth() )
1388           aTrh->SetWidth( GetWidth() );
1389         
1390         if ( !myIO.IsNull() )
1391         {
1392           aTrh->setIO( myIO );
1393           aTrh->SetOwner( myIO );
1394         }
1395         aTrh->SetComponent( aPlc );
1396         aTrh->SetToUpdate();
1397       }
1398       occPrs->SetToActivate( ToActivate() );
1399     }
1400   }
1401   else
1402   {
1403     // 
1404     // processing for usual geometry presentation
1405     // 
1406
1407     // if presentation is empty we try to create new one
1408     if ( occPrs->IsNull() )
1409     {
1410       // create presentation (specific for vectors)
1411       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1412                                                                  : new GEOM_AISShape ( myShape, "" );
1413
1414       if( myType == GEOM_FIELD_STEP )
1415         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1416       // update shape properties
1417       updateShapeProperties( AISShape, true );
1418
1419       // add shape to the presentation
1420       occPrs->AddObject( AISShape );
1421
1422       // In accordance with ToActivate() value object will be activated/deactivated
1423       // when it will be displayed
1424       occPrs->SetToActivate( ToActivate() );
1425
1426       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1427         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1428
1429         // create additional wireframe shape
1430         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1431         aWirePrs->SetWidth(AISShape->Width());
1432         if ( !myIO.IsNull() ) {
1433           aWirePrs->setIO( myIO );
1434           aWirePrs->SetOwner( myIO );
1435         }
1436
1437         // add shape to the presentation
1438         occPrs->AddObject( aWirePrs );
1439       }
1440     }
1441     // if presentation is found -> set again shape for it
1442     else
1443     {
1444       AIS_ListOfInteractive IOList;
1445       occPrs->GetObjects( IOList );
1446       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1447       for ( ; Iter.More(); Iter.Next() )
1448       {
1449         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1450         if ( AISShape.IsNull() )
1451           continue;
1452
1453         // re-set shape (it might be changed)
1454         if ( AISShape->Shape() != myShape )
1455           AISShape->Set( myShape );
1456
1457         // update shape properties
1458         updateShapeProperties( AISShape, false );
1459
1460         // force updating
1461         AISShape->UpdateSelection();
1462         AISShape->SetToUpdate();
1463       }
1464     }
1465
1466     updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1467   }
1468 }
1469
1470 //=================================================================
1471 /*!
1472  *  GEOM_Displayer::Update
1473  *  Update VTK presentaion
1474  *  [ Reimplemented from SALOME_Displayer ]
1475  */
1476 //=================================================================
1477 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1478 {
1479   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1480   SalomeApp_Study* study = getStudy();
1481
1482   if ( !vtkPrs || myShape.IsNull() || !study )
1483     return;
1484
1485   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1486   {
1487     // 
1488     // specific processing for local coordinate system presentation
1489     // 
1490
1491     TopoDS_Face aFace = TopoDS::Face( myShape );
1492     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1493     if ( !aPlane.IsNull() ) {
1494       gp_Ax3 aPos = aPlane->Pln().Position();
1495       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1496
1497       GEOM_VTKTrihedron* aTrh = 0;
1498
1499       if ( vtkPrs->IsNull() ) {
1500         // new presentation is being created
1501         aTrh = GEOM_VTKTrihedron::New();
1502         vtkPrs->AddObject( aTrh );
1503       }
1504       else {
1505         // presentation is being updated
1506         vtkActorCollection* actors = vtkPrs->GetObjects();
1507         if ( actors ) {
1508           actors->InitTraversal();
1509           vtkActor* a = actors->GetNextActor();
1510           while ( a && !aTrh ) {
1511             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1512             a = actors->GetNextActor();
1513           }
1514         }
1515       }
1516       
1517       if ( aTrh ) {
1518         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1519         if ( HasColor() ) {
1520           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1521           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1522         }
1523 #ifdef VTK_TRIHEDRON_WIDTH
1524         // 
1525         // VSR: currently isn't supported
1526         //
1527         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1528         if ( HasWidth() )
1529           aTrh->SetWidth( GetWidth() );
1530 #endif
1531
1532         if ( !myIO.IsNull() )
1533           aTrh->setIO( myIO );
1534
1535         aTrh->SetPlacement( aPlc );
1536       }
1537     }
1538   }
1539   else
1540   {
1541     // 
1542     // processing for usual geometry presentation
1543     // 
1544
1545     // if presentation is empty we try to create new one
1546     if ( vtkPrs->IsNull() )
1547     {
1548       // create an actor
1549       GEOM_Actor* actor = GEOM_Actor::New();
1550       // update actor properties
1551       updateActorProperties( actor, true );
1552       // add actor to the presentation
1553       vtkPrs->AddObject( actor );
1554     }
1555     else {
1556       // presentation is being updated
1557       vtkActorCollection* actors = vtkPrs->GetObjects();
1558       if ( actors ) {
1559         actors->InitTraversal();
1560         vtkActor* a = actors->GetNextActor();
1561         while ( a ) {
1562           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1563           if ( actor ) {
1564             // update actor properties
1565             updateActorProperties( actor, false );
1566             a = actors->GetNextActor();
1567           }
1568         }
1569       }
1570     }
1571   }
1572 }
1573
1574 //=================================================================
1575 /*!
1576  *  GEOM_Displayer::BuildPrs
1577  *  Build presentation accordint to the current viewer type
1578  */
1579 //=================================================================
1580 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1581 {
1582   if ( theObj->_is_nil() )
1583     return 0;
1584
1585   myViewFrame = GetActiveView();
1586   if ( myViewFrame == 0 )
1587     return 0;
1588
1589   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1590   if ( aPrs == 0 )
1591     return 0;
1592
1593   internalReset();
1594   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1595   myType = theObj->GetType();
1596
1597   // Update presentation
1598   UpdatePrs( aPrs );
1599
1600   return aPrs;
1601 }
1602
1603 //=================================================================
1604 /*!
1605  *  GEOM_Displayer::BuildPrs
1606  *  Build presentation accordint to the current viewer type
1607  */
1608 //=================================================================
1609 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1610 {
1611   myViewFrame = GetActiveView();
1612   if ( theShape.IsNull() || myViewFrame == 0 )
1613     return 0;
1614
1615   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1616   if ( aPrs == 0 )
1617     return 0;
1618
1619   internalReset();
1620   setShape( theShape );
1621   myType = -1;
1622
1623   UpdatePrs( aPrs );
1624
1625   return aPrs;
1626 }
1627
1628 //=================================================================
1629 /*!
1630  *  GEOM_Displayer::buildPresentation
1631  *  Builds/finds object's presentation for the current viewer
1632  *  Calls corresponding Update() method by means of double dispatch
1633  *  [ internal ]
1634  */
1635 //=================================================================
1636 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1637                                                SALOME_View* theViewFrame )
1638 {
1639   SALOME_Prs* prs = 0;
1640   internalReset();
1641
1642   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1643
1644   if ( myViewFrame )
1645   {
1646     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1647     if ( prs )
1648     {
1649       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1650       theIO->setEntry( entry.toLatin1().constData() );
1651       if ( !theIO.IsNull() )
1652       {
1653         // set interactive object
1654         setIO( theIO );
1655         //  Find SOBject (because shape should be published previously)
1656         SUIT_Session* session = SUIT_Session::session();
1657         SUIT_Application* app = session->activeApplication();
1658         if ( app )
1659         {
1660           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1661           if ( study )
1662           {
1663             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1664             if ( SO )
1665             {
1666               // get CORBA reference to data object
1667               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1668               if ( !CORBA::is_nil( object ) )
1669               {
1670                 // downcast to GEOM base object
1671                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1672                 if ( !GeomBaseObject->_is_nil() )
1673                 {
1674                   myType = GeomBaseObject->GetType();
1675
1676                   // downcast to GEOM object
1677                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1678                   if ( myType == GEOM_FIELD_STEP )
1679                   {
1680                     // get the GEOM object from the field's shape
1681                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1682                     if ( !GeomFieldStep->_is_nil() )
1683                     {
1684                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1685                       if ( !GeomField->_is_nil() )
1686                         GeomObject = GeomField->GetShape();
1687                     }
1688
1689                     // read the field step information
1690                     readFieldStepInfo( GeomFieldStep );
1691                   }
1692
1693                   if ( !GeomObject->_is_nil() )
1694                   {
1695                     // finally set shape
1696                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1697                   }
1698                 }
1699               }
1700             }
1701           }
1702         }
1703       }
1704       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1705     }
1706   }
1707   return prs;
1708 }
1709
1710 //=================================================================
1711 /*!
1712  *  GEOM_Displayer::buildSubshapePresentation
1713  *  Builds/finds object's presentation for the current viewer
1714  *  Calls corresponding Update() method by means of double dispatch
1715  *  For not published objects (for Mantis issue 0020435)
1716  */
1717 //=================================================================
1718 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1719                                                       const QString& entry,
1720                                                       SALOME_View* theViewFrame)
1721 {
1722   SALOME_Prs* prs = 0;
1723   internalReset();
1724
1725   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1726
1727   if (myViewFrame)
1728   {
1729     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1730     if (prs)
1731     {
1732       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1733       theIO->setEntry(entry.toLatin1().constData());
1734       if (!theIO.IsNull())
1735       {
1736         // set interactive object
1737         setIO(theIO);
1738         // finally set shape
1739         setShape(aShape);
1740         myType = GEOM_SUBSHAPE;
1741       }
1742       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1743     }
1744   }
1745   return prs;
1746 }
1747
1748 //=================================================================
1749 /*!
1750  *  GEOM_Displayer::internalReset
1751  *  Resets internal data
1752  *  [internal]
1753  */
1754 //=================================================================
1755 void GEOM_Displayer::internalReset()
1756 {
1757   myIO.Nullify();
1758   myShape.Nullify();
1759
1760   myFieldDataType = GEOM::FDT_Double;
1761   myFieldDimension = 0;
1762   myFieldStepData.clear();
1763   myFieldStepName.Clear();
1764   myFieldStepRangeMin = 0;
1765   myFieldStepRangeMax = 0;
1766 }
1767
1768 //=================================================================
1769 /*!
1770  *  GEOM_Displayer::LocalSelection
1771  *  Activate selection of CAD shapes with activisation of selection
1772  *  of their sub-shapes (with opened local context for OCC viewer)
1773  */
1774 //=================================================================
1775 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1776 {
1777   SUIT_Session* session = SUIT_Session::session();
1778   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1779   if ( !app )
1780     return;
1781
1782   LightApp_SelectionMgr* sm = app->selectionMgr();
1783
1784   // remove all filters from selection
1785   sm->clearFilters();
1786
1787   SALOME_View* vf = GetActiveView();
1788   if ( vf ) {
1789     if (!theIO.IsNull() && !vf->isVisible(theIO))
1790       Display(theIO);
1791     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1792     vf->LocalSelection( prs, theMode );
1793     delete prs;  // delete presentation because displayer is its owner
1794   }
1795 }
1796
1797 //=================================================================
1798 /*!
1799  *  GEOM_Displayer::globalSelection
1800  *  Activate selection of CAD shapes without activisation of selection
1801  *  of their sub-shapes (without opened local context for OCC viewer)
1802  */
1803 //=================================================================
1804 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1805 {
1806   TColStd_MapOfInteger aModes;
1807   aModes.Add( theMode );
1808   GlobalSelection( aModes, update );
1809 }
1810
1811 //=================================================================
1812 /*!
1813  *  GEOM_Displayer::globalSelection
1814  *  Activate selection of CAD shapes without activisation of selection
1815  *  of their sub-shapes (without opened local context for OCC viewer)
1816  */
1817 //=================================================================
1818 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1819                                       const bool update, const QList<int>* theSubShapes )
1820 {
1821   SUIT_Session* session = SUIT_Session::session();
1822   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1823   if ( !app )
1824     return;
1825
1826   SALOME_View* vf = GetActiveView();
1827   if ( vf == 0 )
1828     return;
1829
1830   // Close local context
1831   vf->GlobalSelection( update );
1832
1833   // Set selection filters in accordance with current mode
1834   LightApp_SelectionMgr* sm = app->selectionMgr();
1835   if ( !sm )
1836     return;
1837
1838   // Remove from selection temporary objects if necessary
1839   if ( !theModes.Contains( GEOM_PREVIEW ) )
1840     clearTemporary( sm );
1841
1842   //@ aSel->ClearIndex();
1843
1844   sm->clearFilters();
1845
1846   // Remove filters from AIS_InteractiveContext
1847   Handle(AIS_InteractiveContext) ic;
1848   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1849   if ( viewer )
1850     {
1851       ic = viewer->getAISContext();
1852       if ( !ic.IsNull() )
1853         ic->RemoveFilters();
1854     }
1855
1856   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1857     return;
1858
1859   SUIT_SelectionFilter* aFilter;
1860   if ( theModes.Extent() == 1 )
1861     {
1862       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1863
1864       if ( aMode == GEOM_COMPOUNDFILTER )
1865         aFilter = getComplexFilter( theSubShapes );
1866       else
1867         aFilter = getFilter( aMode );
1868     }
1869   else if ( theModes.Extent() > 1 )
1870     {
1871       TColStd_MapOfInteger aTopAbsModes;
1872       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1873       QList<SUIT_SelectionFilter*> aListOfFilters;
1874       for ( ; anIter.More(); anIter.Next() )
1875         {
1876           SUIT_SelectionFilter* aFilter;
1877           int aMode = anIter.Key();
1878           if ( aMode == GEOM_COMPOUNDFILTER )
1879             aFilter = getComplexFilter( theSubShapes );
1880           else
1881             aFilter = getFilter( aMode );
1882
1883           if ( aFilter )
1884             aListOfFilters.append( aFilter );
1885         }
1886
1887       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1888     }
1889   else
1890     return;
1891
1892   if ( aFilter )
1893     {
1894       sm->installFilter( aFilter );
1895       if ( !ic.IsNull() )
1896         {
1897           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1898           ic->AddFilter( anOCCFilter );
1899         }
1900     }
1901 }
1902
1903 //=================================================================
1904 /*!
1905  *  GEOM_Displayer::LocalSelection
1906  *  Activate selection of CAD shapes with activisation of selection
1907  *  of their sub-shapes (with opened local context for OCC viewer)
1908  */
1909 //=================================================================
1910 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1911 {
1912   SALOME_ListIteratorOfListIO Iter( theIOList );
1913   for ( ; Iter.More(); Iter.Next() )
1914     LocalSelection( Iter.Value(), theMode );
1915 }
1916
1917 //=================================================================
1918 /*!
1919  *  GEOM_Displayer::BeforeDisplay
1920  *  Called before displaying of pars. Close local context
1921  *  [ Reimplemented from SALOME_Displayer ]
1922  */
1923 //=================================================================
1924 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1925 {
1926   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1927   if ( vf )
1928   {
1929     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1930     if ( !ic.IsNull() )
1931     {
1932       if ( ic->HasOpenedContext() )
1933       ic->CloseAllContexts();
1934     }
1935   }
1936 }
1937
1938 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1939 {
1940   UpdateColorScale(false,false);
1941 }
1942
1943 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
1944 {
1945   LightApp_Displayer::BeforeErase( v, p );
1946   releaseTextures( p );
1947 }
1948
1949 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1950 {
1951   LightApp_Displayer::AfterErase( v, p );
1952   UpdateColorScale(false,false);
1953 }
1954
1955 //=================================================================
1956 /*!
1957  *  GEOM_Displayer::SetColor
1958  *  Set color for shape displaying. If it is equal -1 then default color is used.
1959  *  Available values are from Quantity_NameOfColor enumeration
1960  */
1961 //=================================================================
1962 void GEOM_Displayer::SetColor( const int color )
1963 {
1964   if ( color == -1 )
1965     UnsetColor();
1966   else
1967   {
1968     myColor = color;
1969     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1970   }
1971 }
1972
1973 int GEOM_Displayer::GetColor() const
1974 {
1975   return myColor;
1976 }
1977
1978 bool GEOM_Displayer::HasColor() const
1979 {
1980   return myColor != -1;
1981 }
1982
1983 void GEOM_Displayer::UnsetColor()
1984 {
1985   myColor = -1;
1986
1987   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1988   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1989   myShadingColor = SalomeApp_Tools::color( col );
1990 }
1991
1992 //=================================================================
1993 /*!
1994  *  GEOM_Displayer::SetTransparency
1995  *  Set transparency for shape displaying.
1996  */
1997 //=================================================================
1998 double GEOM_Displayer::SetTransparency( const double transparency )
1999 {
2000   double aPrevTransparency = myTransparency;
2001   if ( transparency < 0 ) {
2002     UnsetTransparency();
2003   }
2004   else {
2005     myTransparency = transparency;
2006     myHasTransparency = true;
2007   }
2008   return aPrevTransparency;
2009 }
2010
2011 //=================================================================
2012 /*!
2013  *  GEOM_Displayer::GetTransparency
2014  *  Get transparency for shape displaying.
2015  */
2016 //=================================================================
2017 double GEOM_Displayer::GetTransparency() const
2018 {
2019   return myTransparency;
2020 }
2021
2022 //=================================================================
2023 /*!
2024  *  GEOM_Displayer::HasTransparency
2025  *  Check if transparency for shape displaying is set.
2026  */
2027 //=================================================================
2028 bool GEOM_Displayer::HasTransparency() const
2029 {
2030   return myHasTransparency;
2031 }
2032
2033 //=================================================================
2034 /*!
2035  *  GEOM_Displayer::UnsetTransparency
2036  *  Unset transparency for shape displaying.
2037  */
2038 //=================================================================
2039 double GEOM_Displayer::UnsetTransparency()
2040 {
2041   double aPrevTransparency = myTransparency;
2042   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2043   myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
2044   myHasTransparency = false;
2045   return aPrevTransparency;
2046 }
2047
2048
2049 //=================================================================
2050 /*!
2051  *  GEOM_Displayer::SetTexture
2052  *  Set color for shape displaying. If it is equal -1 then default color is used.
2053  *  Available values are from Quantity_NameOfColor enumeration
2054  */
2055 //=================================================================
2056 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2057 {
2058   if(texureFileName!="")
2059   {
2060     myTexture = texureFileName;
2061   }
2062 }
2063
2064 bool GEOM_Displayer::HasTexture() const
2065 {
2066   return myTexture != "";
2067 }
2068
2069 std::string GEOM_Displayer::GetTexture() const
2070 {
2071   return myTexture;
2072 }
2073
2074 //=================================================================
2075 /*!
2076  *  GEOM_Displayer::SetWidth
2077  *  Set width of shape displaying. If it is equal -1 then default width is used.
2078  */
2079 //=================================================================
2080 void GEOM_Displayer::SetWidth( const double width )
2081 {
2082   myWidth = width;
2083 }
2084
2085 double GEOM_Displayer::GetWidth() const
2086 {
2087   return myWidth;
2088 }
2089
2090 bool GEOM_Displayer::HasWidth() const
2091 {
2092   return myWidth != -1;
2093 }
2094
2095 void GEOM_Displayer::UnsetWidth()
2096 {
2097   myWidth = -1;
2098 }
2099
2100
2101 int GEOM_Displayer::GetIsosWidth() const
2102 {
2103   return myIsosWidth;
2104 }
2105
2106 void GEOM_Displayer::SetIsosWidth(const int width)
2107 {
2108   myIsosWidth = width;
2109 }
2110
2111 bool GEOM_Displayer::HasIsosWidth() const
2112 {
2113   return myIsosWidth != -1;
2114 }
2115
2116
2117 //=================================================================
2118 /*!
2119  *  GEOM_Displayer::SetToActivate
2120  *  This method is used for activisation/deactivisation of objects to be displayed
2121  */
2122 //=================================================================
2123 void GEOM_Displayer::SetToActivate( const bool toActivate )
2124 {
2125   myToActivate = toActivate;
2126 }
2127 bool GEOM_Displayer::ToActivate() const
2128 {
2129   return myToActivate;
2130 }
2131
2132 //=================================================================
2133 /*!
2134  *  GEOM_Displayer::clearTemporary
2135  *  Removes from selection temporary objects
2136  */
2137 //=================================================================
2138 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2139 {
2140   SALOME_ListIO selected, toSelect;
2141   theSelMgr->selectedObjects( selected );
2142
2143   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2144     Handle(SALOME_InteractiveObject) io = it.Value();
2145     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2146       toSelect.Append( it.Value() );
2147   }
2148
2149   theSelMgr->setSelectedObjects( toSelect, true );
2150 }
2151
2152 void GEOM_Displayer::SetName( const char* theName )
2153 {
2154   myName = theName;
2155 }
2156
2157 void GEOM_Displayer::UnsetName()
2158 {
2159   myName = "";
2160 }
2161
2162 SalomeApp_Study* GEOM_Displayer::getStudy() const
2163 {
2164   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2165 }
2166
2167 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2168 {
2169   myIO = theIO;
2170 }
2171
2172 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2173 {
2174   myShape = theShape;
2175 }
2176
2177 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2178                                        const int theFieldDimension,
2179                                        const QList<QVariant>& theFieldStepData,
2180                                        const TCollection_AsciiString& theFieldStepName,
2181                                        const double theFieldStepRangeMin,
2182                                        const double theFieldStepRangeMax )
2183 {
2184   myFieldDataType = theFieldDataType;
2185   myFieldDimension = theFieldDimension;
2186   myFieldStepData = theFieldStepData;
2187   myFieldStepName = theFieldStepName;
2188   myFieldStepRangeMin = theFieldStepRangeMin;
2189   myFieldStepRangeMax = theFieldStepRangeMax;
2190 }
2191
2192 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2193 {
2194   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2195   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2196   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2197   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2198   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2199          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2200 }
2201
2202 int GEOM_Displayer::SetDisplayMode( const int theMode )
2203 {
2204   int aPrevMode = myDisplayMode;
2205   if ( theMode != -1 ) {
2206     myDisplayMode = theMode;
2207     myHasDisplayMode = true;
2208   }
2209   else {
2210     UnsetDisplayMode();
2211   }
2212   return aPrevMode;
2213 }
2214
2215 int GEOM_Displayer::GetDisplayMode() const
2216 {
2217   return myDisplayMode;
2218 }
2219
2220 int GEOM_Displayer::UnsetDisplayMode()
2221 {
2222   int aPrevMode = myDisplayMode;
2223   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2224   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2225   myHasDisplayMode = false;
2226   return aPrevMode;
2227 }
2228
2229 bool GEOM_Displayer::HasDisplayMode() const
2230 {
2231   return myHasDisplayMode;
2232 }
2233
2234 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2235 {
2236   static QList<QColor> colors;
2237
2238   if ( colors.isEmpty() ) {
2239
2240     for (int s = 0; s < 2 ; s++)
2241     {
2242       for (int v = 100; v >= 40; v = v - 20)
2243       {
2244         for (int h = 0; h < 359 ; h = h + 60)
2245         {
2246           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2247         }
2248       }
2249     }
2250   }
2251
2252   static int currentColor = 0;
2253
2254   SALOMEDS::Color color;
2255   color.R = (double)colors[currentColor].red()   / 255.0;
2256   color.G = (double)colors[currentColor].green() / 255.0;
2257   color.B = (double)colors[currentColor].blue()  / 255.0;
2258
2259   currentColor = (currentColor+1) % colors.count();
2260
2261   return color;
2262 }
2263
2264 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2265 {
2266   int aHue = -1;
2267   int aTolerance = 64;
2268   int anIterations = 0;
2269   int aPeriod = 5;
2270
2271   while( 1 )
2272   {
2273     anIterations++;
2274     if( anIterations % aPeriod == 0 )
2275     {
2276       aTolerance /= 2;
2277       if( aTolerance < 1 )
2278         break;
2279     }
2280     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2281
2282     aHue = (int)( 360.0 * rand() / RAND_MAX );
2283     //std::cout << "Hue = " << aHue << std::endl;
2284
2285     //std::cout << "Auto colors : ";
2286     bool ok = true;
2287     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2288     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2289     for( ; it != itEnd; ++it )
2290     {
2291       SALOMEDS::Color anAutoColor = *it;
2292       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2293
2294       int h, s, v;
2295       aQColor.getHsv( &h, &s, &v );
2296       //std::cout << h << " ";
2297       if( abs( h - aHue ) < aTolerance )
2298       {
2299         ok = false;
2300         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2301         break;
2302       }
2303     }
2304     //std::cout << std::endl;
2305
2306     if( ok )
2307       break;
2308   }
2309
2310   //std::cout << "Hue of the returned color = " << aHue << std::endl;
2311   QColor aColor;
2312   aColor.setHsv( aHue, 255, 255 );
2313
2314   SALOMEDS::Color aSColor;
2315   aSColor.R = (double)aColor.red() / 255.0;
2316   aSColor.G = (double)aColor.green() / 255.0;
2317   aSColor.B = (double)aColor.blue() / 255.0;
2318
2319   return aSColor;
2320 }
2321
2322 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2323                                              const QString& entry,
2324                                              SALOME_View* view )
2325 {
2326   // get default properties for the explicitly specified default view type
2327   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2328
2329   if ( study && view ) {
2330     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2331     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2332     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2333   
2334     if ( viewModel && viewId != -1 ) {
2335       // get properties from the study
2336       PropMap storedMap = study->getObjectPropMap( viewId, entry );
2337       // overwrite default properties from stored ones (that are specified)
2338       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2339         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2340           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
2341                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2342       }
2343       // ... specific processing for color
2344       // ... current implementation is to use same stored color for all aspects
2345       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2346       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2347         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2348         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2349         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2350         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2351         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2352       }
2353
2354       if ( !entry.isEmpty() ) {
2355         // get CORBA reference to geom object
2356         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2357         if ( SO ) {
2358           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2359           if ( !CORBA::is_nil( object ) ) {
2360             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2361             if ( !CORBA::is_nil( geomObject ) ) { // to check
2362               // check that geom object has color properly set
2363               bool hasColor = false;
2364               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2365               // set color from geometry object (only once, if it is not yet set in GUI)
2366               // current implementation is to use same color for all aspects
2367               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2368               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2369                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2370                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
2371                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2372                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
2373                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
2374                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
2375               }
2376               // check that object has point marker properly set
2377               GEOM::marker_type mType = geomObject->GetMarkerType();
2378               GEOM::marker_size mSize = geomObject->GetMarkerSize();
2379               int mTextureId = geomObject->GetMarkerTexture();
2380               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
2381                                ( mType == GEOM::MT_USER && mTextureId > 0 );
2382               // set point marker from geometry object (only once, if it is not yet set in GUI)
2383               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2384                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2385                   // standard type
2386                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2387                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2388                 }
2389                 else if ( mType == GEOM::MT_USER ) {
2390                   // custom texture
2391                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2392                 }
2393               }
2394             }
2395           }
2396         }
2397       }
2398     }
2399   }
2400   return propMap;
2401 }
2402
2403 PropMap GEOM_Displayer::getDefaultPropertyMap()
2404 {
2405   PropMap propMap;
2406
2407   // get resource manager
2408   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2409
2410   // fill in the properties map with default values
2411
2412   // - visibility (false by default)
2413   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2414
2415   // - nb isos (take default value from preferences)
2416   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2417                   QString( "%1%2%3" ).
2418                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2419                   arg( GEOM::subSectionSeparator() ).
2420                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2421
2422   // - transparency (opacity = 1-transparency)
2423   propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2424                   resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2425
2426   // - display mode (take default value from preferences)
2427   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2428                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2429
2430   // - show edges direction flag (false by default)
2431   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2432
2433   // - show vertices flag (false by default)
2434   propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2435
2436   // - shading color (take default value from preferences)
2437   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2438                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2439
2440   // - wireframe color (take default value from preferences)
2441   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2442                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2443
2444   // - standalone edges color (take default value from preferences)
2445   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2446                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2447
2448   // - free boundaries color (take default value from preferences)
2449   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2450                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2451
2452   // - points color (take default value from preferences)
2453   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2454                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2455
2456   // - isos color (take default value from preferences)
2457   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2458                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2459
2460   // - outlines color (take default value from preferences)
2461   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2462                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2463
2464   // - deflection coefficient (take default value from preferences)
2465   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2466                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2467
2468   // - material (take default value from preferences)
2469   Material_Model material;
2470   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2471   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2472
2473   // - edge width (take default value from preferences)
2474   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2475                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2476
2477   // - isos width (take default value from preferences)
2478   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2479                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2480
2481   // - point marker (take default value from preferences)
2482   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2483                   QString( "%1%2%3" ).
2484                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2485                   arg( GEOM::subSectionSeparator() ).
2486                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2487
2488   // - top-level flag (false by default)
2489   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2490
2491   return propMap;
2492 }
2493
2494 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2495   SALOMEDS::Color aSColor;
2496   hasColor = false;
2497
2498   SUIT_Session* session = SUIT_Session::session();
2499   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2500
2501   if ( app && !theGeomObject->_is_nil()) {
2502     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2503
2504     if ( study ) {
2505       _PTR(Study) aStudy = study->studyDS();
2506       aSColor = theGeomObject->GetColor();
2507       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2508       if ( !hasColor ) {
2509 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2510         bool general_autocolor = true;
2511 #else                    // auto-color for groups only
2512         bool general_autocolor = false;
2513 #endif                   // GENERAL_AUTOCOLOR
2514         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2515           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2516           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2517 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2518             aSColor = getPredefinedUniqueColor();
2519             hasColor = true;
2520 #else                    // old algorithm  for auto-colors
2521             QList<SALOMEDS::Color> aReservedColors;
2522             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2523             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2524             if ( aMainSObject ) {
2525               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2526               for ( ; it->More(); it->Next() ) {
2527                 _PTR(SObject) aChildSObject( it->Value() );
2528                 GEOM::GEOM_Object_var aChildObject =
2529                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2530                 if ( CORBA::is_nil( aChildObject ) )
2531                   continue;
2532
2533                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2534                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2535                   aReservedColors.append( aReservedColor );
2536               }
2537             }
2538             aSColor = getUniqueColor( aReservedColors );
2539             hasColor = true;
2540 #endif                   // SIMPLE_AUTOCOLOR
2541           }
2542         }
2543       }
2544     }
2545   }
2546   return aSColor;
2547 }
2548
2549
2550 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2551                                        const bool eraseOnlyChildren) {
2552   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2553   if ( !app )
2554     return;
2555
2556   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2557   if ( !appStudy )
2558     return;
2559
2560   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2561
2562   if( !parent)
2563     return;
2564
2565   // Erase from all views
2566   QList<SALOME_View*> views;
2567   SALOME_View* view;
2568   ViewManagerList vmans = app->viewManagers();
2569   SUIT_ViewManager* vman;
2570   foreach ( vman, vmans ) {
2571     SUIT_ViewModel* vmod = vman->getViewModel();
2572     view = dynamic_cast<SALOME_View*> ( vmod );
2573     if ( view )
2574       views.append( view );
2575   }
2576
2577   if( views.count() == 0 )
2578     return;
2579
2580   //Erase childrens w/o update views
2581   DataObjectList listObj = parent->children( true );
2582   SUIT_DataObject* obj;
2583   foreach( obj, listObj ) {
2584     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2585     if(l_obj)
2586       foreach ( view, views ) {
2587       Handle(SALOME_InteractiveObject) anIO =
2588         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2589       Erase(anIO, false, false, view);
2590     }
2591   }
2592
2593   //Erase parent with view update or repaint views
2594   foreach ( view, views ) {
2595     if(!eraseOnlyChildren)
2596       Erase(theIO, false, true, view);
2597     else
2598       view->Repaint();
2599   }
2600 }
2601
2602 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2603 {
2604   if( theGeomFieldStep->_is_nil() )
2605     return;
2606
2607   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2608   if( aGeomField->_is_nil() )
2609     return;
2610
2611   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2612   if( aGeomFieldShape->_is_nil() )
2613     return;
2614
2615   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2616   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2617   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2618
2619   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2620
2621   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2622
2623   int aFieldDimension = aGeomField->GetDimension();
2624
2625   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2626   int aFieldNbComponents = aFieldComponents->length();
2627
2628   QList<QVariant> aFieldStepData;
2629   if( aFieldDataType == GEOM::FDT_Bool )
2630   {
2631     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2632     if ( !aGeomBoolFieldStep->_is_nil() )
2633     {
2634       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2635       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2636         aFieldStepData << (bool)aValues[i];
2637     }
2638   }
2639   else if( aFieldDataType == GEOM::FDT_Int )
2640   {
2641     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2642     if ( !aGeomIntFieldStep->_is_nil() )
2643     {
2644       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2645       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2646         aFieldStepData << (qlonglong)aValues[i];
2647     }
2648   }
2649   else if( aFieldDataType == GEOM::FDT_Double )
2650   {
2651     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2652     if ( !aGeomDoubleFieldStep->_is_nil() )
2653     {
2654       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2655       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2656         aFieldStepData << (double)aValues[i];
2657     }
2658   }
2659   else if( aFieldDataType == GEOM::FDT_String )
2660   {
2661     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2662     if ( !aGeomStringFieldStep->_is_nil() )
2663     {
2664       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2665       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2666         aFieldStepData << QString( aValues[i] );
2667     }
2668   }
2669
2670   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2671   aFieldStepData = groupFieldData( aFieldStepData,
2672                                    aFieldNbComponents,
2673                                    aFieldDataType == GEOM::FDT_String,
2674                                    aFieldStepRangeMin,
2675                                    aFieldStepRangeMax );
2676
2677   setFieldStepInfo( aFieldDataType,
2678                     aFieldDimension,
2679                     aFieldStepData,
2680                     aFieldStepName,
2681                     aFieldStepRangeMin,
2682                     aFieldStepRangeMax );
2683 }
2684
2685 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2686                                                 const int theFieldNbComponents,
2687                                                 const bool theIsString,
2688                                                 double& theFieldStepRangeMin,
2689                                                 double& theFieldStepRangeMax )
2690 {
2691   QList<QVariant> aResultList;
2692   theFieldStepRangeMin = 0;
2693   theFieldStepRangeMax = 0;
2694
2695   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2696     return aResultList;
2697
2698   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2699
2700   QList<QVariant> aGroupedList;
2701
2702   bool anIsBoolean = false;
2703   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2704   {
2705     double aNorm = 0;
2706     QStringList aStringList;
2707
2708     int aBaseIndex = aSubShape * theFieldNbComponents;
2709     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2710     {
2711       int anIndex = aComponent + aBaseIndex;
2712
2713       const QVariant& aVariant = theFieldStepData[ anIndex ];
2714       if( theIsString )
2715       {
2716         if( aVariant.type() == QVariant::String )
2717           aStringList << aVariant.toString();
2718       }
2719       else
2720       {
2721         double aValue = 0;
2722         if( aVariant.type() == QVariant::Bool )
2723         {
2724           aValue = aVariant.toBool() ? 1.0 : 0.0;
2725           aNorm += aValue;
2726           anIsBoolean = true;
2727         }
2728         else
2729         {
2730           if( aVariant.type() == QVariant::LongLong )
2731             aValue = double( aVariant.toLongLong() );
2732           else if( aVariant.type() == QVariant::Double )
2733             aValue = aVariant.toDouble();
2734           aNorm += aValue * aValue;
2735         }
2736       }
2737     }
2738
2739     if( theIsString )
2740       aGroupedList << aStringList.join( "\n" );
2741     else
2742     {
2743       if( anIsBoolean )
2744         aNorm /= theFieldNbComponents;
2745       else
2746         aNorm = pow( aNorm, 0.5 );
2747
2748       if( aGroupedList.isEmpty() )
2749         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2750       else
2751       {
2752         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2753         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2754       }
2755
2756       aGroupedList << aNorm;
2757     }
2758   }
2759
2760   if( anIsBoolean )
2761   {
2762     theFieldStepRangeMin = 0.0;
2763     theFieldStepRangeMax = 1.0;
2764   }
2765
2766   SUIT_Session* session = SUIT_Session::session();
2767   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2768   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2769
2770   QListIterator<QVariant> anIter( aGroupedList );
2771   while( anIter.hasNext() )
2772   {
2773     const QVariant& aVariant = anIter.next();
2774     if( theIsString )
2775       aResultList << aVariant;
2776     else
2777     {
2778       QColor aQColor;
2779       Quantity_Color aColor;
2780       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2781         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2782       aResultList << aQColor;
2783     }
2784   }
2785   return aResultList;
2786 }
2787
2788 // Note: the method is copied from Aspect_ColorScale class
2789 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2790                                                const Standard_Integer aMin,
2791                                                const Standard_Integer aMax )
2792 {
2793   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2794
2795   Standard_Integer aHue = maxLimit;
2796   if ( aMin != aMax )
2797     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2798
2799   aHue = Min( Max( minLimit, aHue ), maxLimit );
2800
2801   return aHue;
2802 }
2803
2804 // Note: the method is copied from Aspect_ColorScale class
2805 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2806                                             const Standard_Real aMin,
2807                                             const Standard_Real aMax,
2808                                             const Standard_Integer ColorsCount,
2809                                             Quantity_Color& aColor )
2810 {
2811   if( aValue<aMin || aValue>aMax || aMax<aMin )
2812     return Standard_False;
2813
2814   else
2815   {
2816     Standard_Real IntervNumber = 0;
2817     if( aValue<aMin )
2818       IntervNumber = 0;
2819     else if( aValue>aMax )
2820       IntervNumber = ColorsCount-1;
2821     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2822       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2823
2824     Standard_Integer Interv = Standard_Integer( IntervNumber );
2825
2826     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2827
2828     return Standard_True;
2829   } 
2830 }
2831
2832 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2833 {
2834   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2835   if( !aStudy )
2836     return;
2837
2838   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2839   if( !aViewModel )
2840     return;
2841
2842   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2843   if( aViewer.IsNull() )
2844     return;
2845
2846   aViewer->InitActiveViews();
2847   if( !aViewer->MoreActiveViews() )
2848     return;
2849
2850   Handle(V3d_View) aView = aViewer->ActiveView();
2851   if( aView.IsNull() )
2852     return;
2853
2854   Standard_Boolean anIsDisplayColorScale = Standard_False;
2855   TCollection_AsciiString aColorScaleTitle;
2856   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2857   Standard_Boolean anIsBoolean = Standard_False;
2858
2859   SALOME_ListIO aSelectedObjects;
2860   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2861   if( aSelectedObjects.Extent() == 1 )
2862   {
2863     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2864     if( !anIO.IsNull() )
2865     {
2866       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2867       if( aPrs )
2868       {
2869         AIS_ListOfInteractive aList;
2870         aPrs->GetObjects( aList );
2871         AIS_ListIteratorOfListOfInteractive anIter( aList );
2872         for( ; anIter.More(); anIter.Next() )
2873         {
2874           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2875           if( !aShape.IsNull() )
2876           {
2877             GEOM::field_data_type aFieldDataType;
2878             int aFieldDimension;
2879             QList<QVariant> aFieldStepData;
2880             TCollection_AsciiString aFieldStepName;
2881             double aFieldStepRangeMin, aFieldStepRangeMax;
2882             aShape->getFieldStepInfo( aFieldDataType,
2883                                       aFieldDimension,
2884                                       aFieldStepData,
2885                                       aFieldStepName,
2886                                       aFieldStepRangeMin,
2887                                       aFieldStepRangeMax );
2888             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2889             {
2890               anIsDisplayColorScale = Standard_True;
2891               aColorScaleTitle = aFieldStepName;
2892               aColorScaleMin = aFieldStepRangeMin;
2893               aColorScaleMax = aFieldStepRangeMax;
2894               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2895             }
2896           }
2897         }
2898       }
2899     }
2900   }
2901
2902   if( anIsDisplayColorScale )
2903   {
2904     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2905     if( !aColorScale.IsNull() )
2906     {
2907       SUIT_Session* session = SUIT_Session::session();
2908       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2909
2910       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2911       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2912       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2913       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2914       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2915       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2916  
2917       aColorScale->SetXPosition( anXPos );
2918       aColorScale->SetYPosition( anYPos );
2919       aColorScale->SetWidth( aWidth );
2920       aColorScale->SetHeight( aHeight );
2921
2922       aColorScale->SetTextHeight( aTextHeight );
2923       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2924
2925       aColorScale->SetTitle( aColorScaleTitle );
2926       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2927     }
2928     if( !aView->ColorScaleIsDisplayed() )
2929       aView->ColorScaleDisplay();
2930   }
2931   else
2932   {
2933     if( aView->ColorScaleIsDisplayed() )
2934       aView->ColorScaleErase();
2935   }
2936
2937   if( theIsRedisplayFieldSteps )
2938   {
2939     _PTR(Study) aStudyDS = aStudy->studyDS();
2940     QList<SUIT_ViewManager*> vmList;
2941     myApp->viewManagers( vmList );
2942     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2943     {
2944       if( SUIT_ViewManager* aViewManager = *vmIt )
2945       {
2946         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2947         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2948         {
2949           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2950           if( aSObj )
2951           {
2952             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2953             if( !CORBA::is_nil( anObject ) )
2954             {
2955               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2956               if( !aFieldStep->_is_nil() )
2957               {
2958                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2959                 Handle(SALOME_InteractiveObject) aStepIO =
2960                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2961                 Redisplay( aStepIO, false, false );
2962               }
2963             }
2964           }
2965         }
2966       }
2967     }
2968   }
2969   if(updateViewer)
2970     UpdateViewer();
2971 }