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