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_SewingDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_SewingDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
46 #include <qvalidator.h>
47 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_SewingDlg()
55 // purpose : Constructs a GeometryGUI_SewingDlg 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_SewingDlg::GeometryGUI_SewingDlg( 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_SEWING")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_SewingDlg" );
69 setCaption( tr( "GEOM_SEWING_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 GeometryGUI_SewingDlgLayout = new QGridLayout( this );
72 GeometryGUI_SewingDlgLayout->setSpacing( 6 );
73 GeometryGUI_SewingDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_SEWING" ) );
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)3, (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_SewingDlgLayout->addWidget( GroupConstructors, 0, 0 );
97 /***************************************************************/
98 GroupButtons = new QGroupBox( this, "GroupButtons" );
99 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
100 GroupButtons->setTitle( tr( "" ) );
101 GroupButtons->setColumnLayout(0, Qt::Vertical );
102 GroupButtons->layout()->setSpacing( 0 );
103 GroupButtons->layout()->setMargin( 0 );
104 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
105 GroupButtonsLayout->setAlignment( Qt::AlignTop );
106 GroupButtonsLayout->setSpacing( 6 );
107 GroupButtonsLayout->setMargin( 11 );
108 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
109 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
110 buttonCancel->setAutoDefault( TRUE );
111 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
112 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
113 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
114 buttonApply->setAutoDefault( TRUE );
115 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
116 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
117 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
118 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
119 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
120 buttonOk->setAutoDefault( TRUE );
121 buttonOk->setDefault( TRUE );
122 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
123 GeometryGUI_SewingDlgLayout->addWidget( GroupButtons, 2, 0 );
124 GroupC1 = new QGroupBox( this, "GroupC1" );
125 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
126 GroupC1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupC1->sizePolicy().hasHeightForWidth() ) );
127 GroupC1->setColumnLayout(0, Qt::Vertical );
128 GroupC1->layout()->setSpacing( 0 );
129 GroupC1->layout()->setMargin( 0 );
130 GroupC1Layout = new QGridLayout( GroupC1->layout() );
131 GroupC1Layout->setAlignment( Qt::AlignTop );
132 GroupC1Layout->setSpacing( 6 );
133 GroupC1Layout->setMargin( 11 );
134 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
135 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
136 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
137 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
138 LineEditC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2->sizePolicy().hasHeightForWidth() ) );
139 LineEditC1A2->setMinimumSize( QSize( 40, 0 ) );
140 LineEditC1A2->setMaximumSize( QSize( 32767, 32767 ) );
141 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
142 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
143 SelectButtonC1A1->setText( tr( "" ) );
144 SelectButtonC1A1->setPixmap( image1 );
145 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
146 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
147 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
148 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
149 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
150 TextLabelC1A1->setFrameShadow( QLabel::Plain );
151 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
152 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
153 TextLabelC1A2->setText( tr( "GEOM_PRECISION" ) );
154 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
155 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
156 TextLabelC1A2->setFrameShadow( QLabel::Plain );
157 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
158 GeometryGUI_SewingDlgLayout->addWidget( GroupC1, 1, 0 );
159 /***************************************************************/
161 Init(Sel) ; /* Initialisations */
165 //=================================================================================
166 // function : ~GeometryGUI_SewingDlg()
167 // purpose : Destroys the object and frees any allocated resources
168 //=================================================================================
169 GeometryGUI_SewingDlg::~GeometryGUI_SewingDlg()
171 // no need to delete child widgets, Qt does it all for us
175 //=================================================================================
178 //=================================================================================
179 void GeometryGUI_SewingDlg::Init( SALOME_Selection* Sel )
181 LineEditC1A1->setMaxLength( 10 );
182 QDoubleValidator *Va = new QDoubleValidator( -0.000001, +10000.0, 3, LineEditC1A1 ) ;
183 LineEditC1A1->setValidator( Va ) ;
186 myConstructorId = 0 ;
187 Constructor1->setChecked( TRUE );
188 myEditCurrentArgument = LineEditC1A1 ;
190 this->myOkListShapes = false ;
191 this->myPrecision = 0.00001 ;
192 LineEditC1A2->setText("0.00001") ;
193 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
194 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
196 // TODO previous selection into argument ?
198 /* Filter definitions */
199 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
200 myGeom = GEOM::GEOM_Gen::_narrow(comp);
202 /* signals and slots connections */
203 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
204 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
205 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
206 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
208 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
209 connect( LineEditC1A2, SIGNAL (returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
210 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
211 /* to close dialog if study change */
212 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
214 /* Move widget on the botton right corner of main widget */
216 myGeomGUI->DefineDlgPosition( this, x, y ) ;
218 this->show() ; /* displays Dialog */
224 //=================================================================================
225 // function : ConstructorsClicked()
226 // purpose : Radio button management
227 //=================================================================================
228 void GeometryGUI_SewingDlg::ConstructorsClicked(int constructorId)
233 //=================================================================================
234 // function : ClickOnOk()
236 //=================================================================================
237 void GeometryGUI_SewingDlg::ClickOnOk()
239 this->ClickOnApply() ;
240 this->ClickOnCancel() ;
245 //=================================================================================
246 // function : ClickOnApply()
248 //=================================================================================
249 void GeometryGUI_SewingDlg::ClickOnApply()
251 switch(myConstructorId)
256 myGeomGUI->MakeSewingAndDisplay( myListShapes, myPrecision ) ;
266 //=================================================================================
267 // function : ClickOnCancel()
269 //=================================================================================
270 void GeometryGUI_SewingDlg::ClickOnCancel()
272 myGeomGUI->ResetState() ;
278 //=================================================================================
279 // function : SelectionIntoArgument()
280 // purpose : Called when selection as changed or other case
281 //=================================================================================
282 void GeometryGUI_SewingDlg::SelectionIntoArgument()
284 /* All this for first constructor */
285 // if(myEditCurrentArgument == LineEditC1A1 )
287 myOkListShapes = false;
288 myEditCurrentArgument->setText("") ;
289 QString aString = ""; /* name of selection */
291 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
296 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
297 myEditCurrentArgument->setText(aString) ;
298 myOkListShapes = true ;
305 //=================================================================================
306 // function : SetEditCurrentArgument()
308 //=================================================================================
309 void GeometryGUI_SewingDlg::SetEditCurrentArgument()
311 QPushButton* send = (QPushButton*)sender();
312 switch (myConstructorId)
314 case 0: /* default constructor */
316 if(send == SelectButtonC1A1) {
317 LineEditC1A1->setFocus() ;
318 myEditCurrentArgument = LineEditC1A1;
320 SelectionIntoArgument() ;
329 //=================================================================================
330 // function : LineEditReturnPressed()
332 //=================================================================================
333 void GeometryGUI_SewingDlg::LineEditReturnPressed()
335 this->myPrecision = LineEditC1A2->text().toFloat();
340 //=================================================================================
341 // function : DeactivateActiveDialog()
343 //=================================================================================
344 void GeometryGUI_SewingDlg::DeactivateActiveDialog()
346 if ( GroupConstructors->isEnabled() ) {
347 GroupConstructors->setEnabled(false) ;
348 GroupC1->setEnabled(false) ;
349 GroupButtons->setEnabled(false) ;
355 //=================================================================================
356 // function : ActivateThisDialog()
358 //=================================================================================
359 void GeometryGUI_SewingDlg::ActivateThisDialog()
361 /* Emit a signal to deactivate the active dialog */
362 myGeomGUI->EmitSignalDeactivateDialog() ;
363 GroupConstructors->setEnabled(true) ;
364 GroupC1->setEnabled(true) ;
365 GroupButtons->setEnabled(true) ;
370 //=================================================================================
371 // function : enterEvent()
373 //=================================================================================
374 void GeometryGUI_SewingDlg::enterEvent(QEvent* e)
376 if ( GroupConstructors->isEnabled() )
378 ActivateThisDialog() ;
383 //=================================================================================
384 // function : closeEvent()
386 //=================================================================================
387 void GeometryGUI_SewingDlg::closeEvent( QCloseEvent* e )
389 /* same than click on cancel button */
390 this->ClickOnCancel() ;