]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ArchimedeDlg.cxx
Salome HOME
IPAL20715 impossible to select sub-shape after apply group
[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 
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "OperationGUI_ArchimedeDlg.h"
29 #include "DlgRef_1Sel3Spin.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <qlabel.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, "ArchimedeDlg", false,
47                       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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   setCaption(tr("GEOM_ARCHIMEDE_TITLE"));
53
54   /***************************************************************/
55   GroupConstructors->setTitle(tr("GEOM_ARCHIMEDE"));
56   RadioButton1->setPixmap(image0);
57   RadioButton2->close(TRUE);
58   RadioButton3->close(TRUE);
59
60   GroupPoints = new DlgRef_1Sel3Spin(this, "GroupPoints");
61   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
62   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
63   GroupPoints->TextLabel2->setText(tr("GEOM_WEIGHT"));
64   GroupPoints->TextLabel3->setText(tr("GEOM_WATER_DENSITY"));
65   GroupPoints->TextLabel4->setText(tr("GEOM_MESHING_DEFLECTION"));
66   GroupPoints->PushButton1->setPixmap(image1);
67   GroupPoints->LineEdit1->setReadOnly( true );
68
69   Layout1->addWidget(GroupPoints, 2, 0);
70   /***************************************************************/
71
72   setHelpFileName("archimede_page.html");
73
74   /* Initialisations */
75   Init();
76 }
77
78
79 //=================================================================================
80 // function : ~OperationGUI_ArchimedeDlg()
81 // purpose  : Destroys the object and frees any allocated resources
82 //=================================================================================
83 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
84 {
85   // no need to delete child widgets, Qt does it all for us
86 }
87
88
89 //=================================================================================
90 // function : Init()
91 // purpose  :
92 //=================================================================================
93 void OperationGUI_ArchimedeDlg::Init()
94 {
95   /* init variables */
96   myEditCurrentArgument = GroupPoints->LineEdit1;
97
98   /* Get setting of myStep value from file configuration */
99   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
100   double myStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
101
102   double SpecificStep1 = 0.1;
103   double SpecificStep2 = 0.01;
104   /* min, max, myStep and decimals for spin boxes & initial values */
105   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, myStep, DBL_DIGITS_DISPLAY);
106   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep1, DBL_DIGITS_DISPLAY);
107   GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep2, DBL_DIGITS_DISPLAY);
108
109   GroupPoints->SpinBox_DX->SetValue( 100.0 );
110   GroupPoints->SpinBox_DY->SetValue( 1.0 );
111   GroupPoints->SpinBox_DZ->SetValue( 0.01 );
112
113   /* signals and slots connections */
114   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116
117   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118
119   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
120   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
121   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
122   
123   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
124           this, SLOT(SelectionIntoArgument()));
125   
126   initName( tr( "GEOM_ARCHIMEDE" ) );
127   
128   globalSelection( GEOM_ALLSHAPES );
129
130   SelectionIntoArgument();
131 }
132
133
134 //=================================================================================
135 // function : ClickOnOk()
136 // purpose  :
137 //=================================================================================
138 void OperationGUI_ArchimedeDlg::ClickOnOk()
139 {
140   if ( ClickOnApply() )
141     ClickOnCancel();
142 }
143
144
145 //=================================================================================
146 // function : ClickOnApply()
147 // purpose  :
148 //=================================================================================
149 bool OperationGUI_ArchimedeDlg::ClickOnApply()
150 {
151   if ( !onAccept() )
152     return false;
153
154   initName();
155   return true;
156 }
157
158
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose  : Called when selection as changed or other case
162 //=================================================================================
163 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
164 {
165   myEditCurrentArgument->setText( "" );
166   myShape = GEOM::GEOM_Object::_nil();
167   
168   if ( IObjectCount() != 1 )
169     return;
170
171   Standard_Boolean testResult = Standard_False;
172   myShape = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
173
174   if ( !testResult || myShape->_is_nil() || !GEOMBase::IsShape( myShape ) )
175   {
176     myShape = GEOM::GEOM_Object::_nil();
177     return;
178   }
179
180   myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
181 }
182
183
184 //=================================================================================
185 // function : LineEditReturnPressed()
186 // purpose  :
187 //=================================================================================
188 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
189 {
190   QLineEdit* send = (QLineEdit*)sender();
191   if(send == GroupPoints->LineEdit1)
192     myEditCurrentArgument = GroupPoints->LineEdit1;
193   else
194     return;
195
196   GEOMBase_Skeleton::LineEditReturnPressed();
197   return;
198 }
199
200 //=================================================================================
201 // function : ActivateThisDialog()
202 // purpose  :
203 //=================================================================================
204 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
205 {
206   GEOMBase_Skeleton::ActivateThisDialog();
207   globalSelection( GEOM_ALLSHAPES );
208   connect(myGeomGUI->getApp()->selectionMgr(),
209           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
210   return;
211 }
212
213
214 //=================================================================================
215 // function : enterEvent()
216 // purpose  :
217 //=================================================================================
218 void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
219 {
220   if(GroupConstructors->isEnabled())
221     return;
222   this->ActivateThisDialog();
223   return;
224 }
225
226
227 //=================================================================================
228 // function : createOperation
229 // purpose  :
230 //=================================================================================
231 GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
232 {
233   return getGeomEngine()->GetILocalOperations( getStudyId() );
234 }
235
236 //=================================================================================
237 // function : isValid
238 // purpose  :
239 //=================================================================================
240 bool OperationGUI_ArchimedeDlg::isValid( QString& )
241 {
242   return !myShape->_is_nil();
243 }
244
245 //=================================================================================
246 // function : execute
247 // purpose  :
248 //=================================================================================
249 bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
250 {
251   GEOM::GEOM_Object_var anObj;
252
253   double aWeight         = GroupPoints->SpinBox_DX->GetValue();
254   double aWaterDensity   = GroupPoints->SpinBox_DY->GetValue();
255   double aMeshDeflection = GroupPoints->SpinBox_DZ->GetValue();
256   
257   anObj = GEOM::GEOM_ILocalOperations::_narrow(
258     getOperation() )->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
259
260   if ( !anObj->_is_nil() )
261     objects.push_back( anObj._retn() );
262
263   return true;
264 }