1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ObstacleDlg.h"
25 #include "HYDROGUI_Tool.h"
27 #include <SUIT_FileDlg.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
34 #include <QToolButton>
35 #include <QRadioButton>
36 #include <QButtonGroup>
40 static QString lastUsedFilter;
42 HYDROGUI_ObstacleDlg::HYDROGUI_ObstacleDlg( HYDROGUI_Module* theModule, const QString& theTitle,
43 const bool theIsToEnableFileSelection )
44 : HYDROGUI_InputPanel( theModule, theTitle ),
45 myFileSelectionEnabled ( theIsToEnableFileSelection )
47 // Get resource manager
48 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
51 QGroupBox* aFileNameGroup = 0;
53 if ( myFileSelectionEnabled ) {
54 aFileNameGroup = new QGroupBox( tr( "GET_SHAPE_FROM_FILE" ), this );
56 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFileNameGroup );
58 myFileName = new QLineEdit( aFileNameGroup );
59 myFileName->setReadOnly( true );
61 QToolButton* aBrowseBtn = new QToolButton( aFileNameGroup );
62 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
64 QBoxLayout* aFileNameLayout = new QHBoxLayout( aFileNameGroup );
65 aFileNameLayout->setMargin( 5 );
66 aFileNameLayout->setSpacing( 5 );
67 aFileNameLayout->addWidget( aFileNameLabel );
68 aFileNameLayout->addWidget( myFileName );
69 aFileNameLayout->addWidget( aBrowseBtn );
71 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
75 myObstacleNameGroup = new QGroupBox( tr( "OBSTACLE_NAME" ), this );
77 QLabel* anObstacleNameLabel = new QLabel( tr( "NAME" ), myObstacleNameGroup );
78 myObstacleName = new QLineEdit( myObstacleNameGroup );
80 QBoxLayout* anObstacleNameLayout = new QHBoxLayout( myObstacleNameGroup );
81 anObstacleNameLayout->setMargin( 5 );
82 anObstacleNameLayout->setSpacing( 5 );
83 anObstacleNameLayout->addWidget( anObstacleNameLabel );
84 anObstacleNameLayout->addWidget( myObstacleName );
86 myObstacleNameGroup->hide(); //TODO to be enabled?
88 // Mode selector (create/edit)
89 myModeGroup = new QGroupBox( tr( "MODE" ), this );
91 QRadioButton* aNewObstacleRB = new QRadioButton( tr( "CREATE_NEW_OBSTACLE" ), mainFrame() );
92 QRadioButton* aModifyObstacleRB = new QRadioButton( tr( "MODIFY_OBSTACLE" ), mainFrame() );
94 myModeButtons = new QButtonGroup( mainFrame() );
95 myModeButtons->addButton( aNewObstacleRB, CreateNewId );
96 myModeButtons->addButton( aModifyObstacleRB, ModifyExistentId );
98 QBoxLayout* aModeSelectorLayout = new QHBoxLayout( myModeGroup );
99 aModeSelectorLayout->setMargin( 5 );
100 aModeSelectorLayout->setSpacing( 5 );
101 aModeSelectorLayout->addWidget( aNewObstacleRB );
102 aModeSelectorLayout->addWidget( aModifyObstacleRB );
104 // Existing obstacles selector
105 myObstaclesGroup = new QGroupBox( tr( "OBSTACLE_TO_EDIT" ), this );
107 QLabel* anObstacleLabel = new QLabel( tr( "OBSTACLE" ), myObstaclesGroup );
109 myObstacles = new QComboBox( mainFrame() );
110 myObstacles->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112 QBoxLayout* anObstaclesSelectorLayout = new QHBoxLayout( myObstaclesGroup );
113 anObstaclesSelectorLayout->setMargin( 5 );
114 anObstaclesSelectorLayout->setSpacing( 5 );
115 anObstaclesSelectorLayout->addWidget( anObstacleLabel );
116 anObstaclesSelectorLayout->addWidget( myObstacles );
119 if ( aFileNameGroup ) {
120 addWidget( aFileNameGroup );
122 addWidget( myObstacleNameGroup );
123 addWidget( myModeGroup );
124 addWidget( myObstaclesGroup );
127 // Connect signals and slots
128 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), this, SLOT( onModeActivated( int ) ) );
129 connect( myObstacles, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onObstacleSelectionChanged( ) ) );
132 HYDROGUI_ObstacleDlg::~HYDROGUI_ObstacleDlg()
136 void HYDROGUI_ObstacleDlg::setObstacleNames( const QStringList& theObstacles )
138 myObstacles->clear();
139 myObstacles->addItems( theObstacles );
144 void HYDROGUI_ObstacleDlg::onModeActivated( int theMode )
149 QString HYDROGUI_ObstacleDlg::getObstacleName() const
151 return myObstacleName->text();
156 if ( myModeButtons->checkedId() == ModifyExistentId ) {
157 aName = myObstacles->currentText();
163 QString HYDROGUI_ObstacleDlg::getEditedObstacleName() const
167 if ( myModeButtons->checkedId() == ModifyExistentId ) {
168 aName = myObstacles->currentText();
174 QString HYDROGUI_ObstacleDlg::getFileName() const
176 return myFileName->text();
179 void HYDROGUI_ObstacleDlg::onBrowse()
181 SUIT_FileDlg* aFileDlg = new SUIT_FileDlg( this, true );
182 aFileDlg->setWindowTitle( tr("IMPORT_OBSTACLE_FROM_FILE") );
183 aFileDlg->setFilter( tr("OBSTACLE_FILTER") );
184 if ( !lastUsedFilter.isEmpty() ) {
185 aFileDlg->selectFilter( lastUsedFilter );
188 if ( aFileDlg->exec() == QDialog::Accepted ) {
189 QString aFileName = aFileDlg->selectedFile();
190 lastUsedFilter = aFileDlg->selectedFilter();
192 if ( !aFileName.isEmpty() ) {
193 myFileName->setText( aFileName );
195 QFileInfo aFileInfo( aFileName );
196 QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() );
197 myObstacleName->setText( aName );
204 void HYDROGUI_ObstacleDlg::reset()
206 if ( myFileSelectionEnabled ) {
209 myObstacleName->clear();
211 // Activate the creation mode
212 myModeButtons->button( CreateNewId )->setChecked( true );
213 onModeActivated( CreateNewId );
218 void HYDROGUI_ObstacleDlg::onObstacleSelectionChanged()
220 if ( myObstacleName->text().isEmpty() ) {
221 myObstacleName->setText( myObstacles->currentText() );
225 void HYDROGUI_ObstacleDlg::UpdateControls()
227 myObstacleNameGroup->setEnabled( !myFileSelectionEnabled ||
228 !myFileName->text().isEmpty() );
229 myModeGroup->setEnabled( myObstacleNameGroup->isEnabled() &&
230 myObstacles->count() > 0 );
231 myObstaclesGroup->setEnabled( myModeButtons->checkedId() == ModifyExistentId );