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