Salome HOME
EDF 2281: Missing doc file and some translations
[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           MESSAGE("myDisplayMode = "<< myDisplayMode)
687           AISShape->SetDisplayMode( myDisplayMode );
688           AISShape->SetShadingColor( myShadingColor );
689         }
690
691         // Set color and number for iso lines
692         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
693         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
694                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
695         Quantity_Color aColor = SalomeApp_Tools::color( col );
696
697         //get the ISOS number, set transparency if need
698         int anUIsoNumber, aVIsoNumber;
699         if(useStudy) {
700           QString anIsos = aPropMap.value(ISOS_PROP).toString();
701           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
702           anUIsoNumber = uv[0].toInt();
703           aVIsoNumber = uv[1].toInt();
704           AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
705         } else {
706           anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
707           aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
708         }
709
710         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
711         anAspect->SetNumber( anUIsoNumber );
712         anAspect->SetColor( aColor );
713
714         if(HasIsosWidth())
715           anAspect->SetWidth( GetIsosWidth() );
716         AISShape->Attributes()->SetUIsoAspect( anAspect );
717         anAspect = AISShape->Attributes()->VIsoAspect();
718         anAspect->SetNumber( aVIsoNumber );
719         if(HasIsosWidth())
720           anAspect->SetWidth( GetIsosWidth() );
721         anAspect->SetColor( aColor );
722         AISShape->Attributes()->SetVIsoAspect( anAspect );
723
724         if ( HasColor() )
725         {
726           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
727           if ( onlyVertex )
728           {
729             if(aPropMap.contains(MARKER_TYPE_PROP)) {
730               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
731               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
732                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
733                 int  aTypeOfMarker = aList[0].toInt();
734                 double  aScaleOfMarker = aList[1].toDouble();
735                 anAspect->SetScale( aScaleOfMarker );
736                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
737                 anAspect->SetColor((Quantity_NameOfColor)GetColor());
738                 AISShape->Attributes()->SetPointAspect(anAspect);
739               } else { //Custom marker string contains "IdOfTexsture"
740                 int textureId = aList[0].toInt();
741                 Standard_Integer aWidth, aHeight;
742 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
743                 Handle(TColStd_HArray1OfByte) aTexture =
744 #else
745                 Handle(Graphic3d_HArray1OfBytes) aTexture =
746 #endif
747                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
748                 if (!aTexture.IsNull()) {
749                   static int TextureId = 0;
750                   Handle(Prs3d_PointAspect) aTextureAspect =
751                     new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
752                                            ++TextureId,
753                                            aWidth, aHeight,
754                                            aTexture);
755                   AISShape->Attributes()->SetPointAspect(aTextureAspect);
756                 } else {
757                   useObjMarker = true;
758                 }
759               }
760             } else {
761               useObjMarker = true;
762             }
763           }
764         }        
765         else
766         {
767           if ( onlyVertex )
768           {
769             col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
770             aColor = SalomeApp_Tools::color( col );
771
772             if(aPropMap.contains(MARKER_TYPE_PROP)) {
773               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
774               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
775                 int  aTypeOfMarker = aList[0].toInt();
776                 double  aScaleOfMarker = aList[1].toDouble();
777                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
778                 anAspect->SetScale( aScaleOfMarker );
779                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
780                 anAspect->SetColor( aColor );
781                 AISShape->Attributes()->SetPointAspect( anAspect );
782               } else { //Custom marker string contains "IdOfTexsture"
783                 int textureId = aList[0].toInt();
784                 Standard_Integer aWidth, aHeight;
785 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
786                 Handle(TColStd_HArray1OfByte) aTexture =
787 #else
788                 Handle(Graphic3d_HArray1OfBytes) aTexture =
789 #endif
790                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
791                 if (!aTexture.IsNull()) {
792                   static int TextureId = 0;
793                   Handle(Prs3d_PointAspect) aTextureAspect =
794                     new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
795                   AISShape->Attributes()->SetPointAspect( aTextureAspect );
796                 } else {
797                   useObjMarker = true;
798                 }
799               }
800             } else {
801               useObjMarker = true;
802             }
803           }
804           else {
805             // Set line aspect
806             col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
807             aColor = SalomeApp_Tools::color( col );
808
809             Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
810             anAspect->SetColor( aColor );
811             AISShape->Attributes()->SetLineAspect( anAspect );
812
813             // Set unfree boundaries aspect
814             anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
815             anAspect->SetColor( aColor );
816             AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
817             AISShape->storeBoundaryColors();
818
819             // Set free boundaries aspect
820             col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
821             aColor = SalomeApp_Tools::color( col );
822
823             anAspect = AISShape->Attributes()->FreeBoundaryAspect();
824             anAspect->SetColor( aColor );
825             AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
826
827             // Set wire aspect
828             col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
829             aColor = SalomeApp_Tools::color( col );
830
831             anAspect = AISShape->Attributes()->WireAspect();
832             anAspect->SetColor( aColor );
833             AISShape->Attributes()->SetWireAspect( anAspect );
834
835             // Set color for edges in shading
836             col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
837             aColor = SalomeApp_Tools::color( col );
838             AISShape->SetEdgesInShadingColor( aColor );
839             
840             // bug [SALOME platform 0019868]
841             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
842             //AISShape->SetOwnDeviationAngle( 10*PI/180 );
843
844             // IMP 0020626
845             double aDC = 0;
846             if(useStudy) {
847               aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
848               SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
849               SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
850             }
851             else {
852               aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
853             }
854
855             aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
856             AISShape->SetOwnDeviationCoefficient(aDC);
857           }
858         }
859                 
860         if ( HasTexture() )
861         {
862           AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
863           AISShape->SetTextureMapOn();
864           AISShape->DisableTextureModulate();
865           AISShape->SetDisplayMode(3);
866         }
867           
868         if ( HasWidth() )
869           AISShape->SetWidth( GetWidth() );
870
871         if ( !myIO.IsNull() )
872         {
873           AISShape->setIO( myIO );
874           AISShape->SetOwner( myIO );
875         }
876         else if ( !myName.empty() )
877         {
878           // Workaround to allow selection of temporary objects
879           static int tempId = 0;
880           char buf[50];
881           sprintf( buf, "TEMP_%d", tempId++ );
882           Handle( SALOME_InteractiveObject ) anObj =
883             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
884           AISShape->setIO( anObj );
885           AISShape->SetOwner( anObj );
886         }
887
888         Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
889         if ( !anIO.IsNull() ) {
890           _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
891           if ( SO ) {
892             // get CORBA reference to data object
893             CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
894             if ( !CORBA::is_nil( object ) ) {
895               // downcast to GEOM object
896               GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
897               bool hasColor = false;
898               SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
899               if( hasColor && useObjColor) {
900                 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
901                 AISShape->SetColor( aQuanColor );
902                 AISShape->SetShadingColor( aQuanColor );
903                 if ( onlyVertex ) {
904                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
905                   anAspect->SetColor( aQuanColor );
906                   anAspect->SetScale( myScaleOfMarker );
907                   anAspect->SetTypeOfMarker( myTypeOfMarker );
908                   AISShape->Attributes()->SetPointAspect( anAspect );
909                 }
910                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
911               } else if( !hasColor ) {
912                 //In case if color wasn't defined in the property map of the object
913                 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
914                 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
915                 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
916                 AISShape->SetShadingColor( aQuanColor );
917                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
918               }
919
920               // ... marker type
921               if(useObjMarker) {
922                 GEOM::marker_type aType = aGeomObject->GetMarkerType();
923                 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
924                 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
925                   Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
926                   double aMSize = ((int)aSize+1)*0.5;
927                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
928                   anAspect->SetScale( aMSize );
929                   anAspect->SetTypeOfMarker( aMType );
930                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
931                   if ( hasColor )
932                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
933                   anAspect->SetColor( aQuanColor );
934                   AISShape->Attributes()->SetPointAspect( anAspect );
935                 }
936                 else if ( aType == GEOM::MT_USER ) {
937                   int aTextureId = aGeomObject->GetMarkerTexture();
938                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
939                   if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
940                   Standard_Integer aWidth, aHeight;
941 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
942                   Handle(TColStd_HArray1OfByte) aTexture =
943 #else
944                   Handle(Graphic3d_HArray1OfBytes) aTexture =
945 #endif
946                     GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
947                   if (!aTexture.IsNull()) {
948                     static int TextureId = 0;
949                     Handle(Prs3d_PointAspect) aTextureAspect =
950                       new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
951                     AISShape->Attributes()->SetPointAspect( aTextureAspect );
952                   }
953                 } else { //Use marker from the preferences
954                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
955                   anAspect->SetScale( myScaleOfMarker );
956                   anAspect->SetTypeOfMarker( myTypeOfMarker );
957                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
958                   if ( hasColor )
959                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
960                   anAspect->SetColor( aQuanColor );
961                   AISShape->Attributes()->SetPointAspect( anAspect );
962                 }
963               }
964             }
965           }
966
967           // get material properties, set material
968           Material_Model material;
969           if ( useStudy ) {
970             // Get material property from study and construct material model
971             material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
972           } else {
973             // Get material property from study and construct material model
974                   QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
975             material.fromResources( mname );
976           }
977
978           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
979
980           // Set material for the selected shape
981                 AISShape->SetMaterial( material.getMaterialOCCAspect() );
982                 if(HasWidth())
983                   aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
984                 if(HasIsosWidth())
985                   aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
986         }
987
988         // AISShape->SetName(???); ??? necessary to set name ???
989         occPrs->AddObject( AISShape );
990         
991         // In accordance with ToActivate() value object will be activated/deactivated
992         // when it will be displayed
993         occPrs->SetToActivate( ToActivate() );
994                 
995                 if( AISShape->isTopLevel() && AISShape->topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor) {
996                 //21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
997                 // Display wireframe presentation additionally
998                         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
999                         aWirePrs->SetWidth(AISShape->Width());
1000                         if ( !myIO.IsNull() ) {
1001                                 aWirePrs->setIO( myIO );
1002                                 aWirePrs->SetOwner( myIO );
1003                         }
1004                         occPrs->AddObject(aWirePrs);
1005                 }
1006       }
1007     }
1008     // if presentation is found -> set again shape for it
1009     else
1010     {
1011       if ( !myShape.IsNull() )
1012       {
1013         AIS_ListOfInteractive IOList;
1014         occPrs->GetObjects( IOList );
1015         AIS_ListIteratorOfListOfInteractive Iter( IOList );
1016         for ( ; Iter.More(); Iter.Next() )
1017         {
1018           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1019           if ( AISShape.IsNull() )
1020             continue;
1021           if ( AISShape->Shape() != myShape )
1022           {
1023             AISShape->Set( myShape );
1024             AISShape->UpdateSelection();
1025             AISShape->SetToUpdate();
1026           }
1027           if ( !myIO.IsNull() )
1028           {
1029             AISShape->setIO( myIO );
1030             AISShape->SetOwner( myIO );
1031           }
1032         }
1033       }
1034     }
1035   }
1036 }
1037
1038 //=================================================================
1039 /*!
1040  *  GEOM_Displayer::Update
1041  *  Update VTK presentaion
1042  *  [ Reimplemented from SALOME_Displayer ]
1043  */
1044 //=================================================================
1045 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1046 {
1047   SalomeApp_Study* aStudy = getStudy();
1048   int aMgrId = -1;
1049   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1050
1051   if ( !vtkPrs || myShape.IsNull() || !aStudy)
1052     return;
1053
1054   bool useStudy = false;
1055   bool useObjCol = false;
1056   PropMap aPropMap;
1057
1058   vtkActorCollection* theActors = 0;
1059
1060   QString anEntry;
1061   if(!myIO.IsNull()) {
1062     anEntry = myIO->getEntry();
1063   }
1064
1065   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1066     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1067     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1068
1069     if ( HasColor() ) {
1070       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1071       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1072     }
1073
1074     Handle(Geom_Plane) aPlane =
1075       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1076     if ( aPlane.IsNull() )
1077       return;
1078
1079     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1080     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1081
1082     //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1083     //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1084
1085     vtkPrs->AddObject( aTrh );
1086
1087     theActors = vtkActorCollection::New();
1088     theActors->AddItem( aTrh );
1089   }
1090   else {
1091     PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1092
1093     if(!myIO.IsNull()) {
1094       aMgrId = getViewManagerId(myViewFrame);
1095     }
1096     useStudy = !anEntry.isEmpty() && aMgrId != -1;
1097
1098
1099     theActors = vtkActorCollection::New();
1100     GEOM_Actor* aGeomActor = GEOM_Actor::New();
1101     aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1102     theActors->AddItem(aGeomActor);
1103     aGeomActor->Delete();
1104
1105     if(useStudy) {
1106       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1107       if(!aPropMap.contains(COLOR_PROP))
1108         useObjCol = true;
1109       MergePropertyMaps(aPropMap, aDefPropMap);
1110     }
1111   }
1112
1113   theActors->InitTraversal();
1114
1115   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1116
1117   vtkProperty* aProp = 0;
1118
1119   if ( HasColor() || HasWidth() )
1120   {
1121     aProp = vtkProperty::New();
1122     aProp->SetRepresentationToWireframe();
1123   }
1124
1125   if ( HasColor() )
1126   {
1127     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1128     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1129   }
1130
1131   while ( anActor != NULL )
1132   {
1133     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1134
1135     GActor->setIO( myIO );
1136
1137     if ( aProp )
1138     {
1139       GActor->SetProperty( aProp );
1140       GActor->SetPreviewProperty( aProp );
1141     }
1142
1143     GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1144     if ( aGeomGActor != 0 )
1145     {
1146       if ( aProp ) {
1147         aGeomGActor->SetShadingProperty( aProp );
1148         aGeomGActor->SetWireframeProperty( aProp );
1149       }
1150
1151       // Set color for edges in shading
1152       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1153       if(aResMgr) {
1154         QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1155         aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1156       }
1157
1158       int aIsos[2]= { 1, 1 };
1159       if(useStudy) {
1160         QString anIsos = aPropMap.value(ISOS_PROP).toString();
1161         QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
1162         aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1163         aGeomGActor->SetNbIsos(aIsos);
1164         aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1165         SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1166         SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1167         aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1168         int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1169         // Specially processing of 'Shading with edges' mode from preferences,
1170         // because there is the following enum in VTK viewer:
1171         // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1172         // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1173         // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1174         if ( aDispModeId == 2 )
1175           // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1176           // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1177           aDispModeId++;
1178         aGeomGActor->setDisplayMode(aDispModeId);
1179         aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1180
1181         // Create material model
1182         Material_Model material;
1183         material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );      
1184         // Set material properties for the object
1185         aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );     
1186         // Set the same front and back materials for the selected shape
1187         std::vector<vtkProperty*> aProps;
1188         aProps.push_back( material.getMaterialVTKProperty() );
1189         aGeomGActor->SetMaterial(aProps);
1190           
1191         vtkFloatingPointType aColor[3] = {1.,0.,0.};
1192         if ( useObjCol ) { //Get Color from geom object
1193           Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1194           if ( !anIO.IsNull() ) {
1195             _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1196             if ( SO ) {
1197               // get CORBA reference to data object
1198               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1199               if ( !CORBA::is_nil( object ) ) {
1200                 // downcast to GEOM object
1201                 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1202                 bool hasColor = false;
1203                 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1204                 if(hasColor) {
1205                   aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1206                 } else {
1207                   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1208                   if(aResMgr) {
1209                     QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1210                     aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1211                   }
1212                 }
1213                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
1214               }
1215             }
1216           }
1217         } else {
1218           QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1219           aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1220         } 
1221
1222         if ( !material.isPhysical() )
1223           aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1224       }
1225       else {
1226         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1227         if ( aResMgr ) {
1228                  // Create material model
1229                  Material_Model material;
1230                  // Get material name from resources
1231                  QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1232                  material.fromResources( mname );
1233                  // Set material properties for the object
1234                  aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1235                  // Set material for the selected shape
1236                  std::vector<vtkProperty*> aProps;
1237                  aProps.push_back( material.getMaterialVTKProperty() );
1238                  aGeomGActor->SetMaterial(aProps);
1239         }
1240       }
1241     }
1242     if ( aGeomGActor )
1243     {
1244       if ( HasWidth() )
1245         aGeomGActor->SetWidth( GetWidth() );
1246
1247       if ( HasIsosWidth() )
1248         aGeomGActor->SetIsosWidth( GetIsosWidth() );
1249     }
1250     
1251     if ( myToActivate )
1252       GActor->PickableOn();
1253     else
1254       GActor->PickableOff();
1255
1256     vtkPrs->AddObject( GActor );
1257
1258     anActor = (vtkActor*)theActors->GetNextActor();
1259   }
1260
1261   if ( aProp )
1262     aProp->Delete();
1263
1264   theActors->Delete();
1265 }
1266
1267 //=================================================================
1268 /*!
1269  *  GEOM_Displayer::BuildPrs
1270  *  Build presentation accordint to the current viewer type
1271  */
1272 //=================================================================
1273 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1274 {
1275   if ( theObj->_is_nil() )
1276     return 0;
1277
1278   myViewFrame = GetActiveView();
1279   if ( myViewFrame == 0 )
1280     return 0;
1281
1282   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1283   if ( aPrs == 0 )
1284     return 0;
1285
1286   internalReset();
1287   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1288   myType = theObj->GetType();
1289
1290   // Update presentation
1291   UpdatePrs( aPrs );
1292
1293   return aPrs;
1294 }
1295
1296 //=================================================================
1297 /*!
1298  *  GEOM_Displayer::BuildPrs
1299  *  Build presentation accordint to the current viewer type
1300  */
1301 //=================================================================
1302 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1303 {
1304   myViewFrame = GetActiveView();
1305   if ( theShape.IsNull() || myViewFrame == 0 )
1306     return 0;
1307
1308   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1309   if ( aPrs == 0 )
1310     return 0;
1311
1312   internalReset();
1313   setShape( theShape );
1314   myType = -1;
1315
1316   UpdatePrs( aPrs );
1317
1318   return aPrs;
1319 }
1320
1321 //=================================================================
1322 /*!
1323  *  GEOM_Displayer::buildPresentation
1324  *  Builds/finds object's presentation for the current viewer
1325  *  Calls corresponding Update() method by means of double dispatch
1326  *  [ internal ]
1327  */
1328 //=================================================================
1329 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1330                                                SALOME_View* theViewFrame )
1331 {
1332   SALOME_Prs* prs = 0;
1333   internalReset();
1334
1335   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1336
1337   if ( myViewFrame )
1338   {
1339     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1340     if ( prs )
1341     {
1342       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1343       theIO->setEntry( entry.toLatin1().constData() );
1344       if ( !theIO.IsNull() )
1345       {
1346         // set interactive object
1347         setIO( theIO );
1348         //  Find SOBject (because shape should be published previously)
1349         SUIT_Session* session = SUIT_Session::session();
1350         SUIT_Application* app = session->activeApplication();
1351         if ( app )
1352         {
1353           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1354           if ( study )
1355           {
1356             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1357             if ( SO )
1358             {
1359               // get CORBA reference to data object
1360               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1361               if ( !CORBA::is_nil( object ) )
1362               {
1363                 // downcast to GEOM object
1364                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1365                 if ( !GeomObject->_is_nil() )
1366                 {
1367                   // finally set shape
1368                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1369                   myType = GeomObject->GetType();
1370                 }
1371               }
1372             }
1373           }
1374         }
1375       }
1376       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1377     }
1378   }
1379   return prs;
1380 }
1381
1382 //=================================================================
1383 /*!
1384  *  GEOM_Displayer::buildSubshapePresentation
1385  *  Builds/finds object's presentation for the current viewer
1386  *  Calls corresponding Update() method by means of double dispatch
1387  *  For not published objects (for Mantis issue 0020435)
1388  */
1389 //=================================================================
1390 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1391                                                       const QString& entry,
1392                                                       SALOME_View* theViewFrame)
1393 {
1394   SALOME_Prs* prs = 0;
1395   internalReset();
1396
1397   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1398
1399   if (myViewFrame)
1400   {
1401     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1402     if (prs)
1403     {
1404       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1405       theIO->setEntry(entry.toLatin1().constData());
1406       if (!theIO.IsNull())
1407       {
1408         // set interactive object
1409         setIO(theIO);
1410         // finally set shape
1411         setShape(aShape);
1412         myType = GEOM_SUBSHAPE;
1413       }
1414       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1415     }
1416   }
1417   return prs;
1418 }
1419
1420 //=================================================================
1421 /*!
1422  *  GEOM_Displayer::internalReset
1423  *  Resets internal data
1424  *  [internal]
1425  */
1426 //=================================================================
1427 void GEOM_Displayer::internalReset()
1428 {
1429   myIO.Nullify();
1430   myShape.Nullify();
1431 }
1432
1433 //=================================================================
1434 /*!
1435  *  GEOM_Displayer::LocalSelection
1436  *  Activate selection of CAD shapes with activisation of selection
1437  *  of their sub-shapes (with opened local context for OCC viewer)
1438  */
1439 //=================================================================
1440 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1441 {
1442   SUIT_Session* session = SUIT_Session::session();
1443   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1444   if ( !app )
1445     return;
1446
1447   LightApp_SelectionMgr* sm = app->selectionMgr();
1448
1449   // remove all filters from selection
1450   sm->clearFilters();
1451
1452   SALOME_View* vf = GetActiveView();
1453   if ( vf ) {
1454     if (!theIO.IsNull() && !vf->isVisible(theIO))
1455       Display(theIO);
1456     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1457     vf->LocalSelection( prs, theMode );
1458     delete prs;  // delete presentation because displayer is its owner
1459   }
1460 }
1461
1462 //=================================================================
1463 /*!
1464  *  GEOM_Displayer::globalSelection
1465  *  Activate selection of CAD shapes without activisation of selection
1466  *  of their sub-shapes (without opened local context for OCC viewer)
1467  */
1468 //=================================================================
1469 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1470 {
1471   TColStd_MapOfInteger aModes;
1472   aModes.Add( theMode );
1473   GlobalSelection( aModes, update );
1474 }
1475
1476 //=================================================================
1477 /*!
1478  *  GEOM_Displayer::globalSelection
1479  *  Activate selection of CAD shapes without activisation of selection
1480  *  of their sub-shapes (without opened local context for OCC viewer)
1481  */
1482 //=================================================================
1483 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1484                                       const bool update, const QList<int>* theSubShapes )
1485 {
1486   SUIT_Session* session = SUIT_Session::session();
1487   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1488   if ( !app )
1489     return;
1490
1491   SALOME_View* vf = GetActiveView();
1492   if ( vf == 0 )
1493     return;
1494
1495   // Close local context
1496   vf->GlobalSelection( update );
1497
1498   // Set selection filters in accordance with current mode
1499   LightApp_SelectionMgr* sm = app->selectionMgr();
1500   if ( !sm )
1501     return;
1502
1503   // Remove from selection temporary objects if necessary
1504   if ( !theModes.Contains( GEOM_PREVIEW ) )
1505     clearTemporary( sm );
1506
1507   //@ aSel->ClearIndex();
1508
1509   sm->clearFilters();
1510
1511   // Remove filters from AIS_InteractiveContext
1512   Handle(AIS_InteractiveContext) ic;
1513   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1514   if ( viewer )
1515     {
1516       ic = viewer->getAISContext();
1517       if ( !ic.IsNull() )
1518         ic->RemoveFilters();
1519     }
1520
1521   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1522     return;
1523
1524   SUIT_SelectionFilter* aFilter;
1525   if ( theModes.Extent() == 1 )
1526     {
1527       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1528
1529       if ( aMode == GEOM_COMPOUNDFILTER )
1530         aFilter = getComplexFilter( theSubShapes );
1531       else
1532         aFilter = getFilter( aMode );
1533     }
1534   else if ( theModes.Extent() > 1 )
1535     {
1536       TColStd_MapOfInteger aTopAbsModes;
1537       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1538       QList<SUIT_SelectionFilter*> aListOfFilters;
1539       for ( ; anIter.More(); anIter.Next() )
1540         {
1541           SUIT_SelectionFilter* aFilter;
1542           int aMode = anIter.Key();
1543           if ( aMode == GEOM_COMPOUNDFILTER )
1544             aFilter = getComplexFilter( theSubShapes );
1545           else
1546             aFilter = getFilter( aMode );
1547
1548           if ( aFilter )
1549             aListOfFilters.append( aFilter );
1550         }
1551
1552       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1553     }
1554   else
1555     return;
1556
1557   if ( aFilter )
1558     {
1559       sm->installFilter( aFilter );
1560       if ( !ic.IsNull() )
1561         {
1562           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1563           ic->AddFilter( anOCCFilter );
1564         }
1565     }
1566 }
1567
1568 //=================================================================
1569 /*!
1570  *  GEOM_Displayer::LocalSelection
1571  *  Activate selection of CAD shapes with activisation of selection
1572  *  of their sub-shapes (with opened local context for OCC viewer)
1573  */
1574 //=================================================================
1575 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1576 {
1577   SALOME_ListIteratorOfListIO Iter( theIOList );
1578   for ( ; Iter.More(); Iter.Next() )
1579     LocalSelection( Iter.Value(), theMode );
1580 }
1581
1582 //=================================================================
1583 /*!
1584  *  GEOM_Displayer::BeforeDisplay
1585  *  Called before displaying of pars. Close local context
1586  *  [ Reimplemented from SALOME_Displayer ]
1587  */
1588 //=================================================================
1589 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1590 {
1591   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1592   if ( vf )
1593   {
1594     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1595     if ( !ic.IsNull() )
1596     {
1597       if ( ic->HasOpenedContext() )
1598       ic->CloseAllContexts();
1599     }
1600   }
1601 }
1602
1603 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1604 {
1605   SalomeApp_Study* aStudy = getStudy();
1606   if (!aStudy) return;
1607   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1608   if ( vf && !p->IsNull() ) {
1609     int aMgrId = getViewManagerId( vf );
1610     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1611     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1612     if ( !ic.IsNull() && prs ) {
1613       AIS_ListOfInteractive objects;
1614       prs->GetObjects( objects );
1615       AIS_ListIteratorOfListOfInteractive it( objects );
1616       for ( ; it.More(); it.Next() ) {
1617         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1618         if ( sh.IsNull() ) continue;
1619         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1620         if ( IO.IsNull() ) continue;
1621         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1622         if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1623           double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1624           ic->SetTransparency( sh, transparency, true );
1625         }
1626       }
1627     }
1628   }
1629 }
1630
1631 //=================================================================
1632 /*!
1633  *  GEOM_Displayer::SetColor
1634  *  Set color for shape displaying. If it is equal -1 then default color is used.
1635  *  Available values are from Quantity_NameOfColor enumeration
1636  */
1637 //=================================================================
1638 void GEOM_Displayer::SetColor( const int color )
1639 {
1640   if ( color == -1 )
1641     UnsetColor();
1642   else
1643   {
1644     myColor = color;
1645     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1646   }
1647 }
1648
1649 int GEOM_Displayer::GetColor() const
1650 {
1651   return myColor;
1652 }
1653
1654 bool GEOM_Displayer::HasColor() const
1655 {
1656   return myColor != -1;
1657 }
1658
1659 void GEOM_Displayer::UnsetColor()
1660 {
1661   myColor = -1;
1662
1663   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1664   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1665   myShadingColor = SalomeApp_Tools::color( col );
1666 }
1667
1668 //=================================================================
1669 /*!
1670  *  GEOM_Displayer::SetTexture
1671  *  Set color for shape displaying. If it is equal -1 then default color is used.
1672  *  Available values are from Quantity_NameOfColor enumeration
1673  */
1674 //=================================================================
1675 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1676 {
1677   if(texureFileName!="")
1678   {
1679     myTexture = texureFileName;
1680   }
1681 }
1682
1683 bool GEOM_Displayer::HasTexture() const
1684 {
1685   return myTexture != "";
1686 }
1687
1688 std::string GEOM_Displayer::GetTexture() const
1689 {
1690   return myTexture;
1691 }
1692
1693 //=================================================================
1694 /*!
1695  *  GEOM_Displayer::SetWidth
1696  *  Set width of shape displaying. If it is equal -1 then default width is used.
1697  */
1698 //=================================================================
1699 void GEOM_Displayer::SetWidth( const double width )
1700 {
1701   myWidth = width;
1702 }
1703
1704 double GEOM_Displayer::GetWidth() const
1705 {
1706   return myWidth;
1707 }
1708
1709 bool GEOM_Displayer::HasWidth() const
1710 {
1711   return myWidth != -1;
1712 }
1713
1714 void GEOM_Displayer::UnsetWidth()
1715 {
1716   myWidth = -1;
1717 }
1718
1719
1720 int GEOM_Displayer::GetIsosWidth() const
1721 {
1722   return myIsosWidth;
1723 }
1724
1725 void GEOM_Displayer::SetIsosWidth(const int width) 
1726 {
1727   myIsosWidth = width;
1728 }
1729
1730 bool GEOM_Displayer::HasIsosWidth() const
1731 {
1732   return myIsosWidth != -1;
1733 }
1734
1735
1736 //=================================================================
1737 /*!
1738  *  GEOM_Displayer::SetToActivate
1739  *  This method is used for activisation/deactivisation of objects to be displayed
1740  */
1741 //=================================================================
1742 void GEOM_Displayer::SetToActivate( const bool toActivate )
1743 {
1744   myToActivate = toActivate;
1745 }
1746 bool GEOM_Displayer::ToActivate() const
1747 {
1748   return myToActivate;
1749 }
1750
1751 //=================================================================
1752 /*!
1753  *  GEOM_Displayer::clearTemporary
1754  *  Removes from selection temporary objects
1755  */
1756 //=================================================================
1757 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1758 {
1759   SALOME_ListIO selected, toSelect;
1760   theSelMgr->selectedObjects( selected );
1761
1762   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1763     Handle(SALOME_InteractiveObject) io = it.Value();
1764     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1765       toSelect.Append( it.Value() );
1766   }
1767
1768   theSelMgr->setSelectedObjects( toSelect, true );
1769 }
1770
1771 void GEOM_Displayer::SetName( const char* theName )
1772 {
1773   myName = theName;
1774 }
1775
1776 void GEOM_Displayer::UnsetName()
1777 {
1778   myName = "";
1779 }
1780
1781 SalomeApp_Study* GEOM_Displayer::getStudy() const
1782 {
1783   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1784 }
1785
1786 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1787 {
1788   myIO = theIO;
1789 }
1790
1791 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1792 {
1793   myShape = theShape;
1794 }
1795
1796 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1797 {
1798   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1799 }
1800
1801 int GEOM_Displayer::SetDisplayMode( const int theMode )
1802 {
1803   int aPrevMode = myDisplayMode;
1804   if ( theMode != -1 )
1805     myDisplayMode = theMode;
1806   else
1807   {
1808     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1809     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1810   }
1811   return aPrevMode;
1812 }
1813
1814 int GEOM_Displayer::GetDisplayMode() const
1815 {
1816   return myDisplayMode;
1817 }
1818
1819 int GEOM_Displayer::UnsetDisplayMode()
1820 {
1821   int aPrevMode = myDisplayMode;
1822   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1823   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1824   return aPrevMode;
1825 }
1826
1827 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1828 {
1829   int aHue = -1;
1830   int aTolerance = 64;
1831   int anIterations = 0;
1832   int aPeriod = 5;
1833
1834   while( 1 )
1835   {
1836     anIterations++;
1837     if( anIterations % aPeriod == 0 )
1838     {
1839       aTolerance /= 2;
1840       if( aTolerance < 1 )
1841         break;
1842     }
1843     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1844
1845     aHue = (int)( 360.0 * rand() / RAND_MAX );
1846     //std::cout << "Hue = " << aHue << std::endl;
1847
1848     //std::cout << "Auto colors : ";
1849     bool ok = true;
1850     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1851     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1852     for( ; it != itEnd; ++it )
1853     {
1854       SALOMEDS::Color anAutoColor = *it;
1855       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1856
1857       int h, s, v;
1858       aQColor.getHsv( &h, &s, &v );
1859       //std::cout << h << " ";
1860       if( abs( h - aHue ) < aTolerance )
1861       {
1862         ok = false;
1863         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1864         break;
1865       }
1866     }
1867     //std::cout << std::endl;
1868
1869     if( ok )
1870       break;
1871   }
1872
1873   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1874   QColor aColor;
1875   aColor.setHsv( aHue, 255, 255 );
1876
1877   SALOMEDS::Color aSColor;
1878   aSColor.R = (double)aColor.red() / 255.0;
1879   aSColor.G = (double)aColor.green() / 255.0;
1880   aSColor.B = (double)aColor.blue() / 255.0;
1881
1882   return aSColor;
1883 }
1884
1885
1886
1887 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1888   PropMap aDefaultMap;
1889   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1890   //1. Visibility
1891   aDefaultMap.insert(VISIBILITY_PROP , 1);
1892
1893   //2. Nb Isos
1894   int anUIsoNumber;
1895   int aVIsoNumber;
1896   if(viewer_type == SOCC_Viewer::Type()) {
1897     anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1898     aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1899   } else if( viewer_type==SVTK_Viewer::Type()) {
1900     anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1901     aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1902   }
1903   QString anIsos("%1%2%3");
1904   anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1905   aDefaultMap.insert(ISOS_PROP , anIsos);
1906
1907   //3. Transparency
1908   aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1909
1910   //4. Display Mode
1911   aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1912
1913   //5. Vector Mode
1914   aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1915
1916   //6. Color
1917   QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1918   aDefaultMap.insert( COLOR_PROP , col);
1919
1920   //7. Deflection Coeff
1921   double aDC;
1922
1923   if(viewer_type == SOCC_Viewer::Type()) {
1924     aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1925   } else if( viewer_type==SVTK_Viewer::Type()) {
1926     aDC = 0.001;
1927   }
1928
1929   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1930
1931   //8. Material
1932   Material_Model material;
1933   QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1934   material.fromResources( mname );
1935   aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );  
1936
1937   //9. Width of the edges
1938   aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1939
1940
1941   //10. Width of iso-lines
1942   aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1943
1944   if(viewer_type == SOCC_Viewer::Type()) {
1945
1946     aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1947   }
1948
1949   return aDefaultMap;
1950 }
1951
1952 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1953   int nbInserted = 0;
1954   if(!theOrigin.contains(VISIBILITY_PROP)) {
1955     theOrigin.insert(VISIBILITY_PROP, 0);
1956     nbInserted++;
1957   }
1958   if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1959     theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1960     nbInserted++;
1961   }
1962   if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1963     theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1964     nbInserted++;
1965   }
1966   if(!theOrigin.contains(ISOS_PROP)) {
1967     theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1968     nbInserted++;
1969   }
1970   if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1971     theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1972     nbInserted++;
1973   }
1974   if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1975     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1976     nbInserted++;
1977   }
1978   if(!theOrigin.contains(MATERIAL_PROP)) {
1979     theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1980     nbInserted++;
1981   }
1982
1983   if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1984     theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1985     nbInserted++;
1986   }
1987
1988   if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1989     theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1990     nbInserted++;
1991   }
1992
1993   if(!theOrigin.contains(COLOR_PROP)) {
1994     theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1995     nbInserted++;
1996   }
1997
1998   return (nbInserted > 0);
1999 }
2000
2001
2002 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2003   SALOMEDS::Color aSColor;
2004   hasColor = false;
2005
2006   SUIT_Session* session = SUIT_Session::session();
2007   SUIT_Application* app = session->activeApplication();
2008
2009   if ( app && !theGeomObject->_is_nil()) {
2010     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2011
2012     if ( study ) {
2013       aSColor = theGeomObject->GetColor();
2014       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2015       if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2016         GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2017         GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2018         GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2019         if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2020           {
2021             QList<SALOMEDS::Color> aReservedColors;
2022
2023             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2024             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2025             if ( strcmp(IOR.in(), "") != 0 )
2026               {
2027                 _PTR(Study) aStudy = study->studyDS();
2028                 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2029                 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2030                 for( ; it->More(); it->Next() )
2031                   {
2032                     _PTR(SObject) aChildSObject( it->Value() );
2033                     GEOM::GEOM_Object_var aChildObject =
2034                       GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2035                     if( CORBA::is_nil( aChildObject ) )
2036                       continue;
2037
2038                     if( aChildObject->GetType() != GEOM_GROUP )
2039                       continue;
2040
2041                     SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2042                     aReservedColors.append( aReservedColor );
2043                   }
2044               }
2045
2046             aSColor = getUniqueColor( aReservedColors );
2047             hasColor = true;
2048           }
2049       }
2050     }
2051   }
2052   return aSColor;
2053 }
2054
2055
2056 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2057                                        const bool eraseOnlyChildren) {
2058   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2059   if ( !app )
2060     return;
2061
2062   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2063   if ( !appStudy )
2064     return;
2065
2066   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2067
2068   if( !parent)
2069     return;
2070
2071   // Erase from all views
2072   QList<SALOME_View*> views;
2073   SALOME_View* view;
2074   ViewManagerList vmans = app->viewManagers();
2075   SUIT_ViewManager* vman;
2076   foreach ( vman, vmans ) {
2077     SUIT_ViewModel* vmod = vman->getViewModel();
2078     view = dynamic_cast<SALOME_View*> ( vmod );
2079     if ( view )
2080       views.append( view );
2081   }
2082
2083   if( views.count() == 0 )
2084     return;
2085
2086   //Erase childrens w/o update views
2087   DataObjectList listObj = parent->children( true );
2088   SUIT_DataObject* obj;
2089   foreach( obj, listObj ) {
2090     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2091     if(l_obj)
2092       foreach ( view, views ) {
2093       Handle(SALOME_InteractiveObject) anIO =
2094         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2095       Erase(anIO, false, false, view);
2096     }
2097   }
2098
2099   //Erase parent with view update or repaint views
2100   foreach ( view, views ) {
2101     if(!eraseOnlyChildren)
2102       Erase(theIO, false, true, view);
2103     else
2104       view->Repaint();
2105   }
2106 }