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