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"
28 #include "HYDROGUI_OCCDisplayer.h"
30 #include <HYDROData_Document.h>
31 #include <HYDROData_Iterator.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Study.h>
40 #include <QApplication>
42 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
43 : LightApp_Operation(),
44 myModule( theModule ),
46 myIsPrintErrorMessage( true ),
47 myPreviewManager( 0 ),
50 connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
52 theModule->application(), SLOT( onHelpContextModule( const QString&,
53 const QString&, const QString& ) ) );
56 HYDROGUI_Operation::~HYDROGUI_Operation()
60 void HYDROGUI_Operation::setName( const QString& theName )
65 const QString& HYDROGUI_Operation::getName() const
70 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
74 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
75 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
76 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
77 connect( myPanel, SIGNAL( panelHelp() ), this, SLOT( onHelp() ) );
82 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
84 return myModule->getApp()->selectionMgr();
87 HYDROGUI_Module* HYDROGUI_Operation::module() const
93 * Returns Z layer of the operation preview.
94 \ returns a layer position
96 int HYDROGUI_Operation::getPreviewZLayer() const
98 return myPreviewZLayer;
102 * Set Z layer for the operation preview.
103 \param theLayer a layer position
105 void HYDROGUI_Operation::setPreviewZLayer( int theLayer )
107 if ( theLayer != myPreviewZLayer )
108 myPreviewZLayer = theLayer;
112 * Return the operation preview manager
114 OCCViewer_ViewManager* HYDROGUI_Operation::getPreviewManager()
116 return myPreviewManager;
120 * Set the preview manager
122 void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager )
124 if ( !theManager && myPreviewManager )
125 module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
127 myPreviewManager = theManager;
129 if ( myPreviewManager )
130 setPreviewZLayer( module()->getOCCDisplayer()->AddTopZLayer( myPreviewManager ) );
133 void HYDROGUI_Operation::startOperation()
135 LightApp_Operation::startOperation();
136 myModule->getActiveOperations().push( this );
140 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
141 inputPanel()->show();
145 void HYDROGUI_Operation::abortOperation()
147 LightApp_Operation::abortOperation();
151 void HYDROGUI_Operation::commitOperation()
153 LightApp_Operation::commitOperation();
157 void HYDROGUI_Operation::stopOperation()
159 LightApp_Operation::stopOperation();
161 // pop the operation from the cached map of active operations
162 QStack<HYDROGUI_Operation*>& anOperations = myModule->getActiveOperations();
163 if ( anOperations.top() == this )
168 // find in the stack the current operation and remove it from the stack
169 QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
171 aVIt.previous(); // skip the top show/hide operation
172 while ( aVIt.hasPrevious() )
174 HYDROGUI_Operation* anOp = aVIt.previous();
176 anOperations.remove( anOperations.lastIndexOf( anOp ) );
180 // removes the Z layer, created for the operation preview
181 if ( myPreviewManager && getPreviewZLayer() >= 0 )
182 module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
185 void HYDROGUI_Operation::setDialogActive( const bool active )
187 LightApp_Operation::setDialogActive( active );
197 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
202 void HYDROGUI_Operation::closeInputPanel()
206 myModule->getApp()->desktop()->removeDockWidget( myPanel );
212 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
213 QString& theErrorMsg )
218 void HYDROGUI_Operation::processCancel()
222 void HYDROGUI_Operation::startDocOperation()
224 // Open transaction in the model document
225 if ( !doc()->IsOperation() )
226 doc()->StartOperation();
229 void HYDROGUI_Operation::abortDocOperation()
231 // Abort transaction in the model document
232 if ( doc()->IsOperation() )
233 doc()->AbortOperation();
236 void HYDROGUI_Operation::commitDocOperation()
238 // Commit transaction in the model document
239 if ( doc()->IsOperation() )
240 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
243 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
245 return HYDROData_Document::Document( myModule->getStudyId() );
248 void HYDROGUI_Operation::onApply()
250 QApplication::setOverrideCursor( Qt::WaitCursor );
254 int anUpdateFlags = 0;
257 bool aResult = false;
261 aResult = processApply( anUpdateFlags, anErrorMsg );
263 catch ( Standard_Failure )
265 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
266 anErrorMsg = aFailure->GetMessageString();
274 QApplication::restoreOverrideCursor();
278 module()->update( anUpdateFlags );
279 commitDocOperation();
284 // Abort document opeartion only if requested
285 if ( isToAbortOnApply() )
288 printErrorMessage( anErrorMsg );
290 // If the operation has no input panel - do abort
291 if ( !inputPanel() ) {
297 void HYDROGUI_Operation::setPrintErrorMessage( const bool theIsPrint )
299 myIsPrintErrorMessage = theIsPrint;
302 void HYDROGUI_Operation::printErrorMessage( const QString& theErrorMsg )
304 if ( myIsPrintErrorMessage )
306 QString aMsg = tr( "INPUT_VALID_DATA" );
307 if( !theErrorMsg.isEmpty() )
308 aMsg.prepend( theErrorMsg + "\n" );
309 SUIT_MessageBox::critical( module()->getApp()->desktop(),
310 tr( "INSUFFICIENT_INPUT_DATA" ),
315 myIsPrintErrorMessage = true;
318 void HYDROGUI_Operation::onCancel()
324 void HYDROGUI_Operation::onHelp()
326 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
329 QString HYDROGUI_Operation::getHelpComponent() const
331 return module()->moduleName();
334 QString HYDROGUI_Operation::getHelpFile() const
336 QString aFileName = ((myName.isEmpty())? operationName() : myName);
337 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
340 QString HYDROGUI_Operation::getHelpContext() const