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