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 ),
46 connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
48 theModule->application(), SLOT( onHelpContextModule( const QString&,
49 const QString&, const QString& ) ) );
52 HYDROGUI_Operation::~HYDROGUI_Operation()
56 void HYDROGUI_Operation::setName( const QString& theName )
61 const QString& HYDROGUI_Operation::getName() const
66 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
70 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
71 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
72 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
73 connect( myPanel, SIGNAL( panelHelp() ), this, SLOT( onHelp() ) );
78 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
80 return myModule->getApp()->selectionMgr();
83 HYDROGUI_Module* HYDROGUI_Operation::module() const
88 void HYDROGUI_Operation::startOperation()
90 LightApp_Operation::startOperation();
94 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
99 void HYDROGUI_Operation::abortOperation()
101 LightApp_Operation::abortOperation();
105 void HYDROGUI_Operation::commitOperation()
107 LightApp_Operation::commitOperation();
111 void HYDROGUI_Operation::setDialogActive( const bool active )
113 LightApp_Operation::setDialogActive( active );
123 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
128 void HYDROGUI_Operation::closeInputPanel()
132 myModule->getApp()->desktop()->removeDockWidget( myPanel );
138 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
139 QString& theErrorMsg )
144 void HYDROGUI_Operation::processCancel()
148 void HYDROGUI_Operation::startDocOperation()
150 // Open transaction in the model document
151 if ( !doc()->IsOperation() )
152 doc()->StartOperation();
155 void HYDROGUI_Operation::abortDocOperation()
157 // Abort transaction in the model document
158 if ( doc()->IsOperation() )
159 doc()->AbortOperation();
162 void HYDROGUI_Operation::commitDocOperation()
164 // Commit transaction in the model document
165 if ( doc()->IsOperation() )
166 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
169 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
171 return HYDROData_Document::Document( myModule->getStudyId() );
174 void HYDROGUI_Operation::onApply()
176 QApplication::setOverrideCursor( Qt::WaitCursor );
180 int anUpdateFlags = 0;
183 bool aResult = false;
187 aResult = processApply( anUpdateFlags, anErrorMsg );
189 catch ( Standard_Failure )
191 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
192 anErrorMsg = aFailure->GetMessageString();
200 QApplication::restoreOverrideCursor();
204 module()->update( anUpdateFlags );
205 commitDocOperation();
211 QString aMsg = tr( "INPUT_VALID_DATA" );
212 if( !anErrorMsg.isEmpty() )
213 aMsg.prepend( anErrorMsg + "\n" );
214 SUIT_MessageBox::critical( module()->getApp()->desktop(),
215 tr( "INSUFFICIENT_INPUT_DATA" ),
220 void HYDROGUI_Operation::onCancel()
226 void HYDROGUI_Operation::onHelp()
228 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
231 QString HYDROGUI_Operation::getHelpComponent() const
233 return module()->moduleName();
236 QString HYDROGUI_Operation::getHelpFile() const
238 QString aFileName = ((myName.isEmpty())? operationName() : myName);
239 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
242 QString HYDROGUI_Operation::getHelpContext() const