]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
Merge from V7_3_BR branch 18/12/2013
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 // Copyright (C) 2007-2013  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.
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
29 #include "GeometryGUI.h"
30
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
39
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_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 <Material_Model.h>
49
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ResourceMgr.h>
55
56 #include <Basics_OCCTVersion.hxx>
57
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Application.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_DataObject.h>
62 #include <SalomeApp_TypeFilter.h>
63 #include <SalomeApp_Tools.h>
64
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_Prs.h>
68
69 #include <SOCC_Prs.h>
70 #include <SOCC_ViewModel.h>
71
72 #include <SVTK_Prs.h>
73 #include <SVTK_ViewModel.h>
74
75 #include <OCCViewer_ViewWindow.h>
76 #include <OCCViewer_ViewPort3d.h>
77
78 // OCCT Includes
79 #include <AIS_Drawer.hxx>
80 #include <AIS_ListIteratorOfListOfInteractive.hxx>
81 #include <Aspect_ColorScale.hxx>
82 #include <Prs3d_IsoAspect.hxx>
83 #include <Prs3d_PointAspect.hxx>
84 #include <StdSelect_TypeOfEdge.hxx>
85 #include <StdSelect_TypeOfFace.hxx>
86 #include <StdSelect_DisplayMode.hxx>
87 #include <TopoDS_Face.hxx>
88 #include <BRep_Tool.hxx>
89 #include <Geom_Plane.hxx>
90 #include <Geom_Axis2Placement.hxx>
91 #include <Graphic3d_AspectFillArea3d.hxx>
92 #include <gp_Pln.hxx>
93 #include <TColStd_MapOfInteger.hxx>
94 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
95 #include <TopoDS_Iterator.hxx>
96 #include <Graphic3d_AspectMarker3d.hxx>
97 #include <TopTools_MapOfShape.hxx>
98 #include <TopTools_ListOfShape.hxx>
99 #include <TopTools_ListIteratorOfListOfShape.hxx>
100 #include <TopoDS.hxx>
101
102 #include <Prs3d_ShadingAspect.hxx>
103
104 #include <BRepMesh_IncrementalMesh.hxx>
105
106 // VTK Includes
107 #include <vtkActorCollection.h>
108 #include <vtkProperty.h>
109
110 // CORBA Headers
111 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
112
113 #include <GEOMImpl_Types.hxx>
114
115 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
116 #include <TColStd_HArray1OfByte.hxx>
117 #else
118 #include <Graphic3d_HArray1OfBytes.hxx>
119 #endif
120
121 // If the next macro is defined, autocolor feature works for all sub-shapes;
122 // if it is undefined, autocolor feature works for groups only
123 #define GENERAL_AUTOCOLOR
124 // Below macro, when uncommented, switches on simplified (more performant) algorithm
125 // of auto-color picking up
126 #define SIMPLE_AUTOCOLOR
127
128 // Hard-coded value of shape deflection coefficient for VTK viewer
129 const double VTK_MIN_DEFLECTION = 0.001;
130
131 //================================================================
132 // Function : getActiveStudy
133 // Purpose  : Get active study, returns 0 if no open study frame
134 //================================================================
135 static inline SalomeApp_Study* getActiveStudy()
136 {
137   SUIT_Session* session = SUIT_Session::session();
138   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
139   if ( app )
140     return ( SalomeApp_Study* )app->activeStudy();
141   return 0;
142 }
143
144 static inline int getViewManagerId( SALOME_View* theViewFrame) {
145   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
146   SUIT_ViewManager* aViewMgr = 0;
147   if (aModel != 0)
148     aViewMgr = aModel->getViewManager();
149   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
150 }
151
152 //================================================================
153 // Function : getTopAbsMode
154 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
155 //            one from GEOMImpl_Types.h
156 //================================================================
157 static inline int getTopAbsMode( const int implType )
158 {
159   switch ( implType )
160   {
161     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
162     case GEOM_SOLID     : return TopAbs_SOLID;
163     case GEOM_SHELL     : return TopAbs_SHELL;
164     case GEOM_FACE      : return TopAbs_FACE;
165     case GEOM_WIRE      : return TopAbs_WIRE;
166     case GEOM_EDGE      : return TopAbs_EDGE;
167     case GEOM_POINT     : return TopAbs_VERTEX;
168     default             : return -1;
169   }
170 }
171
172 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
173 {
174   if ( shape.IsNull() )
175     return TopAbs_SHAPE;
176
177   int ret = shape.ShapeType();
178
179   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
180     TopoDS_Iterator it(shape, Standard_True, Standard_False);
181     for (; it.More(); it.Next()) {
182       TopoDS_Shape sub_shape = it.Value();
183       if ( sub_shape.IsNull() ) continue;
184       int stype = getMinMaxShapeType( sub_shape, ismin );
185       if ( stype == TopAbs_SHAPE ) continue;
186       if ( ismin && stype > ret )
187         ret = stype;
188       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
189         ret = stype;
190     }
191   }
192
193   return ret;
194 }
195
196 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
197 {
198   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
199 }
200
201 //================================================================
202 // Function : getFilter
203 // Purpose  : Get filter corresponding to the type of object
204 //            from GEOMImpl_Types.h
205 //================================================================
206 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
207 {
208   SUIT_SelectionFilter* aFilter;
209
210   int aTopAbsMode = getTopAbsMode( theMode );
211   if ( aTopAbsMode != -1 )
212     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
213   else
214     switch ( theMode )
215       {
216       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
217       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
218
219       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
220       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
221       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
222       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
223       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
224       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
225
226       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
227
228       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
229       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
230
231       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
232       }
233
234   return aFilter;
235 }
236
237 //================================================================
238 // Function : getComplexFilter
239 // Purpose  : Get compound filter corresponding to the type of
240 //            object from GEOMImpl_Types.h
241 //================================================================
242 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
243 {
244   GEOM_CompoundFilter* aFilter;
245
246   if(aSubShapes != NULL ) {
247     aFilter = new GEOM_CompoundFilter(getStudy());
248     QList<int> aTopAbsTypes;
249     QList<int>::const_iterator it;
250     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
251       int topAbsMode = getTopAbsMode(*it);
252       if(topAbsMode != -1 )
253         aTopAbsTypes.append(topAbsMode);
254     }
255     aFilter->addSubTypes(aTopAbsTypes);
256   }
257
258   return aFilter;
259 }
260
261 //================================================================
262 // Function : getEntry
263 // Purpose  :
264 //================================================================
265 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
266 {
267   SUIT_Session* session = SUIT_Session::session();
268   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
269   if ( app )
270   {
271     CORBA::String_var IOR = app->orb()->object_to_string( object );
272     if ( strcmp(IOR.in(), "") != 0 )
273     {
274       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
275       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
276       if ( SO )
277         return SO->GetID();
278     }
279   }
280   return "";
281 }
282
283 //================================================================
284 // Function : getName
285 // Purpose  :
286 //================================================================
287 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
288 {
289   SUIT_Session* session = SUIT_Session::session();
290   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
291   if ( app )
292   {
293     CORBA::String_var IOR = app->orb()->object_to_string( object );
294     if ( strcmp(IOR.in(), "") != 0 )
295     {
296       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
297       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
298
299       _PTR(GenericAttribute) anAttr;
300
301       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
302       {
303         _PTR(AttributeName) aNameAttr( anAttr );
304         return aNameAttr->Value();
305       }
306     }
307   }
308
309   return "";
310 }
311
312 //=================================================================
313 /*!
314  *  GEOM_Displayer::GEOM_Displayer
315  *  Constructor
316  */
317 //=================================================================
318 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
319 {
320   if( st )
321     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
322   else
323     myApp = 0;
324
325   /* Shading Color */
326   SUIT_Session* session = SUIT_Session::session();
327   SUIT_ResourceMgr* resMgr = session->resourceMgr();
328
329   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
330   myShadingColor = SalomeApp_Tools::color( col );
331
332   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
333   myHasDisplayMode = false;
334
335   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
336   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
337   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
338
339   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
340   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
341   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
342
343   myColor = -1;
344   // This color is used for shape displaying. If it is equal -1 then
345   // default color is used.
346   myTexture = "";
347
348   myWidth = -1;
349   myType = -1;
350
351   myToActivate = true;
352   // This parameter is used for activisation/deactivisation of objects to be displayed
353
354   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
355   // Activate parallel vizualisation only for testing purpose
356   // and if the corresponding env variable is set to 1
357   char* parallel_visu = getenv("PARALLEL_VISU");
358   if (parallel_visu && atoi(parallel_visu))
359   {
360     MESSAGE("Parallel visualisation on");
361     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
362   }
363   #endif
364
365   myViewFrame = 0;
366
367   myFieldDataType = GEOM::FDT_Double;
368   myFieldDimension = 0;
369   myFieldStepRangeMin = 0;
370   myFieldStepRangeMax = 0;
371 }
372
373 //=================================================================
374 /*!
375  *  GEOM_Displayer::~GEOM_Displayer
376  *  Destructor
377  */
378 //=================================================================
379 GEOM_Displayer::~GEOM_Displayer()
380 {
381 }
382
383 //=================================================================
384 /*!
385  *  GEOM_Displayer::Display
386  *  Display interactive object in the current viewer
387  */
388 //=================================================================
389 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
390                              const bool updateViewer,
391                              SALOME_View* theViewFrame )
392 {
393   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
394   if ( vf )
395   {
396     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
397
398     if ( prs )
399     {
400       vf->BeforeDisplay( this, prs );
401       vf->Display( prs );
402       vf->AfterDisplay( this, prs );
403
404       if ( updateViewer )
405         vf->Repaint();
406
407       int aMgrId = getViewManagerId(vf);
408       SalomeApp_Study* aStudy = getStudy();
409       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
410
411       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
412
413       delete prs;  // delete presentation because displayer is its owner
414     }
415   }
416 }
417
418 //=================================================================
419 /*!
420  *  GEOM_Displayer::Display
421  *  This overloaded Display() method can be useful for operations
422  *  not using dialog boxes.
423  */
424 //=================================================================
425 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
426 {
427   if ( theObj->_is_nil() )
428     return;
429
430   std::string entry = getEntry( theObj );
431   if ( entry != "" ) {
432     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
433             updateViewer);
434   }
435 }
436
437 //=================================================================
438 /*!
439  *  GEOM_Displayer::Erase
440  *  Erase interactive object in the current viewer
441  */
442 //=================================================================
443 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
444                             const bool forced,
445                             const bool updateViewer,
446                             SALOME_View* theViewFrame )
447 {
448   if ( theIO.IsNull() )
449     return;
450
451   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
452
453   if ( vf ) {
454     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
455     if ( prs ) {
456       vf->BeforeErase( this, prs );
457       vf->Erase( prs, forced );
458       vf->AfterErase( this, prs );
459       if ( updateViewer )
460         vf->Repaint();
461       delete prs;  // delete presentation because displayer is its owner
462
463       int aMgrId = getViewManagerId(vf);
464       SalomeApp_Study* aStudy = getStudy();
465       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
466
467       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
468     }
469   }
470 }
471
472 //=================================================================
473 /*!
474  *  GEOM_Displayer::Erase
475  *  Erase geometry object in the current viewer
476  */
477 //=================================================================
478 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
479                             const bool forced,
480                             const bool updateViewer )
481 {
482   std::string entry = getEntry( theObj );
483   if ( entry != "" )
484   {
485     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
486           forced, updateViewer);
487   }
488 }
489
490 //=================================================================
491 /*!
492  *  GEOM_Displayer::Redisplay
493  *  Redisplay (erase and then display again) interactive object
494  *  in the current viewer
495  */
496 //=================================================================
497 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
498                                 const bool updateViewer,
499                                 const bool checkActiveViewer )
500 {
501   // Remove the object permanently (<forced> == true)
502   SUIT_Session* ses = SUIT_Session::session();
503   SUIT_Application* app = ses->activeApplication();
504   if ( app )
505   {
506     SUIT_Desktop* desk = app->desktop();
507     QList<SUIT_ViewWindow*> wnds = desk->windows();
508     SUIT_ViewWindow* wnd;
509     QListIterator<SUIT_ViewWindow*> it( wnds );
510     while ( it.hasNext() && (wnd = it.next()) )
511     {
512       SUIT_ViewManager* vman = wnd->getViewManager();
513       if ( vman )
514       {
515         SUIT_ViewModel* vmodel = vman->getViewModel();
516         if ( vmodel )
517         {
518           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
519           if ( view )
520           {
521             if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
522             {
523               Erase( theIO, true, false, view );
524               Display( theIO, updateViewer, view );
525             }
526           }
527         }
528       }
529     }
530   }
531 }
532
533 //=================================================================
534 /*!
535  *  GEOM_Displayer::Display
536  *  Calls Display() method for each object in the given list
537  */
538 //=================================================================
539 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
540 {
541   SALOME_ListIteratorOfListIO Iter( theIOList );
542   for ( ; Iter.More(); Iter.Next() ) {
543     Display( Iter.Value(), false );
544   }
545   if ( updateViewer )
546     UpdateViewer();
547 }
548
549 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
550 {
551   // VSR: this method can be improved in future:
552   // to improve performance, the default values from resource manager should be cached in the displayer
553   return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
554 }
555
556 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
557 {
558   // VSR: this method can be improved in future:
559   // to improve performance, the default values from resource manager should be cached in the displayer
560   return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
561 }
562
563 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
564 {
565   // check that shape is not null
566   if ( AISShape.IsNull() ) return;
567   
568   // check that study is active
569   SalomeApp_Study* study = getStudy();
570   if ( !study ) return;
571
572   if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
573        !TopoDS_Iterator(myShape).More() )
574     return; // NPAL15983 (Bug when displaying empty groups)
575
576   // set interactive object
577
578   Handle( SALOME_InteractiveObject ) anIO;
579
580   if ( !myIO.IsNull() ) {
581     AISShape->setIO( myIO );
582     AISShape->SetOwner( myIO );
583     anIO = myIO;
584   }
585   else if ( !myName.empty() ) {
586     // workaround to allow selection of temporary objects
587     static int tempId = 0;
588     anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
589     AISShape->setIO( anIO );
590     AISShape->SetOwner( anIO );
591   }
592
593   // flag:  only vertex or compound of vertices is processed (specific handling)
594   bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
595   // presentation study entry (empty for temporary objects like preview)
596   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
597   // flag: temporary object
598   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
599   // currently active view window's ID (-1 if no active view)
600   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
601
602   // get presentation properties
603   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
604
605   // Temporary staff: vertex must be infinite for correct visualization
606   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
607
608   // set material
609   Material_Model material;
610   // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
611   if( !HasColor() )
612     material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
613   // - set front material properties
614   AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
615   AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
616   // - set back material properties
617   AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
618   AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
619   // - switch to default (both sides) facing mode
620   AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
621
622   // set colors
623
624   // - shading color
625   if ( HasColor()  ) {
626     // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
627     // we set it to the shape not taking into account material properties
628     AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
629   }
630   else if ( !material.isPhysical() ) {
631     // shading color from properties is used only for non-physical materials
632     AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
633   }
634
635   // - wireframe color
636   Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
637   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
638                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
639   AISShape->Attributes()->SetLineAspect( anAspect );
640   
641   // - unfree boundaries color
642   anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
643   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
644                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
645   AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
646   
647   // - free boundaries color
648   anAspect = AISShape->Attributes()->FreeBoundaryAspect();
649   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
650                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
651   AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
652   
653   // - standalone edges color
654   anAspect = AISShape->Attributes()->WireAspect();
655   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
656                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
657   AISShape->Attributes()->SetWireAspect( anAspect );
658   
659   // - color for edges in shading+edges mode
660   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
661   
662   // ???
663   AISShape->storeBoundaryColors();
664
665   // set display mode
666   AISShape->SetDisplayMode( HasDisplayMode() ? 
667                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
668                             GetDisplayMode() :
669                             // display mode from properties
670                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
671
672   // set display vectors flag
673   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
674
675   // set transparency
676   AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
677
678   // set iso properties
679   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
680   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
681   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
682   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
683   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
684   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
685   uIsoAspect->SetColor( isosColor );
686   uIsoAspect->SetWidth( isosWidth );
687   uIsoAspect->SetNumber( uIsos );
688   vIsoAspect->SetColor( isosColor );
689   vIsoAspect->SetWidth( isosWidth );
690   vIsoAspect->SetNumber( vIsos );
691   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
692   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
693
694   // set deflection coefficient
695   // ... to avoid to small values of the coefficient, its lower value is limited 
696   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
697
698   // set texture
699   bool textureAdded = false;
700   if ( HasTexture() ) {
701     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
702     AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
703     if ( ! entry.isEmpty() ) {
704       // check that study is active
705       SalomeApp_Study* study = getActiveStudy();
706       if ( study ) {
707         // Store the texture in object properties for next displays
708         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
709         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
710         
711         // Update porpeties map
712         propMap = getObjectProperties( study, entry, myViewFrame );
713       }
714     }
715     textureAdded = true;
716   }
717   else {
718     // Texture from properties
719     QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
720     if ( !aTexture.isEmpty() ) {
721        AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toStdString().c_str() ) );
722        textureAdded = true;
723     }
724   }
725  
726   if ( textureAdded ){ 
727     AISShape->SetTextureMapOn();
728     AISShape->DisableTextureModulate();
729   }
730
731   // set line width
732   AISShape->SetWidth( HasWidth() ?
733                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
734                       GetWidth() :
735                       // libe width from properties
736                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
737
738   // set top-level flag
739   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
740
741   // set point marker (for vertex / compound of vertices only)
742   if ( onlyVertex ) {
743     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
744     if ( aList.size() == 2 ) {
745       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
746       int aTypeOfMarker = aList[0].toInt();
747       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
748       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
749       anAspect->SetScale( aScaleOfMarker );
750       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
751       anAspect->SetColor( HasColor() ? 
752                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
753                           (Quantity_NameOfColor)GetColor() : 
754                           // color from properties
755                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
756       AISShape->Attributes()->SetPointAspect( anAspect );
757     }
758     else if ( aList.size() == 1 ) {
759       // custom marker string contains "IdOfTexture"
760       int textureId = aList[0].toInt();
761       Standard_Integer aWidth, aHeight;
762 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
763       Handle(TColStd_HArray1OfByte) aTexture =
764 #else
765         Handle(Graphic3d_HArray1OfBytes) aTexture =
766 #endif
767         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
768       if ( !aTexture.IsNull() ) {
769 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
770         Handle(Prs3d_PointAspect) aTextureAspect =
771           new Prs3d_PointAspect( HasColor() ? 
772                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
773                                  (Quantity_NameOfColor)GetColor() : 
774                                  // color from properties 
775                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
776                                  aWidth, aHeight,
777                                  aTexture );
778 #else
779         int TextureId = 0;
780         Handle(Prs3d_PointAspect) aTextureAspect =
781           new Prs3d_PointAspect( HasColor() ? 
782                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
783                                  (Quantity_NameOfColor)GetColor() : 
784                                  // color from properties 
785                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
786                                  ++TextureId,
787                                  aWidth, aHeight,
788                                  aTexture );
789 #endif
790         AISShape->Attributes()->SetPointAspect( aTextureAspect );
791       }
792     }
793   }
794
795   // set field step data
796   AISShape->setFieldStepInfo( myFieldDataType,
797                               myFieldDimension,
798                               myFieldStepData,
799                               myFieldStepName,
800                               myFieldStepRangeMin,
801                               myFieldStepRangeMax );
802
803   if ( create && !isTemporary && aMgrId != -1 ) {
804     // set properties to the study
805     study->setObjectPropMap( aMgrId, entry, propMap );
806   }
807
808   // AISShape->SetName(???); ??? necessary to set name ???
809 }
810
811 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
812 {
813   // check that actor is not null
814   if ( !actor ) return;
815   
816   // check that study is active
817   SalomeApp_Study* study = getStudy();
818   if ( !study ) return;
819
820   // set interactive object
821
822   Handle( SALOME_InteractiveObject ) anIO;
823
824   if ( !myIO.IsNull() ) {
825     actor->setIO( myIO );
826     anIO = myIO;
827   }
828   else if ( !myName.empty() ) {
829     // workaround to allow selection of temporary objects
830     static int tempId = 0;
831     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
832     actor->setIO( anIO );
833   }
834
835   // presentation study entry (empty for temporary objects like preview)
836   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
837   // flag: temporary object
838   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
839   // currently active view window's ID (-1 if no active view)
840   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
841
842   // get presentation properties
843   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
844   QColor c;
845
846   /////////////////////////////////////////////////////////////////////////
847   // VSR: for VTK viewer currently deflection coefficient is hardcoded
848   //      due to performance problem
849   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
850   /////////////////////////////////////////////////////////////////////////
851   if ( !actor->getTopo().IsSame( myShape ) )
852     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
853
854   // set material
855   Material_Model material;
856   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
857   std::vector<vtkProperty*> mprops;
858   mprops.push_back( material.getMaterialVTKProperty( true ) );
859   mprops.push_back( material.getMaterialVTKProperty( false) );
860   actor->SetMaterial( mprops );
861
862   // set iso-lines properties
863
864   // - set number of iso-lines
865   int nbIsos[2]= { 1, 1 };
866   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
867   nbIsos[0] = isos[0].toInt();
868   nbIsos[1] = isos[1].toInt();
869   actor->SetNbIsos( nbIsos );
870
871   // - set iso-lines width
872   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
873
874   // - set iso-lines color
875   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
876   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
877
878   // set colors
879
880   if ( HasColor()  ) {
881     // - same color for all sub-actors
882     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
883     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
884   }
885   else {
886     // shading color (for non-physical materials)
887     if ( !material.isPhysical() ) {
888       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
889       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
890       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
891     }
892
893     // - standalone edge color
894     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
895     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
896
897     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
898     // - shared edges color ???
899     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
900
901     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
902     // - free edges color ???
903     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
904
905     // - point color
906     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
907     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
908   }
909
910   // - color for edges in shading+edges mode
911   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
912   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
913
914   // set opacity
915   actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
916
917   // set line width
918   actor->SetWidth( HasWidth() ?
919                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
920                    GetWidth() :
921                    // libe width from properties
922                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
923   
924   // set display vectors flag
925   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
926
927   // set display mode
928   int displayMode = HasDisplayMode() ? 
929     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
930     GetDisplayMode() :
931     // display mode from properties
932     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
933
934   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
935   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
936   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
937   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
938
939   if ( displayMode == 2 )
940       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
941       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
942     displayMode++;
943   actor->setDisplayMode( displayMode );
944
945   if ( myToActivate )
946     actor->PickableOn();
947   else
948     actor->PickableOff();
949
950   if ( create && !isTemporary && aMgrId != -1 ) {
951     // set properties to the study
952     study->setObjectPropMap( aMgrId, entry, propMap );
953   }
954 }
955
956 //=================================================================
957 /*!
958  *  GEOM_Displayer::Erase
959  *  Calls Erase() method for each object in the given list
960  */
961 //=================================================================
962 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
963                             const bool forced,
964                             const bool updateViewer )
965 {
966   SALOME_ListIteratorOfListIO Iter( theIOList );
967   for ( ; Iter.More(); Iter.Next() )
968     Erase( Iter.Value(), forced, false );
969
970   if ( updateViewer )
971     UpdateViewer();
972 }
973
974 //=================================================================
975 /*!
976  *  GEOM_Displayer::Redisplay
977  *  Calls Redisplay() method for each object in the given list
978  */
979 //=================================================================
980 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
981                                 const bool updateViewer,
982                                 const bool checkActiveViewer )
983 {
984   SALOME_ListIteratorOfListIO Iter( theIOList );
985   for ( ; Iter.More(); Iter.Next() )
986     Redisplay( Iter.Value(), false, checkActiveViewer );
987
988   if ( updateViewer )
989     UpdateViewer();
990 }
991
992 //=================================================================
993 /*!
994  *  GEOM_Displayer::Update
995  *  Update OCC presentaion
996  *  [ Reimplemented from SALOME_Displayer ]
997  */
998 //=================================================================
999 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1000 {
1001   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1002   SalomeApp_Study* study = getStudy();
1003
1004   if ( !occPrs || myShape.IsNull() || !study )
1005     return;
1006
1007   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1008   {
1009     // 
1010     // specific processing for local coordinate system presentation
1011     // 
1012
1013     TopoDS_Face aFace = TopoDS::Face( myShape );
1014     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1015     if ( !aPlane.IsNull() )
1016     {
1017       gp_Ax3 aPos = aPlane->Pln().Position();
1018       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1019
1020       Handle(GEOM_AISTrihedron) aTrh;
1021
1022       if ( occPrs->IsNull() )
1023       {
1024         // new presentation is being created
1025         aTrh = new GEOM_AISTrihedron( aPlc );
1026         occPrs->AddObject( aTrh );
1027       }
1028       else
1029       {
1030         // presentation is being updated
1031         AIS_ListOfInteractive aList;
1032         occPrs->GetObjects( aList );
1033         AIS_ListIteratorOfListOfInteractive anIter( aList );
1034         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1035           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1036         }
1037       }
1038         
1039       if ( !aTrh.IsNull() ) {
1040         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1041         if ( HasColor() )
1042           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1043         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1044         if ( HasWidth() )
1045           aTrh->SetWidth( GetWidth() );
1046         
1047         if ( !myIO.IsNull() )
1048         {
1049           aTrh->setIO( myIO );
1050           aTrh->SetOwner( myIO );
1051         }
1052         aTrh->SetComponent( aPlc );
1053         aTrh->SetToUpdate();
1054       }
1055       occPrs->SetToActivate( ToActivate() );
1056     }
1057   }
1058   else
1059   {
1060     // 
1061     // processing for usual geometry presentation
1062     // 
1063
1064     // if presentation is empty we try to create new one
1065     if ( occPrs->IsNull() )
1066     {
1067       // create presentation (specific for vectors)
1068       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1069                                                                  : new GEOM_AISShape ( myShape, "" );
1070
1071       if( myType == GEOM_FIELD_STEP )
1072         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1073       // update shape properties
1074       updateShapeProperties( AISShape, true );
1075
1076       // add shape to the presentation
1077       occPrs->AddObject( AISShape );
1078
1079       // In accordance with ToActivate() value object will be activated/deactivated
1080       // when it will be displayed
1081       occPrs->SetToActivate( ToActivate() );
1082
1083       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1084         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1085
1086         // create additional wireframe shape
1087         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1088         aWirePrs->SetWidth(AISShape->Width());
1089         if ( !myIO.IsNull() ) {
1090           aWirePrs->setIO( myIO );
1091           aWirePrs->SetOwner( myIO );
1092         }
1093
1094         // add shape to the presentation
1095         occPrs->AddObject( aWirePrs );
1096       }
1097     }
1098     // if presentation is found -> set again shape for it
1099     else
1100     {
1101       AIS_ListOfInteractive IOList;
1102       occPrs->GetObjects( IOList );
1103       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1104       for ( ; Iter.More(); Iter.Next() )
1105       {
1106         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1107         if ( AISShape.IsNull() )
1108           continue;
1109
1110         // re-set shape (it might be changed)
1111         if ( AISShape->Shape() != myShape )
1112           AISShape->Set( myShape );
1113
1114         // update shape properties
1115         updateShapeProperties( AISShape, false );
1116
1117         // force updating
1118         AISShape->UpdateSelection();
1119         AISShape->SetToUpdate();
1120       }
1121     }
1122   }
1123 }
1124
1125 //=================================================================
1126 /*!
1127  *  GEOM_Displayer::Update
1128  *  Update VTK presentaion
1129  *  [ Reimplemented from SALOME_Displayer ]
1130  */
1131 //=================================================================
1132 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1133 {
1134   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1135   SalomeApp_Study* study = getStudy();
1136
1137   if ( !vtkPrs || myShape.IsNull() || !study )
1138     return;
1139
1140   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1141   {
1142     // 
1143     // specific processing for local coordinate system presentation
1144     // 
1145
1146     TopoDS_Face aFace = TopoDS::Face( myShape );
1147     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1148     if ( !aPlane.IsNull() ) {
1149       gp_Ax3 aPos = aPlane->Pln().Position();
1150       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1151
1152       GEOM_VTKTrihedron* aTrh = 0;
1153
1154       if ( vtkPrs->IsNull() ) {
1155         // new presentation is being created
1156         aTrh = GEOM_VTKTrihedron::New();
1157         vtkPrs->AddObject( aTrh );
1158       }
1159       else {
1160         // presentation is being updated
1161         vtkActorCollection* actors = vtkPrs->GetObjects();
1162         if ( actors ) {
1163           actors->InitTraversal();
1164           vtkActor* a = actors->GetNextActor();
1165           while ( a && !aTrh ) {
1166             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1167             a = actors->GetNextActor();
1168           }
1169         }
1170       }
1171       
1172       if ( aTrh ) {
1173         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1174         if ( HasColor() ) {
1175           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1176           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1177         }
1178 #ifdef VTK_TRIHEDRON_WIDTH
1179         // 
1180         // VSR: currently isn't supported
1181         //
1182         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1183         if ( HasWidth() )
1184           aTrh->SetWidth( GetWidth() );
1185 #endif
1186
1187         if ( !myIO.IsNull() )
1188           aTrh->setIO( myIO );
1189
1190         aTrh->SetPlacement( aPlc );
1191       }
1192     }
1193   }
1194   else
1195   {
1196     // 
1197     // processing for usual geometry presentation
1198     // 
1199
1200     // if presentation is empty we try to create new one
1201     if ( vtkPrs->IsNull() )
1202     {
1203       // create an actor
1204       GEOM_Actor* actor = GEOM_Actor::New();
1205       // update actor properties
1206       updateActorProperties( actor, true );
1207       // add actor to the presentation
1208       vtkPrs->AddObject( actor );
1209     }
1210     else {
1211       // presentation is being updated
1212       vtkActorCollection* actors = vtkPrs->GetObjects();
1213       if ( actors ) {
1214         actors->InitTraversal();
1215         vtkActor* a = actors->GetNextActor();
1216         while ( a ) {
1217           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1218           if ( actor ) {
1219             // update actor properties
1220             updateActorProperties( actor, false );
1221             a = actors->GetNextActor();
1222           }
1223         }
1224       }
1225     }
1226   }
1227 }
1228
1229 //=================================================================
1230 /*!
1231  *  GEOM_Displayer::BuildPrs
1232  *  Build presentation accordint to the current viewer type
1233  */
1234 //=================================================================
1235 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1236 {
1237   if ( theObj->_is_nil() )
1238     return 0;
1239
1240   myViewFrame = GetActiveView();
1241   if ( myViewFrame == 0 )
1242     return 0;
1243
1244   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1245   if ( aPrs == 0 )
1246     return 0;
1247
1248   internalReset();
1249   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1250   myType = theObj->GetType();
1251
1252   // Update presentation
1253   UpdatePrs( aPrs );
1254
1255   return aPrs;
1256 }
1257
1258 //=================================================================
1259 /*!
1260  *  GEOM_Displayer::BuildPrs
1261  *  Build presentation accordint to the current viewer type
1262  */
1263 //=================================================================
1264 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1265 {
1266   myViewFrame = GetActiveView();
1267   if ( theShape.IsNull() || myViewFrame == 0 )
1268     return 0;
1269
1270   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1271   if ( aPrs == 0 )
1272     return 0;
1273
1274   internalReset();
1275   setShape( theShape );
1276   myType = -1;
1277
1278   UpdatePrs( aPrs );
1279
1280   return aPrs;
1281 }
1282
1283 //=================================================================
1284 /*!
1285  *  GEOM_Displayer::buildPresentation
1286  *  Builds/finds object's presentation for the current viewer
1287  *  Calls corresponding Update() method by means of double dispatch
1288  *  [ internal ]
1289  */
1290 //=================================================================
1291 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1292                                                SALOME_View* theViewFrame )
1293 {
1294   SALOME_Prs* prs = 0;
1295   internalReset();
1296
1297   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1298
1299   if ( myViewFrame )
1300   {
1301     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1302     if ( prs )
1303     {
1304       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1305       theIO->setEntry( entry.toLatin1().constData() );
1306       if ( !theIO.IsNull() )
1307       {
1308         // set interactive object
1309         setIO( theIO );
1310         //  Find SOBject (because shape should be published previously)
1311         SUIT_Session* session = SUIT_Session::session();
1312         SUIT_Application* app = session->activeApplication();
1313         if ( app )
1314         {
1315           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1316           if ( study )
1317           {
1318             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1319             if ( SO )
1320             {
1321               // get CORBA reference to data object
1322               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1323               if ( !CORBA::is_nil( object ) )
1324               {
1325                 // downcast to GEOM base object
1326                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1327                 if ( !GeomBaseObject->_is_nil() )
1328                 {
1329                   myType = GeomBaseObject->GetType();
1330
1331                   // downcast to GEOM object
1332                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1333                   if ( myType == GEOM_FIELD_STEP )
1334                   {
1335                     // get the GEOM object from the field's shape
1336                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1337                     if ( !GeomFieldStep->_is_nil() )
1338                     {
1339                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1340                       if ( !GeomField->_is_nil() )
1341                         GeomObject = GeomField->GetShape();
1342                     }
1343
1344                     // read the field step information
1345                     readFieldStepInfo( GeomFieldStep );
1346                   }
1347
1348                   if ( !GeomObject->_is_nil() )
1349                   {
1350                     // finally set shape
1351                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1352                   }
1353                 }
1354               }
1355             }
1356           }
1357         }
1358       }
1359       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1360     }
1361   }
1362   return prs;
1363 }
1364
1365 //=================================================================
1366 /*!
1367  *  GEOM_Displayer::buildSubshapePresentation
1368  *  Builds/finds object's presentation for the current viewer
1369  *  Calls corresponding Update() method by means of double dispatch
1370  *  For not published objects (for Mantis issue 0020435)
1371  */
1372 //=================================================================
1373 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1374                                                       const QString& entry,
1375                                                       SALOME_View* theViewFrame)
1376 {
1377   SALOME_Prs* prs = 0;
1378   internalReset();
1379
1380   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1381
1382   if (myViewFrame)
1383   {
1384     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1385     if (prs)
1386     {
1387       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1388       theIO->setEntry(entry.toLatin1().constData());
1389       if (!theIO.IsNull())
1390       {
1391         // set interactive object
1392         setIO(theIO);
1393         // finally set shape
1394         setShape(aShape);
1395         myType = GEOM_SUBSHAPE;
1396       }
1397       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1398     }
1399   }
1400   return prs;
1401 }
1402
1403 //=================================================================
1404 /*!
1405  *  GEOM_Displayer::internalReset
1406  *  Resets internal data
1407  *  [internal]
1408  */
1409 //=================================================================
1410 void GEOM_Displayer::internalReset()
1411 {
1412   myIO.Nullify();
1413   myShape.Nullify();
1414
1415   myFieldDataType = GEOM::FDT_Double;
1416   myFieldDimension = 0;
1417   myFieldStepData.clear();
1418   myFieldStepName.Clear();
1419   myFieldStepRangeMin = 0;
1420   myFieldStepRangeMax = 0;
1421 }
1422
1423 //=================================================================
1424 /*!
1425  *  GEOM_Displayer::LocalSelection
1426  *  Activate selection of CAD shapes with activisation of selection
1427  *  of their sub-shapes (with opened local context for OCC viewer)
1428  */
1429 //=================================================================
1430 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1431 {
1432   SUIT_Session* session = SUIT_Session::session();
1433   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1434   if ( !app )
1435     return;
1436
1437   LightApp_SelectionMgr* sm = app->selectionMgr();
1438
1439   // remove all filters from selection
1440   sm->clearFilters();
1441
1442   SALOME_View* vf = GetActiveView();
1443   if ( vf ) {
1444     if (!theIO.IsNull() && !vf->isVisible(theIO))
1445       Display(theIO);
1446     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1447     vf->LocalSelection( prs, theMode );
1448     delete prs;  // delete presentation because displayer is its owner
1449   }
1450 }
1451
1452 //=================================================================
1453 /*!
1454  *  GEOM_Displayer::globalSelection
1455  *  Activate selection of CAD shapes without activisation of selection
1456  *  of their sub-shapes (without opened local context for OCC viewer)
1457  */
1458 //=================================================================
1459 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1460 {
1461   TColStd_MapOfInteger aModes;
1462   aModes.Add( theMode );
1463   GlobalSelection( aModes, update );
1464 }
1465
1466 //=================================================================
1467 /*!
1468  *  GEOM_Displayer::globalSelection
1469  *  Activate selection of CAD shapes without activisation of selection
1470  *  of their sub-shapes (without opened local context for OCC viewer)
1471  */
1472 //=================================================================
1473 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1474                                       const bool update, const QList<int>* theSubShapes )
1475 {
1476   SUIT_Session* session = SUIT_Session::session();
1477   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1478   if ( !app )
1479     return;
1480
1481   SALOME_View* vf = GetActiveView();
1482   if ( vf == 0 )
1483     return;
1484
1485   // Close local context
1486   vf->GlobalSelection( update );
1487
1488   // Set selection filters in accordance with current mode
1489   LightApp_SelectionMgr* sm = app->selectionMgr();
1490   if ( !sm )
1491     return;
1492
1493   // Remove from selection temporary objects if necessary
1494   if ( !theModes.Contains( GEOM_PREVIEW ) )
1495     clearTemporary( sm );
1496
1497   //@ aSel->ClearIndex();
1498
1499   sm->clearFilters();
1500
1501   // Remove filters from AIS_InteractiveContext
1502   Handle(AIS_InteractiveContext) ic;
1503   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1504   if ( viewer )
1505     {
1506       ic = viewer->getAISContext();
1507       if ( !ic.IsNull() )
1508         ic->RemoveFilters();
1509     }
1510
1511   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1512     return;
1513
1514   SUIT_SelectionFilter* aFilter;
1515   if ( theModes.Extent() == 1 )
1516     {
1517       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1518
1519       if ( aMode == GEOM_COMPOUNDFILTER )
1520         aFilter = getComplexFilter( theSubShapes );
1521       else
1522         aFilter = getFilter( aMode );
1523     }
1524   else if ( theModes.Extent() > 1 )
1525     {
1526       TColStd_MapOfInteger aTopAbsModes;
1527       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1528       QList<SUIT_SelectionFilter*> aListOfFilters;
1529       for ( ; anIter.More(); anIter.Next() )
1530         {
1531           SUIT_SelectionFilter* aFilter;
1532           int aMode = anIter.Key();
1533           if ( aMode == GEOM_COMPOUNDFILTER )
1534             aFilter = getComplexFilter( theSubShapes );
1535           else
1536             aFilter = getFilter( aMode );
1537
1538           if ( aFilter )
1539             aListOfFilters.append( aFilter );
1540         }
1541
1542       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1543     }
1544   else
1545     return;
1546
1547   if ( aFilter )
1548     {
1549       sm->installFilter( aFilter );
1550       if ( !ic.IsNull() )
1551         {
1552           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1553           ic->AddFilter( anOCCFilter );
1554         }
1555     }
1556 }
1557
1558 //=================================================================
1559 /*!
1560  *  GEOM_Displayer::LocalSelection
1561  *  Activate selection of CAD shapes with activisation of selection
1562  *  of their sub-shapes (with opened local context for OCC viewer)
1563  */
1564 //=================================================================
1565 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1566 {
1567   SALOME_ListIteratorOfListIO Iter( theIOList );
1568   for ( ; Iter.More(); Iter.Next() )
1569     LocalSelection( Iter.Value(), theMode );
1570 }
1571
1572 //=================================================================
1573 /*!
1574  *  GEOM_Displayer::BeforeDisplay
1575  *  Called before displaying of pars. Close local context
1576  *  [ Reimplemented from SALOME_Displayer ]
1577  */
1578 //=================================================================
1579 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1580 {
1581   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1582   if ( vf )
1583   {
1584     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1585     if ( !ic.IsNull() )
1586     {
1587       if ( ic->HasOpenedContext() )
1588       ic->CloseAllContexts();
1589     }
1590   }
1591 }
1592
1593 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1594 {
1595   UpdateColorScale(false,false);
1596 }
1597
1598 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1599 {
1600   LightApp_Displayer::AfterErase( v, p );
1601   UpdateColorScale(false,false);
1602 }
1603
1604 //=================================================================
1605 /*!
1606  *  GEOM_Displayer::SetColor
1607  *  Set color for shape displaying. If it is equal -1 then default color is used.
1608  *  Available values are from Quantity_NameOfColor enumeration
1609  */
1610 //=================================================================
1611 void GEOM_Displayer::SetColor( const int color )
1612 {
1613   if ( color == -1 )
1614     UnsetColor();
1615   else
1616   {
1617     myColor = color;
1618     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1619   }
1620 }
1621
1622 int GEOM_Displayer::GetColor() const
1623 {
1624   return myColor;
1625 }
1626
1627 bool GEOM_Displayer::HasColor() const
1628 {
1629   return myColor != -1;
1630 }
1631
1632 void GEOM_Displayer::UnsetColor()
1633 {
1634   myColor = -1;
1635
1636   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1637   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1638   myShadingColor = SalomeApp_Tools::color( col );
1639 }
1640
1641 //=================================================================
1642 /*!
1643  *  GEOM_Displayer::SetTexture
1644  *  Set color for shape displaying. If it is equal -1 then default color is used.
1645  *  Available values are from Quantity_NameOfColor enumeration
1646  */
1647 //=================================================================
1648 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1649 {
1650   if(texureFileName!="")
1651   {
1652     myTexture = texureFileName;
1653   }
1654 }
1655
1656 bool GEOM_Displayer::HasTexture() const
1657 {
1658   return myTexture != "";
1659 }
1660
1661 std::string GEOM_Displayer::GetTexture() const
1662 {
1663   return myTexture;
1664 }
1665
1666 //=================================================================
1667 /*!
1668  *  GEOM_Displayer::SetWidth
1669  *  Set width of shape displaying. If it is equal -1 then default width is used.
1670  */
1671 //=================================================================
1672 void GEOM_Displayer::SetWidth( const double width )
1673 {
1674   myWidth = width;
1675 }
1676
1677 double GEOM_Displayer::GetWidth() const
1678 {
1679   return myWidth;
1680 }
1681
1682 bool GEOM_Displayer::HasWidth() const
1683 {
1684   return myWidth != -1;
1685 }
1686
1687 void GEOM_Displayer::UnsetWidth()
1688 {
1689   myWidth = -1;
1690 }
1691
1692
1693 int GEOM_Displayer::GetIsosWidth() const
1694 {
1695   return myIsosWidth;
1696 }
1697
1698 void GEOM_Displayer::SetIsosWidth(const int width)
1699 {
1700   myIsosWidth = width;
1701 }
1702
1703 bool GEOM_Displayer::HasIsosWidth() const
1704 {
1705   return myIsosWidth != -1;
1706 }
1707
1708
1709 //=================================================================
1710 /*!
1711  *  GEOM_Displayer::SetToActivate
1712  *  This method is used for activisation/deactivisation of objects to be displayed
1713  */
1714 //=================================================================
1715 void GEOM_Displayer::SetToActivate( const bool toActivate )
1716 {
1717   myToActivate = toActivate;
1718 }
1719 bool GEOM_Displayer::ToActivate() const
1720 {
1721   return myToActivate;
1722 }
1723
1724 //=================================================================
1725 /*!
1726  *  GEOM_Displayer::clearTemporary
1727  *  Removes from selection temporary objects
1728  */
1729 //=================================================================
1730 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1731 {
1732   SALOME_ListIO selected, toSelect;
1733   theSelMgr->selectedObjects( selected );
1734
1735   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1736     Handle(SALOME_InteractiveObject) io = it.Value();
1737     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1738       toSelect.Append( it.Value() );
1739   }
1740
1741   theSelMgr->setSelectedObjects( toSelect, true );
1742 }
1743
1744 void GEOM_Displayer::SetName( const char* theName )
1745 {
1746   myName = theName;
1747 }
1748
1749 void GEOM_Displayer::UnsetName()
1750 {
1751   myName = "";
1752 }
1753
1754 SalomeApp_Study* GEOM_Displayer::getStudy() const
1755 {
1756   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1757 }
1758
1759 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1760 {
1761   myIO = theIO;
1762 }
1763
1764 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1765 {
1766   myShape = theShape;
1767 }
1768
1769 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1770                                        const int theFieldDimension,
1771                                        const QList<QVariant>& theFieldStepData,
1772                                        const TCollection_AsciiString& theFieldStepName,
1773                                        const double theFieldStepRangeMin,
1774                                        const double theFieldStepRangeMax )
1775 {
1776   myFieldDataType = theFieldDataType;
1777   myFieldDimension = theFieldDimension;
1778   myFieldStepData = theFieldStepData;
1779   myFieldStepName = theFieldStepName;
1780   myFieldStepRangeMin = theFieldStepRangeMin;
1781   myFieldStepRangeMax = theFieldStepRangeMax;
1782 }
1783
1784 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1785 {
1786   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1787   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1788   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
1789   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1790   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
1791          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1792 }
1793
1794 int GEOM_Displayer::SetDisplayMode( const int theMode )
1795 {
1796   int aPrevMode = myDisplayMode;
1797   if ( theMode != -1 ) {
1798     myDisplayMode = theMode;
1799     myHasDisplayMode = true;
1800   }
1801   else {
1802     UnsetDisplayMode();
1803   }
1804   return aPrevMode;
1805 }
1806
1807 int GEOM_Displayer::GetDisplayMode() const
1808 {
1809   return myDisplayMode;
1810 }
1811
1812 int GEOM_Displayer::UnsetDisplayMode()
1813 {
1814   int aPrevMode = myDisplayMode;
1815   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1816   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1817   myHasDisplayMode = false;
1818   return aPrevMode;
1819 }
1820
1821 bool GEOM_Displayer::HasDisplayMode() const
1822 {
1823   return myHasDisplayMode;
1824 }
1825
1826 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1827 {
1828   static QList<QColor> colors;
1829
1830   if ( colors.isEmpty() ) {
1831
1832     for (int s = 0; s < 2 ; s++)
1833     {
1834       for (int v = 100; v >= 40; v = v - 20)
1835       {
1836         for (int h = 0; h < 359 ; h = h + 60)
1837         {
1838           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1839         }
1840       }
1841     }
1842   }
1843
1844   static int currentColor = 0;
1845
1846   SALOMEDS::Color color;
1847   color.R = (double)colors[currentColor].red()   / 255.0;
1848   color.G = (double)colors[currentColor].green() / 255.0;
1849   color.B = (double)colors[currentColor].blue()  / 255.0;
1850
1851   currentColor = (currentColor+1) % colors.count();
1852
1853   return color;
1854 }
1855
1856 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1857 {
1858   int aHue = -1;
1859   int aTolerance = 64;
1860   int anIterations = 0;
1861   int aPeriod = 5;
1862
1863   while( 1 )
1864   {
1865     anIterations++;
1866     if( anIterations % aPeriod == 0 )
1867     {
1868       aTolerance /= 2;
1869       if( aTolerance < 1 )
1870         break;
1871     }
1872     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1873
1874     aHue = (int)( 360.0 * rand() / RAND_MAX );
1875     //std::cout << "Hue = " << aHue << std::endl;
1876
1877     //std::cout << "Auto colors : ";
1878     bool ok = true;
1879     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1880     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1881     for( ; it != itEnd; ++it )
1882     {
1883       SALOMEDS::Color anAutoColor = *it;
1884       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1885
1886       int h, s, v;
1887       aQColor.getHsv( &h, &s, &v );
1888       //std::cout << h << " ";
1889       if( abs( h - aHue ) < aTolerance )
1890       {
1891         ok = false;
1892         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1893         break;
1894       }
1895     }
1896     //std::cout << std::endl;
1897
1898     if( ok )
1899       break;
1900   }
1901
1902   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1903   QColor aColor;
1904   aColor.setHsv( aHue, 255, 255 );
1905
1906   SALOMEDS::Color aSColor;
1907   aSColor.R = (double)aColor.red() / 255.0;
1908   aSColor.G = (double)aColor.green() / 255.0;
1909   aSColor.B = (double)aColor.blue() / 255.0;
1910
1911   return aSColor;
1912 }
1913
1914 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1915                                              const QString& entry,
1916                                              SALOME_View* view )
1917 {
1918   // get default properties for the explicitly specified default view type
1919   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1920
1921   if ( study && view ) {
1922     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1923     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1924     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1925   
1926     if ( viewModel && viewId != -1 ) {
1927       // get properties from the study
1928       PropMap storedMap = study->getObjectPropMap( viewId, entry );
1929       // overwrite default properties from stored ones (that are specified)
1930       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1931         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1932           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
1933                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1934       }
1935       // ... specific processing for color
1936       // ... current implementation is to use same stored color for all aspects
1937       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1938       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1939         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1940         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1941         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1942         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1943         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1944       }
1945
1946       if ( !entry.isEmpty() ) {
1947         // get CORBA reference to geom object
1948         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1949         if ( SO ) {
1950           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1951           if ( !CORBA::is_nil( object ) ) {
1952             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1953             if ( !CORBA::is_nil( geomObject ) ) { // to check
1954               // check that geom object has color properly set
1955               bool hasColor = false;
1956               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1957               // set color from geometry object (only once, if it is not yet set in GUI)
1958               // current implementation is to use same color for all aspects
1959               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1960               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1961                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1962                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
1963                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1964                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
1965                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
1966                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
1967               }
1968               // check that object has point marker properly set
1969               GEOM::marker_type mType = geomObject->GetMarkerType();
1970               GEOM::marker_size mSize = geomObject->GetMarkerSize();
1971               int mTextureId = geomObject->GetMarkerTexture();
1972               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
1973                                ( mType == GEOM::MT_USER && mTextureId > 0 );
1974               // set point marker from geometry object (only once, if it is not yet set in GUI)
1975               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1976                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1977                   // standard type
1978                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1979                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1980                 }
1981                 else if ( mType == GEOM::MT_USER ) {
1982                   // custom texture
1983                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1984                 }
1985               }
1986             }
1987           }
1988         }
1989       }
1990     }
1991   }
1992   return propMap;
1993 }
1994
1995 PropMap GEOM_Displayer::getDefaultPropertyMap()
1996 {
1997   PropMap propMap;
1998
1999   // get resource manager
2000   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2001
2002   // fill in the properties map with default values
2003
2004   // - visibility (false by default)
2005   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2006
2007   // - nb isos (take default value from preferences)
2008   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2009                   QString( "%1%2%3" ).
2010                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2011                   arg( GEOM::subSectionSeparator() ).
2012                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2013
2014   // - transparency (opacity = 1-transparency)
2015   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2016
2017   // - display mode (take default value from preferences)
2018   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2019                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2020
2021   // - show edges direction flag (false by default)
2022   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2023
2024   // - shading color (take default value from preferences)
2025   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2026                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2027
2028   // - wireframe color (take default value from preferences)
2029   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2030                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2031
2032   // - standalone edges color (take default value from preferences)
2033   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2034                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2035
2036   // - free boundaries color (take default value from preferences)
2037   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2038                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2039
2040   // - points color (take default value from preferences)
2041   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2042                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2043
2044   // - isos color (take default value from preferences)
2045   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2046                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2047
2048   // - outlines color (take default value from preferences)
2049   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2050                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2051
2052   // - deflection coefficient (take default value from preferences)
2053   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2054                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2055
2056   // - material (take default value from preferences)
2057   Material_Model material;
2058   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2059   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2060
2061   // - edge width (take default value from preferences)
2062   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2063                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2064
2065   // - isos width (take default value from preferences)
2066   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2067                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2068
2069   // - point marker (take default value from preferences)
2070   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2071                   QString( "%1%2%3" ).
2072                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2073                   arg( GEOM::subSectionSeparator() ).
2074                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2075
2076   // - top-level flag (false by default)
2077   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2078
2079   return propMap;
2080 }
2081
2082 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2083   SALOMEDS::Color aSColor;
2084   hasColor = false;
2085
2086   SUIT_Session* session = SUIT_Session::session();
2087   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2088
2089   if ( app && !theGeomObject->_is_nil()) {
2090     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2091
2092     if ( study ) {
2093       _PTR(Study) aStudy = study->studyDS();
2094       aSColor = theGeomObject->GetColor();
2095       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2096       if ( !hasColor ) {
2097 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2098         bool general_autocolor = true;
2099 #else                    // auto-color for groups only
2100         bool general_autocolor = false;
2101 #endif                   // GENERAL_AUTOCOLOR
2102         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2103           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2104           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2105 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2106             aSColor = getPredefinedUniqueColor();
2107             hasColor = true;
2108 #else                    // old algorithm  for auto-colors
2109             QList<SALOMEDS::Color> aReservedColors;
2110             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2111             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2112             if ( aMainSObject ) {
2113               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2114               for ( ; it->More(); it->Next() ) {
2115                 _PTR(SObject) aChildSObject( it->Value() );
2116                 GEOM::GEOM_Object_var aChildObject =
2117                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2118                 if ( CORBA::is_nil( aChildObject ) )
2119                   continue;
2120
2121                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2122                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2123                   aReservedColors.append( aReservedColor );
2124               }
2125             }
2126             aSColor = getUniqueColor( aReservedColors );
2127             hasColor = true;
2128 #endif                   // SIMPLE_AUTOCOLOR
2129           }
2130         }
2131       }
2132     }
2133   }
2134   return aSColor;
2135 }
2136
2137
2138 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2139                                        const bool eraseOnlyChildren) {
2140   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2141   if ( !app )
2142     return;
2143
2144   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2145   if ( !appStudy )
2146     return;
2147
2148   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2149
2150   if( !parent)
2151     return;
2152
2153   // Erase from all views
2154   QList<SALOME_View*> views;
2155   SALOME_View* view;
2156   ViewManagerList vmans = app->viewManagers();
2157   SUIT_ViewManager* vman;
2158   foreach ( vman, vmans ) {
2159     SUIT_ViewModel* vmod = vman->getViewModel();
2160     view = dynamic_cast<SALOME_View*> ( vmod );
2161     if ( view )
2162       views.append( view );
2163   }
2164
2165   if( views.count() == 0 )
2166     return;
2167
2168   //Erase childrens w/o update views
2169   DataObjectList listObj = parent->children( true );
2170   SUIT_DataObject* obj;
2171   foreach( obj, listObj ) {
2172     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2173     if(l_obj)
2174       foreach ( view, views ) {
2175       Handle(SALOME_InteractiveObject) anIO =
2176         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2177       Erase(anIO, false, false, view);
2178     }
2179   }
2180
2181   //Erase parent with view update or repaint views
2182   foreach ( view, views ) {
2183     if(!eraseOnlyChildren)
2184       Erase(theIO, false, true, view);
2185     else
2186       view->Repaint();
2187   }
2188 }
2189
2190 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2191 {
2192   if( theGeomFieldStep->_is_nil() )
2193     return;
2194
2195   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2196   if( aGeomField->_is_nil() )
2197     return;
2198
2199   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2200   if( aGeomFieldShape->_is_nil() )
2201     return;
2202
2203   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2204   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2205   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2206
2207   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2208
2209   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2210
2211   int aFieldDimension = aGeomField->GetDimension();
2212
2213   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2214   int aFieldNbComponents = aFieldComponents->length();
2215
2216   QList<QVariant> aFieldStepData;
2217   if( aFieldDataType == GEOM::FDT_Bool )
2218   {
2219     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2220     if ( !aGeomBoolFieldStep->_is_nil() )
2221     {
2222       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2223       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2224         aFieldStepData << (bool)aValues[i];
2225     }
2226   }
2227   else if( aFieldDataType == GEOM::FDT_Int )
2228   {
2229     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2230     if ( !aGeomIntFieldStep->_is_nil() )
2231     {
2232       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2233       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2234         aFieldStepData << (qlonglong)aValues[i];
2235     }
2236   }
2237   else if( aFieldDataType == GEOM::FDT_Double )
2238   {
2239     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2240     if ( !aGeomDoubleFieldStep->_is_nil() )
2241     {
2242       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2243       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2244         aFieldStepData << (double)aValues[i];
2245     }
2246   }
2247   else if( aFieldDataType == GEOM::FDT_String )
2248   {
2249     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2250     if ( !aGeomStringFieldStep->_is_nil() )
2251     {
2252       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2253       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2254         aFieldStepData << QString( aValues[i] );
2255     }
2256   }
2257
2258   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2259   aFieldStepData = groupFieldData( aFieldStepData,
2260                                    aFieldNbComponents,
2261                                    aFieldDataType == GEOM::FDT_String,
2262                                    aFieldStepRangeMin,
2263                                    aFieldStepRangeMax );
2264
2265   setFieldStepInfo( aFieldDataType,
2266                     aFieldDimension,
2267                     aFieldStepData,
2268                     aFieldStepName,
2269                     aFieldStepRangeMin,
2270                     aFieldStepRangeMax );
2271 }
2272
2273 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2274                                                 const int theFieldNbComponents,
2275                                                 const bool theIsString,
2276                                                 double& theFieldStepRangeMin,
2277                                                 double& theFieldStepRangeMax )
2278 {
2279   QList<QVariant> aResultList;
2280   theFieldStepRangeMin = 0;
2281   theFieldStepRangeMax = 0;
2282
2283   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2284     return aResultList;
2285
2286   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2287
2288   QList<QVariant> aGroupedList;
2289
2290   bool anIsBoolean = false;
2291   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2292   {
2293     double aNorm = 0;
2294     QStringList aStringList;
2295
2296     int aBaseIndex = aSubShape * theFieldNbComponents;
2297     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2298     {
2299       int anIndex = aComponent + aBaseIndex;
2300
2301       const QVariant& aVariant = theFieldStepData[ anIndex ];
2302       if( theIsString )
2303       {
2304         if( aVariant.type() == QVariant::String )
2305           aStringList << aVariant.toString();
2306       }
2307       else
2308       {
2309         double aValue = 0;
2310         if( aVariant.type() == QVariant::Bool )
2311         {
2312           aValue = aVariant.toBool() ? 1.0 : 0.0;
2313           aNorm += aValue;
2314           anIsBoolean = true;
2315         }
2316         else
2317         {
2318           if( aVariant.type() == QVariant::Int )
2319             aValue = double( aVariant.toInt() );
2320           else if( aVariant.type() == QVariant::Double )
2321             aValue = aVariant.toDouble();
2322           aNorm += aValue * aValue;
2323         }
2324       }
2325     }
2326
2327     if( theIsString )
2328       aGroupedList << aStringList.join( "\n" );
2329     else
2330     {
2331       if( anIsBoolean )
2332         aNorm /= theFieldNbComponents;
2333       else
2334         aNorm = pow( aNorm, 0.5 );
2335
2336       if( aGroupedList.isEmpty() )
2337         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2338       else
2339       {
2340         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2341         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2342       }
2343
2344       aGroupedList << aNorm;
2345     }
2346   }
2347
2348   if( anIsBoolean )
2349   {
2350     theFieldStepRangeMin = 0.0;
2351     theFieldStepRangeMax = 1.0;
2352   }
2353
2354   SUIT_Session* session = SUIT_Session::session();
2355   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2356   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2357
2358   QListIterator<QVariant> anIter( aGroupedList );
2359   while( anIter.hasNext() )
2360   {
2361     const QVariant& aVariant = anIter.next();
2362     if( theIsString )
2363       aResultList << aVariant;
2364     else
2365     {
2366       QColor aQColor;
2367       Quantity_Color aColor;
2368       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2369         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2370       aResultList << aQColor;
2371     }
2372   }
2373   return aResultList;
2374 }
2375
2376 // Note: the method is copied from Aspect_ColorScale class
2377 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2378                                                const Standard_Integer aMin,
2379                                                const Standard_Integer aMax )
2380 {
2381   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2382
2383   Standard_Integer aHue = maxLimit;
2384   if ( aMin != aMax )
2385     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2386
2387   aHue = Min( Max( minLimit, aHue ), maxLimit );
2388
2389   return aHue;
2390 }
2391
2392 // Note: the method is copied from Aspect_ColorScale class
2393 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2394                                             const Standard_Real aMin,
2395                                             const Standard_Real aMax,
2396                                             const Standard_Integer ColorsCount,
2397                                             Quantity_Color& aColor )
2398 {
2399   if( aValue<aMin || aValue>aMax || aMax<aMin )
2400     return Standard_False;
2401
2402   else
2403   {
2404     Standard_Real IntervNumber = 0;
2405     if( aValue<aMin )
2406       IntervNumber = 0;
2407     else if( aValue>aMax )
2408       IntervNumber = ColorsCount-1;
2409     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2410       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2411
2412     Standard_Integer Interv = Standard_Integer( IntervNumber );
2413
2414     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2415
2416     return Standard_True;
2417   } 
2418 }
2419
2420 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2421 {
2422   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2423   if( !aStudy )
2424     return;
2425
2426   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2427   if( !aViewModel )
2428     return;
2429
2430   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2431   if( aViewer.IsNull() )
2432     return;
2433
2434   aViewer->InitActiveViews();
2435   if( !aViewer->MoreActiveViews() )
2436     return;
2437
2438   Handle(V3d_View) aView = aViewer->ActiveView();
2439   if( aView.IsNull() )
2440     return;
2441
2442   Standard_Boolean anIsDisplayColorScale = Standard_False;
2443   TCollection_AsciiString aColorScaleTitle;
2444   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2445   Standard_Boolean anIsBoolean = Standard_False;
2446
2447   SALOME_ListIO aSelectedObjects;
2448   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2449   if( aSelectedObjects.Extent() == 1 )
2450   {
2451     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2452     if( !anIO.IsNull() )
2453     {
2454       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2455       if( aPrs )
2456       {
2457         AIS_ListOfInteractive aList;
2458         aPrs->GetObjects( aList );
2459         AIS_ListIteratorOfListOfInteractive anIter( aList );
2460         for( ; anIter.More(); anIter.Next() )
2461         {
2462           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2463           if( !aShape.IsNull() )
2464           {
2465             GEOM::field_data_type aFieldDataType;
2466             int aFieldDimension;
2467             QList<QVariant> aFieldStepData;
2468             TCollection_AsciiString aFieldStepName;
2469             double aFieldStepRangeMin, aFieldStepRangeMax;
2470             aShape->getFieldStepInfo( aFieldDataType,
2471                                       aFieldDimension,
2472                                       aFieldStepData,
2473                                       aFieldStepName,
2474                                       aFieldStepRangeMin,
2475                                       aFieldStepRangeMax );
2476             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2477             {
2478               anIsDisplayColorScale = Standard_True;
2479               aColorScaleTitle = aFieldStepName;
2480               aColorScaleMin = aFieldStepRangeMin;
2481               aColorScaleMax = aFieldStepRangeMax;
2482               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2483             }
2484           }
2485         }
2486       }
2487     }
2488   }
2489
2490   if( anIsDisplayColorScale )
2491   {
2492     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2493     if( !aColorScale.IsNull() )
2494     {
2495       SUIT_Session* session = SUIT_Session::session();
2496       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2497
2498       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2499       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2500       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2501       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2502       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2503       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2504  
2505       aColorScale->SetXPosition( anXPos );
2506       aColorScale->SetYPosition( anYPos );
2507       aColorScale->SetWidth( aWidth );
2508       aColorScale->SetHeight( aHeight );
2509
2510       aColorScale->SetTextHeight( aTextHeight );
2511       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2512
2513       aColorScale->SetTitle( aColorScaleTitle );
2514       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2515     }
2516     if( !aView->ColorScaleIsDisplayed() )
2517       aView->ColorScaleDisplay();
2518   }
2519   else
2520   {
2521     if( aView->ColorScaleIsDisplayed() )
2522       aView->ColorScaleErase();
2523   }
2524
2525   if( theIsRedisplayFieldSteps )
2526   {
2527     _PTR(Study) aStudyDS = aStudy->studyDS();
2528     QList<SUIT_ViewManager*> vmList;
2529     myApp->viewManagers( vmList );
2530     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2531     {
2532       if( SUIT_ViewManager* aViewManager = *vmIt )
2533       {
2534         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2535         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2536         {
2537           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2538           if( aSObj )
2539           {
2540             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2541             if( !CORBA::is_nil( anObject ) )
2542             {
2543               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2544               if( !aFieldStep->_is_nil() )
2545               {
2546                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2547                 Handle(SALOME_InteractiveObject) aStepIO =
2548                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2549                 Redisplay( aStepIO, false, false );
2550               }
2551             }
2552           }
2553         }
2554       }
2555     }
2556   }
2557   if(updateViewer)
2558     UpdateViewer();
2559 }