2 // File : GeometryGUI_SewingDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_SewingDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
26 #include <qvalidator.h>
27 #include <qwhatsthis.h>
33 //=================================================================================
34 // class : GeometryGUI_SewingDlg()
35 // purpose : Constructs a GeometryGUI_SewingDlg which is a child of 'parent', with the
36 // name 'name' and widget flags set to 'f'.
37 // The dialog will by default be modeless, unless you set 'modal' to
38 // TRUE to construct a modal dialog.
39 //=================================================================================
40 GeometryGUI_SewingDlg::GeometryGUI_SewingDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
41 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SEWING")));
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
47 setName( "GeometryGUI_SewingDlg" );
49 setCaption( tr( "GEOM_SEWING_TITLE" ) );
50 setSizeGripEnabled( TRUE );
51 GeometryGUI_SewingDlgLayout = new QGridLayout( this );
52 GeometryGUI_SewingDlgLayout->setSpacing( 6 );
53 GeometryGUI_SewingDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "GEOM_SEWING" ) );
58 GroupConstructors->setExclusive( TRUE );
59 GroupConstructors->setColumnLayout(0, Qt::Vertical );
60 GroupConstructors->layout()->setSpacing( 0 );
61 GroupConstructors->layout()->setMargin( 0 );
62 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64 GroupConstructorsLayout->setSpacing( 6 );
65 GroupConstructorsLayout->setMargin( 11 );
66 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
67 Constructor1->setText( tr( "" ) );
68 Constructor1->setPixmap( image0 );
69 Constructor1->setChecked( TRUE );
70 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
71 Constructor1->setMinimumSize( QSize( 50, 0 ) );
72 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
73 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 GroupConstructorsLayout->addItem( spacer, 0, 1 );
75 GeometryGUI_SewingDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupButtons = new QGroupBox( this, "GroupButtons" );
79 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
80 GroupButtons->setTitle( tr( "" ) );
81 GroupButtons->setColumnLayout(0, Qt::Vertical );
82 GroupButtons->layout()->setSpacing( 0 );
83 GroupButtons->layout()->setMargin( 0 );
84 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
85 GroupButtonsLayout->setAlignment( Qt::AlignTop );
86 GroupButtonsLayout->setSpacing( 6 );
87 GroupButtonsLayout->setMargin( 11 );
88 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
89 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
90 buttonCancel->setAutoDefault( TRUE );
91 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
92 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
93 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
94 buttonApply->setAutoDefault( TRUE );
95 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
96 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
98 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
99 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
100 buttonOk->setAutoDefault( TRUE );
101 buttonOk->setDefault( TRUE );
102 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
103 GeometryGUI_SewingDlgLayout->addWidget( GroupButtons, 2, 0 );
104 GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
106 GroupC1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupC1->sizePolicy().hasHeightForWidth() ) );
107 GroupC1->setColumnLayout(0, Qt::Vertical );
108 GroupC1->layout()->setSpacing( 0 );
109 GroupC1->layout()->setMargin( 0 );
110 GroupC1Layout = new QGridLayout( GroupC1->layout() );
111 GroupC1Layout->setAlignment( Qt::AlignTop );
112 GroupC1Layout->setSpacing( 6 );
113 GroupC1Layout->setMargin( 11 );
114 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
115 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
116 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
117 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
118 LineEditC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2->sizePolicy().hasHeightForWidth() ) );
119 LineEditC1A2->setMinimumSize( QSize( 40, 0 ) );
120 LineEditC1A2->setMaximumSize( QSize( 32767, 32767 ) );
121 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
122 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
123 SelectButtonC1A1->setText( tr( "" ) );
124 SelectButtonC1A1->setPixmap( image1 );
125 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
126 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
127 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
128 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
129 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
130 TextLabelC1A1->setFrameShadow( QLabel::Plain );
131 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
132 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
133 TextLabelC1A2->setText( tr( "GEOM_PRECISION" ) );
134 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
135 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
136 TextLabelC1A2->setFrameShadow( QLabel::Plain );
137 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
138 GeometryGUI_SewingDlgLayout->addWidget( GroupC1, 1, 0 );
139 /***************************************************************/
141 Init(Sel) ; /* Initialisations */
145 //=================================================================================
146 // function : ~GeometryGUI_SewingDlg()
147 // purpose : Destroys the object and frees any allocated resources
148 //=================================================================================
149 GeometryGUI_SewingDlg::~GeometryGUI_SewingDlg()
151 // no need to delete child widgets, Qt does it all for us
155 //=================================================================================
158 //=================================================================================
159 void GeometryGUI_SewingDlg::Init( SALOME_Selection* Sel )
161 LineEditC1A1->setMaxLength( 10 );
162 QDoubleValidator *Va = new QDoubleValidator( -0.000001, +10000.0, 3, LineEditC1A1 ) ;
163 LineEditC1A1->setValidator( Va ) ;
166 myConstructorId = 0 ;
167 Constructor1->setChecked( TRUE );
168 myEditCurrentArgument = LineEditC1A1 ;
170 this->myOkListShapes = false ;
171 this->myPrecision = 0.00001 ;
172 LineEditC1A2->setText("0.00001") ;
173 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
174 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
176 // TODO previous selection into argument ?
178 /* Filter definitions */
179 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
180 myGeom = GEOM::GEOM_Gen::_narrow(comp);
182 /* signals and slots connections */
183 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
184 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
185 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
186 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
188 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
189 connect( LineEditC1A2, SIGNAL (returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
190 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
191 /* to close dialog if study change */
192 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
194 /* Move widget on the botton right corner of main widget */
196 myGeomGUI->DefineDlgPosition( this, x, y ) ;
198 this->show() ; /* displays Dialog */
204 //=================================================================================
205 // function : ConstructorsClicked()
206 // purpose : Radio button management
207 //=================================================================================
208 void GeometryGUI_SewingDlg::ConstructorsClicked(int constructorId)
213 //=================================================================================
214 // function : ClickOnOk()
216 //=================================================================================
217 void GeometryGUI_SewingDlg::ClickOnOk()
219 this->ClickOnApply() ;
220 this->ClickOnCancel() ;
225 //=================================================================================
226 // function : ClickOnApply()
228 //=================================================================================
229 void GeometryGUI_SewingDlg::ClickOnApply()
231 switch(myConstructorId)
236 myGeomGUI->MakeSewingAndDisplay( myListShapes, myPrecision ) ;
246 //=================================================================================
247 // function : ClickOnCancel()
249 //=================================================================================
250 void GeometryGUI_SewingDlg::ClickOnCancel()
252 myGeomGUI->ResetState() ;
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void GeometryGUI_SewingDlg::SelectionIntoArgument()
264 /* All this for first constructor */
265 // if(myEditCurrentArgument == LineEditC1A1 )
267 myOkListShapes = false;
268 myEditCurrentArgument->setText("") ;
269 QString aString = ""; /* name of selection */
271 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
276 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
277 myEditCurrentArgument->setText(aString) ;
278 myOkListShapes = true ;
285 //=================================================================================
286 // function : SetEditCurrentArgument()
288 //=================================================================================
289 void GeometryGUI_SewingDlg::SetEditCurrentArgument()
291 QPushButton* send = (QPushButton*)sender();
292 switch (myConstructorId)
294 case 0: /* default constructor */
296 if(send == SelectButtonC1A1) {
297 LineEditC1A1->setFocus() ;
298 myEditCurrentArgument = LineEditC1A1;
300 SelectionIntoArgument() ;
309 //=================================================================================
310 // function : LineEditReturnPressed()
312 //=================================================================================
313 void GeometryGUI_SewingDlg::LineEditReturnPressed()
315 this->myPrecision = LineEditC1A2->text().toFloat();
320 //=================================================================================
321 // function : DeactivateActiveDialog()
323 //=================================================================================
324 void GeometryGUI_SewingDlg::DeactivateActiveDialog()
326 if ( GroupConstructors->isEnabled() ) {
327 GroupConstructors->setEnabled(false) ;
328 GroupC1->setEnabled(false) ;
329 GroupButtons->setEnabled(false) ;
335 //=================================================================================
336 // function : ActivateThisDialog()
338 //=================================================================================
339 void GeometryGUI_SewingDlg::ActivateThisDialog()
341 /* Emit a signal to deactivate the active dialog */
342 myGeomGUI->EmitSignalDeactivateDialog() ;
343 GroupConstructors->setEnabled(true) ;
344 GroupC1->setEnabled(true) ;
345 GroupButtons->setEnabled(true) ;
350 //=================================================================================
351 // function : enterEvent()
353 //=================================================================================
354 void GeometryGUI_SewingDlg::enterEvent(QEvent* e)
356 if ( GroupConstructors->isEnabled() )
358 ActivateThisDialog() ;
363 //=================================================================================
364 // function : closeEvent()
366 //=================================================================================
367 void GeometryGUI_SewingDlg::closeEvent( QCloseEvent* e )
369 /* same than click on cancel button */
370 this->ClickOnCancel() ;