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