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