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