]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
Add two fields in the Geometry preference menu :
[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   myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", 0);
241   myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
242   if(myScaleOfMarker < 1.)
243     myScaleOfMarker = 1.;
244   if(myScaleOfMarker > 8.)
245     myScaleOfMarker = 8.;
246
247
248   myColor = -1;
249   // This color is used for shape displaying. If it is equal -1 then
250   // default color is used.
251
252   myWidth = -1;
253   myType = -1;
254
255   myToActivate = true;
256   // This parameter is used for activisation/deactivisation of objects to be displayed
257
258   myViewFrame = 0;
259 }
260
261 //=================================================================
262 /*!
263  *  GEOM_Displayer::~GEOM_Displayer
264  *  Destructor
265  */
266 //=================================================================
267 GEOM_Displayer::~GEOM_Displayer()
268 {
269 }
270
271 //=================================================================
272 /*!
273  *  GEOM_Displayer::Display
274  *  Display interactive object in the current viewer
275  */
276 //=================================================================
277 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
278                              const bool updateViewer,
279                              SALOME_View* theViewFrame )
280 {
281   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
282   if ( vf )
283   {
284     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
285
286     if ( prs )
287     {
288       vf->BeforeDisplay( this );
289       vf->Display( prs );
290       vf->AfterDisplay( this );
291
292       if ( updateViewer )
293         vf->Repaint();
294
295       delete prs;  // delete presentation because displayer is its owner
296     }
297   }
298 }
299
300 //=================================================================
301 /*!
302  *  GEOM_Displayer::Display
303  *  This overloaded Display() method can be useful for operations
304  *  not using dialog boxes.
305  */
306 //=================================================================
307 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
308 {
309   if ( theObj->_is_nil() )
310     return;
311
312   string entry = getEntry( theObj );
313   if ( entry != "" ) {
314     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
315             updateViewer);
316   }
317 }
318
319 //=================================================================
320 /*!
321  *  GEOM_Displayer::Erase
322  *  Erase interactive object in the current viewer
323  */
324 //=================================================================
325 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
326                             const bool forced,
327                             const bool updateViewer,
328                             SALOME_View* theViewFrame )
329 {
330   if ( theIO.IsNull() )
331     return;
332
333   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
334
335   if ( vf ) {
336     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
337     if ( prs ) {
338       vf->Erase( prs, forced );
339       if ( updateViewer )
340         vf->Repaint();
341       delete prs;  // delete presentation because displayer is its owner
342     }
343   }
344 }
345
346 //=================================================================
347 /*!
348  *  GEOM_Displayer::Erase
349  *  Erase geometry object in the current viewer
350  */
351 //=================================================================
352 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
353                             const bool forced,
354                             const bool updateViewer )
355 {
356   string entry = getEntry( theObj );
357   if ( entry != "" )
358   {
359     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
360           forced, updateViewer);
361   }
362 }
363
364 //=================================================================
365 /*!
366  *  GEOM_Displayer::Redisplay
367  *  Redisplay (erase and then display again) interactive object
368  *  in the current viewer
369  */
370 //=================================================================
371 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
372                                 const bool updateViewer )
373 {
374   // Remove the object permanently (<forced> == true)
375   SUIT_Session* ses = SUIT_Session::session();
376   SUIT_Application* app = ses->activeApplication();
377   if ( app )
378   {
379     SUIT_Desktop* desk = app->desktop();
380     QPtrList<SUIT_ViewWindow> wnds = desk->windows();
381     SUIT_ViewWindow* wnd;
382     for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
383     {
384       SUIT_ViewManager* vman = wnd->getViewManager();
385       if ( vman )
386       {
387         SUIT_ViewModel* vmodel = vman->getViewModel();
388         if ( vmodel )
389         {
390           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
391           if ( view )
392           {
393             if ( view->isVisible( theIO ) || view == GetActiveView() )
394             {
395               Erase( theIO, true, false, view );
396               Display( theIO, updateViewer, view );
397             }
398           }
399         }
400       }
401     }
402   }
403 }
404
405 //=================================================================
406 /*!
407  *  GEOM_Displayer::Display
408  *  Calls Display() method for each object in the given list
409  */
410 //=================================================================
411 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
412 {
413   SALOME_ListIteratorOfListIO Iter( theIOList );
414   for ( ; Iter.More(); Iter.Next() ) {
415     Display( Iter.Value(), false );
416   }
417   if ( updateViewer )
418     UpdateViewer();
419 }
420
421 //=================================================================
422 /*!
423  *  GEOM_Displayer::Erase
424  *  Calls Erase() method for each object in the given list
425  */
426 //=================================================================
427 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
428                             const bool forced,
429                             const bool updateViewer )
430 {
431   SALOME_ListIteratorOfListIO Iter( theIOList );
432   for ( ; Iter.More(); Iter.Next() )
433     Erase( Iter.Value(), forced, false );
434
435   if ( updateViewer )
436     UpdateViewer();
437 }
438
439 //=================================================================
440 /*!
441  *  GEOM_Displayer::Redisplay
442  *  Calls Redisplay() method for each object in the given list
443  */
444 //=================================================================
445 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
446 {
447   SALOME_ListIteratorOfListIO Iter( theIOList );
448   for ( ; Iter.More(); Iter.Next() )
449     Redisplay( Iter.Value(), false );
450
451   if ( updateViewer )
452     UpdateViewer();
453 }
454
455 //=================================================================
456 /*!
457  *  GEOM_Displayer::Update
458  *  Update OCC presentaion
459  *  [ Reimplemented from SALOME_Displayer ]
460  */
461 //=================================================================
462 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
463 {
464   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
465   if ( !occPrs )
466     return;
467
468   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
469   {
470     TopoDS_Face aFace = TopoDS::Face( myShape );
471     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
472     if ( !aPlane.IsNull() )
473     {
474       gp_Ax3 aPos = aPlane->Pln().Position();
475       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
476
477       Handle(GEOM_AISTrihedron) aTrh;
478
479       if ( occPrs->IsNull() )
480       {
481         aTrh = new GEOM_AISTrihedron( aPlc );
482
483         if ( HasColor() )
484           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
485
486         if ( HasWidth() )
487           aTrh->SetWidth( GetWidth() );
488
489         if ( !myIO.IsNull() )
490         {
491           aTrh->setIO( myIO );
492           aTrh->SetOwner( myIO );
493         }
494
495         occPrs->AddObject( aTrh );
496       }
497       else
498       {
499         AIS_ListOfInteractive aList;
500         occPrs->GetObjects( aList );
501         AIS_ListIteratorOfListOfInteractive anIter( aList );
502         for ( ; anIter.More(); anIter.Next() )
503         {
504           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
505           if ( !aTrh.IsNull() )
506           {
507             aTrh->SetComponent( aPlc );
508             aTrh->SetToUpdate();
509           }
510         }
511       }
512
513       occPrs->SetToActivate( ToActivate() );
514     }
515   }
516   else
517   {
518     // if presentation is empty we try to create new one
519     if ( occPrs->IsNull() )
520     {
521       if ( !myShape.IsNull() )
522       {
523         Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
524         // Temporary staff: vertex must be infinite for correct visualization
525         AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
526
527         // Setup shape properties here ..., e.g. display mode, color, transparency, etc
528         AISShape->SetDisplayMode( myDisplayMode );
529         AISShape->SetShadingColor( myShadingColor );
530
531         // Set color and number for iso lines
532         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
533         QColor col = aResMgr->colorValue( "Geometry", "isos_color", 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.IsNull() && 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     theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
707
708   theActors->InitTraversal();
709
710   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
711
712   vtkProperty* aProp = 0;
713
714   if ( HasColor() || HasWidth() )
715   {
716     aProp = vtkProperty::New();
717     aProp->SetRepresentationToWireframe();
718   }
719
720   if ( HasColor() )
721   {
722     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
723     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
724   }
725
726   if ( HasWidth() )
727   {
728     aProp->SetLineWidth( GetWidth() );
729   }
730
731   while ( anActor != NULL )
732   {
733     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
734
735     GActor->setIO( myIO );
736
737     if ( aProp )
738     {
739       GActor->SetProperty( aProp );
740       GActor->SetPreviewProperty( aProp );
741
742       GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
743       if ( aGeomGActor != 0 )
744       {
745         aGeomGActor->SetShadingProperty( aProp );
746         aGeomGActor->SetWireframeProperty( aProp );
747       }
748     }
749
750     if ( myToActivate )
751       GActor->PickableOn();
752     else
753       GActor->PickableOff();
754
755     vtkPrs->AddObject( GActor );
756
757     anActor = (vtkActor*)theActors->GetNextActor();
758   }
759
760   if ( aProp )
761     aProp->Delete();
762
763   theActors->Delete();
764 }
765
766 //=================================================================
767 /*!
768  *  GEOM_Displayer::BuildPrs
769  *  Build presentation accordint to the current viewer type
770  */
771 //=================================================================
772 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
773 {
774   if ( theObj->_is_nil() )
775     return 0;
776
777   myViewFrame = GetActiveView();
778   if ( myViewFrame == 0 )
779     return 0;
780
781   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
782   if ( aPrs == 0 )
783     return 0;
784
785   internalReset();
786   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
787   myType = theObj->GetType();
788
789   // Update presentation
790   UpdatePrs( aPrs );
791
792   return aPrs;
793 }
794
795 //=================================================================
796 /*!
797  *  GEOM_Displayer::BuildPrs
798  *  Build presentation accordint to the current viewer type
799  */
800 //=================================================================
801 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
802 {
803   myViewFrame = GetActiveView();
804   if ( theShape.IsNull() || myViewFrame == 0 )
805     return 0;
806
807   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
808   if ( aPrs == 0 )
809     return 0;
810
811   internalReset();
812   setShape( theShape );
813   myType = -1;
814
815   UpdatePrs( aPrs );
816
817   return aPrs;
818 }
819
820 //=================================================================
821 /*!
822  *  GEOM_Displayer::buildPresentation
823  *  Builds/finds object's presentation for the current viewer
824  *  Calls corresponding Update() method by means of double dispatch
825  *  [ internal ]
826  */
827 //=================================================================
828 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
829                                                SALOME_View* theViewFrame )
830 {
831   SALOME_Prs* prs = 0;
832   internalReset();
833
834   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
835
836   if ( myViewFrame )
837   {
838     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
839     if ( prs )
840     {
841       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
842       theIO->setEntry( entry.latin1() );
843       if ( !theIO.IsNull() )
844       {
845         // set interactive object
846         setIO( theIO );
847         //  Find SOBject (because shape should be published previously)
848         SUIT_Session* session = SUIT_Session::session();
849         SUIT_Application* app = session->activeApplication();
850         if ( app )
851         {
852           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
853           if ( study )
854           {
855             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
856             if ( SO )
857             {
858               // get CORBA reference to data object
859               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
860               if ( !CORBA::is_nil( object ) )
861               {
862                 // downcast to GEOM object
863                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
864                 if ( !GeomObject->_is_nil() )
865                 {
866                   // finally set shape
867                   setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
868                   myType = GeomObject->GetType();
869                 }
870               }
871             }
872           }
873         }
874       }
875       UpdatePrs( prs );  // Update presentation by using of the double dispatch
876     }
877   }
878   return prs;
879 }
880
881 //=================================================================
882 /*!
883  *  GEOM_Displayer::internalReset
884  *  Resets internal data
885  *  [internal]
886  */
887 //=================================================================
888 void GEOM_Displayer::internalReset()
889 {
890   myIO.Nullify();
891   myShape.Nullify();
892 }
893
894 //=================================================================
895 /*!
896  *  GEOM_Displayer::LocalSelection
897  *  Activate selection of CAD shapes with activisation of selection
898  *  of their sub-shapes (with opened local context for OCC viewer)
899  */
900 //=================================================================
901 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
902 {
903   SUIT_Session* session = SUIT_Session::session();
904   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
905   if ( !app )
906     return;
907
908   LightApp_SelectionMgr* sm = app->selectionMgr();
909
910   // remove all filters from selection
911   sm->clearFilters();
912
913   SALOME_View* vf = GetActiveView();
914   if ( vf ) {
915     if (!theIO.IsNull() && !vf->isVisible(theIO))
916       Display(theIO);
917     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
918     vf->LocalSelection( prs, theMode );
919     delete prs;  // delete presentation because displayer is its owner
920   }
921 }
922
923 //=================================================================
924 /*!
925  *  GEOM_Displayer::globalSelection
926  *  Activate selection of CAD shapes without activisation of selection
927  *  of their sub-shapes (without opened local context for OCC viewer)
928  */
929 //=================================================================
930 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
931 {
932   TColStd_MapOfInteger aModes;
933   aModes.Add( theMode );
934   GlobalSelection( aModes, update );
935 }
936
937 //=================================================================
938 /*!
939  *  GEOM_Displayer::globalSelection
940  *  Activate selection of CAD shapes without activisation of selection
941  *  of their sub-shapes (without opened local context for OCC viewer)
942  */
943 //=================================================================
944 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
945                                       const bool update )
946 {
947   SUIT_Session* session = SUIT_Session::session();
948   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
949   if ( !app )
950     return;
951
952   SALOME_View* vf = GetActiveView();
953   if ( vf == 0 )
954     return;
955
956   // Close local context
957   vf->GlobalSelection( update );
958
959   // Set selection filters in accordance with current mode
960   LightApp_SelectionMgr* sm = app->selectionMgr();
961   if ( !sm )
962     return;
963
964   // Remove from selection temporary objects if necessary
965   if ( !theModes.Contains( GEOM_PREVIEW ) )
966     clearTemporary( sm );
967
968   //@ aSel->ClearIndex();
969
970   sm->clearFilters();
971
972   // Remove filters from AIS_InteractiveContext
973   Handle(AIS_InteractiveContext) ic;
974   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
975   if ( viewer )
976     {
977       ic = viewer->getAISContext();
978       if ( !ic.IsNull() )
979         ic->RemoveFilters();
980     }
981
982   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
983     return;
984
985   SUIT_SelectionFilter* aFilter;
986   if ( theModes.Extent() == 1 )
987     {
988       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
989       aFilter = getFilter( aMode );
990     }
991   else if ( theModes.Extent() > 1 )
992     {
993       TColStd_MapOfInteger aTopAbsModes;
994       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
995       QPtrList<SUIT_SelectionFilter> aListOfFilters;
996       for ( ; anIter.More(); anIter.Next() )
997         {
998           SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
999           if ( aFilter )
1000             aListOfFilters.append( aFilter );
1001         }
1002
1003       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1004     }
1005   else
1006     return;
1007
1008   if ( aFilter )
1009     {
1010       sm->installFilter( aFilter );
1011       if ( !ic.IsNull() )
1012         {
1013           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1014           ic->AddFilter( anOCCFilter );
1015         }
1016     }
1017 }
1018
1019 //=================================================================
1020 /*!
1021  *  GEOM_Displayer::LocalSelection
1022  *  Activate selection of CAD shapes with activisation of selection
1023  *  of their sub-shapes (with opened local context for OCC viewer)
1024  */
1025 //=================================================================
1026 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1027 {
1028   SALOME_ListIteratorOfListIO Iter( theIOList );
1029   for ( ; Iter.More(); Iter.Next() )
1030     LocalSelection( Iter.Value(), theMode );
1031 }
1032
1033 //=================================================================
1034 /*!
1035  *  GEOM_Displayer::BeforeDisplay
1036  *  Called before displaying of pars. Close local context
1037  *  [ Reimplemented from SALOME_Displayer ]
1038  */
1039 //=================================================================
1040 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1041 {
1042   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1043   if ( vf )
1044   {
1045     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1046     if ( !ic.IsNull() )
1047     {
1048       if ( ic->HasOpenedContext() )
1049       ic->CloseAllContexts();
1050     }
1051   }
1052 }
1053
1054 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1055 {
1056 }
1057
1058
1059 //=================================================================
1060 /*!
1061  *  GEOM_Displayer::SetColor
1062  *  Set color for shape displaying. If it is equal -1 then default color is used.
1063  *  Available values are from Quantity_NameOfColor enumeration
1064  */
1065 //=================================================================
1066 void GEOM_Displayer::SetColor( const int color )
1067 {
1068   myColor = color;
1069 }
1070
1071 int GEOM_Displayer::GetColor() const
1072 {
1073   return myColor;
1074 }
1075
1076 bool GEOM_Displayer::HasColor() const
1077 {
1078   return myColor != -1;
1079 }
1080
1081 void GEOM_Displayer::UnsetColor()
1082 {
1083   myColor = -1;
1084 }
1085
1086 //=================================================================
1087 /*!
1088  *  GEOM_Displayer::SetWidth
1089  *  Set width of shape displaying. If it is equal -1 then default width is used.
1090  */
1091 //=================================================================
1092 void GEOM_Displayer::SetWidth( const double width )
1093 {
1094   myWidth = width;
1095 }
1096
1097 double GEOM_Displayer::GetWidth() const
1098 {
1099   return myWidth;
1100 }
1101
1102 bool GEOM_Displayer::HasWidth() const
1103 {
1104   return myWidth != -1;
1105 }
1106
1107 void GEOM_Displayer::UnsetWidth()
1108 {
1109   myWidth = -1;
1110 }
1111
1112 //=================================================================
1113 /*!
1114  *  GEOM_Displayer::SetToActivate
1115  *  This method is used for activisation/deactivisation of objects to be displayed
1116  */
1117 //=================================================================
1118 void GEOM_Displayer::SetToActivate( const bool toActivate )
1119 {
1120   myToActivate = toActivate;
1121 }
1122 bool GEOM_Displayer::ToActivate() const
1123 {
1124   return myToActivate;
1125 }
1126
1127 //=================================================================
1128 /*!
1129  *  GEOM_Displayer::clearTemporary
1130  *  Removes from selection temporary objects
1131  */
1132 //=================================================================
1133 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1134 {
1135   SALOME_ListIO selected, toSelect;
1136   theSelMgr->selectedObjects( selected );
1137
1138   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1139     Handle(SALOME_InteractiveObject) io = it.Value();
1140     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1141       toSelect.Append( it.Value() );
1142   }
1143
1144   theSelMgr->setSelectedObjects( toSelect, true );
1145 }
1146
1147 void GEOM_Displayer::SetName( const char* theName )
1148 {
1149   myName = theName;
1150 }
1151
1152 void GEOM_Displayer::UnsetName()
1153 {
1154   myName = "";
1155 }
1156
1157 SalomeApp_Study* GEOM_Displayer::getStudy() const
1158 {
1159   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1160 }
1161
1162 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1163 {
1164   myIO = theIO;
1165 }
1166
1167 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1168 {
1169   myShape = theShape;
1170 }
1171
1172 bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const
1173 {
1174   return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type();
1175 }