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