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