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_ShellDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_ShellDlg.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 <qwhatsthis.h>
50 //=================================================================================
51 // class : GeometryGUI_ShellDlg()
52 // purpose : Constructs a GeometryGUI_ShellDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 GeometryGUI_ShellDlg::GeometryGUI_ShellDlg( QWidget* parent, const char* name, SALOME_Selection* Sel = 0, bool modal, WFlags fl )
58 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
60 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SHELL")));
61 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
63 setName( "GeometryGUI_ShellDlg" );
65 setCaption( tr( "GEOM_SHELL_TITLE" ) );
66 setSizeGripEnabled( TRUE );
67 GeometryGUI_ShellDlgLayout = new QGridLayout( this );
68 GeometryGUI_ShellDlgLayout->setSpacing( 6 );
69 GeometryGUI_ShellDlgLayout->setMargin( 11 );
71 /***************************************************************/
72 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
73 GroupConstructors->setTitle( tr( "GEOM_SHELL" ) );
74 GroupConstructors->setExclusive( TRUE );
75 GroupConstructors->setColumnLayout(0, Qt::Vertical );
76 GroupConstructors->layout()->setSpacing( 0 );
77 GroupConstructors->layout()->setMargin( 0 );
78 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
79 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
80 GroupConstructorsLayout->setSpacing( 6 );
81 GroupConstructorsLayout->setMargin( 11 );
82 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
83 GroupConstructorsLayout->addItem( spacer, 0, 1 );
84 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
85 Constructor1->setText( tr( "" ) );
86 Constructor1->setPixmap( image0 );
87 Constructor1->setChecked( TRUE );
88 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
89 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
90 GeometryGUI_ShellDlgLayout->addWidget( GroupConstructors, 0, 0 );
92 /***************************************************************/
93 GroupC1 = new QGroupBox( this, "GroupC1" );
94 GroupC1->setTitle( tr( "GEOM_SHELL_LIST" ) );
95 GroupC1->setColumnLayout(0, Qt::Vertical );
96 GroupC1->layout()->setSpacing( 0 );
97 GroupC1->layout()->setMargin( 0 );
98 GroupC1Layout = new QGridLayout( GroupC1->layout() );
99 GroupC1Layout->setAlignment( Qt::AlignTop );
100 GroupC1Layout->setSpacing( 6 );
101 GroupC1Layout->setMargin( 11 );
102 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
103 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
104 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
105 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
106 SelectButtonC1A1->setText( tr( "" ) );
107 SelectButtonC1A1->setPixmap( image1 );
108 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
109 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
110 TextLabelC1A1->setText( tr( "GEOM_FACES" ) );
111 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
112 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
113 TextLabelC1A1->setFrameShadow( QLabel::Plain );
114 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
115 GeometryGUI_ShellDlgLayout->addWidget( GroupC1, 1, 0 );
117 /***************************************************************/
118 GroupButtons = new QGroupBox( this, "GroupButtons" );
119 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
120 GroupButtons->setTitle( tr( "" ) );
121 GroupButtons->setColumnLayout(0, Qt::Vertical );
122 GroupButtons->layout()->setSpacing( 0 );
123 GroupButtons->layout()->setMargin( 0 );
124 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
125 GroupButtonsLayout->setAlignment( Qt::AlignTop );
126 GroupButtonsLayout->setSpacing( 6 );
127 GroupButtonsLayout->setMargin( 11 );
128 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
129 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
130 buttonCancel->setAutoDefault( TRUE );
131 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
132 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
133 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
134 buttonApply->setAutoDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
136 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
137 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
138 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
139 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
140 buttonOk->setAutoDefault( TRUE );
141 buttonOk->setDefault( TRUE );
142 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
143 GeometryGUI_ShellDlgLayout->addWidget( GroupButtons, 2, 0 );
144 /***************************************************************/
146 Init(Sel) ; /* Initialisations */
150 //=================================================================================
151 // function : ~GeometryGUI_ShellDlg()
152 // purpose : Destroys the object and frees any allocated resources
153 //=================================================================================
154 GeometryGUI_ShellDlg::~GeometryGUI_ShellDlg()
156 // no need to delete child widgets, Qt does it all for us
161 //=================================================================================
164 //=================================================================================
165 void GeometryGUI_ShellDlg::Init( SALOME_Selection* Sel )
169 myConstructorId = 0 ;
170 Constructor1->setChecked( TRUE );
171 myEditCurrentArgument = LineEditC1A1 ;
173 this->myOkListShapes = false ;
174 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
175 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
177 // TODO : previous selection into argument ?
179 /* Filter definitions */
180 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
181 myGeom = GEOM::GEOM_Gen::_narrow(comp);
183 /* signals and slots connections */
184 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
185 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
186 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
187 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
189 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
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 */
203 //=================================================================================
204 // function : ConstructorsClicked()
205 // purpose : Radio button management
206 //=================================================================================
207 void GeometryGUI_ShellDlg::ConstructorsClicked(int constructorId)
213 //=================================================================================
214 // function : ClickOnOk()
216 //=================================================================================
217 void GeometryGUI_ShellDlg::ClickOnOk()
219 this->ClickOnApply() ;
220 this->ClickOnCancel() ;
226 //=================================================================================
227 // function : ClickOnApply()
229 //=================================================================================
230 void GeometryGUI_ShellDlg::ClickOnApply()
232 switch(myConstructorId)
237 // myGeomGUI->MakeShellAndDisplay( myListShapes ) ;
247 //=================================================================================
248 // function : ClickOnCancel()
250 //=================================================================================
251 void GeometryGUI_ShellDlg::ClickOnCancel()
253 disconnect( mySelection, 0, this, 0 );
254 myGeomGUI->ResetState() ;
260 //=================================================================================
261 // function : SelectionIntoArgument()
262 // purpose : Called when selection as changed or other case
263 //=================================================================================
264 void GeometryGUI_ShellDlg::SelectionIntoArgument()
266 /* All this for first constructor */
267 // if(myEditCurrentArgument == LineEditC1A1 )
268 myEditCurrentArgument->setText("") ;
269 myOkListShapes = false;
271 QString aString = ""; /* name of future selection */
273 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
277 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
279 myEditCurrentArgument->setText(aString) ;
280 myOkListShapes = true ;
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void GeometryGUI_ShellDlg::SetEditCurrentArgument()
292 QPushButton* send = (QPushButton*)sender();
293 switch (myConstructorId)
295 case 0: /* default constructor */
297 if(send == SelectButtonC1A1) {
298 LineEditC1A1->setFocus() ;
299 myEditCurrentArgument = LineEditC1A1;
301 SelectionIntoArgument() ;
310 //=================================================================================
311 // function : LineEditReturnPressed()
313 //=================================================================================
314 void GeometryGUI_ShellDlg::LineEditReturnPressed()
320 //=================================================================================
321 // function : DeactivateActiveDialog()
323 //=================================================================================
324 void GeometryGUI_ShellDlg::DeactivateActiveDialog()
326 if ( GroupConstructors->isEnabled() ) {
327 disconnect( mySelection, 0, this, 0 );
328 GroupConstructors->setEnabled(false) ;
329 GroupC1->setEnabled(false) ;
330 GroupButtons->setEnabled(false) ;
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void GeometryGUI_ShellDlg::ActivateThisDialog()
342 /* Emit a signal to deactivate the active dialog */
343 myGeomGUI->EmitSignalDeactivateDialog() ;
344 GroupConstructors->setEnabled(true) ;
345 GroupC1->setEnabled(true) ;
346 GroupButtons->setEnabled(true) ;
347 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
352 //=================================================================================
353 // function : enterEvent()
355 //=================================================================================
356 void GeometryGUI_ShellDlg::enterEvent(QEvent* e)
358 if ( GroupConstructors->isEnabled() )
360 ActivateThisDialog() ;
365 //=================================================================================
366 // function : closeEvent()
368 //=================================================================================
369 void GeometryGUI_ShellDlg::closeEvent( QCloseEvent* e )
371 /* same than click on cancel button */
372 this->ClickOnCancel() ;