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