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