1 z// 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 "SUIT_Application.h"
34 #include "SUIT_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->setColumnLayout(0, Qt::Vertical);
98 GroupButtons->layout()->setSpacing(0);
99 GroupButtons->layout()->setMargin(0);
100 GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
101 GroupButtonsLayout->setAlignment(Qt::AlignTop);
102 GroupButtonsLayout->setSpacing(6);
103 GroupButtonsLayout->setMargin(11);
105 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
106 buttonCancel->setText(tr("BUT_CLOSE"));
107 buttonCancel->setAutoDefault(TRUE);
108 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
110 buttonApply = new QPushButton (GroupButtons, "buttonApply");
111 buttonApply->setText(tr("BUT_APPLY"));
112 buttonApply->setAutoDefault(TRUE);
113 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
115 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
116 GroupButtonsLayout->addItem(spacer_9, 0, 2);
118 buttonOk = new QPushButton(GroupButtons, "buttonOk");
119 buttonOk->setText(tr("BUT_OK"));
120 buttonOk->setAutoDefault(TRUE);
121 buttonOk->setDefault(TRUE);
122 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
124 VisuGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
126 /***************************************************************/
127 GroupC1 = new QGroupBox( this, "GroupC1" );
128 GroupC1->setTitle( tr( "Visu_ARGUMENTS" ) );
129 GroupC1->setMinimumSize( QSize( 0, 0 ) );
130 GroupC1->setFrameShape( QGroupBox::Box );
131 GroupC1->setFrameShadow( QGroupBox::Sunken );
132 GroupC1->setColumnLayout(0, Qt::Vertical );
133 GroupC1->layout()->setSpacing( 0 );
134 GroupC1->layout()->setMargin( 0 );
135 GroupC1Layout = new QGridLayout( GroupC1->layout() );
136 GroupC1Layout->setAlignment( Qt::AlignTop );
137 GroupC1Layout->setSpacing( 6 );
138 GroupC1Layout->setMargin( 11 );
140 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
141 TextLabelC1A1->setText( tr( "Visu_OBJECT_GEOM" ) );
142 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
143 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
144 TextLabelC1A1->setFrameShadow( QLabel::Plain );
145 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
146 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
147 //SelectButtonC1A1->setText( tr( "" ) );
148 SelectButtonC1A1->setPixmap( image0 );
149 SelectButtonC1A1->setToggleButton( FALSE );
150 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
151 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
152 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
154 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
155 TextLabel_NameMesh->setText( tr( "Visu_NAME" ) );
156 GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
157 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
158 GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
160 VisuGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
161 /***************************************************************/
166 //=================================================================================
167 // function : ~VisuGUI_InitMeshDlg()
168 // purpose : Destroys the object and frees any allocated resources
169 //=================================================================================
170 VisuGUI_InitMeshDlg::~VisuGUI_InitMeshDlg()
172 // no need to delete child widgets, Qt does it all for us
176 //=================================================================================
179 //=================================================================================
180 void VisuGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
183 myConstructorId = 0 ;
184 Constructor1->setChecked( TRUE );
185 myEditCurrentArgument = LineEditC1A1 ;
187 myVisuGUI = VisuGUI::GetVisuGUI() ;
188 myVisuGUI->SetActiveDialogBox( (QDialog*)this ) ;
190 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
191 mySelection->AddFilter( myGeomFilter );
195 /* signals and slots connections */
196 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( ClickOnOk() ) );
197 connect( buttonApply, SIGNAL( pressed() ), this, SLOT(ClickOnApply() ) );
198 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( ClickOnCancel() ) ) ;
199 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
201 connect( SelectButtonC1A1, SIGNAL (pressed() ), this, SLOT( SetEditCurrentArgument() ) ) ;
202 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
204 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
205 connect( myVisuGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
206 connect( myVisuGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
209 // myVisuGUI->DefineDlgPosition( this, x, y ) ;
210 // this->move( x, y ) ;
217 //=================================================================================
218 // function : ConstructorsClicked()
219 // purpose : Radio button management
220 //=================================================================================
221 void VisuGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
226 //=================================================================================
227 // function : ClickOnOk()
229 //=================================================================================
230 void VisuGUI_InitMeshDlg::ClickOnOk()
232 this->ClickOnApply() ;
233 this->ClickOnCancel() ;
238 //=================================================================================
239 // function : ClickOnApply()
241 //=================================================================================
242 void VisuGUI_InitMeshDlg::ClickOnApply()
244 switch(myConstructorId)
248 if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
249 myVisuGUI->InitMesh( mySMeshMesh, myNameMesh ) ;
256 //=================================================================================
257 // function : ClickOnCancel()
259 //=================================================================================
260 void VisuGUI_InitMeshDlg::ClickOnCancel()
262 mySelection->ClearFilters() ;
263 disconnect( mySelection, 0, this, 0 );
264 myVisuGUI->ResetState() ;
270 //=================================================================================
271 // function : SelectionIntoArgument()
272 // purpose : Called when selection as changed or other case
273 //=================================================================================
274 void VisuGUI_InitMeshDlg::SelectionIntoArgument()
276 myEditCurrentArgument->setText("") ;
277 QString aString = "";
278 myGeomShape = GEOM::GEOM_Shape::_nil();
280 int nbSel = myVisuGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
284 Standard_Boolean testResult ;
285 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
286 myGeomShape = myVisuGUI->ConvertIOinGEOMShape(IO, testResult) ;
287 if( !testResult ) return ;
290 myEditCurrentArgument->setText(aString) ;
294 //=================================================================================
295 // function : SetEditCurrentArgument()
297 //=================================================================================
298 void VisuGUI_InitMeshDlg::SetEditCurrentArgument()
300 QPushButton* send = (QPushButton*)sender();
301 switch (myConstructorId)
303 case 0: /* default constructor */
305 if(send == SelectButtonC1A1) {
306 LineEditC1A1->setFocus() ;
307 myEditCurrentArgument = LineEditC1A1;
309 SelectionIntoArgument() ;
316 //=================================================================================
317 // function : DeactivateActiveDialog()
319 //=================================================================================
320 void VisuGUI_InitMeshDlg::DeactivateActiveDialog()
322 if ( GroupConstructors->isEnabled() ) {
323 disconnect( mySelection, 0, this, 0 );
324 GroupConstructors->setEnabled(false) ;
325 GroupC1->setEnabled(false) ;
326 GroupButtons->setEnabled(false) ;
331 //=================================================================================
332 // function : ActivateThisDialog()
334 //=================================================================================
335 void VisuGUI_InitMeshDlg::ActivateThisDialog()
337 myVisuGUI->EmitSignalDeactivateDialog() ;
338 GroupConstructors->setEnabled(true) ;
339 GroupC1->setEnabled(true) ;
340 GroupButtons->setEnabled(true) ;
341 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
346 //=================================================================================
347 // function : enterEvent()
349 //=================================================================================
350 void VisuGUI_InitMeshDlg::enterEvent(QEvent* e)
352 if ( GroupConstructors->isEnabled() )
354 ActivateThisDialog() ;
359 //=================================================================================
360 // function : closeEvent()
362 //=================================================================================
363 void VisuGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
365 this->ClickOnCancel() ;
369 //=================================================================================
370 // function : TextChangedInLineEdit()
372 //=================================================================================
373 void VisuGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
375 QLineEdit* send = (QLineEdit*)sender();
377 if (send == LineEdit_NameMesh) {
378 myNameMesh = newText;