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