2 // File : GeometryGUI_FaceDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
11 #include "GeometryGUI_FaceDlg.h"
12 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 #include <qbuttongroup.h>
19 #include <qcheckbox.h>
20 #include <qgroupbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
28 #include <qwhatsthis.h>
34 //=================================================================================
35 // class : GeometryGUI_FaceDlg()
36 // purpose : Constructs a GeometryGUI_FaceDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 GeometryGUI_FaceDlg::GeometryGUI_FaceDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BUILD_FACE")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
48 setName( "GeometryGUI_FaceDlg" );
50 setCaption( tr( "GEOM_FACE_TITLE" ) );
51 setSizeGripEnabled( TRUE );
52 GeometryGUI_FaceDlgLayout = new QGridLayout( this );
53 GeometryGUI_FaceDlgLayout->setSpacing( 6 );
54 GeometryGUI_FaceDlgLayout->setMargin( 11 );
56 /***************************************************************/
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
59 GroupConstructors->setExclusive( TRUE );
60 GroupConstructors->setColumnLayout(0, Qt::Vertical );
61 GroupConstructors->layout()->setSpacing( 0 );
62 GroupConstructors->layout()->setMargin( 0 );
63 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
64 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
65 GroupConstructorsLayout->setSpacing( 6 );
66 GroupConstructorsLayout->setMargin( 11 );
67 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
68 Constructor1->setText( tr( "" ) );
69 Constructor1->setPixmap( image0 );
70 Constructor1->setChecked( TRUE );
71 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
72 Constructor1->setMinimumSize( QSize( 50, 0 ) );
73 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
74 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
75 GroupConstructorsLayout->addItem( spacer, 0, 1 );
76 GeometryGUI_FaceDlgLayout->addWidget( GroupConstructors, 0, 0 );
78 /***************************************************************/
79 GroupC1 = new QGroupBox( this, "GroupC1" );
80 GroupC1->setTitle( tr( "GEOM_FACE_FFW" ) );
81 GroupC1->setMinimumSize( QSize( 0, 0 ) );
82 GroupC1->setFrameShape( QGroupBox::Box );
83 GroupC1->setFrameShadow( QGroupBox::Sunken );
84 GroupC1->setColumnLayout(0, Qt::Vertical );
85 GroupC1->layout()->setSpacing( 0 );
86 GroupC1->layout()->setMargin( 0 );
87 GroupC1Layout = new QGridLayout( GroupC1->layout() );
88 GroupC1Layout->setAlignment( Qt::AlignTop );
89 GroupC1Layout->setSpacing( 6 );
90 GroupC1Layout->setMargin( 11 );
91 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
92 TextLabelC1A1->setText( tr( "GEOM_WIRE" ) );
93 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
94 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
95 TextLabelC1A1->setFrameShadow( QLabel::Plain );
96 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
97 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
98 SelectButtonC1A1->setText( tr( "" ) );
99 SelectButtonC1A1->setPixmap( image1 );
100 SelectButtonC1A1->setToggleButton( FALSE );
101 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
102 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
103 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
104 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
105 CheckBox1->setText( tr( "GEOM_FACE_OPT" ) );
106 CheckBox1->setChecked( TRUE );
107 GroupC1Layout->addWidget( CheckBox1, 1, 2);
108 GeometryGUI_FaceDlgLayout->addWidget( GroupC1, 1, 0 );
110 /***************************************************************/
111 GroupButtons = new QGroupBox( this, "GroupButtons" );
112 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
113 GroupButtons->setTitle( tr( "" ) );
114 GroupButtons->setColumnLayout(0, Qt::Vertical );
115 GroupButtons->layout()->setSpacing( 0 );
116 GroupButtons->layout()->setMargin( 0 );
117 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
118 GroupButtonsLayout->setAlignment( Qt::AlignTop );
119 GroupButtonsLayout->setSpacing( 6 );
120 GroupButtonsLayout->setMargin( 11 );
121 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
122 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
123 buttonCancel->setAutoDefault( TRUE );
124 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
125 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
126 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
127 buttonApply->setAutoDefault( TRUE );
128 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
129 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
130 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
131 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
132 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
133 buttonOk->setAutoDefault( TRUE );
134 buttonOk->setDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
136 GeometryGUI_FaceDlgLayout->addWidget( GroupButtons, 2, 0 );
138 Init(Sel) ; /* Initialisations */
142 //=================================================================================
143 // function : ~GeometryGUI_FaceDlg()
144 // purpose : Destroys the object and frees any allocated resources
145 //=================================================================================
146 GeometryGUI_FaceDlg::~GeometryGUI_FaceDlg()
148 // no need to delete child widgets, Qt does it all for us
153 //=================================================================================
156 //=================================================================================
157 void GeometryGUI_FaceDlg::Init( SALOME_Selection* Sel )
161 myConstructorId = 0 ;
162 Constructor1->setChecked( TRUE );
163 CheckBox1->setChecked( TRUE );
165 myEditCurrentArgument = LineEditC1A1 ;
167 this->myOkShape = false ;
168 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
169 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
171 // TODO previous selection into argument ?
173 /* Filter definitions */
174 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
175 myGeom = GEOM::GEOM_Gen::_narrow(comp);
176 myWireFilter = new GEOM_ShapeTypeFilter( TopAbs_WIRE, myGeom );
177 mySelection->AddFilter(myWireFilter) ; /* first filter used */
179 /* signals and slots connections */
180 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
181 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
182 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
183 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
185 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
187 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
188 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
189 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
190 /* to close dialog if study change */
191 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
193 /* Move widget on the botton right corner of main widget */
195 myGeomGUI->DefineDlgPosition( this, x, y ) ;
197 this->show() ; /* displays Dialog */
203 //=================================================================================
204 // function : ConstructorsClicked()
205 // purpose : Radio button management
206 //=================================================================================
207 void GeometryGUI_FaceDlg::ConstructorsClicked(int constructorId)
212 //=================================================================================
213 // function : ClickOnOk()
215 //=================================================================================
216 void GeometryGUI_FaceDlg::ClickOnOk()
218 this->ClickOnApply() ;
219 this->ClickOnCancel() ;
224 //=================================================================================
225 // function : ClickOnApply()
227 //=================================================================================
228 void GeometryGUI_FaceDlg::ClickOnApply()
230 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
231 switch(myConstructorId)
236 myGeomGUI->MakeFaceAndDisplay(this->myGeomShape, this->CheckBox1->isChecked() ) ;
246 //=================================================================================
247 // function : ClickOnCancel()
249 //=================================================================================
250 void GeometryGUI_FaceDlg::ClickOnCancel()
252 mySelection->ClearFilters() ;
253 myGeomGUI->ResetState() ;
254 disconnect( mySelection, 0, this, 0 );
260 //=================================================================================
261 // function : SelectionIntoArgument()
262 // purpose : Called when selection as changed or other case
263 //=================================================================================
264 void GeometryGUI_FaceDlg::SelectionIntoArgument()
266 /* All this for first constructor */
267 // if(myEditCurrentArgument == LineEditC1A1 )
270 myEditCurrentArgument->setText("") ;
271 QString aString = ""; /* future the name of selection */
273 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
278 Standard_Boolean testResult ;
279 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
280 if( !myGeomGUI->GetTopoFromSelection(this->mySelection, this->myShape) )
283 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
287 myEditCurrentArgument->setText(aString) ;
288 this->myOkShape = true ;
295 //=================================================================================
296 // function : SetEditCurrentArgument()
298 //=================================================================================
299 void GeometryGUI_FaceDlg::SetEditCurrentArgument()
301 QPushButton* send = (QPushButton*)sender();
302 mySelection->ClearFilters() ;
304 switch (myConstructorId)
306 case 0: /* default constructor */
308 if(send == SelectButtonC1A1) {
309 LineEditC1A1->setFocus() ;
310 myEditCurrentArgument = LineEditC1A1;
311 mySelection->AddFilter(myWireFilter) ;
313 SelectionIntoArgument() ;
322 //=================================================================================
323 // function : LineEditReturnPressed()
325 //=================================================================================
326 void GeometryGUI_FaceDlg::LineEditReturnPressed()
328 QLineEdit* send = (QLineEdit*)sender();
329 if( send == LineEditC1A1 )
330 myEditCurrentArgument = LineEditC1A1 ;
334 /* User name of object input management */
335 /* If successfull the selection is changed and signal emitted... */
336 /* so SelectionIntoArgument() is automatically called. */
337 const QString objectUserName = myEditCurrentArgument->text() ;
338 QWidget* thisWidget = (QWidget*)this ;
339 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
340 myEditCurrentArgument->setText( objectUserName ) ;
346 //=================================================================================
347 // function : DeactivateActiveDialog()
349 //=================================================================================
350 void GeometryGUI_FaceDlg::DeactivateActiveDialog()
352 if ( GroupConstructors->isEnabled() ) {
353 disconnect( mySelection, 0, this, 0 );
354 mySelection->ClearFilters() ;
355 GroupConstructors->setEnabled(false) ;
356 GroupC1->setEnabled(false) ;
357 GroupButtons->setEnabled(false) ;
363 //=================================================================================
364 // function : ActivateThisDialog()
366 //=================================================================================
367 void GeometryGUI_FaceDlg::ActivateThisDialog()
369 /* Emit a signal to deactivate the active dialog */
370 myGeomGUI->EmitSignalDeactivateDialog() ;
371 GroupConstructors->setEnabled(true) ;
372 GroupC1->setEnabled(true) ;
373 GroupButtons->setEnabled(true) ;
374 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
379 //=================================================================================
380 // function : enterEvent()
382 //=================================================================================
383 void GeometryGUI_FaceDlg::enterEvent(QEvent* e)
385 if ( GroupConstructors->isEnabled() )
387 ActivateThisDialog() ;
392 //=================================================================================
393 // function : closeEvent()
395 //=================================================================================
396 void GeometryGUI_FaceDlg::closeEvent( QCloseEvent* e )
398 /* same than click on cancel button */
399 this->ClickOnCancel() ;