1 // Copyright (C) 2007-2010 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
22 // SMESH SMESHGUI : implementaion of Salome mesh GUI
23 // File : SMESHGUI_Operation.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_Operation.h"
29 #include "SMESHGUI_Dialog.h"
31 // SALOME GUI includes
32 #include <SalomeApp_Study.h>
33 #include <LightApp_Application.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ResourceMgr.h>
41 #include <QStringList>
44 Class : SMESHGUI_Operation
45 Description : Base class for all SMESH operations
48 //=======================================================================
49 // name : SMESHGUI_Operation
50 // Purpose : Constructor
51 //=======================================================================
52 SMESHGUI_Operation::SMESHGUI_Operation()
53 : LightApp_Operation(),
54 myIsApplyAndClose( false )
59 //=======================================================================
60 // name : ~SMESHGUI_Operation
61 // Purpose : Destructor
62 //=======================================================================
63 SMESHGUI_Operation::~SMESHGUI_Operation()
67 //=======================================================================
69 // Purpose : Get SMESH module
70 //=======================================================================
71 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
73 return dynamic_cast<SMESHGUI*>( module() );
76 //=======================================================================
77 // name : startOperation
78 // Purpose : Start opeartion
79 //=======================================================================
80 void SMESHGUI_Operation::startOperation()
84 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
85 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
86 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
87 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
88 disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
90 if( dlg()->testButtonFlags( QtxDialog::OK ) )
91 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
93 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
94 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
96 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
97 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
99 if( dlg()->testButtonFlags( QtxDialog::Help ) )
100 connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
102 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
103 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
104 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
109 LightApp_Operation::startOperation();
112 //=======================================================================
113 // name : isReadyToStart
114 // Purpose : Verify whether operation is ready to start
115 //=======================================================================
116 bool SMESHGUI_Operation::isReadyToStart() const
118 if ( !LightApp_Operation::isReadyToStart() )
120 else if ( getSMESHGUI() == 0 )
122 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
126 else if ( isStudyLocked() )
132 //=======================================================================
133 // name : setDialogActive
135 //=======================================================================
136 void SMESHGUI_Operation::setDialogActive( const bool active )
138 LightApp_Operation::setDialogActive( active );
140 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
142 d->setContentActive( active );
146 //=======================================================================
149 //=======================================================================
150 _PTR(Study) SMESHGUI_Operation::studyDS() const
152 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
156 //=======================================================================
159 //=======================================================================
160 void SMESHGUI_Operation::onOk()
162 setIsApplyAndClose( true );
165 setIsApplyAndClose( false );
170 //=======================================================================
173 //=======================================================================
174 bool SMESHGUI_Operation::onApply()
179 //=======================================================================
182 //=======================================================================
183 void SMESHGUI_Operation::onCancel()
188 //=======================================================================
191 //=======================================================================
192 void SMESHGUI_Operation::onHelp()
194 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
196 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
200 platform = "winapplication";
202 platform = "application";
204 SUIT_MessageBox::warning( desktop(), tr("WRN_WARNING"),
205 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
206 arg(app->resourceMgr()->stringValue("ExternalBrowser",
208 arg(myHelpFileName) );
212 //=======================================================================
215 //=======================================================================
216 void SMESHGUI_Operation::initDialog()
220 //================================================================
221 // name : setIsApplyAndClose
222 // Purpose : Set value of the flag indicating that the dialog is
223 // accepted by Apply & Close button
224 //================================================================
225 void SMESHGUI_Operation::setIsApplyAndClose( const bool theFlag )
227 myIsApplyAndClose = theFlag;
230 //================================================================
231 // name : isApplyAndClose
232 // Purpose : Get value of the flag indicating that the dialog is
233 // accepted by Apply & Close button
234 //================================================================
235 bool SMESHGUI_Operation::isApplyAndClose() const
237 return myIsApplyAndClose;
241 * \brief Verifies whether study of operation is locked
242 * \param theMess - specifies whether message box must be shown if study is locked
243 * \return State of study.
245 * Verifies whether study of operation is locked. If second parameter is TRUE and study
246 * is locked when corresponding message box appears
248 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
252 if ( studyDS()->GetProperties()->IsLocked() )
255 SUIT_MessageBox::warning( SMESHGUI::desktop(), tr( "WRN_WARNING" ),
256 tr( "WRN_STUDY_LOCKED" ) );
265 * \brief Verifies whether given operator is valid for this one
266 * \param theOtherOp - other operation
267 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
269 * Virtual method redefined from base class verifies whether given operator is valid for
270 * this one (i.e. can be started "above" this operator). In current implementation method
271 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
274 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
276 static QStringList anOps;
277 if ( anOps.count() == 0 )
279 anOps.append( "SMESHGUI_DeleteOp" );
280 // to do add other operations here
283 return ( theOtherOp &&
284 ( ( theOtherOp->inherits("SMESHGUI_Operation") && ( !anOps.contains(theOtherOp->metaObject()->className() ) || anOps.contains(metaObject()->className()) ) ) ||
285 ( theOtherOp->inherits("LightApp_ShowHideOp") ) ) );