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