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