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