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