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