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