Salome HOME
Issue 0020194: EDF 977 ALL: Get rid of warnings PACKAGE_VERSION already defined
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 //  Copyright (C) 2007-2008  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GEOM_Displayer.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #include "GEOM_Displayer.h"
27
28 #include "GeometryGUI.h"
29
30 #include <GEOM_TypeFilter.h>
31 #include <GEOM_EdgeFilter.h>
32 #include <GEOM_FaceFilter.h>
33 #include <GEOM_CompoundFilter.h>
34 #include <GEOM_PreviewFilter.h>
35 #include <GEOM_LogicalFilter.h>
36 #include <GEOM_OCCFilter.h>
37
38 #include <GEOM_Actor.h>
39 #include <GEOM_AssemblyBuilder.h>
40 #include <GEOM_AISShape.hxx>
41 #include <GEOM_AISVector.hxx>
42 #include <GEOM_AISTrihedron.hxx>
43 #include <GEOM_VTKTrihedron.hxx>
44
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewManager.h>
49 #include <SUIT_ResourceMgr.h>
50
51 #include <SalomeApp_Study.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_TypeFilter.h>
55 #include <SalomeApp_Tools.h>
56
57 #include <SALOME_ListIteratorOfListIO.hxx>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOME_Prs.h>
60
61 #include <SOCC_Prs.h>
62 #include <SOCC_ViewModel.h>
63
64 #include <SVTK_Prs.h>
65 #include <SVTK_ViewModel.h>
66
67 // OCCT Includes
68 #include <AIS_Drawer.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <Prs3d_IsoAspect.hxx>
71 #include <Prs3d_PointAspect.hxx>
72 #include <StdSelect_TypeOfEdge.hxx>
73 #include <StdSelect_TypeOfFace.hxx>
74 #include <TopoDS_Face.hxx>
75 #include <BRep_Tool.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_Axis2Placement.hxx>
78 #include <gp_Pln.hxx>
79 #include <TColStd_MapOfInteger.hxx>
80 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
81 #include <TopoDS_Iterator.hxx>
82
83 // VTK Includes
84 #include <vtkActorCollection.h>
85 #include <vtkProperty.h>
86
87 // CORBA Headers
88 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
89
90 #include <GEOMImpl_Types.hxx>
91
92 using namespace std;
93
94 //================================================================
95 // Function : getActiveStudy
96 // Purpose  : Get active study, returns 0 if no open study frame
97 //================================================================
98 static inline SalomeApp_Study* getActiveStudy()
99 {
100   SUIT_Session* session = SUIT_Session::session();
101   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
102   if ( app )
103     return ( SalomeApp_Study* )app->activeStudy();
104   return 0;
105 }
106
107 //================================================================
108 // Function : getTopAbsMode
109 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
110 //            one from GEOMImpl_Types.h
111 //================================================================
112 static inline int getTopAbsMode( const int implType )
113 {
114   switch ( implType )
115   {
116     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
117     case GEOM_SOLID     : return TopAbs_SOLID;
118     case GEOM_SHELL     : return TopAbs_SHELL;
119     case GEOM_FACE      : return TopAbs_FACE;
120     case GEOM_WIRE      : return TopAbs_WIRE;
121     case GEOM_EDGE      : return TopAbs_EDGE;
122     case GEOM_POINT     : return TopAbs_VERTEX;
123     default             : return -1;
124   }
125 }
126
127 //================================================================
128 // Function : getFilter
129 // Purpose  : Get filter corresponding to the type of object
130 //            from GEOMImpl_Types.h
131 //================================================================
132 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
133 {
134   SUIT_SelectionFilter* aFilter;
135
136   int aTopAbsMode = getTopAbsMode( theMode );
137   if ( aTopAbsMode != -1 )
138     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
139   else
140     switch ( theMode )
141       {
142       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
143       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
144
145       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
146       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
147       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
148       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
149       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
150       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
151
152       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
153
154       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
155       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
156
157       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
158       }
159
160   return aFilter;
161 }
162
163 //================================================================
164 // Function : getComplexFilter
165 // Purpose  : Get compound filter corresponding to the type of 
166 //            object from GEOMImpl_Types.h
167 //================================================================
168 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
169 {
170   GEOM_CompoundFilter* aFilter;
171   
172   if(aSubShapes != NULL ) {
173     aFilter = new GEOM_CompoundFilter(getStudy());
174     QList<int> aTopAbsTypes;
175     QList<int>::const_iterator it;
176     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
177       int topAbsMode = getTopAbsMode(*it);
178       if(topAbsMode != -1 )
179         aTopAbsTypes.append(topAbsMode);
180     }
181     aFilter->addSubTypes(aTopAbsTypes);
182   }
183   
184   return aFilter;
185 }
186
187 //================================================================
188 // Function : getEntry
189 // Purpose  :
190 //================================================================
191 static string getEntry( GEOM::GEOM_Object_ptr object )
192 {
193   SUIT_Session* session = SUIT_Session::session();
194   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
195   if ( app )
196   {
197     CORBA::String_var IOR = app->orb()->object_to_string( object );
198     if ( strcmp(IOR.in(), "") != 0 )
199     {
200       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
201       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
202       if ( SO )
203         return SO->GetID();
204     }
205   }
206   return "";
207 }
208
209 //================================================================
210 // Function : getName
211 // Purpose  :
212 //================================================================
213 static string getName( GEOM::GEOM_Object_ptr object )
214 {
215   SUIT_Session* session = SUIT_Session::session();
216   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
217   if ( app )
218   {
219     CORBA::String_var IOR = app->orb()->object_to_string( object );
220     if ( strcmp(IOR.in(), "") != 0 )
221     {
222       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
223       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
224
225       _PTR(GenericAttribute) anAttr;
226
227       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
228       {
229         _PTR(AttributeName) aNameAttr( anAttr );
230         return aNameAttr->Value();
231       }
232     }
233   }
234
235   return "";
236 }
237
238 //=================================================================
239 /*!
240  *  GEOM_Displayer::GEOM_Displayer
241  *  Constructor
242  */
243 //=================================================================
244 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
245 {
246   if( st )
247     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
248   else
249     myApp = 0;
250
251   /* Shading Color */
252   SUIT_Session* session = SUIT_Session::session();
253   SUIT_ResourceMgr* resMgr = session->resourceMgr();
254
255   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
256   myShadingColor = SalomeApp_Tools::color( col );
257
258   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
259   myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
260   myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
261   if(myScaleOfMarker < 1.0)
262     myScaleOfMarker = 1.0;
263   if(myScaleOfMarker > 7.)
264     myScaleOfMarker = 7.;
265
266
267   myColor = -1;
268   // This color is used for shape displaying. If it is equal -1 then
269   // default color is used.
270
271   myWidth = -1;
272   myType = -1;
273
274   myToActivate = true;
275   // This parameter is used for activisation/deactivisation of objects to be displayed
276
277   myViewFrame = 0;
278 }
279
280 //=================================================================
281 /*!
282  *  GEOM_Displayer::~GEOM_Displayer
283  *  Destructor
284  */
285 //=================================================================
286 GEOM_Displayer::~GEOM_Displayer()
287 {
288 }
289
290 //=================================================================
291 /*!
292  *  GEOM_Displayer::Display
293  *  Display interactive object in the current viewer
294  */
295 //=================================================================
296 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
297                              const bool updateViewer,
298                              SALOME_View* theViewFrame )
299 {
300   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
301   if ( vf )
302   {
303     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
304
305     if ( prs )
306     {
307       vf->BeforeDisplay( this );
308       vf->Display( prs );
309       vf->AfterDisplay( this );
310
311       if ( updateViewer )
312         vf->Repaint();
313
314       delete prs;  // delete presentation because displayer is its owner
315     }
316   }
317 }
318
319 //=================================================================
320 /*!
321  *  GEOM_Displayer::Display
322  *  This overloaded Display() method can be useful for operations
323  *  not using dialog boxes.
324  */
325 //=================================================================
326 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
327 {
328   if ( theObj->_is_nil() )
329     return;
330
331   string entry = getEntry( theObj );
332   if ( entry != "" ) {
333     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
334             updateViewer);
335   }
336 }
337
338 //=================================================================
339 /*!
340  *  GEOM_Displayer::Erase
341  *  Erase interactive object in the current viewer
342  */
343 //=================================================================
344 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
345                             const bool forced,
346                             const bool updateViewer,
347                             SALOME_View* theViewFrame )
348 {
349   if ( theIO.IsNull() )
350     return;
351
352   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
353
354   if ( vf ) {
355     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
356     if ( prs ) {
357       vf->Erase( prs, forced );
358       if ( updateViewer )
359         vf->Repaint();
360       delete prs;  // delete presentation because displayer is its owner
361     }
362   }
363 }
364
365 //=================================================================
366 /*!
367  *  GEOM_Displayer::Erase
368  *  Erase geometry object in the current viewer
369  */
370 //=================================================================
371 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
372                             const bool forced,
373                             const bool updateViewer )
374 {
375   string entry = getEntry( theObj );
376   if ( entry != "" )
377   {
378     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
379           forced, updateViewer);
380   }
381 }
382
383 //=================================================================
384 /*!
385  *  GEOM_Displayer::Redisplay
386  *  Redisplay (erase and then display again) interactive object
387  *  in the current viewer
388  */
389 //=================================================================
390 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
391                                 const bool updateViewer )
392 {
393   // Remove the object permanently (<forced> == true)
394   SUIT_Session* ses = SUIT_Session::session();
395   SUIT_Application* app = ses->activeApplication();
396   if ( app )
397   {
398     SUIT_Desktop* desk = app->desktop();
399     QList<SUIT_ViewWindow*> wnds = desk->windows();
400     SUIT_ViewWindow* wnd;
401     QListIterator<SUIT_ViewWindow*> it( wnds );
402     while ( it.hasNext() && (wnd = it.next()) )
403     {
404       SUIT_ViewManager* vman = wnd->getViewManager();
405       if ( vman )
406       {
407         SUIT_ViewModel* vmodel = vman->getViewModel();
408         if ( vmodel )
409         {
410           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
411           if ( view )
412           {
413             if ( view->isVisible( theIO ) || view == GetActiveView() )
414             {
415               Erase( theIO, true, false, view );
416               Display( theIO, updateViewer, view );
417             }
418           }
419         }
420       }
421     }
422   }
423 }
424
425 //=================================================================
426 /*!
427  *  GEOM_Displayer::Display
428  *  Calls Display() method for each object in the given list
429  */
430 //=================================================================
431 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
432 {
433   SALOME_ListIteratorOfListIO Iter( theIOList );
434   for ( ; Iter.More(); Iter.Next() ) {
435     Display( Iter.Value(), false );
436   }
437   if ( updateViewer )
438     UpdateViewer();
439 }
440
441 //=================================================================
442 /*!
443  *  GEOM_Displayer::Erase
444  *  Calls Erase() method for each object in the given list
445  */
446 //=================================================================
447 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
448                             const bool forced,
449                             const bool updateViewer )
450 {
451   SALOME_ListIteratorOfListIO Iter( theIOList );
452   for ( ; Iter.More(); Iter.Next() )
453     Erase( Iter.Value(), forced, false );
454
455   if ( updateViewer )
456     UpdateViewer();
457 }
458
459 //=================================================================
460 /*!
461  *  GEOM_Displayer::Redisplay
462  *  Calls Redisplay() method for each object in the given list
463  */
464 //=================================================================
465 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
466 {
467   SALOME_ListIteratorOfListIO Iter( theIOList );
468   for ( ; Iter.More(); Iter.Next() )
469     Redisplay( Iter.Value(), false );
470
471   if ( updateViewer )
472     UpdateViewer();
473 }
474
475 //=================================================================
476 /*!
477  *  GEOM_Displayer::Update
478  *  Update OCC presentaion
479  *  [ Reimplemented from SALOME_Displayer ]
480  */
481 //=================================================================
482 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
483 {
484   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
485   if ( !occPrs )
486     return;
487
488   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
489   {
490     TopoDS_Face aFace = TopoDS::Face( myShape );
491     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
492     if ( !aPlane.IsNull() )
493     {
494       gp_Ax3 aPos = aPlane->Pln().Position();
495       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
496
497       Handle(GEOM_AISTrihedron) aTrh;
498
499       if ( occPrs->IsNull() )
500       {
501         aTrh = new GEOM_AISTrihedron( aPlc );
502
503         if ( HasColor() )
504           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
505
506         if ( HasWidth() )
507           aTrh->SetWidth( GetWidth() );
508
509         if ( !myIO.IsNull() )
510         {
511           aTrh->setIO( myIO );
512           aTrh->SetOwner( myIO );
513         }
514
515         occPrs->AddObject( aTrh );
516       }
517       else
518       {
519         AIS_ListOfInteractive aList;
520         occPrs->GetObjects( aList );
521         AIS_ListIteratorOfListOfInteractive anIter( aList );
522         for ( ; anIter.More(); anIter.Next() )
523         {
524           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
525           if ( !aTrh.IsNull() )
526           {
527             aTrh->SetComponent( aPlc );
528             aTrh->SetToUpdate();
529           }
530         }
531       }
532
533       occPrs->SetToActivate( ToActivate() );
534     }
535   }
536   else
537   {
538     // if presentation is empty we try to create new one
539     if ( occPrs->IsNull() )
540     {
541       if ( !myShape.IsNull() )
542       {
543         //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
544         Handle(GEOM_AISShape) AISShape;
545         if (myType == GEOM_VECTOR)
546           AISShape = new GEOM_AISVector (myShape, "");
547         else {
548           if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
549               !TopoDS_Iterator(myShape).More())
550             return;// NPAL15983 (Bug when displaying empty groups)
551           AISShape = new GEOM_AISShape (myShape, "");
552         }
553         // Temporary staff: vertex must be infinite for correct visualization
554         AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
555
556         // Setup shape properties here ..., e.g. display mode, color, transparency, etc
557         AISShape->SetDisplayMode( myDisplayMode );
558         AISShape->SetShadingColor( myShadingColor );
559
560         // Set color and number for iso lines
561         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
562         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
563                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
564         Quantity_Color aColor = SalomeApp_Tools::color( col );
565         int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
566         int aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
567
568         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
569         anAspect->SetNumber( anUIsoNumber );
570         anAspect->SetColor( aColor );
571         AISShape->Attributes()->SetUIsoAspect( anAspect );
572
573         anAspect = AISShape->Attributes()->VIsoAspect();
574         anAspect->SetNumber( aVIsoNumber );
575         anAspect->SetColor( aColor );
576         AISShape->Attributes()->SetVIsoAspect( anAspect );
577
578         if ( HasColor() )
579         {
580           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
581           if ( myShape.ShapeType() == TopAbs_VERTEX )
582           {
583             Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
584             anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
585             anAspect->SetScale( myScaleOfMarker );
586             anAspect->SetTypeOfMarker( myTypeOfMarker );
587             AISShape->Attributes()->SetPointAspect( anAspect );
588           }
589         }
590         else
591           {
592             if ( myShape.ShapeType() == TopAbs_VERTEX )
593               {
594                 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
595                 aColor = SalomeApp_Tools::color( col );
596
597                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
598                 anAspect->SetColor( aColor );
599                 anAspect->SetScale( myScaleOfMarker );
600                 anAspect->SetTypeOfMarker( myTypeOfMarker );
601                 AISShape->Attributes()->SetPointAspect( anAspect );
602               }
603             else
604               {
605                 // Set line aspect
606                 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
607                 aColor = SalomeApp_Tools::color( col );
608
609                 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
610                 anAspect->SetColor( aColor );
611                 AISShape->Attributes()->SetLineAspect( anAspect );
612
613                 // Set unfree boundaries aspect
614                 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
615                 anAspect->SetColor( aColor );
616                 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
617
618                 // Set free boundaries aspect
619                 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
620                 aColor = SalomeApp_Tools::color( col );
621
622                 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
623                 anAspect->SetColor( aColor );
624                 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
625
626                 // Set wire aspect
627                 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
628                 aColor = SalomeApp_Tools::color( col );
629
630                 anAspect = AISShape->Attributes()->WireAspect();
631                 anAspect->SetColor( aColor );
632                 AISShape->Attributes()->SetWireAspect( anAspect );
633
634                 // bug [SALOME platform 0019868]
635                 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
636                 AISShape->SetOwnDeviationAngle( 10*PI/180 );
637               }
638           }
639
640         if ( HasWidth() )
641           AISShape->SetWidth( GetWidth() );
642
643         if ( !myIO.IsNull() )
644         {
645           AISShape->setIO( myIO );
646           AISShape->SetOwner( myIO );
647         }
648         else if ( !myName.empty() )
649         {
650           // Workaround to allow selection of temporary objects
651           static int tempId = 0;
652           char buf[50];
653           sprintf( buf, "TEMP_%d", tempId++ );
654           Handle( SALOME_InteractiveObject ) anObj =
655             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
656           AISShape->setIO( anObj );
657           AISShape->SetOwner( anObj );
658         }
659
660         // Get color from GEOM_Object
661         SUIT_Session* session = SUIT_Session::session();
662         SUIT_Application* app = session->activeApplication();
663         if ( app )
664         {
665           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
666           if ( study )
667           {
668             Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
669             if ( !anIO.IsNull() )
670             {
671               _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) );
672               if ( SO )
673               {
674                 // get CORBA reference to data object
675                 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
676                 if ( !CORBA::is_nil( object ) )
677                 {
678                   // downcast to GEOM object
679                   GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
680                   if ( !aGeomObject->_is_nil() )
681                   {
682                     SALOMEDS::Color aSColor = aGeomObject->GetColor();
683                     bool hasColor = aSColor.R > 0 || aSColor.G > 0 || aSColor.B > 0;
684                     if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
685                     {
686                       GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
687                       GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() );
688                       GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
689                       if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
690                       {
691                         QList<SALOMEDS::Color> aReservedColors;
692
693                         SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
694                         CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
695                         if ( strcmp(IOR.in(), "") != 0 )
696                         {
697                           _PTR(Study) aStudy = study->studyDS();
698                           _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
699                           _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
700                           for( ; it->More(); it->Next() )
701                           {
702                             _PTR(SObject) aChildSObject( it->Value() );
703                             GEOM::GEOM_Object_var aChildObject =
704                               GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
705                             if( CORBA::is_nil( aChildObject ) )
706                               continue;
707
708                             if( aChildObject->GetType() != GEOM_GROUP )
709                               continue;
710
711                             SALOMEDS::Color aReservedColor = aChildObject->GetColor();
712                             aReservedColors.append( aReservedColor );
713                           }
714                         }
715
716                         aSColor = getUniqueColor( aReservedColors );
717                         hasColor = true;
718                       }
719                     }
720
721                     if( hasColor )
722                     {
723                       Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
724                       AISShape->SetColor( aQuanColor );
725                       AISShape->SetShadingColor( aQuanColor );
726                     }
727                   }
728                 }
729               }
730             }
731           }
732         }
733
734         // AISShape->SetName(???); ??? necessary to set name ???
735         occPrs->AddObject( AISShape );
736
737         // In accordance with ToActivate() value object will be activated/deactivated
738         // when it will be displayed
739         occPrs->SetToActivate( ToActivate() );
740       }
741     }
742     // if presentation is found -> set again shape for it
743     else
744     {
745       if ( !myShape.IsNull() )
746       {
747         AIS_ListOfInteractive IOList;
748         occPrs->GetObjects( IOList );
749         AIS_ListIteratorOfListOfInteractive Iter( IOList );
750         for ( ; Iter.More(); Iter.Next() )
751         {
752           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
753           if ( AISShape.IsNull() )
754             continue;
755           if ( AISShape->Shape() != myShape )
756           {
757             AISShape->Set( myShape );
758             AISShape->UpdateSelection();
759             AISShape->SetToUpdate();
760           }
761           if ( !myIO.IsNull() )
762           {
763             AISShape->setIO( myIO );
764             AISShape->SetOwner( myIO );
765           }
766         }
767       }
768     }
769   }
770 }
771
772 //=================================================================
773 /*!
774  *  GEOM_Displayer::Update
775  *  Update VTK presentaion
776  *  [ Reimplemented from SALOME_Displayer ]
777  */
778 //=================================================================
779 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
780 {
781   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
782   if ( !vtkPrs || myShape.IsNull() )
783     return;
784
785   vtkActorCollection* theActors = 0;
786
787   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
788   {
789     myToActivate = false;
790     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
791
792     if ( HasColor() )
793     {
794       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
795       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
796     }
797
798     Handle(Geom_Plane) aPlane =
799       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
800     if ( aPlane.IsNull() )
801       return;
802
803     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
804     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
805
806 //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
807 //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
808
809     vtkPrs->AddObject( aTrh );
810
811     theActors = vtkActorCollection::New();
812     theActors->AddItem( aTrh );
813   }
814   else
815   {
816     bool isVector;
817     if (myType == GEOM_VECTOR) isVector = true;
818     theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
819   }
820
821   theActors->InitTraversal();
822
823   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
824
825   vtkProperty* aProp = 0;
826
827   if ( HasColor() || HasWidth() )
828   {
829     aProp = vtkProperty::New();
830     aProp->SetRepresentationToWireframe();
831   }
832
833   if ( HasColor() )
834   {
835     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
836     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
837   }
838
839   if ( HasWidth() )
840   {
841     aProp->SetLineWidth( GetWidth() );
842   }
843
844   while ( anActor != NULL )
845   {
846     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
847
848     GActor->setIO( myIO );
849
850     if ( aProp )
851     {
852       GActor->SetProperty( aProp );
853       GActor->SetPreviewProperty( aProp );
854
855       GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
856       if ( aGeomGActor != 0 )
857       {
858         aGeomGActor->SetShadingProperty( aProp );
859         aGeomGActor->SetWireframeProperty( aProp );
860       }
861     }
862
863     if ( myToActivate )
864       GActor->PickableOn();
865     else
866       GActor->PickableOff();
867
868     vtkPrs->AddObject( GActor );
869
870     anActor = (vtkActor*)theActors->GetNextActor();
871   }
872
873   if ( aProp )
874     aProp->Delete();
875
876   theActors->Delete();
877 }
878
879 //=================================================================
880 /*!
881  *  GEOM_Displayer::BuildPrs
882  *  Build presentation accordint to the current viewer type
883  */
884 //=================================================================
885 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
886 {
887   if ( theObj->_is_nil() )
888     return 0;
889
890   myViewFrame = GetActiveView();
891   if ( myViewFrame == 0 )
892     return 0;
893
894   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
895   if ( aPrs == 0 )
896     return 0;
897
898   internalReset();
899   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
900   myType = theObj->GetType();
901
902   // Update presentation
903   UpdatePrs( aPrs );
904
905   return aPrs;
906 }
907
908 //=================================================================
909 /*!
910  *  GEOM_Displayer::BuildPrs
911  *  Build presentation accordint to the current viewer type
912  */
913 //=================================================================
914 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
915 {
916   myViewFrame = GetActiveView();
917   if ( theShape.IsNull() || myViewFrame == 0 )
918     return 0;
919
920   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
921   if ( aPrs == 0 )
922     return 0;
923
924   internalReset();
925   setShape( theShape );
926   myType = -1;
927
928   UpdatePrs( aPrs );
929
930   return aPrs;
931 }
932
933 //=================================================================
934 /*!
935  *  GEOM_Displayer::buildPresentation
936  *  Builds/finds object's presentation for the current viewer
937  *  Calls corresponding Update() method by means of double dispatch
938  *  [ internal ]
939  */
940 //=================================================================
941 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
942                                                SALOME_View* theViewFrame )
943 {
944   SALOME_Prs* prs = 0;
945   internalReset();
946
947   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
948
949   if ( myViewFrame )
950   {
951     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
952     if ( prs )
953     {
954       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
955       theIO->setEntry( entry.toLatin1().constData() );
956       if ( !theIO.IsNull() )
957       {
958         // set interactive object
959         setIO( theIO );
960         //  Find SOBject (because shape should be published previously)
961         SUIT_Session* session = SUIT_Session::session();
962         SUIT_Application* app = session->activeApplication();
963         if ( app )
964         {
965           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
966           if ( study )
967           {
968             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
969             if ( SO )
970             {
971               // get CORBA reference to data object
972               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
973               if ( !CORBA::is_nil( object ) )
974               {
975                 // downcast to GEOM object
976                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
977                 if ( !GeomObject->_is_nil() )
978                 {
979                   // finally set shape
980                   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
981                   myType = GeomObject->GetType();
982                 }
983               }
984             }
985           }
986         }
987       }
988       UpdatePrs( prs );  // Update presentation by using of the double dispatch
989     }
990   }
991   return prs;
992 }
993
994 //=================================================================
995 /*!
996  *  GEOM_Displayer::internalReset
997  *  Resets internal data
998  *  [internal]
999  */
1000 //=================================================================
1001 void GEOM_Displayer::internalReset()
1002 {
1003   myIO.Nullify();
1004   myShape.Nullify();
1005 }
1006
1007 //=================================================================
1008 /*!
1009  *  GEOM_Displayer::LocalSelection
1010  *  Activate selection of CAD shapes with activisation of selection
1011  *  of their sub-shapes (with opened local context for OCC viewer)
1012  */
1013 //=================================================================
1014 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1015 {
1016   SUIT_Session* session = SUIT_Session::session();
1017   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1018   if ( !app )
1019     return;
1020
1021   LightApp_SelectionMgr* sm = app->selectionMgr();
1022
1023   // remove all filters from selection
1024   sm->clearFilters();
1025
1026   SALOME_View* vf = GetActiveView();
1027   if ( vf ) {
1028     if (!theIO.IsNull() && !vf->isVisible(theIO))
1029       Display(theIO);
1030     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1031     vf->LocalSelection( prs, theMode );
1032     delete prs;  // delete presentation because displayer is its owner
1033   }
1034 }
1035
1036 //=================================================================
1037 /*!
1038  *  GEOM_Displayer::globalSelection
1039  *  Activate selection of CAD shapes without activisation of selection
1040  *  of their sub-shapes (without opened local context for OCC viewer)
1041  */
1042 //=================================================================
1043 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1044 {
1045   TColStd_MapOfInteger aModes;
1046   aModes.Add( theMode );
1047   GlobalSelection( aModes, update );
1048 }
1049
1050 //=================================================================
1051 /*!
1052  *  GEOM_Displayer::globalSelection
1053  *  Activate selection of CAD shapes without activisation of selection
1054  *  of their sub-shapes (without opened local context for OCC viewer)
1055  */
1056 //=================================================================
1057 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1058                                       const bool update, const QList<int>* theSubShapes )
1059 {
1060   SUIT_Session* session = SUIT_Session::session();
1061   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1062   if ( !app )
1063     return;
1064
1065   SALOME_View* vf = GetActiveView();
1066   if ( vf == 0 )
1067     return;
1068
1069   // Close local context
1070   vf->GlobalSelection( update );
1071
1072   // Set selection filters in accordance with current mode
1073   LightApp_SelectionMgr* sm = app->selectionMgr();
1074   if ( !sm )
1075     return;
1076
1077   // Remove from selection temporary objects if necessary
1078   if ( !theModes.Contains( GEOM_PREVIEW ) )
1079     clearTemporary( sm );
1080
1081   //@ aSel->ClearIndex();
1082
1083   sm->clearFilters();
1084
1085   // Remove filters from AIS_InteractiveContext
1086   Handle(AIS_InteractiveContext) ic;
1087   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1088   if ( viewer )
1089     {
1090       ic = viewer->getAISContext();
1091       if ( !ic.IsNull() )
1092         ic->RemoveFilters();
1093     }
1094
1095   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1096     return;
1097
1098   SUIT_SelectionFilter* aFilter;
1099   if ( theModes.Extent() == 1 )
1100     {
1101       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1102       
1103       if ( aMode == GEOM_COMPOUNDFILTER )
1104         aFilter = getComplexFilter( theSubShapes );
1105       else    
1106         aFilter = getFilter( aMode );
1107     }
1108   else if ( theModes.Extent() > 1 )
1109     {
1110       TColStd_MapOfInteger aTopAbsModes;
1111       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1112       QList<SUIT_SelectionFilter*> aListOfFilters;
1113       for ( ; anIter.More(); anIter.Next() )
1114         {
1115           SUIT_SelectionFilter* aFilter;
1116           int aMode = anIter.Key();
1117           if ( aMode == GEOM_COMPOUNDFILTER )
1118             aFilter = getComplexFilter( theSubShapes );
1119           else    
1120             aFilter = getFilter( aMode );
1121
1122           if ( aFilter )
1123             aListOfFilters.append( aFilter );
1124         }
1125
1126       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1127     }
1128   else
1129     return;
1130
1131   if ( aFilter )
1132     {
1133       sm->installFilter( aFilter );
1134       if ( !ic.IsNull() )
1135         {
1136           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1137           ic->AddFilter( anOCCFilter );
1138         }
1139     }
1140 }
1141
1142 //=================================================================
1143 /*!
1144  *  GEOM_Displayer::LocalSelection
1145  *  Activate selection of CAD shapes with activisation of selection
1146  *  of their sub-shapes (with opened local context for OCC viewer)
1147  */
1148 //=================================================================
1149 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1150 {
1151   SALOME_ListIteratorOfListIO Iter( theIOList );
1152   for ( ; Iter.More(); Iter.Next() )
1153     LocalSelection( Iter.Value(), theMode );
1154 }
1155
1156 //=================================================================
1157 /*!
1158  *  GEOM_Displayer::BeforeDisplay
1159  *  Called before displaying of pars. Close local context
1160  *  [ Reimplemented from SALOME_Displayer ]
1161  */
1162 //=================================================================
1163 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1164 {
1165   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1166   if ( vf )
1167   {
1168     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1169     if ( !ic.IsNull() )
1170     {
1171       if ( ic->HasOpenedContext() )
1172       ic->CloseAllContexts();
1173     }
1174   }
1175 }
1176
1177 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1178 {
1179 }
1180
1181
1182 //=================================================================
1183 /*!
1184  *  GEOM_Displayer::SetColor
1185  *  Set color for shape displaying. If it is equal -1 then default color is used.
1186  *  Available values are from Quantity_NameOfColor enumeration
1187  */
1188 //=================================================================
1189 void GEOM_Displayer::SetColor( const int color )
1190 {
1191   if ( color == -1 )
1192     UnsetColor();
1193   else
1194   {
1195     myColor = color;
1196     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1197   }
1198 }
1199
1200 int GEOM_Displayer::GetColor() const
1201 {
1202   return myColor;
1203 }
1204
1205 bool GEOM_Displayer::HasColor() const
1206 {
1207   return myColor != -1;
1208 }
1209
1210 void GEOM_Displayer::UnsetColor()
1211 {
1212   myColor = -1;
1213   
1214   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1215   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1216   myShadingColor = SalomeApp_Tools::color( col );
1217 }
1218
1219 //=================================================================
1220 /*!
1221  *  GEOM_Displayer::SetWidth
1222  *  Set width of shape displaying. If it is equal -1 then default width is used.
1223  */
1224 //=================================================================
1225 void GEOM_Displayer::SetWidth( const double width )
1226 {
1227   myWidth = width;
1228 }
1229
1230 double GEOM_Displayer::GetWidth() const
1231 {
1232   return myWidth;
1233 }
1234
1235 bool GEOM_Displayer::HasWidth() const
1236 {
1237   return myWidth != -1;
1238 }
1239
1240 void GEOM_Displayer::UnsetWidth()
1241 {
1242   myWidth = -1;
1243 }
1244
1245 //=================================================================
1246 /*!
1247  *  GEOM_Displayer::SetToActivate
1248  *  This method is used for activisation/deactivisation of objects to be displayed
1249  */
1250 //=================================================================
1251 void GEOM_Displayer::SetToActivate( const bool toActivate )
1252 {
1253   myToActivate = toActivate;
1254 }
1255 bool GEOM_Displayer::ToActivate() const
1256 {
1257   return myToActivate;
1258 }
1259
1260 //=================================================================
1261 /*!
1262  *  GEOM_Displayer::clearTemporary
1263  *  Removes from selection temporary objects
1264  */
1265 //=================================================================
1266 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1267 {
1268   SALOME_ListIO selected, toSelect;
1269   theSelMgr->selectedObjects( selected );
1270
1271   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1272     Handle(SALOME_InteractiveObject) io = it.Value();
1273     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1274       toSelect.Append( it.Value() );
1275   }
1276
1277   theSelMgr->setSelectedObjects( toSelect, true );
1278 }
1279
1280 void GEOM_Displayer::SetName( const char* theName )
1281 {
1282   myName = theName;
1283 }
1284
1285 void GEOM_Displayer::UnsetName()
1286 {
1287   myName = "";
1288 }
1289
1290 SalomeApp_Study* GEOM_Displayer::getStudy() const
1291 {
1292   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1293 }
1294
1295 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1296 {
1297   myIO = theIO;
1298 }
1299
1300 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1301 {
1302   myShape = theShape;
1303 }
1304
1305 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1306 {
1307   return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1308 }
1309
1310 int GEOM_Displayer::SetDisplayMode( const int theMode )
1311 {
1312   int aPrevMode = myDisplayMode;
1313   if ( theMode != -1 )
1314     myDisplayMode = theMode;
1315   else
1316   {
1317     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1318     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1319   }
1320   return aPrevMode;
1321 }
1322
1323 int GEOM_Displayer::GetDisplayMode() const
1324 {
1325   return myDisplayMode;
1326 }
1327
1328 int GEOM_Displayer::UnsetDisplayMode()
1329 {
1330   int aPrevMode = myDisplayMode;
1331   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1332   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1333   return aPrevMode;
1334 }
1335
1336 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1337 {
1338   int aHue = -1;
1339   int aTolerance = 64;
1340   int anIterations = 0;
1341   int aPeriod = 5;
1342
1343   while( 1 )
1344   {
1345     anIterations++;
1346     if( anIterations % aPeriod == 0 )
1347     {
1348       aTolerance /= 2;
1349       if( aTolerance < 1 )
1350         break;
1351     }
1352     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1353
1354     aHue = (int)( 360.0 * rand() / RAND_MAX );
1355     //cout << "Hue = " << aHue << endl;
1356
1357     //cout << "Auto colors : ";
1358     bool ok = true;
1359     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1360     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1361     for( ; it != itEnd; ++it )
1362     {
1363       SALOMEDS::Color anAutoColor = *it;
1364       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1365
1366       int h, s, v;
1367       aQColor.getHsv( &h, &s, &v );
1368       //cout << h << " ";
1369       if( abs( h - aHue ) < aTolerance )
1370       {
1371         ok = false;
1372         //cout << "break (diff = " << abs( h - aHue ) << ")";
1373         break;
1374       }
1375     }
1376     //cout << endl;
1377
1378     if( ok )
1379       break;
1380   }
1381
1382   //cout << "Hue of the returned color = " << aHue << endl;
1383   QColor aColor;
1384   aColor.setHsv( aHue, 255, 255 );
1385
1386   SALOMEDS::Color aSColor;
1387   aSColor.R = (double)aColor.red() / 255.0;
1388   aSColor.G = (double)aColor.green() / 255.0;
1389   aSColor.B = (double)aColor.blue() / 255.0;
1390
1391   return aSColor;
1392 }