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