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