2 // File : GeometryGUI_WorkingPlaneDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_WorkingPlaneDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <BRepAdaptor_Surface.hxx>
22 #include <qbuttongroup.h>
23 #include <qgroupbox.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
31 #include <qwhatsthis.h>
35 //=================================================================================
36 // class : GeometryGUI_WorkingPlaneDlg()
37 // purpose : Constructs a GeometryGUI_WorkingPlaneDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 GeometryGUI_WorkingPlaneDlg::GeometryGUI_WorkingPlaneDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
43 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_WPLANE_FACE")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
49 setName( "GeometryGUI_WorkingPlaneDlg" );
51 setCaption( tr( "GEOM_WPLANE_TITLE" ) );
52 setSizeGripEnabled( TRUE );
53 GeometryGUI_WorkingPlaneDlgLayout = new QGridLayout( this );
54 GeometryGUI_WorkingPlaneDlgLayout->setSpacing( 6 );
55 GeometryGUI_WorkingPlaneDlgLayout->setMargin( 11 );
57 /***************************************************************/
58 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
59 GroupConstructors->setTitle( tr( "GEOM_WPLANE" ) );
60 GroupConstructors->setExclusive( TRUE );
61 GroupConstructors->setColumnLayout(0, Qt::Vertical );
62 GroupConstructors->layout()->setSpacing( 0 );
63 GroupConstructors->layout()->setMargin( 0 );
64 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
65 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
66 GroupConstructorsLayout->setSpacing( 6 );
67 GroupConstructorsLayout->setMargin( 11 );
68 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
69 Constructor1->setText( tr( "" ) );
70 Constructor1->setPixmap( image0 );
71 Constructor1->setChecked( TRUE );
72 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
73 Constructor1->setMinimumSize( QSize( 50, 0 ) );
74 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
75 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
76 GroupConstructorsLayout->addItem( spacer, 0, 1 );
77 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupConstructors, 0, 0 );
79 /***************************************************************/
80 GroupButtons = new QGroupBox( this, "GroupButtons" );
81 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
82 GroupButtons->setTitle( tr( "" ) );
83 GroupButtons->setColumnLayout(0, Qt::Vertical );
84 GroupButtons->layout()->setSpacing( 0 );
85 GroupButtons->layout()->setMargin( 0 );
86 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
87 GroupButtonsLayout->setAlignment( Qt::AlignTop );
88 GroupButtonsLayout->setSpacing( 6 );
89 GroupButtonsLayout->setMargin( 11 );
90 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
91 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
92 buttonCancel->setAutoDefault( TRUE );
93 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
94 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
95 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
96 buttonApply->setAutoDefault( TRUE );
97 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
98 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
100 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
101 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
102 buttonOk->setAutoDefault( TRUE );
103 buttonOk->setDefault( TRUE );
104 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
105 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupButtons, 2, 0 );
107 /***************************************************************/
108 GroupC1 = new QGroupBox( this, "GroupC1" );
109 GroupC1->setTitle( tr( "GEOM_WPLANE_FACE" ) );
110 GroupC1->setMinimumSize( QSize( 0, 0 ) );
111 GroupC1->setFrameShape( QGroupBox::Box );
112 GroupC1->setFrameShadow( QGroupBox::Sunken );
113 GroupC1->setColumnLayout(0, Qt::Vertical );
114 GroupC1->layout()->setSpacing( 0 );
115 GroupC1->layout()->setMargin( 0 );
116 GroupC1Layout = new QGridLayout( GroupC1->layout() );
117 GroupC1Layout->setAlignment( Qt::AlignTop );
118 GroupC1Layout->setSpacing( 6 );
119 GroupC1Layout->setMargin( 11 );
120 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
121 TextLabelC1A1->setText( tr( "GEOM_SELECTION" ) );
122 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
123 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
124 TextLabelC1A1->setFrameShadow( QLabel::Plain );
125 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
126 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
127 SelectButtonC1A1->setText( tr( "" ) );
128 SelectButtonC1A1->setPixmap( image1 );
129 SelectButtonC1A1->setToggleButton( FALSE );
130 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
131 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
132 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
133 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupC1, 1, 0 );
134 /***************************************************************/
136 Init(Sel) ; /* Initialisations */
139 //=================================================================================
140 // function : ~GeometryGUI_WorkingPlaneDlg()
141 // purpose : Destroys the object and frees any allocated resources
142 //=================================================================================
143 GeometryGUI_WorkingPlaneDlg::~GeometryGUI_WorkingPlaneDlg()
145 // no need to delete child widgets, Qt does it all for us
149 //=================================================================================
152 //=================================================================================
153 void GeometryGUI_WorkingPlaneDlg::Init( SALOME_Selection* Sel )
157 myConstructorId = 0 ;
158 Constructor1->setChecked( TRUE );
159 myEditCurrentArgument = LineEditC1A1 ;
161 this->myOkPlane = false ;
162 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
163 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
165 // TODO : previous selection into argument ?
167 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
168 myGeom = GEOM::GEOM_Gen::_narrow(comp);
169 /* Filter definition */
170 myFaceFilter = new GEOM_FaceFilter( StdSelect_Plane, myGeom );
171 mySelection->AddFilter( myFaceFilter ); /* filter for next selection */
173 /* signals and slots connections */
174 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
175 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
176 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
177 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
179 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
181 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
182 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
183 /* to close dialog if study change */
184 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
186 /* Move widget on the botton right corner of main widget */
188 myGeomGUI->DefineDlgPosition( this, x, y ) ;
190 this->show() ; /* displays Dialog */
196 //=================================================================================
197 // function : ConstructorsClicked()
198 // purpose : Radio button management
199 //=================================================================================
200 void GeometryGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void GeometryGUI_WorkingPlaneDlg::ClickOnOk()
211 this->ClickOnApply() ;
212 this->ClickOnCancel() ;
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 void GeometryGUI_WorkingPlaneDlg::ClickOnApply()
223 mySelection->ClearFilters() ;
224 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
225 switch(myConstructorId)
230 myGeomGUI->MakeWorkingPlane( this->myLoc, this->myDir ) ;
240 //=================================================================================
241 // function : ClickOnCancel()
243 //=================================================================================
244 void GeometryGUI_WorkingPlaneDlg::ClickOnCancel()
246 mySelection->ClearFilters() ;
247 disconnect( mySelection, 0, this, 0 );
248 myGeomGUI->ResetState() ;
254 //=================================================================================
255 // function : SelectionIntoArgument()
256 // purpose : Called when selection as changed or other case
257 //=================================================================================
258 void GeometryGUI_WorkingPlaneDlg::SelectionIntoArgument()
260 /* All this for first constructor */
261 // if(myEditCurrentArgument == LineEditC1A1 )
263 myEditCurrentArgument->setText("") ;
264 QString aString = ""; /* future the name of selection */
266 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
268 switch (myConstructorId)
272 if ( myEditCurrentArgument == LineEditC1A1 ) {
283 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
286 if ( myEditCurrentArgument == LineEditC1A1 ) {
287 BRepAdaptor_Surface surf(TopoDS::Face(S));
288 gp_Pln Plane = surf.Plane();
289 myLoc = Plane.Location();
290 myDir = Plane.Axis().Direction();
292 LineEditC1A1->setText(aString) ;
301 //=================================================================================
302 // function : SetEditCurrentArgument()
304 //=================================================================================
305 void GeometryGUI_WorkingPlaneDlg::SetEditCurrentArgument()
307 QPushButton* send = (QPushButton*)sender();
308 switch (myConstructorId)
310 case 0: /* default constructor */
312 if(send == SelectButtonC1A1) {
313 LineEditC1A1->setFocus() ;
314 myEditCurrentArgument = LineEditC1A1;
316 mySelection->AddFilter(myFaceFilter) ;
317 SelectionIntoArgument() ;
326 //=================================================================================
327 // function : LineEditReturnPressed()
329 //=================================================================================
330 void GeometryGUI_WorkingPlaneDlg::LineEditReturnPressed()
332 QLineEdit* send = (QLineEdit*)sender();
333 if( send == LineEditC1A1 )
334 myEditCurrentArgument = LineEditC1A1 ;
337 /* User name of object input management */
338 /* If successfull the selection is changed and signal emitted... */
339 /* so SelectionIntoArgument() is automatically called. */
340 const QString objectUserName = myEditCurrentArgument->text() ;
341 QWidget* thisWidget = (QWidget*)this ;
342 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
343 myEditCurrentArgument->setText( objectUserName ) ;
349 //=================================================================================
350 // function : DeactivateActiveDialog()
352 //=================================================================================
353 void GeometryGUI_WorkingPlaneDlg::DeactivateActiveDialog()
355 if ( GroupConstructors->isEnabled() ) {
356 mySelection->ClearFilters() ;
357 disconnect( mySelection, 0, this, 0 );
358 GroupConstructors->setEnabled(false) ;
359 GroupC1->setEnabled(false) ;
360 GroupButtons->setEnabled(false) ;
366 //=================================================================================
367 // function : ActivateThisDialog()
369 //=================================================================================
370 void GeometryGUI_WorkingPlaneDlg::ActivateThisDialog()
372 /* Emit a signal to deactivate the active dialog */
373 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
374 myGeomGUI->EmitSignalDeactivateDialog() ;
375 GroupConstructors->setEnabled(true) ;
376 GroupC1->setEnabled(true) ;
377 GroupButtons->setEnabled(true) ;
382 //=================================================================================
383 // function : enterEvent()
385 //=================================================================================
386 void GeometryGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
388 if ( GroupConstructors->isEnabled() )
390 ActivateThisDialog() ;
395 //=================================================================================
396 // function : closeEvent()
398 //=================================================================================
399 void GeometryGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
401 /* same than click on cancel button */
402 this->ClickOnCancel() ;