1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_FaceDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_FaceDlg.h"
31 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qcheckbox.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_FaceDlg()
55 // purpose : Constructs a GeometryGUI_FaceDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_FaceDlg::GeometryGUI_FaceDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BUILD_FACE")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_FaceDlg" );
69 setCaption( tr( "GEOM_FACE_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 GeometryGUI_FaceDlgLayout = new QGridLayout( this );
72 GeometryGUI_FaceDlgLayout->setSpacing( 6 );
73 GeometryGUI_FaceDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
78 GroupConstructors->setExclusive( TRUE );
79 GroupConstructors->setColumnLayout(0, Qt::Vertical );
80 GroupConstructors->layout()->setSpacing( 0 );
81 GroupConstructors->layout()->setMargin( 0 );
82 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84 GroupConstructorsLayout->setSpacing( 6 );
85 GroupConstructorsLayout->setMargin( 11 );
86 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
87 Constructor1->setText( tr( "" ) );
88 Constructor1->setPixmap( image0 );
89 Constructor1->setChecked( TRUE );
90 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
91 Constructor1->setMinimumSize( QSize( 50, 0 ) );
92 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
93 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94 GroupConstructorsLayout->addItem( spacer, 0, 1 );
95 GeometryGUI_FaceDlgLayout->addWidget( GroupConstructors, 0, 0 );
97 /***************************************************************/
98 GroupC1 = new QGroupBox( this, "GroupC1" );
99 GroupC1->setTitle( tr( "GEOM_FACE_FFW" ) );
100 GroupC1->setMinimumSize( QSize( 0, 0 ) );
101 GroupC1->setFrameShape( QGroupBox::Box );
102 GroupC1->setFrameShadow( QGroupBox::Sunken );
103 GroupC1->setColumnLayout(0, Qt::Vertical );
104 GroupC1->layout()->setSpacing( 0 );
105 GroupC1->layout()->setMargin( 0 );
106 GroupC1Layout = new QGridLayout( GroupC1->layout() );
107 GroupC1Layout->setAlignment( Qt::AlignTop );
108 GroupC1Layout->setSpacing( 6 );
109 GroupC1Layout->setMargin( 11 );
110 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
111 TextLabelC1A1->setText( tr( "GEOM_WIRE" ) );
112 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
113 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
114 TextLabelC1A1->setFrameShadow( QLabel::Plain );
115 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
116 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
117 SelectButtonC1A1->setText( tr( "" ) );
118 SelectButtonC1A1->setPixmap( image1 );
119 SelectButtonC1A1->setToggleButton( FALSE );
120 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
121 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
122 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
123 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
124 CheckBox1->setText( tr( "GEOM_FACE_OPT" ) );
125 CheckBox1->setChecked( TRUE );
126 GroupC1Layout->addWidget( CheckBox1, 1, 2);
127 GeometryGUI_FaceDlgLayout->addWidget( GroupC1, 1, 0 );
129 /***************************************************************/
130 GroupButtons = new QGroupBox( this, "GroupButtons" );
131 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
132 GroupButtons->setTitle( tr( "" ) );
133 GroupButtons->setColumnLayout(0, Qt::Vertical );
134 GroupButtons->layout()->setSpacing( 0 );
135 GroupButtons->layout()->setMargin( 0 );
136 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
137 GroupButtonsLayout->setAlignment( Qt::AlignTop );
138 GroupButtonsLayout->setSpacing( 6 );
139 GroupButtonsLayout->setMargin( 11 );
140 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
141 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
142 buttonCancel->setAutoDefault( TRUE );
143 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
144 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
145 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
146 buttonApply->setAutoDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
148 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
149 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
150 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
151 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
152 buttonOk->setAutoDefault( TRUE );
153 buttonOk->setDefault( TRUE );
154 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
155 GeometryGUI_FaceDlgLayout->addWidget( GroupButtons, 2, 0 );
157 Init(Sel) ; /* Initialisations */
161 //=================================================================================
162 // function : ~GeometryGUI_FaceDlg()
163 // purpose : Destroys the object and frees any allocated resources
164 //=================================================================================
165 GeometryGUI_FaceDlg::~GeometryGUI_FaceDlg()
167 // no need to delete child widgets, Qt does it all for us
172 //=================================================================================
175 //=================================================================================
176 void GeometryGUI_FaceDlg::Init( SALOME_Selection* Sel )
180 myConstructorId = 0 ;
181 Constructor1->setChecked( TRUE );
182 CheckBox1->setChecked( TRUE );
184 myEditCurrentArgument = LineEditC1A1 ;
186 this->myOkShape = false ;
187 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
188 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
190 // TODO previous selection into argument ?
192 /* Filter definitions */
193 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
194 myGeom = GEOM::GEOM_Gen::_narrow(comp);
195 myWireFilter = new GEOM_ShapeTypeFilter( TopAbs_WIRE, myGeom );
196 mySelection->AddFilter(myWireFilter) ; /* first filter used */
198 /* signals and slots connections */
199 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
200 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
201 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
202 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
204 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
206 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
207 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
208 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209 /* to close dialog if study change */
210 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
212 /* Move widget on the botton right corner of main widget */
214 myGeomGUI->DefineDlgPosition( this, x, y ) ;
216 this->show() ; /* displays Dialog */
222 //=================================================================================
223 // function : ConstructorsClicked()
224 // purpose : Radio button management
225 //=================================================================================
226 void GeometryGUI_FaceDlg::ConstructorsClicked(int constructorId)
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void GeometryGUI_FaceDlg::ClickOnOk()
237 this->ClickOnApply() ;
238 this->ClickOnCancel() ;
243 //=================================================================================
244 // function : ClickOnApply()
246 //=================================================================================
247 void GeometryGUI_FaceDlg::ClickOnApply()
249 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
250 switch(myConstructorId)
255 myGeomGUI->MakeFaceAndDisplay(this->myGeomShape, this->CheckBox1->isChecked() ) ;
265 //=================================================================================
266 // function : ClickOnCancel()
268 //=================================================================================
269 void GeometryGUI_FaceDlg::ClickOnCancel()
271 mySelection->ClearFilters() ;
272 myGeomGUI->ResetState() ;
273 disconnect( mySelection, 0, this, 0 );
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose : Called when selection as changed or other case
282 //=================================================================================
283 void GeometryGUI_FaceDlg::SelectionIntoArgument()
285 /* All this for first constructor */
286 // if(myEditCurrentArgument == LineEditC1A1 )
289 myEditCurrentArgument->setText("") ;
290 QString aString = ""; /* future the name of selection */
292 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
297 Standard_Boolean testResult ;
298 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
299 if( !myGeomGUI->GetTopoFromSelection(this->mySelection, this->myShape) )
302 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
306 myEditCurrentArgument->setText(aString) ;
307 this->myOkShape = true ;
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void GeometryGUI_FaceDlg::SetEditCurrentArgument()
320 QPushButton* send = (QPushButton*)sender();
321 mySelection->ClearFilters() ;
323 switch (myConstructorId)
325 case 0: /* default constructor */
327 if(send == SelectButtonC1A1) {
328 LineEditC1A1->setFocus() ;
329 myEditCurrentArgument = LineEditC1A1;
330 mySelection->AddFilter(myWireFilter) ;
332 SelectionIntoArgument() ;
341 //=================================================================================
342 // function : LineEditReturnPressed()
344 //=================================================================================
345 void GeometryGUI_FaceDlg::LineEditReturnPressed()
347 QLineEdit* send = (QLineEdit*)sender();
348 if( send == LineEditC1A1 )
349 myEditCurrentArgument = LineEditC1A1 ;
353 /* User name of object input management */
354 /* If successfull the selection is changed and signal emitted... */
355 /* so SelectionIntoArgument() is automatically called. */
356 const QString objectUserName = myEditCurrentArgument->text() ;
357 QWidget* thisWidget = (QWidget*)this ;
358 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
359 myEditCurrentArgument->setText( objectUserName ) ;
365 //=================================================================================
366 // function : DeactivateActiveDialog()
368 //=================================================================================
369 void GeometryGUI_FaceDlg::DeactivateActiveDialog()
371 if ( GroupConstructors->isEnabled() ) {
372 disconnect( mySelection, 0, this, 0 );
373 mySelection->ClearFilters() ;
374 GroupConstructors->setEnabled(false) ;
375 GroupC1->setEnabled(false) ;
376 GroupButtons->setEnabled(false) ;
382 //=================================================================================
383 // function : ActivateThisDialog()
385 //=================================================================================
386 void GeometryGUI_FaceDlg::ActivateThisDialog()
388 /* Emit a signal to deactivate the active dialog */
389 myGeomGUI->EmitSignalDeactivateDialog() ;
390 GroupConstructors->setEnabled(true) ;
391 GroupC1->setEnabled(true) ;
392 GroupButtons->setEnabled(true) ;
393 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
398 //=================================================================================
399 // function : enterEvent()
401 //=================================================================================
402 void GeometryGUI_FaceDlg::enterEvent(QEvent* e)
404 if ( GroupConstructors->isEnabled() )
406 ActivateThisDialog() ;
411 //=================================================================================
412 // function : closeEvent()
414 //=================================================================================
415 void GeometryGUI_FaceDlg::closeEvent( QCloseEvent* e )
417 /* same than click on cancel button */
418 this->ClickOnCancel() ;