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