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