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"
29 #include "HYDROGUI_Shape.h"
31 #include <HYDROData_Document.h>
32 #include <HYDROData_Iterator.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Study.h>
41 #include <QApplication>
43 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
44 : LightApp_Operation(),
45 myModule( theModule ),
47 myIsPrintErrorMessage( true ),
48 myPreviewManager( 0 ),
51 connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
53 theModule->application(), SLOT( onHelpContextModule( const QString&,
54 const QString&, const QString& ) ) );
57 HYDROGUI_Operation::~HYDROGUI_Operation()
61 void HYDROGUI_Operation::setName( const QString& theName )
66 const QString& HYDROGUI_Operation::getName() const
71 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
75 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
76 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
77 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
78 connect( myPanel, SIGNAL( panelHelp() ), this, SLOT( onHelp() ) );
83 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
85 return myModule->getApp()->selectionMgr();
88 HYDROGUI_Module* HYDROGUI_Operation::module() const
94 * Returns Z layer of the operation preview.
95 \ returns a layer position
97 int HYDROGUI_Operation::getPreviewZLayer() const
99 return myPreviewZLayer;
103 * Update Z layer for the operation preview.
104 \param theLayer a layer position
106 void HYDROGUI_Operation::updatePreviewZLayer( int theLayer )
108 setPreviewZLayer( theLayer );
110 HYDROGUI_Shape* aPreview = getPreviewShape();
112 aPreview->setZLayer( getPreviewZLayer() );
116 * Set Z layer for the operation preview.
117 \param theLayer a layer position
119 void HYDROGUI_Operation::setPreviewZLayer( int theLayer )
121 if ( theLayer != myPreviewZLayer )
122 myPreviewZLayer = theLayer;
126 * Returns a shape preview of the operation
128 HYDROGUI_Shape* HYDROGUI_Operation::getPreviewShape() const
134 * Return the operation preview manager
136 OCCViewer_ViewManager* HYDROGUI_Operation::getPreviewManager()
138 return myPreviewManager;
142 * Set the preview manager
144 void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager )
146 if ( !theManager && myPreviewManager )
147 module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
149 myPreviewManager = theManager;
151 if ( myPreviewManager )
152 setPreviewZLayer( module()->getOCCDisplayer()->AddTopZLayer( myPreviewManager ) );
155 void HYDROGUI_Operation::startOperation()
157 LightApp_Operation::startOperation();
158 myModule->getActiveOperations().push( this );
162 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
163 inputPanel()->show();
167 void HYDROGUI_Operation::abortOperation()
169 LightApp_Operation::abortOperation();
173 void HYDROGUI_Operation::commitOperation()
175 LightApp_Operation::commitOperation();
179 void HYDROGUI_Operation::stopOperation()
181 LightApp_Operation::stopOperation();
183 // pop the operation from the cached map of active operations
184 QStack<HYDROGUI_Operation*>& anOperations = myModule->getActiveOperations();
185 if ( anOperations.top() == this )
190 // find in the stack the current operation and remove it from the stack
191 QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
193 aVIt.previous(); // skip the top show/hide operation
194 while ( aVIt.hasPrevious() )
196 HYDROGUI_Operation* anOp = aVIt.previous();
198 anOperations.remove( anOperations.lastIndexOf( anOp ) );
201 // release the preview manager with removing the added preview Z layer
202 setPreviewManager( 0 );
205 void HYDROGUI_Operation::setDialogActive( const bool active )
207 LightApp_Operation::setDialogActive( active );
217 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
222 void HYDROGUI_Operation::closeInputPanel()
226 myModule->getApp()->desktop()->removeDockWidget( myPanel );
232 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
233 QString& theErrorMsg )
238 void HYDROGUI_Operation::processCancel()
242 void HYDROGUI_Operation::startDocOperation()
244 // Open transaction in the model document
245 if ( !doc()->IsOperation() )
246 doc()->StartOperation();
249 void HYDROGUI_Operation::abortDocOperation()
251 // Abort transaction in the model document
252 if ( doc()->IsOperation() )
253 doc()->AbortOperation();
256 void HYDROGUI_Operation::commitDocOperation()
258 // Commit transaction in the model document
259 if ( doc()->IsOperation() )
260 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
263 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
265 return HYDROData_Document::Document( myModule->getStudyId() );
268 void HYDROGUI_Operation::onApply()
270 QApplication::setOverrideCursor( Qt::WaitCursor );
274 int anUpdateFlags = 0;
277 bool aResult = false;
281 aResult = processApply( anUpdateFlags, anErrorMsg );
283 catch ( Standard_Failure )
285 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
286 anErrorMsg = aFailure->GetMessageString();
294 QApplication::restoreOverrideCursor();
298 module()->update( anUpdateFlags );
299 commitDocOperation();
304 // Abort document opeartion only if requested
305 if ( isToAbortOnApply() )
308 printErrorMessage( anErrorMsg );
310 // If the operation has no input panel - do abort
311 if ( !inputPanel() ) {
317 void HYDROGUI_Operation::setPrintErrorMessage( const bool theIsPrint )
319 myIsPrintErrorMessage = theIsPrint;
322 void HYDROGUI_Operation::printErrorMessage( const QString& theErrorMsg )
324 if ( myIsPrintErrorMessage )
326 QString aMsg = tr( "INPUT_VALID_DATA" );
327 if( !theErrorMsg.isEmpty() )
328 aMsg.prepend( theErrorMsg + "\n" );
329 SUIT_MessageBox::critical( module()->getApp()->desktop(),
330 tr( "INSUFFICIENT_INPUT_DATA" ),
335 myIsPrintErrorMessage = true;
338 void HYDROGUI_Operation::onCancel()
344 void HYDROGUI_Operation::onHelp()
346 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
349 QString HYDROGUI_Operation::getHelpComponent() const
351 return module()->moduleName();
354 QString HYDROGUI_Operation::getHelpFile() const
356 QString aFileName = ((myName.isEmpty())? operationName() : myName);
357 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
360 QString HYDROGUI_Operation::getHelpContext() const