]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Operation.cxx
Salome HOME
b19684ab4b6fbed37f84bf2509419e76b7617a90
[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
25 #include "HYDROGUI_InputPanel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Iterator.h>
31
32 #include <LightApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Study.h>
38
39 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
40 : LightApp_Operation(),
41   myModule( theModule ),
42   myPanel( 0 )
43 {
44 }
45
46 HYDROGUI_Operation::~HYDROGUI_Operation()
47 {
48 }
49
50 void HYDROGUI_Operation::setName( const QString& theName )
51 {
52   myName = theName;
53 }
54
55 const QString& HYDROGUI_Operation::getName() const
56 {
57   return myName;
58 }
59
60 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
61 {
62   if( !myPanel )
63   {
64     ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
65     connect( myPanel, SIGNAL( panelApply() ),  this, SLOT( onApply() ) );
66     connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
67   }
68   return myPanel;
69 }
70
71 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
72 {
73   return myModule->getApp()->selectionMgr();
74 }
75
76 HYDROGUI_Module* HYDROGUI_Operation::module() const
77 {
78   return myModule;
79 }
80
81 void HYDROGUI_Operation::startOperation()
82 {
83   LightApp_Operation::startOperation();
84
85   doc()->StartOperation();
86
87   if( inputPanel() )
88   {
89     myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
90     inputPanel()->show();
91   }
92 }
93
94 void HYDROGUI_Operation::abortOperation()
95 {
96   doc()->AbortOperation();
97
98   LightApp_Operation::abortOperation();
99
100   if( inputPanel() )
101     inputPanel()->hide();
102 }
103
104 void HYDROGUI_Operation::commitOperation()
105 {
106   doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
107
108   LightApp_Operation::commitOperation();
109
110   if( inputPanel() )
111     inputPanel()->hide();
112 }
113
114 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
115 {
116   return NULL;
117 }
118
119 bool HYDROGUI_Operation::processApply( int& theUpdateFlags )
120 {
121   return false;
122 }
123
124 void HYDROGUI_Operation::processCancel()
125 {
126 }
127
128 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
129 {
130   int aStudyId = myModule->application()->activeStudy()->id();
131   return HYDROData_Document::Document( aStudyId );
132 }
133
134 Handle_HYDROData_Object HYDROGUI_Operation::findObjectByName( const QString& theName, int theKind ) const
135 {
136   HYDROData_Iterator anIt( doc(), theKind );
137   for( ; anIt.More(); anIt.Next() )
138   {
139     if( anIt.Current()->GetName() == theName )
140       return anIt.Current();
141   }
142   return Handle_HYDROData_Object();
143 }
144
145 void HYDROGUI_Operation::onApply()
146 {
147   int anUpdateFlags = 0;
148   if( processApply( anUpdateFlags ) )
149   {
150     module()->update( anUpdateFlags );
151     commit();
152   }
153   else
154   {
155     SUIT_MessageBox::critical( module()->getApp()->desktop(),
156                                tr( "INSUFFICIENT_INPUT_DATA" ),
157                                tr( "INPUT_VALID_DATA" ) ); 
158   }
159 }
160
161 void HYDROGUI_Operation::onCancel()
162 {
163   processCancel();
164   abort();
165 }