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