1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SMESHGUI_Operation.h
22 // Author : Sergey LITONIN
25 #include "SMESHGUI_Operation.h"
27 #include <SMESHGUI_Dialog.h>
29 #include <SalomeApp_Study.h>
30 #include <LightApp_Application.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Desktop.h>
36 #include <qstringlist.h>
39 Class : SMESHGUI_Operation
40 Description : Base class for all SMESH operations
43 //=======================================================================
44 // name : SMESHGUI_Operation
45 // Purpose : Constructor
46 //=======================================================================
47 SMESHGUI_Operation::SMESHGUI_Operation()
48 : LightApp_Operation()
53 //=======================================================================
54 // name : ~SMESHGUI_Operation
55 // Purpose : Destructor
56 //=======================================================================
57 SMESHGUI_Operation::~SMESHGUI_Operation()
61 //=======================================================================
63 // Purpose : Get SMESH module
64 //=======================================================================
65 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
67 return dynamic_cast<SMESHGUI*>( module() );
70 //=======================================================================
71 // name : startOperation
72 // Purpose : Start opeartion
73 //=======================================================================
74 void SMESHGUI_Operation::startOperation()
78 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
79 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
80 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
81 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
82 disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
84 // dlg()->setButtonText(1, "&Ok"); //rename Apply and Close to OK
86 if( dlg()->testButtonFlags( QtxDialog::OK ) )
87 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
89 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
90 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
92 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
93 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
95 if( dlg()->testButtonFlags( QtxDialog::Help ) )
96 connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
98 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
99 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
100 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
105 LightApp_Operation::startOperation();
108 //=======================================================================
109 // name : isReadyToStart
110 // Purpose : Verify whether operation is ready to start
111 //=======================================================================
112 bool SMESHGUI_Operation::isReadyToStart() const
114 if ( !LightApp_Operation::isReadyToStart() )
116 else if ( getSMESHGUI() == 0 )
118 SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
119 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
122 else if ( isStudyLocked() )
128 //=======================================================================
129 // name : setDialogActive
131 //=======================================================================
132 void SMESHGUI_Operation::setDialogActive( const bool active )
134 LightApp_Operation::setDialogActive( active );
136 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
138 d->setContentActive( active );
142 //=======================================================================
145 //=======================================================================
146 _PTR(Study) SMESHGUI_Operation::studyDS() const
148 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
152 //=======================================================================
155 //=======================================================================
156 void SMESHGUI_Operation::onOk()
164 //=======================================================================
167 //=======================================================================
168 bool SMESHGUI_Operation::onApply()
173 //=======================================================================
176 //=======================================================================
177 void SMESHGUI_Operation::onCancel()
182 //=======================================================================
185 //=======================================================================
186 void SMESHGUI_Operation::onHelp()
188 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
190 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
194 platform = "winapplication";
196 platform = "application";
198 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
199 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
200 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
201 QObject::tr("BUT_OK"));
205 //=======================================================================
208 //=======================================================================
209 void SMESHGUI_Operation::initDialog()
214 * \brief Verifies whether study of operation is locked
215 * \param theMess - specifies whether message box must be shown if study is locked
216 * \return State of study.
218 * Verifies whether study of operation is locked. If second parameter is TRUE and study
219 * is locked when corresponding message box appears
221 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
225 if ( studyDS()->GetProperties()->IsLocked() )
228 SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
229 QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
238 * \brief Verifies whether given operator is valid for this one
239 * \param theOtherOp - other operation
240 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
242 * Virtual method redefined from base class verifies whether given operator is valid for
243 * this one (i.e. can be started "above" this operator). In current implementation method
244 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
247 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
249 static QStringList anOps;
250 if ( anOps.count() == 0 )
252 anOps.append( "SMESHGUI_DeleteOp" );
253 // to do add other operations here
256 return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
257 ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );