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