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.empty() ) {
186 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 ) );
202 // release the preview manager with removing the added preview Z layer
203 setPreviewManager( 0 );
206 void HYDROGUI_Operation::setDialogActive( const bool active )
208 LightApp_Operation::setDialogActive( active );
218 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
223 void HYDROGUI_Operation::closeInputPanel()
227 myModule->getApp()->desktop()->removeDockWidget( myPanel );
233 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
234 QString& theErrorMsg )
239 void HYDROGUI_Operation::processCancel()
243 void HYDROGUI_Operation::startDocOperation()
245 // Open transaction in the model document
246 if ( !doc()->IsOperation() )
247 doc()->StartOperation();
250 void HYDROGUI_Operation::abortDocOperation()
252 // Abort transaction in the model document
253 if ( doc()->IsOperation() )
254 doc()->AbortOperation();
257 void HYDROGUI_Operation::commitDocOperation()
259 // Commit transaction in the model document
260 if ( doc()->IsOperation() )
261 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
264 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
266 return HYDROData_Document::Document( myModule->getStudyId() );
269 void HYDROGUI_Operation::onApply()
271 QApplication::setOverrideCursor( Qt::WaitCursor );
275 int anUpdateFlags = 0;
278 bool aResult = false;
282 aResult = processApply( anUpdateFlags, anErrorMsg );
284 catch ( Standard_Failure )
286 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
287 anErrorMsg = aFailure->GetMessageString();
295 QApplication::restoreOverrideCursor();
299 module()->update( anUpdateFlags );
300 commitDocOperation();
305 // Abort document opeartion only if requested
306 if ( isToAbortOnApply() )
309 printErrorMessage( anErrorMsg );
311 // If the operation has no input panel - do abort
312 if ( !inputPanel() ) {
318 void HYDROGUI_Operation::setPrintErrorMessage( const bool theIsPrint )
320 myIsPrintErrorMessage = theIsPrint;
323 void HYDROGUI_Operation::printErrorMessage( const QString& theErrorMsg )
325 if ( myIsPrintErrorMessage )
327 QString aMsg = tr( "INPUT_VALID_DATA" );
328 if( !theErrorMsg.isEmpty() )
329 aMsg.prepend( theErrorMsg + "\n" );
330 SUIT_MessageBox::critical( module()->getApp()->desktop(),
331 tr( "INSUFFICIENT_INPUT_DATA" ),
336 myIsPrintErrorMessage = true;
339 void HYDROGUI_Operation::onCancel()
345 void HYDROGUI_Operation::onHelp()
347 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
350 QString HYDROGUI_Operation::getHelpComponent() const
352 return module()->moduleName();
355 QString HYDROGUI_Operation::getHelpFile() const
357 QString aFileName = ((myName.isEmpty())? operationName() : myName);
358 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
361 QString HYDROGUI_Operation::getHelpContext() const