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