]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
a5deecd692dd2d90fdd2c5b0df0d79a36c0fe069
[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         //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
648         Handle(GEOM_AISShape) AISShape;
649         if (myType == GEOM_VECTOR)
650           AISShape = new GEOM_AISVector (myShape, "");
651         else {
652           if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
653               !TopoDS_Iterator(myShape).More())
654             return;// NPAL15983 (Bug when displaying empty groups)
655           AISShape = new GEOM_AISShape (myShape, "");
656         }
657         // Temporary staff: vertex must be infinite for correct visualization
658         AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
659
660         if(useStudy){
661           aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
662           aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
663           Quantity_Color  quant_col;
664           if(aPropMap.contains(COLOR_PROP)) {
665             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
666             AISShape->SetShadingColor( quant_col );
667           } else
668             useObjColor = true;
669           MergePropertyMaps(aPropMap, aDefPropMap);
670           if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
671             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
672             AISShape->SetShadingColor( quant_col );
673           }
674
675           // Setup shape properties here ..., e.g. display mode, color, transparency, etc
676           AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
677           AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
678           if(aPropMap.contains(TOP_LEVEL_PROP)) {
679             AISShape->setTopLevel( aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>() );
680           } 
681         }else {
682           MESSAGE("myDisplayMode = "<< myDisplayMode)
683           AISShape->SetDisplayMode( myDisplayMode );
684           AISShape->SetShadingColor( myShadingColor );
685         }
686
687         // Set color and number for iso lines
688         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
689         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
690                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
691         Quantity_Color aColor = SalomeApp_Tools::color( col );
692
693         //get the ISOS number, set transparency if need
694         int anUIsoNumber, aVIsoNumber;
695         if(useStudy) {
696           QString anIsos = aPropMap.value(ISOS_PROP).toString();
697           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
698           anUIsoNumber = uv[0].toInt();
699           aVIsoNumber = uv[1].toInt();
700           //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
701         } else {
702           anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
703           aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
704         }
705
706         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
707         anAspect->SetNumber( anUIsoNumber );
708         anAspect->SetColor( aColor );
709
710         if(HasIsosWidth())
711           anAspect->SetWidth( GetIsosWidth() );
712         AISShape->Attributes()->SetUIsoAspect( anAspect );
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 material;
965           if ( useStudy ) {
966             // Get material property from study and construct material model
967             material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
968           } else {
969             // Get material property from study and construct material model
970             QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
971             material.fromResources( mname );
972           }
973
974           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
975
976           // Set material for the selected shape
977           AISShape->SetMaterial( material.getMaterialOCCAspect() );
978
979           if(HasWidth())
980             aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
981
982           if(HasIsosWidth())
983             aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
984
985
986         }
987
988         // AISShape->SetName(???); ??? necessary to set name ???
989         occPrs->AddObject( AISShape );
990
991         // In accordance with ToActivate() value object will be activated/deactivated
992         // when it will be displayed
993         occPrs->SetToActivate( ToActivate() );
994       }
995     }
996     // if presentation is found -> set again shape for it
997     else
998     {
999       if ( !myShape.IsNull() )
1000       {
1001         AIS_ListOfInteractive IOList;
1002         occPrs->GetObjects( IOList );
1003         AIS_ListIteratorOfListOfInteractive Iter( IOList );
1004         for ( ; Iter.More(); Iter.Next() )
1005         {
1006           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1007           if ( AISShape.IsNull() )
1008             continue;
1009           if ( AISShape->Shape() != myShape )
1010           {
1011             AISShape->Set( myShape );
1012             AISShape->UpdateSelection();
1013             AISShape->SetToUpdate();
1014           }
1015           if ( !myIO.IsNull() )
1016           {
1017             AISShape->setIO( myIO );
1018             AISShape->SetOwner( myIO );
1019           }
1020         }
1021       }
1022     }
1023   }
1024 }
1025
1026 //=================================================================
1027 /*!
1028  *  GEOM_Displayer::Update
1029  *  Update VTK presentaion
1030  *  [ Reimplemented from SALOME_Displayer ]
1031  */
1032 //=================================================================
1033 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1034 {
1035   SalomeApp_Study* aStudy = getStudy();
1036   int aMgrId = -1;
1037   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1038
1039   if ( !vtkPrs || myShape.IsNull() || !aStudy)
1040     return;
1041
1042   bool useStudy = false;
1043   PropMap aPropMap;
1044
1045   vtkActorCollection* theActors = 0;
1046
1047   QString anEntry;
1048   if(!myIO.IsNull()) {
1049     anEntry = myIO->getEntry();
1050   }
1051
1052   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1053     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1054     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1055
1056     if ( HasColor() ) {
1057       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1058       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1059     }
1060
1061     Handle(Geom_Plane) aPlane =
1062       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1063     if ( aPlane.IsNull() )
1064       return;
1065
1066     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1067     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1068
1069     //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1070     //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1071
1072     vtkPrs->AddObject( aTrh );
1073
1074     theActors = vtkActorCollection::New();
1075     theActors->AddItem( aTrh );
1076   }
1077   else {
1078     PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1079
1080     if(!myIO.IsNull()) {
1081       aMgrId = getViewManagerId(myViewFrame);
1082     }
1083     useStudy = !anEntry.isEmpty() && aMgrId != -1;
1084
1085
1086     theActors = vtkActorCollection::New();
1087     GEOM_Actor* aGeomActor = GEOM_Actor::New();
1088     aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1089     theActors->AddItem(aGeomActor);
1090     aGeomActor->Delete();
1091
1092     if(useStudy) {
1093       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1094       MergePropertyMaps(aPropMap, aDefPropMap);
1095     }
1096   }
1097
1098   theActors->InitTraversal();
1099
1100   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1101
1102   vtkProperty* aProp = 0;
1103
1104   if ( HasColor() || HasWidth() )
1105   {
1106     aProp = vtkProperty::New();
1107     aProp->SetRepresentationToWireframe();
1108   }
1109
1110   if ( HasColor() )
1111   {
1112     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1113     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1114   }
1115
1116   while ( anActor != NULL )
1117   {
1118     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1119
1120     GActor->setIO( myIO );
1121
1122     if ( aProp )
1123     {
1124       GActor->SetProperty( aProp );
1125       GActor->SetPreviewProperty( aProp );
1126     }
1127
1128     GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1129     if ( aGeomGActor != 0 )
1130       {
1131         if ( aProp ) {
1132           aGeomGActor->SetShadingProperty( aProp );
1133           aGeomGActor->SetWireframeProperty( aProp );
1134         }
1135
1136         // Set color for edges in shading
1137         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1138         if(aResMgr) {
1139           QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1140           aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1141         }
1142
1143         int aIsos[2]= { 1, 1 };
1144         if(useStudy) {
1145           QString anIsos = aPropMap.value(ISOS_PROP).toString();
1146           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
1147           aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1148           aGeomGActor->SetNbIsos(aIsos);
1149           aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1150           SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1151           SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1152           aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1153           int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1154           // Specially processing of 'Shading with edges' mode from preferences,
1155           // because there is the following enum in VTK viewer:
1156           // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1157           // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1158           // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1159           if ( aDispModeId == 2 )
1160             // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1161             // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1162             aDispModeId++;
1163           aGeomGActor->setDisplayMode(aDispModeId);
1164           aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1165
1166           // Create material model
1167           Material_Model material;
1168           material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );    
1169           // Set material properties for the object
1170           aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );   
1171           // Set the same front and back materials for the selected shape
1172           std::vector<vtkProperty*> aProps;
1173           aProps.push_back( material.getMaterialVTKProperty() );
1174           aGeomGActor->SetMaterial(aProps);
1175           
1176           vtkFloatingPointType aColor[3] = {1.,0.,0.};
1177           if(aPropMap.contains(COLOR_PROP)) {
1178             QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1179             aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1180           } else { //Get Color from geom object
1181             Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1182             if ( !anIO.IsNull() ) {
1183               _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1184               if ( SO ) {
1185                 // get CORBA reference to data object
1186                 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1187                 if ( !CORBA::is_nil( object ) ) {
1188                   // downcast to GEOM object
1189                   GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1190                   bool hasColor = false;
1191                   SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1192                   if(hasColor) {
1193                     aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1194                   } else {
1195                     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1196                     if(aResMgr) {
1197                       QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1198                       aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1199                       aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1200                     }
1201                   }
1202                 }
1203               }
1204             }
1205           }
1206           if ( !material.isPhysical() )
1207             aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1208         }
1209         else {
1210           SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1211           if ( aResMgr ) {
1212             // Create material model
1213             Material_Model material;
1214             // Get material name from resources
1215             QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1216             material.fromResources( mname );
1217             // Set material properties for the object
1218             aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1219             // Set material for the selected shape
1220             std::vector<vtkProperty*> aProps;
1221             aProps.push_back( material.getMaterialVTKProperty() );
1222             aGeomGActor->SetMaterial(aProps);
1223           }
1224         }
1225       }
1226
1227       if ( aGeomGActor )
1228       {
1229         if ( HasWidth() )
1230           aGeomGActor->SetWidth( GetWidth() );
1231
1232         if ( HasIsosWidth() )
1233           aGeomGActor->SetIsosWidth( GetIsosWidth() );
1234       }
1235     
1236     if ( myToActivate )
1237       GActor->PickableOn();
1238     else
1239       GActor->PickableOff();
1240
1241     vtkPrs->AddObject( GActor );
1242
1243     anActor = (vtkActor*)theActors->GetNextActor();
1244   }
1245
1246   if ( aProp )
1247     aProp->Delete();
1248
1249   theActors->Delete();
1250 }
1251
1252 //=================================================================
1253 /*!
1254  *  GEOM_Displayer::BuildPrs
1255  *  Build presentation accordint to the current viewer type
1256  */
1257 //=================================================================
1258 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1259 {
1260   if ( theObj->_is_nil() )
1261     return 0;
1262
1263   myViewFrame = GetActiveView();
1264   if ( myViewFrame == 0 )
1265     return 0;
1266
1267   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1268   if ( aPrs == 0 )
1269     return 0;
1270
1271   internalReset();
1272   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1273   myType = theObj->GetType();
1274
1275   // Update presentation
1276   UpdatePrs( aPrs );
1277
1278   return aPrs;
1279 }
1280
1281 //=================================================================
1282 /*!
1283  *  GEOM_Displayer::BuildPrs
1284  *  Build presentation accordint to the current viewer type
1285  */
1286 //=================================================================
1287 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1288 {
1289   myViewFrame = GetActiveView();
1290   if ( theShape.IsNull() || myViewFrame == 0 )
1291     return 0;
1292
1293   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1294   if ( aPrs == 0 )
1295     return 0;
1296
1297   internalReset();
1298   setShape( theShape );
1299   myType = -1;
1300
1301   UpdatePrs( aPrs );
1302
1303   return aPrs;
1304 }
1305
1306 //=================================================================
1307 /*!
1308  *  GEOM_Displayer::buildPresentation
1309  *  Builds/finds object's presentation for the current viewer
1310  *  Calls corresponding Update() method by means of double dispatch
1311  *  [ internal ]
1312  */
1313 //=================================================================
1314 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1315                                                SALOME_View* theViewFrame )
1316 {
1317   SALOME_Prs* prs = 0;
1318   internalReset();
1319
1320   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1321
1322   if ( myViewFrame )
1323   {
1324     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1325     if ( prs )
1326     {
1327       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1328       theIO->setEntry( entry.toLatin1().constData() );
1329       if ( !theIO.IsNull() )
1330       {
1331         // set interactive object
1332         setIO( theIO );
1333         //  Find SOBject (because shape should be published previously)
1334         SUIT_Session* session = SUIT_Session::session();
1335         SUIT_Application* app = session->activeApplication();
1336         if ( app )
1337         {
1338           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1339           if ( study )
1340           {
1341             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1342             if ( SO )
1343             {
1344               // get CORBA reference to data object
1345               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1346               if ( !CORBA::is_nil( object ) )
1347               {
1348                 // downcast to GEOM object
1349                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1350                 if ( !GeomObject->_is_nil() )
1351                 {
1352                   // finally set shape
1353                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1354                   myType = GeomObject->GetType();
1355                 }
1356               }
1357             }
1358           }
1359         }
1360       }
1361       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1362     }
1363   }
1364   return prs;
1365 }
1366
1367 //=================================================================
1368 /*!
1369  *  GEOM_Displayer::buildSubshapePresentation
1370  *  Builds/finds object's presentation for the current viewer
1371  *  Calls corresponding Update() method by means of double dispatch
1372  *  For not published objects (for Mantis issue 0020435)
1373  */
1374 //=================================================================
1375 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1376                                                       const QString& entry,
1377                                                       SALOME_View* theViewFrame)
1378 {
1379   SALOME_Prs* prs = 0;
1380   internalReset();
1381
1382   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1383
1384   if (myViewFrame)
1385   {
1386     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1387     if (prs)
1388     {
1389       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1390       theIO->setEntry(entry.toLatin1().constData());
1391       if (!theIO.IsNull())
1392       {
1393         // set interactive object
1394         setIO(theIO);
1395         // finally set shape
1396         setShape(aShape);
1397         myType = GEOM_SUBSHAPE;
1398       }
1399       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1400     }
1401   }
1402   return prs;
1403 }
1404
1405 //=================================================================
1406 /*!
1407  *  GEOM_Displayer::internalReset
1408  *  Resets internal data
1409  *  [internal]
1410  */
1411 //=================================================================
1412 void GEOM_Displayer::internalReset()
1413 {
1414   myIO.Nullify();
1415   myShape.Nullify();
1416 }
1417
1418 //=================================================================
1419 /*!
1420  *  GEOM_Displayer::LocalSelection
1421  *  Activate selection of CAD shapes with activisation of selection
1422  *  of their sub-shapes (with opened local context for OCC viewer)
1423  */
1424 //=================================================================
1425 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1426 {
1427   SUIT_Session* session = SUIT_Session::session();
1428   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1429   if ( !app )
1430     return;
1431
1432   LightApp_SelectionMgr* sm = app->selectionMgr();
1433
1434   // remove all filters from selection
1435   sm->clearFilters();
1436
1437   SALOME_View* vf = GetActiveView();
1438   if ( vf ) {
1439     if (!theIO.IsNull() && !vf->isVisible(theIO))
1440       Display(theIO);
1441     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1442     vf->LocalSelection( prs, theMode );
1443     delete prs;  // delete presentation because displayer is its owner
1444   }
1445 }
1446
1447 //=================================================================
1448 /*!
1449  *  GEOM_Displayer::globalSelection
1450  *  Activate selection of CAD shapes without activisation of selection
1451  *  of their sub-shapes (without opened local context for OCC viewer)
1452  */
1453 //=================================================================
1454 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1455 {
1456   TColStd_MapOfInteger aModes;
1457   aModes.Add( theMode );
1458   GlobalSelection( aModes, update );
1459 }
1460
1461 //=================================================================
1462 /*!
1463  *  GEOM_Displayer::globalSelection
1464  *  Activate selection of CAD shapes without activisation of selection
1465  *  of their sub-shapes (without opened local context for OCC viewer)
1466  */
1467 //=================================================================
1468 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1469                                       const bool update, const QList<int>* theSubShapes )
1470 {
1471   SUIT_Session* session = SUIT_Session::session();
1472   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1473   if ( !app )
1474     return;
1475
1476   SALOME_View* vf = GetActiveView();
1477   if ( vf == 0 )
1478     return;
1479
1480   // Close local context
1481   vf->GlobalSelection( update );
1482
1483   // Set selection filters in accordance with current mode
1484   LightApp_SelectionMgr* sm = app->selectionMgr();
1485   if ( !sm )
1486     return;
1487
1488   // Remove from selection temporary objects if necessary
1489   if ( !theModes.Contains( GEOM_PREVIEW ) )
1490     clearTemporary( sm );
1491
1492   //@ aSel->ClearIndex();
1493
1494   sm->clearFilters();
1495
1496   // Remove filters from AIS_InteractiveContext
1497   Handle(AIS_InteractiveContext) ic;
1498   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1499   if ( viewer )
1500     {
1501       ic = viewer->getAISContext();
1502       if ( !ic.IsNull() )
1503         ic->RemoveFilters();
1504     }
1505
1506   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1507     return;
1508
1509   SUIT_SelectionFilter* aFilter;
1510   if ( theModes.Extent() == 1 )
1511     {
1512       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1513
1514       if ( aMode == GEOM_COMPOUNDFILTER )
1515         aFilter = getComplexFilter( theSubShapes );
1516       else
1517         aFilter = getFilter( aMode );
1518     }
1519   else if ( theModes.Extent() > 1 )
1520     {
1521       TColStd_MapOfInteger aTopAbsModes;
1522       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1523       QList<SUIT_SelectionFilter*> aListOfFilters;
1524       for ( ; anIter.More(); anIter.Next() )
1525         {
1526           SUIT_SelectionFilter* aFilter;
1527           int aMode = anIter.Key();
1528           if ( aMode == GEOM_COMPOUNDFILTER )
1529             aFilter = getComplexFilter( theSubShapes );
1530           else
1531             aFilter = getFilter( aMode );
1532
1533           if ( aFilter )
1534             aListOfFilters.append( aFilter );
1535         }
1536
1537       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1538     }
1539   else
1540     return;
1541
1542   if ( aFilter )
1543     {
1544       sm->installFilter( aFilter );
1545       if ( !ic.IsNull() )
1546         {
1547           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1548           ic->AddFilter( anOCCFilter );
1549         }
1550     }
1551 }
1552
1553 //=================================================================
1554 /*!
1555  *  GEOM_Displayer::LocalSelection
1556  *  Activate selection of CAD shapes with activisation of selection
1557  *  of their sub-shapes (with opened local context for OCC viewer)
1558  */
1559 //=================================================================
1560 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1561 {
1562   SALOME_ListIteratorOfListIO Iter( theIOList );
1563   for ( ; Iter.More(); Iter.Next() )
1564     LocalSelection( Iter.Value(), theMode );
1565 }
1566
1567 //=================================================================
1568 /*!
1569  *  GEOM_Displayer::BeforeDisplay
1570  *  Called before displaying of pars. Close local context
1571  *  [ Reimplemented from SALOME_Displayer ]
1572  */
1573 //=================================================================
1574 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1575 {
1576   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1577   if ( vf )
1578   {
1579     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1580     if ( !ic.IsNull() )
1581     {
1582       if ( ic->HasOpenedContext() )
1583       ic->CloseAllContexts();
1584     }
1585   }
1586 }
1587
1588 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1589 {
1590   SalomeApp_Study* aStudy = getStudy();
1591   if (!aStudy) return;
1592   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1593   if ( vf && !p->IsNull() ) {
1594     int aMgrId = getViewManagerId( vf );
1595     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1596     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1597     if ( !ic.IsNull() && prs ) {
1598       AIS_ListOfInteractive objects;
1599       prs->GetObjects( objects );
1600       AIS_ListIteratorOfListOfInteractive it( objects );
1601       for ( ; it.More(); it.Next() ) {
1602         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1603         if ( sh.IsNull() ) continue;
1604         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1605         if ( IO.IsNull() ) continue;
1606         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1607         if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1608           double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1609           ic->SetTransparency( sh, transparency, true );
1610         }
1611       }
1612     }
1613   }
1614 }
1615
1616 //=================================================================
1617 /*!
1618  *  GEOM_Displayer::SetColor
1619  *  Set color for shape displaying. If it is equal -1 then default color is used.
1620  *  Available values are from Quantity_NameOfColor enumeration
1621  */
1622 //=================================================================
1623 void GEOM_Displayer::SetColor( const int color )
1624 {
1625   if ( color == -1 )
1626     UnsetColor();
1627   else
1628   {
1629     myColor = color;
1630     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1631   }
1632 }
1633
1634 int GEOM_Displayer::GetColor() const
1635 {
1636   return myColor;
1637 }
1638
1639 bool GEOM_Displayer::HasColor() const
1640 {
1641   return myColor != -1;
1642 }
1643
1644 void GEOM_Displayer::UnsetColor()
1645 {
1646   myColor = -1;
1647
1648   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1649   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1650   myShadingColor = SalomeApp_Tools::color( col );
1651 }
1652
1653 //=================================================================
1654 /*!
1655  *  GEOM_Displayer::SetTexture
1656  *  Set color for shape displaying. If it is equal -1 then default color is used.
1657  *  Available values are from Quantity_NameOfColor enumeration
1658  */
1659 //=================================================================
1660 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1661 {
1662   if(texureFileName!="")
1663   {
1664     myTexture = texureFileName;
1665   }
1666 }
1667
1668 bool GEOM_Displayer::HasTexture() const
1669 {
1670   return myTexture != "";
1671 }
1672
1673 std::string GEOM_Displayer::GetTexture() const
1674 {
1675   return myTexture;
1676 }
1677
1678 //=================================================================
1679 /*!
1680  *  GEOM_Displayer::SetWidth
1681  *  Set width of shape displaying. If it is equal -1 then default width is used.
1682  */
1683 //=================================================================
1684 void GEOM_Displayer::SetWidth( const double width )
1685 {
1686   myWidth = width;
1687 }
1688
1689 double GEOM_Displayer::GetWidth() const
1690 {
1691   return myWidth;
1692 }
1693
1694 bool GEOM_Displayer::HasWidth() const
1695 {
1696   return myWidth != -1;
1697 }
1698
1699 void GEOM_Displayer::UnsetWidth()
1700 {
1701   myWidth = -1;
1702 }
1703
1704
1705 int GEOM_Displayer::GetIsosWidth() const
1706 {
1707   return myIsosWidth;
1708 }
1709
1710 void GEOM_Displayer::SetIsosWidth(const int width) 
1711 {
1712   myIsosWidth = width;
1713 }
1714
1715 bool GEOM_Displayer::HasIsosWidth() const
1716 {
1717   return myIsosWidth != -1;
1718 }
1719
1720
1721 //=================================================================
1722 /*!
1723  *  GEOM_Displayer::SetToActivate
1724  *  This method is used for activisation/deactivisation of objects to be displayed
1725  */
1726 //=================================================================
1727 void GEOM_Displayer::SetToActivate( const bool toActivate )
1728 {
1729   myToActivate = toActivate;
1730 }
1731 bool GEOM_Displayer::ToActivate() const
1732 {
1733   return myToActivate;
1734 }
1735
1736 //=================================================================
1737 /*!
1738  *  GEOM_Displayer::clearTemporary
1739  *  Removes from selection temporary objects
1740  */
1741 //=================================================================
1742 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1743 {
1744   SALOME_ListIO selected, toSelect;
1745   theSelMgr->selectedObjects( selected );
1746
1747   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1748     Handle(SALOME_InteractiveObject) io = it.Value();
1749     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1750       toSelect.Append( it.Value() );
1751   }
1752
1753   theSelMgr->setSelectedObjects( toSelect, true );
1754 }
1755
1756 void GEOM_Displayer::SetName( const char* theName )
1757 {
1758   myName = theName;
1759 }
1760
1761 void GEOM_Displayer::UnsetName()
1762 {
1763   myName = "";
1764 }
1765
1766 SalomeApp_Study* GEOM_Displayer::getStudy() const
1767 {
1768   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1769 }
1770
1771 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1772 {
1773   myIO = theIO;
1774 }
1775
1776 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1777 {
1778   myShape = theShape;
1779 }
1780
1781 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1782 {
1783   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1784 }
1785
1786 int GEOM_Displayer::SetDisplayMode( const int theMode )
1787 {
1788   int aPrevMode = myDisplayMode;
1789   if ( theMode != -1 )
1790     myDisplayMode = theMode;
1791   else
1792   {
1793     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1794     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1795   }
1796   return aPrevMode;
1797 }
1798
1799 int GEOM_Displayer::GetDisplayMode() const
1800 {
1801   return myDisplayMode;
1802 }
1803
1804 int GEOM_Displayer::UnsetDisplayMode()
1805 {
1806   int aPrevMode = myDisplayMode;
1807   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1808   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1809   return aPrevMode;
1810 }
1811
1812 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1813 {
1814   int aHue = -1;
1815   int aTolerance = 64;
1816   int anIterations = 0;
1817   int aPeriod = 5;
1818
1819   while( 1 )
1820   {
1821     anIterations++;
1822     if( anIterations % aPeriod == 0 )
1823     {
1824       aTolerance /= 2;
1825       if( aTolerance < 1 )
1826         break;
1827     }
1828     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1829
1830     aHue = (int)( 360.0 * rand() / RAND_MAX );
1831     //std::cout << "Hue = " << aHue << std::endl;
1832
1833     //std::cout << "Auto colors : ";
1834     bool ok = true;
1835     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1836     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1837     for( ; it != itEnd; ++it )
1838     {
1839       SALOMEDS::Color anAutoColor = *it;
1840       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1841
1842       int h, s, v;
1843       aQColor.getHsv( &h, &s, &v );
1844       //std::cout << h << " ";
1845       if( abs( h - aHue ) < aTolerance )
1846       {
1847         ok = false;
1848         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1849         break;
1850       }
1851     }
1852     //std::cout << std::endl;
1853
1854     if( ok )
1855       break;
1856   }
1857
1858   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1859   QColor aColor;
1860   aColor.setHsv( aHue, 255, 255 );
1861
1862   SALOMEDS::Color aSColor;
1863   aSColor.R = (double)aColor.red() / 255.0;
1864   aSColor.G = (double)aColor.green() / 255.0;
1865   aSColor.B = (double)aColor.blue() / 255.0;
1866
1867   return aSColor;
1868 }
1869
1870
1871
1872 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1873   PropMap aDefaultMap;
1874   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1875   //1. Visibility
1876   aDefaultMap.insert(VISIBILITY_PROP , 1);
1877
1878   //2. Nb Isos
1879   int anUIsoNumber;
1880   int aVIsoNumber;
1881   if(viewer_type == SOCC_Viewer::Type()) {
1882     anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1883     aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1884   } else if( viewer_type==SVTK_Viewer::Type()) {
1885     anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1886     aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1887   }
1888   QString anIsos("%1%2%3");
1889   anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1890   aDefaultMap.insert(ISOS_PROP , anIsos);
1891
1892   //3. Transparency
1893   aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1894
1895   //4. Display Mode
1896   aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1897
1898   //5. Vector Mode
1899   aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1900
1901   //6. Color
1902   QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1903   aDefaultMap.insert( COLOR_PROP , col);
1904
1905   //7. Deflection Coeff
1906   double aDC;
1907
1908   if(viewer_type == SOCC_Viewer::Type()) {
1909     aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1910   } else if( viewer_type==SVTK_Viewer::Type()) {
1911     aDC = 0.001;
1912   }
1913
1914   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1915
1916   //8. Material
1917   Material_Model material;
1918   QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1919   material.fromResources( mname );
1920   aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );  
1921
1922   //9. Width of the edges
1923   aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1924
1925
1926   //10. Width of iso-lines
1927   aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1928
1929   if(viewer_type == SOCC_Viewer::Type()) {
1930
1931     aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1932   }
1933
1934   return aDefaultMap;
1935 }
1936
1937 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1938   int nbInserted = 0;
1939   if(!theOrigin.contains(VISIBILITY_PROP)) {
1940     theOrigin.insert(VISIBILITY_PROP, 0);
1941     nbInserted++;
1942   }
1943   if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1944     theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1945     nbInserted++;
1946   }
1947   if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1948     theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1949     nbInserted++;
1950   }
1951   if(!theOrigin.contains(ISOS_PROP)) {
1952     theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1953     nbInserted++;
1954   }
1955   if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1956     theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1957     nbInserted++;
1958   }
1959   if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1960     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1961     nbInserted++;
1962   }
1963   if(!theOrigin.contains(MATERIAL_PROP)) {
1964     theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1965     nbInserted++;
1966   }
1967
1968   if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1969     theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1970     nbInserted++;
1971   }
1972
1973   if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1974     theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1975     nbInserted++;
1976   }
1977
1978   if(!theOrigin.contains(COLOR_PROP)) {
1979     theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1980     nbInserted++;
1981   }
1982
1983   return (nbInserted > 0);
1984 }
1985
1986
1987 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1988   SALOMEDS::Color aSColor;
1989   hasColor = false;
1990
1991   SUIT_Session* session = SUIT_Session::session();
1992   SUIT_Application* app = session->activeApplication();
1993
1994   if ( app && !theGeomObject->_is_nil()) {
1995     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1996
1997     if ( study ) {
1998       aSColor = theGeomObject->GetColor();
1999       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2000       if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2001         GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2002         GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2003         GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2004         if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2005           {
2006             QList<SALOMEDS::Color> aReservedColors;
2007
2008             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2009             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2010             if ( strcmp(IOR.in(), "") != 0 )
2011               {
2012                 _PTR(Study) aStudy = study->studyDS();
2013                 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2014                 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2015                 for( ; it->More(); it->Next() )
2016                   {
2017                     _PTR(SObject) aChildSObject( it->Value() );
2018                     GEOM::GEOM_Object_var aChildObject =
2019                       GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2020                     if( CORBA::is_nil( aChildObject ) )
2021                       continue;
2022
2023                     if( aChildObject->GetType() != GEOM_GROUP )
2024                       continue;
2025
2026                     SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2027                     aReservedColors.append( aReservedColor );
2028                   }
2029               }
2030
2031             aSColor = getUniqueColor( aReservedColors );
2032             hasColor = true;
2033           }
2034       }
2035     }
2036   }
2037   return aSColor;
2038 }
2039
2040
2041 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2042                                        const bool eraseOnlyChildren) {
2043   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2044   if ( !app )
2045     return;
2046
2047   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2048   if ( !appStudy )
2049     return;
2050
2051   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2052
2053   if( !parent)
2054     return;
2055
2056   // Erase from all views
2057   QList<SALOME_View*> views;
2058   SALOME_View* view;
2059   ViewManagerList vmans = app->viewManagers();
2060   SUIT_ViewManager* vman;
2061   foreach ( vman, vmans ) {
2062     SUIT_ViewModel* vmod = vman->getViewModel();
2063     view = dynamic_cast<SALOME_View*> ( vmod );
2064     if ( view )
2065       views.append( view );
2066   }
2067
2068   if( views.count() == 0 )
2069     return;
2070
2071   //Erase childrens w/o update views
2072   DataObjectList listObj = parent->children( true );
2073   SUIT_DataObject* obj;
2074   foreach( obj, listObj ) {
2075     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2076     if(l_obj)
2077       foreach ( view, views ) {
2078       Handle(SALOME_InteractiveObject) anIO =
2079         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2080       Erase(anIO, false, false, view);
2081     }
2082   }
2083
2084   //Erase parent with view update or repaint views
2085   foreach ( view, views ) {
2086     if(!eraseOnlyChildren)
2087       Erase(theIO, false, true, view);
2088     else
2089       view->Repaint();
2090   }
2091 }