1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 /////////////////////////////////////////////////////////////////
21 /// \package libSMESH_Swig
22 /// \brief Python API for %SMESH GUI.
24 /// See SMESH_Swig class for %SMESH GUI Python API.
26 /// \par Note about publishing of mesh objects in the study
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
32 /// So, normally functions of %SMESH GUI Python API like
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.
42 /// Note that if there are no open study, these methods will do
45 /// \par Note about selection
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
56 /////////////////////////////////////////////////////////////////
58 #include "libSMESH_Swig.h"
60 #include <SVTK_Selector.h>
63 #include <SMESHGUI_Utils.h>
64 #include <SMESHGUI_Displayer.h>
65 #include <SMESHGUI_VTKUtils.h>
66 #include <SMESH_Actor.h>
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>
74 #include <utilities.h>
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>
91 #include <TColStd_MapOfInteger.hxx>
94 #include <QApplication>
97 #include <SALOMEconfig.h>
98 #include CORBA_SERVER_HEADER(SMESH_Gen)
99 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
102 #include <vtkActorCollection.h>
103 #include <vtkRenderer.h>
107 ///////////////////////////////////////////////////////////////
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)
117 printf("libSMESH_Swig: method '%s' is deprecated; use '%s' instead.\n", function, replacement);
119 printf("libSMESH_Swig: method '%s' is deprecated.\n", function);
122 ///////////////////////////////////////////////////////////////
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)
130 return SalomeApp_Application::orb()->string_to_object(ior.c_str());
133 ///////////////////////////////////////////////////////////////
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
139 ///////////////////////////////////////////////////////////////
140 _PTR(SObject) uid2object(const std::string& uid)
142 _PTR(SObject) sobject;
144 _PTR(Study) study = SMESH::getStudy();
147 sobject = study->FindObjectID( uid );
149 sobject = study->FindObjectIOR( uid );
155 ///////////////////////////////////////////////////////////////
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)
163 SALOME_View* window = 0;
165 SUIT_Session* session = SUIT_Session::session();
166 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
171 ViewManagerList vms = app->viewManagers();
172 for ( int i = 0; i < vms.count() && !window; i++ )
174 SUIT_ViewManager* vm = vms[i];
175 QVector<SUIT_ViewWindow*> vws = vm->getViews();
176 for ( int j = 0; j < vws.count() && !window; j++)
178 SUIT_ViewWindow* vw = vws[0];
179 if ( uid == vw->getId() )
180 window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
186 SUIT_ViewManager* vm = app->getViewManager( SVTK_Viewer::Type(), create );
189 window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
196 ///////////////////////////////////////////////////////////////
198 /// \brief Get all view windows.
199 /// \return List of view windows.
200 ///////////////////////////////////////////////////////////////
201 QList<SALOME_View*> windows()
203 QList<SALOME_View*> views;
204 SUIT_Session* session = SUIT_Session::session();
205 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
208 ViewManagerList vms = app->viewManagers();
209 foreach( SUIT_ViewManager* vm, vms )
211 if ( vm && vm->getType() == SVTK_Viewer::Type() )
213 SALOME_View* view = dynamic_cast<SALOME_View*>( vm->getViewModel() );
222 ///////////////////////////////////////////////////////////////
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)
231 SMESH_Actor* actor = 0;
232 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( view );
235 SUIT_ViewWindow* vw = model->getViewManager()->getActiveView();
238 actor = SMESH::FindActorByEntry( vw, uid );
244 ///////////////////////////////////////////////////////////////
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)
254 SMESH_Actor* actor = actorFromView( view, uid );
257 actor->GetNodeColor( props.nodeColor.r,
260 props.markerType = actor->GetMarkerType();
261 props.markerScale = actor->GetMarkerScale();
263 actor->GetEdgeColor( props.edgeColor.r,
266 props.edgeWidth = qMax( (int)actor->GetLineWidth(), 1 );
268 actor->GetSufaceColor( props.surfaceColor.r,
269 props.surfaceColor.g,
270 props.surfaceColor.b,
271 props.surfaceColor.delta );
273 actor->GetVolumeColor( props.volumeColor.r,
276 props.volumeColor.delta );
278 actor->Get0DColor( props.elem0dColor.r,
280 props.elem0dColor.b );
281 props.elem0dSize = qMax( (int)actor->Get0DSize(), 1 );
283 actor->GetBallColor( props.ballColor.r,
286 props.ballScale = qMax( actor->GetBallScale(), 1e-2 );
288 actor->GetOutlineColor( props.outlineColor.r,
289 props.outlineColor.g,
290 props.outlineColor.b );
291 props.outlineWidth = qMax( (int)actor->GetOutlineWidth(), 1 );
293 actor->GetFacesOrientationColor( props.orientationColor.r,
294 props.orientationColor.g,
295 props.orientationColor.b );
296 props.orientationScale = actor->GetFacesOrientationScale();
297 props.orientation3d = actor->GetFacesOrientation3DVectors();
299 props.shrinkFactor = actor->GetShrinkFactor();
301 props.opacity = actor->GetOpacity();
306 ///////////////////////////////////////////////////////////////
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)
315 SMESH_Actor* actor = actorFromView( view, uid );
318 actor->SetNodeColor( props.nodeColor.r,
321 if ( props.markerType != VTK::MT_USER )
322 actor->SetMarkerStd( props.markerType, props.markerScale );
324 actor->SetEdgeColor( props.edgeColor.r,
327 actor->SetLineWidth( qMax( (double)props.edgeWidth, 1. ) );
329 actor->SetSufaceColor( props.surfaceColor.r,
330 props.surfaceColor.g,
331 props.surfaceColor.b,
332 props.surfaceColor.delta );
334 actor->SetVolumeColor( props.volumeColor.r,
337 props.volumeColor.delta );
339 actor->Set0DColor( props.elem0dColor.r,
341 props.elem0dColor.b );
342 actor->Set0DSize( qMax( (double)props.elem0dSize, 1. ) );
344 actor->SetBallColor( props.ballColor.r,
347 actor->SetBallScale( qMax( props.ballScale, 1e-2 ) );
349 actor->SetOutlineColor( props.outlineColor.r,
350 props.outlineColor.g,
351 props.outlineColor.b );
352 actor->SetOutlineWidth( qMax( (double)props.outlineWidth, 1. ) );
354 actor->SetFacesOrientationColor( props.orientationColor.r,
355 props.orientationColor.g,
356 props.orientationColor.b );
357 actor->SetFacesOrientationScale( props.orientationScale );
358 actor->SetFacesOrientation3DVectors( props.orientation3d );
360 actor->SetShrinkFactor( props.shrinkFactor );
362 actor->SetOpacity( props.opacity );
367 } // end of anonymous namespace
369 /////////////////////////////////////////////////////////////////
371 /// \brief Enumeration for mesh entities.
372 /// \var EntityMode Entity0d
373 /// \brief 0D elements.
374 /// \var EntityMode EntityEdges
376 /// \var EntityMode EntityFaces
378 /// \var EntityMode EntityVolumes
380 /// \var EntityMode EntityBalls
381 /// \brief Ball elements.
382 /// \var EntityMode EntityAll
383 /// \brief All elements.
384 /////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////
435 /////////////////////////////////////////////////////////////////
436 /// \brief Constructor.
437 /////////////////////////////////////////////////////////////////
438 ColorData::ColorData()
439 : r( 0 ), g( 0 ), b( 0 )
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 /////////////////////////////////////////////////////////////////
455 /////////////////////////////////////////////////////////////////
456 /// \brief Constructor.
457 /////////////////////////////////////////////////////////////////
458 BicolorData::BicolorData()
459 : r( 0 ), g( 0 ), b( 0 ), delta( 0 )
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
501 /////////////////////////////////////////////////////////////////
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 ),
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 /////////////////////////////////////////////////////////////////
526 /////////////////////////////////////////////////////////////////
527 /// \class SMESH_Swig
528 /// \brief %SMESH GUI Python interface.
529 /////////////////////////////////////////////////////////////////
531 /////////////////////////////////////////////////////////////////
532 /// \brief Constructor.
533 /////////////////////////////////////////////////////////////////
534 SMESH_Swig::SMESH_Swig()
539 /////////////////////////////////////////////////////////////////
540 /// \brief Destructor.
541 /////////////////////////////////////////////////////////////////
542 SMESH_Swig::~SMESH_Swig()
546 /////////////////////////////////////////////////////////////////
548 /// \brief Initialize interface.
549 /////////////////////////////////////////////////////////////////
550 void SMESH_Swig::init()
552 class TInitEvent: public SALOME_Event
556 virtual void Execute()
558 SUIT_Session* session = SUIT_Session::session();
559 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
561 if ( !SMESHGUI::GetSMESHGUI() )
562 app->loadModule( "Mesh" );
566 // load SMESH GUI if it's not yet loaded
567 ProcessVoidEvent( new TInitEvent() );
568 SMESHGUI::GetSMESHGen()->UpdateStudy();
571 /////////////////////////////////////////////////////////////////
572 /// \brief Publish object.
573 /// \param ior IOR of the mesh object to publish.
574 /// \param name Study name of the object; if not given,
575 /// name is assigned automatically.
576 /// \return UID of the data object.
577 /////////////////////////////////////////////////////////////////
578 const char* SMESH_Swig::publish(const char* ior, const char* name)
583 CORBA::Object_var object = string2object( ior );
584 if ( !CORBA::is_nil( object ) )
586 SALOMEDS::SObject_var sobject =
587 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(),
590 if ( !CORBA::is_nil( sobject ) )
592 uid = sobject->GetID();
594 sobject->UnRegister();
597 return strdup( uid.c_str() );
600 /////////////////////////////////////////////////////////////////
601 /// \brief Set new study name of given object.
602 /// \param uid Object's study UID or IOR.
603 /// \param name New name of the object.
604 /////////////////////////////////////////////////////////////////
605 void SMESH_Swig::rename(const char* uid, const char* name)
609 _PTR(SObject) sobject = uid2object( uid );
611 sobject->SetAttrString( "AttributeName", name );
614 /////////////////////////////////////////////////////////////////
615 /// \brief Display mesh object.
616 /// \param uid Object's study UID or IOR.
617 /// \param viewUid View window UID (0 means currently active view
618 /// window; if there's no view, it is created).
620 /// \param updateViewer "Update view" flag. Default: \c true.
621 /////////////////////////////////////////////////////////////////
622 void SMESH_Swig::display(const char* uid, int viewUid, bool updateViewer)
624 class TDisplayEvent: public SALOME_Event
631 TDisplayEvent(const char* uid, int viewUid, bool updateViewer)
632 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
633 virtual void Execute()
635 SALOME_View* view = uid2wnd( myViewUid, true ); // create view if it's not present
637 LightApp_Displayer::FindDisplayer( "Mesh", true )->Display( myUid, myIsUpdate, view );
643 _PTR(SObject) sobject = uid2object( uid );
645 ProcessVoidEvent( new TDisplayEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
648 /////////////////////////////////////////////////////////////////
649 /// \brief Erase mesh object.
650 /// \param uid Object's study UID or IOR.
651 /// \param viewUid View window UID (0 means currently active view
652 /// window); -1 means "all view windows".
654 /// \param updateViewer "Update view" flag. Default: \c true.
655 /////////////////////////////////////////////////////////////////
656 void SMESH_Swig::erase(const char* uid, int viewUid, bool updateViewer)
658 class TEraseEvent: public SALOME_Event
665 TEraseEvent(const char* uid, int viewUid, bool updateViewer)
666 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
667 virtual void Execute()
669 if ( myViewUid == -1 )
671 QList<SALOME_View*> views = windows();
672 foreach( SALOME_View* view, views )
673 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
677 SALOME_View* view = uid2wnd( myViewUid );
679 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
686 _PTR(SObject) sobject = uid2object( uid );
688 ProcessVoidEvent( new TEraseEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
691 /////////////////////////////////////////////////////////////////
692 /// \brief Update mesh object.
693 /// \param uid Object's study UID or IOR.
694 /////////////////////////////////////////////////////////////////
695 void SMESH_Swig::update(const char* uid)
697 class TUpdateEvent: public SALOME_Event
702 TUpdateEvent( const char* uid ) : myUid( uid ) {}
703 virtual void Execute()
705 Handle(SALOME_InteractiveObject) io =
706 new SALOME_InteractiveObject( myUid, "SMESH", "" );
707 SMESH::Update( io, true );
713 _PTR(SObject) sobject = uid2object( uid );
715 ProcessVoidEvent( new TUpdateEvent( uid ) );
718 /////////////////////////////////////////////////////////////////
720 class TGetPropsEvent: public SALOME_Event
723 typedef Properties TResult;
728 TGetPropsEvent( const char* uid, int viewUid )
729 : myUid( uid ), myViewUid( viewUid ) {}
731 virtual void Execute()
733 SALOME_View* view = uid2wnd( myViewUid );
734 myResult = properties( view, myUid );
738 /////////////////////////////////////////////////////////////////
739 /// \brief Get mesh object's visual properties.
740 /// \param uid Mesh object's study UID or IOR.
741 /// \param viewUid View window UID (0 means currently active view
742 /// window); Default: 0.
743 /// \return Properties data structure.
744 /////////////////////////////////////////////////////////////////
745 Properties SMESH_Swig::properties(const char* uid, int viewUid)
751 _PTR(SObject) sobject = uid2object( uid );
753 props = ProcessEvent( new TGetPropsEvent( sobject->GetID().c_str(), viewUid ) );
758 /////////////////////////////////////////////////////////////////
760 /////////////////////////////////////////////////////////////////
761 class TSetPropsEvent: public SALOME_Event
768 TSetPropsEvent( const char* uid, const Properties& props, int viewUid )
769 : myUid( uid ), myProps( props), myViewUid( viewUid ) {}
771 virtual void Execute()
773 if ( myViewUid == -1 )
775 QList<SALOME_View*> views = windows();
776 foreach( SALOME_View* view, views )
778 setProperties( view, myUid, myProps );
783 SALOME_View* view = uid2wnd( myViewUid );
784 setProperties( view, myUid, myProps );
789 /////////////////////////////////////////////////////////////////
790 /// \brief Set mesh object's visual properties.
791 /// \param uid Mesh object's study UID or IOR.
792 /// \param props Properties data structure.
793 /// \param viewUid View window UID (0 means currently active view
794 /// window); Default: 0.
795 /////////////////////////////////////////////////////////////////
796 void SMESH_Swig::setProperties(const char* uid, const Properties& props, int viewUid)
800 _PTR(SObject) sobject = uid2object( uid );
802 ProcessVoidEvent( new TSetPropsEvent( sobject->GetID().c_str(), props, viewUid ) );
805 /////////////////////////////////////////////////////////////////
807 /////////////////////////////////////////////////////////////////
808 class TGetNodeNumberingEvent: public SALOME_Event
811 typedef bool TResult;
816 TGetNodeNumberingEvent( const char* uid, int viewUid )
817 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
819 virtual void Execute()
821 SALOME_View* view = uid2wnd( myViewUid );
822 SMESH_Actor* actor = actorFromView( view, myUid );
824 myResult = actor->GetPointsLabeled();
828 /////////////////////////////////////////////////////////////////
829 /// \brief Check if nodes numbering is switched on.
830 /// \param uid Mesh object's study UID or IOR.
831 /// \param viewUid View window UID (0 means currently active view
832 /// window); Default: 0.
833 /// \return \c true if nodes numbering is switched on;
834 /// \c false otherwise.
835 /////////////////////////////////////////////////////////////////
836 bool SMESH_Swig::nodesNumbering(const char* uid, int viewUid)
838 bool numbering = false;
842 _PTR(SObject) sobject = uid2object( uid );
844 numbering = ProcessEvent( new TGetNodeNumberingEvent( sobject->GetID().c_str(), viewUid ) );
849 /////////////////////////////////////////////////////////////////
851 /////////////////////////////////////////////////////////////////
852 class TSetNodeNumberingEvent: public SALOME_Event
859 TSetNodeNumberingEvent( const char* uid, bool numbering, int viewUid )
860 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
862 virtual void Execute()
864 SALOME_View* view = uid2wnd( myViewUid );
865 SMESH_Actor* actor = actorFromView( view, myUid );
868 actor->SetPointsLabeled( myNumbering );
875 /////////////////////////////////////////////////////////////////
876 /// \brief Switch nodes numbering on/off.
877 /// \param uid Mesh object's study UID or IOR.
878 /// \param numbering \c true to switch nodes numbering on;
879 /// \c false otherwise.
880 /// \param viewUid View window UID (0 means currently active view
881 /// window); Default: 0.
882 /////////////////////////////////////////////////////////////////
883 void SMESH_Swig::setNodesNumbering(const char* uid, bool numbering, int viewUid)
887 _PTR(SObject) sobject = uid2object( uid );
889 ProcessVoidEvent( new TSetNodeNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
892 /////////////////////////////////////////////////////////////////
894 /////////////////////////////////////////////////////////////////
895 class TGetElementNumberingEvent: public SALOME_Event
898 typedef bool TResult;
903 TGetElementNumberingEvent( const char* uid, int viewUid )
904 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
906 virtual void Execute()
908 SALOME_View* view = uid2wnd( myViewUid );
909 SMESH_Actor* actor = actorFromView( view, myUid );
911 myResult = actor->GetCellsLabeled();
915 /////////////////////////////////////////////////////////////////
916 /// \brief Check if elements numbering is switched on.
917 /// \param uid Mesh object's study UID or IOR.
918 /// \param viewUid View window UID (0 means currently active view
919 /// window); Default: 0.
920 /// \return \c true if elements numbering is switched on;
921 /// \c false otherwise.
922 /////////////////////////////////////////////////////////////////
923 bool SMESH_Swig::elementsNumbering(const char* uid, int viewUid)
925 bool numbering = false;
929 _PTR(SObject) sobject = uid2object( uid );
931 numbering = ProcessEvent( new TGetElementNumberingEvent( sobject->GetID().c_str(), viewUid ) );
936 /////////////////////////////////////////////////////////////////
938 /////////////////////////////////////////////////////////////////
939 class TSetElementNumberingEvent: public SALOME_Event
946 TSetElementNumberingEvent( const char* uid, bool numbering, int viewUid )
947 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
949 virtual void Execute()
951 SALOME_View* view = uid2wnd( myViewUid );
952 SMESH_Actor* actor = actorFromView( view, myUid );
955 actor->SetCellsLabeled( myNumbering );
962 /////////////////////////////////////////////////////////////////
963 /// \brief Switch elements numbering on/off.
964 /// \param uid Mesh object's study UID or IOR.
965 /// \param numbering \c true to switch elements numbering on;
966 /// \c false otherwise.
967 /// \param viewUid View window UID (0 means currently active view
968 /// window); Default: 0.
969 /////////////////////////////////////////////////////////////////
970 void SMESH_Swig::setElementsNumbering(const char* uid, bool numbering, int viewUid)
974 _PTR(SObject) sobject = uid2object( uid );
976 ProcessVoidEvent( new TSetElementNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
979 /////////////////////////////////////////////////////////////////
981 /////////////////////////////////////////////////////////////////
982 class TGetDisplayModeEvent: public SALOME_Event
985 typedef DisplayMode TResult;
990 TGetDisplayModeEvent( const char* uid, int viewUid )
991 : myResult( UndefinedMode ), myUid( uid ), myViewUid( viewUid ) {}
993 virtual void Execute()
995 SALOME_View* view = uid2wnd( myViewUid );
996 SMESH_Actor* actor = actorFromView( view, myUid );
998 myResult = (DisplayMode)actor->GetRepresentation();
1002 /////////////////////////////////////////////////////////////////
1003 /// \brief Get mesh object's display mode.
1004 /// \param uid Mesh object's study UID or IOR.
1005 /// \param viewUid View window UID (0 means currently active view
1006 /// window); Default: 0.
1007 /// \return Display mode (UndefinedMode if actor isn't found).
1008 /////////////////////////////////////////////////////////////////
1009 DisplayMode SMESH_Swig::displayMode(const char* uid, int viewUid)
1011 DisplayMode mode = UndefinedMode;
1015 _PTR(SObject) sobject = uid2object( uid );
1017 mode = ProcessEvent( new TGetDisplayModeEvent( sobject->GetID().c_str(), viewUid ) );
1022 /////////////////////////////////////////////////////////////////
1024 /////////////////////////////////////////////////////////////////
1025 class TSetDisplayModeEvent: public SALOME_Event
1032 TSetDisplayModeEvent( const char* uid, DisplayMode mode, int viewUid )
1033 : myUid( uid ), myMode( mode), myViewUid( viewUid ) {}
1035 virtual void Execute()
1037 SALOME_View* view = uid2wnd( myViewUid );
1038 SMESH_Actor* actor = actorFromView( view, myUid );
1039 if ( actor && myMode != UndefinedMode )
1041 actor->SetRepresentation( myMode );
1048 /////////////////////////////////////////////////////////////////
1049 /// \brief Set mesh object's display mode.
1050 /// \param uid Mesh object's study UID or IOR.
1051 /// \param mode Display mode.
1052 /// \param viewUid View window UID (0 means currently active view
1053 /// window); Default: 0.
1054 /////////////////////////////////////////////////////////////////
1055 void SMESH_Swig::setDisplayMode(const char* uid, DisplayMode mode, int viewUid)
1059 _PTR(SObject) sobject = uid2object( uid );
1061 ProcessVoidEvent( new TSetDisplayModeEvent( sobject->GetID().c_str(), mode, viewUid ) );
1064 /////////////////////////////////////////////////////////////////
1066 /////////////////////////////////////////////////////////////////
1067 class TGetShrinkModeEvent: public SALOME_Event
1070 typedef bool TResult;
1075 TGetShrinkModeEvent( const char* uid, int viewUid )
1076 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1078 virtual void Execute()
1080 SALOME_View* view = uid2wnd( myViewUid );
1081 SMESH_Actor* actor = actorFromView( view, myUid );
1083 myResult = actor->IsShrunk();
1087 /////////////////////////////////////////////////////////////////
1088 /// \brief Check if shrink mode is switched on.
1089 /// \param uid Mesh object's study UID or IOR.
1090 /// \param viewUid View window UID (0 means currently active view
1091 /// window); Default: 0.
1092 /// \return \c true if shrink mode is switched on;
1093 /// \c false otherwise.
1094 /////////////////////////////////////////////////////////////////
1095 bool SMESH_Swig::shrinkMode(const char* uid, int viewUid)
1097 bool shrinkMode = false;
1101 _PTR(SObject) sobject = uid2object( uid );
1103 shrinkMode = ProcessEvent( new TGetShrinkModeEvent( sobject->GetID().c_str(), viewUid ) );
1108 /////////////////////////////////////////////////////////////////
1110 /////////////////////////////////////////////////////////////////
1111 class TSetShrinkModeEvent: public SALOME_Event
1118 TSetShrinkModeEvent( const char* uid, bool shrink, int viewUid )
1119 : myUid( uid ), myShrink( shrink ), myViewUid( viewUid ) {}
1121 virtual void Execute()
1123 SALOME_View* view = uid2wnd( myViewUid );
1124 SMESH_Actor* actor = actorFromView( view, myUid );
1137 /////////////////////////////////////////////////////////////////
1138 /// \brief Switch shrink mode on/off.
1139 /// \param uid Mesh object's study UID or IOR.
1140 /// \param shrink \c true to switch shrink mode on;
1141 /// \c false otherwise.
1142 /// \param viewUid View window UID (0 means currently active view
1143 /// window); Default: 0.
1144 /////////////////////////////////////////////////////////////////
1145 void SMESH_Swig::setShrinkMode(const char* uid, bool shrink, int viewUid)
1149 _PTR(SObject) sobject = uid2object( uid );
1151 ProcessVoidEvent( new TSetShrinkModeEvent( sobject->GetID().c_str(), shrink, viewUid ) );
1154 /////////////////////////////////////////////////////////////////
1156 /////////////////////////////////////////////////////////////////
1157 class TGetOpacityEvent: public SALOME_Event
1160 typedef double TResult;
1165 TGetOpacityEvent( const char* uid, int viewUid )
1166 : myResult( 0 ), myUid( uid ), myViewUid( viewUid ) {}
1168 virtual void Execute()
1170 SALOME_View* view = uid2wnd( myViewUid );
1171 SMESH_Actor* actor = actorFromView( view, myUid );
1173 myResult = actor->GetOpacity();
1177 /////////////////////////////////////////////////////////////////
1178 /// \brief Get mesh object's opacity.
1179 /// \param uid Mesh object's study UID or IOR.
1180 /// \param viewUid View window UID (0 means currently active view
1181 /// window); Default: 0.
1182 /// \return Opacity value.
1183 /////////////////////////////////////////////////////////////////
1184 double SMESH_Swig::opacity(const char* uid, int viewUid)
1190 _PTR(SObject) sobject = uid2object( uid );
1192 opacity = ProcessEvent( new TGetOpacityEvent( sobject->GetID().c_str(), viewUid ) );
1197 /////////////////////////////////////////////////////////////////
1199 /////////////////////////////////////////////////////////////////
1200 class TSetOpacityEvent: public SALOME_Event
1207 TSetOpacityEvent( const char* uid, double opacity, int viewUid )
1208 : myUid( uid ), myOpacity( opacity ), myViewUid( viewUid ) {}
1210 virtual void Execute()
1212 SALOME_View* view = uid2wnd( myViewUid );
1213 SMESH_Actor* actor = actorFromView( view, myUid );
1216 actor->SetOpacity( myOpacity );
1223 /////////////////////////////////////////////////////////////////
1224 /// \brief Set mesh object's opacity.
1225 /// \param uid Mesh object's study UID or IOR.
1226 /// \param opacity Opacity value.
1227 /// \param viewUid View window UID (0 means currently active view
1228 /// window); Default: 0.
1229 /////////////////////////////////////////////////////////////////
1230 void SMESH_Swig::setOpacity(const char* uid, double opacity, int viewUid)
1234 _PTR(SObject) sobject = uid2object( uid );
1236 ProcessVoidEvent( new TSetOpacityEvent( sobject->GetID().c_str(), opacity, viewUid ) );
1239 /////////////////////////////////////////////////////////////////
1241 /////////////////////////////////////////////////////////////////
1242 class TGetOrientationEvent: public SALOME_Event
1245 typedef bool TResult;
1250 TGetOrientationEvent( const char* uid, int viewUid )
1251 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1253 virtual void Execute()
1255 SALOME_View* view = uid2wnd( myViewUid );
1256 SMESH_Actor* actor = actorFromView( view, myUid );
1258 myResult = actor->GetFacesOriented();
1262 /////////////////////////////////////////////////////////////////
1263 /// \brief Check if faces orientation vectors are shown.
1264 /// \param uid Mesh object's study UID or IOR.
1265 /// \param viewUid View window UID (0 means currently active view
1266 /// window); Default: 0.
1267 /// \return \c true if faces orientation vectors are shown;
1268 /// \c false otherwise.
1269 /////////////////////////////////////////////////////////////////
1270 bool SMESH_Swig::isOrientationShown(const char* uid, int viewUid)
1276 _PTR(SObject) sobject = uid2object( uid );
1278 shown = ProcessEvent( new TGetOrientationEvent( sobject->GetID().c_str(), viewUid ) );
1283 /////////////////////////////////////////////////////////////////
1285 /////////////////////////////////////////////////////////////////
1286 class TSetOrientationEvent: public SALOME_Event
1293 TSetOrientationEvent( const char* uid, bool shown, int viewUid )
1294 : myUid( uid ), myShown( shown ), myViewUid( viewUid ) {}
1296 virtual void Execute()
1298 SALOME_View* view = uid2wnd( myViewUid );
1299 SMESH_Actor* actor = actorFromView( view, myUid );
1302 actor->SetFacesOriented( myShown );
1309 /////////////////////////////////////////////////////////////////
1310 /// \brief Show/hide faces orientation vectors.
1311 /// \param uid Mesh object's study UID or IOR.
1312 /// \param shown \c true to show faces orientation vectors;
1313 /// \c false otherwise.
1314 /// \param viewUid View window UID (0 means currently active view
1315 /// window); Default: 0.
1316 /////////////////////////////////////////////////////////////////
1317 void SMESH_Swig::setOrientationShown(const char* uid, bool shown, int viewUid)
1321 _PTR(SObject) sobject = uid2object( uid );
1323 ProcessVoidEvent( new TSetOrientationEvent( sobject->GetID().c_str(), shown, viewUid ) );
1326 /////////////////////////////////////////////////////////////////
1328 /////////////////////////////////////////////////////////////////
1329 class TGetEntitiesEvent: public SALOME_Event
1332 typedef int TResult;
1337 TGetEntitiesEvent( const char* uid, int viewUid )
1338 : myResult( EntityNone ), myUid( uid ), myViewUid( viewUid ) {}
1340 virtual void Execute()
1342 SALOME_View* view = uid2wnd( myViewUid );
1343 SMESH_Actor* actor = actorFromView( view, myUid );
1345 myResult = actor->GetEntityMode();
1349 /////////////////////////////////////////////////////////////////
1350 /// \brief Get mesh object's visible entities.
1351 /// \param uid Mesh object's study UID or IOR.
1352 /// \param viewUid View window UID (0 means currently active view
1353 /// window); Default: 0.
1354 /// \return Enumerator describing entities being visible.
1355 /////////////////////////////////////////////////////////////////
1356 int SMESH_Swig::entitiesShown(const char* uid, int viewUid)
1358 int entities = EntityNone;
1362 _PTR(SObject) sobject = uid2object( uid );
1364 entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1369 /////////////////////////////////////////////////////////////////
1371 /////////////////////////////////////////////////////////////////
1372 class TSetEntitiesEvent: public SALOME_Event
1379 TSetEntitiesEvent( const char* uid, int entities, int viewUid )
1380 : myUid( uid ), myEntities( entities ), myViewUid( viewUid ) {}
1382 virtual void Execute()
1384 SALOME_View* view = uid2wnd( myViewUid );
1385 SMESH_Actor* actor = actorFromView( view, myUid );
1388 actor->SetEntityMode( myEntities );
1395 /////////////////////////////////////////////////////////////////
1396 /// \brief Set mesh object's visible entities.
1397 /// \param uid Mesh object's study UID or IOR.
1398 /// \param entities Enumerator describing entities to be shown.
1399 /// \param viewUid View window UID (0 means currently active view
1400 /// window); Default: 0.
1401 /////////////////////////////////////////////////////////////////
1402 void SMESH_Swig::setEntitiesShown(const char* uid, int entities, int viewUid)
1406 _PTR(SObject) sobject = uid2object( uid );
1408 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1411 /////////////////////////////////////////////////////////////////
1412 /// \brief Check if given mesh object's entity is shown.
1413 /// \param uid Mesh object's study UID or IOR.
1414 /// \param entity Mesh entity.
1415 /// \param viewUid View window UID (0 means currently active view
1416 /// window); Default: 0.
1417 /// \return \c true if entity is shown; \c false otherwise.
1418 /////////////////////////////////////////////////////////////////
1419 bool SMESH_Swig::isEntityShown(const char* uid, EntityMode entity, int viewUid)
1425 _PTR(SObject) sobject = uid2object( uid );
1428 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1429 shown = (bool)( entities & entity );
1435 /////////////////////////////////////////////////////////////////
1436 /// \brief Show/hide entity for given mesh object.
1437 /// \param uid Mesh object's study UID or IOR.
1438 /// \param entity Mesh entity.
1439 /// \param show Visibility status.
1440 /// \param viewUid View window UID (0 means currently active view
1441 /// window); Default: 0.
1442 /////////////////////////////////////////////////////////////////
1443 void SMESH_Swig::setEntityShown(const char* uid, EntityMode entity, bool show, int viewUid)
1447 _PTR(SObject) sobject = uid2object( uid );
1450 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1454 entities &= ~entity;
1455 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1459 /////////////////////////////////////////////////////////////////
1460 /// \brief Initialize %SMESH GUI Python interface.
1461 /// \deprecated Interface is initialized automatically.
1462 /////////////////////////////////////////////////////////////////
1463 void SMESH_Swig::Init()
1465 deprecated("SMESH_Swig::Init");
1466 // does nothing; initialization is done automatically.
1469 /////////////////////////////////////////////////////////////////
1470 /// \brief Publish mesh in the active study.
1471 /// \deprecated Publishing is done automatically.
1472 /// \param ior IOR of the mesh.
1473 /// \param name Name of the mesh (optional).
1474 /// \return UID of the data object.
1475 /////////////////////////////////////////////////////////////////
1476 const char* SMESH_Swig::AddNewMesh(const char* ior, const char* name)
1478 deprecated("SMESH_Swig::AddNewMesh", "SMESH_Swig::publish");
1479 return publish( ior, name );
1482 /////////////////////////////////////////////////////////////////
1483 /// \brief Publish hypothesis in the active study.
1484 /// \deprecated Publishing is done automatically.
1485 /// \param ior IOR of the hypothesis.
1486 /// \param name Name of the hypothesis (optional).
1487 /// \return UID of the data object.
1488 /////////////////////////////////////////////////////////////////
1489 const char* SMESH_Swig::AddNewHypothesis(const char* ior, const char* name)
1491 deprecated("SMESH_Swig::AddNewHypothesis", "SMESH_Swig::publish");
1492 return publish( ior, name );
1495 /////////////////////////////////////////////////////////////////
1496 /// \brief Publish algorithm in the active study.
1497 /// \deprecated Publishing is done automatically.
1498 /// \param ior IOR of the algorithm.
1499 /// \param name Name of the algorithm (optional).
1500 /// \return UID of the data object.
1501 /////////////////////////////////////////////////////////////////
1502 const char* SMESH_Swig::AddNewAlgorithm(const char* ior, const char* name)
1504 deprecated("SMESH_Swig::AddNewAlgorithm", "SMESH_Swig::publish");
1505 return publish( ior, name );
1508 /////////////////////////////////////////////////////////////////
1509 /// \deprecated Publishing is done automatically.
1510 /// \deprecated Synonim of AddNewAlgorithm().
1511 /// \param ior IOR of the algorithm.
1512 /// \param name Name of the algorithm (optional).
1513 /// \return UID of the data object.
1514 /////////////////////////////////////////////////////////////////
1515 const char* SMESH_Swig::AddNewAlgorithms(const char* ior, const char* name)
1517 deprecated("SMESH_Swig::AddNewAlgorithms", "SMESH_Swig::publish");
1518 return publish( ior, name );
1521 /////////////////////////////////////////////////////////////////
1522 /// \brief Add reference on a shape for mesh in a study.
1523 /// \deprecated Publishing is done automatically.
1524 /// \param shapeUid GEOM shape's study UID (not used).
1525 /// \param meshUid Mesh's study UID (not used).
1526 /////////////////////////////////////////////////////////////////
1527 void SMESH_Swig::SetShape(const char* /*shapeUid*/, const char* /*meshUid*/)
1529 deprecated("SMESH_Swig::SetShape", "SMESH_Swig::publish");
1530 // does nothing: publishing is done automatically
1533 /////////////////////////////////////////////////////////////////
1534 /// \brief Assign hypothesis to mesh or sub-mesh.
1535 /// \deprecated Publishing is done automatically.
1536 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1537 /// \param hypoUID Hypothesis's study UID (not used).
1538 /////////////////////////////////////////////////////////////////
1539 void SMESH_Swig::SetHypothesis(const char* /*meshUid*/, const char* /*hypoUID*/)
1541 deprecated("SMESH_Swig::SetHypothesis", "SMESH_Swig::publish");
1542 // does nothing: publishing is done automatically
1545 /////////////////////////////////////////////////////////////////
1546 /// \brief Assign algorithm to mesh or sub-mesh.
1547 /// \deprecated Publishing is done automatically.
1548 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1549 /// \param algoUID Algorithm's study UID (not used).
1550 /////////////////////////////////////////////////////////////////
1551 void SMESH_Swig::SetAlgorithms(const char* /*meshUid*/, const char* /*algoUID*/)
1553 deprecated("SMESH_Swig::SetAlgorithms", "SMESH_Swig::publish");
1554 // does nothing: publishing is done automatically
1557 /////////////////////////////////////////////////////////////////
1558 /// \brief Anassign hypothesis or algorithm from mesh or sub-mesh.
1559 /// \deprecated Unpublishing is done automatically.
1560 /// \param uid Hypothesis's or algorithm's study UID (not used).
1561 /////////////////////////////////////////////////////////////////
1562 void SMESH_Swig::UnSetHypothesis(const char* /*uid*/)
1564 deprecated("SMESH_Swig::UnSetHypothesis");
1565 // does nothing: unpublishing is done automatically
1568 /////////////////////////////////////////////////////////////////
1569 /// \brief Publish sub-mesh in the active study.
1570 /// \deprecated Publishing is done automatically.
1571 /// \param meshUid Parent mesh's study UID (not used).
1572 /// \param ior IOR of the sub-mesh.
1573 /// \param shapeType GEOM shape's type (not used).
1574 /// \param name Name of the sub-mesh (optional).
1575 /// \return UID of the data object.
1576 /////////////////////////////////////////////////////////////////
1577 const char* SMESH_Swig::AddSubMesh(const char* /*meshUid*/,
1582 deprecated("SMESH_Swig::AddSubMesh", "SMESH_Swig::publish");
1583 return publish( ior, name );
1586 /////////////////////////////////////////////////////////////////
1587 /// \brief Publish sub-mesh in the active study.
1588 /// \deprecated Publishing is done automatically.
1589 /// \param meshUid Parent mesh's study UID (not used).
1590 /// \param shapeUid GEOM shape's study UID (not used).
1591 /// \param ior IOR of the sub-mesh.
1592 /// \param shapeType GEOM shape's type (not used).
1593 /// \param name Name of the sub-mesh (optional).
1594 /// \return UID of the data object.
1595 /////////////////////////////////////////////////////////////////
1596 const char* SMESH_Swig::AddSubMeshOnShape(const char* /*meshUid*/,
1597 const char* /*shapeUid*/,
1602 deprecated("SMESH_Swig::AddSubMeshOnShape", "SMESH_Swig::publish");
1603 return publish( ior, name );
1606 /////////////////////////////////////////////////////////////////
1607 /// \brief Set new study name of given object.
1608 /// \deprecated Use rename() method.
1609 /// \param uid Object's study UID or IOR.
1610 /// \param name New name of the object.
1611 /////////////////////////////////////////////////////////////////
1612 void SMESH_Swig::SetName(const char* uid, const char* name)
1614 deprecated("SMESH_Swig::SetName", "SMESH_Swig::rename");
1615 rename( uid, name );
1618 /////////////////////////////////////////////////////////////////
1619 /// \brief Set mesh icon according to compute status
1620 /// \deprecated Publishing is done automatically.
1621 /// \param meshUid Mesh's study UID (not used).
1622 /// \param isComputed Flag pointing that mesh is computed or no
1624 /// \param isEmpty Flag pointing that mesh is empty or no
1626 /////////////////////////////////////////////////////////////////
1627 void SMESH_Swig::SetMeshIcon(const char* /*meshUid*/,
1628 const bool /*isComputed*/,
1629 const bool /*isEmpty*/)
1631 deprecated("SMESH_Swig::SetMeshIcon", "SMESH_Swig::publish");
1632 // does nothing: publishing is done automatically
1635 /////////////////////////////////////////////////////////////////
1636 /// Display mesh in the currently active view window.
1637 /// \deprecated Use display() method.
1638 /// \param meshUid Mesh's study UID.
1639 /////////////////////////////////////////////////////////////////
1640 void SMESH_Swig::CreateAndDisplayActor(const char* meshUid)
1642 deprecated("SMESH_Swig::CreateAndDisplayActor", "SMESH_Swig::display");
1646 /////////////////////////////////////////////////////////////////
1647 /// Erase mesh in the view window(s).
1648 /// \deprecated Use erase() method.
1649 /// \param meshUid Mesh's study UID.
1650 /// \param allViewers If \c true, mesh is removed from all views.
1651 /// Default: \c false.
1652 /////////////////////////////////////////////////////////////////
1653 void SMESH_Swig::EraseActor(const char* meshUid, const bool allViewers)
1655 deprecated("SMESH_Swig::EraseActor", "SMESH_Swig::erase");
1656 erase( meshUid, allViewers ? -1 : 0 );
1659 /////////////////////////////////////////////////////////////////
1660 /// Update mesh object.
1661 /// \deprecated Use update() method.
1662 /// \param meshUid Mesh's study UID.
1663 /////////////////////////////////////////////////////////////////
1664 void SMESH_Swig::UpdateActor(const char* meshUid)
1666 deprecated("SMESH_Swig::UpdateActor", "SMESH_Swig::update");
1670 /////////////////////////////////////////////////////////////////
1671 /// Get mesh object's properties.
1672 /// \deprecated Use properties() method.
1673 /// \param meshUid Mesh's study UID.
1674 /// \param viewUid View window UID (0 means currently active view
1675 /// window). Default: 0.
1676 /////////////////////////////////////////////////////////////////
1677 actorAspect SMESH_Swig::GetActorAspect(const char* meshUid, int viewUid)
1679 deprecated("SMESH_Swig::GetActorAspect", "SMESH_Swig::properties");
1680 return properties( meshUid, viewUid );
1683 /////////////////////////////////////////////////////////////////
1684 /// Set mesh object's properties.
1685 /// \deprecated Use setProperties() method.
1686 /// \param meshUid Mesh's study UID.
1687 /// \param viewUid View window UID (0 means currently active view
1688 /// window). Default: 0.
1689 /////////////////////////////////////////////////////////////////
1690 void SMESH_Swig::SetActorAspect(const actorAspect& aspect, const char* meshUid, int viewUid)
1692 deprecated("SMESH_Swig::SetActorAspect", "SMESH_Swig::setProperties");
1693 setProperties( meshUid, aspect, viewUid );
1696 /////////////////////////////////////////////////////////////////
1698 /////////////////////////////////////////////////////////////////
1699 class TSelectListEvent: public SALOME_Event
1702 std::vector<int> myIds;
1706 TSelectListEvent(const char* uid, std::vector<int> ids, bool append)
1707 : myUid( uid ), myIds( ids ), myIsAppend( append )
1710 virtual void Execute()
1712 LightApp_SelectionMgr* selMgr = 0;
1713 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1715 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1720 selMgr->clearFilters();
1722 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1726 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1728 if ( !actor || !actor->hasIO() )
1731 Handle(SALOME_InteractiveObject) io = actor->getIO();
1734 selMgr->setSelectedObjects( ios, false );
1736 if ( vw->SelectionMode() == ActorSelection )
1739 TColStd_MapOfInteger idMap;
1740 std::vector<int>::const_iterator it;
1741 for ( it = myIds.begin(); it != myIds.end(); ++it )
1746 // Set new selection
1747 SVTK_Selector* selector = vw->GetSelector();
1748 selector->AddOrRemoveIndex( io, idMap, myIsAppend );
1749 vw->highlight( io, true, true );
1750 vw->GetInteractor()->onEmitSelectionChanged();
1754 /////////////////////////////////////////////////////////////////
1755 /// \brief Select elements of the mesh, sub-mesh or group.
1756 /// \param uid Mesh object's study UID or IOR.
1757 /// \param ids List of mesh elements.
1758 /// \param append If \c true, elements are added to current
1759 /// selection; otherwise, previous selection is
1761 /////////////////////////////////////////////////////////////////
1762 void SMESH_Swig::select(const char* uid, std::vector<int> ids, bool append)
1766 _PTR(SObject) sobject = uid2object( uid );
1768 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1771 /////////////////////////////////////////////////////////////////
1772 /// \brief Select element of the mesh, sub-mesh or group.
1773 /// \param uid Mesh object's study UID or IOR.
1774 /// \param id Mesh element.
1775 /// \param append If \c true, element is added to current
1776 /// selection; otherwise, previous selection is
1778 /////////////////////////////////////////////////////////////////
1779 void SMESH_Swig::select(const char* uid, int id, bool append)
1783 std::vector<int> ids;
1784 ids.push_back( id );
1786 _PTR(SObject) sobject = uid2object( uid );
1788 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1791 /////////////////////////////////////////////////////////////////
1793 /////////////////////////////////////////////////////////////////
1794 class TSelectListOfPairEvent: public SALOME_Event
1797 std::vector<std::pair<int, int> > myIds;
1801 TSelectListOfPairEvent(const char* uid, std::vector<std::pair<int, int> > ids, bool append)
1802 : myUid( uid ), myIds( ids ), myIsAppend( append )
1805 virtual void Execute()
1807 LightApp_SelectionMgr* selMgr = 0;
1808 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1810 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1815 selMgr->clearFilters();
1817 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1821 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1823 if ( !actor || !actor->hasIO() )
1826 Handle(SALOME_InteractiveObject) io = actor->getIO();
1829 selMgr->setSelectedObjects( ios, false );
1831 if ( vw->SelectionMode() != EdgeOfCellSelection )
1834 SVTK_IndexedMapOfIds idMap;
1835 std::vector<std::pair<int, int> >::const_iterator it;
1836 for ( it = myIds.begin(); it != myIds.end(); ++it )
1838 std::vector<int> pair;
1839 pair.push_back( (*it).first );
1840 pair.push_back( (*it).second );
1844 // Set new selection
1845 SVTK_Selector* selector = vw->GetSelector();
1846 selector->AddOrRemoveCompositeIndex( io, idMap, myIsAppend );
1847 vw->highlight( io, true, true );
1848 vw->GetInteractor()->onEmitSelectionChanged();
1852 /////////////////////////////////////////////////////////////////
1853 /// \brief Select pseudo-edges (specified by two nodes)
1854 /// of the mesh, sub-mesh or group.
1855 /// \param uid Mesh object's study UID or IOR.
1856 /// \param ids List of pairs containing two nodes IDs.
1857 /// \param append If \c true, pseudo-edges are added to current
1858 /// selection; otherwise, previous selection is
1860 /////////////////////////////////////////////////////////////////
1861 void SMESH_Swig::select(const char* uid, std::vector<std::pair<int,int> > ids, bool append)
1865 _PTR(SObject) sobject = uid2object( uid );
1867 ProcessVoidEvent( new TSelectListOfPairEvent( sobject->GetID().c_str(), ids, append ) );
1870 /////////////////////////////////////////////////////////////////
1872 /////////////////////////////////////////////////////////////////
1873 class TGetSelectionModeEvent: public SALOME_Event
1876 typedef SelectionMode TResult;
1880 TGetSelectionModeEvent( int viewUid ) :
1881 myResult( Undefined ), myViewUid( viewUid ) {}
1883 virtual void Execute()
1885 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1888 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1890 myResult = (SelectionMode)vw->SelectionMode();
1895 /////////////////////////////////////////////////////////////////
1896 /// \brief Get selection mode of view window.
1897 /// \param viewUid View window UID (0 means currently active view
1898 /// window); Default: 0.
1899 /// \return Current selection mode.
1900 /////////////////////////////////////////////////////////////////
1901 SelectionMode SMESH_Swig::getSelectionMode(int viewUid)
1904 return ProcessEvent( new TGetSelectionModeEvent( viewUid ) );
1907 /////////////////////////////////////////////////////////////////
1909 /////////////////////////////////////////////////////////////////
1910 class TSetSelectionModeEvent: public SALOME_Event
1912 SelectionMode mySelectionMode;
1916 TSetSelectionModeEvent( const SelectionMode selectionMode, int viewUid )
1917 : mySelectionMode( selectionMode ), myViewUid( viewUid )
1920 virtual void Execute()
1922 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1925 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1928 SelectionMode previousMode = (SelectionMode)vw->SelectionMode();
1929 bool switchPointMode = ( previousMode == Node && mySelectionMode != Node ) ||
1930 ( previousMode != Node && mySelectionMode == Node );
1931 if ( switchPointMode )
1933 vtkRenderer* renderer = vw->getRenderer();
1934 VTK::ActorCollectionCopy actors( renderer->GetActors() );
1935 vtkActorCollection* collection = actors.GetActors();
1936 collection->InitTraversal();
1937 while ( vtkActor* vtkActor = collection->GetNextActor() )
1939 if ( SMESH_Actor* actor = dynamic_cast<SMESH_Actor*>( vtkActor ) )
1941 if ( actor->GetVisibility() )
1942 actor->SetPointRepresentation( mySelectionMode == Node );
1946 vw->SetSelectionMode( mySelectionMode );
1952 /////////////////////////////////////////////////////////////////
1953 /// \brief Set selection mode to view window.
1954 /// \param viewUid View window UID (0 means currently active view
1955 /// window); Default: 0.
1956 /// \param mode Selection mode.
1957 /////////////////////////////////////////////////////////////////
1958 void SMESH_Swig::setSelectionMode(SelectionMode mode, int viewUid)
1961 ProcessVoidEvent( new TSetSelectionModeEvent( mode, viewUid ) );
1964 /////////////////////////////////////////////////////////////////
1966 /////////////////////////////////////////////////////////////////
1967 class TGetSelectedEvent: public SALOME_Event
1970 typedef std::vector<int> TResult;
1974 TGetSelectedEvent( const char* uid )
1977 virtual void Execute()
1979 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1983 SVTK_Selector* selector = vw->GetSelector();
1987 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1988 if ( !actor || !actor->hasIO() )
1991 TColStd_IndexedMapOfInteger idMap;
1992 selector->GetIndex( actor->getIO(), idMap );
1994 for ( int i = 1; i <= idMap.Extent(); i++ )
1995 myResult.push_back( idMap( i ) );
1999 /////////////////////////////////////////////////////////////////
2000 /// \brief Get selected elements of the mesh, sub-mesh or group.
2001 /// \param uid Mesh object's study UID or IOR.
2002 /// \return List of selected mesh elements.
2003 /////////////////////////////////////////////////////////////////
2004 std::vector<int> SMESH_Swig::getSelected(const char* uid)
2006 std::vector<int> ids;
2010 _PTR(SObject) sobject = uid2object( uid );
2012 ids = ProcessEvent( new TGetSelectedEvent( sobject->GetID().c_str() ) );
2017 /////////////////////////////////////////////////////////////////
2019 /////////////////////////////////////////////////////////////////
2020 class TGetSelectedPairEvent : public SALOME_Event
2023 typedef std::vector<std::pair<int, int> > TResult;
2027 TGetSelectedPairEvent( const char* uid )
2030 virtual void Execute()
2032 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2036 if ( vw->SelectionMode() != EdgeOfCellSelection )
2039 SVTK_Selector* selector = vw->GetSelector();
2043 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2044 if ( !actor || !actor->hasIO() )
2047 SVTK_IndexedMapOfIds idMap;
2048 selector->GetCompositeIndex( actor->getIO(), idMap );
2050 for ( int i = 1; i <= idMap.Extent(); i++ )
2051 myResult.push_back( std::make_pair<int,int>( (int)idMap( i )[0], (int)idMap( i )[1]) );
2055 /////////////////////////////////////////////////////////////////
2056 /// \brief Get selected pseudo-edges (specified by two nodes)
2057 /// of the mesh, sub-mesh or group.
2058 /// \param uid Mesh object's study UID or IOR.
2059 /// \param ids List of pairs containing two nodes IDs.
2060 /// \param append If \c true, pseudo-edges are added to current
2061 /// selection; otherwise, previous selection is
2063 /////////////////////////////////////////////////////////////////
2064 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell(const char* uid)
2066 std::vector<std::pair<int,int> > pairs;
2070 _PTR(SObject) sobject = uid2object( uid );
2072 pairs = ProcessEvent( new TGetSelectedPairEvent( sobject->GetID().c_str() ) );