Salome HOME
b36929250b9aec6219174857f350c7991eb2054b
[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   if ( SUIT_Session::session() )
568   {
569     ProcessVoidEvent( new TInitEvent() );
570     SMESHGUI::GetSMESHGen()->UpdateStudy();
571   }
572 }
573
574 /////////////////////////////////////////////////////////////////
575 /// \brief Publish object.
576 /// \param ior IOR of the mesh object to publish.
577 /// \param name Study name of the object; if not given,
578 ///             name is assigned automatically.
579 /// \return UID of the data object.
580 /////////////////////////////////////////////////////////////////
581 const char* SMESH_Swig::publish(const char* ior, const char* name)
582 {
583   init();
584
585   std::string uid;
586   CORBA::Object_var object = string2object( ior );
587   if ( !CORBA::is_nil( object ) )
588     {
589       SALOMEDS::SObject_var sobject =
590         SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(),
591                                                  object.in(),
592                                                  name );
593       if ( !CORBA::is_nil( sobject ) )
594         {
595           uid = sobject->GetID();
596         }
597       sobject->UnRegister();
598     }
599
600   return strdup( uid.c_str() );
601 }
602
603 /////////////////////////////////////////////////////////////////
604 /// \brief Set new study name of given object.
605 /// \param uid Object's study UID or IOR.
606 /// \param name New name of the object.
607 /////////////////////////////////////////////////////////////////
608 void SMESH_Swig::rename(const char* uid, const char* name)
609 {
610   init();
611
612   _PTR(SObject) sobject = uid2object( uid );
613   if ( sobject )
614     sobject->SetAttrString( "AttributeName", name );
615 }
616
617 /////////////////////////////////////////////////////////////////
618 /// \brief Display mesh object.
619 /// \param uid Object's study UID or IOR.
620 /// \param viewUid View window UID (0 means currently active view
621 ///                window; if there's no view, it is created).
622 ///                Default: 0.
623 /// \param updateViewer "Update view" flag. Default: \c true.
624 /////////////////////////////////////////////////////////////////
625 void SMESH_Swig::display(const char* uid, int viewUid, bool updateViewer)
626 {
627   class TDisplayEvent: public SALOME_Event
628   {
629   private:
630     const char* myUid;
631     int myViewUid;
632     bool myIsUpdate;
633   public:
634     TDisplayEvent(const char* uid, int viewUid, bool updateViewer)
635       : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
636     virtual void Execute()
637     {
638       SALOME_View* view = uid2wnd( myViewUid, true ); // create view if it's not present
639       if ( view )
640         LightApp_Displayer::FindDisplayer( "Mesh", true )->Display( myUid, myIsUpdate, view );
641     }
642   };
643
644   init();
645
646   _PTR(SObject) sobject = uid2object( uid );
647   if ( sobject )
648     ProcessVoidEvent( new TDisplayEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
649 }
650
651 /////////////////////////////////////////////////////////////////
652 /// \brief Erase mesh object.
653 /// \param uid Object's study UID or IOR.
654 /// \param viewUid View window UID (0 means currently active view
655 ///                window); -1 means "all view windows".
656 ///                Default: 0.
657 /// \param updateViewer "Update view" flag. Default: \c true.
658 /////////////////////////////////////////////////////////////////
659 void SMESH_Swig::erase(const char* uid, int viewUid, bool updateViewer)
660 {
661   class TEraseEvent: public SALOME_Event
662   {
663   private:
664     const char* myUid;
665     int myViewUid;
666     bool myIsUpdate;
667   public:
668     TEraseEvent(const char* uid, int viewUid, bool updateViewer)
669       : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
670     virtual void Execute()
671     {
672       if ( myViewUid == -1 )
673       {
674         QList<SALOME_View*> views = windows();
675         foreach( SALOME_View* view, views )
676           LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
677       }
678       else
679       {
680         SALOME_View* view = uid2wnd( myViewUid );
681         if ( view )
682           LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
683       }
684     }
685   };
686
687   init();
688
689   _PTR(SObject) sobject = uid2object( uid );
690   if ( sobject )
691     ProcessVoidEvent( new TEraseEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
692 }
693
694 /////////////////////////////////////////////////////////////////
695 /// \brief Update mesh object.
696 /// \param uid Object's study UID or IOR.
697 /////////////////////////////////////////////////////////////////
698 void SMESH_Swig::update(const char* uid)
699 {
700   class TUpdateEvent: public SALOME_Event
701   {
702   private:
703     const char* myUid;
704   public:
705     TUpdateEvent( const char* uid ) : myUid( uid ) {}
706     virtual void Execute()
707     {
708       Handle(SALOME_InteractiveObject) io = 
709         new SALOME_InteractiveObject( myUid, "SMESH", "" );
710       SMESH::Update( io, true );
711     }
712   };
713
714   init();
715
716   _PTR(SObject) sobject = uid2object( uid );
717   if ( sobject )
718     ProcessVoidEvent( new TUpdateEvent( uid ) );
719 }
720
721 /////////////////////////////////////////////////////////////////
722 /// \internal
723 class TGetPropsEvent: public SALOME_Event
724 {
725 public:
726   typedef Properties TResult;
727   TResult myResult;
728   const char* myUid;
729   int myViewUid;
730
731   TGetPropsEvent( const char* uid, int viewUid )
732     : myUid( uid ), myViewUid( viewUid ) {}
733
734   virtual void Execute()
735   {
736     SALOME_View* view = uid2wnd( myViewUid );
737     myResult = properties( view, myUid );
738   }
739 };
740
741 /////////////////////////////////////////////////////////////////
742 /// \brief Get mesh object's visual properties.
743 /// \param uid Mesh object's study UID or IOR.
744 /// \param viewUid View window UID (0 means currently active view
745 ///                window); Default: 0.
746 /// \return Properties data structure.
747 /////////////////////////////////////////////////////////////////
748 Properties SMESH_Swig::properties(const char* uid, int viewUid)
749 {
750   Properties props;
751
752   init();
753
754   _PTR(SObject) sobject = uid2object( uid );
755   if ( sobject )
756     props = ProcessEvent( new TGetPropsEvent( sobject->GetID().c_str(), viewUid ) );
757
758   return props;
759 }
760
761 /////////////////////////////////////////////////////////////////
762 /// \internal
763 /////////////////////////////////////////////////////////////////
764 class TSetPropsEvent: public SALOME_Event
765 {
766 public:
767   const char* myUid;
768   Properties myProps;
769   int myViewUid;
770
771   TSetPropsEvent( const char* uid, const Properties& props, int viewUid )
772     : myUid( uid ), myProps( props), myViewUid( viewUid ) {}
773
774   virtual void Execute()
775   {
776     if ( myViewUid == -1 )
777     {
778       QList<SALOME_View*> views = windows();
779       foreach( SALOME_View* view, views )
780       {
781         setProperties( view, myUid, myProps );
782       }
783     }
784     else
785     {
786       SALOME_View* view = uid2wnd( myViewUid );
787       setProperties( view, myUid, myProps );
788     }
789   }
790 };
791
792 /////////////////////////////////////////////////////////////////
793 /// \brief Set mesh object's visual properties.
794 /// \param uid Mesh object's study UID or IOR.
795 /// \param props Properties data structure.
796 /// \param viewUid View window UID (0 means currently active view
797 ///                window); Default: 0.
798 /////////////////////////////////////////////////////////////////
799 void SMESH_Swig::setProperties(const char* uid, const Properties& props, int viewUid)
800 {
801   init();
802
803   _PTR(SObject) sobject = uid2object( uid );
804   if ( sobject )
805     ProcessVoidEvent( new TSetPropsEvent( sobject->GetID().c_str(), props, viewUid ) );
806 }
807
808 /////////////////////////////////////////////////////////////////
809 /// \internal
810 /////////////////////////////////////////////////////////////////
811 class TGetNodeNumberingEvent: public SALOME_Event
812 {
813 public:
814   typedef bool TResult;
815   TResult myResult;
816   const char* myUid;
817   int myViewUid;
818
819   TGetNodeNumberingEvent( const char* uid, int viewUid )
820     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
821
822   virtual void Execute()
823   {
824     SALOME_View* view = uid2wnd( myViewUid );
825     SMESH_Actor* actor = actorFromView( view, myUid );
826     if ( actor )
827       myResult = actor->GetPointsLabeled();
828   }
829 };
830
831 /////////////////////////////////////////////////////////////////
832 /// \brief Check if nodes numbering is switched on.
833 /// \param uid Mesh object's study UID or IOR.
834 /// \param viewUid View window UID (0 means currently active view
835 ///                window); Default: 0.
836 /// \return \c true if nodes numbering is switched on;
837 ///         \c false otherwise.
838 /////////////////////////////////////////////////////////////////
839 bool SMESH_Swig::nodesNumbering(const char* uid, int viewUid)
840 {
841   bool numbering = false;
842
843   init();
844
845   _PTR(SObject) sobject = uid2object( uid );
846   if ( sobject )
847     numbering = ProcessEvent( new TGetNodeNumberingEvent( sobject->GetID().c_str(), viewUid ) );
848
849   return numbering;
850 }
851
852 /////////////////////////////////////////////////////////////////
853 /// \internal
854 /////////////////////////////////////////////////////////////////
855 class TSetNodeNumberingEvent: public SALOME_Event
856 {
857 public:
858   const char* myUid;
859   bool myNumbering;
860   int myViewUid;
861
862   TSetNodeNumberingEvent( const char* uid, bool numbering, int viewUid )
863     : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
864
865   virtual void Execute()
866   {
867     SALOME_View* view = uid2wnd( myViewUid );
868     SMESH_Actor* actor = actorFromView( view, myUid );
869     if ( actor )
870     {
871       actor->SetPointsLabeled( myNumbering );
872       if ( view )
873         view->Repaint();
874     }
875   }
876 };
877
878 /////////////////////////////////////////////////////////////////
879 /// \brief Switch nodes numbering on/off.
880 /// \param uid Mesh object's study UID or IOR.
881 /// \param numbering \c true to switch nodes numbering on;
882 ///                  \c false otherwise.
883 /// \param viewUid View window UID (0 means currently active view
884 ///                window); Default: 0.
885 /////////////////////////////////////////////////////////////////
886 void SMESH_Swig::setNodesNumbering(const char* uid, bool numbering, int viewUid)
887 {
888   init();
889
890   _PTR(SObject) sobject = uid2object( uid );
891   if ( sobject )
892     ProcessVoidEvent( new TSetNodeNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
893 }
894
895 /////////////////////////////////////////////////////////////////
896 /// \internal
897 /////////////////////////////////////////////////////////////////
898 class TGetElementNumberingEvent: public SALOME_Event
899 {
900 public:
901   typedef bool TResult;
902   TResult myResult;
903   const char* myUid;
904   int myViewUid;
905
906   TGetElementNumberingEvent( const char* uid, int viewUid )
907     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
908
909   virtual void Execute()
910   {
911     SALOME_View* view = uid2wnd( myViewUid );
912     SMESH_Actor* actor = actorFromView( view, myUid );
913     if ( actor )
914       myResult = actor->GetCellsLabeled();
915   }
916 };
917
918 /////////////////////////////////////////////////////////////////
919 /// \brief Check if elements numbering is switched on.
920 /// \param uid Mesh object's study UID or IOR.
921 /// \param viewUid View window UID (0 means currently active view
922 ///                window); Default: 0.
923 /// \return \c true if elements numbering is switched on;
924 ///         \c false otherwise.
925 /////////////////////////////////////////////////////////////////
926 bool SMESH_Swig::elementsNumbering(const char* uid, int viewUid)
927 {
928   bool numbering = false;
929
930   init();
931
932   _PTR(SObject) sobject = uid2object( uid );
933   if ( sobject )
934     numbering = ProcessEvent( new TGetElementNumberingEvent( sobject->GetID().c_str(), viewUid ) );
935
936   return numbering;
937 }
938
939 /////////////////////////////////////////////////////////////////
940 /// \internal
941 /////////////////////////////////////////////////////////////////
942 class TSetElementNumberingEvent: public SALOME_Event
943 {
944 public:
945   const char* myUid;
946   bool myNumbering;
947   int myViewUid;
948
949   TSetElementNumberingEvent( const char* uid, bool numbering, int viewUid )
950     : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
951
952   virtual void Execute()
953   {
954     SALOME_View* view = uid2wnd( myViewUid );
955     SMESH_Actor* actor = actorFromView( view, myUid );
956     if ( actor )
957     {
958       actor->SetCellsLabeled( myNumbering );
959       if ( view )
960         view->Repaint();
961     }
962   }
963 };
964
965 /////////////////////////////////////////////////////////////////
966 /// \brief Switch elements numbering on/off.
967 /// \param uid Mesh object's study UID or IOR.
968 /// \param numbering \c true to switch elements numbering on;
969 ///                  \c false otherwise.
970 /// \param viewUid View window UID (0 means currently active view
971 ///                window); Default: 0.
972 /////////////////////////////////////////////////////////////////
973 void SMESH_Swig::setElementsNumbering(const char* uid, bool numbering, int viewUid)
974 {
975   init();
976
977   _PTR(SObject) sobject = uid2object( uid );
978   if ( sobject )
979     ProcessVoidEvent( new TSetElementNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
980 }
981
982 /////////////////////////////////////////////////////////////////
983 /// \internal
984 /////////////////////////////////////////////////////////////////
985 class TGetDisplayModeEvent: public SALOME_Event
986 {
987 public:
988   typedef DisplayMode TResult;
989   TResult myResult;
990   const char* myUid;
991   int myViewUid;
992
993   TGetDisplayModeEvent( const char* uid, int viewUid )
994     : myResult( UndefinedMode ), myUid( uid ), myViewUid( viewUid ) {}
995
996   virtual void Execute()
997   {
998     SALOME_View* view = uid2wnd( myViewUid );
999     SMESH_Actor* actor = actorFromView( view, myUid );
1000     if ( actor )
1001       myResult = (DisplayMode)actor->GetRepresentation();
1002   }
1003 };
1004
1005 /////////////////////////////////////////////////////////////////
1006 /// \brief Get mesh object's display mode.
1007 /// \param uid Mesh object's study UID or IOR.
1008 /// \param viewUid View window UID (0 means currently active view
1009 ///                window); Default: 0.
1010 /// \return Display mode (UndefinedMode if actor isn't found).
1011 /////////////////////////////////////////////////////////////////
1012 DisplayMode SMESH_Swig::displayMode(const char* uid, int viewUid)
1013 {
1014   DisplayMode mode = UndefinedMode;
1015
1016   init();
1017
1018   _PTR(SObject) sobject = uid2object( uid );
1019   if ( sobject )
1020     mode = ProcessEvent( new TGetDisplayModeEvent( sobject->GetID().c_str(), viewUid ) );
1021
1022   return mode;
1023 }
1024
1025 /////////////////////////////////////////////////////////////////
1026 /// \internal
1027 /////////////////////////////////////////////////////////////////
1028 class TSetDisplayModeEvent: public SALOME_Event
1029 {
1030 public:
1031   const char* myUid;
1032   DisplayMode myMode;
1033   int myViewUid;
1034
1035   TSetDisplayModeEvent( const char* uid, DisplayMode mode, int viewUid )
1036     : myUid( uid ), myMode( mode), myViewUid( viewUid ) {}
1037
1038   virtual void Execute()
1039   {
1040     SALOME_View* view = uid2wnd( myViewUid );
1041     SMESH_Actor* actor = actorFromView( view, myUid );
1042     if ( actor && myMode != UndefinedMode )
1043     {
1044       actor->SetRepresentation( myMode );
1045       if ( view )
1046         view->Repaint();
1047     }
1048   }
1049 };
1050
1051 /////////////////////////////////////////////////////////////////
1052 /// \brief Set mesh object's display mode.
1053 /// \param uid Mesh object's study UID or IOR.
1054 /// \param mode Display mode.
1055 /// \param viewUid View window UID (0 means currently active view
1056 ///                window); Default: 0.
1057 /////////////////////////////////////////////////////////////////
1058 void SMESH_Swig::setDisplayMode(const char* uid, DisplayMode mode, int viewUid)
1059 {
1060   init();
1061
1062   _PTR(SObject) sobject = uid2object( uid );
1063   if ( sobject )
1064     ProcessVoidEvent( new TSetDisplayModeEvent( sobject->GetID().c_str(), mode, viewUid ) );
1065 }
1066
1067 /////////////////////////////////////////////////////////////////
1068 /// \internal
1069 /////////////////////////////////////////////////////////////////
1070 class TGetShrinkModeEvent: public SALOME_Event
1071 {
1072 public:
1073   typedef bool TResult;
1074   TResult myResult;
1075   const char* myUid;
1076   int myViewUid;
1077
1078   TGetShrinkModeEvent( const char* uid, int viewUid )
1079     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1080
1081   virtual void Execute()
1082   {
1083     SALOME_View* view = uid2wnd( myViewUid );
1084     SMESH_Actor* actor = actorFromView( view, myUid );
1085     if ( actor )
1086       myResult = actor->IsShrunk();
1087   }
1088 };
1089
1090 /////////////////////////////////////////////////////////////////
1091 /// \brief Check if shrink mode is switched on.
1092 /// \param uid Mesh object's study UID or IOR.
1093 /// \param viewUid View window UID (0 means currently active view
1094 ///                window); Default: 0.
1095 /// \return \c true if shrink mode is switched on;
1096 ///         \c false otherwise.
1097 /////////////////////////////////////////////////////////////////
1098 bool SMESH_Swig::shrinkMode(const char* uid, int viewUid)
1099 {
1100   bool shrinkMode = false;
1101
1102   init();
1103
1104   _PTR(SObject) sobject = uid2object( uid );
1105   if ( sobject )
1106     shrinkMode = ProcessEvent( new TGetShrinkModeEvent( sobject->GetID().c_str(), viewUid ) );
1107
1108   return shrinkMode;
1109 }
1110
1111 /////////////////////////////////////////////////////////////////
1112 /// \internal
1113 /////////////////////////////////////////////////////////////////
1114 class TSetShrinkModeEvent: public SALOME_Event
1115 {
1116 public:
1117   const char* myUid;
1118   bool myShrink;
1119   int myViewUid;
1120
1121   TSetShrinkModeEvent( const char* uid, bool shrink, int viewUid )
1122     : myUid( uid ), myShrink( shrink ), myViewUid( viewUid ) {}
1123
1124   virtual void Execute()
1125   {
1126     SALOME_View* view = uid2wnd( myViewUid );
1127     SMESH_Actor* actor = actorFromView( view, myUid );
1128     if ( actor )
1129     {
1130       if ( myShrink )
1131         actor->SetShrink();
1132       else
1133         actor->UnShrink();
1134       if ( view )
1135         view->Repaint();
1136     }
1137   }
1138 };
1139
1140 /////////////////////////////////////////////////////////////////
1141 /// \brief Switch shrink mode on/off.
1142 /// \param uid Mesh object's study UID or IOR.
1143 /// \param shrink \c true to switch shrink mode on;
1144 ///               \c false otherwise.
1145 /// \param viewUid View window UID (0 means currently active view
1146 ///                window); Default: 0.
1147 /////////////////////////////////////////////////////////////////
1148 void SMESH_Swig::setShrinkMode(const char* uid, bool shrink, int viewUid)
1149 {
1150   init();
1151
1152   _PTR(SObject) sobject = uid2object( uid );
1153   if ( sobject )
1154     ProcessVoidEvent( new TSetShrinkModeEvent( sobject->GetID().c_str(), shrink, viewUid ) );
1155 }
1156
1157 /////////////////////////////////////////////////////////////////
1158 /// \internal
1159 /////////////////////////////////////////////////////////////////
1160 class TGetOpacityEvent: public SALOME_Event
1161 {
1162 public:
1163   typedef double TResult;
1164   TResult myResult;
1165   const char* myUid;
1166   int myViewUid;
1167
1168   TGetOpacityEvent( const char* uid, int viewUid )
1169     : myResult( 0 ), myUid( uid ), myViewUid( viewUid ) {}
1170
1171   virtual void Execute()
1172   {
1173     SALOME_View* view = uid2wnd( myViewUid );
1174     SMESH_Actor* actor = actorFromView( view, myUid );
1175     if ( actor )
1176       myResult = actor->GetOpacity();
1177   }
1178 };
1179
1180 /////////////////////////////////////////////////////////////////
1181 /// \brief Get mesh object's opacity.
1182 /// \param uid Mesh object's study UID or IOR.
1183 /// \param viewUid View window UID (0 means currently active view
1184 ///                window); Default: 0.
1185 /// \return Opacity value.
1186 /////////////////////////////////////////////////////////////////
1187 double SMESH_Swig::opacity(const char* uid, int viewUid)
1188 {
1189   double opacity = 0;
1190
1191   init();
1192
1193   _PTR(SObject) sobject = uid2object( uid );
1194   if ( sobject )
1195     opacity = ProcessEvent( new TGetOpacityEvent( sobject->GetID().c_str(), viewUid ) );
1196
1197   return opacity;
1198 }
1199
1200 /////////////////////////////////////////////////////////////////
1201 /// \internal
1202 /////////////////////////////////////////////////////////////////
1203 class TSetOpacityEvent: public SALOME_Event
1204 {
1205 public:
1206   const char* myUid;
1207   double myOpacity;
1208   int myViewUid;
1209
1210   TSetOpacityEvent( const char* uid, double opacity, int viewUid )
1211     : myUid( uid ), myOpacity( opacity ), myViewUid( viewUid ) {}
1212
1213   virtual void Execute()
1214   {
1215     SALOME_View* view = uid2wnd( myViewUid );
1216     SMESH_Actor* actor = actorFromView( view, myUid );
1217     if ( actor )
1218     {
1219       actor->SetOpacity( myOpacity );
1220       if ( view )
1221         view->Repaint();
1222     }
1223   }
1224 };
1225
1226 /////////////////////////////////////////////////////////////////
1227 /// \brief Set mesh object's opacity.
1228 /// \param uid Mesh object's study UID or IOR.
1229 /// \param opacity Opacity value.
1230 /// \param viewUid View window UID (0 means currently active view
1231 ///                window); Default: 0.
1232 /////////////////////////////////////////////////////////////////
1233 void SMESH_Swig::setOpacity(const char* uid, double opacity, int viewUid)
1234 {
1235   init();
1236
1237   _PTR(SObject) sobject = uid2object( uid );
1238   if ( sobject )
1239     ProcessVoidEvent( new TSetOpacityEvent( sobject->GetID().c_str(), opacity, viewUid ) );
1240 }
1241
1242 /////////////////////////////////////////////////////////////////
1243 /// \internal
1244 /////////////////////////////////////////////////////////////////
1245 class TGetOrientationEvent: public SALOME_Event
1246 {
1247 public:
1248   typedef bool TResult;
1249   TResult myResult;
1250   const char* myUid;
1251   int myViewUid;
1252
1253   TGetOrientationEvent( const char* uid, int viewUid )
1254     : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1255
1256   virtual void Execute()
1257   {
1258     SALOME_View* view = uid2wnd( myViewUid );
1259     SMESH_Actor* actor = actorFromView( view, myUid );
1260     if ( actor )
1261       myResult = actor->GetFacesOriented();
1262   }
1263 };
1264
1265 /////////////////////////////////////////////////////////////////
1266 /// \brief Check if faces orientation vectors are shown.
1267 /// \param uid Mesh object's study UID or IOR.
1268 /// \param viewUid View window UID (0 means currently active view
1269 ///                window); Default: 0.
1270 /// \return \c true if faces orientation vectors are shown;
1271 ///         \c false otherwise.
1272 /////////////////////////////////////////////////////////////////
1273 bool SMESH_Swig::isOrientationShown(const char* uid, int viewUid)
1274 {
1275   bool shown = false;
1276
1277   init();
1278
1279   _PTR(SObject) sobject = uid2object( uid );
1280   if ( sobject )
1281     shown = ProcessEvent( new TGetOrientationEvent( sobject->GetID().c_str(), viewUid ) );
1282
1283   return shown;
1284 }
1285
1286 /////////////////////////////////////////////////////////////////
1287 /// \internal
1288 /////////////////////////////////////////////////////////////////
1289 class TSetOrientationEvent: public SALOME_Event
1290 {
1291 public:
1292   const char* myUid;
1293   bool myShown;
1294   int myViewUid;
1295
1296   TSetOrientationEvent( const char* uid, bool shown, int viewUid )
1297     : myUid( uid ), myShown( shown ), myViewUid( viewUid ) {}
1298
1299   virtual void Execute()
1300   {
1301     SALOME_View* view = uid2wnd( myViewUid );
1302     SMESH_Actor* actor = actorFromView( view, myUid );
1303     if ( actor )
1304     {
1305       actor->SetFacesOriented( myShown );
1306       if ( view )
1307         view->Repaint();
1308     }
1309   }
1310 };
1311
1312 /////////////////////////////////////////////////////////////////
1313 /// \brief Show/hide faces orientation vectors.
1314 /// \param uid Mesh object's study UID or IOR.
1315 /// \param shown \c true to show faces orientation vectors;
1316 ///              \c false otherwise.
1317 /// \param viewUid View window UID (0 means currently active view
1318 ///                window); Default: 0.
1319 /////////////////////////////////////////////////////////////////
1320 void SMESH_Swig::setOrientationShown(const char* uid, bool shown, int viewUid)
1321 {
1322   init();
1323
1324   _PTR(SObject) sobject = uid2object( uid );
1325   if ( sobject )
1326     ProcessVoidEvent( new TSetOrientationEvent( sobject->GetID().c_str(), shown, viewUid ) );
1327 }
1328
1329 /////////////////////////////////////////////////////////////////
1330 /// \internal
1331 /////////////////////////////////////////////////////////////////
1332 class TGetEntitiesEvent: public SALOME_Event
1333 {
1334 public:
1335   typedef int TResult;
1336   TResult myResult;
1337   const char* myUid;
1338   int myViewUid;
1339
1340   TGetEntitiesEvent( const char* uid, int viewUid )
1341     : myResult( EntityNone ), myUid( uid ), myViewUid( viewUid ) {}
1342
1343   virtual void Execute()
1344   {
1345     SALOME_View* view = uid2wnd( myViewUid );
1346     SMESH_Actor* actor = actorFromView( view, myUid );
1347     if ( actor )
1348       myResult = actor->GetEntityMode();
1349   }
1350 };
1351
1352 /////////////////////////////////////////////////////////////////
1353 /// \brief Get mesh object's visible entities.
1354 /// \param uid Mesh object's study UID or IOR.
1355 /// \param viewUid View window UID (0 means currently active view
1356 ///                window); Default: 0.
1357 /// \return Enumerator describing entities being visible.
1358 /////////////////////////////////////////////////////////////////
1359 int SMESH_Swig::entitiesShown(const char* uid, int viewUid)
1360 {
1361   int entities = EntityNone;
1362
1363   init();
1364
1365   _PTR(SObject) sobject = uid2object( uid );
1366   if ( sobject )
1367     entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1368
1369   return entities;
1370 }
1371
1372 /////////////////////////////////////////////////////////////////
1373 /// \internal
1374 /////////////////////////////////////////////////////////////////
1375 class TSetEntitiesEvent: public SALOME_Event
1376 {
1377 public:
1378   const char* myUid;
1379   int myEntities;
1380   int myViewUid;
1381
1382   TSetEntitiesEvent( const char* uid, int entities, int viewUid )
1383     : myUid( uid ), myEntities( entities ), myViewUid( viewUid ) {}
1384
1385   virtual void Execute()
1386   {
1387     SALOME_View* view = uid2wnd( myViewUid );
1388     SMESH_Actor* actor = actorFromView( view, myUid );
1389     if ( actor )
1390     {
1391       actor->SetEntityMode( myEntities );
1392       if ( view )
1393         view->Repaint();
1394     }
1395   }
1396 };
1397
1398 /////////////////////////////////////////////////////////////////
1399 /// \brief Set mesh object's visible entities.
1400 /// \param uid Mesh object's study UID or IOR.
1401 /// \param entities Enumerator describing entities to be shown.
1402 /// \param viewUid View window UID (0 means currently active view
1403 ///                window); Default: 0.
1404 /////////////////////////////////////////////////////////////////
1405 void SMESH_Swig::setEntitiesShown(const char* uid, int entities, int viewUid)
1406 {
1407   init();
1408
1409   _PTR(SObject) sobject = uid2object( uid );
1410   if ( sobject )
1411     ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1412 }
1413
1414 /////////////////////////////////////////////////////////////////
1415 /// \brief Check if given mesh object's entity is shown.
1416 /// \param uid Mesh object's study UID or IOR.
1417 /// \param entity Mesh entity.
1418 /// \param viewUid View window UID (0 means currently active view
1419 ///                window); Default: 0.
1420 /// \return \c true if entity is shown; \c false otherwise.
1421 /////////////////////////////////////////////////////////////////
1422 bool SMESH_Swig::isEntityShown(const char* uid, EntityMode entity, int viewUid)
1423 {
1424   bool shown = false;
1425
1426   init();
1427
1428   _PTR(SObject) sobject = uid2object( uid );
1429   if ( sobject )
1430   {
1431     int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1432     shown = (bool)( entities & entity );
1433   }
1434
1435   return shown;
1436 }
1437
1438 /////////////////////////////////////////////////////////////////
1439 /// \brief Show/hide entity for given mesh object.
1440 /// \param uid Mesh object's study UID or IOR.
1441 /// \param entity Mesh entity.
1442 /// \param show Visibility status.
1443 /// \param viewUid View window UID (0 means currently active view
1444 ///                window); Default: 0.
1445 /////////////////////////////////////////////////////////////////
1446 void SMESH_Swig::setEntityShown(const char* uid, EntityMode entity, bool show, int viewUid)
1447 {
1448   init();
1449
1450   _PTR(SObject) sobject = uid2object( uid );
1451   if ( sobject )
1452   {
1453     int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1454     if ( show )
1455       entities |= entity;
1456     else
1457       entities &= ~entity;
1458     ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1459   }
1460 }
1461
1462 /////////////////////////////////////////////////////////////////
1463 /// \brief Initialize %SMESH GUI Python interface.
1464 /// \deprecated Interface is initialized automatically.
1465 /////////////////////////////////////////////////////////////////
1466 void SMESH_Swig::Init()
1467 {
1468   deprecated("SMESH_Swig::Init");
1469   // does nothing; initialization is done automatically.
1470 }
1471
1472 /////////////////////////////////////////////////////////////////
1473 /// \brief Publish mesh in the active study.
1474 /// \deprecated Publishing is done automatically.
1475 /// \param ior IOR of the mesh.
1476 /// \param name Name of the mesh (optional).
1477 /// \return UID of the data object.
1478 /////////////////////////////////////////////////////////////////
1479 const char* SMESH_Swig::AddNewMesh(const char* ior, const char* name)
1480 {
1481   deprecated("SMESH_Swig::AddNewMesh", "SMESH_Swig::publish");
1482   return publish( ior, name );
1483 }
1484
1485 /////////////////////////////////////////////////////////////////
1486 /// \brief Publish hypothesis in the active study.
1487 /// \deprecated Publishing is done automatically.
1488 /// \param ior IOR of the hypothesis.
1489 /// \param name Name of the hypothesis (optional).
1490 /// \return UID of the data object.
1491 /////////////////////////////////////////////////////////////////
1492 const char* SMESH_Swig::AddNewHypothesis(const char* ior, const char* name)
1493 {
1494   deprecated("SMESH_Swig::AddNewHypothesis", "SMESH_Swig::publish");
1495   return publish( ior, name );
1496 }
1497
1498 /////////////////////////////////////////////////////////////////
1499 /// \brief Publish algorithm in the active study.
1500 /// \deprecated Publishing is done automatically.
1501 /// \param ior IOR of the algorithm.
1502 /// \param name Name of the algorithm (optional).
1503 /// \return UID of the data object.
1504 /////////////////////////////////////////////////////////////////
1505 const char* SMESH_Swig::AddNewAlgorithm(const char* ior, const char* name)
1506 {
1507   deprecated("SMESH_Swig::AddNewAlgorithm", "SMESH_Swig::publish");
1508   return publish( ior, name );
1509 }
1510
1511 /////////////////////////////////////////////////////////////////
1512 /// \deprecated Publishing is done automatically.
1513 /// \deprecated Synonim of AddNewAlgorithm().
1514 /// \param ior IOR of the algorithm.
1515 /// \param name Name of the algorithm (optional).
1516 /// \return UID of the data object.
1517 /////////////////////////////////////////////////////////////////
1518 const char* SMESH_Swig::AddNewAlgorithms(const char* ior, const char* name)
1519 {
1520   deprecated("SMESH_Swig::AddNewAlgorithms", "SMESH_Swig::publish");
1521   return publish( ior, name );
1522 }
1523
1524 /////////////////////////////////////////////////////////////////
1525 /// \brief Add reference on a shape for mesh in a study.
1526 /// \deprecated Publishing is done automatically.
1527 /// \param shapeUid GEOM shape's study UID (not used).
1528 /// \param meshUid Mesh's study UID (not used).
1529 /////////////////////////////////////////////////////////////////
1530 void SMESH_Swig::SetShape(const char* /*shapeUid*/, const char* /*meshUid*/)
1531 {
1532   deprecated("SMESH_Swig::SetShape", "SMESH_Swig::publish");
1533   // does nothing: publishing is done automatically
1534 }
1535
1536 /////////////////////////////////////////////////////////////////
1537 /// \brief Assign hypothesis to mesh or sub-mesh.
1538 /// \deprecated Publishing is done automatically.
1539 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1540 /// \param hypoUID Hypothesis's study UID (not used).
1541 /////////////////////////////////////////////////////////////////
1542 void SMESH_Swig::SetHypothesis(const char* /*meshUid*/, const char* /*hypoUID*/)
1543 {
1544   deprecated("SMESH_Swig::SetHypothesis", "SMESH_Swig::publish");
1545   // does nothing: publishing is done automatically
1546 }
1547
1548 /////////////////////////////////////////////////////////////////
1549 /// \brief Assign algorithm to mesh or sub-mesh.
1550 /// \deprecated Publishing is done automatically.
1551 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1552 /// \param algoUID Algorithm's study UID (not used).
1553 /////////////////////////////////////////////////////////////////
1554 void SMESH_Swig::SetAlgorithms(const char* /*meshUid*/, const char* /*algoUID*/)
1555 {
1556   deprecated("SMESH_Swig::SetAlgorithms", "SMESH_Swig::publish");
1557   // does nothing: publishing is done automatically
1558 }
1559
1560 /////////////////////////////////////////////////////////////////
1561 /// \brief Anassign hypothesis or algorithm from mesh or sub-mesh.
1562 /// \deprecated Unpublishing is done automatically.
1563 /// \param uid Hypothesis's or algorithm's study UID (not used).
1564 /////////////////////////////////////////////////////////////////
1565 void SMESH_Swig::UnSetHypothesis(const char* /*uid*/)
1566 {
1567   deprecated("SMESH_Swig::UnSetHypothesis");
1568   // does nothing: unpublishing is done automatically
1569 }
1570
1571 /////////////////////////////////////////////////////////////////
1572 /// \brief Publish sub-mesh in the active study.
1573 /// \deprecated Publishing is done automatically.
1574 /// \param meshUid Parent mesh's study UID (not used).
1575 /// \param ior IOR of the sub-mesh.
1576 /// \param shapeType GEOM shape's type (not used).
1577 /// \param name Name of the sub-mesh (optional).
1578 /// \return UID of the data object.
1579 /////////////////////////////////////////////////////////////////
1580 const char* SMESH_Swig::AddSubMesh(const char* /*meshUid*/,
1581                                    const char* ior,
1582                                    int /*shapeType*/,
1583                                    const char* name)
1584 {
1585   deprecated("SMESH_Swig::AddSubMesh", "SMESH_Swig::publish");
1586   return publish( ior, name );
1587 }
1588
1589 /////////////////////////////////////////////////////////////////
1590 /// \brief Publish sub-mesh in the active study.
1591 /// \deprecated Publishing is done automatically.
1592 /// \param meshUid Parent mesh's study UID (not used).
1593 /// \param shapeUid GEOM shape's study UID (not used).
1594 /// \param ior IOR of the sub-mesh.
1595 /// \param shapeType GEOM shape's type (not used).
1596 /// \param name Name of the sub-mesh (optional).
1597 /// \return UID of the data object.
1598 /////////////////////////////////////////////////////////////////
1599 const char* SMESH_Swig::AddSubMeshOnShape(const char* /*meshUid*/,
1600                                           const char* /*shapeUid*/,
1601                                           const char* ior,
1602                                           int /*shapeType*/,
1603                                           const char* name)
1604 {
1605   deprecated("SMESH_Swig::AddSubMeshOnShape", "SMESH_Swig::publish");
1606   return publish( ior, name );
1607 }
1608
1609 /////////////////////////////////////////////////////////////////
1610 /// \brief Set new study name of given object.
1611 /// \deprecated Use rename() method.
1612 /// \param uid Object's study UID or IOR.
1613 /// \param name New name of the object.
1614 /////////////////////////////////////////////////////////////////
1615 void SMESH_Swig::SetName(const char* uid, const char* name)
1616 {
1617   deprecated("SMESH_Swig::SetName", "SMESH_Swig::rename");
1618   rename( uid, name );
1619 }
1620
1621 /////////////////////////////////////////////////////////////////
1622 /// \brief Set mesh icon according to compute status
1623 /// \deprecated Publishing is done automatically.
1624 /// \param meshUid Mesh's study UID (not used).
1625 /// \param isComputed Flag pointing that mesh is computed or no
1626 ///        (not used).
1627 /// \param isEmpty Flag pointing that mesh is empty or no
1628 ///        (not used).
1629 /////////////////////////////////////////////////////////////////
1630 void SMESH_Swig::SetMeshIcon(const char* /*meshUid*/,
1631                              const bool /*isComputed*/,
1632                              const bool /*isEmpty*/)
1633 {
1634   deprecated("SMESH_Swig::SetMeshIcon", "SMESH_Swig::publish");
1635   // does nothing: publishing is done automatically
1636 }
1637
1638 /////////////////////////////////////////////////////////////////
1639 /// Display mesh in the currently active view window.
1640 /// \deprecated Use display() method.
1641 /// \param meshUid Mesh's study UID.
1642 /////////////////////////////////////////////////////////////////
1643 void SMESH_Swig::CreateAndDisplayActor(const char* meshUid)
1644 {
1645   deprecated("SMESH_Swig::CreateAndDisplayActor", "SMESH_Swig::display");
1646   display( meshUid );
1647 }
1648
1649 /////////////////////////////////////////////////////////////////
1650 /// Erase mesh in the view window(s).
1651 /// \deprecated Use erase() method.
1652 /// \param meshUid Mesh's study UID.
1653 /// \param allViewers If \c true, mesh is removed from all views.
1654 ///                   Default: \c false.
1655 /////////////////////////////////////////////////////////////////
1656 void SMESH_Swig::EraseActor(const char* meshUid, const bool allViewers)
1657 {
1658   deprecated("SMESH_Swig::EraseActor", "SMESH_Swig::erase");
1659   erase( meshUid, allViewers ? -1 : 0 );
1660 }
1661
1662 /////////////////////////////////////////////////////////////////
1663 /// Update mesh object.
1664 /// \deprecated Use update() method.
1665 /// \param meshUid Mesh's study UID.
1666 /////////////////////////////////////////////////////////////////
1667 void SMESH_Swig::UpdateActor(const char* meshUid)
1668 {
1669   deprecated("SMESH_Swig::UpdateActor", "SMESH_Swig::update");
1670   update( meshUid );
1671 }
1672
1673 /////////////////////////////////////////////////////////////////
1674 /// Get mesh object's properties.
1675 /// \deprecated Use properties() method.
1676 /// \param meshUid Mesh's study UID.
1677 /// \param viewUid View window UID (0 means currently active view
1678 ///                window). Default: 0.
1679 /////////////////////////////////////////////////////////////////
1680 actorAspect SMESH_Swig::GetActorAspect(const char* meshUid, int viewUid)
1681 {
1682   deprecated("SMESH_Swig::GetActorAspect", "SMESH_Swig::properties");
1683   return properties( meshUid, viewUid );
1684 }
1685
1686 /////////////////////////////////////////////////////////////////
1687 /// Set mesh object's properties.
1688 /// \deprecated Use setProperties() method.
1689 /// \param meshUid Mesh's study UID.
1690 /// \param viewUid View window UID (0 means currently active view
1691 ///                window). Default: 0.
1692 /////////////////////////////////////////////////////////////////
1693 void SMESH_Swig::SetActorAspect(const actorAspect& aspect, const char* meshUid, int viewUid)
1694 {
1695   deprecated("SMESH_Swig::SetActorAspect", "SMESH_Swig::setProperties");
1696   setProperties( meshUid, aspect, viewUid );
1697 }
1698
1699 /////////////////////////////////////////////////////////////////
1700 /// \internal
1701 /////////////////////////////////////////////////////////////////
1702 class TSelectListEvent: public SALOME_Event
1703 {
1704   const char* myUid;
1705   std::vector<int> myIds;
1706   bool myIsAppend;
1707
1708 public:
1709   TSelectListEvent(const char* uid, std::vector<int> ids, bool append)
1710     : myUid( uid ), myIds( ids ), myIsAppend( append )
1711   {}
1712
1713   virtual void Execute()
1714   {
1715     LightApp_SelectionMgr* selMgr = 0;
1716     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1717     if ( app )
1718       selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1719
1720     if ( !selMgr )
1721       return;
1722     
1723     selMgr->clearFilters();
1724
1725     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1726     if ( !vw )
1727       return;
1728
1729     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1730     
1731     if ( !actor || !actor->hasIO() )
1732       return;
1733     
1734     Handle(SALOME_InteractiveObject) io = actor->getIO();
1735     SALOME_ListIO ios;
1736     ios.Append( io );
1737     selMgr->setSelectedObjects( ios, false );
1738
1739     if ( vw->SelectionMode() == ActorSelection )
1740       return;
1741         
1742     TColStd_MapOfInteger idMap;
1743     std::vector<int>::const_iterator it;
1744     for ( it = myIds.begin(); it != myIds.end(); ++it )
1745     {
1746       idMap.Add( *it );
1747     }
1748
1749     // Set new selection
1750     SVTK_Selector* selector = vw->GetSelector();
1751     selector->AddOrRemoveIndex( io, idMap, myIsAppend );
1752     vw->highlight( io, true, true );
1753     vw->GetInteractor()->onEmitSelectionChanged();
1754   }
1755 };
1756
1757 /////////////////////////////////////////////////////////////////
1758 /// \brief Select elements of the mesh, sub-mesh or group.
1759 /// \param uid Mesh object's study UID or IOR.
1760 /// \param ids List of mesh elements.
1761 /// \param append If \c true, elements are added to current
1762 ///               selection; otherwise, previous selection is
1763 ///               cleared.
1764 /////////////////////////////////////////////////////////////////
1765 void SMESH_Swig::select(const char* uid, std::vector<int> ids, bool append)
1766 {
1767   init();
1768
1769   _PTR(SObject) sobject = uid2object( uid );
1770   if ( sobject )
1771     ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1772 }
1773   
1774 /////////////////////////////////////////////////////////////////
1775 /// \brief Select element of the mesh, sub-mesh or group.
1776 /// \param uid Mesh object's study UID or IOR.
1777 /// \param id Mesh element.
1778 /// \param append If \c true, element is added to current
1779 ///               selection; otherwise, previous selection is
1780 ///               cleared.
1781 /////////////////////////////////////////////////////////////////
1782 void SMESH_Swig::select(const char* uid, int id, bool append)
1783 {
1784   init();
1785
1786   std::vector<int> ids;
1787   ids.push_back( id );
1788
1789   _PTR(SObject) sobject = uid2object( uid );
1790   if ( sobject )
1791     ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1792 }
1793
1794 /////////////////////////////////////////////////////////////////
1795 /// \internal
1796 /////////////////////////////////////////////////////////////////
1797 class TSelectListOfPairEvent: public SALOME_Event
1798 {
1799   const char* myUid;
1800   std::vector<std::pair<int, int> > myIds;
1801   bool myIsAppend;
1802
1803 public:
1804   TSelectListOfPairEvent(const char* uid, std::vector<std::pair<int, int> > ids, bool append)
1805     : myUid( uid ), myIds( ids ), myIsAppend( append )
1806   {}
1807
1808   virtual void Execute()
1809   {
1810     LightApp_SelectionMgr* selMgr = 0;
1811     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1812     if ( app )
1813       selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1814
1815     if ( !selMgr )
1816       return;
1817     
1818     selMgr->clearFilters();
1819
1820     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1821     if ( !vw )
1822       return;
1823
1824     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1825     
1826     if ( !actor || !actor->hasIO() )
1827       return;
1828     
1829     Handle(SALOME_InteractiveObject) io = actor->getIO();
1830     SALOME_ListIO ios;
1831     ios.Append( io );
1832     selMgr->setSelectedObjects( ios, false );
1833
1834     if ( vw->SelectionMode() != EdgeOfCellSelection )
1835       return;
1836         
1837     SVTK_IndexedMapOfIds idMap;
1838     std::vector<std::pair<int, int> >::const_iterator it;
1839     for ( it = myIds.begin(); it != myIds.end(); ++it )
1840     {
1841       std::vector<int> pair;
1842       pair.push_back( (*it).first );
1843       pair.push_back( (*it).second );
1844       idMap.Add( pair );
1845     }
1846
1847     // Set new selection
1848     SVTK_Selector* selector = vw->GetSelector();
1849     selector->AddOrRemoveCompositeIndex( io, idMap, myIsAppend );
1850     vw->highlight( io, true, true );
1851     vw->GetInteractor()->onEmitSelectionChanged();
1852   }
1853 };
1854
1855 /////////////////////////////////////////////////////////////////
1856 /// \brief Select pseudo-edges (specified by two nodes)
1857 ///        of the mesh, sub-mesh or group.
1858 /// \param uid Mesh object's study UID or IOR.
1859 /// \param ids List of pairs containing two nodes IDs.
1860 /// \param append If \c true, pseudo-edges are added to current
1861 ///               selection; otherwise, previous selection is
1862 ///               cleared.
1863 /////////////////////////////////////////////////////////////////
1864 void SMESH_Swig::select(const char* uid, std::vector<std::pair<int,int> > ids, bool append)
1865 {
1866   init();
1867
1868   _PTR(SObject) sobject = uid2object( uid );
1869   if ( sobject )
1870     ProcessVoidEvent( new TSelectListOfPairEvent( sobject->GetID().c_str(), ids, append ) );
1871 }
1872
1873 /////////////////////////////////////////////////////////////////
1874 /// \internal
1875 /////////////////////////////////////////////////////////////////
1876 class TGetSelectionModeEvent: public SALOME_Event
1877 {
1878 public:
1879   typedef SelectionMode TResult;
1880   TResult myResult;
1881   int myViewUid;
1882
1883   TGetSelectionModeEvent( int viewUid ) :
1884     myResult( Undefined ), myViewUid( viewUid ) {}
1885
1886   virtual void Execute()
1887   {
1888     SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1889     if ( model )
1890     {
1891       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1892       if ( vw )
1893         myResult = (SelectionMode)vw->SelectionMode();
1894     }
1895   }
1896 };
1897
1898 /////////////////////////////////////////////////////////////////
1899 /// \brief Get selection mode of view window.
1900 /// \param viewUid View window UID (0 means currently active view
1901 ///                window); Default: 0.
1902 /// \return Current selection mode.
1903 /////////////////////////////////////////////////////////////////
1904 SelectionMode SMESH_Swig::getSelectionMode(int viewUid)
1905 {
1906   init();
1907   return ProcessEvent( new TGetSelectionModeEvent( viewUid ) );
1908 }
1909
1910 /////////////////////////////////////////////////////////////////
1911 /// \internal
1912 /////////////////////////////////////////////////////////////////
1913 class TSetSelectionModeEvent: public SALOME_Event
1914 {
1915   SelectionMode mySelectionMode;
1916   int myViewUid;
1917
1918 public:
1919   TSetSelectionModeEvent( const SelectionMode selectionMode, int viewUid )
1920     : mySelectionMode( selectionMode ), myViewUid( viewUid )
1921   {}
1922
1923   virtual void Execute()
1924   {
1925     SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1926     if ( model )
1927     {
1928       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1929       if ( vw )
1930       {
1931         SelectionMode previousMode = (SelectionMode)vw->SelectionMode();
1932         bool switchPointMode = ( previousMode == Node && mySelectionMode != Node ) ||
1933           ( previousMode != Node && mySelectionMode == Node );
1934         if ( switchPointMode )
1935         {
1936           vtkRenderer* renderer = vw->getRenderer();
1937           VTK::ActorCollectionCopy actors( renderer->GetActors() );
1938           vtkActorCollection* collection = actors.GetActors();
1939           collection->InitTraversal();
1940           while ( vtkActor* vtkActor = collection->GetNextActor() )
1941           {
1942             if ( SMESH_Actor* actor = dynamic_cast<SMESH_Actor*>( vtkActor ) )
1943             {
1944               if ( actor->GetVisibility() )
1945                 actor->SetPointRepresentation( mySelectionMode == Node );
1946             }
1947           }
1948         }
1949         vw->SetSelectionMode( mySelectionMode );
1950       }
1951     }
1952   }
1953 };
1954
1955 /////////////////////////////////////////////////////////////////
1956 /// \brief Set selection mode to view window.
1957 /// \param viewUid View window UID (0 means currently active view
1958 ///                window); Default: 0.
1959 /// \param mode Selection mode.
1960 /////////////////////////////////////////////////////////////////
1961 void SMESH_Swig::setSelectionMode(SelectionMode mode, int viewUid)
1962 {
1963   init();
1964   ProcessVoidEvent( new TSetSelectionModeEvent( mode, viewUid ) ); 
1965 }
1966
1967 /////////////////////////////////////////////////////////////////
1968 /// \internal
1969 /////////////////////////////////////////////////////////////////
1970 class TGetSelectedEvent: public SALOME_Event
1971 {
1972 public:
1973   typedef std::vector<int> TResult;
1974   TResult myResult;
1975   const char* myUid;
1976   
1977   TGetSelectedEvent( const char* uid )
1978     : myUid( uid ) {}
1979   
1980   virtual void Execute()
1981   {
1982     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1983     if ( !vw )
1984       return;
1985
1986     SVTK_Selector* selector = vw->GetSelector();    
1987     if ( !selector )
1988       return;
1989
1990     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1991     if ( !actor || !actor->hasIO() )
1992       return;
1993
1994     TColStd_IndexedMapOfInteger idMap;
1995     selector->GetIndex( actor->getIO(), idMap );
1996
1997     for ( int i = 1; i <= idMap.Extent(); i++ )
1998       myResult.push_back( idMap( i ) );
1999   }
2000 };
2001
2002 /////////////////////////////////////////////////////////////////
2003 /// \brief Get selected elements of the mesh, sub-mesh or group.
2004 /// \param uid Mesh object's study UID or IOR.
2005 /// \return List of selected mesh elements.
2006 /////////////////////////////////////////////////////////////////
2007 std::vector<int> SMESH_Swig::getSelected(const char* uid)
2008 {
2009   std::vector<int> ids;
2010
2011   init();
2012
2013   _PTR(SObject) sobject = uid2object( uid );
2014   if ( sobject )
2015     ids = ProcessEvent( new TGetSelectedEvent( sobject->GetID().c_str() ) );
2016
2017   return ids;
2018 }
2019
2020 /////////////////////////////////////////////////////////////////
2021 /// \internal
2022 /////////////////////////////////////////////////////////////////
2023 class TGetSelectedPairEvent : public SALOME_Event
2024 {
2025 public:
2026   typedef std::vector<std::pair<int, int> > TResult;
2027   TResult myResult;
2028   const char* myUid;
2029   
2030   TGetSelectedPairEvent( const char* uid )
2031     :  myUid( uid ) {}
2032   
2033   virtual void Execute()
2034   {
2035     SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2036     if ( !vw )
2037       return;
2038
2039     if ( vw->SelectionMode() != EdgeOfCellSelection )
2040       return;
2041
2042     SVTK_Selector* selector = vw->GetSelector();    
2043     if ( !selector )
2044       return;
2045
2046     SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2047     if ( !actor || !actor->hasIO() )
2048       return;
2049
2050     SVTK_IndexedMapOfIds idMap;
2051     selector->GetCompositeIndex( actor->getIO(), idMap );
2052
2053     for ( int i = 1; i <= idMap.Extent(); i++ ) {
2054       myResult.push_back( std::make_pair( (int)idMap(i)[0], (int)idMap(i)[1]) );
2055         }
2056   }
2057 };
2058
2059 /////////////////////////////////////////////////////////////////
2060 /// \brief Get selected pseudo-edges (specified by two nodes)
2061 ///        of the mesh, sub-mesh or group.
2062 /// \param uid Mesh object's study UID or IOR.
2063 /// \param ids List of pairs containing two nodes IDs.
2064 /// \param append If \c true, pseudo-edges are added to current
2065 ///               selection; otherwise, previous selection is
2066 ///               cleared.
2067 /////////////////////////////////////////////////////////////////
2068 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell(const char* uid)
2069 {
2070   std::vector<std::pair<int,int> > pairs;
2071
2072   init();
2073
2074   _PTR(SObject) sobject = uid2object( uid );
2075   if ( sobject )
2076     pairs = ProcessEvent( new TGetSelectedPairEvent( sobject->GetID().c_str() ) );
2077
2078   return pairs;
2079 }