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