Salome HOME
*** empty log message ***
[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       connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
75
76     initDialog();
77   }
78
79   SalomeApp_Operation::startOperation();
80 }
81
82 //=======================================================================
83 // name    : isReadyToStart
84 // Purpose : Verify whether operation is ready to start
85 //=======================================================================
86 bool SMESHGUI_Operation::isReadyToStart() const
87 {
88   if ( !SalomeApp_Operation::isReadyToStart() )
89     return false;
90   else if ( getSMESHGUI() == 0 )
91   {
92     SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
93       tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
94     return false;
95   }
96   
97   return true;
98 }
99
100 //=======================================================================
101 // name    : setDialogActive
102 // Purpose : 
103 //=======================================================================
104 void SMESHGUI_Operation::setDialogActive( const bool active )
105 {
106   SalomeApp_Operation::setDialogActive( active );
107
108   SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
109   if( d )
110     d->setContentActive( active );
111
112 }
113
114 //=======================================================================
115 // name    : studyDS
116 // Purpose :
117 //=======================================================================
118 _PTR(Study) SMESHGUI_Operation::studyDS() const
119 {
120   SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
121   return s->studyDS();
122 }
123
124 //=======================================================================
125 // name    : onOk
126 // Purpose :
127 //=======================================================================
128 void SMESHGUI_Operation::onOk()
129 {
130   if( onApply() )
131     commit();
132   else
133     abort();
134 }
135
136 //=======================================================================
137 // name    : onApply
138 // Purpose :
139 //=======================================================================
140 bool SMESHGUI_Operation::onApply()
141 {
142   return false;
143 }
144
145 //=======================================================================
146 // name    : onClose
147 // Purpose :
148 //=======================================================================
149 void SMESHGUI_Operation::onCancel()
150 {
151   abort();
152 }
153
154 //=======================================================================
155 // name    : initDialog
156 // Purpose :
157 //=======================================================================
158 void SMESHGUI_Operation::initDialog()
159 {
160 }
161
162 /*!
163  * \brief Verifies whether study of operation is locked
164   * \param theMess - specifies whether message box must be shown if study is locked
165   * \return State of study.
166 *
167 * Verifies whether study of operation is locked. If second parameter is TRUE and study
168 * is locked when corresponding message box appears
169 */
170 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
171 {
172   if ( studyDS() )
173   {
174     if ( studyDS()->GetProperties()->IsLocked() )
175     {
176       if ( theMess )
177         SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
178           QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
179       return true;
180     }
181   }
182   
183   return false;
184 }
185
186 //=======================================================================
187 // name    : isValid
188 // Purpose :
189 //=======================================================================
190 bool SMESHGUI_Operation::isValid( SUIT_Operation* op ) const
191 {
192   return( op && op->inherits( "SMESHGUI_Operation" ) );
193 }