1 // Copyright (C) 2007-2008 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 SMDS : implementaion of Salome mesh data structure
23 // File : SMESHGUI_Operation.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_Operation.h"
30 #include "SMESHGUI_Dialog.h"
32 // SALOME GUI includes
33 #include <SalomeApp_Study.h>
34 #include <LightApp_Application.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_ResourceMgr.h>
42 #include <QStringList>
45 Class : SMESHGUI_Operation
46 Description : Base class for all SMESH operations
49 //=======================================================================
50 // name : SMESHGUI_Operation
51 // Purpose : Constructor
52 //=======================================================================
53 SMESHGUI_Operation::SMESHGUI_Operation()
54 : LightApp_Operation()
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()
168 //=======================================================================
171 //=======================================================================
172 bool SMESHGUI_Operation::onApply()
177 //=======================================================================
180 //=======================================================================
181 void SMESHGUI_Operation::onCancel()
186 //=======================================================================
189 //=======================================================================
190 void SMESHGUI_Operation::onHelp()
192 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
194 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
198 platform = "winapplication";
200 platform = "application";
202 SUIT_MessageBox::warning( desktop(), tr("WRN_WARNING"),
203 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
204 arg(app->resourceMgr()->stringValue("ExternalBrowser",
206 arg(myHelpFileName) );
210 //=======================================================================
213 //=======================================================================
214 void SMESHGUI_Operation::initDialog()
219 * \brief Verifies whether study of operation is locked
220 * \param theMess - specifies whether message box must be shown if study is locked
221 * \return State of study.
223 * Verifies whether study of operation is locked. If second parameter is TRUE and study
224 * is locked when corresponding message box appears
226 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
230 if ( studyDS()->GetProperties()->IsLocked() )
233 SUIT_MessageBox::warning( SMESHGUI::desktop(), tr( "WRN_WARNING" ),
234 tr( "WRN_STUDY_LOCKED" ) );
243 * \brief Verifies whether given operator is valid for this one
244 * \param theOtherOp - other operation
245 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
247 * Virtual method redefined from base class verifies whether given operator is valid for
248 * this one (i.e. can be started "above" this operator). In current implementation method
249 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
252 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
254 static QStringList anOps;
255 if ( anOps.count() == 0 )
257 anOps.append( "SMESHGUI_DeleteOp" );
258 // to do add other operations here
261 return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
262 ( !anOps.contains( theOtherOp->metaObject()->className() ) ||
263 anOps.contains( metaObject()->className() ) );