Salome HOME
Porting to Qt4.
[modules/geom.git] / src / GenerationGUI / GenerationGUI_FillingDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : GenerationGUI_FillingDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GenerationGUI_FillingDlg.h"
30 #include "DlgRef_1Sel5Spin.h"
31 #include "DlgRef_SpinBox.h"
32
33 #include "GeometryGUI.h"
34 #include "GEOMBase.h"
35
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
40
41 #include <TopoDS_Iterator.hxx>
42 #include "GEOMImpl_Types.hxx"
43
44 //=================================================================================
45 // class    : GenerationGUI_FillingDlg()
46 // purpose  : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52                                                    const char* name, bool modal, Qt::WindowFlags fl)
53   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
54 {
55   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
56   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
57
58   setWindowTitle(tr("GEOM_FILLING_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_FILLING"));
62   RadioButton1->setIcon(image0);
63   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64   RadioButton2->close();
65   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66   RadioButton3->close();
67
68   GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
69   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70   GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
71   GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
72   GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
73   GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
74   GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
75   GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
76   GroupPoints->PushButton1->setIcon(image1);
77   GroupPoints->LineEdit1->setReadOnly( true );
78
79   gridLayout1->addWidget(GroupPoints, 2, 0);
80   /***************************************************************/
81
82   setHelpFileName("filling.htm");
83
84   /* Initialisations */
85   Init();
86 }
87
88 //=================================================================================
89 // function : ~GenerationGUI_FillingDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
93 {
94   // no need to delete child widgets, Qt does it all for us
95 }
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void GenerationGUI_FillingDlg::Init()
102 {
103   /* init variables */
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105   GroupPoints->LineEdit1->setReadOnly( true );
106
107   myMinDeg = 2;
108   myMaxDeg = 5;
109   myTol3D = 0.0001;
110   myTol2D = 0.0001;
111   myNbIter = 5;
112   myOkCompound = false;
113
114   globalSelection( GEOM_COMPOUND );
115
116   double SpecificStep1 = 1;
117   double SpecificStep2 = 0.0001;
118   /* min, max, step and decimals for spin boxes & initial values */
119   GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
120   GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
121   GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
122   GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
123   GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
124
125   GroupPoints->SpinBox_1->SetValue(myMinDeg);
126   GroupPoints->SpinBox_2->SetValue(myTol2D);
127   GroupPoints->SpinBox_3->SetValue(myNbIter);
128   GroupPoints->SpinBox_4->SetValue(myMaxDeg);
129   GroupPoints->SpinBox_5->SetValue(myTol3D);
130
131   /* signals and slots connections */
132   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134
135   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137
138   connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139   connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140   connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141   connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142   connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143
144   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
145   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
146   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
147   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
148   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
149
150   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
152
153   initName(tr("GEOM_FILLING").toStdString().c_str());
154 }
155
156
157 //=================================================================================
158 // function : ClickOnOk()
159 // purpose  :
160 //=================================================================================
161 void GenerationGUI_FillingDlg::ClickOnOk()
162 {
163   if ( ClickOnApply() )
164     ClickOnCancel();
165 }
166
167
168 //=================================================================================
169 // function : ClickOnApply()
170 // purpose  :
171 //=================================================================================
172 bool GenerationGUI_FillingDlg::ClickOnApply()
173 {
174   if ( !onAccept() )
175     return false;
176
177   initName();
178   return true;
179 }
180
181
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose  : Called when selection as changed or other case
185 //=================================================================================
186 void GenerationGUI_FillingDlg::SelectionIntoArgument()
187 {
188   erasePreview();
189   myEditCurrentArgument->setText("");
190
191   if(IObjectCount() != 1) {
192     if(myEditCurrentArgument == GroupPoints->LineEdit1)
193       myOkCompound = false;
194     return;
195   }
196
197   // nbSel == 1
198   Standard_Boolean testResult = Standard_False;
199   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
200
201   if (!testResult)
202     return;
203
204   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
205     TopoDS_Shape S;
206     myOkCompound = false;
207
208     if ( GEOMBase::GetShape(aSelectedObject, S) &&
209          S.ShapeType() == TopAbs_COMPOUND)
210       {
211         // myCompound should be a compound of edges
212         for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
213           if ( it.Value().ShapeType() != TopAbs_EDGE )
214             return;
215         myCompound = aSelectedObject;
216         myOkCompound = true;
217       }
218   }
219
220   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
221   displayPreview();
222 }
223
224
225 //=================================================================================
226 // function : SetEditCurrentArgument()
227 // purpose  :
228 //=================================================================================
229 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
230 {
231   QPushButton* send = (QPushButton*)sender();
232   globalSelection( GEOM_ALLSHAPES );
233
234   if(send == GroupPoints->PushButton1) {
235     GroupPoints->LineEdit1->setFocus();
236     myEditCurrentArgument = GroupPoints->LineEdit1;
237     globalSelection( GEOM_COMPOUND );
238     this->SelectionIntoArgument();
239   }
240 }
241
242
243 //=================================================================================
244 // function : LineEditReturnPressed()
245 // purpose  :
246 //=================================================================================
247 void GenerationGUI_FillingDlg::LineEditReturnPressed()
248 {
249   QLineEdit* send = (QLineEdit*)sender();
250   if(send == GroupPoints->LineEdit1)
251     {
252       myEditCurrentArgument = send;
253       GEOMBase_Skeleton::LineEditReturnPressed();
254     }
255 }
256
257
258 //=================================================================================
259 // function : ActivateThisDialog()
260 // purpose  :
261 //=================================================================================
262 void GenerationGUI_FillingDlg::ActivateThisDialog()
263 {
264   GEOMBase_Skeleton::ActivateThisDialog();
265   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
266           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
267   globalSelection( GEOM_COMPOUND );
268   displayPreview();
269 }
270
271
272 //=================================================================================
273 // function : enterEvent()
274 // purpose  :
275 //=================================================================================
276 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
277 {
278   if ( !GroupConstructors->isEnabled() )
279     ActivateThisDialog();
280 }
281
282
283 //=================================================================================
284 // function : ValueChangedInSpinBox()
285 // purpose  :
286 //=================================================================================
287 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
288 {
289   QObject* send = (QObject*)sender();
290
291   if(send == GroupPoints->SpinBox_1)
292     myMinDeg = int(newValue);
293   else if(send == GroupPoints->SpinBox_2)
294     myTol2D = newValue;
295   else if(send == GroupPoints->SpinBox_3)
296     myNbIter = int(newValue);
297   else if(send == GroupPoints->SpinBox_4)
298     myMaxDeg = int(newValue);
299   else if(send == GroupPoints->SpinBox_5)
300     myTol3D = newValue;
301
302   displayPreview();
303 }
304
305 //=================================================================================
306 // function : createOperation
307 // purpose  :
308 //=================================================================================
309 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
310 {
311   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
312 }
313
314 //=================================================================================
315 // function : isValid
316 // purpose  :
317 //=================================================================================
318 bool GenerationGUI_FillingDlg::isValid( QString& )
319 {
320   return myOkCompound > 0;
321 }
322
323 //=================================================================================
324 // function : execute
325 // purpose  :
326 //=================================================================================
327 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
328 {
329   GEOM::GEOM_Object_var anObj;
330
331   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
332     myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
333
334   if ( !anObj->_is_nil() )
335     objects.push_back( anObj._retn() );
336
337   return true;
338 }