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