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