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