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