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