Salome HOME
6a682eabc97f233637d125c7bc3fd38266703f09
[modules/geom.git] / src / OperationGUI / OperationGUI_ArchimedeDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : OperationGUI_ArchimedeDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 //
27 #include "OperationGUI_ArchimedeDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 //=================================================================================
40 // class    : OperationGUI_ArchimedeDlg()
41 // purpose  : Constructs a OperationGUI_ArchimedeDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47   : GEOMBase_Skeleton( theGeometryGUI, parent, false )
48 {
49   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARCHIMEDE" ) ) );
50   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51   
52   setWindowTitle( tr( "GEOM_ARCHIMEDE_TITLE" ) );
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARCHIMEDE" ) );
56   mainFrame()->RadioButton1->setIcon( image0 );
57   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58   mainFrame()->RadioButton2->close();
59   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton3->close();
61
62   GroupPoints = new DlgRef_1Sel3Spin( centralWidget() );
63   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
64   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
65   GroupPoints->TextLabel2->setText( tr( "GEOM_WEIGHT" ) );
66   GroupPoints->TextLabel3->setText( tr( "GEOM_WATER_DENSITY" ) );
67   GroupPoints->TextLabel4->setText( tr( "GEOM_MESHING_DEFLECTION" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->LineEdit1->setReadOnly( true );
70
71   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72   layout->setMargin( 0 ); layout->setSpacing( 6 );
73   layout->addWidget( GroupPoints );
74
75   /***************************************************************/
76
77   setHelpFileName( "archimede_page.html" );
78
79   /* Initialisations */
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~OperationGUI_ArchimedeDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
89 {
90   // no need to delete child widgets, Qt does it all for us
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void OperationGUI_ArchimedeDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupPoints->LineEdit1;
102
103   /* Get setting of myStep value from file configuration */
104   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
105   double myStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
106
107   double SpecificStep1 = 0.1;
108   double SpecificStep2 = 0.01;
109   /* min, max, myStep and decimals for spin boxes & initial values */
110   initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, myStep, "weight_precision" );
111   initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, SpecificStep1, "density_precision" );
112   initSpinBox( GroupPoints->SpinBox_DZ, 0.001, COORD_MAX, SpecificStep2, "parametric_precision" );
113
114   showOnlyPreviewControl();
115
116   GroupPoints->SpinBox_DX->setValue( 100.0 );
117   GroupPoints->SpinBox_DY->setValue( 1.0 );
118   GroupPoints->SpinBox_DZ->setValue( 0.01 );
119
120   /* signals and slots connections */
121   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
122   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
123
124   connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
125
126   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
127   
128   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
129            this, SLOT( SelectionIntoArgument() ) );
130
131
132   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
133   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
134   connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
135   
136   initName( tr( "GEOM_ARCHIMEDE" ) );
137   
138   globalSelection( GEOM_ALLSHAPES );
139
140   SelectionIntoArgument();
141   resize(100,100);
142 }
143
144
145 //=================================================================================
146 // function : SetDoubleSpinBoxStep()
147 // purpose  : Double spin box management
148 //=================================================================================
149 void OperationGUI_ArchimedeDlg::SetDoubleSpinBoxStep( double step )
150 {
151   GroupPoints->SpinBox_DX->setSingleStep(step);
152   
153   // san: Commented so as not to override specific step settings
154   //GroupPoints->SpinBox_DY->setSingleStep(step);
155   //GroupPoints->SpinBox_DZ->setSingleStep(step);
156 }
157
158 //=================================================================================
159 // function : ClickOnOk()
160 // purpose  :
161 //=================================================================================
162 void OperationGUI_ArchimedeDlg::ClickOnOk()
163 {
164   setIsApplyAndClose( true );
165   if ( ClickOnApply() )
166     ClickOnCancel();
167 }
168
169
170 //=================================================================================
171 // function : ClickOnApply()
172 // purpose  :
173 //=================================================================================
174 bool OperationGUI_ArchimedeDlg::ClickOnApply()
175 {
176   if ( !onAccept() )
177     return false;
178
179   initName();
180   return true;
181 }
182
183 //=================================================================================
184 // function : SelectionIntoArgument()
185 // purpose  : Called when selection as changed or other case
186 //=================================================================================
187 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
188 {
189   myEditCurrentArgument->setText("");
190   myShape = GEOM::GEOM_Object::_nil();
191
192   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
193   SALOME_ListIO aSelList;
194   aSelMgr->selectedObjects(aSelList);
195
196   if (aSelList.Extent() != 1)
197     return;
198
199   myShape = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
200
201   if ( !GEOMBase::IsShape(myShape) ) {
202     myShape = GEOM::GEOM_Object::_nil();
203     return;
204   }
205   myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
206   processPreview();
207 }
208
209 //=================================================================================
210 // function : LineEditReturnPressed()
211 // purpose  :
212 //=================================================================================
213 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
214 {
215   QLineEdit* send = (QLineEdit*)sender();
216   if ( send == GroupPoints->LineEdit1 )
217     myEditCurrentArgument = GroupPoints->LineEdit1;
218   else
219     return;
220
221   GEOMBase_Skeleton::LineEditReturnPressed();
222 }
223
224 //=================================================================================
225 // function : ActivateThisDialog()
226 // purpose  :
227 //=================================================================================
228 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
229 {
230   GEOMBase_Skeleton::ActivateThisDialog();
231   globalSelection( GEOM_ALLSHAPES );
232   connect( myGeomGUI->getApp()->selectionMgr(),
233            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234   processPreview();
235 }
236
237
238 //=================================================================================
239 // function : enterEvent()
240 // purpose  :
241 //=================================================================================
242 void OperationGUI_ArchimedeDlg::enterEvent( QEvent* )
243 {
244   if ( mainFrame()->GroupConstructors->isEnabled() )
245     return;
246   this->ActivateThisDialog();
247 }
248
249
250 //=================================================================================
251 // function : createOperation
252 // purpose  :
253 //=================================================================================
254 GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
255 {
256   return getGeomEngine()->GetILocalOperations();
257 }
258
259 //=================================================================================
260 // function : isValid
261 // purpose  :
262 //=================================================================================
263 bool OperationGUI_ArchimedeDlg::isValid( QString& msg )
264 {
265   bool ok = true;
266   ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
267   ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
268   ok = GroupPoints->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
269   return !myShape->_is_nil() && ok;
270 }
271
272 //=================================================================================
273 // function : execute
274 // purpose  :
275 //=================================================================================
276 bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
277 {
278   double aWeight         = GroupPoints->SpinBox_DX->value();
279   double aWaterDensity   = GroupPoints->SpinBox_DY->value();
280   double aMeshDeflection = GroupPoints->SpinBox_DZ->value();
281   
282   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
283   GEOM::GEOM_Object_var anObj = anOper->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
284
285   if ( !anObj->_is_nil() )
286   {
287     if ( !IsPreview() )
288     {
289       QStringList aParameters;
290       aParameters << GroupPoints->SpinBox_DX->text();
291       aParameters << GroupPoints->SpinBox_DY->text();
292       aParameters << GroupPoints->SpinBox_DZ->text();
293       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
294     }
295     objects.push_back( anObj._retn() );
296   }
297
298   return true;
299 }
300
301 //=================================================================================
302 // function : ValueChangedInSpinBox()
303 // purpose  :
304 //=================================================================================
305 void OperationGUI_ArchimedeDlg::ValueChangedInSpinBox(double /*newValue*/)
306 {
307   processPreview();
308 }
309
310 //=================================================================================
311 // function : getSourceObjects
312 // purpose  : virtual method to get source objects
313 //=================================================================================
314 QList<GEOM::GeomObjPtr> OperationGUI_ArchimedeDlg::getSourceObjects()
315 {
316   QList<GEOM::GeomObjPtr> res;
317   GEOM::GeomObjPtr aGeomObjPtr(myShape);
318   res << aGeomObjPtr;
319   return res;
320 }