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