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.h
24 // Author : Sergey LITONIN
27 #include "SMESHGUI_Operation.h"
29 #include <SMESHGUI_Dialog.h>
31 #include <SalomeApp_Study.h>
32 #include <LightApp_Application.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Desktop.h>
38 #include <qstringlist.h>
41 Class : SMESHGUI_Operation
42 Description : Base class for all SMESH operations
45 //=======================================================================
46 // name : SMESHGUI_Operation
47 // Purpose : Constructor
48 //=======================================================================
49 SMESHGUI_Operation::SMESHGUI_Operation()
50 : LightApp_Operation()
55 //=======================================================================
56 // name : ~SMESHGUI_Operation
57 // Purpose : Destructor
58 //=======================================================================
59 SMESHGUI_Operation::~SMESHGUI_Operation()
63 //=======================================================================
65 // Purpose : Get SMESH module
66 //=======================================================================
67 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
69 return dynamic_cast<SMESHGUI*>( module() );
72 //=======================================================================
73 // name : startOperation
74 // Purpose : Start opeartion
75 //=======================================================================
76 void SMESHGUI_Operation::startOperation()
80 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
81 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
82 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
83 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
84 disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
86 // dlg()->setButtonText(1, "&Ok"); //rename Apply and Close to OK
88 if( dlg()->testButtonFlags( QtxDialog::OK ) )
89 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
91 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
92 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
94 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
95 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
97 if( dlg()->testButtonFlags( QtxDialog::Help ) )
98 connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
100 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
101 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
102 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
107 LightApp_Operation::startOperation();
110 //=======================================================================
111 // name : isReadyToStart
112 // Purpose : Verify whether operation is ready to start
113 //=======================================================================
114 bool SMESHGUI_Operation::isReadyToStart() const
116 if ( !LightApp_Operation::isReadyToStart() )
118 else if ( getSMESHGUI() == 0 )
120 SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
121 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
124 else if ( isStudyLocked() )
130 //=======================================================================
131 // name : setDialogActive
133 //=======================================================================
134 void SMESHGUI_Operation::setDialogActive( const bool active )
136 LightApp_Operation::setDialogActive( active );
138 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
140 d->setContentActive( active );
144 //=======================================================================
147 //=======================================================================
148 _PTR(Study) SMESHGUI_Operation::studyDS() const
150 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
154 //=======================================================================
157 //=======================================================================
158 void SMESHGUI_Operation::onOk()
166 //=======================================================================
169 //=======================================================================
170 bool SMESHGUI_Operation::onApply()
175 //=======================================================================
178 //=======================================================================
179 void SMESHGUI_Operation::onCancel()
184 //=======================================================================
187 //=======================================================================
188 void SMESHGUI_Operation::onHelp()
190 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
192 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
196 platform = "winapplication";
198 platform = "application";
200 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
201 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
202 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
203 QObject::tr("BUT_OK"));
207 //=======================================================================
210 //=======================================================================
211 void SMESHGUI_Operation::initDialog()
216 * \brief Verifies whether study of operation is locked
217 * \param theMess - specifies whether message box must be shown if study is locked
218 * \return State of study.
220 * Verifies whether study of operation is locked. If second parameter is TRUE and study
221 * is locked when corresponding message box appears
223 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
227 if ( studyDS()->GetProperties()->IsLocked() )
230 SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
231 QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
240 * \brief Verifies whether given operator is valid for this one
241 * \param theOtherOp - other operation
242 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
244 * Virtual method redefined from base class verifies whether given operator is valid for
245 * this one (i.e. can be started "above" this operator). In current implementation method
246 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
249 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
251 static QStringList anOps;
252 if ( anOps.count() == 0 )
254 anOps.append( "SMESHGUI_DeleteOp" );
255 // to do add other operations here
258 return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
259 ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );