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 studyId Study UID.
137 /// \param uid Object's study UID or IOR.
138 /// \return Pointer to study object (null object if it isn't
140 ///////////////////////////////////////////////////////////////
141 _PTR(SObject) uid2object(int studyId, const std::string& uid)
143 _PTR(SObject) sobject;
146 _PTR(Study) study = SalomeApp_Application::studyMgr()->GetStudyByID( studyId );
149 sobject = study->FindObjectID( uid );
151 sobject = study->FindObjectIOR( uid );
157 ///////////////////////////////////////////////////////////////
159 /// \brief Get view window by its identifier.
160 /// \param uid Window's identifier.
161 /// \return Pointer to the view window (0 if it isn't found).
162 ///////////////////////////////////////////////////////////////
163 SALOME_View* uid2wnd(int uid, bool create = false)
165 SALOME_View* window = 0;
167 SUIT_Session* session = SUIT_Session::session();
168 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
173 ViewManagerList vms = app->viewManagers();
174 for ( int i = 0; i < vms.count() && !window; i++ )
176 SUIT_ViewManager* vm = vms[i];
177 QVector<SUIT_ViewWindow*> vws = vm->getViews();
178 for ( int j = 0; j < vws.count() && !window; j++)
180 SUIT_ViewWindow* vw = vws[0];
181 if ( uid == vw->getId() )
182 window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
188 SUIT_ViewManager* vm = app->getViewManager( SVTK_Viewer::Type(), create );
191 window = dynamic_cast<SALOME_View*>( vm->getViewModel() );
198 ///////////////////////////////////////////////////////////////
200 /// \brief Get all view windows.
201 /// \return List of view windows.
202 ///////////////////////////////////////////////////////////////
203 QList<SALOME_View*> windows()
205 QList<SALOME_View*> views;
206 SUIT_Session* session = SUIT_Session::session();
207 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
210 ViewManagerList vms = app->viewManagers();
211 foreach( SUIT_ViewManager* vm, vms )
213 if ( vm && vm->getType() == SVTK_Viewer::Type() )
215 SALOME_View* view = dynamic_cast<SALOME_View*>( vm->getViewModel() );
224 ///////////////////////////////////////////////////////////////
226 /// \brief Get mesh actor from view.
227 /// \param view Pointer to the view window.
228 /// \param uid Mesh object's study UID.
229 /// \return Mesh actor (0 if it isn't found).
230 ///////////////////////////////////////////////////////////////
231 SMESH_Actor* actorFromView(SALOME_View* view, const char* uid)
233 SMESH_Actor* actor = 0;
234 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( view );
237 SUIT_ViewWindow* vw = model->getViewManager()->getActiveView();
240 actor = SMESH::FindActorByEntry( vw, uid );
246 ///////////////////////////////////////////////////////////////
248 /// \brief Get mesh object's visual properties.
249 /// \param view Pointer to the view window.
250 /// \param uid Mesh object's study UID.
251 /// \return Properties data structure.
252 ///////////////////////////////////////////////////////////////
253 Properties properties(SALOME_View* view, const char* uid)
256 SMESH_Actor* actor = actorFromView( view, uid );
259 actor->GetNodeColor( props.nodeColor.r,
262 props.markerType = actor->GetMarkerType();
263 props.markerScale = actor->GetMarkerScale();
265 actor->GetEdgeColor( props.edgeColor.r,
268 props.edgeWidth = qMax( (int)actor->GetLineWidth(), 1 );
270 actor->GetSufaceColor( props.surfaceColor.r,
271 props.surfaceColor.g,
272 props.surfaceColor.b,
273 props.surfaceColor.delta );
275 actor->GetVolumeColor( props.volumeColor.r,
278 props.volumeColor.delta );
280 actor->Get0DColor( props.elem0dColor.r,
282 props.elem0dColor.b );
283 props.elem0dSize = qMax( (int)actor->Get0DSize(), 1 );
285 actor->GetBallColor( props.ballColor.r,
288 props.ballScale = qMax( actor->GetBallScale(), 1e-2 );
290 actor->GetOutlineColor( props.outlineColor.r,
291 props.outlineColor.g,
292 props.outlineColor.b );
293 props.outlineWidth = qMax( (int)actor->GetOutlineWidth(), 1 );
295 actor->GetFacesOrientationColor( props.orientationColor.r,
296 props.orientationColor.g,
297 props.orientationColor.b );
298 props.orientationScale = actor->GetFacesOrientationScale();
299 props.orientation3d = actor->GetFacesOrientation3DVectors();
301 props.shrinkFactor = actor->GetShrinkFactor();
303 props.opacity = actor->GetOpacity();
308 ///////////////////////////////////////////////////////////////
310 /// \brief Set mesh object's visual properties.
311 /// \param view Pointer to the view window.
312 /// \param uid Mesh object's study UID.
313 /// \param props Properties data structure.
314 ///////////////////////////////////////////////////////////////
315 void setProperties(SALOME_View* view, const char* uid, const Properties& props)
317 SMESH_Actor* actor = actorFromView( view, uid );
320 actor->SetNodeColor( props.nodeColor.r,
323 if ( props.markerType != VTK::MT_USER )
324 actor->SetMarkerStd( props.markerType, props.markerScale );
326 actor->SetEdgeColor( props.edgeColor.r,
329 actor->SetLineWidth( qMax( (double)props.edgeWidth, 1. ) );
331 actor->SetSufaceColor( props.surfaceColor.r,
332 props.surfaceColor.g,
333 props.surfaceColor.b,
334 props.surfaceColor.delta );
336 actor->SetVolumeColor( props.volumeColor.r,
339 props.volumeColor.delta );
341 actor->Set0DColor( props.elem0dColor.r,
343 props.elem0dColor.b );
344 actor->Set0DSize( qMax( (double)props.elem0dSize, 1. ) );
346 actor->SetBallColor( props.ballColor.r,
349 actor->SetBallScale( qMax( props.ballScale, 1e-2 ) );
351 actor->SetOutlineColor( props.outlineColor.r,
352 props.outlineColor.g,
353 props.outlineColor.b );
354 actor->SetOutlineWidth( qMax( (double)props.outlineWidth, 1. ) );
356 actor->SetFacesOrientationColor( props.orientationColor.r,
357 props.orientationColor.g,
358 props.orientationColor.b );
359 actor->SetFacesOrientationScale( props.orientationScale );
360 actor->SetFacesOrientation3DVectors( props.orientation3d );
362 actor->SetShrinkFactor( props.shrinkFactor );
364 actor->SetOpacity( props.opacity );
369 } // end of anonymous namespace
371 /////////////////////////////////////////////////////////////////
373 /// \brief Enumeration for mesh entities.
374 /// \var EntityMode Entity0d
375 /// \brief 0D elements.
376 /// \var EntityMode EntityEdges
378 /// \var EntityMode EntityFaces
380 /// \var EntityMode EntityVolumes
382 /// \var EntityMode EntityBalls
383 /// \brief Ball elements.
384 /// \var EntityMode EntityAll
385 /// \brief All elements.
386 /////////////////////////////////////////////////////////////////
388 /////////////////////////////////////////////////////////////////
389 /// \enum SelectionMode
390 /// \brief Selection mode.
391 /// \var SelectionMode Undefined
392 /// \brief Undefined selection mode.
393 /// \var SelectionMode Node
394 /// \brief Selection of mesh nodes.
395 /// \var SelectionMode Cell
396 /// \brief Selection of any mesh cells.
397 /// \var SelectionMode EdgeOfCell
398 /// \brief Selection of pseudo-edges specified by couple of nodes.
399 /// \var SelectionMode Edge
400 /// \brief Selection of edges.
401 /// \var SelectionMode Face
402 /// \brief Selection of faces.
403 /// \var SelectionMode Volume
404 /// \brief Selection of volumes
405 /// \var SelectionMode Actor
406 /// \brief Selection of whole actors (meshes, sub-meshes, groups).
407 /// \var SelectionMode Elem0D
408 /// \brief Selection of 0D elements.
409 /// \var SelectionMode Ball
410 /// \brief Selection of ball ellements.
411 /////////////////////////////////////////////////////////////////
413 /////////////////////////////////////////////////////////////////
414 /// \enum DisplayMode
415 /// \brief Display mode.
416 /// \var DisplayMode UndefinedMode
417 /// \brief Undefined display mode.
418 /// \var DisplayMode PointMode
419 /// \brief Point representation.
420 /// \var DisplayMode EdgeMode
421 /// \brief Wireframe representation.
422 /// \var DisplayMode SurfaceMode
423 /// \brief Surface representation.
424 /////////////////////////////////////////////////////////////////
426 /////////////////////////////////////////////////////////////////
427 /// \struct ColorData
428 /// \brief Color data, in RGBf format.
429 /// \var ColorData::r
430 /// \brief Red color's component (0.0:1.0).
431 /// \var ColorData::g
432 /// \brief Green color's component (0.0:1.0).
433 /// \var ColorData::b
434 /// \brief Blue color's component (0.0:1.0).
435 /////////////////////////////////////////////////////////////////
437 /////////////////////////////////////////////////////////////////
438 /// \brief Constructor.
439 /////////////////////////////////////////////////////////////////
440 ColorData::ColorData()
441 : r( 0 ), g( 0 ), b( 0 )
444 /////////////////////////////////////////////////////////////////
445 /// \struct BicolorData
446 /// \brief Bi-color data, in RGBf format.
447 /// \var BicolorData::r
448 /// \brief Red color's component (0.0:1.0).
449 /// \var BicolorData::g
450 /// \brief Green color's component (0.0:1.0).
451 /// \var BicolorData::b
452 /// \brief Blue color's component (0.0:1.0).
453 /// \var BicolorData::delta
454 /// \brief Shift for backface color (-100:100).
455 /////////////////////////////////////////////////////////////////
457 /////////////////////////////////////////////////////////////////
458 /// \brief Constructor.
459 /////////////////////////////////////////////////////////////////
460 BicolorData::BicolorData()
461 : r( 0 ), g( 0 ), b( 0 ), delta( 0 )
464 /////////////////////////////////////////////////////////////////
465 /// \struct Properties
466 /// \brief Mesh object presentation's properties.
467 /// \var Properties::nodeColor
468 /// \brief Node color.
469 /// \var Properties::markerType
470 /// \brief Node standard marker type.
471 /// \var Properties::markerScale
472 /// \brief Node scale factor.
473 /// \var Properties::edgeColor
474 /// \brief Edges color.
475 /// \var Properties::edgeWidth
476 /// \brief Edges width.
477 /// \var Properties::surfaceColor
478 /// \brief Faces color.
479 /// \var Properties::volumeColor
480 /// \brief Volumes color.
481 /// \var Properties::elem0dColor
482 /// \brief 0D elements color.
483 /// \var Properties::elem0dSize
484 /// \brief 0D elements size.
485 /// \var Properties::ballColor
486 /// \brief Ball elements color.
487 /// \var Properties::ballScale
488 /// \brief Ball elements scale factor.
489 /// \var Properties::outlineColor
490 /// \brief Outlines color.
491 /// \var Properties::outlineWidth
492 /// \brief Outlines width.
493 /// \var Properties::orientationColor
494 /// \brief Face orientation vectors color.
495 /// \var Properties::orientationScale
496 /// \brief Face orientation vectors scale factor.
497 /// \var Properties::orientation3d
498 /// \brief Face orientation vectors 3d flag.
499 /// \var Properties::shrinkFactor
500 /// \brief Shrink coefficient.
501 /// \var Properties::opacity
503 /////////////////////////////////////////////////////////////////
505 /////////////////////////////////////////////////////////////////
506 /// \brief Constructor.
507 /////////////////////////////////////////////////////////////////
508 Properties::Properties()
509 : markerType( VTK::MT_NONE ), markerScale( VTK::MS_NONE ),
510 edgeWidth( 1 ), elem0dSize( 1 ), ballScale( 1 ), outlineWidth( 1 ),
511 orientationScale( 0 ), orientation3d( false ), shrinkFactor( 0 ),
515 /////////////////////////////////////////////////////////////////
516 /// \typedef nodeColorStruct
517 /// \deprecated Use ColorData instead.
518 /// \typedef edgeColorStruct
519 /// \deprecated Use ColorData instead.
520 /// \typedef surfaceColorStruct
521 /// \deprecated Use BicolorData instead.
522 /// \typedef volumeColorStruct
523 /// \deprecated Use BicolorData instead.
524 /// \typedef actorAspect
525 /// \deprecated Use Properties instead.
526 /////////////////////////////////////////////////////////////////
528 /////////////////////////////////////////////////////////////////
529 /// \class SMESH_Swig
530 /// \brief %SMESH GUI Python interface.
531 /////////////////////////////////////////////////////////////////
533 /////////////////////////////////////////////////////////////////
534 /// \brief Constructor.
535 /////////////////////////////////////////////////////////////////
536 SMESH_Swig::SMESH_Swig()
537 : myCachedStudyId( 0 )
542 /////////////////////////////////////////////////////////////////
543 /// \brief Destructor.
544 /////////////////////////////////////////////////////////////////
545 SMESH_Swig::~SMESH_Swig()
549 /////////////////////////////////////////////////////////////////
551 /// \brief Initialize interface.
552 /////////////////////////////////////////////////////////////////
553 void SMESH_Swig::init()
555 class TInitEvent: public SALOME_Event
559 virtual void Execute()
561 SUIT_Session* session = SUIT_Session::session();
562 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
564 if ( !SMESHGUI::GetSMESHGUI() )
565 app->loadModule( "Mesh" );
569 // load SMESH GUI if it's not yet loaded
570 ProcessVoidEvent( new TInitEvent() );
573 std::vector<std::string> studies = SalomeApp_Application::studyMgr()->GetOpenStudies();
574 if ( studies.size() > 0 )
576 _PTR(Study) study = SalomeApp_Application::studyMgr()->GetStudyByName( studies[0] );
577 int studyId = study->StudyId();
578 if ( myCachedStudyId != studyId )
580 myCachedStudyId = studyId;
581 SMESHGUI::GetSMESHGen()->SetCurrentStudy( _CAST(Study, study)->GetStudy() );
590 /////////////////////////////////////////////////////////////////
591 /// \brief Publish object.
592 /// \param ior IOR of the mesh object to publish.
593 /// \param name Study name of the object; if not given,
594 /// name is assigned automatically.
595 /// \return UID of the data object.
596 /////////////////////////////////////////////////////////////////
597 const char* SMESH_Swig::publish(const char* ior, const char* name)
603 if ( myCachedStudyId > 0 )
605 _PTR(Study) study = SalomeApp_Application::studyMgr()->GetStudyByID( myCachedStudyId );
606 CORBA::Object_var object = string2object( ior );
607 if ( study && !CORBA::is_nil( object ) )
609 SALOMEDS::SObject_var sobject =
610 SMESHGUI::GetSMESHGen()->PublishInStudy( _CAST(Study, study)->GetStudy(),
611 SALOMEDS::SObject::_nil(),
614 if ( !CORBA::is_nil( sobject ) )
616 uid = sobject->GetID();
618 sobject->UnRegister();
622 return strdup( uid.c_str() );
625 /////////////////////////////////////////////////////////////////
626 /// \brief Set new study name of given object.
627 /// \param uid Object's study UID or IOR.
628 /// \param name New name of the object.
629 /////////////////////////////////////////////////////////////////
630 void SMESH_Swig::rename(const char* uid, const char* name)
634 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
636 sobject->SetAttrString( "AttributeName", name );
639 /////////////////////////////////////////////////////////////////
640 /// \brief Display mesh object.
641 /// \param uid Object's study UID or IOR.
642 /// \param viewUid View window UID (0 means currently active view
643 /// window; if there's no view, it is created).
645 /// \param updateViewer "Update view" flag. Default: \c true.
646 /////////////////////////////////////////////////////////////////
647 void SMESH_Swig::display(const char* uid, int viewUid, bool updateViewer)
649 class TDisplayEvent: public SALOME_Event
656 TDisplayEvent(const char* uid, int viewUid, bool updateViewer)
657 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
658 virtual void Execute()
660 SALOME_View* view = uid2wnd( myViewUid, true ); // create view if it's not present
662 LightApp_Displayer::FindDisplayer( "Mesh", true )->Display( myUid, myIsUpdate, view );
668 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
670 ProcessVoidEvent( new TDisplayEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
673 /////////////////////////////////////////////////////////////////
674 /// \brief Erase mesh object.
675 /// \param uid Object's study UID or IOR.
676 /// \param viewUid View window UID (0 means currently active view
677 /// window); -1 means "all view windows".
679 /// \param updateViewer "Update view" flag. Default: \c true.
680 /////////////////////////////////////////////////////////////////
681 void SMESH_Swig::erase(const char* uid, int viewUid, bool updateViewer)
683 class TEraseEvent: public SALOME_Event
690 TEraseEvent(const char* uid, int viewUid, bool updateViewer)
691 : myUid( uid ), myViewUid( viewUid ), myIsUpdate( updateViewer ) {}
692 virtual void Execute()
694 if ( myViewUid == -1 )
696 QList<SALOME_View*> views = windows();
697 foreach( SALOME_View* view, views )
698 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
702 SALOME_View* view = uid2wnd( myViewUid );
704 LightApp_Displayer::FindDisplayer( "Mesh", true )->Erase( myUid, true, myIsUpdate, view );
711 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
713 ProcessVoidEvent( new TEraseEvent( sobject->GetID().c_str(), viewUid, updateViewer ) );
716 /////////////////////////////////////////////////////////////////
717 /// \brief Update mesh object.
718 /// \param uid Object's study UID or IOR.
719 /////////////////////////////////////////////////////////////////
720 void SMESH_Swig::update(const char* uid)
722 class TUpdateEvent: public SALOME_Event
727 TUpdateEvent( const char* uid ) : myUid( uid ) {}
728 virtual void Execute()
730 Handle(SALOME_InteractiveObject) io =
731 new SALOME_InteractiveObject( myUid, "SMESH", "" );
732 SMESH::Update( io, true );
738 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
740 ProcessVoidEvent( new TUpdateEvent( uid ) );
743 /////////////////////////////////////////////////////////////////
745 class TGetPropsEvent: public SALOME_Event
748 typedef Properties TResult;
753 TGetPropsEvent( const char* uid, int viewUid )
754 : myUid( uid ), myViewUid( viewUid ) {}
756 virtual void Execute()
758 SALOME_View* view = uid2wnd( myViewUid );
759 myResult = properties( view, myUid );
763 /////////////////////////////////////////////////////////////////
764 /// \brief Get mesh object's visual properties.
765 /// \param uid Mesh object's study UID or IOR.
766 /// \param viewUid View window UID (0 means currently active view
767 /// window); Default: 0.
768 /// \return Properties data structure.
769 /////////////////////////////////////////////////////////////////
770 Properties SMESH_Swig::properties(const char* uid, int viewUid)
776 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
778 props = ProcessEvent( new TGetPropsEvent( sobject->GetID().c_str(), viewUid ) );
783 /////////////////////////////////////////////////////////////////
785 /////////////////////////////////////////////////////////////////
786 class TSetPropsEvent: public SALOME_Event
793 TSetPropsEvent( const char* uid, const Properties& props, int viewUid )
794 : myUid( uid ), myProps( props), myViewUid( viewUid ) {}
796 virtual void Execute()
798 if ( myViewUid == -1 )
800 QList<SALOME_View*> views = windows();
801 foreach( SALOME_View* view, views )
803 setProperties( view, myUid, myProps );
808 SALOME_View* view = uid2wnd( myViewUid );
809 setProperties( view, myUid, myProps );
814 /////////////////////////////////////////////////////////////////
815 /// \brief Set mesh object's visual properties.
816 /// \param uid Mesh object's study UID or IOR.
817 /// \param props Properties data structure.
818 /// \param viewUid View window UID (0 means currently active view
819 /// window); Default: 0.
820 /////////////////////////////////////////////////////////////////
821 void SMESH_Swig::setProperties(const char* uid, const Properties& props, int viewUid)
825 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
827 ProcessVoidEvent( new TSetPropsEvent( sobject->GetID().c_str(), props, viewUid ) );
830 /////////////////////////////////////////////////////////////////
832 /////////////////////////////////////////////////////////////////
833 class TGetNodeNumberingEvent: public SALOME_Event
836 typedef bool TResult;
841 TGetNodeNumberingEvent( const char* uid, int viewUid )
842 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
844 virtual void Execute()
846 SALOME_View* view = uid2wnd( myViewUid );
847 SMESH_Actor* actor = actorFromView( view, myUid );
849 myResult = actor->GetPointsLabeled();
853 /////////////////////////////////////////////////////////////////
854 /// \brief Check if nodes numbering is switched on.
855 /// \param uid Mesh object's study UID or IOR.
856 /// \param viewUid View window UID (0 means currently active view
857 /// window); Default: 0.
858 /// \return \c true if nodes numbering is switched on;
859 /// \c false otherwise.
860 /////////////////////////////////////////////////////////////////
861 bool SMESH_Swig::nodesNumbering(const char* uid, int viewUid)
863 bool numbering = false;
867 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
869 numbering = ProcessEvent( new TGetNodeNumberingEvent( sobject->GetID().c_str(), viewUid ) );
874 /////////////////////////////////////////////////////////////////
876 /////////////////////////////////////////////////////////////////
877 class TSetNodeNumberingEvent: public SALOME_Event
884 TSetNodeNumberingEvent( const char* uid, bool numbering, int viewUid )
885 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
887 virtual void Execute()
889 SALOME_View* view = uid2wnd( myViewUid );
890 SMESH_Actor* actor = actorFromView( view, myUid );
893 actor->SetPointsLabeled( myNumbering );
900 /////////////////////////////////////////////////////////////////
901 /// \brief Switch nodes numbering on/off.
902 /// \param uid Mesh object's study UID or IOR.
903 /// \param numbering \c true to switch nodes numbering on;
904 /// \c false otherwise.
905 /// \param viewUid View window UID (0 means currently active view
906 /// window); Default: 0.
907 /////////////////////////////////////////////////////////////////
908 void SMESH_Swig::setNodesNumbering(const char* uid, bool numbering, int viewUid)
912 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
914 ProcessVoidEvent( new TSetNodeNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
917 /////////////////////////////////////////////////////////////////
919 /////////////////////////////////////////////////////////////////
920 class TGetElementNumberingEvent: public SALOME_Event
923 typedef bool TResult;
928 TGetElementNumberingEvent( const char* uid, int viewUid )
929 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
931 virtual void Execute()
933 SALOME_View* view = uid2wnd( myViewUid );
934 SMESH_Actor* actor = actorFromView( view, myUid );
936 myResult = actor->GetCellsLabeled();
940 /////////////////////////////////////////////////////////////////
941 /// \brief Check if elements numbering is switched on.
942 /// \param uid Mesh object's study UID or IOR.
943 /// \param viewUid View window UID (0 means currently active view
944 /// window); Default: 0.
945 /// \return \c true if elements numbering is switched on;
946 /// \c false otherwise.
947 /////////////////////////////////////////////////////////////////
948 bool SMESH_Swig::elementsNumbering(const char* uid, int viewUid)
950 bool numbering = false;
954 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
956 numbering = ProcessEvent( new TGetElementNumberingEvent( sobject->GetID().c_str(), viewUid ) );
961 /////////////////////////////////////////////////////////////////
963 /////////////////////////////////////////////////////////////////
964 class TSetElementNumberingEvent: public SALOME_Event
971 TSetElementNumberingEvent( const char* uid, bool numbering, int viewUid )
972 : myUid( uid ), myNumbering( numbering ), myViewUid( viewUid ) {}
974 virtual void Execute()
976 SALOME_View* view = uid2wnd( myViewUid );
977 SMESH_Actor* actor = actorFromView( view, myUid );
980 actor->SetCellsLabeled( myNumbering );
987 /////////////////////////////////////////////////////////////////
988 /// \brief Switch elements numbering on/off.
989 /// \param uid Mesh object's study UID or IOR.
990 /// \param numbering \c true to switch elements numbering on;
991 /// \c false otherwise.
992 /// \param viewUid View window UID (0 means currently active view
993 /// window); Default: 0.
994 /////////////////////////////////////////////////////////////////
995 void SMESH_Swig::setElementsNumbering(const char* uid, bool numbering, int viewUid)
999 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1001 ProcessVoidEvent( new TSetElementNumberingEvent( sobject->GetID().c_str(), numbering, viewUid ) );
1004 /////////////////////////////////////////////////////////////////
1006 /////////////////////////////////////////////////////////////////
1007 class TGetDisplayModeEvent: public SALOME_Event
1010 typedef DisplayMode TResult;
1015 TGetDisplayModeEvent( const char* uid, int viewUid )
1016 : myResult( UndefinedMode ), myUid( uid ), myViewUid( viewUid ) {}
1018 virtual void Execute()
1020 SALOME_View* view = uid2wnd( myViewUid );
1021 SMESH_Actor* actor = actorFromView( view, myUid );
1023 myResult = (DisplayMode)actor->GetRepresentation();
1027 /////////////////////////////////////////////////////////////////
1028 /// \brief Get mesh object's display mode.
1029 /// \param uid Mesh object's study UID or IOR.
1030 /// \param viewUid View window UID (0 means currently active view
1031 /// window); Default: 0.
1032 /// \return Display mode (UndefinedMode if actor isn't found).
1033 /////////////////////////////////////////////////////////////////
1034 DisplayMode SMESH_Swig::displayMode(const char* uid, int viewUid)
1036 DisplayMode mode = UndefinedMode;
1040 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1042 mode = ProcessEvent( new TGetDisplayModeEvent( sobject->GetID().c_str(), viewUid ) );
1047 /////////////////////////////////////////////////////////////////
1049 /////////////////////////////////////////////////////////////////
1050 class TSetDisplayModeEvent: public SALOME_Event
1057 TSetDisplayModeEvent( const char* uid, DisplayMode mode, int viewUid )
1058 : myUid( uid ), myMode( mode), myViewUid( viewUid ) {}
1060 virtual void Execute()
1062 SALOME_View* view = uid2wnd( myViewUid );
1063 SMESH_Actor* actor = actorFromView( view, myUid );
1064 if ( actor && myMode != UndefinedMode )
1066 actor->SetRepresentation( myMode );
1073 /////////////////////////////////////////////////////////////////
1074 /// \brief Set mesh object's display mode.
1075 /// \param uid Mesh object's study UID or IOR.
1076 /// \param mode Display mode.
1077 /// \param viewUid View window UID (0 means currently active view
1078 /// window); Default: 0.
1079 /////////////////////////////////////////////////////////////////
1080 void SMESH_Swig::setDisplayMode(const char* uid, DisplayMode mode, int viewUid)
1084 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1086 ProcessVoidEvent( new TSetDisplayModeEvent( sobject->GetID().c_str(), mode, viewUid ) );
1089 /////////////////////////////////////////////////////////////////
1091 /////////////////////////////////////////////////////////////////
1092 class TGetShrinkModeEvent: public SALOME_Event
1095 typedef bool TResult;
1100 TGetShrinkModeEvent( const char* uid, int viewUid )
1101 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1103 virtual void Execute()
1105 SALOME_View* view = uid2wnd( myViewUid );
1106 SMESH_Actor* actor = actorFromView( view, myUid );
1108 myResult = actor->IsShrunk();
1112 /////////////////////////////////////////////////////////////////
1113 /// \brief Check if shrink mode is switched on.
1114 /// \param uid Mesh object's study UID or IOR.
1115 /// \param viewUid View window UID (0 means currently active view
1116 /// window); Default: 0.
1117 /// \return \c true if shrink mode is switched on;
1118 /// \c false otherwise.
1119 /////////////////////////////////////////////////////////////////
1120 bool SMESH_Swig::shrinkMode(const char* uid, int viewUid)
1122 bool shrinkMode = false;
1126 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1128 shrinkMode = ProcessEvent( new TGetShrinkModeEvent( sobject->GetID().c_str(), viewUid ) );
1133 /////////////////////////////////////////////////////////////////
1135 /////////////////////////////////////////////////////////////////
1136 class TSetShrinkModeEvent: public SALOME_Event
1143 TSetShrinkModeEvent( const char* uid, bool shrink, int viewUid )
1144 : myUid( uid ), myShrink( shrink ), myViewUid( viewUid ) {}
1146 virtual void Execute()
1148 SALOME_View* view = uid2wnd( myViewUid );
1149 SMESH_Actor* actor = actorFromView( view, myUid );
1162 /////////////////////////////////////////////////////////////////
1163 /// \brief Switch shrink mode on/off.
1164 /// \param uid Mesh object's study UID or IOR.
1165 /// \param shrink \c true to switch shrink mode on;
1166 /// \c false otherwise.
1167 /// \param viewUid View window UID (0 means currently active view
1168 /// window); Default: 0.
1169 /////////////////////////////////////////////////////////////////
1170 void SMESH_Swig::setShrinkMode(const char* uid, bool shrink, int viewUid)
1174 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1176 ProcessVoidEvent( new TSetShrinkModeEvent( sobject->GetID().c_str(), shrink, viewUid ) );
1179 /////////////////////////////////////////////////////////////////
1181 /////////////////////////////////////////////////////////////////
1182 class TGetOpacityEvent: public SALOME_Event
1185 typedef double TResult;
1190 TGetOpacityEvent( const char* uid, int viewUid )
1191 : myResult( 0 ), myUid( uid ), myViewUid( viewUid ) {}
1193 virtual void Execute()
1195 SALOME_View* view = uid2wnd( myViewUid );
1196 SMESH_Actor* actor = actorFromView( view, myUid );
1198 myResult = actor->GetOpacity();
1202 /////////////////////////////////////////////////////////////////
1203 /// \brief Get mesh object's opacity.
1204 /// \param uid Mesh object's study UID or IOR.
1205 /// \param viewUid View window UID (0 means currently active view
1206 /// window); Default: 0.
1207 /// \return Opacity value.
1208 /////////////////////////////////////////////////////////////////
1209 double SMESH_Swig::opacity(const char* uid, int viewUid)
1215 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1217 opacity = ProcessEvent( new TGetOpacityEvent( sobject->GetID().c_str(), viewUid ) );
1222 /////////////////////////////////////////////////////////////////
1224 /////////////////////////////////////////////////////////////////
1225 class TSetOpacityEvent: public SALOME_Event
1232 TSetOpacityEvent( const char* uid, double opacity, int viewUid )
1233 : myUid( uid ), myOpacity( opacity ), myViewUid( viewUid ) {}
1235 virtual void Execute()
1237 SALOME_View* view = uid2wnd( myViewUid );
1238 SMESH_Actor* actor = actorFromView( view, myUid );
1241 actor->SetOpacity( myOpacity );
1248 /////////////////////////////////////////////////////////////////
1249 /// \brief Set mesh object's opacity.
1250 /// \param uid Mesh object's study UID or IOR.
1251 /// \param opacity Opacity value.
1252 /// \param viewUid View window UID (0 means currently active view
1253 /// window); Default: 0.
1254 /////////////////////////////////////////////////////////////////
1255 void SMESH_Swig::setOpacity(const char* uid, double opacity, int viewUid)
1259 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1261 ProcessVoidEvent( new TSetOpacityEvent( sobject->GetID().c_str(), opacity, viewUid ) );
1264 /////////////////////////////////////////////////////////////////
1266 /////////////////////////////////////////////////////////////////
1267 class TGetOrientationEvent: public SALOME_Event
1270 typedef bool TResult;
1275 TGetOrientationEvent( const char* uid, int viewUid )
1276 : myResult( false ), myUid( uid ), myViewUid( viewUid ) {}
1278 virtual void Execute()
1280 SALOME_View* view = uid2wnd( myViewUid );
1281 SMESH_Actor* actor = actorFromView( view, myUid );
1283 myResult = actor->GetFacesOriented();
1287 /////////////////////////////////////////////////////////////////
1288 /// \brief Check if faces orientation vectors are shown.
1289 /// \param uid Mesh object's study UID or IOR.
1290 /// \param viewUid View window UID (0 means currently active view
1291 /// window); Default: 0.
1292 /// \return \c true if faces orientation vectors are shown;
1293 /// \c false otherwise.
1294 /////////////////////////////////////////////////////////////////
1295 bool SMESH_Swig::isOrientationShown(const char* uid, int viewUid)
1301 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1303 shown = ProcessEvent( new TGetOrientationEvent( sobject->GetID().c_str(), viewUid ) );
1308 /////////////////////////////////////////////////////////////////
1310 /////////////////////////////////////////////////////////////////
1311 class TSetOrientationEvent: public SALOME_Event
1318 TSetOrientationEvent( const char* uid, bool shown, int viewUid )
1319 : myUid( uid ), myShown( shown ), myViewUid( viewUid ) {}
1321 virtual void Execute()
1323 SALOME_View* view = uid2wnd( myViewUid );
1324 SMESH_Actor* actor = actorFromView( view, myUid );
1327 actor->SetFacesOriented( myShown );
1334 /////////////////////////////////////////////////////////////////
1335 /// \brief Show/hide faces orientation vectors.
1336 /// \param uid Mesh object's study UID or IOR.
1337 /// \param shown \c true to show faces orientation vectors;
1338 /// \c false otherwise.
1339 /// \param viewUid View window UID (0 means currently active view
1340 /// window); Default: 0.
1341 /////////////////////////////////////////////////////////////////
1342 void SMESH_Swig::setOrientationShown(const char* uid, bool shown, int viewUid)
1346 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1348 ProcessVoidEvent( new TSetOrientationEvent( sobject->GetID().c_str(), shown, viewUid ) );
1351 /////////////////////////////////////////////////////////////////
1353 /////////////////////////////////////////////////////////////////
1354 class TGetEntitiesEvent: public SALOME_Event
1357 typedef int TResult;
1362 TGetEntitiesEvent( const char* uid, int viewUid )
1363 : myResult( EntityNone ), myUid( uid ), myViewUid( viewUid ) {}
1365 virtual void Execute()
1367 SALOME_View* view = uid2wnd( myViewUid );
1368 SMESH_Actor* actor = actorFromView( view, myUid );
1370 myResult = actor->GetEntityMode();
1374 /////////////////////////////////////////////////////////////////
1375 /// \brief Get mesh object's visible entities.
1376 /// \param uid Mesh object's study UID or IOR.
1377 /// \param viewUid View window UID (0 means currently active view
1378 /// window); Default: 0.
1379 /// \return Enumerator describing entities being visible.
1380 /////////////////////////////////////////////////////////////////
1381 int SMESH_Swig::entitiesShown(const char* uid, int viewUid)
1383 int entities = EntityNone;
1387 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1389 entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1394 /////////////////////////////////////////////////////////////////
1396 /////////////////////////////////////////////////////////////////
1397 class TSetEntitiesEvent: public SALOME_Event
1404 TSetEntitiesEvent( const char* uid, int entities, int viewUid )
1405 : myUid( uid ), myEntities( entities ), myViewUid( viewUid ) {}
1407 virtual void Execute()
1409 SALOME_View* view = uid2wnd( myViewUid );
1410 SMESH_Actor* actor = actorFromView( view, myUid );
1413 actor->SetEntityMode( myEntities );
1420 /////////////////////////////////////////////////////////////////
1421 /// \brief Set mesh object's visible entities.
1422 /// \param uid Mesh object's study UID or IOR.
1423 /// \param entities Enumerator describing entities to be shown.
1424 /// \param viewUid View window UID (0 means currently active view
1425 /// window); Default: 0.
1426 /////////////////////////////////////////////////////////////////
1427 void SMESH_Swig::setEntitiesShown(const char* uid, int entities, int viewUid)
1431 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1433 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1436 /////////////////////////////////////////////////////////////////
1437 /// \brief Check if given mesh object's entity is shown.
1438 /// \param uid Mesh object's study UID or IOR.
1439 /// \param entity Mesh entity.
1440 /// \param viewUid View window UID (0 means currently active view
1441 /// window); Default: 0.
1442 /// \return \c true if entity is shown; \c false otherwise.
1443 /////////////////////////////////////////////////////////////////
1444 bool SMESH_Swig::isEntityShown(const char* uid, EntityMode entity, int viewUid)
1450 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1453 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1454 shown = (bool)( entities & entity );
1460 /////////////////////////////////////////////////////////////////
1461 /// \brief Show/hide entity for given mesh object.
1462 /// \param uid Mesh object's study UID or IOR.
1463 /// \param entity Mesh entity.
1464 /// \param show Visibility status.
1465 /// \param viewUid View window UID (0 means currently active view
1466 /// window); Default: 0.
1467 /////////////////////////////////////////////////////////////////
1468 void SMESH_Swig::setEntityShown(const char* uid, EntityMode entity, bool show, int viewUid)
1472 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1475 int entities = ProcessEvent( new TGetEntitiesEvent( sobject->GetID().c_str(), viewUid ) );
1479 entities &= ~entity;
1480 ProcessVoidEvent( new TSetEntitiesEvent( sobject->GetID().c_str(), entities, viewUid ) );
1484 /////////////////////////////////////////////////////////////////
1485 /// \brief Initialize %SMESH GUI Python interface.
1486 /// \deprecated Interface is initialized automatically.
1487 /// \param studyID Study UID (not used).
1488 /////////////////////////////////////////////////////////////////
1489 void SMESH_Swig::Init(int /*studyID*/)
1491 deprecated("SMESH_Swig::Init");
1492 // does nothing; initialization is done automatically.
1495 /////////////////////////////////////////////////////////////////
1496 /// \brief Publish mesh in the active study.
1497 /// \deprecated Publishing is done automatically.
1498 /// \param ior IOR of the mesh.
1499 /// \param name Name of the mesh (optional).
1500 /// \return UID of the data object.
1501 /////////////////////////////////////////////////////////////////
1502 const char* SMESH_Swig::AddNewMesh(const char* ior, const char* name)
1504 deprecated("SMESH_Swig::AddNewMesh", "SMESH_Swig::publish");
1505 return publish( ior, name );
1508 /////////////////////////////////////////////////////////////////
1509 /// \brief Publish hypothesis in the active study.
1510 /// \deprecated Publishing is done automatically.
1511 /// \param ior IOR of the hypothesis.
1512 /// \param name Name of the hypothesis (optional).
1513 /// \return UID of the data object.
1514 /////////////////////////////////////////////////////////////////
1515 const char* SMESH_Swig::AddNewHypothesis(const char* ior, const char* name)
1517 deprecated("SMESH_Swig::AddNewHypothesis", "SMESH_Swig::publish");
1518 return publish( ior, name );
1521 /////////////////////////////////////////////////////////////////
1522 /// \brief Publish algorithm in the active study.
1523 /// \deprecated Publishing is done automatically.
1524 /// \param ior IOR of the algorithm.
1525 /// \param name Name of the algorithm (optional).
1526 /// \return UID of the data object.
1527 /////////////////////////////////////////////////////////////////
1528 const char* SMESH_Swig::AddNewAlgorithm(const char* ior, const char* name)
1530 deprecated("SMESH_Swig::AddNewAlgorithm", "SMESH_Swig::publish");
1531 return publish( ior, name );
1534 /////////////////////////////////////////////////////////////////
1535 /// \deprecated Publishing is done automatically.
1536 /// \deprecated Synonim of AddNewAlgorithm().
1537 /// \param ior IOR of the algorithm.
1538 /// \param name Name of the algorithm (optional).
1539 /// \return UID of the data object.
1540 /////////////////////////////////////////////////////////////////
1541 const char* SMESH_Swig::AddNewAlgorithms(const char* ior, const char* name)
1543 deprecated("SMESH_Swig::AddNewAlgorithms", "SMESH_Swig::publish");
1544 return publish( ior, name );
1547 /////////////////////////////////////////////////////////////////
1548 /// \brief Add reference on a shape for mesh in a study.
1549 /// \deprecated Publishing is done automatically.
1550 /// \param shapeUid GEOM shape's study UID (not used).
1551 /// \param meshUid Mesh's study UID (not used).
1552 /////////////////////////////////////////////////////////////////
1553 void SMESH_Swig::SetShape(const char* /*shapeUid*/, const char* /*meshUid*/)
1555 deprecated("SMESH_Swig::SetShape", "SMESH_Swig::publish");
1556 // does nothing: publishing is done automatically
1559 /////////////////////////////////////////////////////////////////
1560 /// \brief Assign hypothesis to mesh or sub-mesh.
1561 /// \deprecated Publishing is done automatically.
1562 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1563 /// \param hypoUID Hypothesis's study UID (not used).
1564 /////////////////////////////////////////////////////////////////
1565 void SMESH_Swig::SetHypothesis(const char* /*meshUid*/, const char* /*hypoUID*/)
1567 deprecated("SMESH_Swig::SetHypothesis", "SMESH_Swig::publish");
1568 // does nothing: publishing is done automatically
1571 /////////////////////////////////////////////////////////////////
1572 /// \brief Assign algorithm to mesh or sub-mesh.
1573 /// \deprecated Publishing is done automatically.
1574 /// \param meshUid Mesh's or sub-mesh's study UID (not used).
1575 /// \param algoUID Algorithm's study UID (not used).
1576 /////////////////////////////////////////////////////////////////
1577 void SMESH_Swig::SetAlgorithms(const char* /*meshUid*/, const char* /*algoUID*/)
1579 deprecated("SMESH_Swig::SetAlgorithms", "SMESH_Swig::publish");
1580 // does nothing: publishing is done automatically
1583 /////////////////////////////////////////////////////////////////
1584 /// \brief Anassign hypothesis or algorithm from mesh or sub-mesh.
1585 /// \deprecated Unpublishing is done automatically.
1586 /// \param uid Hypothesis's or algorithm's study UID (not used).
1587 /////////////////////////////////////////////////////////////////
1588 void SMESH_Swig::UnSetHypothesis(const char* /*uid*/)
1590 deprecated("SMESH_Swig::UnSetHypothesis");
1591 // does nothing: unpublishing is done automatically
1594 /////////////////////////////////////////////////////////////////
1595 /// \brief Publish sub-mesh in the active study.
1596 /// \deprecated Publishing is done automatically.
1597 /// \param meshUid Parent mesh's study UID (not used).
1598 /// \param ior IOR of the sub-mesh.
1599 /// \param shapeType GEOM shape's type (not used).
1600 /// \param name Name of the sub-mesh (optional).
1601 /// \return UID of the data object.
1602 /////////////////////////////////////////////////////////////////
1603 const char* SMESH_Swig::AddSubMesh(const char* /*meshUid*/,
1608 deprecated("SMESH_Swig::AddSubMesh", "SMESH_Swig::publish");
1609 return publish( ior, name );
1612 /////////////////////////////////////////////////////////////////
1613 /// \brief Publish sub-mesh in the active study.
1614 /// \deprecated Publishing is done automatically.
1615 /// \param meshUid Parent mesh's study UID (not used).
1616 /// \param shapeUid GEOM shape's study UID (not used).
1617 /// \param ior IOR of the sub-mesh.
1618 /// \param shapeType GEOM shape's type (not used).
1619 /// \param name Name of the sub-mesh (optional).
1620 /// \return UID of the data object.
1621 /////////////////////////////////////////////////////////////////
1622 const char* SMESH_Swig::AddSubMeshOnShape(const char* /*meshUid*/,
1623 const char* /*shapeUid*/,
1628 deprecated("SMESH_Swig::AddSubMeshOnShape", "SMESH_Swig::publish");
1629 return publish( ior, name );
1632 /////////////////////////////////////////////////////////////////
1633 /// \brief Set new study name of given object.
1634 /// \deprecated Use rename() method.
1635 /// \param uid Object's study UID or IOR.
1636 /// \param name New name of the object.
1637 /////////////////////////////////////////////////////////////////
1638 void SMESH_Swig::SetName(const char* uid, const char* name)
1640 deprecated("SMESH_Swig::SetName", "SMESH_Swig::rename");
1641 rename( uid, name );
1644 /////////////////////////////////////////////////////////////////
1645 /// \brief Set mesh icon according to compute status
1646 /// \deprecated Publishing is done automatically.
1647 /// \param meshUid Mesh's study UID (not used).
1648 /// \param isComputed Flag pointing that mesh is computed or no
1650 /// \param isEmpty Flag pointing that mesh is empty or no
1652 /////////////////////////////////////////////////////////////////
1653 void SMESH_Swig::SetMeshIcon(const char* /*meshUid*/,
1654 const bool /*isComputed*/,
1655 const bool /*isEmpty*/)
1657 deprecated("SMESH_Swig::SetMeshIcon", "SMESH_Swig::publish");
1658 // does nothing: publishing is done automatically
1661 /////////////////////////////////////////////////////////////////
1662 /// Display mesh in the currently active view window.
1663 /// \deprecated Use display() method.
1664 /// \param meshUid Mesh's study UID.
1665 /////////////////////////////////////////////////////////////////
1666 void SMESH_Swig::CreateAndDisplayActor(const char* meshUid)
1668 deprecated("SMESH_Swig::CreateAndDisplayActor", "SMESH_Swig::display");
1672 /////////////////////////////////////////////////////////////////
1673 /// Erase mesh in the view window(s).
1674 /// \deprecated Use erase() method.
1675 /// \param meshUid Mesh's study UID.
1676 /// \param allViewers If \c true, mesh is removed from all views.
1677 /// Default: \c false.
1678 /////////////////////////////////////////////////////////////////
1679 void SMESH_Swig::EraseActor(const char* meshUid, const bool allViewers)
1681 deprecated("SMESH_Swig::EraseActor", "SMESH_Swig::erase");
1682 erase( meshUid, allViewers ? -1 : 0 );
1685 /////////////////////////////////////////////////////////////////
1686 /// Update mesh object.
1687 /// \deprecated Use update() method.
1688 /// \param meshUid Mesh's study UID.
1689 /////////////////////////////////////////////////////////////////
1690 void SMESH_Swig::UpdateActor(const char* meshUid)
1692 deprecated("SMESH_Swig::UpdateActor", "SMESH_Swig::update");
1696 /////////////////////////////////////////////////////////////////
1697 /// Get mesh object's properties.
1698 /// \deprecated Use properties() method.
1699 /// \param meshUid Mesh's study UID.
1700 /// \param viewUid View window UID (0 means currently active view
1701 /// window). Default: 0.
1702 /////////////////////////////////////////////////////////////////
1703 actorAspect SMESH_Swig::GetActorAspect(const char* meshUid, int viewUid)
1705 deprecated("SMESH_Swig::GetActorAspect", "SMESH_Swig::properties");
1706 return properties( meshUid, viewUid );
1709 /////////////////////////////////////////////////////////////////
1710 /// Set mesh object's properties.
1711 /// \deprecated Use setProperties() method.
1712 /// \param meshUid Mesh's study UID.
1713 /// \param viewUid View window UID (0 means currently active view
1714 /// window). Default: 0.
1715 /////////////////////////////////////////////////////////////////
1716 void SMESH_Swig::SetActorAspect(const actorAspect& aspect, const char* meshUid, int viewUid)
1718 deprecated("SMESH_Swig::SetActorAspect", "SMESH_Swig::setProperties");
1719 setProperties( meshUid, aspect, viewUid );
1722 /////////////////////////////////////////////////////////////////
1724 /////////////////////////////////////////////////////////////////
1725 class TSelectListEvent: public SALOME_Event
1728 std::vector<int> myIds;
1732 TSelectListEvent(const char* uid, std::vector<int> ids, bool append)
1733 : myUid( uid ), myIds( ids ), myIsAppend( append )
1736 virtual void Execute()
1738 LightApp_SelectionMgr* selMgr = 0;
1739 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1741 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1746 selMgr->clearFilters();
1748 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1752 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1754 if ( !actor || !actor->hasIO() )
1757 Handle(SALOME_InteractiveObject) io = actor->getIO();
1760 selMgr->setSelectedObjects( ios, false );
1762 if ( vw->SelectionMode() == ActorSelection )
1765 TColStd_MapOfInteger idMap;
1766 std::vector<int>::const_iterator it;
1767 for ( it = myIds.begin(); it != myIds.end(); ++it )
1772 // Set new selection
1773 SVTK_Selector* selector = vw->GetSelector();
1774 selector->AddOrRemoveIndex( io, idMap, myIsAppend );
1775 vw->highlight( io, true, true );
1776 vw->GetInteractor()->onEmitSelectionChanged();
1780 /////////////////////////////////////////////////////////////////
1781 /// \brief Select elements of the mesh, sub-mesh or group.
1782 /// \param uid Mesh object's study UID or IOR.
1783 /// \param ids List of mesh elements.
1784 /// \param append If \c true, elements are added to current
1785 /// selection; otherwise, previous selection is
1787 /////////////////////////////////////////////////////////////////
1788 void SMESH_Swig::select(const char* uid, std::vector<int> ids, bool append)
1792 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1794 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1797 /////////////////////////////////////////////////////////////////
1798 /// \brief Select element of the mesh, sub-mesh or group.
1799 /// \param uid Mesh object's study UID or IOR.
1800 /// \param id Mesh element.
1801 /// \param append If \c true, element is added to current
1802 /// selection; otherwise, previous selection is
1804 /////////////////////////////////////////////////////////////////
1805 void SMESH_Swig::select(const char* uid, int id, bool append)
1809 std::vector<int> ids;
1810 ids.push_back( id );
1812 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1814 ProcessVoidEvent( new TSelectListEvent( sobject->GetID().c_str(), ids, append ) );
1817 /////////////////////////////////////////////////////////////////
1819 /////////////////////////////////////////////////////////////////
1820 class TSelectListOfPairEvent: public SALOME_Event
1823 std::vector<std::pair<int, int> > myIds;
1827 TSelectListOfPairEvent(const char* uid, std::vector<std::pair<int, int> > ids, bool append)
1828 : myUid( uid ), myIds( ids ), myIsAppend( append )
1831 virtual void Execute()
1833 LightApp_SelectionMgr* selMgr = 0;
1834 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1836 selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
1841 selMgr->clearFilters();
1843 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
1847 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
1849 if ( !actor || !actor->hasIO() )
1852 Handle(SALOME_InteractiveObject) io = actor->getIO();
1855 selMgr->setSelectedObjects( ios, false );
1857 if ( vw->SelectionMode() != EdgeOfCellSelection )
1860 SVTK_IndexedMapOfIds idMap;
1861 std::vector<std::pair<int, int> >::const_iterator it;
1862 for ( it = myIds.begin(); it != myIds.end(); ++it )
1864 std::vector<int> pair;
1865 pair.push_back( (*it).first );
1866 pair.push_back( (*it).second );
1870 // Set new selection
1871 SVTK_Selector* selector = vw->GetSelector();
1872 selector->AddOrRemoveCompositeIndex( io, idMap, myIsAppend );
1873 vw->highlight( io, true, true );
1874 vw->GetInteractor()->onEmitSelectionChanged();
1878 /////////////////////////////////////////////////////////////////
1879 /// \brief Select pseudo-edges (specified by two nodes)
1880 /// of the mesh, sub-mesh or group.
1881 /// \param uid Mesh object's study UID or IOR.
1882 /// \param ids List of pairs containing two nodes IDs.
1883 /// \param append If \c true, pseudo-edges are added to current
1884 /// selection; otherwise, previous selection is
1886 /////////////////////////////////////////////////////////////////
1887 void SMESH_Swig::select(const char* uid, std::vector<std::pair<int,int> > ids, bool append)
1891 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
1893 ProcessVoidEvent( new TSelectListOfPairEvent( sobject->GetID().c_str(), ids, append ) );
1896 /////////////////////////////////////////////////////////////////
1898 /////////////////////////////////////////////////////////////////
1899 class TGetSelectionModeEvent: public SALOME_Event
1902 typedef SelectionMode TResult;
1906 TGetSelectionModeEvent( int viewUid ) :
1907 myResult( Undefined ), myViewUid( viewUid ) {}
1909 virtual void Execute()
1911 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1914 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1916 myResult = (SelectionMode)vw->SelectionMode();
1921 /////////////////////////////////////////////////////////////////
1922 /// \brief Get selection mode of view window.
1923 /// \param viewUid View window UID (0 means currently active view
1924 /// window); Default: 0.
1925 /// \return Current selection mode.
1926 /////////////////////////////////////////////////////////////////
1927 SelectionMode SMESH_Swig::getSelectionMode(int viewUid)
1930 return ProcessEvent( new TGetSelectionModeEvent( viewUid ) );
1933 /////////////////////////////////////////////////////////////////
1935 /////////////////////////////////////////////////////////////////
1936 class TSetSelectionModeEvent: public SALOME_Event
1938 SelectionMode mySelectionMode;
1942 TSetSelectionModeEvent( const SelectionMode selectionMode, int viewUid )
1943 : mySelectionMode( selectionMode ), myViewUid( viewUid )
1946 virtual void Execute()
1948 SVTK_Viewer* model = dynamic_cast<SVTK_Viewer*>( uid2wnd( myViewUid ) );
1951 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( model->getViewManager()->getActiveView() );
1954 SelectionMode previousMode = (SelectionMode)vw->SelectionMode();
1955 bool switchPointMode = ( previousMode == Node && mySelectionMode != Node ) ||
1956 ( previousMode != Node && mySelectionMode == Node );
1957 if ( switchPointMode )
1959 vtkRenderer* renderer = vw->getRenderer();
1960 VTK::ActorCollectionCopy actors( renderer->GetActors() );
1961 vtkActorCollection* collection = actors.GetActors();
1962 collection->InitTraversal();
1963 while ( vtkActor* vtkActor = collection->GetNextActor() )
1965 if ( SMESH_Actor* actor = dynamic_cast<SMESH_Actor*>( vtkActor ) )
1967 if ( actor->GetVisibility() )
1968 actor->SetPointRepresentation( mySelectionMode == Node );
1972 vw->SetSelectionMode( mySelectionMode );
1978 /////////////////////////////////////////////////////////////////
1979 /// \brief Set selection mode to view window.
1980 /// \param viewUid View window UID (0 means currently active view
1981 /// window); Default: 0.
1982 /// \param mode Selection mode.
1983 /////////////////////////////////////////////////////////////////
1984 void SMESH_Swig::setSelectionMode(SelectionMode mode, int viewUid)
1987 ProcessVoidEvent( new TSetSelectionModeEvent( mode, viewUid ) );
1990 /////////////////////////////////////////////////////////////////
1992 /////////////////////////////////////////////////////////////////
1993 class TGetSelectedEvent: public SALOME_Event
1996 typedef std::vector<int> TResult;
2000 TGetSelectedEvent( const char* uid )
2003 virtual void Execute()
2005 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2009 SVTK_Selector* selector = vw->GetSelector();
2013 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2014 if ( !actor || !actor->hasIO() )
2017 TColStd_IndexedMapOfInteger idMap;
2018 selector->GetIndex( actor->getIO(), idMap );
2020 for ( int i = 1; i <= idMap.Extent(); i++ )
2021 myResult.push_back( idMap( i ) );
2025 /////////////////////////////////////////////////////////////////
2026 /// \brief Get selected elements of the mesh, sub-mesh or group.
2027 /// \param uid Mesh object's study UID or IOR.
2028 /// \return List of selected mesh elements.
2029 /////////////////////////////////////////////////////////////////
2030 std::vector<int> SMESH_Swig::getSelected(const char* uid)
2032 std::vector<int> ids;
2036 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
2038 ids = ProcessEvent( new TGetSelectedEvent( sobject->GetID().c_str() ) );
2043 /////////////////////////////////////////////////////////////////
2045 /////////////////////////////////////////////////////////////////
2046 class TGetSelectedPairEvent : public SALOME_Event
2049 typedef std::vector<std::pair<int, int> > TResult;
2053 TGetSelectedPairEvent( const char* uid )
2056 virtual void Execute()
2058 SVTK_ViewWindow* vw = SMESH::GetViewWindow();
2062 if ( vw->SelectionMode() != EdgeOfCellSelection )
2065 SVTK_Selector* selector = vw->GetSelector();
2069 SMESH_Actor* actor = SMESH::FindActorByEntry( myUid );
2070 if ( !actor || !actor->hasIO() )
2073 SVTK_IndexedMapOfIds idMap;
2074 selector->GetCompositeIndex( actor->getIO(), idMap );
2076 for ( int i = 1; i <= idMap.Extent(); i++ )
2077 myResult.push_back( std::make_pair<int,int>( (int)idMap( i )[0], (int)idMap( i )[1]) );
2081 /////////////////////////////////////////////////////////////////
2082 /// \brief Get selected pseudo-edges (specified by two nodes)
2083 /// of the mesh, sub-mesh or group.
2084 /// \param uid Mesh object's study UID or IOR.
2085 /// \param ids List of pairs containing two nodes IDs.
2086 /// \param append If \c true, pseudo-edges are added to current
2087 /// selection; otherwise, previous selection is
2089 /////////////////////////////////////////////////////////////////
2090 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell(const char* uid)
2092 std::vector<std::pair<int,int> > pairs;
2096 _PTR(SObject) sobject = uid2object( myCachedStudyId, uid );
2098 pairs = ProcessEvent( new TGetSelectedPairEvent( sobject->GetID().c_str() ) );