]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_PlaneDlg.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/geom.git] / src / GEOMGUI / GeometryGUI_PlaneDlg.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GeometryGUI_PlaneDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_PlaneDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
37
38 #include <BRepAdaptor_Surface.hxx>
39 #include <gp_Pln.hxx>
40 #include <gp_Pnt.hxx>
41 #include <gp_Ax1.hxx>
42 #include <gp_Dir.hxx>
43 #include <Precision.hxx>
44
45 #include <qbuttongroup.h>
46 #include <qframe.h>
47 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
51 #include <qlayout.h>
52 #include <qvariant.h>
53 #include <qlabel.h>
54 #include <qtooltip.h>
55 #include <qwhatsthis.h>
56 #include <qimage.h>
57 #include <qpixmap.h>
58 #include <qvalidator.h>
59 #include <qevent.h>
60
61
62 //=================================================================================
63 // class    : GeometryGUI_PlaneDlg()
64 // purpose  : Constructs a GeometryGUI_PlaneDlg which is a child of 'parent', with the 
65 //            name 'name' and widget flags set to 'f'.
66 //            The dialog will by default be modeless, unless you set 'modal' to
67 //            TRUE to construct a modal dialog.
68 //=================================================================================
69 GeometryGUI_PlaneDlg::GeometryGUI_PlaneDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
70     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
71 {
72     /***************************************************************/
73     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PLANE_PV")));
74     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
75     QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PLANE_DXYZ")));
76     QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PLANE_FACE")));
77
78     if ( !name )
79         setName( "GeometryGUI_PlaneDlg" );
80     resize( 365, 220 ); 
81     setCaption( tr( "GEOM_PLANE_TITLE"  ) );
82     setSizeGripEnabled( TRUE );
83     GeometryGUI_PlaneDlgLayout = new QGridLayout( this ); 
84     GeometryGUI_PlaneDlgLayout->setSpacing( 6 );
85     GeometryGUI_PlaneDlgLayout->setMargin( 11 );
86
87     /***************************************************************/
88     GroupButtons = new QGroupBox( this, "GroupButtons" );
89     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
90     GroupButtons->setTitle( tr( ""  ) );
91     GroupButtons->setColumnLayout(0, Qt::Vertical );
92     GroupButtons->layout()->setSpacing( 0 );
93     GroupButtons->layout()->setMargin( 0 );
94     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
95     GroupButtonsLayout->setAlignment( Qt::AlignTop );
96     GroupButtonsLayout->setSpacing( 6 );
97     GroupButtonsLayout->setMargin( 11 );
98     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
99     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
100     buttonCancel->setAutoDefault( TRUE );
101     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
102     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
103     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
104     buttonApply->setAutoDefault( TRUE );
105     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
106     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
107     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
108     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
109     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
110     buttonOk->setAutoDefault( TRUE );
111     buttonOk->setDefault( TRUE );
112     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
113     GeometryGUI_PlaneDlgLayout->addWidget( GroupButtons, 2, 0 );
114
115     /***************************************************************/
116     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
117     GroupConstructors->setTitle( tr( "GEOM_PLANE"  ) );
118     GroupConstructors->setExclusive( TRUE );
119     GroupConstructors->setColumnLayout(0, Qt::Vertical );
120     GroupConstructors->layout()->setSpacing( 0 );
121     GroupConstructors->layout()->setMargin( 0 );
122     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
123     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
124     GroupConstructorsLayout->setSpacing( 6 );
125     GroupConstructorsLayout->setMargin( 11 );
126     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
127     Constructor1->setText( tr( ""  ) );
128     Constructor1->setPixmap( image0 );
129     Constructor1->setChecked( TRUE );
130     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
131     Constructor1->setMinimumSize( QSize( 50, 0 ) );
132     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
133     Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
134     Constructor2->setText( tr( ""  ) );
135     Constructor2->setPixmap( image2 );
136     Constructor2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor2->sizePolicy().hasHeightForWidth() ) );
137     Constructor2->setMinimumSize( QSize( 50, 0 ) );
138     GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
139     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
140     GroupConstructorsLayout->addItem( spacer_2, 0, 3 );
141     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
142     GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
143     Constructor3 = new QRadioButton( GroupConstructors, "Constructor3" );
144     Constructor3->setText( tr( ""  ) );
145     Constructor3->setPixmap( image3 );
146     Constructor3->setMinimumSize( QSize( 50, 0 ) );
147     GroupConstructorsLayout->addWidget( Constructor3, 0, 4 );
148     QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
149     GroupConstructorsLayout->addItem( spacer_4, 0, 5 );
150     GeometryGUI_PlaneDlgLayout->addWidget( GroupConstructors, 0, 0 );
151
152     /***************************************************************/
153     GroupPointDirection = new QGroupBox( this, "GroupPointDirection" );
154     GroupPointDirection->setTitle( tr( "GEOM_PLANE_PV"  ) );
155     GroupPointDirection->setColumnLayout(0, Qt::Vertical );
156     GroupPointDirection->layout()->setSpacing( 0 );
157     GroupPointDirection->layout()->setMargin( 0 );
158     GroupPointDirectionLayout = new QGridLayout( GroupPointDirection->layout() );
159     GroupPointDirectionLayout->setAlignment( Qt::AlignTop );
160     GroupPointDirectionLayout->setSpacing( 6 );
161     GroupPointDirectionLayout->setMargin( 11 );
162     LineEditDirection = new QLineEdit( GroupPointDirection, "LineEditDirection" );
163     LineEditDirection->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditDirection->sizePolicy().hasHeightForWidth() ) );
164     GroupPointDirectionLayout->addWidget( LineEditDirection, 1, 2 );
165     LineEditPt1 = new QLineEdit( GroupPointDirection, "LineEditPt1" );
166     LineEditPt1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditPt1->sizePolicy().hasHeightForWidth() ) );
167     GroupPointDirectionLayout->addWidget( LineEditPt1, 0, 2 );
168     SelectButtonPt1 = new QPushButton( GroupPointDirection, "SelectButtonPt1" );
169     SelectButtonPt1->setText( tr( ""  ) );
170     SelectButtonPt1->setPixmap( image1 );
171     GroupPointDirectionLayout->addWidget( SelectButtonPt1, 0, 1 );
172     SelectButtonDirection = new QPushButton( GroupPointDirection, "SelectButtonDirection" );
173     SelectButtonDirection->setText( tr( ""  ) );
174     SelectButtonDirection->setPixmap( image1 );
175     GroupPointDirectionLayout->addWidget( SelectButtonDirection, 1, 1 );
176     TextLabelDirection = new QLabel( GroupPointDirection, "TextLabelDirection" );
177     TextLabelDirection->setText( tr( "GEOM_VECTOR"  ) );
178     TextLabelDirection->setMinimumSize( QSize( 50, 0 ) );
179     TextLabelDirection->setFrameShape( QLabel::NoFrame );
180     TextLabelDirection->setFrameShadow( QLabel::Plain );
181     GroupPointDirectionLayout->addWidget( TextLabelDirection, 1, 0 );
182     TextLabelPt1 = new QLabel( GroupPointDirection, "TextLabelPt1" );
183     TextLabelPt1->setText( tr( "GEOM_POINT"  ) );
184     TextLabelPt1->setMinimumSize( QSize( 50, 0 ) );
185     TextLabelPt1->setFrameShape( QLabel::NoFrame );
186     TextLabelPt1->setFrameShadow( QLabel::Plain );
187     GroupPointDirectionLayout->addWidget( TextLabelPt1, 0, 0 );
188
189     SpinBox_C1Size = new GeometryGUI_SpinBox( GroupPointDirection, "SpinBox_C1Size" );
190     GroupPointDirectionLayout->addWidget( SpinBox_C1Size, 2, 2 );
191     TextLabelC1Size = new QLabel( GroupPointDirection, "TextLabelC1Size" );
192     TextLabelC1Size->setText( tr( "GEOM_PLANE_SIZE"  ) );
193     TextLabelC1Size->setMinimumSize( QSize( 60, 0 ) );
194     GroupPointDirectionLayout->addWidget( TextLabelC1Size, 2, 0 );
195     
196     GeometryGUI_PlaneDlgLayout->addWidget( GroupPointDirection, 1, 0 );
197
198     /***************************************************************/
199     GroupPointPlusCoordinates = new QGroupBox( this, "GroupPointPlusCoordinates" );
200     GroupPointPlusCoordinates->setTitle( tr( "GEOM_PLANE_PVC"  ) );
201     GroupPointPlusCoordinates->setColumnLayout(0, Qt::Vertical );
202     GroupPointPlusCoordinates->layout()->setSpacing( 0 );
203     GroupPointPlusCoordinates->layout()->setMargin( 0 );
204     GroupPointPlusCoordinatesLayout = new QGridLayout( GroupPointPlusCoordinates->layout() );
205     GroupPointPlusCoordinatesLayout->setAlignment( Qt::AlignTop );
206     GroupPointPlusCoordinatesLayout->setSpacing( 6 );
207     GroupPointPlusCoordinatesLayout->setMargin( 11 );
208
209     LineEditPt2 = new QLineEdit( GroupPointPlusCoordinates, "LineEditPt2" );
210     LineEditPt2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditPt2->sizePolicy().hasHeightForWidth() ) );
211     GroupPointPlusCoordinatesLayout->addMultiCellWidget( LineEditPt2, 0, 0, 5, 8 );
212
213     SelectButtonPt2 = new QPushButton( GroupPointPlusCoordinates, "SelectButtonPt2" );
214     SelectButtonPt2->setText( tr( ""  ) );
215     SelectButtonPt2->setPixmap( image1 );
216     SelectButtonPt2->setMaximumSize( QSize( 28, 32767 ) );
217     GroupPointPlusCoordinatesLayout->addWidget( SelectButtonPt2, 0, 4 );
218
219     TextLabelPt2 = new QLabel( GroupPointPlusCoordinates, "TextLabelPt2" );
220     TextLabelPt2->setText( tr( "GEOM_POINT"  ) );
221     TextLabelPt2->setMinimumSize( QSize( 50, 0 ) );
222     TextLabelPt2->setFrameShape( QLabel::NoFrame );
223     TextLabelPt2->setFrameShadow( QLabel::Plain );
224     GroupPointPlusCoordinatesLayout->addMultiCellWidget( TextLabelPt2, 0, 0, 0, 3 );
225
226     SpinBox_DX = new GeometryGUI_SpinBox( GroupPointPlusCoordinates, "SpinBox_DX" );
227     SpinBox_DX->setMinimumSize( QSize( 50, 0 ) );
228     SpinBox_DX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DX->sizePolicy().hasHeightForWidth() ) );
229     GroupPointPlusCoordinatesLayout->addMultiCellWidget( SpinBox_DX, 1, 1, 3, 4 );
230     
231     SpinBox_DY = new GeometryGUI_SpinBox( GroupPointPlusCoordinates, "SpinBox_DY" );
232     SpinBox_DY->setMinimumSize( QSize( 50, 0 ) );
233     SpinBox_DY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DY->sizePolicy().hasHeightForWidth() ) );
234     GroupPointPlusCoordinatesLayout->addWidget( SpinBox_DY, 1, 6 );
235     
236     SpinBox_DZ = new GeometryGUI_SpinBox( GroupPointPlusCoordinates, "SpinBox_DZ" );
237     SpinBox_DZ->setMinimumSize( QSize( 50, 0 ) );
238     SpinBox_DZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DZ->sizePolicy().hasHeightForWidth() ) );
239     GroupPointPlusCoordinatesLayout->addWidget( SpinBox_DZ, 1, 8 );
240     
241     TextLabel_DX = new QLabel( GroupPointPlusCoordinates, "TextLabel_DX" );
242     TextLabel_DX->setText( tr( "GEOM_DX"  ) );
243     GroupPointPlusCoordinatesLayout->addWidget( TextLabel_DX, 1, 2 );
244
245     TextLabel_DY = new QLabel( GroupPointPlusCoordinates, "TextLabel_DY" );
246     TextLabel_DY->setText( tr( "GEOM_DY"  ) );
247     GroupPointPlusCoordinatesLayout->addWidget( TextLabel_DY, 1, 5 );
248
249     TextLabel_DZ = new QLabel( GroupPointPlusCoordinates, "TextLabel_DZ" );
250     TextLabel_DZ->setText( tr( "GEOM_DZ"  ) );
251     GroupPointPlusCoordinatesLayout->addWidget( TextLabel_DZ, 1, 7 );
252
253     TextLabelCoordinates = new QLabel( GroupPointPlusCoordinates, "TextLabelCoordinates" );
254     TextLabelCoordinates->setText( tr( "GEOM_COOR"  ) );
255     TextLabelCoordinates->setMinimumSize( QSize( 50, 0 ) );
256     TextLabelCoordinates->setFrameShape( QLabel::NoFrame );
257     TextLabelCoordinates->setFrameShadow( QLabel::Plain );
258     GroupPointPlusCoordinatesLayout->addWidget( TextLabelCoordinates, 1, 0 );
259
260     TextLabelC2Size = new QLabel( GroupPointPlusCoordinates, "TextLabelC2Size" );
261     TextLabelC2Size->setText( tr( "GEOM_PLANE_SIZE"  ) );
262     TextLabelC2Size->setMinimumSize( QSize( 60, 0 ) );
263     GroupPointPlusCoordinatesLayout->addMultiCellWidget( TextLabelC2Size, 2, 2, 0, 1 );
264
265     SpinBox_C2Size = new GeometryGUI_SpinBox( GroupPointPlusCoordinates, "SpinBox_C2Size" );
266     GroupPointPlusCoordinatesLayout->addMultiCellWidget( SpinBox_C2Size, 2, 2, 5, 8 );
267
268     QSpacerItem* spacer_c = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
269     GroupPointPlusCoordinatesLayout->addMultiCell( spacer_c, 2, 2, 2, 4 );
270     QSpacerItem* spacer_d = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
271     GroupPointPlusCoordinatesLayout->addItem( spacer_d, 1, 1 );
272
273     GeometryGUI_PlaneDlgLayout->addWidget( GroupPointPlusCoordinates, 1, 0 );
274
275     /***************************************************************/
276
277     GroupFace = new QGroupBox( this, "GroupFace" );
278     GroupFace->setTitle( tr( "GEOM_FACE"  ) );
279     GroupFace->setColumnLayout(0, Qt::Vertical );
280     GroupFace->layout()->setSpacing( 0 );
281     GroupFace->layout()->setMargin( 0 );
282     GroupFaceLayout = new QGridLayout( GroupFace->layout() );
283     GroupFaceLayout->setAlignment( Qt::AlignTop );
284     GroupFaceLayout->setSpacing( 6 );
285     GroupFaceLayout->setMargin( 11 );
286
287     TextLabelFace = new QLabel( GroupFace, "TextLabelFace" );
288     TextLabelFace->setFrameShadow( QLabel::Plain );
289     TextLabelFace->setFrameShape( QLabel::NoFrame );
290     TextLabelFace->setText( tr( "GEOM_SELECTION"  ) );
291     TextLabelFace->setMinimumSize( QSize( 50, 0 ) );
292     GroupFaceLayout->addMultiCellWidget( TextLabelFace, 0, 0, 0, 1 );
293
294     SelectButtonFace = new QPushButton( GroupFace, "SelectButtonFace" );
295     SelectButtonFace->setText( tr( ""  ) );
296     SelectButtonFace->setPixmap( image1 );
297     SelectButtonFace->setMaximumSize( QSize( 28, 32767 ) );
298     GroupFaceLayout->addWidget( SelectButtonFace, 0, 2 );
299
300     LineEditFace = new QLineEdit( GroupFace, "LineEditFace" );
301     LineEditFace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditFace->sizePolicy().hasHeightForWidth() ) );
302     GroupFaceLayout->addWidget( LineEditFace, 0, 3 );
303
304     TextLabelC3Size = new QLabel( GroupFace, "TextLabelC3Size" );
305     TextLabelC3Size->setText( tr( "GEOM_PLANE_SIZE"  ) );
306     TextLabelC3Size->setMinimumSize( QSize( 60, 0 ) );
307     GroupFaceLayout->addWidget( TextLabelC3Size, 1, 0 );
308
309     SpinBox_C3Size = new GeometryGUI_SpinBox( GroupFace, "SpinBox_C3Size" );
310     SpinBox_C3Size->setCaption( tr( ""  ) );
311     GroupFaceLayout->addWidget( SpinBox_C3Size, 1, 3 );
312
313     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
314     GroupFaceLayout->addMultiCell( spacer, 1, 1, 1, 2 );
315     QSpacerItem* spacer_e = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
316     GroupFaceLayout->addItem( spacer_e, 2, 3 );
317     GeometryGUI_PlaneDlgLayout->addWidget( GroupFace, 1, 0 );
318
319     /* Initialisation */
320     Init( Sel ) ;
321 }
322
323
324 //=================================================================================
325 // function : ~GeometryGUI_PlaneDlg()
326 // purpose  : Destroys the object and frees any allocated resources
327 //=================================================================================
328 GeometryGUI_PlaneDlg::~GeometryGUI_PlaneDlg()
329 {  
330   /* no need to delete child widgets, Qt does it all for us */
331   this->destroy(TRUE, TRUE) ;
332 }
333
334
335 //=================================================================================
336 // function : Init()
337 // purpose  :
338 //=================================================================================
339 void GeometryGUI_PlaneDlg::Init( SALOME_Selection* Sel )
340 {
341   double step ;
342   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
343   step = St.toDouble() ;
344   
345   /* min, max, step and decimals for spin boxes */
346   SpinBox_DX->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
347   SpinBox_DX->SetValue( 1.0 ) ;
348   SpinBox_DY->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
349   SpinBox_DY->SetValue( 1.0 ) ;
350   SpinBox_DZ->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
351   SpinBox_DZ->SetValue( 1.0 ) ; 
352   
353   this->myTrimSize = 2000.0 ;
354   SpinBox_C1Size->RangeStepAndValidator( +0.001, 10000000.0, step, 5 ) ;
355   SpinBox_C1Size->SetValue( myTrimSize ) ;
356   SpinBox_C2Size->RangeStepAndValidator( +0.001, 10000000.0, step, 5 ) ;
357   SpinBox_C2Size->SetValue( myTrimSize ) ;
358   SpinBox_C3Size->RangeStepAndValidator( +0.001, 10000000.0, step, 5 ) ;
359   SpinBox_C3Size->SetValue( myTrimSize ) ;
360
361   GroupPointDirection->show();
362   GroupPointPlusCoordinates->hide() ;
363   GroupFace->hide() ;
364   myConstructorId = 0 ;
365   Constructor1->setChecked( TRUE );
366
367   mySelection = Sel ;
368   myEditCurrentArgument = LineEditPt1 ; 
369   mySimulationTopoDs.Nullify() ;
370   myPoint1.SetCoord( 0.0, 0.0, 0.0 );
371   myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false ;
372
373   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
374   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
375
376   // TODO previous selection into argument ?
377   
378   /* Filters definition */
379   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
380   myGeom = GEOM::GEOM_Gen::_narrow(comp);
381   myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
382   myEdgeFilter   = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
383   myFaceFilter   = new GEOM_FaceFilter( StdSelect_Plane, myGeom );
384   /* Filter for the next selection */
385   mySelection->AddFilter( myVertexFilter ) ;
386
387   /* signals and slots connections */
388   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
389   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
390   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
391   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
392
393   connect( LineEditPt1,        SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
394   connect( LineEditDirection,  SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
395
396   connect( LineEditPt2,  SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
397   connect( LineEditFace, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
398
399   connect( SelectButtonPt1, SIGNAL (clicked() ),       this, SLOT( SetEditCurrentArgument() ) ) ;
400   connect( SelectButtonPt2, SIGNAL (clicked() ),       this, SLOT( SetEditCurrentArgument() ) ) ;
401   connect( SelectButtonFace, SIGNAL (clicked() ),      this, SLOT( SetEditCurrentArgument() ) ) ;
402   connect( SelectButtonDirection, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
403
404   connect( SpinBox_DX, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
405   connect( SpinBox_DY, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
406   connect( SpinBox_DZ, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
407
408   connect( SpinBox_C1Size, SIGNAL ( ValueChangedSignal( const double) ), this, SLOT( ValueChangedInSpinBox( const double) ) ) ;
409   connect( SpinBox_C2Size, SIGNAL ( ValueChangedSignal( const double) ), this, SLOT( ValueChangedInSpinBox( const double) ) ) ;
410   connect( SpinBox_C3Size, SIGNAL ( ValueChangedSignal( const double) ), this, SLOT( ValueChangedInSpinBox( const double) ) ) ;
411
412   connect( mySelection, SIGNAL( currentSelectionChanged() ),       this, SLOT( SelectionIntoArgument() ) );
413   connect( myGeomGUI,   SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
414   /* to close dialog if study change */
415   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
416  
417   /* Move widget on the botton right corner of main widget */
418   int x, y ;
419   myGeomGUI->DefineDlgPosition( this, x, y ) ;
420   this->move( x, y ) ;
421   this->show() ; /* Displays Dialog */ 
422
423   return ;
424 }
425
426
427
428 //=================================================================================
429 // function : ConstructorsClicked()
430 // purpose  : Radio button management
431 //=================================================================================
432 void GeometryGUI_PlaneDlg::ConstructorsClicked(int constructorId)
433 {
434   myGeomGUI->EraseSimulationShape() ;
435   myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false ;
436   mySelection->ClearFilters() ;
437   myConstructorId = constructorId ;
438   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
439
440   switch (constructorId)
441     {
442     case 0: /* plane from a point and a direction (vector, edge...) */
443       {
444         GroupPointDirection->show();    
445         GroupPointPlusCoordinates->hide() ;
446         GroupFace->hide() ;
447         myEditCurrentArgument = LineEditPt1 ;
448         LineEditPt1->setText(tr("")) ;
449         LineEditDirection->setText(tr("")) ;
450
451         /* for the first argument */
452         mySelection->AddFilter(myVertexFilter) ;
453         break;
454       }
455
456     case 1: /* plane from a point and vector coordinates */
457       {
458         GroupPointDirection->hide() ;
459         GroupPointPlusCoordinates->show() ;
460         GroupFace->hide() ;
461         myEditCurrentArgument = LineEditPt2 ;
462         LineEditPt2->setText(tr("")) ;
463         SpinBox_DX->SetValue( 1.0 ) ;
464         SpinBox_DY->SetValue( 1.0 ) ;
465         SpinBox_DZ->SetValue( 1.0 ) ;
466         myOkCoordinates = true ;
467
468         /* for the first argument */
469         mySelection->AddFilter(myVertexFilter) ;
470         break ;
471       }
472       
473     case 2: /* plane from a planar face selection */
474       {
475         GroupPointDirection->hide() ;
476         GroupPointPlusCoordinates->hide() ;
477         GroupFace->show() ;
478         myEditCurrentArgument = LineEditFace ;
479         LineEditFace->setText(tr("")) ;
480
481         /* for the first argument */
482         mySelection->AddFilter(myFaceFilter) ;
483         break ;
484       }
485
486     }
487  return ;
488 }
489
490 //=================================================================================
491 // function : ClickOnOk()
492 // purpose  :
493 //=================================================================================
494 void GeometryGUI_PlaneDlg::ClickOnOk()
495 {
496   this->ClickOnApply() ;
497   this->ClickOnCancel() ;
498
499   return ;
500 }
501
502 //=================================================================================
503 // function : ClickOnApply()
504 // purpose  :
505 //=================================================================================
506 void GeometryGUI_PlaneDlg::ClickOnApply()
507 {
508   myGeomGUI->EraseSimulationShape() ;
509   mySimulationTopoDs.Nullify() ;
510   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
511   switch(myConstructorId)
512     { 
513     case 0 : /* args are myPoint1 and myDx, myDy, myDz from a vector(edge) */
514       { 
515         if(myOkPoint1 && myOkDirection) {
516           myGeomGUI->MakePlaneAndDisplay( myPoint1, myDx, myDy, myDz, myTrimSize ) ;
517         }
518         break ;
519       }
520       
521     case 1 : /* args are myPoint1 and myDx, myDy, myDz from a Spin Box */
522       { 
523         if(myOkPoint1) {
524           myGeomGUI->MakePlaneAndDisplay( myPoint1, myDx, myDy, myDz, myTrimSize ) ;
525         }
526         break ;
527       }
528       
529     case 2 :  /* arg is a planar face selection */
530       {
531         if(myOkPlanarFace) {
532           myGeomGUI->MakePlaneAndDisplay( myPoint1, myDx, myDy, myDz, myTrimSize) ;
533         }
534         break ;
535       }
536     }
537   return ;
538 }
539
540
541 //=================================================================================
542 // function : ClickOnCancel()
543 // purpose  :
544 //=================================================================================
545 void GeometryGUI_PlaneDlg::ClickOnCancel()
546 {
547   mySelection->ClearFilters() ;
548   myGeomGUI->EraseSimulationShape() ;
549   mySimulationTopoDs.Nullify() ;
550   disconnect( mySelection, 0, this, 0 );
551   myGeomGUI->ResetState() ;
552   reject() ;
553   return ;
554 }
555
556
557 //=================================================================================
558 // function : SelectionIntoArgument()
559 // purpose  : Called when selection has changed
560 //=================================================================================
561 void GeometryGUI_PlaneDlg::SelectionIntoArgument()
562 {
563   
564   myGeomGUI->EraseSimulationShape() ; 
565   mySimulationTopoDs.Nullify() ;
566
567   /* Future name of argument */
568   QString aString = "";
569   
570   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
571   if ( nbSel != 1 ) {
572     switch (myConstructorId) 
573       {
574        case 0:
575          {
576            if ( myEditCurrentArgument == LineEditPt1 ) {
577              LineEditPt1->setText("") ;
578              myOkPoint1 = false ;
579            }
580            else if ( myEditCurrentArgument == LineEditDirection ) {
581              LineEditDirection->setText("") ;
582              myOkDirection = false ;
583            }
584            break ;
585          }
586       case 1:
587         {
588           if ( myEditCurrentArgument == LineEditPt2 ) {
589             LineEditPt2->setText("") ;
590             myOkPoint1 = false ;
591           }
592           break ;
593         }
594
595       case 2:
596         {
597           if ( myEditCurrentArgument == LineEditFace ) {
598             LineEditFace->setText("") ;
599             if ( aString.compare("") == 0 )
600               myOkPlanarFace = false ;
601             else
602               myOkPlanarFace = true ;
603           }
604           break ;
605         }
606
607       }
608     return ;
609   }
610
611   /*  nbSel == 1  */ 
612   TopoDS_Shape S; 
613   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
614     return ;
615  
616   
617   /* FIRST CONSTRUCTOR */
618   if ( myEditCurrentArgument == LineEditPt1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
619     LineEditPt1->setText(aString) ;
620     myOkPoint1 = true ;
621   }
622   else if ( myEditCurrentArgument == LineEditDirection ) {
623     /* We verify if the selection is a linear edge */
624     gp_Pnt Pfirst, Plast ;
625     if( myGeomGUI->LinearEdgeExtremities(S, Pfirst, Plast ) ) {    
626       myGeomGUI->GetBipointDxDyDz( Pfirst, Plast, myDx, myDy, myDz) ;
627       LineEditDirection->setText(aString) ;
628       myOkDirection = true ;
629       this->myTrimSize = SpinBox_C1Size->GetValue() ;
630     }
631   }
632   
633   /* SECOND CONSTRUCTOR */
634   else if ( myEditCurrentArgument == LineEditPt2 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
635     LineEditPt2->setText(aString) ;
636     /* Get arguments */
637     myDx = SpinBox_DX->GetValue() ;
638     myDy = SpinBox_DY->GetValue() ;
639     myDz = SpinBox_DZ->GetValue() ;
640     this->myTrimSize = SpinBox_C2Size->GetValue() ;
641     myOkPoint1 = true ;    
642     myOkCoordinates = true ;
643   }
644  
645   /* THIRD CONSTRUCTOR */
646   else if ( myEditCurrentArgument == LineEditFace) {
647     if( myOkPlanarFace ) {
648       LineEditFace->setText(aString) ;
649       BRepAdaptor_Surface surf(TopoDS::Face(S));
650       gp_Pln Plane = surf.Plane();
651
652       gp_Pnt myPoint1 = Plane.Location();
653       gp_Ax1 ax = Plane.Axis();
654       myDx = (ax.Direction()).X() ;
655       myDy = (ax.Direction()).Y() ;
656       myDz = (ax.Direction()).Z() ;
657       this->myTrimSize = SpinBox_C3Size->GetValue() ;
658     }
659   }
660
661   /* Call method simulation */    
662   if( ( myOkPoint1 && myOkDirection) || ( myOkPoint1 && myOkCoordinates ) || myOkPlanarFace ) {
663     if ( myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion()*Precision::Confusion() ) {
664       MakePlaneSimulationAndDisplay( myPoint1, myDx, myDy, myDz, myTrimSize ) ;
665     }
666   }
667   return ;
668 }
669
670
671
672 //=================================================================================
673 // function : SetEditCurrentArgument()
674 // purpose  :
675 //=================================================================================
676 void GeometryGUI_PlaneDlg::SetEditCurrentArgument()
677 {
678   QPushButton* send = (QPushButton*)sender();  
679   mySelection->ClearFilters() ;
680
681   switch (myConstructorId)
682     {
683     case 0:
684       { 
685         if(send == SelectButtonPt1) {
686           LineEditPt1->setFocus() ;
687           myEditCurrentArgument = LineEditPt1;
688           mySelection->AddFilter(myVertexFilter) ;
689         }
690         else if(send == SelectButtonDirection) {
691           LineEditDirection->setFocus() ;
692           myEditCurrentArgument = LineEditDirection;    
693           /* Edge filter here */
694           mySelection->AddFilter(myEdgeFilter) ;
695           SelectionIntoArgument() ;
696         }       
697         break;
698       }
699
700     case 1:
701       { 
702         if(send == SelectButtonPt2) {
703           LineEditPt2->setFocus() ;
704           myEditCurrentArgument = LineEditPt2;
705           /* Vertex filter here */
706           mySelection->AddFilter(myVertexFilter) ;
707           SelectionIntoArgument() ;
708         }
709         break;
710       }
711     
712     case 2:
713       {
714         if(send == SelectButtonFace) {
715           LineEditFace->setFocus() ;
716           myEditCurrentArgument = LineEditFace;
717           /* Face filter here */
718           mySelection->AddFilter(myFaceFilter) ;
719           SelectionIntoArgument() ;
720         }
721         break;
722       }
723       
724     }
725   return ;
726 }
727
728 //=================================================================================
729 // function : ValueChangedInSpinBox()
730 // purpose  :
731 //=================================================================================
732 void GeometryGUI_PlaneDlg::ValueChangedInSpinBox( double newValue )
733 {
734   QObject* send = (QObject*)sender() ; 
735   
736   if( send == SpinBox_DX ) {
737     myDx = newValue ;
738     myDy = SpinBox_DY->GetValue() ;
739     myDz = SpinBox_DZ->GetValue() ;
740   } else if( send == SpinBox_DY ) {
741     myDx = SpinBox_DX->GetValue() ;
742     myDy = newValue ;
743     myDz = SpinBox_DZ->GetValue() ;
744   } else if( send == SpinBox_DZ ) {
745     myDx = SpinBox_DX->GetValue() ;
746     myDy = SpinBox_DY->GetValue() ;
747     myDz = newValue ;
748   } else if( send == SpinBox_C1Size || send == SpinBox_C2Size || send == SpinBox_C3Size ) {
749     myTrimSize = newValue ;
750   } else
751     return ;
752   
753   if ( myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion() * Precision::Confusion() ) {
754     MakePlaneSimulationAndDisplay( myPoint1, myDx, myDy, myDz, myTrimSize ) ;
755   }
756   else {
757     myGeomGUI->EraseSimulationShape() ; 
758     mySimulationTopoDs.Nullify() ;
759   }  
760   return ;
761 }
762
763
764 //=================================================================================
765 // function : LineEditReturnPressed()
766 // purpose  :
767 //=================================================================================
768 void GeometryGUI_PlaneDlg::LineEditReturnPressed()
769 {
770   QLineEdit* send = (QLineEdit*)sender();  
771   if( send == LineEditPt1 )
772     myEditCurrentArgument = LineEditPt1 ;
773   else if ( send == LineEditDirection )
774     myEditCurrentArgument = LineEditDirection ; 
775   else if ( send == LineEditPt2 )
776     myEditCurrentArgument = LineEditPt2 ; 
777   else if ( send == LineEditFace )
778     myEditCurrentArgument = LineEditFace ; 
779   else
780     return ;
781   
782   /* User name of object input management                          */
783   /* If successfull the selection is changed and signal emitted... */
784   /* so SelectionIntoArgument() is automatically called.           */
785   const QString objectUserName = myEditCurrentArgument->text() ;
786   QWidget* thisWidget = (QWidget*)this ;
787   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
788     myEditCurrentArgument->setText( objectUserName ) ;
789   }
790   return ;
791 }
792
793
794 //=================================================================================
795 // function : DeactivateActiveDialog()
796 // purpose  :
797 //=================================================================================
798 void GeometryGUI_PlaneDlg::DeactivateActiveDialog()
799 {
800   if ( GroupConstructors->isEnabled() ) {
801     GroupConstructors->setEnabled(false) ;
802     GroupPointDirection->setEnabled(false) ;
803     GroupButtons->setEnabled(false) ;
804     GroupFace->setEnabled(false) ;
805     disconnect( mySelection, 0, this, 0 );
806     myGeomGUI->EraseSimulationShape() ;
807   }
808   return ;
809 }
810
811
812 //=================================================================================
813 // function : ActivateThisDialog()
814 // purpose  :
815 //=================================================================================
816 void GeometryGUI_PlaneDlg::ActivateThisDialog()
817 {
818   /* Emit a signal to deactivate the active dialog */
819   myGeomGUI->EmitSignalDeactivateDialog() ; 
820   
821   GroupConstructors->setEnabled(true) ;
822   GroupPointDirection->setEnabled(true) ;
823   GroupButtons->setEnabled(true) ;
824   GroupFace->setEnabled(true) ;
825   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
826   if( !mySimulationTopoDs.IsNull() )
827     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
828   return ;
829 }
830
831
832 //=================================================================================
833 // function : enterEvent()
834 // purpose  :
835 //=================================================================================
836 void GeometryGUI_PlaneDlg::enterEvent( QEvent* e)
837 {
838   if ( GroupConstructors->isEnabled() )
839     return ;  
840   ActivateThisDialog() ;
841 }
842
843
844 //=================================================================================
845 // function : closeEvent()
846 // purpose  :
847 //=================================================================================
848 void GeometryGUI_PlaneDlg::closeEvent( QCloseEvent* e )
849
850   /* same than click on cancel button */
851   this->ClickOnCancel() ;
852 }
853
854
855
856 //=================================================================================
857 // function : MakePlaneSimulationAndDisplay(()
858 // purpose  :
859 //=================================================================================
860 void GeometryGUI_PlaneDlg::MakePlaneSimulationAndDisplay( const gp_Pnt& P1,
861                                                           const Standard_Real dx,
862                                                           const Standard_Real dy, 
863                                                           const Standard_Real dz, 
864                                                           const Standard_Real trimsize )
865 {
866   try {
867     gp_Dir aDirection( dx, dy, dz ) ;
868     /* We make a trimmed plane */
869     gp_Pln gplane(P1, aDirection) ;
870     mySimulationTopoDs = BRepBuilderAPI_MakeFace(gplane, -trimsize, +trimsize, -trimsize, +trimsize) ;
871   }
872   catch(Standard_Failure) {
873     MESSAGE( "Exception catched in MakePlaneSimulation" << endl ) ;
874     return ;
875   }
876
877   myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
878   return ;
879 }