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