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