1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 myIsTransactionOpened( false ),
49 myPreviewManager( 0 ),
52 connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
54 theModule->application(), SLOT( onHelpContextModule( const QString&,
55 const QString&, const QString& ) ) );
58 HYDROGUI_Operation::~HYDROGUI_Operation()
62 void HYDROGUI_Operation::setName( const QString& theName )
67 const QString& HYDROGUI_Operation::getName() const
72 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
76 ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
77 connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) );
78 connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
79 connect( myPanel, SIGNAL( panelHelp() ), this, SLOT( onHelp() ) );
84 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
86 return myModule->getApp()->selectionMgr();
89 HYDROGUI_Module* HYDROGUI_Operation::module() const
95 * Returns Z layer of the operation preview.
96 \ returns a layer position
98 int HYDROGUI_Operation::getPreviewZLayer() const
100 return myPreviewZLayer;
104 * Update Z layer for the operation preview.
105 \param theLayer a layer position
107 void HYDROGUI_Operation::updatePreviewZLayer( int theLayer )
109 setPreviewZLayer( theLayer );
111 HYDROGUI_Shape* aPreview = getPreviewShape();
113 aPreview->setZLayer( getPreviewZLayer() );
117 * Set Z layer for the operation preview.
118 \param theLayer a layer position
120 void HYDROGUI_Operation::setPreviewZLayer( int theLayer )
122 if ( theLayer != myPreviewZLayer )
123 myPreviewZLayer = theLayer;
127 * Returns a shape preview of the operation
129 HYDROGUI_Shape* HYDROGUI_Operation::getPreviewShape() const
135 * Return the operation preview manager
137 OCCViewer_ViewManager* HYDROGUI_Operation::getPreviewManager()
139 return myPreviewManager;
143 * Set the preview manager
145 void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager )
147 //No good: preview Z layer could be used by usual presentations
148 //if ( !theManager && myPreviewManager )
149 // module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
151 myPreviewManager = theManager;
153 if ( myPreviewManager )
154 setPreviewZLayer( module()->getOCCDisplayer()->AddPreviewZLayer( myPreviewManager ) );
157 void HYDROGUI_Operation::startOperation()
159 LightApp_Operation::startOperation();
160 myModule->getActiveOperations().push( this );
164 myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
165 inputPanel()->show();
169 void HYDROGUI_Operation::abortOperation()
171 LightApp_Operation::abortOperation();
175 void HYDROGUI_Operation::commitOperation()
177 LightApp_Operation::commitOperation();
181 void HYDROGUI_Operation::stopOperation()
183 LightApp_Operation::stopOperation();
185 // pop the operation from the cached map of active operations
186 QStack<HYDROGUI_Operation*>& anOperations = myModule->getActiveOperations();
187 if ( !anOperations.empty() ) {
188 if ( anOperations.top() == this )
192 // find in the stack the current operation and remove it from the stack
193 QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
195 aVIt.previous(); // skip the top show/hide operation
196 while ( aVIt.hasPrevious() )
198 HYDROGUI_Operation* anOp = aVIt.previous();
200 anOperations.remove( anOperations.lastIndexOf( anOp ) );
204 // release the preview manager with removing the added preview Z layer
205 setPreviewManager( 0 );
208 void HYDROGUI_Operation::setDialogActive( const bool active )
210 LightApp_Operation::setDialogActive( active );
220 HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const
225 void HYDROGUI_Operation::closeInputPanel()
229 myModule->getApp()->desktop()->removeDockWidget( myPanel );
235 bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
236 QString& theErrorMsg,
237 QStringList& theBrowseObjectsEntries )
242 void HYDROGUI_Operation::processCancel()
246 void HYDROGUI_Operation::startDocOperation()
248 // Open transaction in the model document only if it not
249 // already opened by other operation (intended for nested operations)
250 if ( !doc()->IsOperation() )
252 doc()->StartOperation();
253 myIsTransactionOpened = true;
257 void HYDROGUI_Operation::abortDocOperation()
259 // Abort transaction in the model document only if it was
260 // opened by this operation (intended for nested operations)
261 if ( myIsTransactionOpened && doc()->IsOperation() )
263 doc()->AbortOperation();
264 myIsTransactionOpened = false;
268 void HYDROGUI_Operation::commitDocOperation()
270 // Commit transaction in the model document only if it was
271 // opened by this operation (intended for nested operations)
272 if ( myIsTransactionOpened && doc()->IsOperation() )
274 doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
275 myIsTransactionOpened = false;
279 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
281 return HYDROData_Document::Document( myModule->getStudyId() );
284 void HYDROGUI_Operation::onApply()
286 QApplication::setOverrideCursor( Qt::WaitCursor );
290 int anUpdateFlags = 0;
293 bool aResult = false;
294 QStringList aBrowseObjectsEntries;
298 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
300 catch ( Standard_Failure )
302 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
303 anErrorMsg = aFailure->GetMessageString();
311 QApplication::restoreOverrideCursor();
315 module()->update( anUpdateFlags );
316 commitDocOperation();
318 browseObjects( aBrowseObjectsEntries );
322 // Abort document opeartion only if requested
323 if ( isToAbortOnApply() )
326 printErrorMessage( anErrorMsg );
328 // If the operation has no input panel - do abort
329 if ( !inputPanel() ) {
335 void HYDROGUI_Operation::setPrintErrorMessage( const bool theIsPrint )
337 myIsPrintErrorMessage = theIsPrint;
340 void HYDROGUI_Operation::printErrorMessage( const QString& theErrorMsg )
342 if ( myIsPrintErrorMessage )
344 QString aMsg = tr( "INPUT_VALID_DATA" );
345 if( !theErrorMsg.isEmpty() )
346 aMsg.prepend( theErrorMsg + "\n" );
347 SUIT_MessageBox::critical( module()->getApp()->desktop(),
348 tr( "INSUFFICIENT_INPUT_DATA" ),
353 myIsPrintErrorMessage = true;
356 void HYDROGUI_Operation::onCancel()
362 void HYDROGUI_Operation::onHelp()
364 emit helpContextModule( getHelpComponent(), getHelpFile(), getHelpContext() );
367 QString HYDROGUI_Operation::getHelpComponent() const
369 return module()->moduleName();
372 QString HYDROGUI_Operation::getHelpFile() const
374 QString aFileName = ((myName.isEmpty())? operationName() : myName);
375 return aFileName.replace(QRegExp("\\s"), "_").append(".html");
378 QString HYDROGUI_Operation::getHelpContext() const
383 void HYDROGUI_Operation::browseObjects( const QStringList& theBrowseObjectsEntries )
385 bool isApplyAndClose = true;
386 bool isOptimizedBrowse = true;
387 module()->getApp()->browseObjects( theBrowseObjectsEntries, isApplyAndClose, isOptimizedBrowse );