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