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