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_CalculationDlg.h"
25 #include "HYDROGUI_ObjSelector.h"
26 #include "HYDROGUI_Tool.h"
28 #include <SUIT_FileDlg.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
36 #include <QListWidget>
38 #include <QPushButton>
39 #include <QToolButton>
41 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
42 : HYDROGUI_InputPanel( theModule, theTitle )
45 myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), mainFrame() );
47 myObjectName = new QLineEdit( myObjectNameGroup );
49 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
50 aNameLayout->setMargin( 5 );
51 aNameLayout->setSpacing( 5 );
52 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
53 aNameLayout->addWidget( myObjectName );
56 // Calculation boundary line
57 QGroupBox* aBndGroup = new QGroupBox( tr( "CALCULATION_BOUNDARY" ), mainFrame() );
59 myBndPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aBndGroup );
61 QBoxLayout* aBndLayout = new QHBoxLayout( aBndGroup );
62 aBndLayout->setMargin( 5 );
63 aBndLayout->setSpacing( 5 );
64 aBndLayout->addWidget( new QLabel( tr( "BOUNDARY_POLYLINE" ), aBndGroup ) );
65 aBndLayout->addWidget( myBndPolyline );
69 QGroupBox* aZonesGroup = new QGroupBox( tr( "CALCULATION_ZONES" ), mainFrame() );
71 myZones = new QListWidget( aZonesGroup );
72 myZones->setSelectionMode( QListWidget::SingleSelection );
73 myZones->setEditTriggers( QListWidget::NoEditTriggers );
74 myZones->setViewMode( QListWidget::ListMode );
76 myRegions = new QListWidget( aZonesGroup );
77 myRegions->setSelectionMode( QListWidget::SingleSelection );
78 myRegions->setEditTriggers( QListWidget::NoEditTriggers );
79 myRegions->setViewMode( QListWidget::ListMode );
81 mySplittedZonesPrefix = new QLineEdit( aZonesGroup );
83 QPushButton* aSplitBtn = new QPushButton( tr( "SPLIT_REFERENCE_ZONES" ), aZonesGroup );
85 QGridLayout* aZonesLayout = new QGridLayout( aZonesGroup );
86 aZonesLayout->setMargin( 5 );
87 aZonesLayout->setSpacing( 5 );
88 aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REFERENCE_ZONES" ), aZonesGroup ), 0, 0, 1, 2 );
89 aZonesLayout->addWidget( myZones, 1, 0, 1, 2 );
90 aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REGIONS" ), aZonesGroup ), 2, 0, 1, 2 );
91 aZonesLayout->addWidget( myRegions, 3, 0, 1, 2 );
92 aZonesLayout->addWidget( new QLabel( tr( "PREFIX_REGIONS" ), aZonesGroup ), 4, 0 );
93 aZonesLayout->addWidget( mySplittedZonesPrefix, 4, 1 );
94 aZonesLayout->addWidget( aSplitBtn, 5, 0, 1, 2 );
97 addWidget( myObjectNameGroup );
98 addWidget( aBndGroup );
99 addWidget( aZonesGroup );
103 // Connect signals and slots
104 connect( aSplitBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( SplitZones() ) );
107 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
111 void HYDROGUI_CalculationDlg::reset()
113 myObjectName->clear();
115 myBndPolyline->Clear();
120 setSplitZonesPrefix( tr( "DEFAULT_PREFIX_REGIONS" ) );
123 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
125 myObjectName->setText( theName );
128 QString HYDROGUI_CalculationDlg::getObjectName() const
130 return myObjectName->text();
133 void HYDROGUI_CalculationDlg::setPolylineName( const QString& theName )
135 myBndPolyline->SetName( theName );
138 QString HYDROGUI_CalculationDlg::getPolylineName() const
140 return myBndPolyline->GetName();
143 void HYDROGUI_CalculationDlg::setZones( const QStringList& theZones )
147 for ( int i = 0, n = theZones.length(); i < n; ++i )
149 QString aZoneName = theZones.at( i );
151 QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, myZones );
152 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable );
153 aListItem->setCheckState( Qt::Unchecked );
157 void HYDROGUI_CalculationDlg::setSelectedZones( const QStringList& theZones )
159 for ( int i = 0, n = theZones.length(); i < n; ++i )
161 QString aZoneName = theZones.at( i );
163 QList<QListWidgetItem *> anItems =
164 myZones->findItems( aZoneName, Qt::MatchFixedString | Qt::MatchCaseSensitive );
165 if ( anItems.isEmpty() )
168 QListWidgetItem* aListItem = anItems.first();
172 aListItem->setCheckState( Qt::Checked );
176 QStringList HYDROGUI_CalculationDlg::getSelectedZones() const
178 QStringList aResList;
180 for ( int i = 0, n = myZones->count(); i < n; ++i )
182 QListWidgetItem* aListItem = myZones->item( i );
183 if ( !aListItem || aListItem->checkState() != Qt::Checked )
186 QString aSelZoneName = aListItem->text();
187 aResList.append( aSelZoneName );
193 void HYDROGUI_CalculationDlg::setRegions( const QStringList& theRegions )
197 for ( int i = 0, n = theRegions.length(); i < n; ++i )
199 QString aRegionName = theRegions.at( i );
201 QListWidgetItem* aListItem = new QListWidgetItem( aRegionName, myRegions );
202 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
206 QStringList HYDROGUI_CalculationDlg::getRegions() const
208 QStringList aResList;
210 for ( int i = 0, n = myRegions->count(); i < n; ++i )
212 QListWidgetItem* aListItem = myRegions->item( i );
216 QString aRegionName = aListItem->text();
217 aResList.append( aRegionName );
223 void HYDROGUI_CalculationDlg::setSplitZonesPrefix( const QString& theName )
225 mySplittedZonesPrefix->setText( theName );
228 QString HYDROGUI_CalculationDlg::getSplitZonesPrefix() const
230 QString aPrefix = mySplittedZonesPrefix->text();
231 if ( aPrefix.isEmpty() )
232 aPrefix = tr( "DEFAULT_PREFIX_REGIONS" );