]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_Operation.cxx
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()
87 {
88   if ( !SalomeApp_Operation::isReadyToStart() )
89     return false;
90     
91   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 }