Salome HOME
Fix of SMESH compilation error...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Operation.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 // 
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. 
9 // 
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. 
14 // 
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 
18 // 
19 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //  File   : SMESHGUI_Operation.h
22 //  Author : Sergey LITONIN
23 //  Module : SALOME
24
25 #include "SMESHGUI_Operation.h"
26 #include <SMESHGUI.h>
27 #include <SMESHGUI_Dialog.h>
28
29 #include <SalomeApp_Study.h>
30 #include <LightApp_Application.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Desktop.h>
35
36 #include <qstringlist.h>
37
38 /*
39   Class       : SMESHGUI_Operation
40   Description : Base class for all SMESH operations
41 */
42
43 //=======================================================================
44 // name    : SMESHGUI_Operation
45 // Purpose : Constructor
46 //=======================================================================
47 SMESHGUI_Operation::SMESHGUI_Operation()
48 : LightApp_Operation()
49 {
50   myHelpFileName = "";
51 }
52
53 //=======================================================================
54 // name    : ~SMESHGUI_Operation
55 // Purpose : Destructor
56 //=======================================================================
57 SMESHGUI_Operation::~SMESHGUI_Operation()
58 {
59 }
60
61 //=======================================================================
62 // name    : getSMESHGUI
63 // Purpose : Get SMESH module
64 //=======================================================================
65 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
66 {
67   return dynamic_cast<SMESHGUI*>( module() );
68 }
69
70 //=======================================================================
71 // name    : startOperation
72 // Purpose : Start opeartion
73 //=======================================================================
74 void SMESHGUI_Operation::startOperation()
75 {
76   if( dlg() )
77   {
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() ) );
83
84     dlg()->setButtonText(1, "&Ok"); //rename Apply and Close to OK
85     
86     if( dlg()->testButtonFlags( QtxDialog::OK ) )
87       connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
88       
89     if( dlg()->testButtonFlags( QtxDialog::Apply ) )
90       connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
91       
92     if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
93       connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
94
95     if( dlg()->testButtonFlags( QtxDialog::Help ) )
96       connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
97       
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() ) );
101
102     initDialog();
103   }
104
105   LightApp_Operation::startOperation();
106 }
107
108 //=======================================================================
109 // name    : isReadyToStart
110 // Purpose : Verify whether operation is ready to start
111 //=======================================================================
112 bool SMESHGUI_Operation::isReadyToStart() const
113 {
114   if ( !LightApp_Operation::isReadyToStart() )
115     return false;
116   else if ( getSMESHGUI() == 0 )
117   {
118     SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
119       tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
120     return false;
121   }
122   else if ( isStudyLocked() )
123     return false;
124   
125   return true;
126 }
127
128 //=======================================================================
129 // name    : setDialogActive
130 // Purpose : 
131 //=======================================================================
132 void SMESHGUI_Operation::setDialogActive( const bool active )
133 {
134   LightApp_Operation::setDialogActive( active );
135
136   SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
137   if( d )
138     d->setContentActive( active );
139
140 }
141
142 //=======================================================================
143 // name    : studyDS
144 // Purpose :
145 //=======================================================================
146 _PTR(Study) SMESHGUI_Operation::studyDS() const
147 {
148   SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
149   return s->studyDS();
150 }
151
152 //=======================================================================
153 // name    : onOk
154 // Purpose :
155 //=======================================================================
156 void SMESHGUI_Operation::onOk()
157 {
158   if( onApply() )
159     commit();
160   //else
161   //  abort();
162 }
163
164 //=======================================================================
165 // name    : onApply
166 // Purpose :
167 //=======================================================================
168 bool SMESHGUI_Operation::onApply()
169 {
170   return false;
171 }
172
173 //=======================================================================
174 // name    : onClose
175 // Purpose :
176 //=======================================================================
177 void SMESHGUI_Operation::onCancel()
178 {
179   abort();
180 }
181
182 //=======================================================================
183 // name    : onHelp
184 // Purpose :
185 //=======================================================================
186 void SMESHGUI_Operation::onHelp()
187 {
188   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
189   if (app) 
190     app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
191   else {
192                 QString platform;
193 #ifdef WIN32
194                 platform = "winapplication";
195 #else
196                 platform = "application";
197 #endif
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"));
202   }
203 }
204
205 //=======================================================================
206 // name    : initDialog
207 // Purpose :
208 //=======================================================================
209 void SMESHGUI_Operation::initDialog()
210 {
211 }
212
213 /*!
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.
217 *
218 * Verifies whether study of operation is locked. If second parameter is TRUE and study
219 * is locked when corresponding message box appears
220 */
221 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
222 {
223   if ( studyDS() )
224   {
225     if ( studyDS()->GetProperties()->IsLocked() )
226     {
227       if ( theMess )
228         SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
229           QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
230       return true;
231     }
232   }
233   
234   return false;
235 }
236
237 /*!
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
241 *
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
245 * elements.
246 */
247 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
248 {
249   static QStringList anOps;
250   if ( anOps.count() == 0 )
251   {
252     anOps.append( "SMESHGUI_DeleteOp" );
253     // to do add other operations here
254   }
255
256   return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
257          ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );
258
259   return true;
260 }
261
262
263
264
265
266
267
268
269
270
271
272