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