]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Operation.cxx
Salome HOME
1) HYDRO: Import Image operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operation.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Operation.h"
24 #include "HYDROGUI_Module.h"
25 #include "HYDROGUI_InputPanel.h"
26
27 #include <HYDROData_Document.h>
28 #include <HYDROData_Iterator.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Study.h>
35
36 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
37 : LightApp_Operation(), myModule( theModule ), myPanel( 0 )
38 {
39 }
40
41 HYDROGUI_Operation::~HYDROGUI_Operation()
42 {
43 }
44
45 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
46 {
47   return myModule->getApp()->selectionMgr();
48 }
49
50 HYDROGUI_Module* HYDROGUI_Operation::module() const
51 {
52   return myModule;
53 }
54
55 void HYDROGUI_Operation::startOperation()
56 {
57   LightApp_Operation::startOperation();
58
59   doc()->StartOperation();
60
61   if( inputPanel() )
62   {
63     inputPanel()->show();
64     myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
65   }
66 }
67
68 void HYDROGUI_Operation::abortOperation()
69 {
70   doc()->AbortOperation();
71
72   LightApp_Operation::abortOperation();
73
74   if( inputPanel() )
75     inputPanel()->hide();
76 }
77
78 void HYDROGUI_Operation::commitOperation()
79 {
80   doc()->CommitOperation();
81
82   LightApp_Operation::commitOperation();
83
84   if( inputPanel() )
85     inputPanel()->hide();
86 }
87
88 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
89 {
90   if( !myPanel )
91   {
92     ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
93     connect( myPanel, SIGNAL( panelApply() ),  this, SLOT( OnApply() ) );
94     connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( OnCancel() ) );
95   }
96   return myPanel;
97 }
98
99 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
100 {
101   int aStudyId = myModule->application()->activeStudy()->id();
102   return HYDROData_Document::Document( aStudyId );
103 }
104
105 void HYDROGUI_Operation::OnApply()
106 {
107   doc()->CommitOperation();
108   inputPanel()->hide();
109 }
110
111 void HYDROGUI_Operation::OnCancel()
112 {
113   doc()->AbortOperation();
114   inputPanel()->hide();
115 }
116
117 Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const
118 {
119   HYDROData_Iterator anIt( doc(), theKind );
120   for( ; anIt.More(); anIt.Next() )
121   {
122     if( anIt.Current()->GetName() == theName )
123       return anIt.Current();
124   }
125   return Handle_HYDROData_Object();
126 }