Salome HOME
Fix of 0022437: EDF GEOM: Texture is lost when hiding and showing again a shape....
[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   // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function
677   //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
678
679   // set iso properties
680   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
681   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
682   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
683   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
684   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
685   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
686   uIsoAspect->SetColor( isosColor );
687   uIsoAspect->SetWidth( isosWidth );
688   uIsoAspect->SetNumber( uIsos );
689   vIsoAspect->SetColor( isosColor );
690   vIsoAspect->SetWidth( isosWidth );
691   vIsoAspect->SetNumber( vIsos );
692   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
693   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
694
695   // set deflection coefficient
696   // ... to avoid to small values of the coefficient, its lower value is limited 
697   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
698
699   // set texture
700   bool textureAdded = false;
701   if ( HasTexture() ) {
702     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
703     AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
704     if ( ! entry.isEmpty() ) {
705       // check that study is active
706       SalomeApp_Study* study = getActiveStudy();
707       if ( study ) {
708         // Store the texture in object properties for next displays
709         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
710         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
711         
712         // Update porpeties map
713         propMap = getObjectProperties( study, entry, myViewFrame );
714       }
715     }
716     textureAdded = true;
717   }
718   else {
719     // Texture from properties
720     QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
721     if ( !aTexture.isEmpty() ) {
722        AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toStdString().c_str() ) );
723        textureAdded = true;
724     }
725   }
726  
727   if ( textureAdded ){ 
728     AISShape->SetTextureMapOn();
729     AISShape->DisableTextureModulate();
730   }
731
732   // set line width
733   AISShape->SetWidth( HasWidth() ?
734                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
735                       GetWidth() :
736                       // libe width from properties
737                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
738
739   // set top-level flag
740   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
741
742   // set point marker (for vertex / compound of vertices only)
743   if ( onlyVertex ) {
744     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
745     if ( aList.size() == 2 ) {
746       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
747       int aTypeOfMarker = aList[0].toInt();
748       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
749       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
750       anAspect->SetScale( aScaleOfMarker );
751       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
752       anAspect->SetColor( HasColor() ? 
753                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
754                           (Quantity_NameOfColor)GetColor() : 
755                           // color from properties
756                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
757       AISShape->Attributes()->SetPointAspect( anAspect );
758     }
759     else if ( aList.size() == 1 ) {
760       // custom marker string contains "IdOfTexture"
761       int textureId = aList[0].toInt();
762       Standard_Integer aWidth, aHeight;
763 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
764       Handle(TColStd_HArray1OfByte) aTexture =
765 #else
766         Handle(Graphic3d_HArray1OfBytes) aTexture =
767 #endif
768         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
769       if ( !aTexture.IsNull() ) {
770 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
771         Handle(Prs3d_PointAspect) aTextureAspect =
772           new Prs3d_PointAspect( HasColor() ? 
773                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
774                                  (Quantity_NameOfColor)GetColor() : 
775                                  // color from properties 
776                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
777                                  aWidth, aHeight,
778                                  aTexture );
779 #else
780         int TextureId = 0;
781         Handle(Prs3d_PointAspect) aTextureAspect =
782           new Prs3d_PointAspect( HasColor() ? 
783                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
784                                  (Quantity_NameOfColor)GetColor() : 
785                                  // color from properties 
786                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
787                                  ++TextureId,
788                                  aWidth, aHeight,
789                                  aTexture );
790 #endif
791         AISShape->Attributes()->SetPointAspect( aTextureAspect );
792       }
793     }
794   }
795
796   // set field step data
797   AISShape->setFieldStepInfo( myFieldDataType,
798                               myFieldDimension,
799                               myFieldStepData,
800                               myFieldStepName,
801                               myFieldStepRangeMin,
802                               myFieldStepRangeMax );
803
804   if ( create && !isTemporary && aMgrId != -1 ) {
805     // set properties to the study
806     study->setObjectPropMap( aMgrId, entry, propMap );
807   }
808
809   // AISShape->SetName(???); ??? necessary to set name ???
810 }
811
812 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
813 {
814   // check that actor is not null
815   if ( !actor ) return;
816   
817   // check that study is active
818   SalomeApp_Study* study = getStudy();
819   if ( !study ) return;
820
821   // set interactive object
822
823   Handle( SALOME_InteractiveObject ) anIO;
824
825   if ( !myIO.IsNull() ) {
826     actor->setIO( myIO );
827     anIO = myIO;
828   }
829   else if ( !myName.empty() ) {
830     // workaround to allow selection of temporary objects
831     static int tempId = 0;
832     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
833     actor->setIO( anIO );
834   }
835
836   // presentation study entry (empty for temporary objects like preview)
837   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
838   // flag: temporary object
839   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
840   // currently active view window's ID (-1 if no active view)
841   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
842
843   // get presentation properties
844   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
845   QColor c;
846
847   /////////////////////////////////////////////////////////////////////////
848   // VSR: for VTK viewer currently deflection coefficient is hardcoded
849   //      due to performance problem
850   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
851   /////////////////////////////////////////////////////////////////////////
852   if ( !actor->getTopo().IsSame( myShape ) )
853     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
854
855   // set material
856   Material_Model material;
857   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
858   std::vector<vtkProperty*> mprops;
859   mprops.push_back( material.getMaterialVTKProperty( true ) );
860   mprops.push_back( material.getMaterialVTKProperty( false) );
861   actor->SetMaterial( mprops );
862
863   // set iso-lines properties
864
865   // - set number of iso-lines
866   int nbIsos[2]= { 1, 1 };
867   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
868   nbIsos[0] = isos[0].toInt();
869   nbIsos[1] = isos[1].toInt();
870   actor->SetNbIsos( nbIsos );
871
872   // - set iso-lines width
873   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
874
875   // - set iso-lines color
876   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
877   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
878
879   // set colors
880
881   if ( HasColor()  ) {
882     // - same color for all sub-actors
883     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
884     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
885   }
886   else {
887     // shading color (for non-physical materials)
888     if ( !material.isPhysical() ) {
889       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
890       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
891       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
892     }
893
894     // - standalone edge color
895     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
896     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
897
898     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
899     // - shared edges color ???
900     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
901
902     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
903     // - free edges color ???
904     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
905
906     // - point color
907     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
908     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
909   }
910
911   // - color for edges in shading+edges mode
912   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
913   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
914
915   // set opacity
916   actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
917
918   // set line width
919   actor->SetWidth( HasWidth() ?
920                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
921                    GetWidth() :
922                    // libe width from properties
923                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
924   
925   // set display vectors flag
926   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
927
928   // set display mode
929   int displayMode = HasDisplayMode() ? 
930     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
931     GetDisplayMode() :
932     // display mode from properties
933     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
934
935   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
936   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
937   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
938   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
939
940   if ( displayMode == 2 )
941       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
942       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
943     displayMode++;
944   actor->setDisplayMode( displayMode );
945
946   if ( myToActivate )
947     actor->PickableOn();
948   else
949     actor->PickableOff();
950
951   if ( create && !isTemporary && aMgrId != -1 ) {
952     // set properties to the study
953     study->setObjectPropMap( aMgrId, entry, propMap );
954   }
955 }
956
957 //=================================================================
958 /*!
959  *  GEOM_Displayer::Erase
960  *  Calls Erase() method for each object in the given list
961  */
962 //=================================================================
963 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
964                             const bool forced,
965                             const bool updateViewer )
966 {
967   SALOME_ListIteratorOfListIO Iter( theIOList );
968   for ( ; Iter.More(); Iter.Next() )
969     Erase( Iter.Value(), forced, false );
970
971   if ( updateViewer )
972     UpdateViewer();
973 }
974
975 //=================================================================
976 /*!
977  *  GEOM_Displayer::Redisplay
978  *  Calls Redisplay() method for each object in the given list
979  */
980 //=================================================================
981 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
982                                 const bool updateViewer,
983                                 const bool checkActiveViewer )
984 {
985   SALOME_ListIteratorOfListIO Iter( theIOList );
986   for ( ; Iter.More(); Iter.Next() )
987     Redisplay( Iter.Value(), false, checkActiveViewer );
988
989   if ( updateViewer )
990     UpdateViewer();
991 }
992
993 //=================================================================
994 /*!
995  *  GEOM_Displayer::Update
996  *  Update OCC presentaion
997  *  [ Reimplemented from SALOME_Displayer ]
998  */
999 //=================================================================
1000 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1001 {
1002   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1003   SalomeApp_Study* study = getStudy();
1004
1005   if ( !occPrs || myShape.IsNull() || !study )
1006     return;
1007
1008   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1009   {
1010     // 
1011     // specific processing for local coordinate system presentation
1012     // 
1013
1014     TopoDS_Face aFace = TopoDS::Face( myShape );
1015     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1016     if ( !aPlane.IsNull() )
1017     {
1018       gp_Ax3 aPos = aPlane->Pln().Position();
1019       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1020
1021       Handle(GEOM_AISTrihedron) aTrh;
1022
1023       if ( occPrs->IsNull() )
1024       {
1025         // new presentation is being created
1026         aTrh = new GEOM_AISTrihedron( aPlc );
1027         occPrs->AddObject( aTrh );
1028       }
1029       else
1030       {
1031         // presentation is being updated
1032         AIS_ListOfInteractive aList;
1033         occPrs->GetObjects( aList );
1034         AIS_ListIteratorOfListOfInteractive anIter( aList );
1035         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1036           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1037         }
1038       }
1039         
1040       if ( !aTrh.IsNull() ) {
1041         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1042         if ( HasColor() )
1043           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1044         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1045         if ( HasWidth() )
1046           aTrh->SetWidth( GetWidth() );
1047         
1048         if ( !myIO.IsNull() )
1049         {
1050           aTrh->setIO( myIO );
1051           aTrh->SetOwner( myIO );
1052         }
1053         aTrh->SetComponent( aPlc );
1054         aTrh->SetToUpdate();
1055       }
1056       occPrs->SetToActivate( ToActivate() );
1057     }
1058   }
1059   else
1060   {
1061     // 
1062     // processing for usual geometry presentation
1063     // 
1064
1065     // if presentation is empty we try to create new one
1066     if ( occPrs->IsNull() )
1067     {
1068       // create presentation (specific for vectors)
1069       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1070                                                                  : new GEOM_AISShape ( myShape, "" );
1071
1072       if( myType == GEOM_FIELD_STEP )
1073         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1074       // update shape properties
1075       updateShapeProperties( AISShape, true );
1076
1077       // add shape to the presentation
1078       occPrs->AddObject( AISShape );
1079
1080       // In accordance with ToActivate() value object will be activated/deactivated
1081       // when it will be displayed
1082       occPrs->SetToActivate( ToActivate() );
1083
1084       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1085         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1086
1087         // create additional wireframe shape
1088         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1089         aWirePrs->SetWidth(AISShape->Width());
1090         if ( !myIO.IsNull() ) {
1091           aWirePrs->setIO( myIO );
1092           aWirePrs->SetOwner( myIO );
1093         }
1094
1095         // add shape to the presentation
1096         occPrs->AddObject( aWirePrs );
1097       }
1098     }
1099     // if presentation is found -> set again shape for it
1100     else
1101     {
1102       AIS_ListOfInteractive IOList;
1103       occPrs->GetObjects( IOList );
1104       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1105       for ( ; Iter.More(); Iter.Next() )
1106       {
1107         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1108         if ( AISShape.IsNull() )
1109           continue;
1110
1111         // re-set shape (it might be changed)
1112         if ( AISShape->Shape() != myShape )
1113           AISShape->Set( myShape );
1114
1115         // update shape properties
1116         updateShapeProperties( AISShape, false );
1117
1118         // force updating
1119         AISShape->UpdateSelection();
1120         AISShape->SetToUpdate();
1121       }
1122     }
1123   }
1124 }
1125
1126 //=================================================================
1127 /*!
1128  *  GEOM_Displayer::Update
1129  *  Update VTK presentaion
1130  *  [ Reimplemented from SALOME_Displayer ]
1131  */
1132 //=================================================================
1133 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1134 {
1135   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1136   SalomeApp_Study* study = getStudy();
1137
1138   if ( !vtkPrs || myShape.IsNull() || !study )
1139     return;
1140
1141   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1142   {
1143     // 
1144     // specific processing for local coordinate system presentation
1145     // 
1146
1147     TopoDS_Face aFace = TopoDS::Face( myShape );
1148     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1149     if ( !aPlane.IsNull() ) {
1150       gp_Ax3 aPos = aPlane->Pln().Position();
1151       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1152
1153       GEOM_VTKTrihedron* aTrh = 0;
1154
1155       if ( vtkPrs->IsNull() ) {
1156         // new presentation is being created
1157         aTrh = GEOM_VTKTrihedron::New();
1158         vtkPrs->AddObject( aTrh );
1159       }
1160       else {
1161         // presentation is being updated
1162         vtkActorCollection* actors = vtkPrs->GetObjects();
1163         if ( actors ) {
1164           actors->InitTraversal();
1165           vtkActor* a = actors->GetNextActor();
1166           while ( a && !aTrh ) {
1167             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1168             a = actors->GetNextActor();
1169           }
1170         }
1171       }
1172       
1173       if ( aTrh ) {
1174         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1175         if ( HasColor() ) {
1176           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1177           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1178         }
1179 #ifdef VTK_TRIHEDRON_WIDTH
1180         // 
1181         // VSR: currently isn't supported
1182         //
1183         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1184         if ( HasWidth() )
1185           aTrh->SetWidth( GetWidth() );
1186 #endif
1187
1188         if ( !myIO.IsNull() )
1189           aTrh->setIO( myIO );
1190
1191         aTrh->SetPlacement( aPlc );
1192       }
1193     }
1194   }
1195   else
1196   {
1197     // 
1198     // processing for usual geometry presentation
1199     // 
1200
1201     // if presentation is empty we try to create new one
1202     if ( vtkPrs->IsNull() )
1203     {
1204       // create an actor
1205       GEOM_Actor* actor = GEOM_Actor::New();
1206       // update actor properties
1207       updateActorProperties( actor, true );
1208       // add actor to the presentation
1209       vtkPrs->AddObject( actor );
1210     }
1211     else {
1212       // presentation is being updated
1213       vtkActorCollection* actors = vtkPrs->GetObjects();
1214       if ( actors ) {
1215         actors->InitTraversal();
1216         vtkActor* a = actors->GetNextActor();
1217         while ( a ) {
1218           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1219           if ( actor ) {
1220             // update actor properties
1221             updateActorProperties( actor, false );
1222             a = actors->GetNextActor();
1223           }
1224         }
1225       }
1226     }
1227   }
1228 }
1229
1230 //=================================================================
1231 /*!
1232  *  GEOM_Displayer::BuildPrs
1233  *  Build presentation accordint to the current viewer type
1234  */
1235 //=================================================================
1236 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1237 {
1238   if ( theObj->_is_nil() )
1239     return 0;
1240
1241   myViewFrame = GetActiveView();
1242   if ( myViewFrame == 0 )
1243     return 0;
1244
1245   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1246   if ( aPrs == 0 )
1247     return 0;
1248
1249   internalReset();
1250   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1251   myType = theObj->GetType();
1252
1253   // Update presentation
1254   UpdatePrs( aPrs );
1255
1256   return aPrs;
1257 }
1258
1259 //=================================================================
1260 /*!
1261  *  GEOM_Displayer::BuildPrs
1262  *  Build presentation accordint to the current viewer type
1263  */
1264 //=================================================================
1265 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1266 {
1267   myViewFrame = GetActiveView();
1268   if ( theShape.IsNull() || myViewFrame == 0 )
1269     return 0;
1270
1271   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1272   if ( aPrs == 0 )
1273     return 0;
1274
1275   internalReset();
1276   setShape( theShape );
1277   myType = -1;
1278
1279   UpdatePrs( aPrs );
1280
1281   return aPrs;
1282 }
1283
1284 //=================================================================
1285 /*!
1286  *  GEOM_Displayer::buildPresentation
1287  *  Builds/finds object's presentation for the current viewer
1288  *  Calls corresponding Update() method by means of double dispatch
1289  *  [ internal ]
1290  */
1291 //=================================================================
1292 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1293                                                SALOME_View* theViewFrame )
1294 {
1295   SALOME_Prs* prs = 0;
1296   internalReset();
1297
1298   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1299
1300   if ( myViewFrame )
1301   {
1302     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1303     if ( prs )
1304     {
1305       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1306       theIO->setEntry( entry.toLatin1().constData() );
1307       if ( !theIO.IsNull() )
1308       {
1309         // set interactive object
1310         setIO( theIO );
1311         //  Find SOBject (because shape should be published previously)
1312         SUIT_Session* session = SUIT_Session::session();
1313         SUIT_Application* app = session->activeApplication();
1314         if ( app )
1315         {
1316           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1317           if ( study )
1318           {
1319             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1320             if ( SO )
1321             {
1322               // get CORBA reference to data object
1323               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1324               if ( !CORBA::is_nil( object ) )
1325               {
1326                 // downcast to GEOM base object
1327                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1328                 if ( !GeomBaseObject->_is_nil() )
1329                 {
1330                   myType = GeomBaseObject->GetType();
1331
1332                   // downcast to GEOM object
1333                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1334                   if ( myType == GEOM_FIELD_STEP )
1335                   {
1336                     // get the GEOM object from the field's shape
1337                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1338                     if ( !GeomFieldStep->_is_nil() )
1339                     {
1340                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1341                       if ( !GeomField->_is_nil() )
1342                         GeomObject = GeomField->GetShape();
1343                     }
1344
1345                     // read the field step information
1346                     readFieldStepInfo( GeomFieldStep );
1347                   }
1348
1349                   if ( !GeomObject->_is_nil() )
1350                   {
1351                     // finally set shape
1352                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1353                   }
1354                 }
1355               }
1356             }
1357           }
1358         }
1359       }
1360       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1361     }
1362   }
1363   return prs;
1364 }
1365
1366 //=================================================================
1367 /*!
1368  *  GEOM_Displayer::buildSubshapePresentation
1369  *  Builds/finds object's presentation for the current viewer
1370  *  Calls corresponding Update() method by means of double dispatch
1371  *  For not published objects (for Mantis issue 0020435)
1372  */
1373 //=================================================================
1374 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1375                                                       const QString& entry,
1376                                                       SALOME_View* theViewFrame)
1377 {
1378   SALOME_Prs* prs = 0;
1379   internalReset();
1380
1381   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1382
1383   if (myViewFrame)
1384   {
1385     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1386     if (prs)
1387     {
1388       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1389       theIO->setEntry(entry.toLatin1().constData());
1390       if (!theIO.IsNull())
1391       {
1392         // set interactive object
1393         setIO(theIO);
1394         // finally set shape
1395         setShape(aShape);
1396         myType = GEOM_SUBSHAPE;
1397       }
1398       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1399     }
1400   }
1401   return prs;
1402 }
1403
1404 //=================================================================
1405 /*!
1406  *  GEOM_Displayer::internalReset
1407  *  Resets internal data
1408  *  [internal]
1409  */
1410 //=================================================================
1411 void GEOM_Displayer::internalReset()
1412 {
1413   myIO.Nullify();
1414   myShape.Nullify();
1415
1416   myFieldDataType = GEOM::FDT_Double;
1417   myFieldDimension = 0;
1418   myFieldStepData.clear();
1419   myFieldStepName.Clear();
1420   myFieldStepRangeMin = 0;
1421   myFieldStepRangeMax = 0;
1422 }
1423
1424 //=================================================================
1425 /*!
1426  *  GEOM_Displayer::LocalSelection
1427  *  Activate selection of CAD shapes with activisation of selection
1428  *  of their sub-shapes (with opened local context for OCC viewer)
1429  */
1430 //=================================================================
1431 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1432 {
1433   SUIT_Session* session = SUIT_Session::session();
1434   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1435   if ( !app )
1436     return;
1437
1438   LightApp_SelectionMgr* sm = app->selectionMgr();
1439
1440   // remove all filters from selection
1441   sm->clearFilters();
1442
1443   SALOME_View* vf = GetActiveView();
1444   if ( vf ) {
1445     if (!theIO.IsNull() && !vf->isVisible(theIO))
1446       Display(theIO);
1447     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1448     vf->LocalSelection( prs, theMode );
1449     delete prs;  // delete presentation because displayer is its owner
1450   }
1451 }
1452
1453 //=================================================================
1454 /*!
1455  *  GEOM_Displayer::globalSelection
1456  *  Activate selection of CAD shapes without activisation of selection
1457  *  of their sub-shapes (without opened local context for OCC viewer)
1458  */
1459 //=================================================================
1460 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1461 {
1462   TColStd_MapOfInteger aModes;
1463   aModes.Add( theMode );
1464   GlobalSelection( aModes, update );
1465 }
1466
1467 //=================================================================
1468 /*!
1469  *  GEOM_Displayer::globalSelection
1470  *  Activate selection of CAD shapes without activisation of selection
1471  *  of their sub-shapes (without opened local context for OCC viewer)
1472  */
1473 //=================================================================
1474 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1475                                       const bool update, const QList<int>* theSubShapes )
1476 {
1477   SUIT_Session* session = SUIT_Session::session();
1478   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1479   if ( !app )
1480     return;
1481
1482   SALOME_View* vf = GetActiveView();
1483   if ( vf == 0 )
1484     return;
1485
1486   // Close local context
1487   vf->GlobalSelection( update );
1488
1489   // Set selection filters in accordance with current mode
1490   LightApp_SelectionMgr* sm = app->selectionMgr();
1491   if ( !sm )
1492     return;
1493
1494   // Remove from selection temporary objects if necessary
1495   if ( !theModes.Contains( GEOM_PREVIEW ) )
1496     clearTemporary( sm );
1497
1498   //@ aSel->ClearIndex();
1499
1500   sm->clearFilters();
1501
1502   // Remove filters from AIS_InteractiveContext
1503   Handle(AIS_InteractiveContext) ic;
1504   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1505   if ( viewer )
1506     {
1507       ic = viewer->getAISContext();
1508       if ( !ic.IsNull() )
1509         ic->RemoveFilters();
1510     }
1511
1512   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1513     return;
1514
1515   SUIT_SelectionFilter* aFilter;
1516   if ( theModes.Extent() == 1 )
1517     {
1518       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1519
1520       if ( aMode == GEOM_COMPOUNDFILTER )
1521         aFilter = getComplexFilter( theSubShapes );
1522       else
1523         aFilter = getFilter( aMode );
1524     }
1525   else if ( theModes.Extent() > 1 )
1526     {
1527       TColStd_MapOfInteger aTopAbsModes;
1528       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1529       QList<SUIT_SelectionFilter*> aListOfFilters;
1530       for ( ; anIter.More(); anIter.Next() )
1531         {
1532           SUIT_SelectionFilter* aFilter;
1533           int aMode = anIter.Key();
1534           if ( aMode == GEOM_COMPOUNDFILTER )
1535             aFilter = getComplexFilter( theSubShapes );
1536           else
1537             aFilter = getFilter( aMode );
1538
1539           if ( aFilter )
1540             aListOfFilters.append( aFilter );
1541         }
1542
1543       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1544     }
1545   else
1546     return;
1547
1548   if ( aFilter )
1549     {
1550       sm->installFilter( aFilter );
1551       if ( !ic.IsNull() )
1552         {
1553           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1554           ic->AddFilter( anOCCFilter );
1555         }
1556     }
1557 }
1558
1559 //=================================================================
1560 /*!
1561  *  GEOM_Displayer::LocalSelection
1562  *  Activate selection of CAD shapes with activisation of selection
1563  *  of their sub-shapes (with opened local context for OCC viewer)
1564  */
1565 //=================================================================
1566 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1567 {
1568   SALOME_ListIteratorOfListIO Iter( theIOList );
1569   for ( ; Iter.More(); Iter.Next() )
1570     LocalSelection( Iter.Value(), theMode );
1571 }
1572
1573 //=================================================================
1574 /*!
1575  *  GEOM_Displayer::BeforeDisplay
1576  *  Called before displaying of pars. Close local context
1577  *  [ Reimplemented from SALOME_Displayer ]
1578  */
1579 //=================================================================
1580 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1581 {
1582   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1583   if ( vf )
1584   {
1585     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1586     if ( !ic.IsNull() )
1587     {
1588       if ( ic->HasOpenedContext() )
1589       ic->CloseAllContexts();
1590     }
1591   }
1592 }
1593
1594 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1595 {
1596   SalomeApp_Study* aStudy = getStudy();
1597   if (!aStudy) return;
1598   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1599   if ( vf && !p->IsNull() ) {
1600     int aMgrId = getViewManagerId( vf );
1601     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1602     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1603     if ( !ic.IsNull() && prs ) {
1604       AIS_ListOfInteractive objects;
1605       prs->GetObjects( objects );
1606       AIS_ListIteratorOfListOfInteractive it( objects );
1607       for ( ; it.More(); it.Next() ) {
1608         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1609         if ( sh.IsNull() ) continue;
1610         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1611         if ( IO.IsNull() ) continue;
1612         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1613         if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1614           double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1615           ic->SetTransparency( sh, transparency, true );
1616         }
1617       }
1618     }
1619   }
1620   UpdateColorScale(false,false);
1621 }
1622
1623 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1624 {
1625   LightApp_Displayer::AfterErase( v, p );
1626   UpdateColorScale(false,false);
1627 }
1628
1629 //=================================================================
1630 /*!
1631  *  GEOM_Displayer::SetColor
1632  *  Set color for shape displaying. If it is equal -1 then default color is used.
1633  *  Available values are from Quantity_NameOfColor enumeration
1634  */
1635 //=================================================================
1636 void GEOM_Displayer::SetColor( const int color )
1637 {
1638   if ( color == -1 )
1639     UnsetColor();
1640   else
1641   {
1642     myColor = color;
1643     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1644   }
1645 }
1646
1647 int GEOM_Displayer::GetColor() const
1648 {
1649   return myColor;
1650 }
1651
1652 bool GEOM_Displayer::HasColor() const
1653 {
1654   return myColor != -1;
1655 }
1656
1657 void GEOM_Displayer::UnsetColor()
1658 {
1659   myColor = -1;
1660
1661   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1662   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1663   myShadingColor = SalomeApp_Tools::color( col );
1664 }
1665
1666 //=================================================================
1667 /*!
1668  *  GEOM_Displayer::SetTexture
1669  *  Set color for shape displaying. If it is equal -1 then default color is used.
1670  *  Available values are from Quantity_NameOfColor enumeration
1671  */
1672 //=================================================================
1673 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1674 {
1675   if(texureFileName!="")
1676   {
1677     myTexture = texureFileName;
1678   }
1679 }
1680
1681 bool GEOM_Displayer::HasTexture() const
1682 {
1683   return myTexture != "";
1684 }
1685
1686 std::string GEOM_Displayer::GetTexture() const
1687 {
1688   return myTexture;
1689 }
1690
1691 //=================================================================
1692 /*!
1693  *  GEOM_Displayer::SetWidth
1694  *  Set width of shape displaying. If it is equal -1 then default width is used.
1695  */
1696 //=================================================================
1697 void GEOM_Displayer::SetWidth( const double width )
1698 {
1699   myWidth = width;
1700 }
1701
1702 double GEOM_Displayer::GetWidth() const
1703 {
1704   return myWidth;
1705 }
1706
1707 bool GEOM_Displayer::HasWidth() const
1708 {
1709   return myWidth != -1;
1710 }
1711
1712 void GEOM_Displayer::UnsetWidth()
1713 {
1714   myWidth = -1;
1715 }
1716
1717
1718 int GEOM_Displayer::GetIsosWidth() const
1719 {
1720   return myIsosWidth;
1721 }
1722
1723 void GEOM_Displayer::SetIsosWidth(const int width)
1724 {
1725   myIsosWidth = width;
1726 }
1727
1728 bool GEOM_Displayer::HasIsosWidth() const
1729 {
1730   return myIsosWidth != -1;
1731 }
1732
1733
1734 //=================================================================
1735 /*!
1736  *  GEOM_Displayer::SetToActivate
1737  *  This method is used for activisation/deactivisation of objects to be displayed
1738  */
1739 //=================================================================
1740 void GEOM_Displayer::SetToActivate( const bool toActivate )
1741 {
1742   myToActivate = toActivate;
1743 }
1744 bool GEOM_Displayer::ToActivate() const
1745 {
1746   return myToActivate;
1747 }
1748
1749 //=================================================================
1750 /*!
1751  *  GEOM_Displayer::clearTemporary
1752  *  Removes from selection temporary objects
1753  */
1754 //=================================================================
1755 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1756 {
1757   SALOME_ListIO selected, toSelect;
1758   theSelMgr->selectedObjects( selected );
1759
1760   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1761     Handle(SALOME_InteractiveObject) io = it.Value();
1762     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1763       toSelect.Append( it.Value() );
1764   }
1765
1766   theSelMgr->setSelectedObjects( toSelect, true );
1767 }
1768
1769 void GEOM_Displayer::SetName( const char* theName )
1770 {
1771   myName = theName;
1772 }
1773
1774 void GEOM_Displayer::UnsetName()
1775 {
1776   myName = "";
1777 }
1778
1779 SalomeApp_Study* GEOM_Displayer::getStudy() const
1780 {
1781   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1782 }
1783
1784 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1785 {
1786   myIO = theIO;
1787 }
1788
1789 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1790 {
1791   myShape = theShape;
1792 }
1793
1794 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1795                                        const int theFieldDimension,
1796                                        const QList<QVariant>& theFieldStepData,
1797                                        const TCollection_AsciiString& theFieldStepName,
1798                                        const double theFieldStepRangeMin,
1799                                        const double theFieldStepRangeMax )
1800 {
1801   myFieldDataType = theFieldDataType;
1802   myFieldDimension = theFieldDimension;
1803   myFieldStepData = theFieldStepData;
1804   myFieldStepName = theFieldStepName;
1805   myFieldStepRangeMin = theFieldStepRangeMin;
1806   myFieldStepRangeMax = theFieldStepRangeMax;
1807 }
1808
1809 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1810 {
1811   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1812   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1813   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
1814   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1815   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
1816          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1817 }
1818
1819 int GEOM_Displayer::SetDisplayMode( const int theMode )
1820 {
1821   int aPrevMode = myDisplayMode;
1822   if ( theMode != -1 ) {
1823     myDisplayMode = theMode;
1824     myHasDisplayMode = true;
1825   }
1826   else {
1827     UnsetDisplayMode();
1828   }
1829   return aPrevMode;
1830 }
1831
1832 int GEOM_Displayer::GetDisplayMode() const
1833 {
1834   return myDisplayMode;
1835 }
1836
1837 int GEOM_Displayer::UnsetDisplayMode()
1838 {
1839   int aPrevMode = myDisplayMode;
1840   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1841   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1842   myHasDisplayMode = false;
1843   return aPrevMode;
1844 }
1845
1846 bool GEOM_Displayer::HasDisplayMode() const
1847 {
1848   return myHasDisplayMode;
1849 }
1850
1851 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1852 {
1853   static QList<QColor> colors;
1854
1855   if ( colors.isEmpty() ) {
1856
1857     for (int s = 0; s < 2 ; s++)
1858     {
1859       for (int v = 100; v >= 40; v = v - 20)
1860       {
1861         for (int h = 0; h < 359 ; h = h + 60)
1862         {
1863           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1864         }
1865       }
1866     }
1867   }
1868
1869   static int currentColor = 0;
1870
1871   SALOMEDS::Color color;
1872   color.R = (double)colors[currentColor].red()   / 255.0;
1873   color.G = (double)colors[currentColor].green() / 255.0;
1874   color.B = (double)colors[currentColor].blue()  / 255.0;
1875
1876   currentColor = (currentColor+1) % colors.count();
1877
1878   return color;
1879 }
1880
1881 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1882 {
1883   int aHue = -1;
1884   int aTolerance = 64;
1885   int anIterations = 0;
1886   int aPeriod = 5;
1887
1888   while( 1 )
1889   {
1890     anIterations++;
1891     if( anIterations % aPeriod == 0 )
1892     {
1893       aTolerance /= 2;
1894       if( aTolerance < 1 )
1895         break;
1896     }
1897     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1898
1899     aHue = (int)( 360.0 * rand() / RAND_MAX );
1900     //std::cout << "Hue = " << aHue << std::endl;
1901
1902     //std::cout << "Auto colors : ";
1903     bool ok = true;
1904     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1905     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1906     for( ; it != itEnd; ++it )
1907     {
1908       SALOMEDS::Color anAutoColor = *it;
1909       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1910
1911       int h, s, v;
1912       aQColor.getHsv( &h, &s, &v );
1913       //std::cout << h << " ";
1914       if( abs( h - aHue ) < aTolerance )
1915       {
1916         ok = false;
1917         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1918         break;
1919       }
1920     }
1921     //std::cout << std::endl;
1922
1923     if( ok )
1924       break;
1925   }
1926
1927   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1928   QColor aColor;
1929   aColor.setHsv( aHue, 255, 255 );
1930
1931   SALOMEDS::Color aSColor;
1932   aSColor.R = (double)aColor.red() / 255.0;
1933   aSColor.G = (double)aColor.green() / 255.0;
1934   aSColor.B = (double)aColor.blue() / 255.0;
1935
1936   return aSColor;
1937 }
1938
1939 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1940                                              const QString& entry,
1941                                              SALOME_View* view )
1942 {
1943   // get default properties for the explicitly specified default view type
1944   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1945
1946   if ( study && view ) {
1947     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1948     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1949     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1950   
1951     if ( viewModel && viewId != -1 ) {
1952       // get properties from the study
1953       PropMap storedMap = study->getObjectPropMap( viewId, entry );
1954       // overwrite default properties from stored ones (that are specified)
1955       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1956         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1957           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
1958                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1959       }
1960       // ... specific processing for color
1961       // ... current implementation is to use same stored color for all aspects
1962       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1963       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1964         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1965         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1966         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1967         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1968         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1969       }
1970
1971       if ( !entry.isEmpty() ) {
1972         // get CORBA reference to geom object
1973         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1974         if ( SO ) {
1975           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1976           if ( !CORBA::is_nil( object ) ) {
1977             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1978             if ( !CORBA::is_nil( geomObject ) ) { // to check
1979               // check that geom object has color properly set
1980               bool hasColor = false;
1981               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1982               // set color from geometry object (only once, if it is not yet set in GUI)
1983               // current implementation is to use same color for all aspects
1984               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1985               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1986                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1987                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
1988                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1989                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
1990                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
1991                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
1992               }
1993               // check that object has point marker properly set
1994               GEOM::marker_type mType = geomObject->GetMarkerType();
1995               GEOM::marker_size mSize = geomObject->GetMarkerSize();
1996               int mTextureId = geomObject->GetMarkerTexture();
1997               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
1998                                ( mType == GEOM::MT_USER && mTextureId > 0 );
1999               // set point marker from geometry object (only once, if it is not yet set in GUI)
2000               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2001                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2002                   // standard type
2003                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2004                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2005                 }
2006                 else if ( mType == GEOM::MT_USER ) {
2007                   // custom texture
2008                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2009                 }
2010               }
2011             }
2012           }
2013         }
2014       }
2015     }
2016   }
2017   return propMap;
2018 }
2019
2020 PropMap GEOM_Displayer::getDefaultPropertyMap()
2021 {
2022   PropMap propMap;
2023
2024   // get resource manager
2025   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2026
2027   // fill in the properties map with default values
2028
2029   // - visibility (false by default)
2030   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2031
2032   // - nb isos (take default value from preferences)
2033   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2034                   QString( "%1%2%3" ).
2035                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2036                   arg( GEOM::subSectionSeparator() ).
2037                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2038
2039   // - transparency (opacity = 1-transparency)
2040   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2041
2042   // - display mode (take default value from preferences)
2043   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2044                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2045
2046   // - show edges direction flag (false by default)
2047   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2048
2049   // - shading color (take default value from preferences)
2050   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2051                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2052
2053   // - wireframe color (take default value from preferences)
2054   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2055                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2056
2057   // - standalone edges color (take default value from preferences)
2058   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2059                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2060
2061   // - free boundaries color (take default value from preferences)
2062   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2063                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2064
2065   // - points color (take default value from preferences)
2066   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2067                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2068
2069   // - isos color (take default value from preferences)
2070   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2071                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2072
2073   // - outlines color (take default value from preferences)
2074   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2075                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2076
2077   // - deflection coefficient (take default value from preferences)
2078   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2079                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2080
2081   // - material (take default value from preferences)
2082   Material_Model material;
2083   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2084   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2085
2086   // - edge width (take default value from preferences)
2087   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2088                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2089
2090   // - isos width (take default value from preferences)
2091   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2092                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2093
2094   // - point marker (take default value from preferences)
2095   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2096                   QString( "%1%2%3" ).
2097                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2098                   arg( GEOM::subSectionSeparator() ).
2099                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2100
2101   // - top-level flag (false by default)
2102   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2103
2104   return propMap;
2105 }
2106
2107 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2108   SALOMEDS::Color aSColor;
2109   hasColor = false;
2110
2111   SUIT_Session* session = SUIT_Session::session();
2112   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2113
2114   if ( app && !theGeomObject->_is_nil()) {
2115     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2116
2117     if ( study ) {
2118       _PTR(Study) aStudy = study->studyDS();
2119       aSColor = theGeomObject->GetColor();
2120       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2121       if ( !hasColor ) {
2122 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2123         bool general_autocolor = true;
2124 #else                    // auto-color for groups only
2125         bool general_autocolor = false;
2126 #endif                   // GENERAL_AUTOCOLOR
2127         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2128           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2129           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2130 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2131             aSColor = getPredefinedUniqueColor();
2132             hasColor = true;
2133 #else                    // old algorithm  for auto-colors
2134             QList<SALOMEDS::Color> aReservedColors;
2135             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2136             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2137             if ( aMainSObject ) {
2138               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2139               for ( ; it->More(); it->Next() ) {
2140                 _PTR(SObject) aChildSObject( it->Value() );
2141                 GEOM::GEOM_Object_var aChildObject =
2142                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2143                 if ( CORBA::is_nil( aChildObject ) )
2144                   continue;
2145
2146                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2147                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2148                   aReservedColors.append( aReservedColor );
2149               }
2150             }
2151             aSColor = getUniqueColor( aReservedColors );
2152             hasColor = true;
2153 #endif                   // SIMPLE_AUTOCOLOR
2154           }
2155         }
2156       }
2157     }
2158   }
2159   return aSColor;
2160 }
2161
2162
2163 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2164                                        const bool eraseOnlyChildren) {
2165   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2166   if ( !app )
2167     return;
2168
2169   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2170   if ( !appStudy )
2171     return;
2172
2173   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2174
2175   if( !parent)
2176     return;
2177
2178   // Erase from all views
2179   QList<SALOME_View*> views;
2180   SALOME_View* view;
2181   ViewManagerList vmans = app->viewManagers();
2182   SUIT_ViewManager* vman;
2183   foreach ( vman, vmans ) {
2184     SUIT_ViewModel* vmod = vman->getViewModel();
2185     view = dynamic_cast<SALOME_View*> ( vmod );
2186     if ( view )
2187       views.append( view );
2188   }
2189
2190   if( views.count() == 0 )
2191     return;
2192
2193   //Erase childrens w/o update views
2194   DataObjectList listObj = parent->children( true );
2195   SUIT_DataObject* obj;
2196   foreach( obj, listObj ) {
2197     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2198     if(l_obj)
2199       foreach ( view, views ) {
2200       Handle(SALOME_InteractiveObject) anIO =
2201         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2202       Erase(anIO, false, false, view);
2203     }
2204   }
2205
2206   //Erase parent with view update or repaint views
2207   foreach ( view, views ) {
2208     if(!eraseOnlyChildren)
2209       Erase(theIO, false, true, view);
2210     else
2211       view->Repaint();
2212   }
2213 }
2214
2215 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2216 {
2217   if( theGeomFieldStep->_is_nil() )
2218     return;
2219
2220   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2221   if( aGeomField->_is_nil() )
2222     return;
2223
2224   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2225   if( aGeomFieldShape->_is_nil() )
2226     return;
2227
2228   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2229   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2230   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2231
2232   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2233
2234   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2235
2236   int aFieldDimension = aGeomField->GetDimension();
2237
2238   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2239   int aFieldNbComponents = aFieldComponents->length();
2240
2241   QList<QVariant> aFieldStepData;
2242   if( aFieldDataType == GEOM::FDT_Bool )
2243   {
2244     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2245     if ( !aGeomBoolFieldStep->_is_nil() )
2246     {
2247       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2248       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2249         aFieldStepData << (bool)aValues[i];
2250     }
2251   }
2252   else if( aFieldDataType == GEOM::FDT_Int )
2253   {
2254     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2255     if ( !aGeomIntFieldStep->_is_nil() )
2256     {
2257       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2258       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2259         aFieldStepData << (qlonglong)aValues[i];
2260     }
2261   }
2262   else if( aFieldDataType == GEOM::FDT_Double )
2263   {
2264     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2265     if ( !aGeomDoubleFieldStep->_is_nil() )
2266     {
2267       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2268       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2269         aFieldStepData << (double)aValues[i];
2270     }
2271   }
2272   else if( aFieldDataType == GEOM::FDT_String )
2273   {
2274     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2275     if ( !aGeomStringFieldStep->_is_nil() )
2276     {
2277       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2278       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2279         aFieldStepData << QString( aValues[i] );
2280     }
2281   }
2282
2283   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2284   aFieldStepData = groupFieldData( aFieldStepData,
2285                                    aFieldNbComponents,
2286                                    aFieldDataType == GEOM::FDT_String,
2287                                    aFieldStepRangeMin,
2288                                    aFieldStepRangeMax );
2289
2290   setFieldStepInfo( aFieldDataType,
2291                     aFieldDimension,
2292                     aFieldStepData,
2293                     aFieldStepName,
2294                     aFieldStepRangeMin,
2295                     aFieldStepRangeMax );
2296 }
2297
2298 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2299                                                 const int theFieldNbComponents,
2300                                                 const bool theIsString,
2301                                                 double& theFieldStepRangeMin,
2302                                                 double& theFieldStepRangeMax )
2303 {
2304   QList<QVariant> aResultList;
2305   theFieldStepRangeMin = 0;
2306   theFieldStepRangeMax = 0;
2307
2308   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2309     return aResultList;
2310
2311   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2312
2313   QList<QVariant> aGroupedList;
2314
2315   bool anIsBoolean = false;
2316   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2317   {
2318     double aNorm = 0;
2319     QStringList aStringList;
2320
2321     int aBaseIndex = aSubShape * theFieldNbComponents;
2322     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2323     {
2324       int anIndex = aComponent + aBaseIndex;
2325
2326       const QVariant& aVariant = theFieldStepData[ anIndex ];
2327       if( theIsString )
2328       {
2329         if( aVariant.type() == QVariant::String )
2330           aStringList << aVariant.toString();
2331       }
2332       else
2333       {
2334         double aValue = 0;
2335         if( aVariant.type() == QVariant::Bool )
2336         {
2337           aValue = aVariant.toBool() ? 1.0 : 0.0;
2338           aNorm += aValue;
2339           anIsBoolean = true;
2340         }
2341         else
2342         {
2343           if( aVariant.type() == QVariant::Int )
2344             aValue = double( aVariant.toInt() );
2345           else if( aVariant.type() == QVariant::Double )
2346             aValue = aVariant.toDouble();
2347           aNorm += aValue * aValue;
2348         }
2349       }
2350     }
2351
2352     if( theIsString )
2353       aGroupedList << aStringList.join( "\n" );
2354     else
2355     {
2356       if( anIsBoolean )
2357         aNorm /= theFieldNbComponents;
2358       else
2359         aNorm = pow( aNorm, 0.5 );
2360
2361       if( aGroupedList.isEmpty() )
2362         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2363       else
2364       {
2365         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2366         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2367       }
2368
2369       aGroupedList << aNorm;
2370     }
2371   }
2372
2373   if( anIsBoolean )
2374   {
2375     theFieldStepRangeMin = 0.0;
2376     theFieldStepRangeMax = 1.0;
2377   }
2378
2379   SUIT_Session* session = SUIT_Session::session();
2380   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2381   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2382
2383   QListIterator<QVariant> anIter( aGroupedList );
2384   while( anIter.hasNext() )
2385   {
2386     const QVariant& aVariant = anIter.next();
2387     if( theIsString )
2388       aResultList << aVariant;
2389     else
2390     {
2391       QColor aQColor;
2392       Quantity_Color aColor;
2393       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2394         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2395       aResultList << aQColor;
2396     }
2397   }
2398   return aResultList;
2399 }
2400
2401 // Note: the method is copied from Aspect_ColorScale class
2402 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2403                                                const Standard_Integer aMin,
2404                                                const Standard_Integer aMax )
2405 {
2406   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2407
2408   Standard_Integer aHue = maxLimit;
2409   if ( aMin != aMax )
2410     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2411
2412   aHue = Min( Max( minLimit, aHue ), maxLimit );
2413
2414   return aHue;
2415 }
2416
2417 // Note: the method is copied from Aspect_ColorScale class
2418 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2419                                             const Standard_Real aMin,
2420                                             const Standard_Real aMax,
2421                                             const Standard_Integer ColorsCount,
2422                                             Quantity_Color& aColor )
2423 {
2424   if( aValue<aMin || aValue>aMax || aMax<aMin )
2425     return Standard_False;
2426
2427   else
2428   {
2429     Standard_Real IntervNumber = 0;
2430     if( aValue<aMin )
2431       IntervNumber = 0;
2432     else if( aValue>aMax )
2433       IntervNumber = ColorsCount-1;
2434     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2435       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2436
2437     Standard_Integer Interv = Standard_Integer( IntervNumber );
2438
2439     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2440
2441     return Standard_True;
2442   } 
2443 }
2444
2445 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2446 {
2447   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2448   if( !aStudy )
2449     return;
2450
2451   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2452   if( !aViewModel )
2453     return;
2454
2455   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2456   if( aViewer.IsNull() )
2457     return;
2458
2459   aViewer->InitActiveViews();
2460   if( !aViewer->MoreActiveViews() )
2461     return;
2462
2463   Handle(V3d_View) aView = aViewer->ActiveView();
2464   if( aView.IsNull() )
2465     return;
2466
2467   Standard_Boolean anIsDisplayColorScale = Standard_False;
2468   TCollection_AsciiString aColorScaleTitle;
2469   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2470   Standard_Boolean anIsBoolean = Standard_False;
2471
2472   SALOME_ListIO aSelectedObjects;
2473   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2474   if( aSelectedObjects.Extent() == 1 )
2475   {
2476     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2477     if( !anIO.IsNull() )
2478     {
2479       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2480       if( aPrs )
2481       {
2482         AIS_ListOfInteractive aList;
2483         aPrs->GetObjects( aList );
2484         AIS_ListIteratorOfListOfInteractive anIter( aList );
2485         for( ; anIter.More(); anIter.Next() )
2486         {
2487           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2488           if( !aShape.IsNull() )
2489           {
2490             GEOM::field_data_type aFieldDataType;
2491             int aFieldDimension;
2492             QList<QVariant> aFieldStepData;
2493             TCollection_AsciiString aFieldStepName;
2494             double aFieldStepRangeMin, aFieldStepRangeMax;
2495             aShape->getFieldStepInfo( aFieldDataType,
2496                                       aFieldDimension,
2497                                       aFieldStepData,
2498                                       aFieldStepName,
2499                                       aFieldStepRangeMin,
2500                                       aFieldStepRangeMax );
2501             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2502             {
2503               anIsDisplayColorScale = Standard_True;
2504               aColorScaleTitle = aFieldStepName;
2505               aColorScaleMin = aFieldStepRangeMin;
2506               aColorScaleMax = aFieldStepRangeMax;
2507               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2508             }
2509           }
2510         }
2511       }
2512     }
2513   }
2514
2515   if( anIsDisplayColorScale )
2516   {
2517     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2518     if( !aColorScale.IsNull() )
2519     {
2520       SUIT_Session* session = SUIT_Session::session();
2521       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2522
2523       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2524       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2525       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2526       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2527       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2528       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2529  
2530       aColorScale->SetXPosition( anXPos );
2531       aColorScale->SetYPosition( anYPos );
2532       aColorScale->SetWidth( aWidth );
2533       aColorScale->SetHeight( aHeight );
2534
2535       aColorScale->SetTextHeight( aTextHeight );
2536       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2537
2538       aColorScale->SetTitle( aColorScaleTitle );
2539       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2540     }
2541     if( !aView->ColorScaleIsDisplayed() )
2542       aView->ColorScaleDisplay();
2543   }
2544   else
2545   {
2546     if( aView->ColorScaleIsDisplayed() )
2547       aView->ColorScaleErase();
2548   }
2549
2550   if( theIsRedisplayFieldSteps )
2551   {
2552     _PTR(Study) aStudyDS = aStudy->studyDS();
2553     QList<SUIT_ViewManager*> vmList;
2554     myApp->viewManagers( vmList );
2555     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2556     {
2557       if( SUIT_ViewManager* aViewManager = *vmIt )
2558       {
2559         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2560         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2561         {
2562           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2563           if( aSObj )
2564           {
2565             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2566             if( !CORBA::is_nil( anObject ) )
2567             {
2568               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2569               if( !aFieldStep->_is_nil() )
2570               {
2571                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2572                 Handle(SALOME_InteractiveObject) aStepIO =
2573                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2574                 Redisplay( aStepIO, false, false );
2575               }
2576             }
2577           }
2578         }
2579       }
2580     }
2581   }
2582   if(updateViewer)
2583     UpdateViewer();
2584 }