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