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