Salome HOME
3b74134f0574b26fa0fda0a142bb02ed8013dd04
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operation.cxx
1
2 #include <HYDROGUI_Operation.h>
3 #include <HYDROGUI_Module.h>
4 #include <HYDROGUI_InputPanel.h>
5 #include <HYDROData_Document.h>
6 #include <HYDROData_Iterator.h>
7 #include <LightApp_Application.h>
8 #include <LightApp_SelectionMgr.h>
9 #include <SUIT_Desktop.h>
10 #include <SUIT_Study.h>
11
12 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
13 : LightApp_Operation(), myModule( theModule ), myPanel( 0 )
14 {
15 }
16
17 HYDROGUI_Operation::~HYDROGUI_Operation()
18 {
19 }
20
21 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
22 {
23   return myModule->getApp()->selectionMgr();
24 }
25
26 HYDROGUI_Module* HYDROGUI_Operation::module() const
27 {
28   return myModule;
29 }
30
31 void HYDROGUI_Operation::startOperation()
32 {
33   doc()->StartOperation();
34
35   if( inputPanel() )
36   {
37     connect( inputPanel(), SIGNAL( panelApply() ),  this, SLOT( OnApply() ) );
38     connect( inputPanel(), SIGNAL( panelCancel() ), this, SLOT( OnCancel() ) );
39
40     inputPanel()->show();
41     myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
42   }
43 }
44
45 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
46 {
47   if( !myPanel )
48     ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
49   return myPanel;
50 }
51
52 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
53 {
54   int aStudyId = myModule->application()->activeStudy()->id();
55   return HYDROData_Document::Document( aStudyId );
56 }
57
58 void HYDROGUI_Operation::OnApply()
59 {
60   doc()->CommitOperation();
61   inputPanel()->hide();
62 }
63
64 void HYDROGUI_Operation::OnCancel()
65 {
66   doc()->AbortOperation();
67   inputPanel()->hide();
68 }
69
70 Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const
71 {
72   HYDROData_Iterator anIt( doc(), theKind );
73   for( ; anIt.More(); anIt.Next() )
74   {
75     if( anIt.Current()->GetName() == theName )
76       return anIt.Current();
77   }
78   return Handle_HYDROData_Object();
79 }