2 // File : GeometryGUI_CompoundDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_CompoundDlg.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 <qwhatsthis.h>
30 //=================================================================================
31 // class : GeometryGUI_CompoundDlg()
32 // purpose : Constructs a GeometryGUI_CompoundDlg which is a child of 'parent', with the
33 // name 'name' and widget flags set to 'f'.
34 // The dialog will by default be modeless, unless you set 'modal' to
35 // TRUE to construct a modal dialog.
36 //=================================================================================
37 GeometryGUI_CompoundDlg::GeometryGUI_CompoundDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
38 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
40 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BUILD_COMPOUND")));
41 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
43 setName( "GeometryGUI_CompoundDlg" );
45 setCaption( tr( "GEOM_COMPOUND_TITLE" ) );
46 setSizeGripEnabled( TRUE );
47 GeometryGUI_CompoundDlgLayout = new QGridLayout( this );
48 GeometryGUI_CompoundDlgLayout->setSpacing( 6 );
49 GeometryGUI_CompoundDlgLayout->setMargin( 11 );
51 /***************************************************************/
52 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
53 GroupConstructors->setTitle( tr( "GEOM_COMPOUND" ) );
54 GroupConstructors->setExclusive( TRUE );
55 GroupConstructors->setColumnLayout(0, Qt::Vertical );
56 GroupConstructors->layout()->setSpacing( 0 );
57 GroupConstructors->layout()->setMargin( 0 );
58 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
59 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
60 GroupConstructorsLayout->setSpacing( 6 );
61 GroupConstructorsLayout->setMargin( 11 );
62 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
63 Constructor1->setText( tr( "" ) );
64 Constructor1->setPixmap( image1 );
65 Constructor1->setChecked( TRUE );
66 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
67 Constructor1->setMinimumSize( QSize( 50, 0 ) );
68 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
69 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
70 GroupConstructorsLayout->addItem( spacer, 0, 1 );
71 GeometryGUI_CompoundDlgLayout->addWidget( GroupConstructors, 0, 0 );
73 /***************************************************************/
74 GroupButtons = new QGroupBox( this, "GroupButtons" );
75 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
76 GroupButtons->setTitle( tr( "" ) );
77 GroupButtons->setColumnLayout(0, Qt::Vertical );
78 GroupButtons->layout()->setSpacing( 0 );
79 GroupButtons->layout()->setMargin( 0 );
80 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
81 GroupButtonsLayout->setAlignment( Qt::AlignTop );
82 GroupButtonsLayout->setSpacing( 6 );
83 GroupButtonsLayout->setMargin( 11 );
84 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
85 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
86 buttonCancel->setAutoDefault( TRUE );
87 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
88 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
89 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
90 buttonApply->setAutoDefault( TRUE );
91 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
92 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
93 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
94 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
95 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
96 buttonOk->setAutoDefault( TRUE );
97 buttonOk->setDefault( TRUE );
98 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
99 GeometryGUI_CompoundDlgLayout->addWidget( GroupButtons, 2, 0 );
101 /***************************************************************/
102 GroupC1 = new QGroupBox( this, "GroupC1" );
103 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
104 GroupC1->setMinimumSize( QSize( 0, 0 ) );
105 GroupC1->setFrameShape( QGroupBox::Box );
106 GroupC1->setFrameShadow( QGroupBox::Sunken );
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 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
115 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
116 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
117 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
118 TextLabelC1A1->setFrameShadow( QLabel::Plain );
119 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
120 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
121 SelectButtonC1A1->setText( tr( "" ) );
122 SelectButtonC1A1->setPixmap( image0 );
123 SelectButtonC1A1->setToggleButton( FALSE );
124 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
125 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
126 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
127 GeometryGUI_CompoundDlgLayout->addWidget( GroupC1, 1, 0 );
128 /***************************************************************/
130 Init(Sel) ; /* Initialisations */
134 //=================================================================================
135 // function : ~GeometryGUI_CompoundDlg()
136 // purpose : Destroys the object and frees any allocated resources
137 //=================================================================================
138 GeometryGUI_CompoundDlg::~GeometryGUI_CompoundDlg()
140 // no need to delete child widgets, Qt does it all for us
144 //=================================================================================
147 //=================================================================================
148 void GeometryGUI_CompoundDlg::Init( SALOME_Selection* Sel )
152 myConstructorId = 0 ;
153 Constructor1->setChecked( TRUE );
154 myEditCurrentArgument = LineEditC1A1 ;
156 this->myOkListShapes = false ;
157 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
158 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
160 // TODO : previous selection into argument ?
162 /* Filter definitions */
163 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
164 myGeom = GEOM::GEOM_Gen::_narrow(comp);
166 /* signals and slots connections */
167 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
168 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
169 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
170 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
172 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
173 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
174 /* to close dialog if study change */
175 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
177 /* Move widget on the botton right corner of main widget */
179 myGeomGUI->DefineDlgPosition( this, x, y ) ;
181 this->show() ; /* displays Dialog */
187 //=================================================================================
188 // function : ConstructorsClicked()
189 // purpose : Radio button management
190 //=================================================================================
191 void GeometryGUI_CompoundDlg::ConstructorsClicked(int constructorId)
196 //=================================================================================
197 // function : ClickOnOk()
199 //=================================================================================
200 void GeometryGUI_CompoundDlg::ClickOnOk()
202 this->ClickOnApply() ;
203 this->ClickOnCancel() ;
208 //=================================================================================
209 // function : ClickOnApply()
211 //=================================================================================
212 void GeometryGUI_CompoundDlg::ClickOnApply()
214 switch(myConstructorId)
219 myGeomGUI->MakeCompoundAndDisplay( myListShapes ) ;
229 //=================================================================================
230 // function : ClickOnCancel()
232 //=================================================================================
233 void GeometryGUI_CompoundDlg::ClickOnCancel()
235 disconnect( mySelection, 0, this, 0 );
236 myGeomGUI->ResetState() ;
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose : Called when selection as changed or other case
245 //=================================================================================
246 void GeometryGUI_CompoundDlg::SelectionIntoArgument()
248 /* All this for first constructor */
249 // if(myEditCurrentArgument == LineEditC1A1 )
251 myOkListShapes = false;
252 myEditCurrentArgument->setText("") ;
253 QString aString = ""; /* name of selection */
255 int nbSel = mySelection->IObjectCount() ;
258 aString = tr( "%1_objects" ).arg( nbSel );
260 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
261 myEditCurrentArgument->setText(aString) ;
262 myOkListShapes = true ;
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void GeometryGUI_CompoundDlg::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_CompoundDlg::LineEditReturnPressed()
301 //=================================================================================
302 // function : DeactivateActiveDialog()
304 //=================================================================================
305 void GeometryGUI_CompoundDlg::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_CompoundDlg::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_CompoundDlg::enterEvent(QEvent* e)
339 if ( GroupConstructors->isEnabled() )
341 ActivateThisDialog() ;
346 //=================================================================================
347 // function : closeEvent()
349 //=================================================================================
350 void GeometryGUI_CompoundDlg::closeEvent( QCloseEvent* e )
352 /* same than click on cancel button */
353 this->ClickOnCancel() ;