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