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