Salome HOME
Merge V9_dev branch into master
[modules/smesh.git] / src / SMESH_SWIG_WITHIHM / libSMESH_Swig.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 /////////////////////////////////////////////////////////////////
21 /// \package libSMESH_Swig
22 /// \brief Python API for %SMESH GUI.
23 ///
24 /// See SMESH_Swig class for %SMESH GUI Python API.
25 ///
26 /// \par Note about publishing of mesh objects in the study
27 ///
28 /// Mesh objects are automatically published in the study. It is
29 /// not needed to specify a target SALOMEDS object (SObject) or
30 /// even name (%SMESH engine will will default name if it is not
31 /// specified).
32 /// So, normally functions of %SMESH GUI Python API like
33 ///   AddNewMesh
34 ///   AddNewHypothesis
35 ///   AddNewAlgorithms
36 ///   etc.
37 /// may only be needed to be called in case if mesh objects are
38 /// created when no active study is set to %SMESH component.
39 /// In this case, mentioned functions can be used to forcibly
40 /// publish existing objects in the currrently active study.
41 ///
42 /// Note that if there are no open study, these methods will do
43 /// nothing.
44 ///
45 /// \par Note about selection
46 ///
47 /// In SALOME, selection is automatically synchronlized between
48 /// all GUI elements (like Object browser, view windows, etc).
49 /// This means that any changes to selection applied with
50 /// select() methods, will automatically apply to all view
51 /// windows, taking into account selection modes switched in
52 /// each particular view window (e.g. if you select edges, while
53 /// in some view window Face selection mode is switched on,
54 /// selection will not be immediately applied to this view
55 /// window.
56 /////////////////////////////////////////////////////////////////
57
58 #include "libSMESH_Swig.h"
59
60 #include <SVTK_Selector.h>
61
62 #include <SMESHGUI.h>
63 #include <SMESHGUI_Utils.h>
64 #include <SMESHGUI_Displayer.h>
65 #include <SMESHGUI_VTKUtils.h>
66 #include <SMESH_Actor.h>
67
68 // SALOME KERNEL includes
69 #include <Utils_ORB_INIT.hxx>
70 #include <Utils_SINGLETON.hxx>
71 #include <SALOMEDSClient_ClientFactory.hxx>
72 #include <SALOMEDS_Study.hxx>
73
74 #include <utilities.h>
75
76 // SALOME GUI includes
77 #include <SUIT_Session.h>
78 #include <SUIT_ViewManager.h>
79 #include <SALOME_Prs.h>
80 #include <SUIT_ViewWindow.h>
81 #include <SVTK_ViewWindow.h>
82 #include <SVTK_ViewModel.h>
83 #include <SALOME_Event.h>
84 #include <SalomeApp_Application.h>
85 #include <LightApp_SelectionMgr.h>
86 #include <SVTK_RenderWindowInteractor.h>
87 #include <VTKViewer_Algorithm.h>
88
89 // OCCT includes
90 #include <TopAbs.hxx>
91 #include <TColStd_MapOfInteger.hxx>
92
93 // Qt includes
94 #include <QApplication>
95
96 // IDL includes
97 #include <SALOMEconfig.h>
98 #include CORBA_SERVER_HEADER(SMESH_Gen)
99 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
100
101 // VTK includes
102 #include <vtkActorCollection.h>
103 #include <vtkRenderer.h>
104
105 namespace
106 {
107   ///////////////////////////////////////////////////////////////
108   /// \internal
109   /// \brief Print deprecation warning to termninal.
110   /// \param function Interface function's name.
111   /// \param replacement Replacement (new) function's name
112   ///        (if there's any).
113   ///////////////////////////////////////////////////////////////
114   void deprecated(const char* function, const char* replacement = 0)
115   {
116     if ( replacement )
117       printf("libSMESH_Swig: method '%s' is deprecated; use '%s' instead.\n", function, replacement);
118     else
119       printf("libSMESH_Swig: method '%s' is deprecated.\n", function);
120   }
121
122   ///////////////////////////////////////////////////////////////
123   /// \internal
124   /// \brief Get CORBA object by its IOR.
125   /// \param ior Object's IOR.
126   /// \return CORBA object (nil object if it isn't found).
127   ///////////////////////////////////////////////////////////////
128   CORBA::Object_var string2object(const std::string& ior)
129   {
130     return SalomeApp_Application::orb()->string_to_object(ior.c_str());
131   }
132
133   ///////////////////////////////////////////////////////////////
134   /// \internal
135   /// \brief Get study object by its study UID or IOR.
136   /// \param uid Object's study UID or IOR.
137   /// \return Pointer to study object (null object if it isn't
138   ///         found).
139   ///////////////////////////////////////////////////////////////
140   _PTR(SObject) uid2object(const std::string& uid)
141   {
142     _PTR(SObject) sobject;
143     {
144       _PTR(Study) study = SMESH::getStudy();
145       if ( study )
146       {
147         sobject = study->FindObjectID( uid );
148         if ( !sobject )
149           sobject = study->FindObjectIOR( uid );
150       }
151     }
152     return sobject;
153   }
154
155   ///////////////////////////////////////////////////////////////
156   /// \internal
157   /// \brief Get view window by its identifier.
158   /// \param uid Window's identifier.
159   /// \return Pointer to the view window (0 if it isn't found).
160   ///////////////////////////////////////////////////////////////
161   SALOME_View* uid2wnd(int uid, bool create = false)
162   {
163     SALOME_View* window = 0;
164
165     SUIT_Session* session = SUIT_Session::session();
166     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
167     if ( app )
168     {
169       if ( uid )
170       {
171         ViewManagerList vms = app->viewManagers();
172         for ( int i = 0; i < vms.count() && !window; i++ )
173         {
174           SUIT_ViewManager* vm = vms[i];
175           QVector<SUIT_ViewWindow*> vws = vm->getViews();
176           for ( int j = 0; j < vws.count() && !window; j++)
177           {
178             SUIT_ViewWindow* vw = vws[0];
179             if ( uid == vw->getId() )
180               window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
181           }
182         }
183       }
184       else
185       {
186         SUIT_ViewManager* vm = app->getViewManager( SVTK_Viewer::Type(), create );
187         if ( vm )
188         { 
189           window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
190         }
191       }
192     }
193     return window;
194   }
195
196   ///////////////////////////////////////////////////////////////
197   /// \internal
198   /// \brief Get all view windows.
199   /// \return List of view windows.
200   ///////////////////////////////////////////////////////////////
201   QList<SALOME_View*> windows()
202   {
203     QList<SALOME_View*> views;
204     SUIT_Session* session = SUIT_Session::session();
205     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
206     if ( app )
207     {
208       ViewManagerList vms = app->viewManagers();
209       foreach( SUIT_ViewManager* vm, vms )
210       {
211         if ( vm && vm->getType() == SVTK_Viewer::Type() )
212         {
213           SALOME_View* view = dynamic_cast<SALOME_View*>( vm->getViewModel() );
214           if ( view )
215             views << view;
216         }
217       }
218     }
219     return views;
220   }
221
222   ///////////////////////////////////////////////////////////////
223   /// \internal
224   /// \brief Get mesh actor from view.
225   /// \param view Pointer to the view window.
226   /// \param uid Mesh object's study UID.
227   /// \return Mesh actor (0 if it isn't found).
228   ///////////////////////////////////////////////////////////////
229   SMESH_Actor* actorFromView(SALOME_View* view, const char* uid)
230   {
231     SMESH_Actor* actor = 0;
232     SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( view );
233     if ( model )
234     {
235       SUIT_ViewWindow* vw = model->getViewManager()->getActiveView();
236       if ( vw )
237       {
238         actor = SMESH::FindActorByEntry( vw, uid );
239       }
240     }
241     return actor;
242   }
243
244   ///////////////////////////////////////////////////////////////
245   /// \internal
246   /// \brief Get mesh object's visual properties.
247   /// \param view Pointer to the view window.
248   /// \param uid Mesh object's study UID.
249   /// \return Properties data structure.
250   ///////////////////////////////////////////////////////////////
251   Properties properties(SALOME_View* view, const char* uid)
252   {
253     Properties props;
254     SMESH_Actor* actor = actorFromView( view, uid );
255     if ( actor )
256     {
257       actor->GetNodeColor( props.nodeColor.r,
258                            props.nodeColor.g,
259                            props.nodeColor.b );
260       props.markerType = actor->GetMarkerType();
261       props.markerScale = actor->GetMarkerScale();
262       
263       actor->GetEdgeColor( props.edgeColor.r,
264                            props.edgeColor.g,
265                            props.edgeColor.b );
266       props.edgeWidth = qMax( (int)actor->GetLineWidth(), 1 );
267       
268       actor->GetSufaceColor( props.surfaceColor.r,
269                              props.surfaceColor.g,
270                              props.surfaceColor.b,
271                              props.surfaceColor.delta );
272       
273       actor->GetVolumeColor( props.volumeColor.r,
274                              props.volumeColor.g,
275                              props.volumeColor.b,
276                              props.volumeColor.delta );
277       
278       actor->Get0DColor( props.elem0dColor.r,
279                          props.elem0dColor.g,
280                          props.elem0dColor.b );
281       props.elem0dSize = qMax( (int)actor->Get0DSize(), 1 );
282       
283       actor->GetBallColor( props.ballColor.r,
284                            props.ballColor.g,
285                            props.ballColor.b );
286       props.ballScale = qMax( actor->GetBallScale(), 1e-2 );
287       
288       actor->GetOutlineColor( props.outlineColor.r,
289                               props.outlineColor.g,
290                               props.outlineColor.b );
291       props.outlineWidth = qMax( (int)actor->GetOutlineWidth(), 1 );
292       
293       actor->GetFacesOrientationColor( props.orientationColor.r,
294                                        props.orientationColor.g,
295                                        props.orientationColor.b );
296       props.orientationScale = actor->GetFacesOrientationScale();
297       props.orientation3d = actor->GetFacesOrientation3DVectors();
298       
299       props.shrinkFactor = actor->GetShrinkFactor();
300       
301       props.opacity = actor->GetOpacity();
302     }
303     return props;
304   }
305
306   ///////////////////////////////////////////////////////////////
307   /// \internal
308   /// \brief Set mesh object's visual properties.
309   /// \param view Pointer to the view window.
310   /// \param uid Mesh object's study UID.
311   /// \param props Properties data structure.
312   ///////////////////////////////////////////////////////////////
313   void setProperties(SALOME_View* view, const char* uid, const Properties& props)
314   {
315     SMESH_Actor* actor = actorFromView( view, uid );
316     if ( actor )
317     {
318       actor->SetNodeColor( props.nodeColor.r,
319                            props.nodeColor.g,
320                            props.nodeColor.b );
321       if ( props.markerType != VTK::MT_USER )
322         actor->SetMarkerStd( props.markerType, props.markerScale );
323       
324       actor->SetEdgeColor( props.edgeColor.r,
325                            props.edgeColor.g,
326                            props.edgeColor.b );
327       actor->SetLineWidth( qMax( (double)props.edgeWidth, 1. ) );
328       
329       actor->SetSufaceColor( props.surfaceColor.r,
330                              props.surfaceColor.g,
331                              props.surfaceColor.b,
332                              props.surfaceColor.delta );
333       
334       actor->SetVolumeColor( props.volumeColor.r,
335                              props.volumeColor.g,
336                              props.volumeColor.b,
337                              props.volumeColor.delta );
338       
339       actor->Set0DColor( props.elem0dColor.r,
340                          props.elem0dColor.g,
341                          props.elem0dColor.b );
342       actor->Set0DSize( qMax( (double)props.elem0dSize, 1. ) );
343       
344       actor->SetBallColor( props.ballColor.r,
345                            props.ballColor.g,
346                            props.ballColor.b );
347       actor->SetBallScale( qMax( props.ballScale, 1e-2 ) );
348       
349       actor->SetOutlineColor( props.outlineColor.r,
350                               props.outlineColor.g,
351                               props.outlineColor.b );
352       actor->SetOutlineWidth( qMax( (double)props.outlineWidth, 1. ) );
353       
354       actor->SetFacesOrientationColor( props.orientationColor.r,
355                                        props.orientationColor.g,
356                                        props.orientationColor.b );
357       actor->SetFacesOrientationScale( props.orientationScale );
358       actor->SetFacesOrientation3DVectors( props.orientation3d );
359       
360       actor->SetShrinkFactor( props.shrinkFactor );
361       
362       actor->SetOpacity( props.opacity );
363       
364       view->Repaint();
365     }
366   }
367 } // end of anonymous namespace
368
369 /////////////////////////////////////////////////////////////////
370 /// \enum EntityMode
371 /// \brief Enumeration for mesh entities.
372 /// \var EntityMode Entity0d
373 /// \brief 0D elements.
374 /// \var EntityMode EntityEdges
375 /// \brief Edges.
376 /// \var EntityMode EntityFaces
377 /// \brief Faces.
378 /// \var EntityMode EntityVolumes
379 /// \brief Volumes.
380 /// \var EntityMode EntityBalls
381 /// \brief Ball elements.
382 /// \var EntityMode EntityAll
383 /// \brief All elements.
384 /////////////////////////////////////////////////////////////////
385
386 /////////////////////////////////////////////////////////////////
387 /// \enum SelectionMode
388 /// \brief Selection mode.
389 /// \var SelectionMode Undefined
390 /// \brief Undefined selection mode.
391 /// \var SelectionMode Node
392 /// \brief Selection of mesh nodes.
393 /// \var SelectionMode Cell
394 /// \brief Selection of any mesh cells.
395 /// \var SelectionMode EdgeOfCell
396 /// \brief Selection of pseudo-edges specified by couple of nodes.
397 /// \var SelectionMode Edge
398 /// \brief Selection of edges.
399 /// \var SelectionMode Face
400 /// \brief Selection of faces.
401 /// \var SelectionMode Volume
402 /// \brief Selection of volumes
403 /// \var SelectionMode Actor
404 /// \brief Selection of whole actors (meshes, sub-meshes, groups).
405 /// \var SelectionMode Elem0D
406 /// \brief Selection of 0D elements.
407 /// \var SelectionMode Ball
408 /// \brief Selection of ball ellements.
409 /////////////////////////////////////////////////////////////////
410
411 /////////////////////////////////////////////////////////////////
412 /// \enum DisplayMode
413 /// \brief Display mode.
414 /// \var DisplayMode UndefinedMode
415 /// \brief Undefined display mode.
416 /// \var DisplayMode PointMode
417 /// \brief Point representation.
418 /// \var DisplayMode EdgeMode
419 /// \brief Wireframe representation.
420 /// \var DisplayMode SurfaceMode
421 /// \brief Surface representation.
422 /////////////////////////////////////////////////////////////////
423
424 /////////////////////////////////////////////////////////////////
425 /// \struct ColorData
426 /// \brief Color data, in RGBf format.
427 /// \var ColorData::r
428 /// \brief Red color's component (0.0:1.0).
429 /// \var ColorData::g
430 /// \brief Green color's component (0.0:1.0).
431 /// \var ColorData::b
432 /// \brief Blue color's component (0.0:1.0).
433 /////////////////////////////////////////////////////////////////
434
435 /////////////////////////////////////////////////////////////////
436 /// \brief Constructor.
437 /////////////////////////////////////////////////////////////////
438 ColorData::ColorData()
439   : r( 0 ), g( 0 ), b( 0 )
440 {}
441
442 /////////////////////////////////////////////////////////////////
443 /// \struct BicolorData
444 /// \brief Bi-color data, in RGBf format.
445 /// \var BicolorData::r
446 /// \brief Red color's component (0.0:1.0).
447 /// \var BicolorData::g
448 /// \brief Green color's component (0.0:1.0).
449 /// \var BicolorData::b
450 /// \brief Blue color's component (0.0:1.0).
451 /// \var BicolorData::delta
452 /// \brief Shift for backface color (-100:100).
453 /////////////////////////////////////////////////////////////////
454
455 /////////////////////////////////////////////////////////////////
456 /// \brief Constructor.
457 /////////////////////////////////////////////////////////////////
458 BicolorData::BicolorData()
459   : r( 0 ), g( 0 ), b( 0 ), delta( 0 )
460 {}
461
462 /////////////////////////////////////////////////////////////////
463 /// \struct Properties
464 /// \brief Mesh object presentation's properties.
465 /// \var Properties::nodeColor
466 /// \brief Node color.
467 /// \var Properties::markerType
468 /// \brief Node standard marker type.
469 /// \var Properties::markerScale
470 /// \brief Node scale factor.
471 /// \var Properties::edgeColor
472 /// \brief Edges color.
473 /// \var Properties::edgeWidth
474 /// \brief Edges width.
475 /// \var Properties::surfaceColor
476 /// \brief Faces color.
477 /// \var Properties::volumeColor
478 /// \brief Volumes color.
479 /// \var Properties::elem0dColor
480 /// \brief 0D elements color.
481 /// \var Properties::elem0dSize
482 /// \brief 0D elements size.
483 /// \var Properties::ballColor
484 /// \brief Ball elements color.
485 /// \var Properties::ballScale
486 /// \brief Ball elements scale factor.
487 /// \var Properties::outlineColor
488 /// \brief Outlines color.
489 /// \var Properties::outlineWidth
490 /// \brief Outlines width.
491 /// \var Properties::orientationColor
492 /// \brief Face orientation vectors color.
493 /// \var Properties::orientationScale
494 /// \brief Face orientation vectors scale factor.
495 /// \var Properties::orientation3d
496 /// \brief Face orientation vectors 3d flag.
497 /// \var Properties::shrinkFactor
498 /// \brief Shrink coefficient.
499 /// \var Properties::opacity
500 /// \brief Opacity.
501 /////////////////////////////////////////////////////////////////
502
503 /////////////////////////////////////////////////////////////////
504 /// \brief Constructor.
505 /////////////////////////////////////////////////////////////////
506 Properties::Properties()
507   : markerType( VTK::MT_NONE ), markerScale( VTK::MS_NONE ),
508     edgeWidth( 1 ), elem0dSize( 1 ), ballScale( 1 ), outlineWidth( 1 ),
509     orientationScale( 0 ), orientation3d( false ), shrinkFactor( 0 ),
510     opacity( 1 )
511 {}
512
513 /////////////////////////////////////////////////////////////////
514 /// \typedef nodeColorStruct
515 /// \deprecated Use ColorData instead.
516 /// \typedef edgeColorStruct
517 /// \deprecated Use ColorData instead.
518 /// \typedef surfaceColorStruct
519 /// \deprecated Use BicolorData instead.
520 /// \typedef volumeColorStruct
521 /// \deprecated Use BicolorData instead.
522 /// \typedef actorAspect
523 /// \deprecated Use Properties instead.
524 /////////////////////////////////////////////////////////////////
525
526 /////////////////////////////////////////////////////////////////
527 /// \class SMESH_Swig
528 /// \brief %SMESH GUI Python interface.
529 /////////////////////////////////////////////////////////////////
530
531 /////////////////////////////////////////////////////////////////
532 /// \brief Constructor.
533 /////////////////////////////////////////////////////////////////
534 SMESH_Swig::SMESH_Swig()
535 {
536   init();
537 }
538
539 /////////////////////////////////////////////////////////////////
540 /// \brief Destructor.
541 /////////////////////////////////////////////////////////////////
542 SMESH_Swig::~SMESH_Swig()
543 {
544 }
545
546 /////////////////////////////////////////////////////////////////
547 /// \internal
548 /// \brief Initialize interface.
549 /////////////////////////////////////////////////////////////////
550 void SMESH_Swig::init()
551 {
552   class TInitEvent: public SALOME_Event
553   {
554   public:
555     TInitEvent() {}
556     virtual void Execute()
557     {
558       SUIT_Session* session = SUIT_Session::session();
559       SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
560
561       if ( !SMESHGUI::GetSMESHGUI() )
562         app->loadModule( "Mesh" );
563     }
564   };
565
566   // load SMESH GUI if it's not yet loaded
567   ProcessVoidEvent( new TInitEvent() );
568   SMESHGUI::GetSMESHGen()->UpdateStudy();
569 }
570
571 /////////////////////////////////////////////////////////////////
572 /// \brief Publish object.
573 /// \param ior IOR of the mesh object to publish.
574 /// \param name Study name of the object; if not given,
575 ///             name is assigned automatically.
576 /// \return UID of the data object.
577 /////////////////////////////////////////////////////////////////
578 const char* SMESH_Swig::publish(const char* ior, const char* name)
579 {
580   init();
581
582   std::string uid;
583   CORBA::Object_var object = string2object( ior );
584   if ( !CORBA::is_nil( object ) )
585     {
586       SALOMEDS::SObject_var sobject =
587         SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(),
588                                                  object.in(),
589                                                  name );
590       if ( !CORBA::is_nil( sobject ) )
591         {
592           uid = sobject->GetID();
593         }
594       sobject->UnRegister();
595     }
596
597   return strdup( uid.c_str() );
598 }
599
600 /////////////////////////////////////////////////////////////////
601 /// \brief Set new study name of given object.
602 /// \param uid Object's study UID or IOR.
603 /// \param name New name of the object.
604 /////////////////////////////////////////////////////////////////
605 void SMESH_Swig::rename(const char* uid, const char* name)
606 {
607   init();
608
609   _PTR(SObject) sobject = uid2object( uid );
610   if ( sobject )
611     sobject->SetAttrString( "AttributeName", name );
612 }
613
614 /////////////////////////////////////////////////////////////////
615 /// \brief Display mesh object.
616 /// \param uid Object's study UID or IOR.
617 /// \param viewUid View window UID (0 means currently active view
618 ///                window; if there's no view, it is created).
619 ///                Default: 0.
620 /// \param updateViewer "Update view" flag. Default: \c true.
621 /////////////////////////////////////////////////////////////////
622 void SMESH_Swig::display(const char* uid, int viewUid, bool updateViewer)
623 {
624   class TDisplayEvent: public SALOME_Event
625   {
626   private:
627     const char* myUid;
628     int myViewUid;
629     bool myIsUpdate;
630   public:
631     TDisplayEvent(const char* uid, int viewUid, bool updateViewer)
632       : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
633     virtual void Execute()
634     {
635       SALOME_View* view = uid2wnd( myViewUid, true ); // create view if it's not present
636       if ( view )
637         LightApp_Displayer::FindDisplayer( "Mesh", true )->Display( myUid, myIsUpdate, view );
638     }
639   };
640
641   init();
642
643   _PTR(SObject) sobject = uid2object( uid );
644   if ( sobject )
645     ProcessVoidEvent( new TDisplayEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
646 }
647
648 /////////////////////////////////////////////////////////////////
649 /// \brief Erase mesh object.
650 /// \param uid Object's study UID or IOR.
651 /// \param viewUid View window UID (0 means currently active view
652 ///                window); -1 means "all view windows".
653 ///                Default: 0.
654 /// \param updateViewer "Update view" flag. Default: \c true.
655 /////////////////////////////////////////////////////////////////
656 void SMESH_Swig::erase(const char* uid, int viewUid, bool updateViewer)
657 {
658   class TEraseEvent: public SALOME_Event
659   {
660   private:
661     const char* myUid;
662     int myViewUid;
663     bool myIsUpdate;
664   public:
665     TEraseEvent(const char* uid, int viewUid, bool updateViewer)
666       : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
667     virtual void Execute()
668     {
669       if ( myViewUid == -1 )
670       {
671         QList<SALOME_View*> views = windows();
672         foreach( SALOME_View* view, views )
673           LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
674       }
675       else
676       {
677         SALOME_View* view = uid2wnd( myViewUid );
678         if ( view )
679           LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
680       }
681     }
682   };
683
684   init();
685
686   _PTR(SObject) sobject = uid2object( uid );
687   if ( sobject )
688     ProcessVoidEvent( new TEraseEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
689 }
690
691 /////////////////////////////////////////////////////////////////
692 /// \brief Update mesh object.
693 /// \param uid Object's study UID or IOR.
694 /////////////////////////////////////////////////////////////////
695 void SMESH_Swig::update(const char* uid)
696 {
697   class TUpdateEvent: public SALOME_Event
698   {
699   private:
700     const char* myUid;
701   public:
702     TUpdateEvent( const char* uid ) : myUid( uid ) {}
703     virtual void Execute()
704     {
705       Handle(SALOME_InteractiveObject) io = 
706         new SALOME_InteractiveObject( myUid, "SMESH", "" );
707       SMESH::Update( io, true );
708     }
709   };
710
711   init();
712
713   _PTR(SObject) sobject = uid2object( uid );
714   if ( sobject )
715     ProcessVoidEvent( new TUpdateEvent( uid ) );
716 }
717
718 /////////////////////////////////////////////////////////////////
719 /// \internal
720 class TGetPropsEvent: public SALOME_Event
721 {
722 public:
723   typedef Properties TResult;
724   TResult myResult;
725   const char* myUid;
726   int myViewUid;
727
728   TGetPropsEvent( const char* uid, int viewUid )
729     : myUid( uid ), myViewUid( viewUid ) {}
730
731   virtual void Execute()
732   {
733     SALOME_View* view = uid2wnd( myViewUid );
734     myResult = properties( view, myUid );
735   }
736 };
737
738 /////////////////////////////////////////////////////////////////
739 /// \brief Get mesh object's visual properties.
740 /// \param uid Mesh object's study UID or IOR.
741 /// \param viewUid View window UID (0 means currently active view
742 ///                window); Default: 0.
743 /// \return Properties data structure.
744 /////////////////////////////////////////////////////////////////
745 Properties SMESH_Swig::properties(const char* uid, int viewUid)
746 {
747   Properties props;
748
749   init();
750
751   _PTR(SObject) sobject = uid2object( uid );
752   if ( sobject )
753     props = ProcessEvent( new TGetPropsEvent( sobject->GetID().c_str(), viewUid ) );
754
755   return props;
756 }
757
758 /////////////////////////////////////////////////////////////////
759 /// \internal
760 /////////////////////////////////////////////////////////////////
761 class TSetPropsEvent: public SALOME_Event
762 {
763 public:
764   const char* myUid;
765   Properties myProps;
766   int myViewUid;
767
768   TSetPropsEvent( const char* uid, const Properties& props, int viewUid )
769     : myUid( uid ), myProps( props), myViewUid( viewUid ) {}
770
771   virtual void Execute()
772   {
773     if ( myViewUid == -1 )
774     {
775       QList<SALOME_View*> views = windows();
776       foreach( SALOME_View* view, views )
777       {
778         setProperties( view, myUid, myProps );
779       }
780     }
781     else
782     {
783       SALOME_View* view = uid2wnd( myViewUid );
784       setProperties( view, myUid, myProps );
785     }
786   }
787 };
788
789 /////////////////////////////////////////////////////////////////
790 /// \brief Set mesh object's visual properties.
791 /// \param uid Mesh object's study UID or IOR.
792 /// \param props Properties data structure.
793 /// \param viewUid View window UID (0 means currently active view
794 ///                window); Default: 0.
795 /////////////////////////////////////////////////////////////////
796 void SMESH_Swig::setProperties(const char* uid, const Properties& props, int viewUid)
797 {
798   init();
799
800   _PTR(SObject) sobject = uid2object( uid );
801   if ( sobject )
802     ProcessVoidEvent( new TSetPropsEvent( sobject->GetID().c_str(), props, viewUid ) );
803 }
804
805 /////////////////////////////////////////////////////////////////
806 /// \internal
807 /////////////////////////////////////////////////////////////////
808 class TGetNodeNumberingEvent: public SALOME_Event
809 {
810 public:
811   typedef bool TResult;
812   TResult myResult;
813   const char* myUid;
814   int myViewUid;
815
816   TGetNodeNumberingEvent( const char* uid, int viewUid )
817     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
818
819   virtual void Execute()
820   {
821     SALOME_View* view = uid2wnd( myViewUid );
822     SMESH_Actor* actor = actorFromView( view, myUid );
823     if ( actor )
824       myResult = actor->GetPointsLabeled();
825   }
826 };
827
828 /////////////////////////////////////////////////////////////////
829 /// \brief Check if nodes numbering is switched on.
830 /// \param uid Mesh object's study UID or IOR.
831 /// \param viewUid View window UID (0 means currently active view
832 ///                window); Default: 0.
833 /// \return \c true if nodes numbering is switched on;
834 ///         \c false otherwise.
835 /////////////////////////////////////////////////////////////////
836 bool SMESH_Swig::nodesNumbering(const char* uid, int viewUid)
837 {
838   bool numbering = false;
839
840   init();
841
842   _PTR(SObject) sobject = uid2object( uid );
843   if ( sobject )
844     numbering = ProcessEvent( new TGetNodeNumberingEvent( sobject->GetID().c_str(), viewUid ) );
845
846   return numbering;
847 }
848
849 /////////////////////////////////////////////////////////////////
850 /// \internal
851 /////////////////////////////////////////////////////////////////
852 class TSetNodeNumberingEvent: public SALOME_Event
853 {
854 public:
855   const char* myUid;
856   bool myNumbering;
857   int myViewUid;
858
859   TSetNodeNumberingEvent( const char* uid, bool numbering, int viewUid )
860     : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
861
862   virtual void Execute()
863   {
864     SALOME_View* view = uid2wnd( myViewUid );
865     SMESH_Actor* actor = actorFromView( view, myUid );
866     if ( actor )
867     {
868       actor->SetPointsLabeled( myNumbering );
869       if ( view )
870         view->Repaint();
871     }
872   }
873 };
874
875 /////////////////////////////////////////////////////////////////
876 /// \brief Switch nodes numbering on/off.
877 /// \param uid Mesh object's study UID or IOR.
878 /// \param numbering \c true to switch nodes numbering on;
879 ///                  \c false otherwise.
880 /// \param viewUid View window UID (0 means currently active view
881 ///                window); Default: 0.
882 /////////////////////////////////////////////////////////////////
883 void SMESH_Swig::setNodesNumbering(const char* uid, bool numbering, int viewUid)
884 {
885   init();
886
887   _PTR(SObject) sobject = uid2object( uid );
888   if ( sobject )
889     ProcessVoidEvent( new TSetNodeNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
890 }
891
892 /////////////////////////////////////////////////////////////////
893 /// \internal
894 /////////////////////////////////////////////////////////////////
895 class TGetElementNumberingEvent: public SALOME_Event
896 {
897 public:
898   typedef bool TResult;
899   TResult myResult;
900   const char* myUid;
901   int myViewUid;
902
903   TGetElementNumberingEvent( const char* uid, int viewUid )
904     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
905
906   virtual void Execute()
907   {
908     SALOME_View* view = uid2wnd( myViewUid );
909     SMESH_Actor* actor = actorFromView( view, myUid );
910     if ( actor )
911       myResult = actor->GetCellsLabeled();
912   }
913 };
914
915 /////////////////////////////////////////////////////////////////
916 /// \brief Check if elements numbering is switched on.
917 /// \param uid Mesh object's study UID or IOR.
918 /// \param viewUid View window UID (0 means currently active view
919 ///                window); Default: 0.
920 /// \return \c true if elements numbering is switched on;
921 ///         \c false otherwise.
922 /////////////////////////////////////////////////////////////////
923 bool SMESH_Swig::elementsNumbering(const char* uid, int viewUid)
924 {
925   bool numbering = false;
926
927   init();
928
929   _PTR(SObject) sobject = uid2object( uid );
930   if ( sobject )
931     numbering = ProcessEvent( new TGetElementNumberingEvent( sobject->GetID().c_str(), viewUid ) );
932
933   return numbering;
934 }
935
936 /////////////////////////////////////////////////////////////////
937 /// \internal
938 /////////////////////////////////////////////////////////////////
939 class TSetElementNumberingEvent: public SALOME_Event
940 {
941 public:
942   const char* myUid;
943   bool myNumbering;
944   int myViewUid;
945
946   TSetElementNumberingEvent( const char* uid, bool numbering, int viewUid )
947     : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
948
949   virtual void Execute()
950   {
951     SALOME_View* view = uid2wnd( myViewUid );
952     SMESH_Actor* actor = actorFromView( view, myUid );
953     if ( actor )
954     {
955       actor->SetCellsLabeled( myNumbering );
956       if ( view )
957         view->Repaint();
958     }
959   }
960 };
961
962 /////////////////////////////////////////////////////////////////
963 /// \brief Switch elements numbering on/off.
964 /// \param uid Mesh object's study UID or IOR.
965 /// \param numbering \c true to switch elements numbering on;
966 ///                  \c false otherwise.
967 /// \param viewUid View window UID (0 means currently active view
968 ///                window); Default: 0.
969 /////////////////////////////////////////////////////////////////
970 void SMESH_Swig::setElementsNumbering(const char* uid, bool numbering, int viewUid)
971 {
972   init();
973
974   _PTR(SObject) sobject = uid2object( uid );
975   if ( sobject )
976     ProcessVoidEvent( new TSetElementNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
977 }
978
979 /////////////////////////////////////////////////////////////////
980 /// \internal
981 /////////////////////////////////////////////////////////////////
982 class TGetDisplayModeEvent: public SALOME_Event
983 {
984 public:
985   typedef DisplayMode TResult;
986   TResult myResult;
987   const char* myUid;
988   int myViewUid;
989
990   TGetDisplayModeEvent( const char* uid, int viewUid )
991     : myResult( UndefinedMode ), myUid( uid ), myViewUid( viewUid ) {}
992
993   virtual void Execute()
994   {
995     SALOME_View* view = uid2wnd( myViewUid );
996     SMESH_Actor* actor = actorFromView( view, myUid );
997     if ( actor )
998       myResult = (DisplayMode)actor->GetRepresentation();
999   }
1000 };
1001
1002 /////////////////////////////////////////////////////////////////
1003 /// \brief Get mesh object's display mode.
1004 /// \param uid Mesh object's study UID or IOR.
1005 /// \param viewUid View window UID (0 means currently active view
1006 ///                window); Default: 0.
1007 /// \return Display mode (UndefinedMode if actor isn't found).
1008 /////////////////////////////////////////////////////////////////
1009 DisplayMode SMESH_Swig::displayMode(const char* uid, int viewUid)
1010 {
1011   DisplayMode mode = UndefinedMode;
1012
1013   init();
1014
1015   _PTR(SObject) sobject = uid2object( uid );
1016   if ( sobject )
1017     mode = ProcessEvent( new TGetDisplayModeEvent( sobject->GetID().c_str(), viewUid ) );
1018
1019   return mode;
1020 }
1021
1022 /////////////////////////////////////////////////////////////////
1023 /// \internal
1024 /////////////////////////////////////////////////////////////////
1025 class TSetDisplayModeEvent: public SALOME_Event
1026 {
1027 public:
1028   const char* myUid;
1029   DisplayMode myMode;
1030   int myViewUid;
1031
1032   TSetDisplayModeEvent( const char* uid, DisplayMode mode, int viewUid )
1033     : myUid( uid ), myMode( mode), myViewUid( viewUid ) {}
1034
1035   virtual void Execute()
1036   {
1037     SALOME_View* view = uid2wnd( myViewUid );
1038     SMESH_Actor* actor = actorFromView( view, myUid );
1039     if ( actor && myMode != UndefinedMode )
1040     {
1041       actor->SetRepresentation( myMode );
1042       if ( view )
1043         view->Repaint();
1044     }
1045   }
1046 };
1047
1048 /////////////////////////////////////////////////////////////////
1049 /// \brief Set mesh object's display mode.
1050 /// \param uid Mesh object's study UID or IOR.
1051 /// \param mode Display mode.
1052 /// \param viewUid View window UID (0 means currently active view
1053 ///                window); Default: 0.
1054 /////////////////////////////////////////////////////////////////
1055 void SMESH_Swig::setDisplayMode(const char* uid, DisplayMode mode, int viewUid)
1056 {
1057   init();
1058
1059   _PTR(SObject) sobject = uid2object( uid );
1060   if ( sobject )
1061     ProcessVoidEvent( new TSetDisplayModeEvent( sobject->GetID().c_str(), mode, viewUid ) );
1062 }
1063
1064 /////////////////////////////////////////////////////////////////
1065 /// \internal
1066 /////////////////////////////////////////////////////////////////
1067 class TGetShrinkModeEvent: public SALOME_Event
1068 {
1069 public:
1070   typedef bool TResult;
1071   TResult myResult;
1072   const char* myUid;
1073   int myViewUid;
1074
1075   TGetShrinkModeEvent( const char* uid, int viewUid )
1076     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1077
1078   virtual void Execute()
1079   {
1080     SALOME_View* view = uid2wnd( myViewUid );
1081     SMESH_Actor* actor = actorFromView( view, myUid );
1082     if ( actor )
1083       myResult = actor->IsShrunk();
1084   }
1085 };
1086
1087 /////////////////////////////////////////////////////////////////
1088 /// \brief Check if shrink mode is switched on.
1089 /// \param uid Mesh object's study UID or IOR.
1090 /// \param viewUid View window UID (0 means currently active view
1091 ///                window); Default: 0.
1092 /// \return \c true if shrink mode is switched on;
1093 ///         \c false otherwise.
1094 /////////////////////////////////////////////////////////////////
1095 bool SMESH_Swig::shrinkMode(const char* uid, int viewUid)
1096 {
1097   bool shrinkMode = false;
1098
1099   init();
1100
1101   _PTR(SObject) sobject = uid2object( uid );
1102   if ( sobject )
1103     shrinkMode = ProcessEvent( new TGetShrinkModeEvent( sobject->GetID().c_str(), viewUid ) );
1104
1105   return shrinkMode;
1106 }
1107
1108 /////////////////////////////////////////////////////////////////
1109 /// \internal
1110 /////////////////////////////////////////////////////////////////
1111 class TSetShrinkModeEvent: public SALOME_Event
1112 {
1113 public:
1114   const char* myUid;
1115   bool myShrink;
1116   int myViewUid;
1117
1118   TSetShrinkModeEvent( const char* uid, bool shrink, int viewUid )
1119     : myUid( uid ), myShrink( shrink ), myViewUid( viewUid ) {}
1120
1121   virtual void Execute()
1122   {
1123     SALOME_View* view = uid2wnd( myViewUid );
1124     SMESH_Actor* actor = actorFromView( view, myUid );
1125     if ( actor )
1126     {
1127       if ( myShrink )
1128         actor->SetShrink();
1129       else
1130         actor->UnShrink();
1131       if ( view )
1132         view->Repaint();
1133     }
1134   }
1135 };
1136
1137 /////////////////////////////////////////////////////////////////
1138 /// \brief Switch shrink mode on/off.
1139 /// \param uid Mesh object's study UID or IOR.
1140 /// \param shrink \c true to switch shrink mode on;
1141 ///               \c false otherwise.
1142 /// \param viewUid View window UID (0 means currently active view
1143 ///                window); Default: 0.
1144 /////////////////////////////////////////////////////////////////
1145 void SMESH_Swig::setShrinkMode(const char* uid, bool shrink, int viewUid)
1146 {
1147   init();
1148
1149   _PTR(SObject) sobject = uid2object( uid );
1150   if ( sobject )
1151     ProcessVoidEvent( new TSetShrinkModeEvent( sobject->GetID().c_str(), shrink, viewUid ) );
1152 }
1153
1154 /////////////////////////////////////////////////////////////////
1155 /// \internal
1156 /////////////////////////////////////////////////////////////////
1157 class TGetOpacityEvent: public SALOME_Event
1158 {
1159 public:
1160   typedef double TResult;
1161   TResult myResult;
1162   const char* myUid;
1163   int myViewUid;
1164
1165   TGetOpacityEvent( const char* uid, int viewUid )
1166     : myResult( 0 ), myUid( uid ), myViewUid( viewUid ) {}
1167
1168   virtual void Execute()
1169   {
1170     SALOME_View* view = uid2wnd( myViewUid );
1171     SMESH_Actor* actor = actorFromView( view, myUid );
1172     if ( actor )
1173       myResult = actor->GetOpacity();
1174   }
1175 };
1176
1177 /////////////////////////////////////////////////////////////////
1178 /// \brief Get mesh object's opacity.
1179 /// \param uid Mesh object's study UID or IOR.
1180 /// \param viewUid View window UID (0 means currently active view
1181 ///                window); Default: 0.
1182 /// \return Opacity value.
1183 /////////////////////////////////////////////////////////////////
1184 double SMESH_Swig::opacity(const char* uid, int viewUid)
1185 {
1186   double opacity = 0;
1187
1188   init();
1189
1190   _PTR(SObject) sobject = uid2object( uid );
1191   if ( sobject )
1192     opacity = ProcessEvent( new TGetOpacityEvent( sobject->GetID().c_str(), viewUid ) );
1193
1194   return opacity;
1195 }
1196
1197 /////////////////////////////////////////////////////////////////
1198 /// \internal
1199 /////////////////////////////////////////////////////////////////
1200 class TSetOpacityEvent: public SALOME_Event
1201 {
1202 public:
1203   const char* myUid;
1204   double myOpacity;
1205   int myViewUid;
1206
1207   TSetOpacityEvent( const char* uid, double opacity, int viewUid )
1208     : myUid( uid ), myOpacity( opacity ), myViewUid( viewUid ) {}
1209
1210   virtual void Execute()
1211   {
1212     SALOME_View* view = uid2wnd( myViewUid );
1213     SMESH_Actor* actor = actorFromView( view, myUid );
1214     if ( actor )
1215     {
1216       actor->SetOpacity( myOpacity );
1217       if ( view )
1218         view->Repaint();
1219     }
1220   }
1221 };
1222
1223 /////////////////////////////////////////////////////////////////
1224 /// \brief Set mesh object's opacity.
1225 /// \param uid Mesh object's study UID or IOR.
1226 /// \param opacity Opacity value.
1227 /// \param viewUid View window UID (0 means currently active view
1228 ///                window); Default: 0.
1229 /////////////////////////////////////////////////////////////////
1230 void SMESH_Swig::setOpacity(const char* uid, double opacity, int viewUid)
1231 {
1232   init();
1233
1234   _PTR(SObject) sobject = uid2object( uid );
1235   if ( sobject )
1236     ProcessVoidEvent( new TSetOpacityEvent( sobject->GetID().c_str(), opacity, viewUid ) );
1237 }
1238
1239 /////////////////////////////////////////////////////////////////
1240 /// \internal
1241 /////////////////////////////////////////////////////////////////
1242 class TGetOrientationEvent: public SALOME_Event
1243 {
1244 public:
1245   typedef bool TResult;
1246   TResult myResult;
1247   const char* myUid;
1248   int myViewUid;
1249
1250   TGetOrientationEvent( const char* uid, int viewUid )
1251     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1252
1253   virtual void Execute()
1254   {
1255     SALOME_View* view = uid2wnd( myViewUid );
1256     SMESH_Actor* actor = actorFromView( view, myUid );
1257     if ( actor )
1258       myResult = actor->GetFacesOriented();
1259   }
1260 };
1261
1262 /////////////////////////////////////////////////////////////////
1263 /// \brief Check if faces orientation vectors are shown.
1264 /// \param uid Mesh object's study UID or IOR.
1265 /// \param viewUid View window UID (0 means currently active view
1266 ///                window); Default: 0.
1267 /// \return \c true if faces orientation vectors are shown;
1268 ///         \c false otherwise.
1269 /////////////////////////////////////////////////////////////////
1270 bool SMESH_Swig::isOrientationShown(const char* uid, int viewUid)
1271 {
1272   bool shown = false;
1273
1274   init();
1275
1276   _PTR(SObject) sobject = uid2object( uid );
1277   if ( sobject )
1278     shown = ProcessEvent( new TGetOrientationEvent( sobject->GetID().c_str(), viewUid ) );
1279
1280   return shown;
1281 }
1282
1283 /////////////////////////////////////////////////////////////////
1284 /// \internal
1285 /////////////////////////////////////////////////////////////////
1286 class TSetOrientationEvent: public SALOME_Event
1287 {
1288 public:
1289   const char* myUid;
1290   bool myShown;
1291   int myViewUid;
1292
1293   TSetOrientationEvent( const char* uid, bool shown, int viewUid )
1294     : myUid( uid ), myShown( shown ), myViewUid( viewUid ) {}
1295
1296   virtual void Execute()
1297   {
1298     SALOME_View* view = uid2wnd( myViewUid );
1299     SMESH_Actor* actor = actorFromView( view, myUid );
1300     if ( actor )
1301     {
1302       actor->SetFacesOriented( myShown );
1303       if ( view )
1304         view->Repaint();
1305     }
1306   }
1307 };
1308
1309 /////////////////////////////////////////////////////////////////
1310 /// \brief Show/hide faces orientation vectors.
1311 /// \param uid Mesh object's study UID or IOR.
1312 /// \param shown \c true to show faces orientation vectors;
1313 ///              \c false otherwise.
1314 /// \param viewUid View window UID (0 means currently active view
1315 ///                window); Default: 0.
1316 /////////////////////////////////////////////////////////////////
1317 void SMESH_Swig::setOrientationShown(const char* uid, bool shown, int viewUid)
1318 {
1319   init();
1320
1321   _PTR(SObject) sobject = uid2object( uid );
1322   if ( sobject )
1323     ProcessVoidEvent( new TSetOrientationEvent( sobject->GetID().c_str(), shown, viewUid ) );
1324 }
1325
1326 /////////////////////////////////////////////////////////////////
1327 /// \internal
1328 /////////////////////////////////////////////////////////////////
1329 class TGetEntitiesEvent: public SALOME_Event
1330 {
1331 public:
1332   typedef int TResult;
1333   TResult myResult;
1334   const char* myUid;
1335   int myViewUid;
1336
1337   TGetEntitiesEvent( const char* uid, int viewUid )
1338     : myResult( EntityNone ), myUid( uid ), myViewUid( viewUid ) {}
1339
1340   virtual void Execute()
1341   {
1342     SALOME_View* view = uid2wnd( myViewUid );
1343     SMESH_Actor* actor = actorFromView( view, myUid );
1344     if ( actor )
1345       myResult = actor->GetEntityMode();
1346   }
1347 };
1348
1349 /////////////////////////////////////////////////////////////////
1350 /// \brief Get mesh object's visible entities.
1351 /// \param uid Mesh object's study UID or IOR.
1352 /// \param viewUid View window UID (0 means currently active view
1353 ///                window); Default: 0.
1354 /// \return Enumerator describing entities being visible.
1355 /////////////////////////////////////////////////////////////////
1356 int SMESH_Swig::entitiesShown(const char* uid, int viewUid)
1357 {
1358   int entities = EntityNone;
1359
1360   init();
1361
1362   _PTR(SObject) sobject = uid2object( uid );
1363   if ( sobject )
1364     entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1365
1366   return entities;
1367 }
1368
1369 /////////////////////////////////////////////////////////////////
1370 /// \internal
1371 /////////////////////////////////////////////////////////////////
1372 class TSetEntitiesEvent: public SALOME_Event
1373 {
1374 public:
1375   const char* myUid;
1376   int myEntities;
1377   int myViewUid;
1378
1379   TSetEntitiesEvent( const char* uid, int entities, int viewUid )
1380     : myUid( uid ), myEntities( entities ), myViewUid( viewUid ) {}
1381
1382   virtual void Execute()
1383   {
1384     SALOME_View* view = uid2wnd( myViewUid );
1385     SMESH_Actor* actor = actorFromView( view, myUid );
1386     if ( actor )
1387     {
1388       actor->SetEntityMode( myEntities );
1389       if ( view )
1390         view->Repaint();
1391     }
1392   }
1393 };
1394
1395 /////////////////////////////////////////////////////////////////
1396 /// \brief Set mesh object's visible entities.
1397 /// \param uid Mesh object's study UID or IOR.
1398 /// \param entities Enumerator describing entities to be shown.
1399 /// \param viewUid View window UID (0 means currently active view
1400 ///                window); Default: 0.
1401 /////////////////////////////////////////////////////////////////
1402 void SMESH_Swig::setEntitiesShown(const char* uid, int entities, int viewUid)
1403 {
1404   init();
1405
1406   _PTR(SObject) sobject = uid2object( uid );
1407   if ( sobject )
1408     ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1409 }
1410
1411 /////////////////////////////////////////////////////////////////
1412 /// \brief Check if given mesh object's entity is shown.
1413 /// \param uid Mesh object's study UID or IOR.
1414 /// \param entity Mesh entity.
1415 /// \param viewUid View window UID (0 means currently active view
1416 ///                window); Default: 0.
1417 /// \return \c true if entity is shown; \c false otherwise.
1418 /////////////////////////////////////////////////////////////////
1419 bool SMESH_Swig::isEntityShown(const char* uid, EntityMode entity, int viewUid)
1420 {
1421   bool shown = false;
1422
1423   init();
1424
1425   _PTR(SObject) sobject = uid2object( uid );
1426   if ( sobject )
1427   {
1428     int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1429     shown = (bool)( entities & entity );
1430   }
1431
1432   return shown;
1433 }
1434
1435 /////////////////////////////////////////////////////////////////
1436 /// \brief Show/hide entity for given mesh object.
1437 /// \param uid Mesh object's study UID or IOR.
1438 /// \param entity Mesh entity.
1439 /// \param show Visibility status.
1440 /// \param viewUid View window UID (0 means currently active view
1441 ///                window); Default: 0.
1442 /////////////////////////////////////////////////////////////////
1443 void SMESH_Swig::setEntityShown(const char* uid, EntityMode entity, bool show, int viewUid)
1444 {
1445   init();
1446
1447   _PTR(SObject) sobject = uid2object( uid );
1448   if ( sobject )
1449   {
1450     int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1451     if ( show )
1452       entities |= entity;
1453     else
1454       entities &= ~entity;
1455     ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1456   }
1457 }
1458
1459 /////////////////////////////////////////////////////////////////
1460 /// \brief Initialize %SMESH GUI Python interface.
1461 /// \deprecated Interface is initialized automatically.
1462 /////////////////////////////////////////////////////////////////
1463 void SMESH_Swig::Init()
1464 {
1465   deprecated("SMESH_Swig::Init");
1466   // does nothing; initialization is done automatically.
1467 }
1468
1469 /////////////////////////////////////////////////////////////////
1470 /// \brief Publish mesh in the active study.
1471 /// \deprecated Publishing is done automatically.
1472 /// \param ior IOR of the mesh.
1473 /// \param name Name of the mesh (optional).
1474 /// \return UID of the data object.
1475 /////////////////////////////////////////////////////////////////
1476 const char* SMESH_Swig::AddNewMesh(const char* ior, const char* name)
1477 {
1478   deprecated("SMESH_Swig::AddNewMesh", "SMESH_Swig::publish");
1479   return publish( ior, name );
1480 }
1481
1482 /////////////////////////////////////////////////////////////////
1483 /// \brief Publish hypothesis in the active study.
1484 /// \deprecated Publishing is done automatically.
1485 /// \param ior IOR of the hypothesis.
1486 /// \param name Name of the hypothesis (optional).
1487 /// \return UID of the data object.
1488 /////////////////////////////////////////////////////////////////
1489 const char* SMESH_Swig::AddNewHypothesis(const char* ior, const char* name)
1490 {
1491   deprecated("SMESH_Swig::AddNewHypothesis", "SMESH_Swig::publish");
1492   return publish( ior, name );
1493 }
1494
1495 /////////////////////////////////////////////////////////////////
1496 /// \brief Publish algorithm in the active study.
1497 /// \deprecated Publishing is done automatically.
1498 /// \param ior IOR of the algorithm.
1499 /// \param name Name of the algorithm (optional).
1500 /// \return UID of the data object.
1501 /////////////////////////////////////////////////////////////////
1502 const char* SMESH_Swig::AddNewAlgorithm(const char* ior, const char* name)
1503 {
1504   deprecated("SMESH_Swig::AddNewAlgorithm", "SMESH_Swig::publish");
1505   return publish( ior, name );
1506 }
1507
1508 /////////////////////////////////////////////////////////////////
1509 /// \deprecated Publishing is done automatically.
1510 /// \deprecated Synonim of AddNewAlgorithm().
1511 /// \param ior IOR of the algorithm.
1512 /// \param name Name of the algorithm (optional).
1513 /// \return UID of the data object.
1514 /////////////////////////////////////////////////////////////////
1515 const char* SMESH_Swig::AddNewAlgorithms(const char* ior, const char* name)
1516 {
1517   deprecated("SMESH_Swig::AddNewAlgorithms", "SMESH_Swig::publish");
1518   return publish( ior, name );
1519 }
1520
1521 /////////////////////////////////////////////////////////////////
1522 /// \brief Add reference on a shape for mesh in a study.
1523 /// \deprecated Publishing is done automatically.
1524 /// \param shapeUid GEOM shape's study UID (not used).
1525 /// \param meshUid Mesh's study UID (not used).
1526 /////////////////////////////////////////////////////////////////
1527 void SMESH_Swig::SetShape(const char* /*shapeUid*/, const char* /*meshUid*/)
1528 {
1529   deprecated("SMESH_Swig::SetShape", "SMESH_Swig::publish");
1530   // does nothing: publishing is done automatically
1531 }
1532
1533 /////////////////////////////////////////////////////////////////
1534 /// \brief Assign hypothesis to mesh or sub-mesh.
1535 /// \deprecated Publishing is done automatically.
1536 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1537 /// \param hypoUID Hypothesis's study UID (not used).
1538 /////////////////////////////////////////////////////////////////
1539 void SMESH_Swig::SetHypothesis(const char* /*meshUid*/, const char* /*hypoUID*/)
1540 {
1541   deprecated("SMESH_Swig::SetHypothesis", "SMESH_Swig::publish");
1542   // does nothing: publishing is done automatically
1543 }
1544
1545 /////////////////////////////////////////////////////////////////
1546 /// \brief Assign algorithm to mesh or sub-mesh.
1547 /// \deprecated Publishing is done automatically.
1548 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1549 /// \param algoUID Algorithm's study UID (not used).
1550 /////////////////////////////////////////////////////////////////
1551 void SMESH_Swig::SetAlgorithms(const char* /*meshUid*/, const char* /*algoUID*/)
1552 {
1553   deprecated("SMESH_Swig::SetAlgorithms", "SMESH_Swig::publish");
1554   // does nothing: publishing is done automatically
1555 }
1556
1557 /////////////////////////////////////////////////////////////////
1558 /// \brief Anassign hypothesis or algorithm from mesh or sub-mesh.
1559 /// \deprecated Unpublishing is done automatically.
1560 /// \param uid Hypothesis's or algorithm's study UID (not used).
1561 /////////////////////////////////////////////////////////////////
1562 void SMESH_Swig::UnSetHypothesis(const char* /*uid*/)
1563 {
1564   deprecated("SMESH_Swig::UnSetHypothesis");
1565   // does nothing: unpublishing is done automatically
1566 }
1567
1568 /////////////////////////////////////////////////////////////////
1569 /// \brief Publish sub-mesh in the active study.
1570 /// \deprecated Publishing is done automatically.
1571 /// \param meshUid Parent mesh's study UID (not used).
1572 /// \param ior IOR of the sub-mesh.
1573 /// \param shapeType GEOM shape's type (not used).
1574 /// \param name Name of the sub-mesh (optional).
1575 /// \return UID of the data object.
1576 /////////////////////////////////////////////////////////////////
1577 const char* SMESH_Swig::AddSubMesh(const char* /*meshUid*/,
1578                                    const char* ior,
1579                                    int /*shapeType*/,
1580                                    const char* name)
1581 {
1582   deprecated("SMESH_Swig::AddSubMesh", "SMESH_Swig::publish");
1583   return publish( ior, name );
1584 }
1585
1586 /////////////////////////////////////////////////////////////////
1587 /// \brief Publish sub-mesh in the active study.
1588 /// \deprecated Publishing is done automatically.
1589 /// \param meshUid Parent mesh's study UID (not used).
1590 /// \param shapeUid GEOM shape's study UID (not used).
1591 /// \param ior IOR of the sub-mesh.
1592 /// \param shapeType GEOM shape's type (not used).
1593 /// \param name Name of the sub-mesh (optional).
1594 /// \return UID of the data object.
1595 /////////////////////////////////////////////////////////////////
1596 const char* SMESH_Swig::AddSubMeshOnShape(const char* /*meshUid*/,
1597                                           const char* /*shapeUid*/,
1598                                           const char* ior,
1599                                           int /*shapeType*/,
1600                                           const char* name)
1601 {
1602   deprecated("SMESH_Swig::AddSubMeshOnShape", "SMESH_Swig::publish");
1603   return publish( ior, name );
1604 }
1605
1606 /////////////////////////////////////////////////////////////////
1607 /// \brief Set new study name of given object.
1608 /// \deprecated Use rename() method.
1609 /// \param uid Object's study UID or IOR.
1610 /// \param name New name of the object.
1611 /////////////////////////////////////////////////////////////////
1612 void SMESH_Swig::SetName(const char* uid, const char* name)
1613 {
1614   deprecated("SMESH_Swig::SetName", "SMESH_Swig::rename");
1615   rename( uid, name );
1616 }
1617
1618 /////////////////////////////////////////////////////////////////
1619 /// \brief Set mesh icon according to compute status
1620 /// \deprecated Publishing is done automatically.
1621 /// \param meshUid Mesh's study UID (not used).
1622 /// \param isComputed Flag pointing that mesh is computed or no
1623 ///        (not used).
1624 /// \param isEmpty Flag pointing that mesh is empty or no
1625 ///        (not used).
1626 /////////////////////////////////////////////////////////////////
1627 void SMESH_Swig::SetMeshIcon(const char* /*meshUid*/,
1628                              const bool /*isComputed*/,
1629                              const bool /*isEmpty*/)
1630 {
1631   deprecated("SMESH_Swig::SetMeshIcon", "SMESH_Swig::publish");
1632   // does nothing: publishing is done automatically
1633 }
1634
1635 /////////////////////////////////////////////////////////////////
1636 /// Display mesh in the currently active view window.
1637 /// \deprecated Use display() method.
1638 /// \param meshUid Mesh's study UID.
1639 /////////////////////////////////////////////////////////////////
1640 void SMESH_Swig::CreateAndDisplayActor(const char* meshUid)
1641 {
1642   deprecated("SMESH_Swig::CreateAndDisplayActor", "SMESH_Swig::display");
1643   display( meshUid );
1644 }
1645
1646 /////////////////////////////////////////////////////////////////
1647 /// Erase mesh in the view window(s).
1648 /// \deprecated Use erase() method.
1649 /// \param meshUid Mesh's study UID.
1650 /// \param allViewers If \c true, mesh is removed from all views.
1651 ///                   Default: \c false.
1652 /////////////////////////////////////////////////////////////////
1653 void SMESH_Swig::EraseActor(const char* meshUid, const bool allViewers)
1654 {
1655   deprecated("SMESH_Swig::EraseActor", "SMESH_Swig::erase");
1656   erase( meshUid, allViewers ? -1 : 0 );
1657 }
1658
1659 /////////////////////////////////////////////////////////////////
1660 /// Update mesh object.
1661 /// \deprecated Use update() method.
1662 /// \param meshUid Mesh's study UID.
1663 /////////////////////////////////////////////////////////////////
1664 void SMESH_Swig::UpdateActor(const char* meshUid)
1665 {
1666   deprecated("SMESH_Swig::UpdateActor", "SMESH_Swig::update");
1667   update( meshUid );
1668 }
1669
1670 /////////////////////////////////////////////////////////////////
1671 /// Get mesh object's properties.
1672 /// \deprecated Use properties() method.
1673 /// \param meshUid Mesh's study UID.
1674 /// \param viewUid View window UID (0 means currently active view
1675 ///                window). Default: 0.
1676 /////////////////////////////////////////////////////////////////
1677 actorAspect SMESH_Swig::GetActorAspect(const char* meshUid, int viewUid)
1678 {
1679   deprecated("SMESH_Swig::GetActorAspect", "SMESH_Swig::properties");
1680   return properties( meshUid, viewUid );
1681 }
1682
1683 /////////////////////////////////////////////////////////////////
1684 /// Set mesh object's properties.
1685 /// \deprecated Use setProperties() method.
1686 /// \param meshUid Mesh's study UID.
1687 /// \param viewUid View window UID (0 means currently active view
1688 ///                window). Default: 0.
1689 /////////////////////////////////////////////////////////////////
1690 void SMESH_Swig::SetActorAspect(const actorAspect& aspect, const char* meshUid, int viewUid)
1691 {
1692   deprecated("SMESH_Swig::SetActorAspect", "SMESH_Swig::setProperties");
1693   setProperties( meshUid, aspect, viewUid );
1694 }
1695
1696 /////////////////////////////////////////////////////////////////
1697 /// \internal
1698 /////////////////////////////////////////////////////////////////
1699 class TSelectListEvent: public SALOME_Event
1700 {
1701   const char* myUid;
1702   std::vector<int> myIds;
1703   bool myIsAppend;
1704
1705 public:
1706   TSelectListEvent(const char* uid, std::vector<int> ids, bool append)
1707     : myUid( uid ), myIds( ids ), myIsAppend( append )
1708   {}
1709
1710   virtual void Execute()
1711   {
1712     LightApp_SelectionMgr* selMgr = 0;
1713     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1714     if ( app )
1715       selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1716
1717     if ( !selMgr )
1718       return;
1719     
1720     selMgr->clearFilters();
1721
1722     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1723     if ( !vw )
1724       return;
1725
1726     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1727     
1728     if ( !actor || !actor->hasIO() )
1729       return;
1730     
1731     Handle(SALOME_InteractiveObject) io = actor->getIO();
1732     SALOME_ListIO ios;
1733     ios.Append( io );
1734     selMgr->setSelectedObjects( ios, false );
1735
1736     if ( vw->SelectionMode() == ActorSelection )
1737       return;
1738         
1739     TColStd_MapOfInteger idMap;
1740     std::vector<int>::const_iterator it;
1741     for ( it = myIds.begin(); it != myIds.end(); ++it )
1742     {
1743       idMap.Add( *it );
1744     }
1745
1746     // Set new selection
1747     SVTK_Selector* selector = vw->GetSelector();
1748     selector->AddOrRemoveIndex( io, idMap, myIsAppend );
1749     vw->highlight( io, true, true );
1750     vw->GetInteractor()->onEmitSelectionChanged();
1751   }
1752 };
1753
1754 /////////////////////////////////////////////////////////////////
1755 /// \brief Select elements of the mesh, sub-mesh or group.
1756 /// \param uid Mesh object's study UID or IOR.
1757 /// \param ids List of mesh elements.
1758 /// \param append If \c true, elements are added to current
1759 ///               selection; otherwise, previous selection is
1760 ///               cleared.
1761 /////////////////////////////////////////////////////////////////
1762 void SMESH_Swig::select(const char* uid, std::vector<int> ids, bool append)
1763 {
1764   init();
1765
1766   _PTR(SObject) sobject = uid2object( uid );
1767   if ( sobject )
1768     ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1769 }
1770   
1771 /////////////////////////////////////////////////////////////////
1772 /// \brief Select element of the mesh, sub-mesh or group.
1773 /// \param uid Mesh object's study UID or IOR.
1774 /// \param id Mesh element.
1775 /// \param append If \c true, element is added to current
1776 ///               selection; otherwise, previous selection is
1777 ///               cleared.
1778 /////////////////////////////////////////////////////////////////
1779 void SMESH_Swig::select(const char* uid, int id, bool append)
1780 {
1781   init();
1782
1783   std::vector<int> ids;
1784   ids.push_back( id );
1785
1786   _PTR(SObject) sobject = uid2object( uid );
1787   if ( sobject )
1788     ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1789 }
1790
1791 /////////////////////////////////////////////////////////////////
1792 /// \internal
1793 /////////////////////////////////////////////////////////////////
1794 class TSelectListOfPairEvent: public SALOME_Event
1795 {
1796   const char* myUid;
1797   std::vector<std::pair<int, int> > myIds;
1798   bool myIsAppend;
1799
1800 public:
1801   TSelectListOfPairEvent(const char* uid, std::vector<std::pair<int, int> > ids, bool append)
1802     : myUid( uid ), myIds( ids ), myIsAppend( append )
1803   {}
1804
1805   virtual void Execute()
1806   {
1807     LightApp_SelectionMgr* selMgr = 0;
1808     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1809     if ( app )
1810       selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1811
1812     if ( !selMgr )
1813       return;
1814     
1815     selMgr->clearFilters();
1816
1817     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1818     if ( !vw )
1819       return;
1820
1821     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1822     
1823     if ( !actor || !actor->hasIO() )
1824       return;
1825     
1826     Handle(SALOME_InteractiveObject) io = actor->getIO();
1827     SALOME_ListIO ios;
1828     ios.Append( io );
1829     selMgr->setSelectedObjects( ios, false );
1830
1831     if ( vw->SelectionMode() != EdgeOfCellSelection )
1832       return;
1833         
1834     SVTK_IndexedMapOfIds idMap;
1835     std::vector<std::pair<int, int> >::const_iterator it;
1836     for ( it = myIds.begin(); it != myIds.end(); ++it )
1837     {
1838       std::vector<int> pair;
1839       pair.push_back( (*it).first );
1840       pair.push_back( (*it).second );
1841       idMap.Add( pair );
1842     }
1843
1844     // Set new selection
1845     SVTK_Selector* selector = vw->GetSelector();
1846     selector->AddOrRemoveCompositeIndex( io, idMap, myIsAppend );
1847     vw->highlight( io, true, true );
1848     vw->GetInteractor()->onEmitSelectionChanged();
1849   }
1850 };
1851
1852 /////////////////////////////////////////////////////////////////
1853 /// \brief Select pseudo-edges (specified by two nodes)
1854 ///        of the mesh, sub-mesh or group.
1855 /// \param uid Mesh object's study UID or IOR.
1856 /// \param ids List of pairs containing two nodes IDs.
1857 /// \param append If \c true, pseudo-edges are added to current
1858 ///               selection; otherwise, previous selection is
1859 ///               cleared.
1860 /////////////////////////////////////////////////////////////////
1861 void SMESH_Swig::select(const char* uid, std::vector<std::pair<int,int> > ids, bool append)
1862 {
1863   init();
1864
1865   _PTR(SObject) sobject = uid2object( uid );
1866   if ( sobject )
1867     ProcessVoidEvent( new TSelectListOfPairEvent( sobject->GetID().c_str(), ids, append ) );
1868 }
1869
1870 /////////////////////////////////////////////////////////////////
1871 /// \internal
1872 /////////////////////////////////////////////////////////////////
1873 class TGetSelectionModeEvent: public SALOME_Event
1874 {
1875 public:
1876   typedef SelectionMode TResult;
1877   TResult myResult;
1878   int myViewUid;
1879
1880   TGetSelectionModeEvent( int viewUid ) :
1881     myResult( Undefined ), myViewUid( viewUid ) {}
1882
1883   virtual void Execute()
1884   {
1885     SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1886     if ( model )
1887     {
1888       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1889       if ( vw )
1890         myResult = (SelectionMode)vw->SelectionMode();
1891     }
1892   }
1893 };
1894
1895 /////////////////////////////////////////////////////////////////
1896 /// \brief Get selection mode of view window.
1897 /// \param viewUid View window UID (0 means currently active view
1898 ///                window); Default: 0.
1899 /// \return Current selection mode.
1900 /////////////////////////////////////////////////////////////////
1901 SelectionMode SMESH_Swig::getSelectionMode(int viewUid)
1902 {
1903   init();
1904   return ProcessEvent( new TGetSelectionModeEvent( viewUid ) );
1905 }
1906
1907 /////////////////////////////////////////////////////////////////
1908 /// \internal
1909 /////////////////////////////////////////////////////////////////
1910 class TSetSelectionModeEvent: public SALOME_Event
1911 {
1912   SelectionMode mySelectionMode;
1913   int myViewUid;
1914
1915 public:
1916   TSetSelectionModeEvent( const SelectionMode selectionMode, int viewUid )
1917     : mySelectionMode( selectionMode ), myViewUid( viewUid )
1918   {}
1919
1920   virtual void Execute()
1921   {
1922     SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1923     if ( model )
1924     {
1925       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1926       if ( vw )
1927       {
1928         SelectionMode previousMode = (SelectionMode)vw->SelectionMode();
1929         bool switchPointMode = ( previousMode == Node && mySelectionMode != Node ) ||
1930           ( previousMode != Node && mySelectionMode == Node );
1931         if ( switchPointMode )
1932         {
1933           vtkRenderer* renderer = vw->getRenderer();
1934           VTK::ActorCollectionCopy actors( renderer->GetActors() );
1935           vtkActorCollection* collection = actors.GetActors();
1936           collection->InitTraversal();
1937           while ( vtkActor* vtkActor = collection->GetNextActor() )
1938           {
1939             if ( SMESH_Actor* actor = dynamic_cast<SMESH_Actor*>( vtkActor ) )
1940             {
1941               if ( actor->GetVisibility() )
1942                 actor->SetPointRepresentation( mySelectionMode == Node );
1943             }
1944           }
1945         }
1946         vw->SetSelectionMode( mySelectionMode );
1947       }
1948     }
1949   }
1950 };
1951
1952 /////////////////////////////////////////////////////////////////
1953 /// \brief Set selection mode to view window.
1954 /// \param viewUid View window UID (0 means currently active view
1955 ///                window); Default: 0.
1956 /// \param mode Selection mode.
1957 /////////////////////////////////////////////////////////////////
1958 void SMESH_Swig::setSelectionMode(SelectionMode mode, int viewUid)
1959 {
1960   init();
1961   ProcessVoidEvent( new TSetSelectionModeEvent( mode, viewUid ) ); 
1962 }
1963
1964 /////////////////////////////////////////////////////////////////
1965 /// \internal
1966 /////////////////////////////////////////////////////////////////
1967 class TGetSelectedEvent: public SALOME_Event
1968 {
1969 public:
1970   typedef std::vector<int> TResult;
1971   TResult myResult;
1972   const char* myUid;
1973   
1974   TGetSelectedEvent( const char* uid )
1975     : myUid( uid ) {}
1976   
1977   virtual void Execute()
1978   {
1979     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1980     if ( !vw )
1981       return;
1982
1983     SVTK_Selector* selector = vw->GetSelector();    
1984     if ( !selector )
1985       return;
1986
1987     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1988     if ( !actor || !actor->hasIO() )
1989       return;
1990
1991     TColStd_IndexedMapOfInteger idMap;
1992     selector->GetIndex( actor->getIO(), idMap );
1993
1994     for ( int i = 1; i <= idMap.Extent(); i++ )
1995       myResult.push_back( idMap( i ) );
1996   }
1997 };
1998
1999 /////////////////////////////////////////////////////////////////
2000 /// \brief Get selected elements of the mesh, sub-mesh or group.
2001 /// \param uid Mesh object's study UID or IOR.
2002 /// \return List of selected mesh elements.
2003 /////////////////////////////////////////////////////////////////
2004 std::vector<int> SMESH_Swig::getSelected(const char* uid)
2005 {
2006   std::vector<int> ids;
2007
2008   init();
2009
2010   _PTR(SObject) sobject = uid2object( uid );
2011   if ( sobject )
2012     ids = ProcessEvent( new TGetSelectedEvent( sobject->GetID().c_str() ) );
2013
2014   return ids;
2015 }
2016
2017 /////////////////////////////////////////////////////////////////
2018 /// \internal
2019 /////////////////////////////////////////////////////////////////
2020 class TGetSelectedPairEvent : public SALOME_Event
2021 {
2022 public:
2023   typedef std::vector<std::pair<int, int> > TResult;
2024   TResult myResult;
2025   const char* myUid;
2026   
2027   TGetSelectedPairEvent( const char* uid )
2028     :  myUid( uid ) {}
2029   
2030   virtual void Execute()
2031   {
2032     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2033     if ( !vw )
2034       return;
2035
2036     if ( vw->SelectionMode() != EdgeOfCellSelection )
2037       return;
2038
2039     SVTK_Selector* selector = vw->GetSelector();    
2040     if ( !selector )
2041       return;
2042
2043     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2044     if ( !actor || !actor->hasIO() )
2045       return;
2046
2047     SVTK_IndexedMapOfIds idMap;
2048     selector->GetCompositeIndex( actor->getIO(), idMap );
2049
2050     for ( int i = 1; i <= idMap.Extent(); i++ )
2051       myResult.push_back( std::make_pair<int,int>( (int)idMap( i )[0], (int)idMap( i )[1]) );
2052   }
2053 };
2054
2055 /////////////////////////////////////////////////////////////////
2056 /// \brief Get selected pseudo-edges (specified by two nodes)
2057 ///        of the mesh, sub-mesh or group.
2058 /// \param uid Mesh object's study UID or IOR.
2059 /// \param ids List of pairs containing two nodes IDs.
2060 /// \param append If \c true, pseudo-edges are added to current
2061 ///               selection; otherwise, previous selection is
2062 ///               cleared.
2063 /////////////////////////////////////////////////////////////////
2064 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell(const char* uid)
2065 {
2066   std::vector<std::pair<int,int> > pairs;
2067
2068   init();
2069
2070   _PTR(SObject) sobject = uid2object( uid );
2071   if ( sobject )
2072     pairs = ProcessEvent( new TGetSelectedPairEvent( sobject->GetID().c_str() ) );
2073
2074   return pairs;
2075 }