Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / OperationGUI / OperationGUI_ArchimedeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : OperationGUI_ArchimedeDlg.cxx
25 //  Author : Nicolas REJNERI 
26 //  Module : GEOM
27 //  $Header$
28
29 #include "OperationGUI_ArchimedeDlg.h"
30 #include "DlgRef_1Sel3Spin.h"
31
32 #include "QAD_Config.h"
33 #include "QAD_Desktop.h"
34
35 //=================================================================================
36 // class    : OperationGUI_ArchimedeDlg()
37 // purpose  : Constructs a OperationGUI_ArchimedeDlg which is a child of 'parent', with the 
38 //            name 'name' and widget flags set to 'f'.
39 //            The dialog will by default be modeless, unless you set 'modal' to
40 //            TRUE to construct a modal dialog.
41 //=================================================================================
42 OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg( QWidget* parent, SALOME_Selection* Sel )
43 : GEOMBase_Skeleton( parent, "ArchimedeDlg", Sel, false,
44     WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 {
46   mySelection = Sel;
47
48   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
49   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50   
51   setCaption(tr("GEOM_ARCHIMEDE_TITLE"));
52
53   /***************************************************************/
54   GroupConstructors->setTitle(tr("GEOM_ARCHIMEDE"));
55   RadioButton1->setPixmap(image0);
56   RadioButton2->close(TRUE);
57   RadioButton3->close(TRUE);
58
59   GroupPoints = new DlgRef_1Sel3Spin(this, "GroupPoints");
60   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
62   GroupPoints->TextLabel2->setText(tr("GEOM_WEIGHT"));
63   GroupPoints->TextLabel3->setText(tr("GEOM_WATER_DENSITY"));
64   GroupPoints->TextLabel4->setText(tr("GEOM_MESHING_DEFLECTION"));
65   GroupPoints->PushButton1->setPixmap(image1);
66   GroupPoints->LineEdit1->setReadOnly( true );
67
68   Layout1->addWidget(GroupPoints, 2, 0);
69   /***************************************************************/
70
71   /* Initialisations */
72   Init( mySelection );
73 }
74
75
76 //=================================================================================
77 // function : ~OperationGUI_ArchimedeDlg()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
81 {
82   // no need to delete child widgets, Qt does it all for us
83 }
84
85
86 //=================================================================================
87 // function : Init()
88 // purpose  :
89 //=================================================================================
90 void OperationGUI_ArchimedeDlg::Init( SALOME_Selection* Sel )
91 {
92   mySelection = Sel;
93
94   /* init variables */
95   myEditCurrentArgument = GroupPoints->LineEdit1;
96
97   /* Get setting of myStep value from file configuration */
98   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
99   myStep = !St.isEmpty() ? St.toDouble() : 100;
100
101   double SpecificStep1 = 0.1;
102   double SpecificStep2 = 0.01;
103   /* min, max, myStep and decimals for spin boxes & initial values */
104   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, myStep, 3);
105   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep1, 3);
106   GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, 999.999, SpecificStep2, 3);
107
108   GroupPoints->SpinBox_DX->SetValue( 100.0 );
109   GroupPoints->SpinBox_DY->SetValue( 1.0 );
110   GroupPoints->SpinBox_DZ->SetValue( 0.01 );
111
112   /* signals and slots connections */
113   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
114   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115
116   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117
118   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
119   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
120   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
121   
122   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
123
124   initName( tr( "GEOM_ARCHIMEDE" ) );
125
126   globalSelection( GEOM_ALLSHAPES );
127
128   SelectionIntoArgument();
129   
130   /* displays Dialog */
131   GroupPoints->show();
132   this->show();
133 }
134
135
136 //=================================================================================
137 // function : ClickOnOk()
138 // purpose  :
139 //=================================================================================
140 void OperationGUI_ArchimedeDlg::ClickOnOk()
141 {
142   if ( ClickOnApply() )
143     ClickOnCancel();
144 }
145
146
147 //=================================================================================
148 // function : ClickOnApply()
149 // purpose  :
150 //=================================================================================
151 bool OperationGUI_ArchimedeDlg::ClickOnApply()
152 {
153   if ( !onAccept() )
154     return false;
155
156   initName();
157   return true;
158 }
159
160
161 //=================================================================================
162 // function : SelectionIntoArgument()
163 // purpose  : Called when selection as changed or other case
164 //=================================================================================
165 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
166 {
167   myEditCurrentArgument->setText( "" );
168   myShape = GEOM::GEOM_Object::_nil();
169   
170   if ( mySelection->IObjectCount() != 1 )
171     return;
172
173   Standard_Boolean testResult = Standard_False;
174   myShape = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
175
176   if ( !testResult || myShape->_is_nil() || !GEOMBase::IsShape( myShape ) )
177   {
178     myShape = GEOM::GEOM_Object::_nil();
179     return;
180   }
181
182   myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
183 }
184
185
186 //=================================================================================
187 // function : LineEditReturnPressed()
188 // purpose  :
189 //=================================================================================
190 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
191 {
192   QLineEdit* send = (QLineEdit*)sender();
193   if(send == GroupPoints->LineEdit1)
194     myEditCurrentArgument = GroupPoints->LineEdit1;
195   else
196     return;
197
198   GEOMBase_Skeleton::LineEditReturnPressed();
199   return;
200 }
201
202 //=================================================================================
203 // function : ActivateThisDialog()
204 // purpose  :
205 //=================================================================================
206 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
207 {
208   GEOMBase_Skeleton::ActivateThisDialog();
209   globalSelection( GEOM_ALLSHAPES );
210   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
211   return;
212 }
213
214
215 //=================================================================================
216 // function : enterEvent()
217 // purpose  :
218 //=================================================================================
219 void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
220 {
221   if(GroupConstructors->isEnabled())
222     return;
223   this->ActivateThisDialog();
224   return;
225 }
226
227
228 //=================================================================================
229 // function : createOperation
230 // purpose  :
231 //=================================================================================
232 GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
233 {
234   return getGeomEngine()->GetILocalOperations( getStudyId() );
235 }
236
237 //=================================================================================
238 // function : isValid
239 // purpose  :
240 //=================================================================================
241 bool OperationGUI_ArchimedeDlg::isValid( QString& )
242 {
243   return !myShape->_is_nil();
244 }
245
246 //=================================================================================
247 // function : execute
248 // purpose  :
249 //=================================================================================
250 bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
251 {
252   GEOM::GEOM_Object_var anObj;
253
254   double aWeight         = GroupPoints->SpinBox_DX->GetValue();
255   double aWaterDensity   = GroupPoints->SpinBox_DY->GetValue();
256   double aMeshDeflection = GroupPoints->SpinBox_DZ->GetValue();
257   
258   anObj = GEOM::GEOM_ILocalOperations::_narrow(
259     getOperation() )->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
260
261   if ( !anObj->_is_nil() )
262     objects.push_back( anObj._retn() );
263
264   return true;
265 }