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