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