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