]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
Bug fixes.
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GEOM_Displayer.cxx
25 //  Author : Vadim SANDLER
26 //  Module : GEOM
27 //  $Header$
28
29 #include <SOCC_ViewModel.h>
30
31 #include "GEOM_Displayer.h"
32 #include "GEOMImpl_Types.hxx"
33
34 #include "GEOM_TypeFilter.h"
35 #include "GEOM_EdgeFilter.h"
36 #include "GEOM_FaceFilter.h"
37 #include "GEOM_PreviewFilter.h"
38 #include "GEOM_LogicalFilter.h"
39 #include "GEOM_OCCFilter.h"
40
41 #include "GEOM_AssemblyBuilder.h"
42 #include "GEOM_Actor.h"
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_Tools.h>
50 #include <SUIT_ViewManager.h>
51
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_SelectionMgr.h>
55 #include <SalomeApp_TypeFilter.h>
56 #include <SalomeApp_Tools.h>
57
58 #include <SALOME_ListIteratorOfListIO.hxx>
59 #include <SALOMEDSClient.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
62
63 #include <SOCC_Prs.h>
64
65 #include <SVTK_Prs.h>
66 #include <SVTK_ViewModel.h>
67
68 #include <TColStd_MapOfInteger.hxx>
69 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
70
71 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
72
73 #include <GeometryGUI.h>
74 #include <GEOM_AISShape.hxx>
75 #include <AIS_ListIteratorOfListOfInteractive.hxx>
76 #include <AIS_Drawer.hxx>
77 #include <Prs3d_PointAspect.hxx>
78 #include <Graphic3d_AspectMarker3d.hxx>
79 #include <Geom_Plane.hxx>
80 #include <TopoDS_Face.hxx>
81 #include <BRep_Tool.hxx>
82 #include <gp_Pln.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <StdSelect_TypeOfEdge.hxx>
85 #include <StdSelect_TypeOfFace.hxx>
86 #include <vtkActorCollection.h>
87
88 #include <cstring>
89
90 using namespace std;
91
92 //================================================================
93 // Function : getActiveStudy
94 // Purpose  : Get active study, returns 0 if no open study frame
95 //================================================================
96 static inline SalomeApp_Study* getActiveStudy()
97 {
98   SUIT_Session* session = SUIT_Session::session();
99   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
100   if ( app )
101     return ( SalomeApp_Study* )app->activeStudy();
102   return 0;
103 }
104
105 //================================================================
106 // Function : getTopAbsMode
107 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
108 //            one from GEOMImpl_Types.h
109 //================================================================
110 static inline int getTopAbsMode( const int implType )
111 {
112   switch ( implType )
113   {
114     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
115     case GEOM_SOLID     : return TopAbs_SOLID;
116     case GEOM_SHELL     : return TopAbs_SHELL;
117     case GEOM_FACE      : return TopAbs_FACE;
118     case GEOM_WIRE      : return TopAbs_WIRE;
119     case GEOM_EDGE      : return TopAbs_EDGE;
120     case GEOM_POINT     : return TopAbs_VERTEX;
121     default             : return -1;
122   }
123 }
124
125 //================================================================
126 // Function : getFilter
127 // Purpose  : Get filter corresponding to the type of object
128 //            from GEOMImpl_Types.h
129 //================================================================
130 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
131 {
132   SUIT_SelectionFilter* aFilter;
133   
134   int aTopAbsMode = getTopAbsMode( theMode );
135   if ( aTopAbsMode != -1 )
136     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
137   else
138     switch ( theMode )
139       {
140       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
141       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
142         
143       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
144       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
145       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
146       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
147       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
148       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
149         
150       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
151         
152       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
153       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
154         
155       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
156       }
157   
158   return aFilter;
159 }
160
161 //================================================================
162 // Function : getEntry
163 // Purpose  :
164 //================================================================
165 static char* getEntry( GEOM::GEOM_Object_ptr object )
166 {
167   SUIT_Session* session = SUIT_Session::session();
168   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
169   if ( app ) 
170   {
171     string IOR = app->orb()->object_to_string( object );
172     if ( IOR != "" ) 
173     {
174       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
175       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
176       if ( SO )
177         return (char*)(SO->GetID().c_str());
178     }
179   }
180   return "";
181 }
182
183 //================================================================
184 // Function : getName
185 // Purpose  :
186 //================================================================
187 static const char* getName( GEOM::GEOM_Object_ptr object )
188 {
189   SUIT_Session* session = SUIT_Session::session();
190   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
191   if ( app ) 
192   {
193     string IOR = app->orb()->object_to_string( object );
194     if ( IOR != "" ) 
195     {
196       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
197       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
198
199       _PTR(GenericAttribute) anAttr;
200
201       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
202       {
203         _PTR(AttributeName) aNameAttr( anAttr );
204         return aNameAttr->Value().c_str();
205       }
206     }
207   }
208
209   return "";
210 }
211
212 //=================================================================
213 /*!
214  *  GEOM_Displayer::GEOM_Displayer
215  *  Constructor
216  */
217 //=================================================================
218 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study )
219 {
220   myStudy = study;
221   
222   /* Shading Color */
223   SUIT_Session* session = SUIT_Session::session();
224   SUIT_ResourceMgr* resMgr = session->resourceMgr();
225
226   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
227   myShadingColor = SalomeApp_Tools::color( col );
228
229   myColor = -1;
230   // This color is used for shape displaying. If it is equal -1 then
231   // default color is used.
232
233   myWidth = -1;
234   myType = -1;
235
236   myToActivate = true;
237   // This parameter is used for activisation/deactivisation of objects to be displayed
238
239   myViewFrame = 0;
240 }
241
242 //=================================================================
243 /*!
244  *  GEOM_Displayer::~GEOM_Displayer
245  *  Destructor
246  */
247 //=================================================================
248 GEOM_Displayer::~GEOM_Displayer()
249 {
250 }
251
252 //=================================================================
253 /*!
254  *  GetActiveView
255  *  Get active study frame, returns 0 if no open study frame
256  */
257 //=================================================================
258 SALOME_View* GEOM_Displayer::GetActiveView()
259 {
260   SUIT_Session* session = SUIT_Session::session();
261   SUIT_Application* app = session->activeApplication();
262   if ( app )
263   {
264     SUIT_Desktop* desk = app->desktop();
265     if ( desk )
266     {
267       SUIT_ViewWindow* win = desk->activeWindow(); 
268       if ( win ) 
269       {
270         SUIT_ViewManager* vman = win->getViewManager();
271         if ( vman )
272         {
273           SUIT_ViewModel* vmodel = vman->getViewModel();
274           if ( vmodel )
275           {
276             SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
277             return view;
278           }
279         }
280       }
281     }
282   }
283   return 0;
284 }
285
286 //=================================================================
287 /*!
288  *  GEOM_Displayer::Display
289  *  Display interactive object in the current viewer
290  */
291 //=================================================================
292 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, 
293                              const bool updateViewer,
294                              SALOME_View* theViewFrame )
295 {
296   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
297   if ( vf )
298   {
299     SALOME_Prs* prs = buildPresentation( theIO, vf );
300     
301     if ( prs )
302     {
303       vf->BeforeDisplay( this );
304       vf->Display( prs );
305       vf->AfterDisplay( this );
306
307       if ( updateViewer )
308         vf->Repaint();
309       
310       delete prs;  // delete presentation because displayer is its owner
311     }
312   }
313 }
314
315 //=================================================================
316 /*!
317  *  GEOM_Displayer::Display
318  *  This overloaded Display() method can be useful for operations
319  *  not using dialog boxes.
320  */
321 //=================================================================
322 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
323 {
324   if ( theObj->_is_nil() )
325     return;
326
327   string entry = getEntry( theObj );
328   if ( entry != "" ) {
329     Display( new SALOME_InteractiveObject(
330       entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
331   }
332 }
333
334 //=================================================================
335 /*!
336  *  GEOM_Displayer::Erase
337  *  Erase interactive object in the current viewer
338  */
339 //=================================================================
340 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
341                             const bool forced,
342                             const bool updateViewer,
343                             SALOME_View* theViewFrame )
344 {
345   if ( theIO.IsNull() )
346     return;
347
348   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
349   
350   if ( vf ) {
351     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
352     if ( prs ) {
353       vf->Erase( prs, forced );
354       if ( updateViewer )
355         vf->Repaint();
356       delete prs;  // delete presentation because displayer is its owner
357     }
358   }
359 }
360
361 //=================================================================
362 /*!
363  *  GEOM_Displayer::Erase
364  *  Erase geometry object in the current viewer
365  */
366 //=================================================================
367 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
368                             const bool forced,
369                             const bool updateViewer )
370 {
371   string entry = getEntry( theObj );
372   if ( entry != "" )
373   {
374     Erase( new SALOME_InteractiveObject(
375       entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
376   }
377 }
378
379 //=================================================================
380 /*!
381  *  GEOM_Displayer::EraseAll
382  *  Erase all objects in the current viewer
383  */
384 //=================================================================
385 void GEOM_Displayer::EraseAll ( const bool forced,
386                                 const bool updateViewer,
387                                 SALOME_View* theViewFrame )
388 {
389   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
390   
391   if ( vf ) {
392     vf->EraseAll( forced );
393     if ( updateViewer )
394       vf->Repaint();
395   }
396 }
397
398 //=================================================================
399 /*!
400  *  GEOM_Displayer::Redisplay
401  *  Redisplay (erase and then display again) interactive object
402  *  in the current viewer
403  */
404 //=================================================================
405 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
406                                 const bool updateViewer )
407 {
408   // Remove the object permanently (<forced> == true)
409   SUIT_Session* ses = SUIT_Session::session();
410   SUIT_Application* app = ses->activeApplication();
411   if ( app )
412   {
413     SUIT_Desktop* desk = app->desktop();
414     QPtrList<SUIT_ViewWindow> wnds = desk->windows();
415     SUIT_ViewWindow* wnd;
416     for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
417     {
418       SUIT_ViewManager* vman = wnd->getViewManager();
419       if ( vman )
420       {
421         SUIT_ViewModel* vmodel = vman->getViewModel();
422         if ( vmodel )
423         {
424           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
425           if ( view )
426           {
427             if ( view->isVisible( theIO ) || view == GetActiveView() )
428             {
429               Erase( theIO, true, false, view );
430               Display( theIO, updateViewer, view );
431             }
432           }
433         }
434       }
435     }
436   }
437 }
438
439 //=================================================================
440 /*!
441  *  GEOM_Displayer::Display
442  *  Calls Display() method for each object in the given list
443  */
444 //=================================================================
445 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
446 {
447   SALOME_ListIteratorOfListIO Iter( theIOList );
448   for ( ; Iter.More(); Iter.Next() ) {
449     Display( Iter.Value(), false );
450   }
451   if ( updateViewer )
452     UpdateViewer();
453 }
454
455 //=================================================================
456 /*!
457  *  GEOM_Displayer::Erase
458  *  Calls Erase() method for each object in the given list
459  */
460 //=================================================================
461 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
462                             const bool forced,
463                             const bool updateViewer )
464 {
465   SALOME_ListIteratorOfListIO Iter( theIOList );
466   for ( ; Iter.More(); Iter.Next() )
467     Erase( Iter.Value(), forced, false );
468
469   if ( updateViewer )
470     UpdateViewer();
471 }
472
473 //=================================================================
474 /*!
475  *  GEOM_Displayer::Redisplay
476  *  Calls Redisplay() method for each object in the given list
477  */
478 //=================================================================
479 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
480 {
481   SALOME_ListIteratorOfListIO Iter( theIOList );
482   for ( ; Iter.More(); Iter.Next() )
483     Redisplay( Iter.Value(), false );
484
485   if ( updateViewer )
486     UpdateViewer();
487 }
488
489 //=================================================================
490 /*!
491  *  GEOM_Displayer::UpdateViewer
492  *  Update current viewer
493  */
494 //=================================================================
495 void GEOM_Displayer::UpdateViewer()
496 {
497   SALOME_View* vf = GetActiveView();
498   if ( vf )
499     vf->Repaint();
500 }
501
502 //=================================================================
503 /*!
504  *  GEOM_Displayer::Update
505  *  Update OCC presentaion
506  *  [ Reimplemented from SALOME_Displayer ]
507  */
508 //=================================================================
509 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
510 {
511   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
512   if ( !occPrs )
513     return;
514
515   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
516   {
517     TopoDS_Face aFace = TopoDS::Face( myShape );
518     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
519     if ( !aPlane.IsNull() )
520     {
521       gp_Ax3 aPos = aPlane->Pln().Position();
522       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
523
524       Handle(GEOM_AISTrihedron) aTrh;
525
526       if ( occPrs->IsNull() )
527       {
528         aTrh = new GEOM_AISTrihedron( aPlc );
529
530         if ( HasColor() )  
531           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
532
533         if ( HasWidth() )
534           aTrh->SetWidth( GetWidth() );
535
536         if ( !myIO.IsNull() )
537         {
538           aTrh->setIO( myIO );
539           aTrh->SetOwner( myIO );
540         }
541
542         occPrs->AddObject( aTrh );
543       }
544       else
545       {
546         AIS_ListOfInteractive aList;
547         occPrs->GetObjects( aList );
548         AIS_ListIteratorOfListOfInteractive anIter( aList );
549         for ( ; anIter.More(); anIter.Next() )
550         {
551           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
552           if ( !aTrh.IsNull() )
553           {
554             aTrh->SetComponent( aPlc );
555             aTrh->SetToUpdate();            
556           }
557         }
558       }
559
560       occPrs->SetToActivate( ToActivate() );
561     }
562   }
563   else
564   {
565     // if presentation is empty we try to create new one
566     if ( occPrs->IsNull() )
567     {
568       if ( !myShape.IsNull() )
569       {
570         Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
571         // Temporary staff: vertex must be infinite for correct visualization
572         AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
573
574         // Setup shape properties here ..., e.g. display mode, color, transparency, etc
575         AISShape->SetShadingColor( myShadingColor );
576         if ( HasColor() )
577         {
578           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
579           if ( myShape.ShapeType() == TopAbs_VERTEX )
580           {
581             Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
582             anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
583             AISShape->Attributes()->SetPointAspect( anAspect );
584           }
585         }
586
587         if ( HasWidth() )
588           AISShape->SetWidth( GetWidth() );
589
590         if ( !myIO.IsNull() )
591         {
592           AISShape->setIO( myIO );
593           AISShape->SetOwner( myIO );
594         }
595         else if ( !myName.empty() )
596         {
597           // Workaround to allow selection of temporary objects
598           static int tempId = 0;
599           char buf[50];
600           sprintf( buf, "TEMP_%d", tempId++ );
601           Handle( SALOME_InteractiveObject ) anObj =
602             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
603           AISShape->setIO( anObj );
604           AISShape->SetOwner( anObj );
605         }
606         // AISShape->SetName(???); ??? necessary to set name ???
607         occPrs->AddObject( AISShape );
608
609         // In accordance with ToActivate() value object will be activated/deactivated
610         // when it will be displayed
611         occPrs->SetToActivate( ToActivate() );
612       }
613     }
614     // if presentation is found -> set again shape for it
615     else
616     {
617       if ( !myShape.IsNull() )
618       {
619         AIS_ListOfInteractive IOList;
620         occPrs->GetObjects( IOList );
621         AIS_ListIteratorOfListOfInteractive Iter( IOList );
622         for ( ; Iter.More(); Iter.Next() )
623         {
624           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
625           if ( AISShape.IsNull() )
626             continue;
627           if ( AISShape->Shape() != myShape )
628           {
629             AISShape->Set( myShape );
630             AISShape->UpdateSelection();
631             AISShape->SetToUpdate();
632           }
633           if ( !myIO.IsNull() )
634           {
635             AISShape->setIO( myIO );
636             AISShape->SetOwner( myIO );
637           }
638         }
639       }
640     }
641   }
642 }
643
644 //=================================================================
645 /*!
646  *  GEOM_Displayer::Update
647  *  Update VTK presentaion
648  *  [ Reimplemented from SALOME_Displayer ]
649  */
650 //=================================================================
651 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
652 {
653   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
654   if ( !vtkPrs || myShape.IsNull() )
655     return;
656
657   vtkActorCollection* theActors = 0;
658   
659   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
660   {
661     myToActivate = false;
662     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
663     
664     if ( HasColor() )
665     {
666       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
667       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
668     }
669
670     Handle(Geom_Plane) aPlane =
671       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
672     if ( aPlane.IsNull() )
673       return;
674
675     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
676     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
677
678 //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
679 //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
680
681     vtkPrs->AddObject( aTrh );
682       
683     theActors = vtkActorCollection::New();
684     theActors->AddItem( aTrh );
685   }
686   else
687     theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
688     
689   theActors->InitTraversal();
690   
691   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
692
693   vtkProperty* aProp = 0;
694
695   if ( HasColor() || HasWidth() )
696   {
697     aProp = vtkProperty::New();
698     aProp->SetRepresentationToWireframe();
699   }
700   
701   if ( HasColor() )
702   {
703     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
704     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
705   }
706
707   if ( HasWidth() )
708   {
709     aProp->SetLineWidth( GetWidth() );
710   }
711
712   while ( anActor != NULL )
713   {
714     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
715     
716     GActor->setIO( myIO );
717
718     if ( aProp )
719     {
720       GActor->SetProperty( aProp );
721       GActor->SetPreviewProperty( aProp );
722
723       GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
724       if ( aGeomGActor != 0 )
725       {
726         aGeomGActor->SetShadingProperty( aProp );
727         aGeomGActor->SetWireframeProperty( aProp );
728       }
729     }
730
731     if ( myToActivate )
732       GActor->PickableOn();
733     else
734       GActor->PickableOff();
735       
736     vtkPrs->AddObject( GActor );
737     
738     anActor = (vtkActor*)theActors->GetNextActor();
739   }
740
741   if ( aProp )
742     aProp->Delete();
743
744   theActors->Delete();
745 }
746
747 //=================================================================
748 /*!
749  *  GEOM_Displayer::BuildPrs
750  *  Build presentation accordint to the current viewer type
751  */
752 //=================================================================
753 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
754 {
755   if ( theObj->_is_nil() )
756     return 0;
757
758   myViewFrame = GetActiveView();
759   if ( myViewFrame == 0 )
760     return 0;
761   
762   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
763   if ( aPrs == 0 )
764     return 0;
765
766   internalReset();  
767   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
768   myType = theObj->GetType();
769
770   // Update presentation
771   UpdatePrs( aPrs );  
772
773   return aPrs;
774 }
775
776 //=================================================================
777 /*!
778  *  GEOM_Displayer::BuildPrs
779  *  Build presentation accordint to the current viewer type
780  */
781 //=================================================================
782 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
783 {
784   myViewFrame = GetActiveView();
785   if ( theShape.IsNull() || myViewFrame == 0 )
786     return 0;
787
788   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
789   if ( aPrs == 0 )
790     return 0;
791
792   internalReset();
793   setShape( theShape );
794   myType = -1;
795
796   UpdatePrs( aPrs );
797
798   return aPrs;
799 }
800
801 //=================================================================
802 /*!
803  *  GEOM_Displayer::buildPresentation
804  *  Builds/finds object's presentation for the current viewer
805  *  Calls corresponding Update() method by means of double dispatch
806  *  [ internal ]      
807  */
808 //=================================================================
809 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO, 
810                                                SALOME_View* theViewFrame )
811 {
812   SALOME_Prs* prs = 0;
813   internalReset();
814
815   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
816   
817   if ( myViewFrame ) 
818   {
819     prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
820     if ( prs ) 
821     {
822       if ( !theIO.IsNull() ) 
823       {
824         // set interactive object
825         setIO( theIO );
826         //  Find SOBject (because shape should be published previously)
827         SUIT_Session* session = SUIT_Session::session();
828         SUIT_Application* app = session->activeApplication();
829         if ( app ) 
830         {
831           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
832           if ( study )
833           {
834             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
835             if ( SO ) 
836             {
837               // get CORBA reference to data object
838               CORBA::Object_var object = dynamic_cast<SALOMEDS_SObject*>(SO.get())->GetObject();
839               if ( !CORBA::is_nil( object ) ) 
840               {
841                 // downcast to GEOM object
842                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
843                 if ( !GeomObject->_is_nil() ) 
844                 {
845                   // finally set shape
846                   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
847                   myType = GeomObject->GetType();
848                 }
849               }
850             }
851           }
852         }
853       }
854       UpdatePrs( prs );  // Update presentation by using of the double dispatch
855     }
856   }
857   return prs;
858 }
859
860 //=================================================================
861 /*!
862  *  GEOM_Displayer::internalReset
863  *  Resets internal data
864  *  [internal]
865  */
866 //=================================================================
867 void GEOM_Displayer::internalReset()
868 {
869   myIO.Nullify();
870   myShape.Nullify();
871 }
872
873 //=================================================================
874 /*!
875  *  GEOM_Displayer::LocalSelection
876  *  Activate selection of CAD shapes with activisation of selection
877  *  of their sub-shapes (with opened local context for OCC viewer)
878  */
879 //=================================================================
880 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
881 {
882   SUIT_Session* session = SUIT_Session::session();
883   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
884   if ( !app )
885     return;
886
887   SalomeApp_SelectionMgr* sm = app->selectionMgr();
888  
889   // remove all filters from selection
890   sm->clearFilters();
891
892   SALOME_View* vf = GetActiveView();
893   if ( vf )
894     {
895       SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
896       vf->LocalSelection( prs, theMode );
897       delete prs;  // delete presentation because displayer is its owner
898     }  
899 }
900
901 //=================================================================
902 /*!
903  *  GEOM_Displayer::globalSelection
904  *  Activate selection of CAD shapes without activisation of selection
905  *  of their sub-shapes (without opened local context for OCC viewer)
906  */
907 //=================================================================
908 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
909 {
910   TColStd_MapOfInteger aModes;
911   aModes.Add( theMode );
912   GlobalSelection( aModes, update );
913 }
914
915 //=================================================================
916 /*!
917  *  GEOM_Displayer::globalSelection
918  *  Activate selection of CAD shapes without activisation of selection
919  *  of their sub-shapes (without opened local context for OCC viewer)
920  */
921 //=================================================================
922 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
923                                       const bool update )
924 {
925   SUIT_Session* session = SUIT_Session::session();
926   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
927   if ( !app )
928     return;
929   
930   SALOME_View* vf = GetActiveView();
931   if ( vf == 0 )
932     return;
933   
934   // Close local context
935   vf->GlobalSelection( update );
936
937   // Set selection filters in accordance with current mode
938   SalomeApp_SelectionMgr* sm = app->selectionMgr();
939   if ( !sm )
940     return;
941
942   // Remove from selection temporary objects if necessary
943   if ( !theModes.Contains( GEOM_PREVIEW ) )
944     clearTemporary( sm );
945
946   //@ aSel->ClearIndex();
947     
948   sm->clearFilters();
949  
950   // Remove filters from AIS_InteractiveContext
951   Handle(AIS_InteractiveContext) ic;
952   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
953   if ( viewer )
954     {
955       ic = viewer->getAISContext();
956       if ( !ic.IsNull() )
957         ic->RemoveFilters();
958     }
959   
960   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
961     return;
962
963   SUIT_SelectionFilter* aFilter;
964   if ( theModes.Extent() == 1 )
965     {
966       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
967       aFilter = getFilter( aMode );
968     }
969   else if ( theModes.Extent() > 1 )
970     {
971       TColStd_MapOfInteger aTopAbsModes;
972       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
973       QPtrList<SUIT_SelectionFilter> aListOfFilters;
974       for ( ; anIter.More(); anIter.Next() )
975         {
976           SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
977           if ( aFilter )
978             aListOfFilters.append( aFilter );
979         }
980       
981       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
982     }
983   else
984     return;
985
986   if ( aFilter )
987     {
988       sm->installFilter( aFilter );
989       if ( !ic.IsNull() )
990         {
991           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
992           ic->AddFilter( anOCCFilter );
993         }
994     }
995 }
996
997 //=================================================================
998 /*!
999  *  GEOM_Displayer::LocalSelection
1000  *  Activate selection of CAD shapes with activisation of selection
1001  *  of their sub-shapes (with opened local context for OCC viewer)
1002  */
1003 //=================================================================
1004 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1005 {
1006   SALOME_ListIteratorOfListIO Iter( theIOList );
1007   for ( ; Iter.More(); Iter.Next() ) 
1008     LocalSelection( Iter.Value(), theMode );
1009 }
1010
1011 //=================================================================
1012 /*!
1013  *  GEOM_Displayer::BeforeDisplay
1014  *  Called before displaying of pars. Close local context
1015  *  [ Reimplemented from SALOME_Displayer ]
1016  */
1017 //=================================================================
1018 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1019 {
1020   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1021   if ( vf )
1022   {
1023     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1024     if ( !ic.IsNull() )
1025     {
1026       if ( ic->HasOpenedContext() )
1027       ic->CloseAllContexts();
1028     }
1029   }
1030 }
1031
1032 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1033 {
1034 }
1035
1036
1037 //=================================================================
1038 /*!
1039  *  GEOM_Displayer::SetColor
1040  *  Set color for shape displaying. If it is equal -1 then default color is used.
1041  *  Available values are from Quantity_NameOfColor enumeration
1042  */
1043 //=================================================================
1044 void GEOM_Displayer::SetColor( const int color )
1045 {
1046   myColor = color;
1047 }
1048
1049 int GEOM_Displayer::GetColor() const
1050 {
1051   return myColor;
1052 }
1053
1054 bool GEOM_Displayer::HasColor() const
1055 {
1056   return myColor != -1;
1057 }
1058
1059 void GEOM_Displayer::UnsetColor()
1060 {
1061   myColor = -1;
1062 }
1063
1064 //=================================================================
1065 /*!
1066  *  GEOM_Displayer::SetWidth
1067  *  Set width of shape displaying. If it is equal -1 then default width is used.
1068  */
1069 //=================================================================
1070 void GEOM_Displayer::SetWidth( const double width )
1071 {
1072   myWidth = width;
1073 }
1074
1075 double GEOM_Displayer::GetWidth() const
1076 {
1077   return myWidth;
1078 }
1079
1080 bool GEOM_Displayer::HasWidth() const
1081 {
1082   return myWidth != -1;
1083 }
1084
1085 void GEOM_Displayer::UnsetWidth()
1086 {
1087   myWidth = -1;
1088 }
1089
1090 //=================================================================
1091 /*!
1092  *  GEOM_Displayer::SetToActivate
1093  *  This method is used for activisation/deactivisation of objects to be displayed
1094  */
1095 //=================================================================
1096 void GEOM_Displayer::SetToActivate( const bool toActivate )
1097 {
1098   myToActivate = toActivate;
1099 }
1100 bool GEOM_Displayer::ToActivate() const
1101 {
1102   return myToActivate;
1103 }
1104
1105 //=================================================================
1106 /*!
1107  *  GEOM_Displayer::clearTemporary
1108  *  Removes from selection temporary objects 
1109  */
1110 //=================================================================
1111 void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
1112 {
1113   SALOME_ListIO selected, toSelect;
1114   theSelMgr->selectedObjects( selected );
1115   
1116   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1117     Handle(SALOME_InteractiveObject) io = it.Value();
1118     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 ) 
1119       toSelect.Append( it.Value() );
1120   }
1121   
1122   theSelMgr->setSelectedObjects( toSelect, true );
1123 }
1124