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