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