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