2 // File : VisuGUI_InitMeshDlg.cxx
3 // Created : Mon May 27 10:20:11 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "VisuGUI_InitMeshDlg.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
28 #include <qwhatsthis.h>
33 //=================================================================================
34 // class : VisuGUI_InitMeshDlg()
35 // purpose : Constructs a VisuGUI_InitMeshDlg 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 VisuGUI_InitMeshDlg::VisuGUI_InitMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel = 0, bool modal, WFlags fl )
41 : QDialog( parent, name, modal, fl )
43 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "VISU",tr("ICON_DLG_INIT_MESH")));
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "VISU",tr("ICON_SELECT")));
46 setName( "VisuGUI_InitMeshDlg" );
48 setCaption( tr( "Visu_INIT_MESH" ) );
49 VisuGUI_InitMeshDlgLayout = new QGridLayout( this );
50 VisuGUI_InitMeshDlgLayout->setSpacing( 6 );
51 VisuGUI_InitMeshDlgLayout->setMargin( 11 );
53 /***************************************************************/
54 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
55 GroupConstructors->setTitle( tr( "Visu_INIT" ) );
56 GroupConstructors->setExclusive( TRUE );
57 GroupConstructors->setColumnLayout(0, Qt::Vertical );
58 GroupConstructors->layout()->setSpacing( 0 );
59 GroupConstructors->layout()->setMargin( 0 );
60 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
61 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
62 GroupConstructorsLayout->setSpacing( 6 );
63 GroupConstructorsLayout->setMargin( 11 );
64 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
65 Constructor1->setText( tr( "" ) );
66 Constructor1->setPixmap( image1 );
67 Constructor1->setChecked( TRUE );
68 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
69 Constructor1->setMinimumSize( QSize( 50, 0 ) );
70 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
71 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72 GroupConstructorsLayout->addItem( spacer, 0, 1 );
73 VisuGUI_InitMeshDlgLayout->addWidget( GroupConstructors, 0, 0 );
75 /***************************************************************/
76 GroupButtons = new QGroupBox( this, "GroupButtons" );
77 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
78 GroupButtons->setTitle( tr( "" ) );
79 GroupButtons->setColumnLayout(0, Qt::Vertical );
80 GroupButtons->layout()->setSpacing( 0 );
81 GroupButtons->layout()->setMargin( 0 );
82 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
83 GroupButtonsLayout->setAlignment( Qt::AlignTop );
84 GroupButtonsLayout->setSpacing( 6 );
85 GroupButtonsLayout->setMargin( 11 );
86 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
87 buttonCancel->setText( tr( "Visu_BUT_CLOSE" ) );
88 buttonCancel->setAutoDefault( TRUE );
89 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
90 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
91 buttonApply->setText( tr( "Visu_BUT_APPLY" ) );
92 buttonApply->setAutoDefault( TRUE );
93 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
94 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
96 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
97 buttonOk->setText( tr( "Visu_BUT_OK" ) );
98 buttonOk->setAutoDefault( TRUE );
99 buttonOk->setDefault( TRUE );
100 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
101 VisuGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
103 /***************************************************************/
104 GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setTitle( tr( "Visu_ARGUMENTS" ) );
106 GroupC1->setMinimumSize( QSize( 0, 0 ) );
107 GroupC1->setFrameShape( QGroupBox::Box );
108 GroupC1->setFrameShadow( QGroupBox::Sunken );
109 GroupC1->setColumnLayout(0, Qt::Vertical );
110 GroupC1->layout()->setSpacing( 0 );
111 GroupC1->layout()->setMargin( 0 );
112 GroupC1Layout = new QGridLayout( GroupC1->layout() );
113 GroupC1Layout->setAlignment( Qt::AlignTop );
114 GroupC1Layout->setSpacing( 6 );
115 GroupC1Layout->setMargin( 11 );
117 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
118 TextLabelC1A1->setText( tr( "Visu_OBJECT_GEOM" ) );
119 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121 TextLabelC1A1->setFrameShadow( QLabel::Plain );
122 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
123 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124 SelectButtonC1A1->setText( tr( "" ) );
125 SelectButtonC1A1->setPixmap( image0 );
126 SelectButtonC1A1->setToggleButton( FALSE );
127 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
128 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
131 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
132 TextLabel_NameMesh->setText( tr( "Visu_NAME" ) );
133 GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
134 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
135 GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
137 VisuGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
138 /***************************************************************/
144 //=================================================================================
145 // function : ~VisuGUI_InitMeshDlg()
146 // purpose : Destroys the object and frees any allocated resources
147 //=================================================================================
148 VisuGUI_InitMeshDlg::~VisuGUI_InitMeshDlg()
150 // no need to delete child widgets, Qt does it all for us
154 //=================================================================================
157 //=================================================================================
158 void VisuGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
161 myConstructorId = 0 ;
162 Constructor1->setChecked( TRUE );
163 myEditCurrentArgument = LineEditC1A1 ;
165 myVisuGUI = VisuGUI::GetVisuGUI() ;
166 myVisuGUI->SetActiveDialogBox( (QDialog*)this ) ;
168 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
169 mySelection->AddFilter( myGeomFilter );
173 /* signals and slots connections */
174 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( ClickOnOk() ) );
175 connect( buttonApply, SIGNAL( pressed() ), this, SLOT(ClickOnApply() ) );
176 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( ClickOnCancel() ) ) ;
177 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
179 connect( SelectButtonC1A1, SIGNAL (pressed() ), this, SLOT( SetEditCurrentArgument() ) ) ;
180 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
182 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
183 connect( myVisuGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
184 connect( myVisuGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
187 // myVisuGUI->DefineDlgPosition( this, x, y ) ;
188 // this->move( x, y ) ;
195 //=================================================================================
196 // function : ConstructorsClicked()
197 // purpose : Radio button management
198 //=================================================================================
199 void VisuGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
204 //=================================================================================
205 // function : ClickOnOk()
207 //=================================================================================
208 void VisuGUI_InitMeshDlg::ClickOnOk()
210 this->ClickOnApply() ;
211 this->ClickOnCancel() ;
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 void VisuGUI_InitMeshDlg::ClickOnApply()
222 switch(myConstructorId)
226 if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
227 myVisuGUI->InitMesh( mySMeshMesh, myNameMesh ) ;
234 //=================================================================================
235 // function : ClickOnCancel()
237 //=================================================================================
238 void VisuGUI_InitMeshDlg::ClickOnCancel()
240 mySelection->ClearFilters() ;
241 disconnect( mySelection, 0, this, 0 );
242 myVisuGUI->ResetState() ;
248 //=================================================================================
249 // function : SelectionIntoArgument()
250 // purpose : Called when selection as changed or other case
251 //=================================================================================
252 void VisuGUI_InitMeshDlg::SelectionIntoArgument()
254 myEditCurrentArgument->setText("") ;
255 QString aString = "";
256 myGeomShape = GEOM::GEOM_Shape::_nil();
258 int nbSel = myVisuGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
262 Standard_Boolean testResult ;
263 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
264 myGeomShape = myVisuGUI->ConvertIOinGEOMShape(IO, testResult) ;
265 if( !testResult ) return ;
268 myEditCurrentArgument->setText(aString) ;
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void VisuGUI_InitMeshDlg::SetEditCurrentArgument()
278 QPushButton* send = (QPushButton*)sender();
279 switch (myConstructorId)
281 case 0: /* default constructor */
283 if(send == SelectButtonC1A1) {
284 LineEditC1A1->setFocus() ;
285 myEditCurrentArgument = LineEditC1A1;
287 SelectionIntoArgument() ;
294 //=================================================================================
295 // function : DeactivateActiveDialog()
297 //=================================================================================
298 void VisuGUI_InitMeshDlg::DeactivateActiveDialog()
300 if ( GroupConstructors->isEnabled() ) {
301 disconnect( mySelection, 0, this, 0 );
302 GroupConstructors->setEnabled(false) ;
303 GroupC1->setEnabled(false) ;
304 GroupButtons->setEnabled(false) ;
309 //=================================================================================
310 // function : ActivateThisDialog()
312 //=================================================================================
313 void VisuGUI_InitMeshDlg::ActivateThisDialog()
315 myVisuGUI->EmitSignalDeactivateDialog() ;
316 GroupConstructors->setEnabled(true) ;
317 GroupC1->setEnabled(true) ;
318 GroupButtons->setEnabled(true) ;
319 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
324 //=================================================================================
325 // function : enterEvent()
327 //=================================================================================
328 void VisuGUI_InitMeshDlg::enterEvent(QEvent* e)
330 if ( GroupConstructors->isEnabled() )
332 ActivateThisDialog() ;
337 //=================================================================================
338 // function : closeEvent()
340 //=================================================================================
341 void VisuGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
343 this->ClickOnCancel() ;
347 //=================================================================================
348 // function : TextChangedInLineEdit()
350 //=================================================================================
351 void VisuGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
353 QLineEdit* send = (QLineEdit*)sender();
354 QString newT = strdup(newText) ;
356 if (send == LineEdit_NameMesh) {
357 myNameMesh = newText;