1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Operation.h"
25 #include "HYDROGUI_InputPanel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Iterator.h>
32 #include <LightApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Study.h>
39 #include <QApplication>
41 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
42 : LightApp_Operation(),
43 myModule( theModule ),
48 HYDROGUI_Operation::~HYDROGUI_Operation()
52 void HYDROGUI_Operation::setName( const QString& theName )
57 const QString& HYDROGUI_Operation::getName() const
62 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
66 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
67 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
68 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
73 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
75 return myModule->getApp()->selectionMgr();
78 HYDROGUI_Module* HYDROGUI_Operation::module() const
83 void HYDROGUI_Operation::startOperation()
85 LightApp_Operation::startOperation();
89 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
94 void HYDROGUI_Operation::abortOperation()
96 LightApp_Operation::abortOperation();
100 void HYDROGUI_Operation::commitOperation()
102 LightApp_Operation::commitOperation();
106 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
111 void HYDROGUI_Operation::closeInputPanel()
115 myModule->getApp()->desktop()->removeDockWidget( myPanel );
121 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
122 QString& theErrorMsg )
127 void HYDROGUI_Operation::processCancel()
131 void HYDROGUI_Operation::startDocOperation()
133 // Open transaction in the model document
134 doc()->StartOperation();
137 void HYDROGUI_Operation::abortDocOperation()
139 // Abort transaction in the model document
140 doc()->AbortOperation();
143 void HYDROGUI_Operation::commitDocOperation()
145 // Commit transaction in the model document
146 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
149 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
151 return HYDROData_Document::Document( myModule->getStudyId() );
154 void HYDROGUI_Operation::onApply()
156 QApplication::setOverrideCursor( Qt::WaitCursor );
160 int anUpdateFlags = 0;
163 bool aResult = false;
167 aResult = processApply( anUpdateFlags, anErrorMsg );
169 catch ( Standard_Failure )
171 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
172 anErrorMsg = aFailure->GetMessageString();
180 QApplication::restoreOverrideCursor();
184 module()->update( anUpdateFlags );
185 commitDocOperation();
191 QString aMsg = tr( "INPUT_VALID_DATA" );
192 if( !anErrorMsg.isEmpty() )
193 aMsg.prepend( anErrorMsg + "\n" );
194 SUIT_MessageBox::critical( module()->getApp()->desktop(),
195 tr( "INSUFFICIENT_INPUT_DATA" ),
200 void HYDROGUI_Operation::onCancel()