1 // VISU VISUGUI : GUI of VISU 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 : VisuGUI_InitMeshDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "VisuGUI_InitMeshDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
52 //=================================================================================
53 // class : VisuGUI_InitMeshDlg()
54 // purpose : Constructs a VisuGUI_InitMeshDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 VisuGUI_InitMeshDlg::VisuGUI_InitMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel = 0, bool modal, WFlags fl )
60 : QDialog( parent, name, modal, fl )
62 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "VISU",tr("ICON_DLG_INIT_MESH")));
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "VISU",tr("ICON_SELECT")));
65 setName( "VisuGUI_InitMeshDlg" );
67 setCaption( tr( "Visu_INIT_MESH" ) );
68 VisuGUI_InitMeshDlgLayout = new QGridLayout( this );
69 VisuGUI_InitMeshDlgLayout->setSpacing( 6 );
70 VisuGUI_InitMeshDlgLayout->setMargin( 11 );
72 /***************************************************************/
73 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
74 GroupConstructors->setTitle( tr( "Visu_INIT" ) );
75 GroupConstructors->setExclusive( TRUE );
76 GroupConstructors->setColumnLayout(0, Qt::Vertical );
77 GroupConstructors->layout()->setSpacing( 0 );
78 GroupConstructors->layout()->setMargin( 0 );
79 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
80 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
81 GroupConstructorsLayout->setSpacing( 6 );
82 GroupConstructorsLayout->setMargin( 11 );
83 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
84 Constructor1->setText( tr( "" ) );
85 Constructor1->setPixmap( image1 );
86 Constructor1->setChecked( TRUE );
87 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
88 Constructor1->setMinimumSize( QSize( 50, 0 ) );
89 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
90 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
91 GroupConstructorsLayout->addItem( spacer, 0, 1 );
92 VisuGUI_InitMeshDlgLayout->addWidget( GroupConstructors, 0, 0 );
94 /***************************************************************/
95 GroupButtons = new QGroupBox( this, "GroupButtons" );
96 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
97 GroupButtons->setTitle( tr( "" ) );
98 GroupButtons->setColumnLayout(0, Qt::Vertical );
99 GroupButtons->layout()->setSpacing( 0 );
100 GroupButtons->layout()->setMargin( 0 );
101 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
102 GroupButtonsLayout->setAlignment( Qt::AlignTop );
103 GroupButtonsLayout->setSpacing( 6 );
104 GroupButtonsLayout->setMargin( 11 );
105 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
106 buttonCancel->setText( tr( "Visu_BUT_CLOSE" ) );
107 buttonCancel->setAutoDefault( TRUE );
108 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
109 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
110 buttonApply->setText( tr( "Visu_BUT_APPLY" ) );
111 buttonApply->setAutoDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
113 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
114 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
115 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
116 buttonOk->setText( tr( "Visu_BUT_OK" ) );
117 buttonOk->setAutoDefault( TRUE );
118 buttonOk->setDefault( TRUE );
119 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
120 VisuGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
122 /***************************************************************/
123 GroupC1 = new QGroupBox( this, "GroupC1" );
124 GroupC1->setTitle( tr( "Visu_ARGUMENTS" ) );
125 GroupC1->setMinimumSize( QSize( 0, 0 ) );
126 GroupC1->setFrameShape( QGroupBox::Box );
127 GroupC1->setFrameShadow( QGroupBox::Sunken );
128 GroupC1->setColumnLayout(0, Qt::Vertical );
129 GroupC1->layout()->setSpacing( 0 );
130 GroupC1->layout()->setMargin( 0 );
131 GroupC1Layout = new QGridLayout( GroupC1->layout() );
132 GroupC1Layout->setAlignment( Qt::AlignTop );
133 GroupC1Layout->setSpacing( 6 );
134 GroupC1Layout->setMargin( 11 );
136 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
137 TextLabelC1A1->setText( tr( "Visu_OBJECT_GEOM" ) );
138 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
139 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
140 TextLabelC1A1->setFrameShadow( QLabel::Plain );
141 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
142 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
143 SelectButtonC1A1->setText( tr( "" ) );
144 SelectButtonC1A1->setPixmap( image0 );
145 SelectButtonC1A1->setToggleButton( FALSE );
146 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
147 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
148 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
150 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
151 TextLabel_NameMesh->setText( tr( "Visu_NAME" ) );
152 GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
153 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
154 GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
156 VisuGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
157 /***************************************************************/
163 //=================================================================================
164 // function : ~VisuGUI_InitMeshDlg()
165 // purpose : Destroys the object and frees any allocated resources
166 //=================================================================================
167 VisuGUI_InitMeshDlg::~VisuGUI_InitMeshDlg()
169 // no need to delete child widgets, Qt does it all for us
173 //=================================================================================
176 //=================================================================================
177 void VisuGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
180 myConstructorId = 0 ;
181 Constructor1->setChecked( TRUE );
182 myEditCurrentArgument = LineEditC1A1 ;
184 myVisuGUI = VisuGUI::GetVisuGUI() ;
185 myVisuGUI->SetActiveDialogBox( (QDialog*)this ) ;
187 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
188 mySelection->AddFilter( myGeomFilter );
192 /* signals and slots connections */
193 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( ClickOnOk() ) );
194 connect( buttonApply, SIGNAL( pressed() ), this, SLOT(ClickOnApply() ) );
195 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( ClickOnCancel() ) ) ;
196 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
198 connect( SelectButtonC1A1, SIGNAL (pressed() ), this, SLOT( SetEditCurrentArgument() ) ) ;
199 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
201 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
202 connect( myVisuGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
203 connect( myVisuGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
206 // myVisuGUI->DefineDlgPosition( this, x, y ) ;
207 // this->move( x, y ) ;
214 //=================================================================================
215 // function : ConstructorsClicked()
216 // purpose : Radio button management
217 //=================================================================================
218 void VisuGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
223 //=================================================================================
224 // function : ClickOnOk()
226 //=================================================================================
227 void VisuGUI_InitMeshDlg::ClickOnOk()
229 this->ClickOnApply() ;
230 this->ClickOnCancel() ;
235 //=================================================================================
236 // function : ClickOnApply()
238 //=================================================================================
239 void VisuGUI_InitMeshDlg::ClickOnApply()
241 switch(myConstructorId)
245 if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
246 myVisuGUI->InitMesh( mySMeshMesh, myNameMesh ) ;
253 //=================================================================================
254 // function : ClickOnCancel()
256 //=================================================================================
257 void VisuGUI_InitMeshDlg::ClickOnCancel()
259 mySelection->ClearFilters() ;
260 disconnect( mySelection, 0, this, 0 );
261 myVisuGUI->ResetState() ;
267 //=================================================================================
268 // function : SelectionIntoArgument()
269 // purpose : Called when selection as changed or other case
270 //=================================================================================
271 void VisuGUI_InitMeshDlg::SelectionIntoArgument()
273 myEditCurrentArgument->setText("") ;
274 QString aString = "";
275 myGeomShape = GEOM::GEOM_Shape::_nil();
277 int nbSel = myVisuGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
281 Standard_Boolean testResult ;
282 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
283 myGeomShape = myVisuGUI->ConvertIOinGEOMShape(IO, testResult) ;
284 if( !testResult ) return ;
287 myEditCurrentArgument->setText(aString) ;
291 //=================================================================================
292 // function : SetEditCurrentArgument()
294 //=================================================================================
295 void VisuGUI_InitMeshDlg::SetEditCurrentArgument()
297 QPushButton* send = (QPushButton*)sender();
298 switch (myConstructorId)
300 case 0: /* default constructor */
302 if(send == SelectButtonC1A1) {
303 LineEditC1A1->setFocus() ;
304 myEditCurrentArgument = LineEditC1A1;
306 SelectionIntoArgument() ;
313 //=================================================================================
314 // function : DeactivateActiveDialog()
316 //=================================================================================
317 void VisuGUI_InitMeshDlg::DeactivateActiveDialog()
319 if ( GroupConstructors->isEnabled() ) {
320 disconnect( mySelection, 0, this, 0 );
321 GroupConstructors->setEnabled(false) ;
322 GroupC1->setEnabled(false) ;
323 GroupButtons->setEnabled(false) ;
328 //=================================================================================
329 // function : ActivateThisDialog()
331 //=================================================================================
332 void VisuGUI_InitMeshDlg::ActivateThisDialog()
334 myVisuGUI->EmitSignalDeactivateDialog() ;
335 GroupConstructors->setEnabled(true) ;
336 GroupC1->setEnabled(true) ;
337 GroupButtons->setEnabled(true) ;
338 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
343 //=================================================================================
344 // function : enterEvent()
346 //=================================================================================
347 void VisuGUI_InitMeshDlg::enterEvent(QEvent* e)
349 if ( GroupConstructors->isEnabled() )
351 ActivateThisDialog() ;
356 //=================================================================================
357 // function : closeEvent()
359 //=================================================================================
360 void VisuGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
362 this->ClickOnCancel() ;
366 //=================================================================================
367 // function : TextChangedInLineEdit()
369 //=================================================================================
370 void VisuGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
372 QLineEdit* send = (QLineEdit*)sender();
373 QString newT = strdup(newText) ;
375 if (send == LineEdit_NameMesh) {
376 myNameMesh = newText;