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