Salome HOME
INT PAL 0052630: Bring to front behavior is not correct
[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   // - color of labels (textual fields and shape name)
836   AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
837
838   // set display mode
839   AISShape->SetDisplayMode( HasDisplayMode() ? 
840                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
841                             GetDisplayMode() :
842                             // display mode from properties
843                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
844
845   // - face boundaries color and line width
846   anAspect = AISShape->Attributes()->FaceBoundaryAspect();
847   anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
848   anAspect->SetWidth( propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
849   AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
850
851   // set display vectors flag
852   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
853
854   // set display vertices flag
855   bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
856   AISShape->SetDisplayVertices( isVerticesMode );
857
858   // set display name flag
859   bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
860   AISShape->SetDisplayName( isNameMode );
861
862   // set transparency
863   if( HasTransparency() ) {
864     AISShape->SetTransparency( GetTransparency() );
865   } else {
866     AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
867   }
868
869   // set iso properties
870   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
871   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
872   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
873   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
874   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
875   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
876
877   if ( HasIsosColor() ) {
878     uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
879     vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
880   }
881   else {
882     uIsoAspect->SetColor( isosColor );
883     vIsoAspect->SetColor( isosColor );
884   }
885
886   if ( HasIsosWidth() ) {
887     uIsoAspect->SetWidth( GetIsosWidth() );
888     vIsoAspect->SetWidth( GetIsosWidth() );
889   }
890   else {
891     uIsoAspect->SetWidth( isosWidth );
892     vIsoAspect->SetWidth( isosWidth );
893   }
894   
895   if ( HasNbIsos() ) {
896     uIsoAspect->SetNumber( GetNbIsos() );
897     vIsoAspect->SetNumber( GetNbIsos() );
898   }
899   else {
900     uIsoAspect->SetNumber( uIsos );
901     vIsoAspect->SetNumber( vIsos );
902   }
903
904   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
905   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
906
907   // set deflection coefficient
908   // ... to avoid to small values of the coefficient, its lower value is limited 
909   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
910
911   // set texture
912   QString aImagePath;
913   if ( HasTexture() ) {
914     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
915     aImagePath = GetTexture().c_str();
916     if ( ! entry.isEmpty() ) {
917       // check that study is active
918       SalomeApp_Study* study = getActiveStudy();
919       if ( study ) {
920         // Store the texture in object properties for next displays
921         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
922         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
923         
924         // Update propeties map
925         propMap = getObjectProperties( study, entry, myViewFrame );
926       }
927     }
928   }
929   else {
930     aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
931   }
932
933 #ifdef USE_TEXTURED_SHAPE
934   Handle(Image_PixMap) aPixmap;
935   if ( !aImagePath.isEmpty() )
936     aPixmap = cacheTextureFor( aImagePath, AISShape );
937   else
938     aPixmap = getDefaultTexture();
939
940   // apply image to shape
941   if ( !aPixmap.IsNull() ) {
942     AISShape->SetTexturePixMap( aPixmap );
943     AISShape->SetTextureMapOn();
944     AISShape->DisableTextureModulate();
945   }
946   else {
947     AISShape->SetTextureMapOff();
948   }
949 #endif
950
951   // set line width
952   AISShape->SetWidth( HasWidth() ?
953                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
954                       GetWidth() :
955                       // libe width from properties
956                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
957
958   // set top-level flag
959   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
960
961   // set point marker (for vertex / compound of vertices only)
962   if ( onlyVertex || isVerticesMode ) {
963     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
964     if ( aList.size() == 2 ) {
965       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
966       int aTypeOfMarker = aList[0].toInt();
967       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
968       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
969       anAspect->SetScale( aScaleOfMarker );
970       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
971       anAspect->SetColor( HasColor() ? 
972                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
973                           (Quantity_NameOfColor)GetColor() : 
974                           // color from properties
975                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
976       AISShape->Attributes()->SetPointAspect( anAspect );
977     }
978     else if ( aList.size() == 1 ) {
979       // custom marker string contains "IdOfTexture"
980       int textureId = aList[0].toInt();
981       Standard_Integer aWidth, aHeight;
982       Handle(TColStd_HArray1OfByte) aTexture =
983         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
984       if ( !aTexture.IsNull() ) {
985         Handle(Prs3d_PointAspect) aTextureAspect =
986           new Prs3d_PointAspect( HasColor() ? 
987                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
988                                  (Quantity_NameOfColor)GetColor() : 
989                                  // color from properties 
990                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
991                                  aWidth, aHeight,
992                                  aTexture );
993         AISShape->Attributes()->SetPointAspect( aTextureAspect );
994       }
995     }
996   }
997
998   // set field step data
999   AISShape->setFieldStepInfo( myFieldDataType,
1000                               myFieldDimension,
1001                               myFieldStepData,
1002                               myFieldStepName,
1003                               myFieldStepRangeMin,
1004                               myFieldStepRangeMax );
1005
1006   if ( create && !isTemporary && aMgrId != -1 ) {
1007     // set properties to the study
1008     study->setObjectProperties( aMgrId, entry, propMap );
1009   }
1010
1011   // AISShape->SetName(???); ??? necessary to set name ???
1012 }
1013
1014 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1015 {
1016   // check that actor is not null
1017   if ( !actor ) return;
1018   
1019   // check that study is active
1020   SalomeApp_Study* study = getStudy();
1021   if ( !study ) return;
1022
1023   // set interactive object
1024
1025   Handle( SALOME_InteractiveObject ) anIO;
1026
1027   if ( !myIO.IsNull() ) {
1028     actor->setIO( myIO );
1029     anIO = myIO;
1030   }
1031   else if ( !myName.empty() ) {
1032     // workaround to allow selection of temporary objects
1033     static int tempId = 0;
1034     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1035     actor->setIO( anIO );
1036   }
1037
1038   // presentation study entry (empty for temporary objects like preview)
1039   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1040   // flag: temporary object
1041   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1042   // currently active view window's ID (-1 if no active view)
1043   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1044
1045   // get presentation properties
1046   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1047   QColor c;
1048
1049   /////////////////////////////////////////////////////////////////////////
1050   // VSR: for VTK viewer currently deflection coefficient is hardcoded
1051   //      due to performance problem
1052   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1053   /////////////////////////////////////////////////////////////////////////
1054   if ( !actor->getTopo().IsSame( myShape ) )
1055 #ifdef LIMIT_DEFLECTION_FOR_VTK
1056     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1057 #else
1058     actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1059 #endif
1060
1061   // set material
1062   Material_Model material;
1063   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1064   std::vector<vtkProperty*> mprops;
1065   mprops.push_back( material.getMaterialVTKProperty( true ) );
1066   mprops.push_back( material.getMaterialVTKProperty( false) );
1067   actor->SetMaterial( mprops );
1068
1069   // set iso-lines properties
1070
1071   // - set number of iso-lines
1072   int nbIsos[2]= { 1, 1 };
1073   if ( HasNbIsos() ) {
1074     nbIsos[0] = GetNbIsos();
1075     nbIsos[1] = GetNbIsos();
1076   }
1077   else {
1078     QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1079     nbIsos[0] = isos[0].toInt();
1080     nbIsos[1] = isos[1].toInt();
1081   }
1082   actor->SetNbIsos( nbIsos );
1083
1084   // - set iso-lines width
1085   actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1086
1087   // - set iso-lines color
1088   if ( HasIsosColor() )
1089     c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1090   else
1091     c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1092   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1093
1094   // set colors
1095
1096   if ( HasColor()  ) {
1097     // - same color for all sub-actors
1098     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1099     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1100   }
1101   else {
1102     // shading color (for non-physical materials)
1103     if ( !material.isPhysical() ) {
1104       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1105       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1106       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1107     }
1108
1109     // - standalone edge color
1110     c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1111     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1112
1113     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1114     // - shared edges color ???
1115     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1116
1117     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1118     // - free edges color ???
1119     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1120
1121     // - point color
1122     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1123     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1124   }
1125
1126   // - color for edges in shading+edges mode
1127   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1128   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1129
1130   // - color of labels (shape name)
1131   c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1132   actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1133
1134   // set opacity
1135   if( HasTransparency() ) {
1136     actor->SetOpacity( 1.0 - GetTransparency() );
1137   } else {
1138     actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1139   }
1140
1141   // set line width
1142   actor->SetWidth( HasWidth() ?
1143                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1144                    GetWidth() :
1145                    // libe width from properties
1146                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1147   
1148   // set display vectors flag
1149   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1150
1151   // set display vertices flag
1152   actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1153
1154   // set display name flag
1155   actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1156
1157   // set display mode
1158   int displayMode = HasDisplayMode() ? 
1159     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
1160     GetDisplayMode() :
1161     // display mode from properties
1162     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1163
1164   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1165   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1166   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1167   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1168
1169   if ( displayMode == 2 )
1170       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1171       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1172     displayMode++;
1173   actor->setDisplayMode( displayMode );
1174
1175   if ( myToActivate )
1176     actor->PickableOn();
1177   else
1178     actor->PickableOff();
1179
1180   if ( create && !isTemporary && aMgrId != -1 ) {
1181     // set properties to the study
1182     study->setObjectProperties( aMgrId, entry, propMap );
1183   }
1184 }
1185
1186 //=================================================================
1187 /*!
1188  *  GEOM_Displayer::updateDimensions
1189  *  Creates or renews dimension presentation for the IO.
1190  */
1191 //=================================================================
1192 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1193                                        SALOME_OCCPrs* thePrs,
1194                                        const gp_Ax3& theShapeLCS )
1195 {
1196   SalomeApp_Study* aStudy = getStudy();
1197   if ( !aStudy )
1198   {
1199     return;
1200   }
1201
1202   if ( theIO.IsNull() )
1203   {
1204     return;
1205   }
1206
1207   SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1208
1209   AIS_ListOfInteractive aListOfIO;
1210
1211   anOccPrs->GetObjects( aListOfIO );
1212
1213   AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1214
1215   // remove outdated presentations of dimensions
1216   for ( ; aIterateIO.More(); aIterateIO.Next() )
1217   {
1218     const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1219     if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1220     {
1221       continue;
1222     }
1223
1224     aListOfIO.Remove( aIterateIO );
1225
1226     if ( !aIterateIO.More() )
1227     {
1228       break;
1229     }
1230   }
1231
1232   // prepare dimension styling
1233   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1234
1235   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1236   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1237   double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1238   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1239   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1240   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1241   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1242
1243   // restore dimension presentation from saved attribute or property data
1244   AIS_ListOfInteractive aRestoredDimensions;
1245
1246   QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1247                                                   theIO->getEntry(),
1248                                                   GEOM::propertyName( GEOM::Dimensions ),
1249                                                   QVariant() );
1250
1251   GEOMGUI_DimensionProperty aRecords;
1252
1253   if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1254   {
1255     aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1256   }
1257   else
1258   {
1259     aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1260   }
1261   
1262   // create up-to-date dimension presentations
1263   for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1264   {
1265     if ( !aRecords.IsVisible( aPrsIt ) )
1266     {
1267       continue;
1268     }
1269
1270     // init dimension by type
1271     Handle(AIS_Dimension) aPrs;
1272     switch( aRecords.GetType( aPrsIt ) )
1273     {
1274       case GEOMGUI_DimensionProperty::DimensionType_Length :
1275       {
1276         Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1277         aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1278         aPrs = aLength;
1279         break;
1280       }
1281
1282       case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1283       {
1284         Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1285         aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1286         aPrs = aDiam;
1287         break;
1288       }
1289
1290       case GEOMGUI_DimensionProperty::DimensionType_Angle :
1291       {
1292         Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1293         aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1294         aPrs = anAng;
1295         break;
1296       }
1297     }
1298
1299     aPrs->SetOwner( theIO );
1300
1301     Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1302
1303     Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1304
1305     aStyle->SetCommonColor( aColor );
1306     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1307     aStyle->MakeText3d( Standard_True );
1308     aStyle->MakeTextShaded( Standard_True );
1309     aStyle->SetExtensionSize( aFontHeight * 0.5 );
1310     aStyle->TextAspect()->SetHeight( aFontHeight );
1311     aStyle->ArrowAspect()->SetLength( anArrowLength );
1312     aStyle->LineAspect()->SetWidth( aLineWidth );
1313     aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1314     aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1315     aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1316     aPrs->SetDimensionAspect( aStyle );
1317     aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1318     aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1319     aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1320
1321     if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1322     {
1323       // show degree symbol for dimension instead of label "deg"
1324       if ( aUnitsAngle == "deg" )
1325       {
1326         aPrs->SetSpecialSymbol(0xB0);
1327         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1328         aStyle->MakeUnitsDisplayed(Standard_False);
1329       }
1330       else
1331       {
1332         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1333         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1334       }
1335     }
1336     else
1337     {
1338       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1339     }
1340
1341     aListOfIO.Append( aPrs );
1342   }
1343
1344   // update presentation
1345   anOccPrs->Clear();
1346
1347   for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1348   {
1349     anOccPrs->AddObject( aIterateIO.Value() );
1350   }
1351 }
1352
1353 //=================================================================
1354 /*!
1355  *  GEOM_Displayer::Erase
1356  *  Calls Erase() method for each object in the given list
1357  */
1358 //=================================================================
1359 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1360                             const bool forced,
1361                             const bool updateViewer )
1362 {
1363   SALOME_ListIteratorOfListIO Iter( theIOList );
1364   for ( ; Iter.More(); Iter.Next() )
1365     Erase( Iter.Value(), forced, false );
1366
1367   if ( updateViewer )
1368     UpdateViewer();
1369 }
1370
1371 //=================================================================
1372 /*!
1373  *  GEOM_Displayer::Redisplay
1374  *  Calls Redisplay() method for each object in the given list
1375  */
1376 //=================================================================
1377 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1378                                 const bool updateViewer,
1379                                 const bool checkActiveViewer )
1380 {
1381   SALOME_ListIteratorOfListIO Iter( theIOList );
1382   for ( ; Iter.More(); Iter.Next() )
1383     Redisplay( Iter.Value(), false, checkActiveViewer );
1384
1385   if ( updateViewer )
1386     UpdateViewer();
1387 }
1388
1389 //=================================================================
1390 /*!
1391  *  GEOM_Displayer::Redisplay
1392  *  Calls Redisplay() method for each object in the given list
1393  */
1394 //=================================================================
1395 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1396                                 const bool theUpdateViewer,
1397                                 SALOME_View* theViewFrame )
1398 {
1399   SALOME_ListIteratorOfListIO anIter( theIOList );
1400   for ( ; anIter.More(); anIter.Next() )
1401   {
1402     Redisplay( anIter.Value(), false, theViewFrame );
1403   }
1404
1405   if ( theUpdateViewer )
1406   {
1407     UpdateViewer();
1408   }
1409 }
1410
1411 //=================================================================
1412 /*!
1413  *  GEOM_Displayer::Update
1414  *  Update OCC presentaion
1415  *  [ Reimplemented from SALOME_Displayer ]
1416  */
1417 //=================================================================
1418 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1419 {
1420   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1421   SalomeApp_Study* study = getStudy();
1422
1423   if ( !occPrs || myShape.IsNull() || !study )
1424     return;
1425
1426   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1427   {
1428     // 
1429     // specific processing for local coordinate system presentation
1430     // 
1431
1432     TopoDS_Face aFace = TopoDS::Face( myShape );
1433     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1434     if ( !aPlane.IsNull() )
1435     {
1436       gp_Ax3 aPos = aPlane->Pln().Position();
1437       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1438
1439       Handle(GEOM_AISTrihedron) aTrh;
1440
1441       if ( occPrs->IsNull() )
1442       {
1443         // new presentation is being created
1444         aTrh = new GEOM_AISTrihedron( aPlc );
1445         occPrs->AddObject( aTrh );
1446       }
1447       else
1448       {
1449         // presentation is being updated
1450         AIS_ListOfInteractive aList;
1451         occPrs->GetObjects( aList );
1452         AIS_ListIteratorOfListOfInteractive anIter( aList );
1453         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1454           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1455         }
1456       }
1457         
1458       if ( !aTrh.IsNull() ) {
1459         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1460         if ( HasColor() )
1461           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1462         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1463         if ( HasWidth() )
1464           aTrh->SetWidth( GetWidth() );
1465         
1466         if ( !myIO.IsNull() )
1467         {
1468           aTrh->setIO( myIO );
1469           aTrh->SetOwner( myIO );
1470         }
1471         aTrh->SetComponent( aPlc );
1472         aTrh->SetToUpdate();
1473       }
1474       occPrs->SetToActivate( ToActivate() );
1475     }
1476   }
1477   else
1478   {
1479     // 
1480     // processing for usual geometry presentation
1481     // 
1482
1483     // if presentation is empty we try to create new one
1484     if ( occPrs->IsNull() )
1485     {
1486       // create presentation (specific for vectors)
1487       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1488                                                                  : new GEOM_AISShape ( myShape, "" );
1489
1490       if( myType == GEOM_FIELD_STEP )
1491         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1492       // update shape properties
1493       updateShapeProperties( AISShape, true );
1494
1495       // add shape to the presentation
1496       occPrs->AddObject( AISShape );
1497
1498       // In accordance with ToActivate() value object will be activated/deactivated
1499       // when it will be displayed
1500       occPrs->SetToActivate( ToActivate() );
1501
1502       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1503         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1504
1505         // create additional wireframe shape
1506         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1507         aWirePrs->SetWidth(AISShape->Width());
1508         if ( !myIO.IsNull() ) {
1509           aWirePrs->setIO( myIO );
1510           aWirePrs->SetOwner( myIO );
1511         }
1512
1513         // add shape to the presentation
1514         occPrs->AddObject( aWirePrs );
1515       }
1516     }
1517     // if presentation is found -> set again shape for it
1518     else
1519     {
1520       AIS_ListOfInteractive IOList;
1521       occPrs->GetObjects( IOList );
1522       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1523       for ( ; Iter.More(); Iter.Next() )
1524       {
1525         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1526         if ( AISShape.IsNull() )
1527           continue;
1528
1529         // re-set shape (it might be changed)
1530         if ( AISShape->Shape() != myShape )
1531           AISShape->Set( myShape );
1532
1533         // update shape properties
1534         updateShapeProperties( AISShape, false );
1535
1536         // force updating
1537         AISShape->UpdateSelection();
1538         AISShape->SetToUpdate();
1539       }
1540     }
1541
1542     updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1543   }
1544 }
1545
1546 //=================================================================
1547 /*!
1548  *  GEOM_Displayer::Update
1549  *  Update VTK presentaion
1550  *  [ Reimplemented from SALOME_Displayer ]
1551  */
1552 //=================================================================
1553 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1554 {
1555   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1556   SalomeApp_Study* study = getStudy();
1557
1558   if ( !vtkPrs || myShape.IsNull() || !study )
1559     return;
1560
1561   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1562   {
1563     // 
1564     // specific processing for local coordinate system presentation
1565     // 
1566
1567     TopoDS_Face aFace = TopoDS::Face( myShape );
1568     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1569     if ( !aPlane.IsNull() ) {
1570       gp_Ax3 aPos = aPlane->Pln().Position();
1571       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1572
1573       GEOM_VTKTrihedron* aTrh = 0;
1574
1575       if ( vtkPrs->IsNull() ) {
1576         // new presentation is being created
1577         aTrh = GEOM_VTKTrihedron::New();
1578         vtkPrs->AddObject( aTrh );
1579       }
1580       else {
1581         // presentation is being updated
1582         vtkActorCollection* actors = vtkPrs->GetObjects();
1583         if ( actors ) {
1584           actors->InitTraversal();
1585           vtkActor* a = actors->GetNextActor();
1586           while ( a && !aTrh ) {
1587             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1588             a = actors->GetNextActor();
1589           }
1590         }
1591       }
1592       
1593       if ( aTrh ) {
1594         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1595         if ( HasColor() ) {
1596           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1597           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1598         }
1599 #ifdef VTK_TRIHEDRON_WIDTH
1600         // 
1601         // VSR: currently isn't supported
1602         //
1603         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1604         if ( HasWidth() )
1605           aTrh->SetWidth( GetWidth() );
1606 #endif
1607
1608         if ( !myIO.IsNull() )
1609           aTrh->setIO( myIO );
1610
1611         aTrh->SetPlacement( aPlc );
1612       }
1613     }
1614   }
1615   else
1616   {
1617     // 
1618     // processing for usual geometry presentation
1619     // 
1620
1621     // if presentation is empty we try to create new one
1622     if ( vtkPrs->IsNull() )
1623     {
1624       // create an actor
1625       GEOM_Actor* actor = GEOM_Actor::New();
1626       // update actor properties
1627       updateActorProperties( actor, true );
1628       // add actor to the presentation
1629       vtkPrs->AddObject( actor );
1630     }
1631     else {
1632       // presentation is being updated
1633       vtkActorCollection* actors = vtkPrs->GetObjects();
1634       if ( actors ) {
1635         actors->InitTraversal();
1636         vtkActor* a = actors->GetNextActor();
1637         while ( a ) {
1638           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1639           if ( actor ) {
1640             // update actor properties
1641             updateActorProperties( actor, false );
1642             a = actors->GetNextActor();
1643           }
1644         }
1645       }
1646     }
1647   }
1648 }
1649
1650 //=================================================================
1651 /*!
1652  *  GEOM_Displayer::BuildPrs
1653  *  Build presentation accordint to the current viewer type
1654  */
1655 //=================================================================
1656 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1657 {
1658   if ( theObj->_is_nil() )
1659     return 0;
1660
1661   myViewFrame = GetActiveView();
1662   if ( myViewFrame == 0 )
1663     return 0;
1664
1665   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1666   if ( aPrs == 0 )
1667     return 0;
1668
1669   internalReset();
1670   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1671   myType = theObj->GetType();
1672
1673   // Update presentation
1674   UpdatePrs( aPrs );
1675
1676   return aPrs;
1677 }
1678
1679 //=================================================================
1680 /*!
1681  *  GEOM_Displayer::BuildPrs
1682  *  Build presentation accordint to the current viewer type
1683  */
1684 //=================================================================
1685 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1686 {
1687   myViewFrame = GetActiveView();
1688   if ( theShape.IsNull() || myViewFrame == 0 )
1689     return 0;
1690
1691   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1692   if ( aPrs == 0 )
1693     return 0;
1694
1695   internalReset();
1696   setShape( theShape );
1697   myType = -1;
1698
1699   UpdatePrs( aPrs );
1700
1701   return aPrs;
1702 }
1703
1704 //=================================================================
1705 /*!
1706  *  GEOM_Displayer::buildPresentation
1707  *  Builds/finds object's presentation for the current viewer
1708  *  Calls corresponding Update() method by means of double dispatch
1709  *  [ internal ]
1710  */
1711 //=================================================================
1712 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1713                                                SALOME_View* theViewFrame )
1714 {
1715   SALOME_Prs* prs = 0;
1716   internalReset();
1717
1718   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1719
1720   if ( myViewFrame )
1721   {
1722     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1723     if ( prs )
1724     {
1725       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1726       theIO->setEntry( entry.toLatin1().constData() );
1727       if ( !theIO.IsNull() )
1728       {
1729         // set interactive object
1730         setIO( theIO );
1731         //  Find SOBject (because shape should be published previously)
1732         SUIT_Session* session = SUIT_Session::session();
1733         SUIT_Application* app = session->activeApplication();
1734         if ( app )
1735         {
1736           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1737           if ( study )
1738           {
1739             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1740             if ( SO )
1741             {
1742               // get CORBA reference to data object
1743               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1744               if ( !CORBA::is_nil( object ) )
1745               {
1746                 // downcast to GEOM base object
1747                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1748                 if ( !GeomBaseObject->_is_nil() )
1749                 {
1750                   myType = GeomBaseObject->GetType();
1751
1752                   // downcast to GEOM object
1753                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1754                   if ( myType == GEOM_FIELD_STEP )
1755                   {
1756                     // get the GEOM object from the field's shape
1757                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1758                     if ( !GeomFieldStep->_is_nil() )
1759                     {
1760                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1761                       if ( !GeomField->_is_nil() )
1762                         GeomObject = GeomField->GetShape();
1763                     }
1764
1765                     // read the field step information
1766                     readFieldStepInfo( GeomFieldStep );
1767                   }
1768
1769                   if ( !GeomObject->_is_nil() )
1770                   {
1771                     theIO->setName( GeomObject->GetName() );
1772                     // finally set shape
1773                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1774                   }
1775                 }
1776               }
1777             }
1778           }
1779         }
1780       }
1781       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1782     }
1783   }
1784   return prs;
1785 }
1786
1787 //=================================================================
1788 /*!
1789  *  GEOM_Displayer::buildSubshapePresentation
1790  *  Builds/finds object's presentation for the current viewer
1791  *  Calls corresponding Update() method by means of double dispatch
1792  *  For not published objects (for Mantis issue 0020435)
1793  */
1794 //=================================================================
1795 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1796                                                       const QString& entry,
1797                                                       SALOME_View* theViewFrame)
1798 {
1799   SALOME_Prs* prs = 0;
1800   internalReset();
1801
1802   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1803
1804   if (myViewFrame)
1805   {
1806     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1807     if (prs)
1808     {
1809       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1810       theIO->setEntry(entry.toLatin1().constData());
1811       if (!theIO.IsNull())
1812       {
1813         // set interactive object
1814         setIO(theIO);
1815         // finally set shape
1816         setShape(aShape);
1817         myType = GEOM_SUBSHAPE;
1818       }
1819       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1820     }
1821   }
1822   return prs;
1823 }
1824
1825 //=================================================================
1826 /*!
1827  *  GEOM_Displayer::internalReset
1828  *  Resets internal data
1829  *  [internal]
1830  */
1831 //=================================================================
1832 void GEOM_Displayer::internalReset()
1833 {
1834   myIO.Nullify();
1835   myShape.Nullify();
1836
1837   myFieldDataType = GEOM::FDT_Double;
1838   myFieldDimension = 0;
1839   myFieldStepData.clear();
1840   myFieldStepName.Clear();
1841   myFieldStepRangeMin = 0;
1842   myFieldStepRangeMax = 0;
1843 }
1844
1845 //=================================================================
1846 /*!
1847  *  GEOM_Displayer::LocalSelection
1848  *  Activate selection of CAD shapes with activisation of selection
1849  *  of their sub-shapes (with opened local context for OCC viewer)
1850  */
1851 //=================================================================
1852 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1853 {
1854   SUIT_Session* session = SUIT_Session::session();
1855   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1856   if ( !app )
1857     return;
1858
1859   LightApp_SelectionMgr* sm = app->selectionMgr();
1860
1861   // remove all filters from selection
1862   sm->clearFilters();
1863
1864   SALOME_View* vf = GetActiveView();
1865   if ( vf ) {
1866     if (!theIO.IsNull() && !vf->isVisible(theIO))
1867       Display(theIO);
1868     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1869     vf->LocalSelection( prs, modes );
1870     delete prs;  // delete presentation because displayer is its owner
1871   }
1872 }
1873
1874 //=================================================================
1875 /*!
1876  *  GEOM_Displayer::LocalSelection
1877  *  Activate selection of CAD shapes with activisation of selection
1878  *  of their sub-shapes (with opened local context for OCC viewer)
1879  */
1880 //=================================================================
1881 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1882 {
1883   std::list<int> modes;
1884   modes.push_back( theMode );
1885   LocalSelection( theIO, modes );
1886 }
1887
1888 //=================================================================
1889 /*!
1890  *  GEOM_Displayer::globalSelection
1891  *  Activate selection of CAD shapes without activisation of selection
1892  *  of their sub-shapes (without opened local context for OCC viewer)
1893  */
1894 //=================================================================
1895 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1896 {
1897   TColStd_MapOfInteger aModes;
1898   aModes.Add( theMode );
1899   GlobalSelection( aModes, update );
1900 }
1901
1902 //=================================================================
1903 /*!
1904  *  GEOM_Displayer::globalSelection
1905  *  Activate selection of CAD shapes without activisation of selection
1906  *  of their sub-shapes (without opened local context for OCC viewer)
1907  */
1908 //=================================================================
1909 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1910                                       const bool update, const QList<int>* theSubShapes )
1911 {
1912   SUIT_Session* session = SUIT_Session::session();
1913   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1914   if ( !app )
1915     return;
1916
1917   SALOME_View* vf = GetActiveView();
1918   if ( vf == 0 )
1919     return;
1920
1921   // Close local context
1922   vf->GlobalSelection( update );
1923
1924   // Set selection filters in accordance with current mode
1925   LightApp_SelectionMgr* sm = app->selectionMgr();
1926   if ( !sm )
1927     return;
1928
1929   // Remove from selection temporary objects if necessary
1930   if ( !theModes.Contains( GEOM_PREVIEW ) )
1931     clearTemporary( sm );
1932
1933   //@ aSel->ClearIndex();
1934
1935   sm->clearFilters();
1936
1937   // Remove filters from AIS_InteractiveContext
1938   Handle(AIS_InteractiveContext) ic;
1939   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1940   if ( viewer )
1941     {
1942       ic = viewer->getAISContext();
1943       if ( !ic.IsNull() )
1944         ic->RemoveFilters();
1945     }
1946
1947   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1948     return;
1949
1950   SUIT_SelectionFilter* aFilter;
1951   if ( theModes.Extent() == 1 )
1952     {
1953       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1954
1955       if ( aMode == GEOM_COMPOUNDFILTER )
1956         aFilter = getComplexFilter( theSubShapes );
1957       else
1958         aFilter = getFilter( aMode );
1959     }
1960   else if ( theModes.Extent() > 1 )
1961     {
1962       TColStd_MapOfInteger aTopAbsModes;
1963       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1964       QList<SUIT_SelectionFilter*> aListOfFilters;
1965       for ( ; anIter.More(); anIter.Next() )
1966         {
1967           SUIT_SelectionFilter* aFilter;
1968           int aMode = anIter.Key();
1969           if ( aMode == GEOM_COMPOUNDFILTER )
1970             aFilter = getComplexFilter( theSubShapes );
1971           else
1972             aFilter = getFilter( aMode );
1973
1974           if ( aFilter )
1975             aListOfFilters.append( aFilter );
1976         }
1977
1978       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1979     }
1980   else
1981     return;
1982
1983   if ( aFilter )
1984     {
1985       sm->installFilter( aFilter );
1986       if ( !ic.IsNull() )
1987         {
1988           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1989           ic->AddFilter( anOCCFilter );
1990         }
1991     }
1992 }
1993
1994 //=================================================================
1995 /*!
1996  *  GEOM_Displayer::LocalSelection
1997  *  Activate selection of CAD shapes with activisation of selection
1998  *  of their sub-shapes (with opened local context for OCC viewer)
1999  */
2000 //=================================================================
2001 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2002 {
2003   SALOME_ListIteratorOfListIO Iter( theIOList );
2004   for ( ; Iter.More(); Iter.Next() )
2005     LocalSelection( Iter.Value(), modes );
2006 }
2007
2008 //=================================================================
2009 /*!
2010  *  GEOM_Displayer::LocalSelection
2011  *  Activate selection of CAD shapes with activisation of selection
2012  *  of their sub-shapes (with opened local context for OCC viewer)
2013  */
2014 //=================================================================
2015 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2016 {
2017   std::list<int> modes;
2018   modes.push_back( theMode );
2019   LocalSelection( theIOList, modes );
2020 }
2021
2022 //=================================================================
2023 /*!
2024  *  GEOM_Displayer::BeforeDisplay
2025  *  Called before displaying of pars. Close local context
2026  *  [ Reimplemented from SALOME_Displayer ]
2027  */
2028 //=================================================================
2029 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2030 {
2031   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2032   if ( vf )
2033   {
2034     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2035     if ( !ic.IsNull() )
2036     {
2037       if ( ic->HasOpenedContext() )
2038       ic->CloseAllContexts();
2039     }
2040   }
2041 }
2042
2043 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2044 {
2045   UpdateColorScale(false,false);
2046 }
2047
2048 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2049 {
2050   LightApp_Displayer::BeforeErase( v, p );
2051   releaseTextures( p );
2052 }
2053
2054 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2055 {
2056   LightApp_Displayer::AfterErase( v, p );
2057   UpdateColorScale(false,false);
2058 }
2059
2060 //=================================================================
2061 /*!
2062  *  GEOM_Displayer::SetColor
2063  *  Set color for shape displaying. If it is equal -1 then default color is used.
2064  *  Available values are from Quantity_NameOfColor enumeration
2065  */
2066 //=================================================================
2067 void GEOM_Displayer::SetColor( const int color )
2068 {
2069   if ( color == -1 )
2070     UnsetColor();
2071   else
2072   {
2073     myColor = color;
2074     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2075   }
2076 }
2077
2078 int GEOM_Displayer::GetColor() const
2079 {
2080   return myColor;
2081 }
2082
2083 bool GEOM_Displayer::HasColor() const
2084 {
2085   return myColor != -1;
2086 }
2087
2088 void GEOM_Displayer::UnsetColor()
2089 {
2090   myColor = -1;
2091
2092   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2093   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2094   myShadingColor = SalomeApp_Tools::color( col );
2095 }
2096
2097 //=================================================================
2098 /*!
2099  *  GEOM_Displayer::SetTransparency
2100  *  Set transparency for shape displaying.
2101  */
2102 //=================================================================
2103 double GEOM_Displayer::SetTransparency( const double transparency )
2104 {
2105   double prevTransparency = myTransparency;
2106   myTransparency = transparency;
2107   return prevTransparency;
2108 }
2109
2110 //=================================================================
2111 /*!
2112  *  GEOM_Displayer::GetTransparency
2113  *  Get transparency for shape displaying.
2114  */
2115 //=================================================================
2116 double GEOM_Displayer::GetTransparency() const
2117 {
2118   return myTransparency;
2119 }
2120
2121 //=================================================================
2122 /*!
2123  *  GEOM_Displayer::HasTransparency
2124  *  Check if transparency for shape displaying is set.
2125  */
2126 //=================================================================
2127 bool GEOM_Displayer::HasTransparency() const
2128 {
2129   return myTransparency >= 0;
2130 }
2131
2132 //=================================================================
2133 /*!
2134  *  GEOM_Displayer::UnsetTransparency
2135  *  Unset transparency for shape displaying.
2136  */
2137 //=================================================================
2138 double GEOM_Displayer::UnsetTransparency()
2139 {
2140   return SetTransparency( -1 );
2141 }
2142
2143 //=================================================================
2144 /*!
2145  *  GEOM_Displayer::SetTexture
2146  */
2147 //=================================================================
2148 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2149 {
2150   myTexture = texureFileName;
2151 }
2152
2153 bool GEOM_Displayer::HasTexture() const
2154 {
2155   return myTexture != "";
2156 }
2157
2158 std::string GEOM_Displayer::GetTexture() const
2159 {
2160   return myTexture;
2161 }
2162
2163 //=================================================================
2164 /*!
2165  *  GEOM_Displayer::SetWidth
2166  *  Set width of shape displaying. If it is equal -1 then default width is used.
2167  */
2168 //=================================================================
2169 void GEOM_Displayer::SetWidth( const double width )
2170 {
2171   myWidth = width;
2172 }
2173
2174 double GEOM_Displayer::GetWidth() const
2175 {
2176   return myWidth;
2177 }
2178
2179 bool GEOM_Displayer::HasWidth() const
2180 {
2181   return myWidth != -1;
2182 }
2183
2184 void GEOM_Displayer::UnsetWidth()
2185 {
2186   myWidth = -1;
2187 }
2188
2189 int GEOM_Displayer::GetIsosWidth() const
2190 {
2191   return myIsosWidth;
2192 }
2193
2194 void GEOM_Displayer::SetIsosWidth(const int width)
2195 {
2196   myIsosWidth = width;
2197 }
2198
2199 bool GEOM_Displayer::HasIsosWidth() const
2200 {
2201   return myIsosWidth != -1;
2202 }
2203
2204 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2205 {
2206   int prevNbIsos = myNbIsos;
2207   myNbIsos = nbIsos;
2208   return prevNbIsos;
2209 }
2210
2211 int GEOM_Displayer::UnsetNbIsos()
2212 {
2213   return SetNbIsos( -1 );
2214 }
2215
2216 int GEOM_Displayer::GetNbIsos() const
2217 {
2218   return myNbIsos;
2219 }
2220
2221 bool GEOM_Displayer::HasNbIsos() const
2222 {
2223   return myNbIsos >= 0;
2224 }
2225
2226 int GEOM_Displayer::SetIsosColor( const int color )
2227 {
2228   int prevColor = myIsosColor;
2229   myIsosColor = color;
2230   return prevColor;
2231 }
2232
2233 int GEOM_Displayer::GetIsosColor() const
2234 {
2235   return myIsosColor;
2236 }
2237
2238 bool GEOM_Displayer::HasIsosColor() const
2239 {
2240   return myIsosColor != -1;
2241 }
2242
2243 int GEOM_Displayer::UnsetIsosColor()
2244 {
2245   return SetIsosColor( -1 );
2246 }
2247
2248 //=================================================================
2249 /*!
2250  *  GEOM_Displayer::SetToActivate
2251  *  This method is used for activisation/deactivisation of objects to be displayed
2252  */
2253 //=================================================================
2254 void GEOM_Displayer::SetToActivate( const bool toActivate )
2255 {
2256   myToActivate = toActivate;
2257 }
2258 bool GEOM_Displayer::ToActivate() const
2259 {
2260   return myToActivate;
2261 }
2262
2263 //=================================================================
2264 /*!
2265  *  GEOM_Displayer::clearTemporary
2266  *  Removes from selection temporary objects
2267  */
2268 //=================================================================
2269 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2270 {
2271   SALOME_ListIO selected, toSelect;
2272   theSelMgr->selectedObjects( selected );
2273
2274   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2275     Handle(SALOME_InteractiveObject) io = it.Value();
2276     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2277       toSelect.Append( it.Value() );
2278   }
2279
2280   theSelMgr->setSelectedObjects( toSelect, true );
2281 }
2282
2283 void GEOM_Displayer::SetName( const char* theName )
2284 {
2285   myName = theName;
2286 }
2287
2288 void GEOM_Displayer::UnsetName()
2289 {
2290   myName = "";
2291 }
2292
2293 SalomeApp_Study* GEOM_Displayer::getStudy() const
2294 {
2295   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2296 }
2297
2298 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2299 {
2300   myIO = theIO;
2301 }
2302
2303 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2304 {
2305   myShape = theShape;
2306 }
2307
2308 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2309                                        const int theFieldDimension,
2310                                        const QList<QVariant>& theFieldStepData,
2311                                        const TCollection_AsciiString& theFieldStepName,
2312                                        const double theFieldStepRangeMin,
2313                                        const double theFieldStepRangeMax )
2314 {
2315   myFieldDataType = theFieldDataType;
2316   myFieldDimension = theFieldDimension;
2317   myFieldStepData = theFieldStepData;
2318   myFieldStepName = theFieldStepName;
2319   myFieldStepRangeMin = theFieldStepRangeMin;
2320   myFieldStepRangeMax = theFieldStepRangeMax;
2321 }
2322
2323 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2324 {
2325   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2326   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2327   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2328   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2329   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2330          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2331 }
2332
2333 int GEOM_Displayer::SetDisplayMode( const int theMode )
2334 {
2335   int aPrevMode = myDisplayMode;
2336   if ( theMode != -1 ) {
2337     myDisplayMode = theMode;
2338     myHasDisplayMode = true;
2339   }
2340   else {
2341     UnsetDisplayMode();
2342   }
2343   return aPrevMode;
2344 }
2345
2346 int GEOM_Displayer::GetDisplayMode() const
2347 {
2348   return myDisplayMode;
2349 }
2350
2351 int GEOM_Displayer::UnsetDisplayMode()
2352 {
2353   int aPrevMode = myDisplayMode;
2354   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2355   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2356   myHasDisplayMode = false;
2357   return aPrevMode;
2358 }
2359
2360 bool GEOM_Displayer::HasDisplayMode() const
2361 {
2362   return myHasDisplayMode;
2363 }
2364
2365 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2366 {
2367   static QList<QColor> colors;
2368
2369   if ( colors.isEmpty() ) {
2370
2371     for (int s = 0; s < 2 ; s++)
2372     {
2373       for (int v = 100; v >= 40; v = v - 20)
2374       {
2375         for (int h = 0; h < 359 ; h = h + 60)
2376         {
2377           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2378         }
2379       }
2380     }
2381   }
2382
2383   static int currentColor = randomize( colors.size() );
2384
2385   SALOMEDS::Color color;
2386   color.R = (double)colors[currentColor].red()   / 255.0;
2387   color.G = (double)colors[currentColor].green() / 255.0;
2388   color.B = (double)colors[currentColor].blue()  / 255.0;
2389
2390   currentColor = (currentColor+1) % colors.count();
2391
2392   return color;
2393 }
2394
2395 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2396 {
2397   int aHue = -1;
2398   int aTolerance = 64;
2399   int anIterations = 0;
2400   int aPeriod = 5;
2401
2402   while( 1 )
2403   {
2404     anIterations++;
2405     if( anIterations % aPeriod == 0 )
2406     {
2407       aTolerance /= 2;
2408       if( aTolerance < 1 )
2409         break;
2410     }
2411     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2412
2413     aHue = (int)( 360.0 * rand() / RAND_MAX );
2414     //std::cout << "Hue = " << aHue << std::endl;
2415
2416     //std::cout << "Auto colors : ";
2417     bool ok = true;
2418     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2419     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2420     for( ; it != itEnd; ++it )
2421     {
2422       SALOMEDS::Color anAutoColor = *it;
2423       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2424
2425       int h, s, v;
2426       aQColor.getHsv( &h, &s, &v );
2427       //std::cout << h << " ";
2428       if( abs( h - aHue ) < aTolerance )
2429       {
2430         ok = false;
2431         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2432         break;
2433       }
2434     }
2435     //std::cout << std::endl;
2436
2437     if( ok )
2438       break;
2439   }
2440
2441   //std::cout << "Hue of the returned color = " << aHue << std::endl;
2442   QColor aColor;
2443   aColor.setHsv( aHue, 255, 255 );
2444
2445   SALOMEDS::Color aSColor;
2446   aSColor.R = (double)aColor.red() / 255.0;
2447   aSColor.G = (double)aColor.green() / 255.0;
2448   aSColor.B = (double)aColor.blue() / 255.0;
2449
2450   return aSColor;
2451 }
2452
2453 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2454                                              const QString& entry,
2455                                              SALOME_View* view )
2456 {
2457   // get default properties for the explicitly specified default view type
2458   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2459
2460   if ( study && view ) {
2461     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2462     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2463     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2464   
2465     if ( viewModel && viewId != -1 ) {
2466       // get properties from the study
2467       PropMap storedMap = study->getObjectProperties( viewId, entry );
2468       // overwrite default properties from stored ones (that are specified)
2469       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2470         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2471           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
2472                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2473       }
2474       // ... specific processing for color
2475       // ... current implementation is to use same stored color for all aspects
2476       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2477       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2478         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2479         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2480         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2481         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2482         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2483       }
2484
2485       if ( !entry.isEmpty() ) {
2486         // get CORBA reference to geom object
2487         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2488         if ( SO ) {
2489           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2490           if ( !CORBA::is_nil( object ) ) {
2491             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2492             if ( !CORBA::is_nil( geomObject ) ) { // to check
2493               // check that geom object has color properly set
2494               bool hasColor = false;
2495               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2496               // set color from geometry object (only once, if it is not yet set in GUI)
2497               // current implementation is to use same color for all aspects
2498               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2499               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2500                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2501                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
2502                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2503                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
2504                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
2505                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
2506               }
2507               // check that object has point marker properly set
2508               GEOM::marker_type mType = geomObject->GetMarkerType();
2509               GEOM::marker_size mSize = geomObject->GetMarkerSize();
2510               int mTextureId = geomObject->GetMarkerTexture();
2511               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
2512                                ( mType == GEOM::MT_USER && mTextureId > 0 );
2513               // set point marker from geometry object (only once, if it is not yet set in GUI)
2514               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2515                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2516                   // standard type
2517                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2518                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2519                 }
2520                 else if ( mType == GEOM::MT_USER ) {
2521                   // custom texture
2522                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2523                 }
2524               }
2525             }
2526           }
2527         }
2528       }
2529     }
2530   }
2531   return propMap;
2532 }
2533
2534 PropMap GEOM_Displayer::getDefaultPropertyMap()
2535 {
2536   PropMap propMap;
2537
2538   // get resource manager
2539   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2540
2541   // fill in the properties map with default values
2542
2543   // - visibility (false by default)
2544   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2545
2546   // - nb isos (take default value from preferences)
2547   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2548                   QString( "%1%2%3" ).
2549                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2550                   arg( GEOM::subSectionSeparator() ).
2551                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2552
2553   // - transparency (opacity = 1-transparency)
2554   propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2555                   resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2556
2557   // - display mode (take default value from preferences)
2558   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2559                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2560
2561   // - show edges direction flag (false by default)
2562   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2563
2564   // - show vertices flag (false by default)
2565   propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2566
2567   // - show name flag (false by default)
2568   propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2569
2570   // - shading color (take default value from preferences)
2571   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2572                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2573
2574   // - wireframe color (take default value from preferences)
2575   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2576                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2577
2578   // - standalone edges color (take default value from preferences)
2579   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2580                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2581
2582   // - free boundaries color (take default value from preferences)
2583   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2584                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2585
2586   // - points color (take default value from preferences)
2587   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2588                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2589
2590   // - isos color (take default value from preferences)
2591   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2592                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2593
2594   // - outlines color (take default value from preferences)
2595   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2596                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2597
2598   // - deflection coefficient (take default value from preferences)
2599   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2600                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2601
2602   // - material (take default value from preferences)
2603   Material_Model material;
2604   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2605   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2606
2607   // - edge width (take default value from preferences)
2608   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2609                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2610
2611   // - isos width (take default value from preferences)
2612   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2613                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2614
2615   // - point marker (take default value from preferences)
2616   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2617                   QString( "%1%2%3" ).
2618                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2619                   arg( GEOM::subSectionSeparator() ).
2620                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2621
2622   // - top-level flag (false by default)
2623   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2624
2625   return propMap;
2626 }
2627
2628 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2629   SALOMEDS::Color aSColor;
2630   hasColor = false;
2631
2632   SUIT_Session* session = SUIT_Session::session();
2633   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2634
2635   if ( app && !theGeomObject->_is_nil()) {
2636     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2637
2638     if ( study ) {
2639       _PTR(Study) aStudy = study->studyDS();
2640       aSColor = theGeomObject->GetColor();
2641       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2642       if ( !hasColor ) {
2643 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2644         bool general_autocolor = true;
2645 #else                    // auto-color for groups only
2646         bool general_autocolor = false;
2647 #endif                   // GENERAL_AUTOCOLOR
2648         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2649           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2650           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2651 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2652             aSColor = getPredefinedUniqueColor();
2653             hasColor = true;
2654 #else                    // old algorithm  for auto-colors
2655             QList<SALOMEDS::Color> aReservedColors;
2656             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2657             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2658             if ( aMainSObject ) {
2659               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2660               for ( ; it->More(); it->Next() ) {
2661                 _PTR(SObject) aChildSObject( it->Value() );
2662                 GEOM::GEOM_Object_var aChildObject =
2663                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2664                 if ( CORBA::is_nil( aChildObject ) )
2665                   continue;
2666
2667                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2668                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2669                   aReservedColors.append( aReservedColor );
2670               }
2671             }
2672             aSColor = getUniqueColor( aReservedColors );
2673             hasColor = true;
2674 #endif                   // SIMPLE_AUTOCOLOR
2675           }
2676         }
2677       }
2678     }
2679   }
2680   return aSColor;
2681 }
2682
2683
2684 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2685                                        const bool eraseOnlyChildren) {
2686   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2687   if ( !app )
2688     return;
2689
2690   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2691   if ( !appStudy )
2692     return;
2693
2694   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2695
2696   if( !parent)
2697     return;
2698
2699   // Erase from all views
2700   QList<SALOME_View*> views;
2701   SALOME_View* view;
2702   ViewManagerList vmans = app->viewManagers();
2703   SUIT_ViewManager* vman;
2704   foreach ( vman, vmans ) {
2705     SUIT_ViewModel* vmod = vman->getViewModel();
2706     view = dynamic_cast<SALOME_View*> ( vmod );
2707     if ( view )
2708       views.append( view );
2709   }
2710
2711   if( views.count() == 0 )
2712     return;
2713
2714   //Erase childrens w/o update views
2715   DataObjectList listObj = parent->children( true );
2716   SUIT_DataObject* obj;
2717   foreach( obj, listObj ) {
2718     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2719     if(l_obj)
2720       foreach ( view, views ) {
2721       Handle(SALOME_InteractiveObject) anIO =
2722         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2723       Erase(anIO, false, false, view);
2724     }
2725   }
2726
2727   //Erase parent with view update or repaint views
2728   foreach ( view, views ) {
2729     if(!eraseOnlyChildren)
2730       Erase(theIO, false, true, view);
2731     else
2732       view->Repaint();
2733   }
2734 }
2735
2736 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2737 {
2738   if( theGeomFieldStep->_is_nil() )
2739     return;
2740
2741   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2742   if( aGeomField->_is_nil() )
2743     return;
2744
2745   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2746   if( aGeomFieldShape->_is_nil() )
2747     return;
2748
2749   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2750   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2751   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2752
2753   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2754
2755   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2756
2757   int aFieldDimension = aGeomField->GetDimension();
2758
2759   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2760   int aFieldNbComponents = aFieldComponents->length();
2761
2762   QList<QVariant> aFieldStepData;
2763   if( aFieldDataType == GEOM::FDT_Bool )
2764   {
2765     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2766     if ( !aGeomBoolFieldStep->_is_nil() )
2767     {
2768       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2769       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2770         aFieldStepData << (bool)aValues[i];
2771     }
2772   }
2773   else if( aFieldDataType == GEOM::FDT_Int )
2774   {
2775     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2776     if ( !aGeomIntFieldStep->_is_nil() )
2777     {
2778       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2779       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2780         aFieldStepData << (qlonglong)aValues[i];
2781     }
2782   }
2783   else if( aFieldDataType == GEOM::FDT_Double )
2784   {
2785     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2786     if ( !aGeomDoubleFieldStep->_is_nil() )
2787     {
2788       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2789       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2790         aFieldStepData << (double)aValues[i];
2791     }
2792   }
2793   else if( aFieldDataType == GEOM::FDT_String )
2794   {
2795     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2796     if ( !aGeomStringFieldStep->_is_nil() )
2797     {
2798       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2799       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2800         aFieldStepData << QString( aValues[i] );
2801     }
2802   }
2803
2804   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2805   aFieldStepData = groupFieldData( aFieldStepData,
2806                                    aFieldNbComponents,
2807                                    aFieldDataType == GEOM::FDT_String,
2808                                    aFieldStepRangeMin,
2809                                    aFieldStepRangeMax );
2810
2811   setFieldStepInfo( aFieldDataType,
2812                     aFieldDimension,
2813                     aFieldStepData,
2814                     aFieldStepName,
2815                     aFieldStepRangeMin,
2816                     aFieldStepRangeMax );
2817 }
2818
2819 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2820                                                 const int theFieldNbComponents,
2821                                                 const bool theIsString,
2822                                                 double& theFieldStepRangeMin,
2823                                                 double& theFieldStepRangeMax )
2824 {
2825   QList<QVariant> aResultList;
2826   theFieldStepRangeMin = 0;
2827   theFieldStepRangeMax = 0;
2828
2829   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2830     return aResultList;
2831
2832   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2833
2834   QList<QVariant> aGroupedList;
2835
2836   bool anIsBoolean = false;
2837   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2838   {
2839     double aNorm = 0;
2840     QStringList aStringList;
2841
2842     int aBaseIndex = aSubShape * theFieldNbComponents;
2843     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2844     {
2845       int anIndex = aComponent + aBaseIndex;
2846
2847       const QVariant& aVariant = theFieldStepData[ anIndex ];
2848       if( theIsString )
2849       {
2850         if( aVariant.type() == QVariant::String )
2851           aStringList << aVariant.toString();
2852       }
2853       else
2854       {
2855         double aValue = 0;
2856         if( aVariant.type() == QVariant::Bool )
2857         {
2858           aValue = aVariant.toBool() ? 1.0 : 0.0;
2859           aNorm += aValue;
2860           anIsBoolean = true;
2861         }
2862         else
2863         {
2864           if( aVariant.type() == QVariant::LongLong )
2865             aValue = double( aVariant.toLongLong() );
2866           else if( aVariant.type() == QVariant::Double )
2867             aValue = aVariant.toDouble();
2868           aNorm += aValue * aValue;
2869         }
2870       }
2871     }
2872
2873     if( theIsString )
2874       aGroupedList << aStringList.join( "\n" );
2875     else
2876     {
2877       if( anIsBoolean )
2878         aNorm /= theFieldNbComponents;
2879       else
2880         aNorm = pow( aNorm, 0.5 );
2881
2882       if( aGroupedList.isEmpty() )
2883         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2884       else
2885       {
2886         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2887         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2888       }
2889
2890       aGroupedList << aNorm;
2891     }
2892   }
2893
2894   if( anIsBoolean )
2895   {
2896     theFieldStepRangeMin = 0.0;
2897     theFieldStepRangeMax = 1.0;
2898   }
2899
2900   SUIT_Session* session = SUIT_Session::session();
2901   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2902   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2903
2904   QListIterator<QVariant> anIter( aGroupedList );
2905   while( anIter.hasNext() )
2906   {
2907     const QVariant& aVariant = anIter.next();
2908     if( theIsString )
2909       aResultList << aVariant;
2910     else
2911     {
2912       QColor aQColor;
2913       Quantity_Color aColor;
2914       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2915         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2916       aResultList << aQColor;
2917     }
2918   }
2919   return aResultList;
2920 }
2921
2922 // Note: the method is copied from Aspect_ColorScale class
2923 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2924                                                const Standard_Integer aMin,
2925                                                const Standard_Integer aMax )
2926 {
2927   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2928
2929   Standard_Integer aHue = maxLimit;
2930   if ( aMin != aMax )
2931     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2932
2933   aHue = Min( Max( minLimit, aHue ), maxLimit );
2934
2935   return aHue;
2936 }
2937
2938 // Note: the method is copied from Aspect_ColorScale class
2939 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2940                                             const Standard_Real aMin,
2941                                             const Standard_Real aMax,
2942                                             const Standard_Integer ColorsCount,
2943                                             Quantity_Color& aColor )
2944 {
2945   if( aValue<aMin || aValue>aMax || aMax<aMin )
2946     return Standard_False;
2947
2948   else
2949   {
2950     Standard_Real IntervNumber = 0;
2951     if( aValue<aMin )
2952       IntervNumber = 0;
2953     else if( aValue>aMax )
2954       IntervNumber = ColorsCount-1;
2955     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2956       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2957
2958     Standard_Integer Interv = Standard_Integer( IntervNumber );
2959
2960     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2961
2962     return Standard_True;
2963   } 
2964 }
2965
2966 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2967 {
2968   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2969   if( !aStudy )
2970     return;
2971
2972   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2973   if( !aViewModel )
2974     return;
2975
2976   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2977   if( aViewer.IsNull() )
2978     return;
2979
2980   aViewer->InitActiveViews();
2981   if( !aViewer->MoreActiveViews() )
2982     return;
2983
2984   Handle(V3d_View) aView = aViewer->ActiveView();
2985   if( aView.IsNull() )
2986     return;
2987
2988   Standard_Boolean anIsDisplayColorScale = Standard_False;
2989   TCollection_AsciiString aColorScaleTitle;
2990   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2991   Standard_Boolean anIsBoolean = Standard_False;
2992
2993   SALOME_ListIO aSelectedObjects;
2994   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2995   if( aSelectedObjects.Extent() == 1 )
2996   {
2997     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2998     if( !anIO.IsNull() )
2999     {
3000       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3001       if( aPrs )
3002       {
3003         AIS_ListOfInteractive aList;
3004         aPrs->GetObjects( aList );
3005         AIS_ListIteratorOfListOfInteractive anIter( aList );
3006         for( ; anIter.More(); anIter.Next() )
3007         {
3008           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3009           if( !aShape.IsNull() )
3010           {
3011             GEOM::field_data_type aFieldDataType;
3012             int aFieldDimension;
3013             QList<QVariant> aFieldStepData;
3014             TCollection_AsciiString aFieldStepName;
3015             double aFieldStepRangeMin, aFieldStepRangeMax;
3016             aShape->getFieldStepInfo( aFieldDataType,
3017                                       aFieldDimension,
3018                                       aFieldStepData,
3019                                       aFieldStepName,
3020                                       aFieldStepRangeMin,
3021                                       aFieldStepRangeMax );
3022             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3023             {
3024               anIsDisplayColorScale = Standard_True;
3025               aColorScaleTitle = aFieldStepName;
3026               aColorScaleMin = aFieldStepRangeMin;
3027               aColorScaleMax = aFieldStepRangeMax;
3028               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3029             }
3030           }
3031         }
3032       }
3033     }
3034   }
3035
3036   if( anIsDisplayColorScale )
3037   {
3038     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
3039     if( !aColorScale.IsNull() )
3040     {
3041       SUIT_Session* session = SUIT_Session::session();
3042       SUIT_ResourceMgr* resMgr = session->resourceMgr();
3043
3044       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3045       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3046       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3047       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3048       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3049       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3050  
3051       aColorScale->SetXPosition( anXPos );
3052       aColorScale->SetYPosition( anYPos );
3053       aColorScale->SetWidth( aWidth );
3054       aColorScale->SetHeight( aHeight );
3055
3056       aColorScale->SetTextHeight( aTextHeight );
3057       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3058
3059       aColorScale->SetTitle( aColorScaleTitle );
3060       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3061     }
3062     if( !aView->ColorScaleIsDisplayed() )
3063       aView->ColorScaleDisplay();
3064   }
3065   else
3066   {
3067     if( aView->ColorScaleIsDisplayed() )
3068       aView->ColorScaleErase();
3069   }
3070
3071   if( theIsRedisplayFieldSteps )
3072   {
3073     _PTR(Study) aStudyDS = aStudy->studyDS();
3074     QList<SUIT_ViewManager*> vmList;
3075     myApp->viewManagers( vmList );
3076     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3077     {
3078       if( SUIT_ViewManager* aViewManager = *vmIt )
3079       {
3080         const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3081         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3082         {
3083           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3084           if( aSObj )
3085           {
3086             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3087             if( !CORBA::is_nil( anObject ) )
3088             {
3089               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3090               if( !aFieldStep->_is_nil() )
3091               {
3092                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3093                 Handle(SALOME_InteractiveObject) aStepIO =
3094                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3095                 Redisplay( aStepIO, false, false );
3096               }
3097             }
3098           }
3099         }
3100       }
3101     }
3102   }
3103   if(updateViewer)
3104     UpdateViewer();
3105 }