Salome HOME
b183b3f53d0c6916cb4bd948b782b0977a1f04cf
[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 = (myType == GEOM_VECTOR);
817     theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
818   }
819
820   theActors->InitTraversal();
821
822   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
823
824   vtkProperty* aProp = 0;
825
826   if ( HasColor() || HasWidth() )
827   {
828     aProp = vtkProperty::New();
829     aProp->SetRepresentationToWireframe();
830   }
831
832   if ( HasColor() )
833   {
834     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
835     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
836   }
837
838   if ( HasWidth() )
839   {
840     aProp->SetLineWidth( GetWidth() );
841   }
842
843   while ( anActor != NULL )
844   {
845     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
846
847     GActor->setIO( myIO );
848
849     if ( aProp )
850     {
851       GActor->SetProperty( aProp );
852       GActor->SetPreviewProperty( aProp );
853
854       GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
855       if ( aGeomGActor != 0 )
856       {
857         aGeomGActor->SetShadingProperty( aProp );
858         aGeomGActor->SetWireframeProperty( aProp );
859       }
860     }
861
862     if ( myToActivate )
863       GActor->PickableOn();
864     else
865       GActor->PickableOff();
866
867     vtkPrs->AddObject( GActor );
868
869     anActor = (vtkActor*)theActors->GetNextActor();
870   }
871
872   if ( aProp )
873     aProp->Delete();
874
875   theActors->Delete();
876 }
877
878 //=================================================================
879 /*!
880  *  GEOM_Displayer::BuildPrs
881  *  Build presentation accordint to the current viewer type
882  */
883 //=================================================================
884 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
885 {
886   if ( theObj->_is_nil() )
887     return 0;
888
889   myViewFrame = GetActiveView();
890   if ( myViewFrame == 0 )
891     return 0;
892
893   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
894   if ( aPrs == 0 )
895     return 0;
896
897   internalReset();
898   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
899   myType = theObj->GetType();
900
901   // Update presentation
902   UpdatePrs( aPrs );
903
904   return aPrs;
905 }
906
907 //=================================================================
908 /*!
909  *  GEOM_Displayer::BuildPrs
910  *  Build presentation accordint to the current viewer type
911  */
912 //=================================================================
913 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
914 {
915   myViewFrame = GetActiveView();
916   if ( theShape.IsNull() || myViewFrame == 0 )
917     return 0;
918
919   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
920   if ( aPrs == 0 )
921     return 0;
922
923   internalReset();
924   setShape( theShape );
925   myType = -1;
926
927   UpdatePrs( aPrs );
928
929   return aPrs;
930 }
931
932 //=================================================================
933 /*!
934  *  GEOM_Displayer::buildPresentation
935  *  Builds/finds object's presentation for the current viewer
936  *  Calls corresponding Update() method by means of double dispatch
937  *  [ internal ]
938  */
939 //=================================================================
940 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
941                                                SALOME_View* theViewFrame )
942 {
943   SALOME_Prs* prs = 0;
944   internalReset();
945
946   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
947
948   if ( myViewFrame )
949   {
950     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
951     if ( prs )
952     {
953       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
954       theIO->setEntry( entry.toLatin1().constData() );
955       if ( !theIO.IsNull() )
956       {
957         // set interactive object
958         setIO( theIO );
959         //  Find SOBject (because shape should be published previously)
960         SUIT_Session* session = SUIT_Session::session();
961         SUIT_Application* app = session->activeApplication();
962         if ( app )
963         {
964           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
965           if ( study )
966           {
967             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
968             if ( SO )
969             {
970               // get CORBA reference to data object
971               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
972               if ( !CORBA::is_nil( object ) )
973               {
974                 // downcast to GEOM object
975                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
976                 if ( !GeomObject->_is_nil() )
977                 {
978                   // finally set shape
979                   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
980                   myType = GeomObject->GetType();
981                 }
982               }
983             }
984           }
985         }
986       }
987       UpdatePrs( prs );  // Update presentation by using of the double dispatch
988     }
989   }
990   return prs;
991 }
992
993 //=================================================================
994 /*!
995  *  GEOM_Displayer::internalReset
996  *  Resets internal data
997  *  [internal]
998  */
999 //=================================================================
1000 void GEOM_Displayer::internalReset()
1001 {
1002   myIO.Nullify();
1003   myShape.Nullify();
1004 }
1005
1006 //=================================================================
1007 /*!
1008  *  GEOM_Displayer::LocalSelection
1009  *  Activate selection of CAD shapes with activisation of selection
1010  *  of their sub-shapes (with opened local context for OCC viewer)
1011  */
1012 //=================================================================
1013 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1014 {
1015   SUIT_Session* session = SUIT_Session::session();
1016   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1017   if ( !app )
1018     return;
1019
1020   LightApp_SelectionMgr* sm = app->selectionMgr();
1021
1022   // remove all filters from selection
1023   sm->clearFilters();
1024
1025   SALOME_View* vf = GetActiveView();
1026   if ( vf ) {
1027     if (!theIO.IsNull() && !vf->isVisible(theIO))
1028       Display(theIO);
1029     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1030     vf->LocalSelection( prs, theMode );
1031     delete prs;  // delete presentation because displayer is its owner
1032   }
1033 }
1034
1035 //=================================================================
1036 /*!
1037  *  GEOM_Displayer::globalSelection
1038  *  Activate selection of CAD shapes without activisation of selection
1039  *  of their sub-shapes (without opened local context for OCC viewer)
1040  */
1041 //=================================================================
1042 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1043 {
1044   TColStd_MapOfInteger aModes;
1045   aModes.Add( theMode );
1046   GlobalSelection( aModes, update );
1047 }
1048
1049 //=================================================================
1050 /*!
1051  *  GEOM_Displayer::globalSelection
1052  *  Activate selection of CAD shapes without activisation of selection
1053  *  of their sub-shapes (without opened local context for OCC viewer)
1054  */
1055 //=================================================================
1056 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1057                                       const bool update, const QList<int>* theSubShapes )
1058 {
1059   SUIT_Session* session = SUIT_Session::session();
1060   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1061   if ( !app )
1062     return;
1063
1064   SALOME_View* vf = GetActiveView();
1065   if ( vf == 0 )
1066     return;
1067
1068   // Close local context
1069   vf->GlobalSelection( update );
1070
1071   // Set selection filters in accordance with current mode
1072   LightApp_SelectionMgr* sm = app->selectionMgr();
1073   if ( !sm )
1074     return;
1075
1076   // Remove from selection temporary objects if necessary
1077   if ( !theModes.Contains( GEOM_PREVIEW ) )
1078     clearTemporary( sm );
1079
1080   //@ aSel->ClearIndex();
1081
1082   sm->clearFilters();
1083
1084   // Remove filters from AIS_InteractiveContext
1085   Handle(AIS_InteractiveContext) ic;
1086   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1087   if ( viewer )
1088     {
1089       ic = viewer->getAISContext();
1090       if ( !ic.IsNull() )
1091         ic->RemoveFilters();
1092     }
1093
1094   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1095     return;
1096
1097   SUIT_SelectionFilter* aFilter;
1098   if ( theModes.Extent() == 1 )
1099     {
1100       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1101       
1102       if ( aMode == GEOM_COMPOUNDFILTER )
1103         aFilter = getComplexFilter( theSubShapes );
1104       else    
1105         aFilter = getFilter( aMode );
1106     }
1107   else if ( theModes.Extent() > 1 )
1108     {
1109       TColStd_MapOfInteger aTopAbsModes;
1110       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1111       QList<SUIT_SelectionFilter*> aListOfFilters;
1112       for ( ; anIter.More(); anIter.Next() )
1113         {
1114           SUIT_SelectionFilter* aFilter;
1115           int aMode = anIter.Key();
1116           if ( aMode == GEOM_COMPOUNDFILTER )
1117             aFilter = getComplexFilter( theSubShapes );
1118           else    
1119             aFilter = getFilter( aMode );
1120
1121           if ( aFilter )
1122             aListOfFilters.append( aFilter );
1123         }
1124
1125       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1126     }
1127   else
1128     return;
1129
1130   if ( aFilter )
1131     {
1132       sm->installFilter( aFilter );
1133       if ( !ic.IsNull() )
1134         {
1135           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1136           ic->AddFilter( anOCCFilter );
1137         }
1138     }
1139 }
1140
1141 //=================================================================
1142 /*!
1143  *  GEOM_Displayer::LocalSelection
1144  *  Activate selection of CAD shapes with activisation of selection
1145  *  of their sub-shapes (with opened local context for OCC viewer)
1146  */
1147 //=================================================================
1148 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1149 {
1150   SALOME_ListIteratorOfListIO Iter( theIOList );
1151   for ( ; Iter.More(); Iter.Next() )
1152     LocalSelection( Iter.Value(), theMode );
1153 }
1154
1155 //=================================================================
1156 /*!
1157  *  GEOM_Displayer::BeforeDisplay
1158  *  Called before displaying of pars. Close local context
1159  *  [ Reimplemented from SALOME_Displayer ]
1160  */
1161 //=================================================================
1162 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1163 {
1164   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1165   if ( vf )
1166   {
1167     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1168     if ( !ic.IsNull() )
1169     {
1170       if ( ic->HasOpenedContext() )
1171       ic->CloseAllContexts();
1172     }
1173   }
1174 }
1175
1176 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1177 {
1178 }
1179
1180
1181 //=================================================================
1182 /*!
1183  *  GEOM_Displayer::SetColor
1184  *  Set color for shape displaying. If it is equal -1 then default color is used.
1185  *  Available values are from Quantity_NameOfColor enumeration
1186  */
1187 //=================================================================
1188 void GEOM_Displayer::SetColor( const int color )
1189 {
1190   if ( color == -1 )
1191     UnsetColor();
1192   else
1193   {
1194     myColor = color;
1195     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1196   }
1197 }
1198
1199 int GEOM_Displayer::GetColor() const
1200 {
1201   return myColor;
1202 }
1203
1204 bool GEOM_Displayer::HasColor() const
1205 {
1206   return myColor != -1;
1207 }
1208
1209 void GEOM_Displayer::UnsetColor()
1210 {
1211   myColor = -1;
1212   
1213   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1214   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1215   myShadingColor = SalomeApp_Tools::color( col );
1216 }
1217
1218 //=================================================================
1219 /*!
1220  *  GEOM_Displayer::SetWidth
1221  *  Set width of shape displaying. If it is equal -1 then default width is used.
1222  */
1223 //=================================================================
1224 void GEOM_Displayer::SetWidth( const double width )
1225 {
1226   myWidth = width;
1227 }
1228
1229 double GEOM_Displayer::GetWidth() const
1230 {
1231   return myWidth;
1232 }
1233
1234 bool GEOM_Displayer::HasWidth() const
1235 {
1236   return myWidth != -1;
1237 }
1238
1239 void GEOM_Displayer::UnsetWidth()
1240 {
1241   myWidth = -1;
1242 }
1243
1244 //=================================================================
1245 /*!
1246  *  GEOM_Displayer::SetToActivate
1247  *  This method is used for activisation/deactivisation of objects to be displayed
1248  */
1249 //=================================================================
1250 void GEOM_Displayer::SetToActivate( const bool toActivate )
1251 {
1252   myToActivate = toActivate;
1253 }
1254 bool GEOM_Displayer::ToActivate() const
1255 {
1256   return myToActivate;
1257 }
1258
1259 //=================================================================
1260 /*!
1261  *  GEOM_Displayer::clearTemporary
1262  *  Removes from selection temporary objects
1263  */
1264 //=================================================================
1265 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1266 {
1267   SALOME_ListIO selected, toSelect;
1268   theSelMgr->selectedObjects( selected );
1269
1270   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1271     Handle(SALOME_InteractiveObject) io = it.Value();
1272     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1273       toSelect.Append( it.Value() );
1274   }
1275
1276   theSelMgr->setSelectedObjects( toSelect, true );
1277 }
1278
1279 void GEOM_Displayer::SetName( const char* theName )
1280 {
1281   myName = theName;
1282 }
1283
1284 void GEOM_Displayer::UnsetName()
1285 {
1286   myName = "";
1287 }
1288
1289 SalomeApp_Study* GEOM_Displayer::getStudy() const
1290 {
1291   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1292 }
1293
1294 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1295 {
1296   myIO = theIO;
1297 }
1298
1299 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1300 {
1301   myShape = theShape;
1302 }
1303
1304 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1305 {
1306   return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1307 }
1308
1309 int GEOM_Displayer::SetDisplayMode( const int theMode )
1310 {
1311   int aPrevMode = myDisplayMode;
1312   if ( theMode != -1 )
1313     myDisplayMode = theMode;
1314   else
1315   {
1316     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1317     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1318   }
1319   return aPrevMode;
1320 }
1321
1322 int GEOM_Displayer::GetDisplayMode() const
1323 {
1324   return myDisplayMode;
1325 }
1326
1327 int GEOM_Displayer::UnsetDisplayMode()
1328 {
1329   int aPrevMode = myDisplayMode;
1330   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1331   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1332   return aPrevMode;
1333 }
1334
1335 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1336 {
1337   int aHue = -1;
1338   int aTolerance = 64;
1339   int anIterations = 0;
1340   int aPeriod = 5;
1341
1342   while( 1 )
1343   {
1344     anIterations++;
1345     if( anIterations % aPeriod == 0 )
1346     {
1347       aTolerance /= 2;
1348       if( aTolerance < 1 )
1349         break;
1350     }
1351     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
1352
1353     aHue = (int)( 360.0 * rand() / RAND_MAX );
1354     //cout << "Hue = " << aHue << endl;
1355
1356     //cout << "Auto colors : ";
1357     bool ok = true;
1358     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1359     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1360     for( ; it != itEnd; ++it )
1361     {
1362       SALOMEDS::Color anAutoColor = *it;
1363       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1364
1365       int h, s, v;
1366       aQColor.getHsv( &h, &s, &v );
1367       //cout << h << " ";
1368       if( abs( h - aHue ) < aTolerance )
1369       {
1370         ok = false;
1371         //cout << "break (diff = " << abs( h - aHue ) << ")";
1372         break;
1373       }
1374     }
1375     //cout << endl;
1376
1377     if( ok )
1378       break;
1379   }
1380
1381   //cout << "Hue of the returned color = " << aHue << endl;
1382   QColor aColor;
1383   aColor.setHsv( aHue, 255, 255 );
1384
1385   SALOMEDS::Color aSColor;
1386   aSColor.R = (double)aColor.red() / 255.0;
1387   aSColor.G = (double)aColor.green() / 255.0;
1388   aSColor.B = (double)aColor.blue() / 255.0;
1389
1390   return aSColor;
1391 }