Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[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_1Sel5Spin( 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->PushButton1->setIcon( image1 );
73   GroupPoints->LineEdit1->setReadOnly( true );
74
75   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76   layout->setMargin( 0 ); layout->setSpacing( 6 );
77   layout->addWidget( GroupPoints  );
78   /***************************************************************/
79
80   setHelpFileName( "creaet_filling_page.html" );
81
82   /* Initialisations */
83   Init();
84 }
85
86 //=================================================================================
87 // function : ~GenerationGUI_FillingDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
91 {
92   // no need to delete child widgets, Qt does it all for us
93 }
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void GenerationGUI_FillingDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupPoints->LineEdit1;
103   GroupPoints->LineEdit1->setReadOnly( true );
104
105   myMinDeg = 2;
106   myMaxDeg = 5;
107   myTol3D = 0.0001;
108   myTol2D = 0.0001;
109   myNbIter = 5;
110   myOkCompound = false;
111
112   globalSelection( GEOM_COMPOUND );
113
114   double SpecificStep1 = 1;
115   double SpecificStep2 = 0.0001;
116   /* min, max, step and decimals for spin boxes & initial values */
117   initSpinBox( GroupPoints->SpinBox1, 2.0, MAX_NUMBER,  SpecificStep1, 3 );
118   initSpinBox( GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, 5 );
119   initSpinBox( GroupPoints->SpinBox3, 1.0, MAX_NUMBER,  SpecificStep1, 3 );
120   initSpinBox( GroupPoints->SpinBox4, 1.0, MAX_NUMBER,  SpecificStep1, 3 );
121   initSpinBox( GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, 5 );
122
123   GroupPoints->SpinBox1->setValue( myMinDeg );
124   GroupPoints->SpinBox2->setValue( myTol2D );
125   GroupPoints->SpinBox3->setValue( myNbIter );
126   GroupPoints->SpinBox4->setValue( myMaxDeg );
127   GroupPoints->SpinBox5->setValue( myTol3D );
128
129   /* signals and slots connections */
130   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
131   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
132
133   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
134   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
135
136   connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
137   connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
138   connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
139   connect( GroupPoints->SpinBox4, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
140   connect( GroupPoints->SpinBox5, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
141
142   // VSR: TODO ->>
143   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox1, SLOT( SetStep( double ) ) );
144   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox2, SLOT( SetStep( double ) ) );
145   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox3, SLOT( SetStep( double ) ) );
146   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox4, SLOT( SetStep( double ) ) );
147   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox5, SLOT( SetStep( double ) ) );
148   // <<-
149
150   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
151            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
152
153   initName( tr( "GEOM_FILLING" ) );
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         // myCompound should be a compound of edges
211         for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
212           if ( it.Value().ShapeType() != TopAbs_EDGE )
213             return;
214         myCompound = aSelectedObject;
215         myOkCompound = true;
216       }
217   }
218
219   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
220   displayPreview();
221 }
222
223
224 //=================================================================================
225 // function : SetEditCurrentArgument()
226 // purpose  :
227 //=================================================================================
228 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
229 {
230   QPushButton* send = (QPushButton*)sender();
231   globalSelection( GEOM_ALLSHAPES );
232
233   if ( send == GroupPoints->PushButton1 ) {
234     GroupPoints->LineEdit1->setFocus();
235     myEditCurrentArgument = GroupPoints->LineEdit1;
236     globalSelection( GEOM_COMPOUND );
237     this->SelectionIntoArgument();
238   }
239 }
240
241
242 //=================================================================================
243 // function : LineEditReturnPressed()
244 // purpose  :
245 //=================================================================================
246 void GenerationGUI_FillingDlg::LineEditReturnPressed()
247 {
248   QLineEdit* send = (QLineEdit*)sender();
249   if ( send == GroupPoints->LineEdit1 ) {
250     myEditCurrentArgument = send;
251     GEOMBase_Skeleton::LineEditReturnPressed();
252   }
253 }
254
255
256 //=================================================================================
257 // function : ActivateThisDialog()
258 // purpose  :
259 //=================================================================================
260 void GenerationGUI_FillingDlg::ActivateThisDialog()
261 {
262   GEOMBase_Skeleton::ActivateThisDialog();
263   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
264            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
265   globalSelection( GEOM_COMPOUND );
266   displayPreview();
267 }
268
269
270 //=================================================================================
271 // function : enterEvent()
272 // purpose  :
273 //=================================================================================
274 void GenerationGUI_FillingDlg::enterEvent( QEvent* )
275 {
276   if ( !mainFrame()->GroupConstructors->isEnabled() )
277     ActivateThisDialog();
278 }
279
280
281 //=================================================================================
282 // function : ValueChangedInSpinBox()
283 // purpose  :
284 //=================================================================================
285 void GenerationGUI_FillingDlg::ValueChangedInSpinBox( double newValue )
286 {
287   QObject* send = (QObject*)sender();
288
289   if ( send == GroupPoints->SpinBox1 )
290     myMinDeg = int( newValue );
291   else if ( send == GroupPoints->SpinBox2 )
292     myTol2D = newValue;
293   else if ( send == GroupPoints->SpinBox3 )
294     myNbIter = int(newValue);
295   else if ( send == GroupPoints->SpinBox4 )
296     myMaxDeg = int(newValue);
297   else if ( send == GroupPoints->SpinBox5 )
298     myTol3D = newValue;
299
300   displayPreview();
301 }
302
303 //=================================================================================
304 // function : createOperation
305 // purpose  :
306 //=================================================================================
307 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
308 {
309   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
310 }
311
312 //=================================================================================
313 // function : isValid
314 // purpose  :
315 //=================================================================================
316 bool GenerationGUI_FillingDlg::isValid( QString& )
317 {
318   return myOkCompound > 0;
319 }
320
321 //=================================================================================
322 // function : execute
323 // purpose  :
324 //=================================================================================
325 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
326 {
327   GEOM::GEOM_Object_var anObj;
328
329   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
330     myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
331
332   if ( !anObj->_is_nil() )
333     objects.push_back( anObj._retn() );
334
335   return true;
336 }