1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
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 currently 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 if ( SUIT_Session::session() )
569 ProcessVoidEvent( new TInitEvent() );
570 SMESHGUI::GetSMESHGen()->UpdateStudy();
574 /////////////////////////////////////////////////////////////////
575 /// \brief Publish object.
576 /// \param ior IOR of the mesh object to publish.
577 /// \param name Study name of the object; if not given,
578 /// name is assigned automatically.
579 /// \return UID of the data object.
580 /////////////////////////////////////////////////////////////////
581 const char* SMESH_Swig::publish(const char* ior, const char* name)
586 CORBA::Object_var object = string2object( ior );
587 if ( !CORBA::is_nil( object ) )
589 SALOMEDS::SObject_var sobject =
590 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(),
593 if ( !CORBA::is_nil( sobject ) )
595 uid = sobject->GetID();
597 sobject->UnRegister();
600 return strdup( uid.c_str() );
603 /////////////////////////////////////////////////////////////////
604 /// \brief Set new study name of given object.
605 /// \param uid Object's study UID or IOR.
606 /// \param name New name of the object.
607 /////////////////////////////////////////////////////////////////
608 void SMESH_Swig::rename(const char* uid, const char* name)
612 _PTR(SObject) sobject = uid2object( uid );
614 sobject->SetAttrString( "AttributeName", name );
617 /////////////////////////////////////////////////////////////////
618 /// \brief Display mesh object.
619 /// \param uid Object's study UID or IOR.
620 /// \param viewUid View window UID (0 means currently active view
621 /// window; if there's no view, it is created).
623 /// \param updateViewer "Update view" flag. Default: \c true.
624 /////////////////////////////////////////////////////////////////
625 void SMESH_Swig::display(const char* uid, int viewUid, bool updateViewer)
627 class TDisplayEvent: public SALOME_Event
634 TDisplayEvent(const char* uid, int viewUid, bool updateViewer)
635 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
636 virtual void Execute()
638 SALOME_View* view = uid2wnd( myViewUid, true ); // create view if it's not present
640 LightApp_Displayer::FindDisplayer( "Mesh", true )->Display( myUid, myIsUpdate, view );
646 _PTR(SObject) sobject = uid2object( uid );
648 ProcessVoidEvent( new TDisplayEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
651 /////////////////////////////////////////////////////////////////
652 /// \brief Erase mesh object.
653 /// \param uid Object's study UID or IOR.
654 /// \param viewUid View window UID (0 means currently active view
655 /// window); -1 means "all view windows".
657 /// \param updateViewer "Update view" flag. Default: \c true.
658 /////////////////////////////////////////////////////////////////
659 void SMESH_Swig::erase(const char* uid, int viewUid, bool updateViewer)
661 class TEraseEvent: public SALOME_Event
668 TEraseEvent(const char* uid, int viewUid, bool updateViewer)
669 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
670 virtual void Execute()
672 if ( myViewUid == -1 )
674 QList<SALOME_View*> views = windows();
675 foreach( SALOME_View* view, views )
676 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
680 SALOME_View* view = uid2wnd( myViewUid );
682 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
689 _PTR(SObject) sobject = uid2object( uid );
691 ProcessVoidEvent( new TEraseEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
694 /////////////////////////////////////////////////////////////////
695 /// \brief Update mesh object.
696 /// \param uid Object's study UID or IOR.
697 /////////////////////////////////////////////////////////////////
698 void SMESH_Swig::update(const char* uid)
700 class TUpdateEvent: public SALOME_Event
705 TUpdateEvent( const char* uid ) : myUid( uid ) {}
706 virtual void Execute()
708 Handle(SALOME_InteractiveObject) io =
709 new SALOME_InteractiveObject( myUid, "SMESH", "" );
710 SMESH::Update( io, true );
716 _PTR(SObject) sobject = uid2object( uid );
718 ProcessVoidEvent( new TUpdateEvent( uid ) );
721 /////////////////////////////////////////////////////////////////
723 class TGetPropsEvent: public SALOME_Event
726 typedef Properties TResult;
731 TGetPropsEvent( const char* uid, int viewUid )
732 : myUid( uid ), myViewUid( viewUid ) {}
734 virtual void Execute()
736 SALOME_View* view = uid2wnd( myViewUid );
737 myResult = properties( view, myUid );
741 /////////////////////////////////////////////////////////////////
742 /// \brief Get mesh object's visual properties.
743 /// \param uid Mesh object's study UID or IOR.
744 /// \param viewUid View window UID (0 means currently active view
745 /// window); Default: 0.
746 /// \return Properties data structure.
747 /////////////////////////////////////////////////////////////////
748 Properties SMESH_Swig::properties(const char* uid, int viewUid)
754 _PTR(SObject) sobject = uid2object( uid );
756 props = ProcessEvent( new TGetPropsEvent( sobject->GetID().c_str(), viewUid ) );
761 /////////////////////////////////////////////////////////////////
763 /////////////////////////////////////////////////////////////////
764 class TSetPropsEvent: public SALOME_Event
771 TSetPropsEvent( const char* uid, const Properties& props, int viewUid )
772 : myUid( uid ), myProps( props), myViewUid( viewUid ) {}
774 virtual void Execute()
776 if ( myViewUid == -1 )
778 QList<SALOME_View*> views = windows();
779 foreach( SALOME_View* view, views )
781 setProperties( view, myUid, myProps );
786 SALOME_View* view = uid2wnd( myViewUid );
787 setProperties( view, myUid, myProps );
792 /////////////////////////////////////////////////////////////////
793 /// \brief Set mesh object's visual properties.
794 /// \param uid Mesh object's study UID or IOR.
795 /// \param props Properties data structure.
796 /// \param viewUid View window UID (0 means currently active view
797 /// window); Default: 0.
798 /////////////////////////////////////////////////////////////////
799 void SMESH_Swig::setProperties(const char* uid, const Properties& props, int viewUid)
803 _PTR(SObject) sobject = uid2object( uid );
805 ProcessVoidEvent( new TSetPropsEvent( sobject->GetID().c_str(), props, viewUid ) );
808 /////////////////////////////////////////////////////////////////
810 /////////////////////////////////////////////////////////////////
811 class TGetNodeNumberingEvent: public SALOME_Event
814 typedef bool TResult;
819 TGetNodeNumberingEvent( const char* uid, int viewUid )
820 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
822 virtual void Execute()
824 SALOME_View* view = uid2wnd( myViewUid );
825 SMESH_Actor* actor = actorFromView( view, myUid );
827 myResult = actor->GetPointsLabeled();
831 /////////////////////////////////////////////////////////////////
832 /// \brief Check if nodes numbering is switched on.
833 /// \param uid Mesh object's study UID or IOR.
834 /// \param viewUid View window UID (0 means currently active view
835 /// window); Default: 0.
836 /// \return \c true if nodes numbering is switched on;
837 /// \c false otherwise.
838 /////////////////////////////////////////////////////////////////
839 bool SMESH_Swig::nodesNumbering(const char* uid, int viewUid)
841 bool numbering = false;
845 _PTR(SObject) sobject = uid2object( uid );
847 numbering = ProcessEvent( new TGetNodeNumberingEvent( sobject->GetID().c_str(), viewUid ) );
852 /////////////////////////////////////////////////////////////////
854 /////////////////////////////////////////////////////////////////
855 class TSetNodeNumberingEvent: public SALOME_Event
862 TSetNodeNumberingEvent( const char* uid, bool numbering, int viewUid )
863 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
865 virtual void Execute()
867 SALOME_View* view = uid2wnd( myViewUid );
868 SMESH_Actor* actor = actorFromView( view, myUid );
871 actor->SetPointsLabeled( myNumbering );
878 /////////////////////////////////////////////////////////////////
879 /// \brief Switch nodes numbering on/off.
880 /// \param uid Mesh object's study UID or IOR.
881 /// \param numbering \c true to switch nodes numbering on;
882 /// \c false otherwise.
883 /// \param viewUid View window UID (0 means currently active view
884 /// window); Default: 0.
885 /////////////////////////////////////////////////////////////////
886 void SMESH_Swig::setNodesNumbering(const char* uid, bool numbering, int viewUid)
890 _PTR(SObject) sobject = uid2object( uid );
892 ProcessVoidEvent( new TSetNodeNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
895 /////////////////////////////////////////////////////////////////
897 /////////////////////////////////////////////////////////////////
898 class TGetElementNumberingEvent: public SALOME_Event
901 typedef bool TResult;
906 TGetElementNumberingEvent( const char* uid, int viewUid )
907 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
909 virtual void Execute()
911 SALOME_View* view = uid2wnd( myViewUid );
912 SMESH_Actor* actor = actorFromView( view, myUid );
914 myResult = actor->GetCellsLabeled();
918 /////////////////////////////////////////////////////////////////
919 /// \brief Check if elements numbering is switched on.
920 /// \param uid Mesh object's study UID or IOR.
921 /// \param viewUid View window UID (0 means currently active view
922 /// window); Default: 0.
923 /// \return \c true if elements numbering is switched on;
924 /// \c false otherwise.
925 /////////////////////////////////////////////////////////////////
926 bool SMESH_Swig::elementsNumbering(const char* uid, int viewUid)
928 bool numbering = false;
932 _PTR(SObject) sobject = uid2object( uid );
934 numbering = ProcessEvent( new TGetElementNumberingEvent( sobject->GetID().c_str(), viewUid ) );
939 /////////////////////////////////////////////////////////////////
941 /////////////////////////////////////////////////////////////////
942 class TSetElementNumberingEvent: public SALOME_Event
949 TSetElementNumberingEvent( const char* uid, bool numbering, int viewUid )
950 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
952 virtual void Execute()
954 SALOME_View* view = uid2wnd( myViewUid );
955 SMESH_Actor* actor = actorFromView( view, myUid );
958 actor->SetCellsLabeled( myNumbering );
965 /////////////////////////////////////////////////////////////////
966 /// \brief Switch elements numbering on/off.
967 /// \param uid Mesh object's study UID or IOR.
968 /// \param numbering \c true to switch elements numbering on;
969 /// \c false otherwise.
970 /// \param viewUid View window UID (0 means currently active view
971 /// window); Default: 0.
972 /////////////////////////////////////////////////////////////////
973 void SMESH_Swig::setElementsNumbering(const char* uid, bool numbering, int viewUid)
977 _PTR(SObject) sobject = uid2object( uid );
979 ProcessVoidEvent( new TSetElementNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
982 /////////////////////////////////////////////////////////////////
984 /////////////////////////////////////////////////////////////////
985 class TGetDisplayModeEvent: public SALOME_Event
988 typedef DisplayMode TResult;
993 TGetDisplayModeEvent( const char* uid, int viewUid )
994 : myResult( UndefinedMode ), myUid( uid ), myViewUid( viewUid ) {}
996 virtual void Execute()
998 SALOME_View* view = uid2wnd( myViewUid );
999 SMESH_Actor* actor = actorFromView( view, myUid );
1001 myResult = (DisplayMode)actor->GetRepresentation();
1005 /////////////////////////////////////////////////////////////////
1006 /// \brief Get mesh object's display mode.
1007 /// \param uid Mesh object's study UID or IOR.
1008 /// \param viewUid View window UID (0 means currently active view
1009 /// window); Default: 0.
1010 /// \return Display mode (UndefinedMode if actor isn't found).
1011 /////////////////////////////////////////////////////////////////
1012 DisplayMode SMESH_Swig::displayMode(const char* uid, int viewUid)
1014 DisplayMode mode = UndefinedMode;
1018 _PTR(SObject) sobject = uid2object( uid );
1020 mode = ProcessEvent( new TGetDisplayModeEvent( sobject->GetID().c_str(), viewUid ) );
1025 /////////////////////////////////////////////////////////////////
1027 /////////////////////////////////////////////////////////////////
1028 class TSetDisplayModeEvent: public SALOME_Event
1035 TSetDisplayModeEvent( const char* uid, DisplayMode mode, int viewUid )
1036 : myUid( uid ), myMode( mode), myViewUid( viewUid ) {}
1038 virtual void Execute()
1040 SALOME_View* view = uid2wnd( myViewUid );
1041 SMESH_Actor* actor = actorFromView( view, myUid );
1042 if ( actor && myMode != UndefinedMode )
1044 actor->SetRepresentation( myMode );
1051 /////////////////////////////////////////////////////////////////
1052 /// \brief Set mesh object's display mode.
1053 /// \param uid Mesh object's study UID or IOR.
1054 /// \param mode Display mode.
1055 /// \param viewUid View window UID (0 means currently active view
1056 /// window); Default: 0.
1057 /////////////////////////////////////////////////////////////////
1058 void SMESH_Swig::setDisplayMode(const char* uid, DisplayMode mode, int viewUid)
1062 _PTR(SObject) sobject = uid2object( uid );
1064 ProcessVoidEvent( new TSetDisplayModeEvent( sobject->GetID().c_str(), mode, viewUid ) );
1067 /////////////////////////////////////////////////////////////////
1069 /////////////////////////////////////////////////////////////////
1070 class TGetShrinkModeEvent: public SALOME_Event
1073 typedef bool TResult;
1078 TGetShrinkModeEvent( const char* uid, int viewUid )
1079 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1081 virtual void Execute()
1083 SALOME_View* view = uid2wnd( myViewUid );
1084 SMESH_Actor* actor = actorFromView( view, myUid );
1086 myResult = actor->IsShrunk();
1090 /////////////////////////////////////////////////////////////////
1091 /// \brief Check if shrink mode is switched on.
1092 /// \param uid Mesh object's study UID or IOR.
1093 /// \param viewUid View window UID (0 means currently active view
1094 /// window); Default: 0.
1095 /// \return \c true if shrink mode is switched on;
1096 /// \c false otherwise.
1097 /////////////////////////////////////////////////////////////////
1098 bool SMESH_Swig::shrinkMode(const char* uid, int viewUid)
1100 bool shrinkMode = false;
1104 _PTR(SObject) sobject = uid2object( uid );
1106 shrinkMode = ProcessEvent( new TGetShrinkModeEvent( sobject->GetID().c_str(), viewUid ) );
1111 /////////////////////////////////////////////////////////////////
1113 /////////////////////////////////////////////////////////////////
1114 class TSetShrinkModeEvent: public SALOME_Event
1121 TSetShrinkModeEvent( const char* uid, bool shrink, int viewUid )
1122 : myUid( uid ), myShrink( shrink ), myViewUid( viewUid ) {}
1124 virtual void Execute()
1126 SALOME_View* view = uid2wnd( myViewUid );
1127 SMESH_Actor* actor = actorFromView( view, myUid );
1140 /////////////////////////////////////////////////////////////////
1141 /// \brief Switch shrink mode on/off.
1142 /// \param uid Mesh object's study UID or IOR.
1143 /// \param shrink \c true to switch shrink mode on;
1144 /// \c false otherwise.
1145 /// \param viewUid View window UID (0 means currently active view
1146 /// window); Default: 0.
1147 /////////////////////////////////////////////////////////////////
1148 void SMESH_Swig::setShrinkMode(const char* uid, bool shrink, int viewUid)
1152 _PTR(SObject) sobject = uid2object( uid );
1154 ProcessVoidEvent( new TSetShrinkModeEvent( sobject->GetID().c_str(), shrink, viewUid ) );
1157 /////////////////////////////////////////////////////////////////
1159 /////////////////////////////////////////////////////////////////
1160 class TGetOpacityEvent: public SALOME_Event
1163 typedef double TResult;
1168 TGetOpacityEvent( const char* uid, int viewUid )
1169 : myResult( 0 ), myUid( uid ), myViewUid( viewUid ) {}
1171 virtual void Execute()
1173 SALOME_View* view = uid2wnd( myViewUid );
1174 SMESH_Actor* actor = actorFromView( view, myUid );
1176 myResult = actor->GetOpacity();
1180 /////////////////////////////////////////////////////////////////
1181 /// \brief Get mesh object's opacity.
1182 /// \param uid Mesh object's study UID or IOR.
1183 /// \param viewUid View window UID (0 means currently active view
1184 /// window); Default: 0.
1185 /// \return Opacity value.
1186 /////////////////////////////////////////////////////////////////
1187 double SMESH_Swig::opacity(const char* uid, int viewUid)
1193 _PTR(SObject) sobject = uid2object( uid );
1195 opacity = ProcessEvent( new TGetOpacityEvent( sobject->GetID().c_str(), viewUid ) );
1200 /////////////////////////////////////////////////////////////////
1202 /////////////////////////////////////////////////////////////////
1203 class TSetOpacityEvent: public SALOME_Event
1210 TSetOpacityEvent( const char* uid, double opacity, int viewUid )
1211 : myUid( uid ), myOpacity( opacity ), myViewUid( viewUid ) {}
1213 virtual void Execute()
1215 SALOME_View* view = uid2wnd( myViewUid );
1216 SMESH_Actor* actor = actorFromView( view, myUid );
1219 actor->SetOpacity( myOpacity );
1226 /////////////////////////////////////////////////////////////////
1227 /// \brief Set mesh object's opacity.
1228 /// \param uid Mesh object's study UID or IOR.
1229 /// \param opacity Opacity value.
1230 /// \param viewUid View window UID (0 means currently active view
1231 /// window); Default: 0.
1232 /////////////////////////////////////////////////////////////////
1233 void SMESH_Swig::setOpacity(const char* uid, double opacity, int viewUid)
1237 _PTR(SObject) sobject = uid2object( uid );
1239 ProcessVoidEvent( new TSetOpacityEvent( sobject->GetID().c_str(), opacity, viewUid ) );
1242 /////////////////////////////////////////////////////////////////
1244 /////////////////////////////////////////////////////////////////
1245 class TGetOrientationEvent: public SALOME_Event
1248 typedef bool TResult;
1253 TGetOrientationEvent( const char* uid, int viewUid )
1254 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1256 virtual void Execute()
1258 SALOME_View* view = uid2wnd( myViewUid );
1259 SMESH_Actor* actor = actorFromView( view, myUid );
1261 myResult = actor->GetFacesOriented();
1265 /////////////////////////////////////////////////////////////////
1266 /// \brief Check if faces orientation vectors are shown.
1267 /// \param uid Mesh object's study UID or IOR.
1268 /// \param viewUid View window UID (0 means currently active view
1269 /// window); Default: 0.
1270 /// \return \c true if faces orientation vectors are shown;
1271 /// \c false otherwise.
1272 /////////////////////////////////////////////////////////////////
1273 bool SMESH_Swig::isOrientationShown(const char* uid, int viewUid)
1279 _PTR(SObject) sobject = uid2object( uid );
1281 shown = ProcessEvent( new TGetOrientationEvent( sobject->GetID().c_str(), viewUid ) );
1286 /////////////////////////////////////////////////////////////////
1288 /////////////////////////////////////////////////////////////////
1289 class TSetOrientationEvent: public SALOME_Event
1296 TSetOrientationEvent( const char* uid, bool shown, int viewUid )
1297 : myUid( uid ), myShown( shown ), myViewUid( viewUid ) {}
1299 virtual void Execute()
1301 SALOME_View* view = uid2wnd( myViewUid );
1302 SMESH_Actor* actor = actorFromView( view, myUid );
1305 actor->SetFacesOriented( myShown );
1312 /////////////////////////////////////////////////////////////////
1313 /// \brief Show/hide faces orientation vectors.
1314 /// \param uid Mesh object's study UID or IOR.
1315 /// \param shown \c true to show faces orientation vectors;
1316 /// \c false otherwise.
1317 /// \param viewUid View window UID (0 means currently active view
1318 /// window); Default: 0.
1319 /////////////////////////////////////////////////////////////////
1320 void SMESH_Swig::setOrientationShown(const char* uid, bool shown, int viewUid)
1324 _PTR(SObject) sobject = uid2object( uid );
1326 ProcessVoidEvent( new TSetOrientationEvent( sobject->GetID().c_str(), shown, viewUid ) );
1329 /////////////////////////////////////////////////////////////////
1331 /////////////////////////////////////////////////////////////////
1332 class TGetEntitiesEvent: public SALOME_Event
1335 typedef int TResult;
1340 TGetEntitiesEvent( const char* uid, int viewUid )
1341 : myResult( EntityNone ), myUid( uid ), myViewUid( viewUid ) {}
1343 virtual void Execute()
1345 SALOME_View* view = uid2wnd( myViewUid );
1346 SMESH_Actor* actor = actorFromView( view, myUid );
1348 myResult = actor->GetEntityMode();
1352 /////////////////////////////////////////////////////////////////
1353 /// \brief Get mesh object's visible entities.
1354 /// \param uid Mesh object's study UID or IOR.
1355 /// \param viewUid View window UID (0 means currently active view
1356 /// window); Default: 0.
1357 /// \return Enumerator describing entities being visible.
1358 /////////////////////////////////////////////////////////////////
1359 int SMESH_Swig::entitiesShown(const char* uid, int viewUid)
1361 int entities = EntityNone;
1365 _PTR(SObject) sobject = uid2object( uid );
1367 entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1372 /////////////////////////////////////////////////////////////////
1374 /////////////////////////////////////////////////////////////////
1375 class TSetEntitiesEvent: public SALOME_Event
1382 TSetEntitiesEvent( const char* uid, int entities, int viewUid )
1383 : myUid( uid ), myEntities( entities ), myViewUid( viewUid ) {}
1385 virtual void Execute()
1387 SALOME_View* view = uid2wnd( myViewUid );
1388 SMESH_Actor* actor = actorFromView( view, myUid );
1391 actor->SetEntityMode( myEntities );
1398 /////////////////////////////////////////////////////////////////
1399 /// \brief Set mesh object's visible entities.
1400 /// \param uid Mesh object's study UID or IOR.
1401 /// \param entities Enumerator describing entities to be shown.
1402 /// \param viewUid View window UID (0 means currently active view
1403 /// window); Default: 0.
1404 /////////////////////////////////////////////////////////////////
1405 void SMESH_Swig::setEntitiesShown(const char* uid, int entities, int viewUid)
1409 _PTR(SObject) sobject = uid2object( uid );
1411 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1414 /////////////////////////////////////////////////////////////////
1415 /// \brief Check if given mesh object's entity is shown.
1416 /// \param uid Mesh object's study UID or IOR.
1417 /// \param entity Mesh entity.
1418 /// \param viewUid View window UID (0 means currently active view
1419 /// window); Default: 0.
1420 /// \return \c true if entity is shown; \c false otherwise.
1421 /////////////////////////////////////////////////////////////////
1422 bool SMESH_Swig::isEntityShown(const char* uid, EntityMode entity, int viewUid)
1428 _PTR(SObject) sobject = uid2object( uid );
1431 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1432 shown = (bool)( entities & entity );
1438 /////////////////////////////////////////////////////////////////
1439 /// \brief Show/hide entity for given mesh object.
1440 /// \param uid Mesh object's study UID or IOR.
1441 /// \param entity Mesh entity.
1442 /// \param show Visibility status.
1443 /// \param viewUid View window UID (0 means currently active view
1444 /// window); Default: 0.
1445 /////////////////////////////////////////////////////////////////
1446 void SMESH_Swig::setEntityShown(const char* uid, EntityMode entity, bool show, int viewUid)
1450 _PTR(SObject) sobject = uid2object( uid );
1453 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1457 entities &= ~entity;
1458 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1462 /////////////////////////////////////////////////////////////////
1463 /// \brief Initialize %SMESH GUI Python interface.
1464 /// \deprecated Interface is initialized automatically.
1465 /////////////////////////////////////////////////////////////////
1466 void SMESH_Swig::Init()
1468 deprecated("SMESH_Swig::Init");
1469 // does nothing; initialization is done automatically.
1472 /////////////////////////////////////////////////////////////////
1473 /// \brief Publish mesh in the active study.
1474 /// \deprecated Publishing is done automatically.
1475 /// \param ior IOR of the mesh.
1476 /// \param name Name of the mesh (optional).
1477 /// \return UID of the data object.
1478 /////////////////////////////////////////////////////////////////
1479 const char* SMESH_Swig::AddNewMesh(const char* ior, const char* name)
1481 deprecated("SMESH_Swig::AddNewMesh", "SMESH_Swig::publish");
1482 return publish( ior, name );
1485 /////////////////////////////////////////////////////////////////
1486 /// \brief Publish hypothesis in the active study.
1487 /// \deprecated Publishing is done automatically.
1488 /// \param ior IOR of the hypothesis.
1489 /// \param name Name of the hypothesis (optional).
1490 /// \return UID of the data object.
1491 /////////////////////////////////////////////////////////////////
1492 const char* SMESH_Swig::AddNewHypothesis(const char* ior, const char* name)
1494 deprecated("SMESH_Swig::AddNewHypothesis", "SMESH_Swig::publish");
1495 return publish( ior, name );
1498 /////////////////////////////////////////////////////////////////
1499 /// \brief Publish algorithm in the active study.
1500 /// \deprecated Publishing is done automatically.
1501 /// \param ior IOR of the algorithm.
1502 /// \param name Name of the algorithm (optional).
1503 /// \return UID of the data object.
1504 /////////////////////////////////////////////////////////////////
1505 const char* SMESH_Swig::AddNewAlgorithm(const char* ior, const char* name)
1507 deprecated("SMESH_Swig::AddNewAlgorithm", "SMESH_Swig::publish");
1508 return publish( ior, name );
1511 /////////////////////////////////////////////////////////////////
1512 /// \deprecated Publishing is done automatically.
1513 /// \deprecated Synonym of AddNewAlgorithm().
1514 /// \param ior IOR of the algorithm.
1515 /// \param name Name of the algorithm (optional).
1516 /// \return UID of the data object.
1517 /////////////////////////////////////////////////////////////////
1518 const char* SMESH_Swig::AddNewAlgorithms(const char* ior, const char* name)
1520 deprecated("SMESH_Swig::AddNewAlgorithms", "SMESH_Swig::publish");
1521 return publish( ior, name );
1524 /////////////////////////////////////////////////////////////////
1525 /// \brief Add reference on a shape for mesh in a study.
1526 /// \deprecated Publishing is done automatically.
1527 /// \param shapeUid GEOM shape's study UID (not used).
1528 /// \param meshUid Mesh's study UID (not used).
1529 /////////////////////////////////////////////////////////////////
1530 void SMESH_Swig::SetShape(const char* /*shapeUid*/, const char* /*meshUid*/)
1532 deprecated("SMESH_Swig::SetShape", "SMESH_Swig::publish");
1533 // does nothing: publishing is done automatically
1536 /////////////////////////////////////////////////////////////////
1537 /// \brief Assign hypothesis to mesh or sub-mesh.
1538 /// \deprecated Publishing is done automatically.
1539 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1540 /// \param hypoUID Hypothesis's study UID (not used).
1541 /////////////////////////////////////////////////////////////////
1542 void SMESH_Swig::SetHypothesis(const char* /*meshUid*/, const char* /*hypoUID*/)
1544 deprecated("SMESH_Swig::SetHypothesis", "SMESH_Swig::publish");
1545 // does nothing: publishing is done automatically
1548 /////////////////////////////////////////////////////////////////
1549 /// \brief Assign algorithm to mesh or sub-mesh.
1550 /// \deprecated Publishing is done automatically.
1551 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1552 /// \param algoUID Algorithm's study UID (not used).
1553 /////////////////////////////////////////////////////////////////
1554 void SMESH_Swig::SetAlgorithms(const char* /*meshUid*/, const char* /*algoUID*/)
1556 deprecated("SMESH_Swig::SetAlgorithms", "SMESH_Swig::publish");
1557 // does nothing: publishing is done automatically
1560 /////////////////////////////////////////////////////////////////
1561 /// \brief Anassign hypothesis or algorithm from mesh or sub-mesh.
1562 /// \deprecated Unpublishing is done automatically.
1563 /// \param uid Hypothesis's or algorithm's study UID (not used).
1564 /////////////////////////////////////////////////////////////////
1565 void SMESH_Swig::UnSetHypothesis(const char* /*uid*/)
1567 deprecated("SMESH_Swig::UnSetHypothesis");
1568 // does nothing: unpublishing is done automatically
1571 /////////////////////////////////////////////////////////////////
1572 /// \brief Publish sub-mesh in the active study.
1573 /// \deprecated Publishing is done automatically.
1574 /// \param meshUid Parent mesh's study UID (not used).
1575 /// \param ior IOR of the sub-mesh.
1576 /// \param shapeType GEOM shape's type (not used).
1577 /// \param name Name of the sub-mesh (optional).
1578 /// \return UID of the data object.
1579 /////////////////////////////////////////////////////////////////
1580 const char* SMESH_Swig::AddSubMesh(const char* /*meshUid*/,
1585 deprecated("SMESH_Swig::AddSubMesh", "SMESH_Swig::publish");
1586 return publish( ior, name );
1589 /////////////////////////////////////////////////////////////////
1590 /// \brief Publish sub-mesh in the active study.
1591 /// \deprecated Publishing is done automatically.
1592 /// \param meshUid Parent mesh's study UID (not used).
1593 /// \param shapeUid GEOM shape's study UID (not used).
1594 /// \param ior IOR of the sub-mesh.
1595 /// \param shapeType GEOM shape's type (not used).
1596 /// \param name Name of the sub-mesh (optional).
1597 /// \return UID of the data object.
1598 /////////////////////////////////////////////////////////////////
1599 const char* SMESH_Swig::AddSubMeshOnShape(const char* /*meshUid*/,
1600 const char* /*shapeUid*/,
1605 deprecated("SMESH_Swig::AddSubMeshOnShape", "SMESH_Swig::publish");
1606 return publish( ior, name );
1609 /////////////////////////////////////////////////////////////////
1610 /// \brief Set new study name of given object.
1611 /// \deprecated Use rename() method.
1612 /// \param uid Object's study UID or IOR.
1613 /// \param name New name of the object.
1614 /////////////////////////////////////////////////////////////////
1615 void SMESH_Swig::SetName(const char* uid, const char* name)
1617 deprecated("SMESH_Swig::SetName", "SMESH_Swig::rename");
1618 rename( uid, name );
1621 /////////////////////////////////////////////////////////////////
1622 /// \brief Set mesh icon according to compute status
1623 /// \deprecated Publishing is done automatically.
1624 /// \param meshUid Mesh's study UID (not used).
1625 /// \param isComputed Flag pointing that mesh is computed or no
1627 /// \param isEmpty Flag pointing that mesh is empty or no
1629 /////////////////////////////////////////////////////////////////
1630 void SMESH_Swig::SetMeshIcon(const char* /*meshUid*/,
1631 const bool /*isComputed*/,
1632 const bool /*isEmpty*/)
1634 deprecated("SMESH_Swig::SetMeshIcon", "SMESH_Swig::publish");
1635 // does nothing: publishing is done automatically
1638 /////////////////////////////////////////////////////////////////
1639 /// Display mesh in the currently active view window.
1640 /// \deprecated Use display() method.
1641 /// \param meshUid Mesh's study UID.
1642 /////////////////////////////////////////////////////////////////
1643 void SMESH_Swig::CreateAndDisplayActor(const char* meshUid)
1645 deprecated("SMESH_Swig::CreateAndDisplayActor", "SMESH_Swig::display");
1649 /////////////////////////////////////////////////////////////////
1650 /// Erase mesh in the view window(s).
1651 /// \deprecated Use erase() method.
1652 /// \param meshUid Mesh's study UID.
1653 /// \param allViewers If \c true, mesh is removed from all views.
1654 /// Default: \c false.
1655 /////////////////////////////////////////////////////////////////
1656 void SMESH_Swig::EraseActor(const char* meshUid, const bool allViewers)
1658 deprecated("SMESH_Swig::EraseActor", "SMESH_Swig::erase");
1659 erase( meshUid, allViewers ? -1 : 0 );
1662 /////////////////////////////////////////////////////////////////
1663 /// Update mesh object.
1664 /// \deprecated Use update() method.
1665 /// \param meshUid Mesh's study UID.
1666 /////////////////////////////////////////////////////////////////
1667 void SMESH_Swig::UpdateActor(const char* meshUid)
1669 deprecated("SMESH_Swig::UpdateActor", "SMESH_Swig::update");
1673 /////////////////////////////////////////////////////////////////
1674 /// Get mesh object's properties.
1675 /// \deprecated Use properties() method.
1676 /// \param meshUid Mesh's study UID.
1677 /// \param viewUid View window UID (0 means currently active view
1678 /// window). Default: 0.
1679 /////////////////////////////////////////////////////////////////
1680 actorAspect SMESH_Swig::GetActorAspect(const char* meshUid, int viewUid)
1682 deprecated("SMESH_Swig::GetActorAspect", "SMESH_Swig::properties");
1683 return properties( meshUid, viewUid );
1686 /////////////////////////////////////////////////////////////////
1687 /// Set mesh object's properties.
1688 /// \deprecated Use setProperties() method.
1689 /// \param meshUid Mesh's study UID.
1690 /// \param viewUid View window UID (0 means currently active view
1691 /// window). Default: 0.
1692 /////////////////////////////////////////////////////////////////
1693 void SMESH_Swig::SetActorAspect(const actorAspect& aspect, const char* meshUid, int viewUid)
1695 deprecated("SMESH_Swig::SetActorAspect", "SMESH_Swig::setProperties");
1696 setProperties( meshUid, aspect, viewUid );
1699 /////////////////////////////////////////////////////////////////
1701 /////////////////////////////////////////////////////////////////
1702 class TSelectListEvent: public SALOME_Event
1705 std::vector<int> myIds;
1709 TSelectListEvent(const char* uid, std::vector<int> ids, bool append)
1710 : myUid( uid ), myIds( ids ), myIsAppend( append )
1713 virtual void Execute()
1715 LightApp_SelectionMgr* selMgr = 0;
1716 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1718 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1723 selMgr->clearFilters();
1725 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1729 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1731 if ( !actor || !actor->hasIO() )
1734 Handle(SALOME_InteractiveObject) io = actor->getIO();
1737 selMgr->setSelectedObjects( ios, false );
1739 if ( vw->SelectionMode() == ActorSelection )
1742 TColStd_MapOfInteger idMap;
1743 std::vector<int>::const_iterator it;
1744 for ( it = myIds.begin(); it != myIds.end(); ++it )
1749 // Set new selection
1750 SVTK_Selector* selector = vw->GetSelector();
1751 selector->AddOrRemoveIndex( io, idMap, myIsAppend );
1752 vw->highlight( io, true, true );
1753 vw->GetInteractor()->onEmitSelectionChanged();
1757 /////////////////////////////////////////////////////////////////
1758 /// \brief Select elements of the mesh, sub-mesh or group.
1759 /// \param uid Mesh object's study UID or IOR.
1760 /// \param ids List of mesh elements.
1761 /// \param append If \c true, elements are added to current
1762 /// selection; otherwise, previous selection is
1764 /////////////////////////////////////////////////////////////////
1765 void SMESH_Swig::select(const char* uid, std::vector<int> ids, bool append)
1769 _PTR(SObject) sobject = uid2object( uid );
1771 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1774 /////////////////////////////////////////////////////////////////
1775 /// \brief Select element of the mesh, sub-mesh or group.
1776 /// \param uid Mesh object's study UID or IOR.
1777 /// \param id Mesh element.
1778 /// \param append If \c true, element is added to current
1779 /// selection; otherwise, previous selection is
1781 /////////////////////////////////////////////////////////////////
1782 void SMESH_Swig::select(const char* uid, int id, bool append)
1786 std::vector<int> ids;
1787 ids.push_back( id );
1789 _PTR(SObject) sobject = uid2object( uid );
1791 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1794 /////////////////////////////////////////////////////////////////
1796 /////////////////////////////////////////////////////////////////
1797 class TSelectListOfPairEvent: public SALOME_Event
1800 std::vector<std::pair<int, int> > myIds;
1804 TSelectListOfPairEvent(const char* uid, std::vector<std::pair<int, int> > ids, bool append)
1805 : myUid( uid ), myIds( ids ), myIsAppend( append )
1808 virtual void Execute()
1810 LightApp_SelectionMgr* selMgr = 0;
1811 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1813 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1818 selMgr->clearFilters();
1820 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1824 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1826 if ( !actor || !actor->hasIO() )
1829 Handle(SALOME_InteractiveObject) io = actor->getIO();
1832 selMgr->setSelectedObjects( ios, false );
1834 if ( vw->SelectionMode() != EdgeOfCellSelection )
1837 SVTK_IndexedMapOfIds idMap;
1838 std::vector<std::pair<int, int> >::const_iterator it;
1839 for ( it = myIds.begin(); it != myIds.end(); ++it )
1841 std::vector<int> pair;
1842 pair.push_back( (*it).first );
1843 pair.push_back( (*it).second );
1847 // Set new selection
1848 SVTK_Selector* selector = vw->GetSelector();
1849 selector->AddOrRemoveCompositeIndex( io, idMap, myIsAppend );
1850 vw->highlight( io, true, true );
1851 vw->GetInteractor()->onEmitSelectionChanged();
1855 /////////////////////////////////////////////////////////////////
1856 /// \brief Select pseudo-edges (specified by two nodes)
1857 /// of the mesh, sub-mesh or group.
1858 /// \param uid Mesh object's study UID or IOR.
1859 /// \param ids List of pairs containing two nodes IDs.
1860 /// \param append If \c true, pseudo-edges are added to current
1861 /// selection; otherwise, previous selection is
1863 /////////////////////////////////////////////////////////////////
1864 void SMESH_Swig::select(const char* uid, std::vector<std::pair<int,int> > ids, bool append)
1868 _PTR(SObject) sobject = uid2object( uid );
1870 ProcessVoidEvent( new TSelectListOfPairEvent( sobject->GetID().c_str(), ids, append ) );
1873 /////////////////////////////////////////////////////////////////
1875 /////////////////////////////////////////////////////////////////
1876 class TGetSelectionModeEvent: public SALOME_Event
1879 typedef SelectionMode TResult;
1883 TGetSelectionModeEvent( int viewUid ) :
1884 myResult( Undefined ), myViewUid( viewUid ) {}
1886 virtual void Execute()
1888 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1891 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1893 myResult = (SelectionMode)vw->SelectionMode();
1898 /////////////////////////////////////////////////////////////////
1899 /// \brief Get selection mode of view window.
1900 /// \param viewUid View window UID (0 means currently active view
1901 /// window); Default: 0.
1902 /// \return Current selection mode.
1903 /////////////////////////////////////////////////////////////////
1904 SelectionMode SMESH_Swig::getSelectionMode(int viewUid)
1907 return ProcessEvent( new TGetSelectionModeEvent( viewUid ) );
1910 /////////////////////////////////////////////////////////////////
1912 /////////////////////////////////////////////////////////////////
1913 class TSetSelectionModeEvent: public SALOME_Event
1915 SelectionMode mySelectionMode;
1919 TSetSelectionModeEvent( const SelectionMode selectionMode, int viewUid )
1920 : mySelectionMode( selectionMode ), myViewUid( viewUid )
1923 virtual void Execute()
1925 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1928 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1931 SelectionMode previousMode = (SelectionMode)vw->SelectionMode();
1932 bool switchPointMode = ( previousMode == Node && mySelectionMode != Node ) ||
1933 ( previousMode != Node && mySelectionMode == Node );
1934 if ( switchPointMode )
1936 vtkRenderer* renderer = vw->getRenderer();
1937 VTK::ActorCollectionCopy actors( renderer->GetActors() );
1938 vtkActorCollection* collection = actors.GetActors();
1939 collection->InitTraversal();
1940 while ( vtkActor* vtkActor = collection->GetNextActor() )
1942 if ( SMESH_Actor* actor = dynamic_cast<SMESH_Actor*>( vtkActor ) )
1944 if ( actor->GetVisibility() )
1945 actor->SetPointRepresentation( mySelectionMode == Node );
1949 vw->SetSelectionMode( mySelectionMode );
1955 /////////////////////////////////////////////////////////////////
1956 /// \brief Set selection mode to view window.
1957 /// \param viewUid View window UID (0 means currently active view
1958 /// window); Default: 0.
1959 /// \param mode Selection mode.
1960 /////////////////////////////////////////////////////////////////
1961 void SMESH_Swig::setSelectionMode(SelectionMode mode, int viewUid)
1964 ProcessVoidEvent( new TSetSelectionModeEvent( mode, viewUid ) );
1967 /////////////////////////////////////////////////////////////////
1969 /////////////////////////////////////////////////////////////////
1970 class TGetSelectedEvent: public SALOME_Event
1973 typedef std::vector<int> TResult;
1977 TGetSelectedEvent( const char* uid )
1980 virtual void Execute()
1982 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1986 SVTK_Selector* selector = vw->GetSelector();
1990 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1991 if ( !actor || !actor->hasIO() )
1994 TColStd_IndexedMapOfInteger idMap;
1995 selector->GetIndex( actor->getIO(), idMap );
1997 for ( int i = 1; i <= idMap.Extent(); i++ )
1998 myResult.push_back( idMap( i ) );
2002 /////////////////////////////////////////////////////////////////
2003 /// \brief Get selected elements of the mesh, sub-mesh or group.
2004 /// \param uid Mesh object's study UID or IOR.
2005 /// \return List of selected mesh elements.
2006 /////////////////////////////////////////////////////////////////
2007 std::vector<int> SMESH_Swig::getSelected(const char* uid)
2009 std::vector<int> ids;
2013 _PTR(SObject) sobject = uid2object( uid );
2015 ids = ProcessEvent( new TGetSelectedEvent( sobject->GetID().c_str() ) );
2020 /////////////////////////////////////////////////////////////////
2022 /////////////////////////////////////////////////////////////////
2023 class TGetSelectedPairEvent : public SALOME_Event
2026 typedef std::vector<std::pair<int, int> > TResult;
2030 TGetSelectedPairEvent( const char* uid )
2033 virtual void Execute()
2035 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2039 if ( vw->SelectionMode() != EdgeOfCellSelection )
2042 SVTK_Selector* selector = vw->GetSelector();
2046 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2047 if ( !actor || !actor->hasIO() )
2050 SVTK_IndexedMapOfIds idMap;
2051 selector->GetCompositeIndex( actor->getIO(), idMap );
2053 for ( int i = 1; i <= idMap.Extent(); i++ ) {
2054 myResult.push_back( std::make_pair( (int)idMap(i)[0], (int)idMap(i)[1]) );
2059 /////////////////////////////////////////////////////////////////
2060 /// \brief Get selected pseudo-edges (specified by two nodes)
2061 /// of the mesh, sub-mesh or group.
2062 /// \param uid Mesh object's study UID or IOR.
2063 /// \param ids List of pairs containing two nodes IDs.
2064 /// \param append If \c true, pseudo-edges are added to current
2065 /// selection; otherwise, previous selection is
2067 /////////////////////////////////////////////////////////////////
2068 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell(const char* uid)
2070 std::vector<std::pair<int,int> > pairs;
2074 _PTR(SObject) sobject = uid2object( uid );
2076 pairs = ProcessEvent( new TGetSelectedPairEvent( sobject->GetID().c_str() ) );