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"
27 #include "HYDROGUI_DataBrowser.h"
28 #include "HYDROGUI_DataModel.h"
29 #include "HYDROGUI_Module.h"
30 #include "HYDROGUI_DataObject.h"
31 #include "HYDROGUI_NameValidator.h"
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Entity.h>
35 #include <HYDROData_Object.h>
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_Study.h>
45 #include <LightApp_Application.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
53 #include <QListWidget>
55 #include <QPushButton>
56 #include <QToolButton>
57 #include <QWizardPage>
60 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
61 : HYDROGUI_Wizard( theModule, theTitle )
63 QWizard* aWizard = wizard();
64 aWizard->addPage( createObjectsPage() );
65 aWizard->addPage( createZonesPage() );
66 connect( aWizard->button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) );
70 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
74 void HYDROGUI_CalculationDlg::reset()
76 myObjectName->clear();
77 myGeomObjects->clear();
80 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
81 QWizardPage* aPage = new QWizardPage( wizard() );
82 QFrame* aFrame = new QFrame( aPage );
84 // myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
86 // myObjectName = new QLineEdit( myObjectNameGroup );
87 myObjectName = new QLineEdit( aPage );
88 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
89 myObjectName->setValidator( myValidator );
91 connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
92 connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
94 //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
95 //aNameLayout->setMargin( 5 );
96 //aNameLayout->setSpacing( 5 );
97 //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
98 //aNameLayout->addWidget( myObjectName );
101 //QFrame* anObjectsFrame = new QFrame( aFrame );
103 //myGeomObjects = new QListWidget( anObjectsFrame );
104 myGeomObjects = new QListWidget( aPage );
105 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
106 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
107 myGeomObjects->setViewMode( QListWidget::ListMode );
108 myGeomObjects->setSortingEnabled( true );
110 QFrame* aBtnsFrame = new QFrame( aPage );
111 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
112 aBtnsLayout->setMargin( 5 );
113 aBtnsLayout->setSpacing( 5 );
114 aBtnsFrame->setLayout( aBtnsLayout );
115 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
116 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
117 aBtnsLayout->addWidget( anAddBtn );
118 aBtnsLayout->addWidget( aRemoveBtn );
119 aBtnsLayout->addStretch( 1 );
121 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
122 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
124 QGridLayout* aZonesLayout = new QGridLayout( aPage );
125 aZonesLayout->setMargin( 5 );
126 aZonesLayout->setSpacing( 5 );
127 aZonesLayout->setVerticalSpacing( 10 );
128 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
129 aZonesLayout->addWidget( myObjectName, 0, 1 );
130 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
131 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
132 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
134 aPage->setLayout( aZonesLayout );
136 connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
137 connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
142 void HYDROGUI_CalculationDlg::onEmptyName()
144 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
145 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
146 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
149 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
151 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
152 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
153 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
156 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
157 QWizardPage* aPage = new QWizardPage( wizard() );
158 QFrame* aFrame = new QFrame( aPage );
160 QGridLayout* aLayout = new QGridLayout( aPage );
161 //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
163 myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
164 myBrowser->setAutoOpenLevel( 3 );
165 aLayout->setMargin( 5 );
166 aLayout->setSpacing( 5 );
168 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
170 QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
171 myBathymetryChoice = new QComboBox( aFrame );
172 myBathymetryChoice->addItem( tr( "ZMIN" ) );
173 myBathymetryChoice->addItem( tr( "ZMAX" ) );
175 aLayout->addWidget( aBatimetryLabel, 1, 0 );
176 aLayout->addWidget( myBathymetryChoice, 1, 1 );
178 aPage->setLayout( aLayout );
183 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
185 myObjectName->setText( theName );
188 QString HYDROGUI_CalculationDlg::getObjectName() const
190 return myObjectName->text();
193 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
197 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
199 myGeomObjects->clear();
201 for ( int i = 0, n = theObjects.length(); i < n; ++i )
203 QString anObjName = theObjects.at( i );
205 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
206 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
210 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
212 QStringList aResList;
213 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
214 for ( int i = 0, n = aList.length(); i < n; ++i )
216 aResList.append( aList.at( i )->text() );
221 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
223 myEditedObject = theCase;
224 myValidator->setEditedObject( theCase );
226 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
227 myBrowser->setRoot(anobj);
229 LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
230 myEditedObject, "", true );
231 myBrowser->updateTree();
232 myBrowser->openLevels();