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 ),
45 myIsPrintErrorMessage( true )
47 connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
49 theModule->application(), SLOT( onHelpContextModule( const QString&,
50 const QString&, const QString& ) ) );
53 HYDROGUI_Operation::~HYDROGUI_Operation()
57 void HYDROGUI_Operation::setName( const QString& theName )
62 const QString& HYDROGUI_Operation::getName() const
67 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
71 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
72 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
73 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
74 connect( myPanel, SIGNAL( panelHelp() ), this, SLOT( onHelp() ) );
79 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
81 return myModule->getApp()->selectionMgr();
84 HYDROGUI_Module* HYDROGUI_Operation::module() const
89 void HYDROGUI_Operation::startOperation()
91 LightApp_Operation::startOperation();
95 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
100 void HYDROGUI_Operation::abortOperation()
102 LightApp_Operation::abortOperation();
106 void HYDROGUI_Operation::commitOperation()
108 LightApp_Operation::commitOperation();
112 void HYDROGUI_Operation::setDialogActive( const bool active )
114 LightApp_Operation::setDialogActive( active );
124 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
129 void HYDROGUI_Operation::closeInputPanel()
133 myModule->getApp()->desktop()->removeDockWidget( myPanel );
139 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
140 QString& theErrorMsg )
145 void HYDROGUI_Operation::processCancel()
149 void HYDROGUI_Operation::startDocOperation()
151 // Open transaction in the model document
152 if ( !doc()->IsOperation() )
153 doc()->StartOperation();
156 void HYDROGUI_Operation::abortDocOperation()
158 // Abort transaction in the model document
159 if ( doc()->IsOperation() )
160 doc()->AbortOperation();
163 void HYDROGUI_Operation::commitDocOperation()
165 // Commit transaction in the model document
166 if ( doc()->IsOperation() )
167 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
170 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
172 return HYDROData_Document::Document( myModule->getStudyId() );
175 void HYDROGUI_Operation::onApply()
177 QApplication::setOverrideCursor( Qt::WaitCursor );
181 int anUpdateFlags = 0;
184 bool aResult = false;
188 aResult = processApply( anUpdateFlags, anErrorMsg );
190 catch ( Standard_Failure )
192 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
193 anErrorMsg = aFailure->GetMessageString();
201 QApplication::restoreOverrideCursor();
205 module()->update( anUpdateFlags );
206 commitDocOperation();
211 // Abort document opeartion only if requested
212 if ( isToAbortOnApply() )
215 printErrorMessage( anErrorMsg );
217 // If the operation has no input panel - do abort
218 if ( !inputPanel() ) {
224 void HYDROGUI_Operation::setPrintErrorMessage( const bool theIsPrint )
226 myIsPrintErrorMessage = theIsPrint;
229 void HYDROGUI_Operation::printErrorMessage( const QString& theErrorMsg )
231 if ( myIsPrintErrorMessage )
233 QString aMsg = tr( "INPUT_VALID_DATA" );
234 if( !theErrorMsg.isEmpty() )
235 aMsg.prepend( theErrorMsg + "\n" );
236 SUIT_MessageBox::critical( module()->getApp()->desktop(),
237 tr( "INSUFFICIENT_INPUT_DATA" ),
242 myIsPrintErrorMessage = true;
245 void HYDROGUI_Operation::onCancel()
251 void HYDROGUI_Operation::onHelp()
253 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
256 QString HYDROGUI_Operation::getHelpComponent() const
258 return module()->moduleName();
261 QString HYDROGUI_Operation::getHelpFile() const
263 QString aFileName = ((myName.isEmpty())? operationName() : myName);
264 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
267 QString HYDROGUI_Operation::getHelpContext() const