Salome HOME
0020321: EDF : Some windows do not appear depending on the platform (MinimumSizeHint())
[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.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_Operation.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Dialog.h"
31
32 // SALOME GUI includes
33 #include <SalomeApp_Study.h>
34 #include <LightApp_Application.h>
35
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_ResourceMgr.h>
40
41 // Qt includes
42 #include <QStringList>
43
44 /*
45   Class       : SMESHGUI_Operation
46   Description : Base class for all SMESH operations
47 */
48
49 //=======================================================================
50 // name    : SMESHGUI_Operation
51 // Purpose : Constructor
52 //=======================================================================
53 SMESHGUI_Operation::SMESHGUI_Operation()
54 : LightApp_Operation()
55 {
56   myHelpFileName = "";
57 }
58
59 //=======================================================================
60 // name    : ~SMESHGUI_Operation
61 // Purpose : Destructor
62 //=======================================================================
63 SMESHGUI_Operation::~SMESHGUI_Operation()
64 {
65 }
66
67 //=======================================================================
68 // name    : getSMESHGUI
69 // Purpose : Get SMESH module
70 //=======================================================================
71 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
72 {
73   return dynamic_cast<SMESHGUI*>( module() );
74 }
75
76 //=======================================================================
77 // name    : startOperation
78 // Purpose : Start opeartion
79 //=======================================================================
80 void SMESHGUI_Operation::startOperation()
81 {
82   if( dlg() )
83   {
84     disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
85     disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
86     disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
87     disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
88     disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
89     
90     if( dlg()->testButtonFlags( QtxDialog::OK ) )
91       connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
92       
93     if( dlg()->testButtonFlags( QtxDialog::Apply ) )
94       connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
95       
96     if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
97       connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
98
99     if( dlg()->testButtonFlags( QtxDialog::Help ) )
100       connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
101       
102     //if( dlg()->testButtonFlags( QtxDialog::Close ) )
103     //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
104     connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
105
106     initDialog();
107   }
108
109   LightApp_Operation::startOperation();
110 }
111
112 //=======================================================================
113 // name    : isReadyToStart
114 // Purpose : Verify whether operation is ready to start
115 //=======================================================================
116 bool SMESHGUI_Operation::isReadyToStart() const
117 {
118   if ( !LightApp_Operation::isReadyToStart() )
119     return false;
120   else if ( getSMESHGUI() == 0 )
121   {
122     SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
123                               tr( "NO_MODULE" ) );
124     return false;
125   }
126   else if ( isStudyLocked() )
127     return false;
128   
129   return true;
130 }
131
132 //=======================================================================
133 // name    : setDialogActive
134 // Purpose : 
135 //=======================================================================
136 void SMESHGUI_Operation::setDialogActive( const bool active )
137 {
138   LightApp_Operation::setDialogActive( active );
139
140   SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
141   if( d )
142     d->setContentActive( active );
143
144 }
145
146 //=======================================================================
147 // name    : studyDS
148 // Purpose :
149 //=======================================================================
150 _PTR(Study) SMESHGUI_Operation::studyDS() const
151 {
152   SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
153   return s->studyDS();
154 }
155
156 //=======================================================================
157 // name    : onOk
158 // Purpose :
159 //=======================================================================
160 void SMESHGUI_Operation::onOk()
161 {
162   if( onApply() )
163     commit();
164   //else
165   //  abort();
166 }
167
168 //=======================================================================
169 // name    : onApply
170 // Purpose :
171 //=======================================================================
172 bool SMESHGUI_Operation::onApply()
173 {
174   return false;
175 }
176
177 //=======================================================================
178 // name    : onClose
179 // Purpose :
180 //=======================================================================
181 void SMESHGUI_Operation::onCancel()
182 {
183   abort();
184 }
185
186 //=======================================================================
187 // name    : onHelp
188 // Purpose :
189 //=======================================================================
190 void SMESHGUI_Operation::onHelp()
191 {
192   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
193   if (app) 
194     app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
195   else {
196     QString platform;
197 #ifdef WIN32
198     platform = "winapplication";
199 #else
200     platform = "application";
201 #endif
202     SUIT_MessageBox::warning( desktop(), tr("WRN_WARNING"),
203                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
204                               arg(app->resourceMgr()->stringValue("ExternalBrowser", 
205                                                                   platform)).
206                               arg(myHelpFileName) );
207   }
208 }
209
210 //=======================================================================
211 // name    : initDialog
212 // Purpose :
213 //=======================================================================
214 void SMESHGUI_Operation::initDialog()
215 {
216 }
217
218 /*!
219  * \brief Verifies whether study of operation is locked
220   * \param theMess - specifies whether message box must be shown if study is locked
221   * \return State of study.
222 *
223 * Verifies whether study of operation is locked. If second parameter is TRUE and study
224 * is locked when corresponding message box appears
225 */
226 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
227 {
228   if ( studyDS() )
229   {
230     if ( studyDS()->GetProperties()->IsLocked() )
231     {
232       if ( theMess )
233         SUIT_MessageBox::warning( SMESHGUI::desktop(), tr( "WRN_WARNING" ),
234                                   tr( "WRN_STUDY_LOCKED" ) );
235       return true;
236     }
237   }
238   
239   return false;
240 }
241
242 /*!
243  * \brief Verifies whether given operator is valid for this one
244   * \param theOtherOp - other operation
245   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
246 *
247 * Virtual method redefined from base class verifies whether given operator is valid for
248 * this one (i.e. can be started "above" this operator). In current implementation method
249 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
250 * elements.
251 */
252 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
253 {
254   static QStringList anOps;
255   if ( anOps.count() == 0 )
256   {
257     anOps.append( "SMESHGUI_DeleteOp" );
258     // to do add other operations here
259   }
260
261   return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
262          ( !anOps.contains( theOtherOp->metaObject()->className() ) || 
263            anOps.contains( metaObject()->className() ) );
264
265   return true;
266 }