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