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