Salome HOME
PAL22319 : Salome is suspended,when we create new Local coordinate system
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 //
27 #include "GEOM_Displayer.h"
28
29 #include "GeometryGUI.h"
30
31 #include <GEOM_TypeFilter.h>
32 #include <GEOM_EdgeFilter.h>
33 #include <GEOM_FaceFilter.h>
34 #include <GEOM_CompoundFilter.h>
35 #include <GEOM_PreviewFilter.h>
36 #include <GEOM_LogicalFilter.h>
37 #include <GEOM_OCCFilter.h>
38
39 #include <GEOM_Actor.h>
40 #include <GEOM_AISShape.hxx>
41 #include <GEOM_AISVector.hxx>
42 #include <GEOM_AISTrihedron.hxx>
43 #include <GEOM_VTKTrihedron.hxx>
44
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewManager.h>
49 #include <SUIT_ResourceMgr.h>
50
51 #include <SalomeApp_Study.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_TypeFilter.h>
55 #include <SalomeApp_Tools.h>
56
57 #include <SALOME_ListIteratorOfListIO.hxx>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOME_Prs.h>
60
61 #include <SOCC_Prs.h>
62 #include <SOCC_ViewModel.h>
63
64 #include <SVTK_Prs.h>
65 #include <SVTK_ViewModel.h>
66
67 // OCCT Includes
68 #include <AIS_Drawer.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <Prs3d_IsoAspect.hxx>
71 #include <Prs3d_PointAspect.hxx>
72 #include <StdSelect_TypeOfEdge.hxx>
73 #include <StdSelect_TypeOfFace.hxx>
74 #include <TopoDS_Face.hxx>
75 #include <BRep_Tool.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_Axis2Placement.hxx>
78 #include <gp_Pln.hxx>
79 #include <TColStd_MapOfInteger.hxx>
80 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
81 #include <TopoDS_Iterator.hxx>
82 #include <Graphic3d_AspectMarker3d.hxx>
83 #include <TopTools_MapOfShape.hxx>
84 #include <TopTools_ListOfShape.hxx>
85 #include <TopTools_ListIteratorOfListOfShape.hxx>
86 #include <TopoDS.hxx>
87
88 // VTK Includes
89 #include <vtkActorCollection.h>
90 #include <vtkProperty.h>
91
92 // CORBA Headers
93 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
94
95 #include <GEOMImpl_Types.hxx>
96 #include <Graphic3d_HArray1OfBytes.hxx>
97
98
99 //================================================================
100 // Function : getActiveStudy
101 // Purpose  : Get active study, returns 0 if no open study frame
102 //================================================================
103 static inline SalomeApp_Study* getActiveStudy()
104 {
105   SUIT_Session* session = SUIT_Session::session();
106   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
107   if ( app )
108     return ( SalomeApp_Study* )app->activeStudy();
109   return 0;
110 }
111
112 static inline int getViewManagerId( SALOME_View* theViewFrame) {
113   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
114   SUIT_ViewManager* aViewMgr = 0;
115   if(aModel != 0) 
116     aViewMgr = aModel->getViewManager();
117   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
118 }
119
120 //================================================================
121 // Function : getTopAbsMode
122 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
123 //            one from GEOMImpl_Types.h
124 //================================================================
125 static inline int getTopAbsMode( const int implType )
126 {
127   switch ( implType )
128   {
129     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
130     case GEOM_SOLID     : return TopAbs_SOLID;
131     case GEOM_SHELL     : return TopAbs_SHELL;
132     case GEOM_FACE      : return TopAbs_FACE;
133     case GEOM_WIRE      : return TopAbs_WIRE;
134     case GEOM_EDGE      : return TopAbs_EDGE;
135     case GEOM_POINT     : return TopAbs_VERTEX;
136     default             : return -1;
137   }
138 }
139
140 static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
141 {
142   if ( shape.IsNull() )
143     return TopAbs_SHAPE;
144
145   int ret = shape.ShapeType();
146
147   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
148     TopoDS_Iterator it(shape, Standard_True, Standard_False);
149     for (; it.More(); it.Next()) {
150       TopoDS_Shape sub_shape = it.Value();
151       if ( sub_shape.IsNull() ) continue;
152       int stype = getMinMaxShapeType( sub_shape, ismin );
153       if ( stype == TopAbs_SHAPE ) continue;
154       if ( ismin && stype > ret )
155         ret = stype;
156       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
157         ret = stype;
158     }
159   }
160
161   return ret;
162 }
163
164 static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
165 {
166   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
167 }
168
169 //================================================================
170 // Function : getFilter
171 // Purpose  : Get filter corresponding to the type of object
172 //            from GEOMImpl_Types.h
173 //================================================================
174 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
175 {
176   SUIT_SelectionFilter* aFilter;
177
178   int aTopAbsMode = getTopAbsMode( theMode );
179   if ( aTopAbsMode != -1 )
180     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
181   else
182     switch ( theMode )
183       {
184       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
185       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
186
187       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
188       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
189       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
190       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
191       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
192       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
193
194       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
195
196       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
197       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
198
199       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
200       }
201
202   return aFilter;
203 }
204
205 //================================================================
206 // Function : getComplexFilter
207 // Purpose  : Get compound filter corresponding to the type of 
208 //            object from GEOMImpl_Types.h
209 //================================================================
210 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
211 {
212   GEOM_CompoundFilter* aFilter;
213   
214   if(aSubShapes != NULL ) {
215     aFilter = new GEOM_CompoundFilter(getStudy());
216     QList<int> aTopAbsTypes;
217     QList<int>::const_iterator it;
218     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
219       int topAbsMode = getTopAbsMode(*it);
220       if(topAbsMode != -1 )
221         aTopAbsTypes.append(topAbsMode);
222     }
223     aFilter->addSubTypes(aTopAbsTypes);
224   }
225   
226   return aFilter;
227 }
228
229 //================================================================
230 // Function : getEntry
231 // Purpose  :
232 //================================================================
233 static std::string getEntry( GEOM::GEOM_Object_ptr object )
234 {
235   SUIT_Session* session = SUIT_Session::session();
236   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
237   if ( app )
238   {
239     CORBA::String_var IOR = app->orb()->object_to_string( object );
240     if ( strcmp(IOR.in(), "") != 0 )
241     {
242       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
243       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
244       if ( SO )
245         return SO->GetID();
246     }
247   }
248   return "";
249 }
250
251 //================================================================
252 // Function : getName
253 // Purpose  :
254 //================================================================
255 static std::string getName( GEOM::GEOM_Object_ptr object )
256 {
257   SUIT_Session* session = SUIT_Session::session();
258   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
259   if ( app )
260   {
261     CORBA::String_var IOR = app->orb()->object_to_string( object );
262     if ( strcmp(IOR.in(), "") != 0 )
263     {
264       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
265       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
266
267       _PTR(GenericAttribute) anAttr;
268
269       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
270       {
271         _PTR(AttributeName) aNameAttr( anAttr );
272         return aNameAttr->Value();
273       }
274     }
275   }
276
277   return "";
278 }
279
280 //=================================================================
281 /*!
282  *  GEOM_Displayer::GEOM_Displayer
283  *  Constructor
284  */
285 //=================================================================
286 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
287 {
288   if( st )
289     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
290   else
291     myApp = 0;
292
293   /* Shading Color */
294   SUIT_Session* session = SUIT_Session::session();
295   SUIT_ResourceMgr* resMgr = session->resourceMgr();
296
297   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
298   myShadingColor = SalomeApp_Tools::color( col );
299
300   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
301   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
302   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
303   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
304   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
305
306   myColor = -1;
307   // This color is used for shape displaying. If it is equal -1 then
308   // default color is used.
309
310   myWidth = -1;
311   myType = -1;
312
313   myToActivate = true;
314   // This parameter is used for activisation/deactivisation of objects to be displayed
315
316   myViewFrame = 0;
317 }
318
319 //=================================================================
320 /*!
321  *  GEOM_Displayer::~GEOM_Displayer
322  *  Destructor
323  */
324 //=================================================================
325 GEOM_Displayer::~GEOM_Displayer()
326 {
327 }
328
329 //=================================================================
330 /*!
331  *  GEOM_Displayer::Display
332  *  Display interactive object in the current viewer
333  */
334 //=================================================================
335 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
336                              const bool updateViewer,
337                              SALOME_View* theViewFrame )
338 {
339   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
340   if ( vf )
341   {
342     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
343
344     if ( prs )
345     {
346       vf->BeforeDisplay( this, prs );
347       vf->Display( prs );
348       vf->AfterDisplay( this, prs );
349
350       if ( updateViewer )
351         vf->Repaint();
352
353       int aMgrId = getViewManagerId(vf);
354       SalomeApp_Study* aStudy = getStudy();
355       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
356       
357       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
358
359       delete prs;  // delete presentation because displayer is its owner
360     }
361   }
362 }
363
364 //=================================================================
365 /*!
366  *  GEOM_Displayer::Display
367  *  This overloaded Display() method can be useful for operations
368  *  not using dialog boxes.
369  */
370 //=================================================================
371 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
372 {
373   if ( theObj->_is_nil() )
374     return;
375
376   std::string entry = getEntry( theObj );
377   if ( entry != "" ) {
378     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
379             updateViewer);
380   }
381 }
382
383 //=================================================================
384 /*!
385  *  GEOM_Displayer::Erase
386  *  Erase interactive object in the current viewer
387  */
388 //=================================================================
389 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
390                             const bool forced,
391                             const bool updateViewer,
392                             SALOME_View* theViewFrame )
393 {
394   if ( theIO.IsNull() )
395     return;
396
397   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
398
399   if ( vf ) {
400     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
401     if ( prs ) {
402       vf->BeforeErase( this, prs );
403       vf->Erase( prs, forced );
404       vf->AfterErase( this, prs );
405       if ( updateViewer )
406         vf->Repaint();
407       delete prs;  // delete presentation because displayer is its owner
408       
409       int aMgrId = getViewManagerId(vf);
410       SalomeApp_Study* aStudy = getStudy();
411       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
412
413       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
414     }
415   }
416 }
417
418 //=================================================================
419 /*!
420  *  GEOM_Displayer::Erase
421  *  Erase geometry object in the current viewer
422  */
423 //=================================================================
424 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
425                             const bool forced,
426                             const bool updateViewer )
427 {
428   std::string entry = getEntry( theObj );
429   if ( entry != "" )
430   {
431     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
432           forced, updateViewer);
433   }
434 }
435
436 //=================================================================
437 /*!
438  *  GEOM_Displayer::Redisplay
439  *  Redisplay (erase and then display again) interactive object
440  *  in the current viewer
441  */
442 //=================================================================
443 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
444                                 const bool updateViewer )
445 {
446   // Remove the object permanently (<forced> == true)
447   SUIT_Session* ses = SUIT_Session::session();
448   SUIT_Application* app = ses->activeApplication();
449   if ( app )
450   {
451     SUIT_Desktop* desk = app->desktop();
452     QList<SUIT_ViewWindow*> wnds = desk->windows();
453     SUIT_ViewWindow* wnd;
454     QListIterator<SUIT_ViewWindow*> it( wnds );
455     while ( it.hasNext() && (wnd = it.next()) )
456     {
457       SUIT_ViewManager* vman = wnd->getViewManager();
458       if ( vman )
459       {
460         SUIT_ViewModel* vmodel = vman->getViewModel();
461         if ( vmodel )
462         {
463           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
464           if ( view )
465           {
466             if ( view->isVisible( theIO ) || view == GetActiveView() )
467             {
468               Erase( theIO, true, false, view );
469               Display( theIO, updateViewer, view );
470             }
471           }
472         }
473       }
474     }
475   }
476 }
477
478 //=================================================================
479 /*!
480  *  GEOM_Displayer::Display
481  *  Calls Display() method for each object in the given list
482  */
483 //=================================================================
484 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
485 {
486   SALOME_ListIteratorOfListIO Iter( theIOList );
487   for ( ; Iter.More(); Iter.Next() ) {
488     Display( Iter.Value(), false );
489   }
490   if ( updateViewer )
491     UpdateViewer();
492 }
493
494 //=================================================================
495 /*!
496  *  GEOM_Displayer::Erase
497  *  Calls Erase() method for each object in the given list
498  */
499 //=================================================================
500 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
501                             const bool forced,
502                             const bool updateViewer )
503 {
504   SALOME_ListIteratorOfListIO Iter( theIOList );
505   for ( ; Iter.More(); Iter.Next() )
506     Erase( Iter.Value(), forced, false );
507
508   if ( updateViewer )
509     UpdateViewer();
510 }
511
512 //=================================================================
513 /*!
514  *  GEOM_Displayer::Redisplay
515  *  Calls Redisplay() method for each object in the given list
516  */
517 //=================================================================
518 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
519 {
520   SALOME_ListIteratorOfListIO Iter( theIOList );
521   for ( ; Iter.More(); Iter.Next() )
522     Redisplay( Iter.Value(), false );
523
524   if ( updateViewer )
525     UpdateViewer();
526 }
527
528 //=================================================================
529 /*!
530  *  GEOM_Displayer::Update
531  *  Update OCC presentaion
532  *  [ Reimplemented from SALOME_Displayer ]
533  */
534 //=================================================================
535 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
536 {
537   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
538   if ( !occPrs )
539     return;
540   
541   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
542   {
543     TopoDS_Face aFace = TopoDS::Face( myShape );
544     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
545     if ( !aPlane.IsNull() )
546     {
547       gp_Ax3 aPos = aPlane->Pln().Position();
548       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
549
550       Handle(GEOM_AISTrihedron) aTrh;
551
552       if ( occPrs->IsNull() )
553       {
554         aTrh = new GEOM_AISTrihedron( aPlc );
555
556         if ( HasColor() )
557           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
558
559         if ( HasWidth() )
560           aTrh->SetWidth( GetWidth() );
561
562         if ( !myIO.IsNull() )
563         {
564           aTrh->setIO( myIO );
565           aTrh->SetOwner( myIO );
566         }
567
568         occPrs->AddObject( aTrh );
569       }
570       else
571       {
572         AIS_ListOfInteractive aList;
573         occPrs->GetObjects( aList );
574         AIS_ListIteratorOfListOfInteractive anIter( aList );
575         for ( ; anIter.More(); anIter.Next() )
576         {
577           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
578           if ( !aTrh.IsNull() )
579           {
580             aTrh->SetComponent( aPlc );
581             aTrh->SetToUpdate();
582           }
583         }
584       }
585
586       occPrs->SetToActivate( ToActivate() );
587     }
588   }
589   else
590   {
591     // if presentation is empty we try to create new one
592     if ( occPrs->IsNull() )
593     {
594       SalomeApp_Study* aStudy = getStudy();
595       if(!aStudy)
596         return;
597       if ( !myShape.IsNull() ) {
598
599         bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
600
601         QString anEntry;
602         int aMgrId = -1;
603         if(!myIO.IsNull()) {
604           aMgrId = getViewManagerId(myViewFrame);
605           anEntry = myIO->getEntry();
606         }
607         bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
608         bool useObjColor = false;
609         bool useObjMarker = false;
610         
611         PropMap aPropMap;
612         PropMap aDefPropMap;
613         
614         if(useStudy){
615           aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
616           aDefPropMap = getDefaultPropepryMap(SOCC_Viewer::Type());
617           bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
618                      
619           if(isDiff)
620             aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
621         }
622
623         //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
624         Handle(GEOM_AISShape) AISShape;
625         if (myType == GEOM_VECTOR)
626           AISShape = new GEOM_AISVector (myShape, "");
627         else {
628           if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
629               !TopoDS_Iterator(myShape).More())
630             return;// NPAL15983 (Bug when displaying empty groups)
631           AISShape = new GEOM_AISShape (myShape, "");
632         }
633         // Temporary staff: vertex must be infinite for correct visualization
634         AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
635
636         // Setup shape properties here ..., e.g. display mode, color, transparency, etc
637         if(useStudy) {
638           AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
639           AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
640
641           //Color property
642           if(aPropMap.contains(COLOR_PROP)) {
643             Quantity_Color  quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
644             AISShape->SetShadingColor( quant_col );
645           } else 
646             useObjColor = true;   
647         }else {
648           AISShape->SetDisplayMode( myDisplayMode );
649           AISShape->SetShadingColor( myShadingColor );
650         }
651         
652
653
654         // Set color and number for iso lines
655         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
656         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
657                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
658         Quantity_Color aColor = SalomeApp_Tools::color( col );
659         
660         //get the ISOS number, set transparency if need
661         int anUIsoNumber, aVIsoNumber;
662         if(useStudy) {
663           QString anIsos = aPropMap.value(ISOS_PROP).toString();
664           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
665           anUIsoNumber = uv[0].toInt();
666           aVIsoNumber = uv[1].toInt();
667           //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
668         } else {
669           anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
670           aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
671         }
672
673         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
674         anAspect->SetNumber( anUIsoNumber );
675         anAspect->SetColor( aColor );
676         AISShape->Attributes()->SetUIsoAspect( anAspect );
677
678         anAspect = AISShape->Attributes()->VIsoAspect();
679         anAspect->SetNumber( aVIsoNumber );
680         anAspect->SetColor( aColor );
681         AISShape->Attributes()->SetVIsoAspect( anAspect );
682
683         if ( HasColor() )
684         {
685           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
686           if ( onlyVertex )
687           {
688             if(aPropMap.contains(MARKER_TYPE_PROP)) {
689               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
690               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
691                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
692                 int  aTypeOfMarker = aList[0].toInt();
693                 double  aScaleOfMarker = aList[1].toDouble();
694                 anAspect->SetScale( aScaleOfMarker );
695                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
696                 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
697                 AISShape->Attributes()->SetPointAspect( anAspect );
698               } else { //Custom marker string contains "IdOfTexsture"
699                 int textureId = aList[0].toInt();
700                 Standard_Integer aWidth, aHeight;
701                 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight );
702                 if ( !aTexture.IsNull() ) {
703                   static int TextureId = 0;
704                   Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect((Quantity_NameOfColor)GetColor(),
705                                                                                    ++TextureId,
706                                                                                    aWidth, aHeight,                                                                                
707                                                                                    aTexture );
708                   AISShape->Attributes()->SetPointAspect( aTextureAspect );
709                   
710                 } else {
711                   useObjMarker = true;
712                 }
713               }
714             } else {
715               useObjMarker = true;
716             }       
717           }
718         }
719         else
720         {
721           if ( onlyVertex )
722           {
723             col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
724             aColor = SalomeApp_Tools::color( col );
725
726             if(aPropMap.contains(MARKER_TYPE_PROP)) {
727               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
728               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
729                 int  aTypeOfMarker = aList[0].toInt();
730                 double  aScaleOfMarker = aList[1].toDouble();
731                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
732                 anAspect->SetScale( aScaleOfMarker );
733                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
734                 anAspect->SetColor( aColor );
735                 AISShape->Attributes()->SetPointAspect( anAspect );
736               } else { //Custom marker string contains "IdOfTexsture"
737                 int textureId = aList[0].toInt();
738                 Standard_Integer aWidth, aHeight;
739                 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight );
740                 if ( !aTexture.IsNull() ) {
741                   static int TextureId = 0;
742                   Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aColor,
743                                                                                    ++TextureId,
744                                                                                    aWidth, aHeight,                                                                                
745                                                                                    aTexture );
746                   AISShape->Attributes()->SetPointAspect( aTextureAspect );
747                   
748                 } else {
749                   useObjMarker = true;
750                 }
751               }
752             } else {
753               useObjMarker = true;
754             }       
755           }
756           else
757           {
758             // Set line aspect
759             col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
760             aColor = SalomeApp_Tools::color( col );
761             
762             Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
763             anAspect->SetColor( aColor );
764             AISShape->Attributes()->SetLineAspect( anAspect );
765             
766             // Set unfree boundaries aspect
767             anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
768             anAspect->SetColor( aColor );
769             AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
770             
771             // Set free boundaries aspect
772             col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
773             aColor = SalomeApp_Tools::color( col );
774             
775             anAspect = AISShape->Attributes()->FreeBoundaryAspect();
776             anAspect->SetColor( aColor );
777             AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
778             
779             // Set wire aspect
780             col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
781             aColor = SalomeApp_Tools::color( col );
782             
783             anAspect = AISShape->Attributes()->WireAspect();
784             anAspect->SetColor( aColor );
785             AISShape->Attributes()->SetWireAspect( anAspect );
786             
787             // bug [SALOME platform 0019868]
788             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
789             //AISShape->SetOwnDeviationAngle( 10*PI/180 );
790
791             // IMP 0020626
792             double aDC = 0;
793             if(useStudy) {
794               aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
795             }
796             else {
797               aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
798             }
799
800             aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
801             AISShape->SetOwnDeviationCoefficient(aDC);
802           }
803         }
804
805         if ( HasWidth() )
806           AISShape->SetWidth( GetWidth() );
807
808         if ( !myIO.IsNull() )
809         {
810           AISShape->setIO( myIO );
811           AISShape->SetOwner( myIO );
812         }
813         else if ( !myName.empty() )
814         {
815           // Workaround to allow selection of temporary objects
816           static int tempId = 0;
817           char buf[50];
818           sprintf( buf, "TEMP_%d", tempId++ );
819           Handle( SALOME_InteractiveObject ) anObj =
820             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
821           AISShape->setIO( anObj );
822           AISShape->SetOwner( anObj );
823         }
824
825         Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
826         if ( !anIO.IsNull() ) {
827           _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
828           if ( SO ) {
829             // get CORBA reference to data object
830             CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
831             if ( !CORBA::is_nil( object ) ) {
832               // downcast to GEOM object
833               GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
834               bool hasColor = false;
835               SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
836               if( hasColor && useObjColor) {
837                 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
838                 AISShape->SetColor( aQuanColor );
839                 AISShape->SetShadingColor( aQuanColor );
840                 if ( onlyVertex ) {
841                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
842                   anAspect->SetColor( aQuanColor );
843                   anAspect->SetScale( myScaleOfMarker );
844                   anAspect->SetTypeOfMarker( myTypeOfMarker );
845                   AISShape->Attributes()->SetPointAspect( anAspect );
846                 }
847               } else if(!hasColor) {
848                 //In case if color wasn't defined in the property map of the object 
849                 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
850                 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
851                 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
852                 AISShape->SetShadingColor( aQuanColor );
853                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
854               }
855
856               // ... marker type
857               if(useObjMarker) {
858                 GEOM::marker_type aType = aGeomObject->GetMarkerType();
859                 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
860                 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
861                   Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
862                   double aMSize = ((int)aSize+1)*0.5;
863                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
864                   anAspect->SetScale( aMSize );
865                   anAspect->SetTypeOfMarker( aMType );
866                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
867                   if ( hasColor )
868                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
869                   anAspect->SetColor( aQuanColor );
870                   AISShape->Attributes()->SetPointAspect( anAspect );
871                 }
872                 else if ( aType == GEOM::MT_USER ) {
873                   int aTextureId = aGeomObject->GetMarkerTexture();
874                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
875                   if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
876                   Standard_Integer aWidth, aHeight;
877                   Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight );
878                   if ( !aTexture.IsNull() ) {
879                     static int TextureId = 0;
880                     Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor,
881                                                                                      ++TextureId,
882                                                                                      aWidth, aHeight,
883                                                                                      aTexture );
884                     AISShape->Attributes()->SetPointAspect( aTextureAspect );
885                   }
886                 } else { //Use marker from the preferences
887                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
888                   anAspect->SetScale( myScaleOfMarker );
889                   anAspect->SetTypeOfMarker( myTypeOfMarker );
890                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
891                   if ( hasColor )
892                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
893                   anAspect->SetColor( aQuanColor );
894                   AISShape->Attributes()->SetPointAspect( anAspect );           
895                 }
896               }
897             }
898           }
899         }
900         // AISShape->SetName(???); ??? necessary to set name ???
901         occPrs->AddObject( AISShape );
902
903         // In accordance with ToActivate() value object will be activated/deactivated
904         // when it will be displayed
905         occPrs->SetToActivate( ToActivate() );
906       }
907     }
908     // if presentation is found -> set again shape for it
909     else
910     {
911       if ( !myShape.IsNull() )
912       {
913         AIS_ListOfInteractive IOList;
914         occPrs->GetObjects( IOList );
915         AIS_ListIteratorOfListOfInteractive Iter( IOList );
916         for ( ; Iter.More(); Iter.Next() )
917         {
918           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
919           if ( AISShape.IsNull() )
920             continue;
921           if ( AISShape->Shape() != myShape )
922           {
923             AISShape->Set( myShape );
924             AISShape->UpdateSelection();
925             AISShape->SetToUpdate();
926           }
927           if ( !myIO.IsNull() )
928           {
929             AISShape->setIO( myIO );
930             AISShape->SetOwner( myIO );
931           }
932         }
933       }
934     }
935   }
936 }
937
938 //=================================================================
939 /*!
940  *  GEOM_Displayer::Update
941  *  Update VTK presentaion
942  *  [ Reimplemented from SALOME_Displayer ]
943  */
944 //=================================================================
945 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
946 {
947   SalomeApp_Study* aStudy = getStudy();
948   int aMgrId = -1;
949   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
950
951   if ( !vtkPrs || myShape.IsNull() || !aStudy)
952     return;
953   
954   bool useStudy = false;
955   PropMap aPropMap;
956
957   vtkActorCollection* theActors = 0;
958
959   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
960     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
961     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
962     
963     if ( HasColor() ) {
964       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
965       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
966     }
967
968     Handle(Geom_Plane) aPlane =
969       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
970     if ( aPlane.IsNull() )
971       return;
972
973     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
974     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
975     
976     //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
977     //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
978
979     vtkPrs->AddObject( aTrh );
980
981     theActors = vtkActorCollection::New();
982     theActors->AddItem( aTrh );
983   }
984   else {
985     PropMap aDefPropMap = getDefaultPropepryMap(SVTK_Viewer::Type());
986
987     QString anEntry;
988     if(!myIO.IsNull()) {
989       aMgrId = getViewManagerId(myViewFrame);
990       anEntry = myIO->getEntry();
991     }
992     useStudy = !anEntry.isEmpty() && aMgrId != -1;
993
994     
995     theActors = vtkActorCollection::New();
996     GEOM_Actor* aGeomActor = GEOM_Actor::New();
997     aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
998     theActors->AddItem(aGeomActor);
999     aGeomActor->Delete();
1000     
1001     if(useStudy){
1002       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1003       bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
1004       if(isDiff)
1005         aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
1006     }
1007   }
1008
1009   theActors->InitTraversal();
1010   
1011   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1012   
1013   vtkProperty* aProp = 0;
1014   
1015   if ( HasColor() || HasWidth() )
1016   {
1017     aProp = vtkProperty::New();
1018     aProp->SetRepresentationToWireframe();
1019   }
1020
1021   if ( HasColor() )
1022   {
1023     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1024     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1025   }
1026
1027   if ( HasWidth() )
1028   {
1029     aProp->SetLineWidth( GetWidth() );
1030   }
1031
1032   while ( anActor != NULL )
1033   {
1034     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1035
1036     GActor->setIO( myIO );
1037
1038     if ( aProp )
1039     {
1040       GActor->SetProperty( aProp );
1041       GActor->SetPreviewProperty( aProp );
1042     }
1043     
1044     GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1045     if ( aGeomGActor != 0 )
1046       {
1047         if ( aProp ) {
1048           aGeomGActor->SetShadingProperty( aProp );
1049           aGeomGActor->SetWireframeProperty( aProp );
1050         }
1051         int aIsos[2]= { 1, 1 };
1052         if(useStudy) {
1053           QString anIsos = aPropMap.value(ISOS_PROP).toString();
1054           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
1055           aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1056           aGeomGActor->SetNbIsos(aIsos);
1057           aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1058           aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1059           aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1060           aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble()); 
1061
1062           vtkFloatingPointType aColor[3] = {1.,0.,0.};
1063           if(aPropMap.contains(COLOR_PROP)) {
1064             QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1065             aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1066           } else { //Get Color from geom object
1067             Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1068             if ( !anIO.IsNull() ) {
1069               _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1070               if ( SO ) {
1071                 // get CORBA reference to data object
1072                 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1073                 if ( !CORBA::is_nil( object ) ) {
1074                   // downcast to GEOM object
1075                   GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1076                   bool hasColor = false;
1077                   SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1078                   if(hasColor) {
1079                     aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1080                   } else {
1081                     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1082                     if(aResMgr) {
1083                       QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1084                       aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1085                       aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1086                     }
1087                   }
1088                 }
1089               }
1090             }
1091           }
1092           aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1093         }
1094       }
1095
1096     if ( myToActivate )
1097       GActor->PickableOn();
1098     else
1099       GActor->PickableOff();
1100
1101     vtkPrs->AddObject( GActor );
1102
1103     anActor = (vtkActor*)theActors->GetNextActor();
1104   }
1105
1106   if ( aProp )
1107     aProp->Delete();
1108
1109   theActors->Delete();
1110 }
1111
1112 //=================================================================
1113 /*!
1114  *  GEOM_Displayer::BuildPrs
1115  *  Build presentation accordint to the current viewer type
1116  */
1117 //=================================================================
1118 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1119 {
1120   if ( theObj->_is_nil() )
1121     return 0;
1122
1123   myViewFrame = GetActiveView();
1124   if ( myViewFrame == 0 )
1125     return 0;
1126
1127   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1128   if ( aPrs == 0 )
1129     return 0;
1130
1131   internalReset();
1132   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1133   myType = theObj->GetType();
1134
1135   // Update presentation
1136   UpdatePrs( aPrs );
1137
1138   return aPrs;
1139 }
1140
1141 //=================================================================
1142 /*!
1143  *  GEOM_Displayer::BuildPrs
1144  *  Build presentation accordint to the current viewer type
1145  */
1146 //=================================================================
1147 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1148 {
1149   myViewFrame = GetActiveView();
1150   if ( theShape.IsNull() || myViewFrame == 0 )
1151     return 0;
1152
1153   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1154   if ( aPrs == 0 )
1155     return 0;
1156
1157   internalReset();
1158   setShape( theShape );
1159   myType = -1;
1160
1161   UpdatePrs( aPrs );
1162
1163   return aPrs;
1164 }
1165
1166 //=================================================================
1167 /*!
1168  *  GEOM_Displayer::buildPresentation
1169  *  Builds/finds object's presentation for the current viewer
1170  *  Calls corresponding Update() method by means of double dispatch
1171  *  [ internal ]
1172  */
1173 //=================================================================
1174 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1175                                                SALOME_View* theViewFrame )
1176 {
1177   SALOME_Prs* prs = 0;
1178   internalReset();
1179
1180   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1181
1182   if ( myViewFrame )
1183   {
1184     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1185     if ( prs )
1186     {
1187       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1188       theIO->setEntry( entry.toLatin1().constData() );
1189       if ( !theIO.IsNull() )
1190       {
1191         // set interactive object
1192         setIO( theIO );
1193         //  Find SOBject (because shape should be published previously)
1194         SUIT_Session* session = SUIT_Session::session();
1195         SUIT_Application* app = session->activeApplication();
1196         if ( app )
1197         {
1198           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1199           if ( study )
1200           {
1201             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1202             if ( SO )
1203             {
1204               // get CORBA reference to data object
1205               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1206               if ( !CORBA::is_nil( object ) )
1207               {
1208                 // downcast to GEOM object
1209                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1210                 if ( !GeomObject->_is_nil() )
1211                 {
1212                   // finally set shape
1213                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1214                   myType = GeomObject->GetType();
1215                 }
1216               }
1217             }
1218           }
1219         }
1220       }
1221       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1222     }
1223   }
1224   return prs;
1225 }
1226
1227 //=================================================================
1228 /*!
1229  *  GEOM_Displayer::buildSubshapePresentation
1230  *  Builds/finds object's presentation for the current viewer
1231  *  Calls corresponding Update() method by means of double dispatch
1232  *  For not published objects (for Mantis issue 0020435)
1233  */
1234 //=================================================================
1235 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1236                                                       const QString& entry,
1237                                                       SALOME_View* theViewFrame)
1238 {
1239   SALOME_Prs* prs = 0;
1240   internalReset();
1241
1242   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1243
1244   if (myViewFrame)
1245   {
1246     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1247     if (prs)
1248     {
1249       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1250       theIO->setEntry(entry.toLatin1().constData());
1251       if (!theIO.IsNull())
1252       {
1253         // set interactive object
1254         setIO(theIO);
1255         // finally set shape
1256         setShape(aShape);
1257         myType = GEOM_SUBSHAPE;
1258       }
1259       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1260     }
1261   }
1262   return prs;
1263 }
1264
1265 //=================================================================
1266 /*!
1267  *  GEOM_Displayer::internalReset
1268  *  Resets internal data
1269  *  [internal]
1270  */
1271 //=================================================================
1272 void GEOM_Displayer::internalReset()
1273 {
1274   myIO.Nullify();
1275   myShape.Nullify();
1276 }
1277
1278 //=================================================================
1279 /*!
1280  *  GEOM_Displayer::LocalSelection
1281  *  Activate selection of CAD shapes with activisation of selection
1282  *  of their sub-shapes (with opened local context for OCC viewer)
1283  */
1284 //=================================================================
1285 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1286 {
1287   SUIT_Session* session = SUIT_Session::session();
1288   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1289   if ( !app )
1290     return;
1291
1292   LightApp_SelectionMgr* sm = app->selectionMgr();
1293
1294   // remove all filters from selection
1295   sm->clearFilters();
1296
1297   SALOME_View* vf = GetActiveView();
1298   if ( vf ) {
1299     if (!theIO.IsNull() && !vf->isVisible(theIO))
1300       Display(theIO);
1301     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1302     vf->LocalSelection( prs, theMode );
1303     delete prs;  // delete presentation because displayer is its owner
1304   }
1305 }
1306
1307 //=================================================================
1308 /*!
1309  *  GEOM_Displayer::globalSelection
1310  *  Activate selection of CAD shapes without activisation of selection
1311  *  of their sub-shapes (without opened local context for OCC viewer)
1312  */
1313 //=================================================================
1314 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1315 {
1316   TColStd_MapOfInteger aModes;
1317   aModes.Add( theMode );
1318   GlobalSelection( aModes, update );
1319 }
1320
1321 //=================================================================
1322 /*!
1323  *  GEOM_Displayer::globalSelection
1324  *  Activate selection of CAD shapes without activisation of selection
1325  *  of their sub-shapes (without opened local context for OCC viewer)
1326  */
1327 //=================================================================
1328 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1329                                       const bool update, const QList<int>* theSubShapes )
1330 {
1331   SUIT_Session* session = SUIT_Session::session();
1332   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1333   if ( !app )
1334     return;
1335
1336   SALOME_View* vf = GetActiveView();
1337   if ( vf == 0 )
1338     return;
1339
1340   // Close local context
1341   vf->GlobalSelection( update );
1342
1343   // Set selection filters in accordance with current mode
1344   LightApp_SelectionMgr* sm = app->selectionMgr();
1345   if ( !sm )
1346     return;
1347
1348   // Remove from selection temporary objects if necessary
1349   if ( !theModes.Contains( GEOM_PREVIEW ) )
1350     clearTemporary( sm );
1351
1352   //@ aSel->ClearIndex();
1353
1354   sm->clearFilters();
1355
1356   // Remove filters from AIS_InteractiveContext
1357   Handle(AIS_InteractiveContext) ic;
1358   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1359   if ( viewer )
1360     {
1361       ic = viewer->getAISContext();
1362       if ( !ic.IsNull() )
1363         ic->RemoveFilters();
1364     }
1365
1366   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1367     return;
1368
1369   SUIT_SelectionFilter* aFilter;
1370   if ( theModes.Extent() == 1 )
1371     {
1372       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1373       
1374       if ( aMode == GEOM_COMPOUNDFILTER )
1375         aFilter = getComplexFilter( theSubShapes );
1376       else    
1377         aFilter = getFilter( aMode );
1378     }
1379   else if ( theModes.Extent() > 1 )
1380     {
1381       TColStd_MapOfInteger aTopAbsModes;
1382       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1383       QList<SUIT_SelectionFilter*> aListOfFilters;
1384       for ( ; anIter.More(); anIter.Next() )
1385         {
1386           SUIT_SelectionFilter* aFilter;
1387           int aMode = anIter.Key();
1388           if ( aMode == GEOM_COMPOUNDFILTER )
1389             aFilter = getComplexFilter( theSubShapes );
1390           else    
1391             aFilter = getFilter( aMode );
1392
1393           if ( aFilter )
1394             aListOfFilters.append( aFilter );
1395         }
1396
1397       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1398     }
1399   else
1400     return;
1401
1402   if ( aFilter )
1403     {
1404       sm->installFilter( aFilter );
1405       if ( !ic.IsNull() )
1406         {
1407           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1408           ic->AddFilter( anOCCFilter );
1409         }
1410     }
1411 }
1412
1413 //=================================================================
1414 /*!
1415  *  GEOM_Displayer::LocalSelection
1416  *  Activate selection of CAD shapes with activisation of selection
1417  *  of their sub-shapes (with opened local context for OCC viewer)
1418  */
1419 //=================================================================
1420 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1421 {
1422   SALOME_ListIteratorOfListIO Iter( theIOList );
1423   for ( ; Iter.More(); Iter.Next() )
1424     LocalSelection( Iter.Value(), theMode );
1425 }
1426
1427 //=================================================================
1428 /*!
1429  *  GEOM_Displayer::BeforeDisplay
1430  *  Called before displaying of pars. Close local context
1431  *  [ Reimplemented from SALOME_Displayer ]
1432  */
1433 //=================================================================
1434 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1435 {
1436   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1437   if ( vf )
1438   {
1439     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1440     if ( !ic.IsNull() )
1441     {
1442       if ( ic->HasOpenedContext() )
1443       ic->CloseAllContexts();
1444     }
1445   }
1446 }
1447
1448 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1449 {
1450   SalomeApp_Study* aStudy = getStudy();
1451   if (!aStudy) return;
1452   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1453   if ( vf && !p->IsNull() ) {
1454     int aMgrId = getViewManagerId( vf );
1455     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1456     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1457     if ( !ic.IsNull() && prs ) {
1458       AIS_ListOfInteractive objects;
1459       prs->GetObjects( objects );
1460       AIS_ListIteratorOfListOfInteractive it( objects );
1461       for ( ; it.More(); it.Next() ) {
1462         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1463         if ( sh.IsNull() ) continue;
1464         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1465         if ( IO.IsNull() ) continue;
1466         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1467         if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1468           double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1469           ic->SetTransparency( sh, transparency, true );
1470         }
1471       }
1472     }
1473   }
1474 }
1475
1476 //=================================================================
1477 /*!
1478  *  GEOM_Displayer::SetColor
1479  *  Set color for shape displaying. If it is equal -1 then default color is used.
1480  *  Available values are from Quantity_NameOfColor enumeration
1481  */
1482 //=================================================================
1483 void GEOM_Displayer::SetColor( const int color )
1484 {
1485   if ( color == -1 )
1486     UnsetColor();
1487   else
1488   {
1489     myColor = color;
1490     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1491   }
1492 }
1493
1494 int GEOM_Displayer::GetColor() const
1495 {
1496   return myColor;
1497 }
1498
1499 bool GEOM_Displayer::HasColor() const
1500 {
1501   return myColor != -1;
1502 }
1503
1504 void GEOM_Displayer::UnsetColor()
1505 {
1506   myColor = -1;
1507   
1508   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1509   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1510   myShadingColor = SalomeApp_Tools::color( col );
1511 }
1512
1513 //=================================================================
1514 /*!
1515  *  GEOM_Displayer::SetWidth
1516  *  Set width of shape displaying. If it is equal -1 then default width is used.
1517  */
1518 //=================================================================
1519 void GEOM_Displayer::SetWidth( const double width )
1520 {
1521   myWidth = width;
1522 }
1523
1524 double GEOM_Displayer::GetWidth() const
1525 {
1526   return myWidth;
1527 }
1528
1529 bool GEOM_Displayer::HasWidth() const
1530 {
1531   return myWidth != -1;
1532 }
1533
1534 void GEOM_Displayer::UnsetWidth()
1535 {
1536   myWidth = -1;
1537 }
1538
1539 //=================================================================
1540 /*!
1541  *  GEOM_Displayer::SetToActivate
1542  *  This method is used for activisation/deactivisation of objects to be displayed
1543  */
1544 //=================================================================
1545 void GEOM_Displayer::SetToActivate( const bool toActivate )
1546 {
1547   myToActivate = toActivate;
1548 }
1549 bool GEOM_Displayer::ToActivate() const
1550 {
1551   return myToActivate;
1552 }
1553
1554 //=================================================================
1555 /*!
1556  *  GEOM_Displayer::clearTemporary
1557  *  Removes from selection temporary objects
1558  */
1559 //=================================================================
1560 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1561 {
1562   SALOME_ListIO selected, toSelect;
1563   theSelMgr->selectedObjects( selected );
1564
1565   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1566     Handle(SALOME_InteractiveObject) io = it.Value();
1567     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1568       toSelect.Append( it.Value() );
1569   }
1570
1571   theSelMgr->setSelectedObjects( toSelect, true );
1572 }
1573
1574 void GEOM_Displayer::SetName( const char* theName )
1575 {
1576   myName = theName;
1577 }
1578
1579 void GEOM_Displayer::UnsetName()
1580 {
1581   myName = "";
1582 }
1583
1584 SalomeApp_Study* GEOM_Displayer::getStudy() const
1585 {
1586   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1587 }
1588
1589 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1590 {
1591   myIO = theIO;
1592 }
1593
1594 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1595 {
1596   myShape = theShape;
1597 }
1598
1599 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1600 {
1601   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1602 }
1603
1604 int GEOM_Displayer::SetDisplayMode( const int theMode )
1605 {
1606   int aPrevMode = myDisplayMode;
1607   if ( theMode != -1 )
1608     myDisplayMode = theMode;
1609   else
1610   {
1611     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1612     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1613   }
1614   return aPrevMode;
1615 }
1616
1617 int GEOM_Displayer::GetDisplayMode() const
1618 {
1619   return myDisplayMode;
1620 }
1621
1622 int GEOM_Displayer::UnsetDisplayMode()
1623 {
1624   int aPrevMode = myDisplayMode;
1625   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1626   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1627   return aPrevMode;
1628 }
1629
1630 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1631 {
1632   int aHue = -1;
1633   int aTolerance = 64;
1634   int anIterations = 0;
1635   int aPeriod = 5;
1636
1637   while( 1 )
1638   {
1639     anIterations++;
1640     if( anIterations % aPeriod == 0 )
1641     {
1642       aTolerance /= 2;
1643       if( aTolerance < 1 )
1644         break;
1645     }
1646     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1647
1648     aHue = (int)( 360.0 * rand() / RAND_MAX );
1649     //std::cout << "Hue = " << aHue << std::endl;
1650
1651     //std::cout << "Auto colors : ";
1652     bool ok = true;
1653     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1654     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1655     for( ; it != itEnd; ++it )
1656     {
1657       SALOMEDS::Color anAutoColor = *it;
1658       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1659
1660       int h, s, v;
1661       aQColor.getHsv( &h, &s, &v );
1662       //std::cout << h << " ";
1663       if( abs( h - aHue ) < aTolerance )
1664       {
1665         ok = false;
1666         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1667         break;
1668       }
1669     }
1670     //std::cout << std::endl;
1671
1672     if( ok )
1673       break;
1674   }
1675
1676   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1677   QColor aColor;
1678   aColor.setHsv( aHue, 255, 255 );
1679
1680   SALOMEDS::Color aSColor;
1681   aSColor.R = (double)aColor.red() / 255.0;
1682   aSColor.G = (double)aColor.green() / 255.0;
1683   aSColor.B = (double)aColor.blue() / 255.0;
1684
1685   return aSColor;
1686 }
1687
1688
1689
1690 PropMap GEOM_Displayer::getDefaultPropepryMap(const QString& viewer_type){
1691   PropMap aDefaultMap;
1692   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();    
1693   //1. Visibility 
1694   aDefaultMap.insert(VISIBILITY_PROP , 1);
1695
1696   //2. Nb Isos
1697   int anUIsoNumber;
1698   int aVIsoNumber;
1699   if(viewer_type == SOCC_Viewer::Type()) {
1700     anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1701     aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1702   } else if( viewer_type==SVTK_Viewer::Type()) {
1703     anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1704     aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1705   }
1706   QString anIsos("%1%2%3");
1707   anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1708   aDefaultMap.insert(ISOS_PROP , anIsos);
1709
1710   //3. Transparency
1711   aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1712
1713   //4. Display Mode
1714   aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1715
1716   //5. Vector Mode
1717   aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1718   
1719   //6. Color
1720   QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1721   aDefaultMap.insert( COLOR_PROP , col);
1722     
1723   //7. Deflection Coeff
1724   double aDC;
1725
1726   if(viewer_type == SOCC_Viewer::Type()) {
1727     aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1728   } else if( viewer_type==SVTK_Viewer::Type()) {
1729     aDC = 0.001;
1730   }
1731
1732   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1733
1734   return aDefaultMap;
1735 }
1736
1737 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1738   int nbInserted = 0;
1739   if(!theOrigin.contains(VISIBILITY_PROP)) {
1740     theOrigin.insert(VISIBILITY_PROP, 0);
1741     nbInserted++;
1742   }
1743   if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1744     theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1745     nbInserted++;
1746   }
1747   if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1748     theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1749     nbInserted++;
1750   }
1751   if(!theOrigin.contains(ISOS_PROP)) {
1752     theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1753     nbInserted++;
1754   }
1755   if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1756     theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1757     nbInserted++;
1758   }
1759   if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1760     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1761     nbInserted++;
1762   }
1763   return (nbInserted > 0);
1764 }
1765
1766
1767 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1768   SALOMEDS::Color aSColor;
1769   hasColor = false;
1770
1771   SUIT_Session* session = SUIT_Session::session();
1772   SUIT_Application* app = session->activeApplication();
1773
1774   if ( app && !theGeomObject->_is_nil()) {
1775     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1776     
1777     if ( study ) {
1778       aSColor = theGeomObject->GetColor();
1779       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1780       if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1781         GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1782         GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1783         GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1784         if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1785           {
1786             QList<SALOMEDS::Color> aReservedColors;
1787             
1788             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1789             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1790             if ( strcmp(IOR.in(), "") != 0 )
1791               {
1792                 _PTR(Study) aStudy = study->studyDS();
1793                 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1794                 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1795                 for( ; it->More(); it->Next() )
1796                   {
1797                     _PTR(SObject) aChildSObject( it->Value() );
1798                     GEOM::GEOM_Object_var aChildObject =
1799                       GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1800                     if( CORBA::is_nil( aChildObject ) )
1801                       continue;
1802                     
1803                     if( aChildObject->GetType() != GEOM_GROUP )
1804                       continue;
1805                     
1806                     SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1807                     aReservedColors.append( aReservedColor );
1808                   }
1809               }
1810             
1811             aSColor = getUniqueColor( aReservedColors );
1812             hasColor = true;
1813           }
1814       }
1815     }
1816   }
1817   return aSColor;
1818 }