Salome HOME
Update mail address
[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     if( dlg()->testButtonFlags( QtxDialog::OK ) )
85       connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
86       
87     if( dlg()->testButtonFlags( QtxDialog::Apply ) )
88       connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
89       
90     if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
91       connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
92
93     if( dlg()->testButtonFlags( QtxDialog::Help ) )
94       connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
95       
96     //if( dlg()->testButtonFlags( QtxDialog::Close ) )
97     //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
98     connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
99
100     initDialog();
101   }
102
103   LightApp_Operation::startOperation();
104 }
105
106 //=======================================================================
107 // name    : isReadyToStart
108 // Purpose : Verify whether operation is ready to start
109 //=======================================================================
110 bool SMESHGUI_Operation::isReadyToStart() const
111 {
112   if ( !LightApp_Operation::isReadyToStart() )
113     return false;
114   else if ( getSMESHGUI() == 0 )
115   {
116     SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
117       tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
118     return false;
119   }
120   else if ( isStudyLocked() )
121     return false;
122   
123   return true;
124 }
125
126 //=======================================================================
127 // name    : setDialogActive
128 // Purpose : 
129 //=======================================================================
130 void SMESHGUI_Operation::setDialogActive( const bool active )
131 {
132   LightApp_Operation::setDialogActive( active );
133
134   SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
135   if( d )
136     d->setContentActive( active );
137
138 }
139
140 //=======================================================================
141 // name    : studyDS
142 // Purpose :
143 //=======================================================================
144 _PTR(Study) SMESHGUI_Operation::studyDS() const
145 {
146   SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
147   return s->studyDS();
148 }
149
150 //=======================================================================
151 // name    : onOk
152 // Purpose :
153 //=======================================================================
154 void SMESHGUI_Operation::onOk()
155 {
156   if( onApply() )
157     commit();
158   //else
159   //  abort();
160 }
161
162 //=======================================================================
163 // name    : onApply
164 // Purpose :
165 //=======================================================================
166 bool SMESHGUI_Operation::onApply()
167 {
168   return false;
169 }
170
171 //=======================================================================
172 // name    : onClose
173 // Purpose :
174 //=======================================================================
175 void SMESHGUI_Operation::onCancel()
176 {
177   abort();
178 }
179
180 //=======================================================================
181 // name    : onHelp
182 // Purpose :
183 //=======================================================================
184 void SMESHGUI_Operation::onHelp()
185 {
186   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
187   if (app) 
188     app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
189   else {
190     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
191                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
192                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
193                            QObject::tr("BUT_OK"));
194   }
195 }
196
197 //=======================================================================
198 // name    : initDialog
199 // Purpose :
200 //=======================================================================
201 void SMESHGUI_Operation::initDialog()
202 {
203 }
204
205 /*!
206  * \brief Verifies whether study of operation is locked
207   * \param theMess - specifies whether message box must be shown if study is locked
208   * \return State of study.
209 *
210 * Verifies whether study of operation is locked. If second parameter is TRUE and study
211 * is locked when corresponding message box appears
212 */
213 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
214 {
215   if ( studyDS() )
216   {
217     if ( studyDS()->GetProperties()->IsLocked() )
218     {
219       if ( theMess )
220         SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
221           QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
222       return true;
223     }
224   }
225   
226   return false;
227 }
228
229 /*!
230  * \brief Verifies whether given operator is valid for this one
231   * \param theOtherOp - other operation
232   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
233 *
234 * Virtual method redefined from base class verifies whether given operator is valid for
235 * this one (i.e. can be started "above" this operator). In current implementation method
236 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
237 * elements.
238 */
239 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
240 {
241   static QStringList anOps;
242   if ( anOps.count() == 0 )
243   {
244     anOps.append( "SMESHGUI_DeleteOp" );
245     // to do add other operations here
246   }
247
248   return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
249          ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );
250
251   return true;
252 }
253
254
255
256
257
258
259
260
261
262
263
264