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