2 // File : GeometryGUI_ShellDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
11 #include "GeometryGUI_ShellDlg.h"
13 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 #include <qbuttongroup.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
31 //=================================================================================
32 // class : GeometryGUI_ShellDlg()
33 // purpose : Constructs a GeometryGUI_ShellDlg which is a child of 'parent', with the
34 // name 'name' and widget flags set to 'f'.
35 // The dialog will by default be modeless, unless you set 'modal' to
36 // TRUE to construct a modal dialog.
37 //=================================================================================
38 GeometryGUI_ShellDlg::GeometryGUI_ShellDlg( QWidget* parent, const char* name, SALOME_Selection* Sel = 0, bool modal, WFlags fl )
39 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SHELL")));
42 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
44 setName( "GeometryGUI_ShellDlg" );
46 setCaption( tr( "GEOM_SHELL_TITLE" ) );
47 setSizeGripEnabled( TRUE );
48 GeometryGUI_ShellDlgLayout = new QGridLayout( this );
49 GeometryGUI_ShellDlgLayout->setSpacing( 6 );
50 GeometryGUI_ShellDlgLayout->setMargin( 11 );
52 /***************************************************************/
53 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
54 GroupConstructors->setTitle( tr( "GEOM_SHELL" ) );
55 GroupConstructors->setExclusive( TRUE );
56 GroupConstructors->setColumnLayout(0, Qt::Vertical );
57 GroupConstructors->layout()->setSpacing( 0 );
58 GroupConstructors->layout()->setMargin( 0 );
59 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
60 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
61 GroupConstructorsLayout->setSpacing( 6 );
62 GroupConstructorsLayout->setMargin( 11 );
63 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
64 GroupConstructorsLayout->addItem( spacer, 0, 1 );
65 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
66 Constructor1->setText( tr( "" ) );
67 Constructor1->setPixmap( image0 );
68 Constructor1->setChecked( TRUE );
69 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
70 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
71 GeometryGUI_ShellDlgLayout->addWidget( GroupConstructors, 0, 0 );
73 /***************************************************************/
74 GroupC1 = new QGroupBox( this, "GroupC1" );
75 GroupC1->setTitle( tr( "GEOM_SHELL_LIST" ) );
76 GroupC1->setColumnLayout(0, Qt::Vertical );
77 GroupC1->layout()->setSpacing( 0 );
78 GroupC1->layout()->setMargin( 0 );
79 GroupC1Layout = new QGridLayout( GroupC1->layout() );
80 GroupC1Layout->setAlignment( Qt::AlignTop );
81 GroupC1Layout->setSpacing( 6 );
82 GroupC1Layout->setMargin( 11 );
83 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
84 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
85 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
86 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
87 SelectButtonC1A1->setText( tr( "" ) );
88 SelectButtonC1A1->setPixmap( image1 );
89 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
90 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
91 TextLabelC1A1->setText( tr( "GEOM_FACES" ) );
92 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
93 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
94 TextLabelC1A1->setFrameShadow( QLabel::Plain );
95 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
96 GeometryGUI_ShellDlgLayout->addWidget( GroupC1, 1, 0 );
98 /***************************************************************/
99 GroupButtons = new QGroupBox( this, "GroupButtons" );
100 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
101 GroupButtons->setTitle( tr( "" ) );
102 GroupButtons->setColumnLayout(0, Qt::Vertical );
103 GroupButtons->layout()->setSpacing( 0 );
104 GroupButtons->layout()->setMargin( 0 );
105 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106 GroupButtonsLayout->setAlignment( Qt::AlignTop );
107 GroupButtonsLayout->setSpacing( 6 );
108 GroupButtonsLayout->setMargin( 11 );
109 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
110 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
111 buttonCancel->setAutoDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
113 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
114 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
115 buttonApply->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
119 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
121 buttonOk->setAutoDefault( TRUE );
122 buttonOk->setDefault( TRUE );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124 GeometryGUI_ShellDlgLayout->addWidget( GroupButtons, 2, 0 );
125 /***************************************************************/
127 Init(Sel) ; /* Initialisations */
131 //=================================================================================
132 // function : ~GeometryGUI_ShellDlg()
133 // purpose : Destroys the object and frees any allocated resources
134 //=================================================================================
135 GeometryGUI_ShellDlg::~GeometryGUI_ShellDlg()
137 // no need to delete child widgets, Qt does it all for us
142 //=================================================================================
145 //=================================================================================
146 void GeometryGUI_ShellDlg::Init( SALOME_Selection* Sel )
150 myConstructorId = 0 ;
151 Constructor1->setChecked( TRUE );
152 myEditCurrentArgument = LineEditC1A1 ;
154 this->myOkListShapes = false ;
155 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
156 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
158 // TODO : previous selection into argument ?
160 /* Filter definitions */
161 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
162 myGeom = GEOM::GEOM_Gen::_narrow(comp);
164 /* signals and slots connections */
165 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
166 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
167 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
168 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
170 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
171 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
172 /* to close dialog if study change */
173 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
175 /* Move widget on the botton right corner of main widget */
177 myGeomGUI->DefineDlgPosition( this, x, y ) ;
179 this->show() ; /* displays Dialog */
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void GeometryGUI_ShellDlg::ConstructorsClicked(int constructorId)
194 //=================================================================================
195 // function : ClickOnOk()
197 //=================================================================================
198 void GeometryGUI_ShellDlg::ClickOnOk()
200 this->ClickOnApply() ;
201 this->ClickOnCancel() ;
207 //=================================================================================
208 // function : ClickOnApply()
210 //=================================================================================
211 void GeometryGUI_ShellDlg::ClickOnApply()
213 switch(myConstructorId)
218 // myGeomGUI->MakeShellAndDisplay( myListShapes ) ;
228 //=================================================================================
229 // function : ClickOnCancel()
231 //=================================================================================
232 void GeometryGUI_ShellDlg::ClickOnCancel()
234 disconnect( mySelection, 0, this, 0 );
235 myGeomGUI->ResetState() ;
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection as changed or other case
244 //=================================================================================
245 void GeometryGUI_ShellDlg::SelectionIntoArgument()
247 /* All this for first constructor */
248 // if(myEditCurrentArgument == LineEditC1A1 )
249 myEditCurrentArgument->setText("") ;
250 myOkListShapes = false;
252 QString aString = ""; /* name of future selection */
254 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
258 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
260 myEditCurrentArgument->setText(aString) ;
261 myOkListShapes = true ;
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void GeometryGUI_ShellDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
274 switch (myConstructorId)
276 case 0: /* default constructor */
278 if(send == SelectButtonC1A1) {
279 LineEditC1A1->setFocus() ;
280 myEditCurrentArgument = LineEditC1A1;
282 SelectionIntoArgument() ;
291 //=================================================================================
292 // function : LineEditReturnPressed()
294 //=================================================================================
295 void GeometryGUI_ShellDlg::LineEditReturnPressed()
301 //=================================================================================
302 // function : DeactivateActiveDialog()
304 //=================================================================================
305 void GeometryGUI_ShellDlg::DeactivateActiveDialog()
307 if ( GroupConstructors->isEnabled() ) {
308 disconnect( mySelection, 0, this, 0 );
309 GroupConstructors->setEnabled(false) ;
310 GroupC1->setEnabled(false) ;
311 GroupButtons->setEnabled(false) ;
317 //=================================================================================
318 // function : ActivateThisDialog()
320 //=================================================================================
321 void GeometryGUI_ShellDlg::ActivateThisDialog()
323 /* Emit a signal to deactivate the active dialog */
324 myGeomGUI->EmitSignalDeactivateDialog() ;
325 GroupConstructors->setEnabled(true) ;
326 GroupC1->setEnabled(true) ;
327 GroupButtons->setEnabled(true) ;
328 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
333 //=================================================================================
334 // function : enterEvent()
336 //=================================================================================
337 void GeometryGUI_ShellDlg::enterEvent(QEvent* e)
339 if ( GroupConstructors->isEnabled() )
341 ActivateThisDialog() ;
346 //=================================================================================
347 // function : closeEvent()
349 //=================================================================================
350 void GeometryGUI_ShellDlg::closeEvent( QCloseEvent* e )
352 /* same than click on cancel button */
353 this->ClickOnCancel() ;