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