Salome HOME
29a4067535ba678f7dc77426789688c6cefb05b7
[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 /*
21   Class       : SMESHGUI_Operation
22   Description : Base class for all SMESH operations
23 */
24
25 //=======================================================================
26 // name    : SMESHGUI_Operation
27 // Purpose : Constructor
28 //=======================================================================
29 SMESHGUI_Operation::SMESHGUI_Operation()
30 : SalomeApp_Operation()
31 {
32 }
33
34 //=======================================================================
35 // name    : ~SMESHGUI_Operation
36 // Purpose : Destructor
37 //=======================================================================
38 SMESHGUI_Operation::~SMESHGUI_Operation()
39 {
40 }
41
42 //=======================================================================
43 // name    : getSMESHGUI
44 // Purpose : Get SMESH module
45 //=======================================================================
46 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
47 {
48   return dynamic_cast<SMESHGUI*>( module() );
49 }
50
51 //=======================================================================
52 // name    : startOperation
53 // Purpose : Start opeartion
54 //=======================================================================
55 void SMESHGUI_Operation::startOperation()
56 {
57   if( dlg() )
58   {
59     disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
60     disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
61     disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
62     disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
63     
64     if( dlg()->testButtonFlags( QtxDialog::OK ) )
65       connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
66       
67     if( dlg()->testButtonFlags( QtxDialog::Apply ) )
68       connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
69       
70     if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
71       connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
72       
73     //if( dlg()->testButtonFlags( QtxDialog::Close ) )
74     //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
75     connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
76
77     initDialog();
78   }
79
80   SalomeApp_Operation::startOperation();
81 }
82
83 //=======================================================================
84 // name    : isReadyToStart
85 // Purpose : Verify whether operation is ready to start
86 //=======================================================================
87 bool SMESHGUI_Operation::isReadyToStart() const
88 {
89   if ( !SalomeApp_Operation::isReadyToStart() )
90     return false;
91   else if ( getSMESHGUI() == 0 )
92   {
93     SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
94       tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
95     return false;
96   }
97   
98   return true;
99 }
100
101 //=======================================================================
102 // name    : setDialogActive
103 // Purpose : 
104 //=======================================================================
105 void SMESHGUI_Operation::setDialogActive( const bool active )
106 {
107   SalomeApp_Operation::setDialogActive( active );
108
109   SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
110   if( d )
111     d->setContentActive( active );
112
113 }
114
115 //=======================================================================
116 // name    : studyDS
117 // Purpose :
118 //=======================================================================
119 _PTR(Study) SMESHGUI_Operation::studyDS() const
120 {
121   SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
122   return s->studyDS();
123 }
124
125 //=======================================================================
126 // name    : onOk
127 // Purpose :
128 //=======================================================================
129 void SMESHGUI_Operation::onOk()
130 {
131   if( onApply() )
132     commit();
133   else
134     abort();
135 }
136
137 //=======================================================================
138 // name    : onApply
139 // Purpose :
140 //=======================================================================
141 bool SMESHGUI_Operation::onApply()
142 {
143   return false;
144 }
145
146 //=======================================================================
147 // name    : onClose
148 // Purpose :
149 //=======================================================================
150 void SMESHGUI_Operation::onCancel()
151 {
152   abort();
153 }
154
155 //=======================================================================
156 // name    : initDialog
157 // Purpose :
158 //=======================================================================
159 void SMESHGUI_Operation::initDialog()
160 {
161 }
162
163 /*!
164  * \brief Verifies whether study of operation is locked
165   * \param theMess - specifies whether message box must be shown if study is locked
166   * \return State of study.
167 *
168 * Verifies whether study of operation is locked. If second parameter is TRUE and study
169 * is locked when corresponding message box appears
170 */
171 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
172 {
173   if ( studyDS() )
174   {
175     if ( studyDS()->GetProperties()->IsLocked() )
176     {
177       if ( theMess )
178         SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
179           QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
180       return true;
181     }
182   }
183   
184   return false;
185 }
186
187 //=======================================================================
188 // name    : isValid
189 // Purpose :
190 //=======================================================================
191 bool SMESHGUI_Operation::isValid( SUIT_Operation* op ) const
192 {
193   return( op && op->inherits( "SMESHGUI_Operation" ) );
194 }