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() );
69 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
73 void HYDROGUI_CalculationDlg::reset()
75 myObjectName->clear();
76 myGeomObjects->clear();
79 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
80 QWizardPage* aPage = new QWizardPage( wizard() );
81 QFrame* aFrame = new QFrame( aPage );
83 // myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
85 // myObjectName = new QLineEdit( myObjectNameGroup );
86 myObjectName = new QLineEdit( aPage );
87 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
88 myObjectName->setValidator( myValidator );
90 connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
91 connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
93 //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
94 //aNameLayout->setMargin( 5 );
95 //aNameLayout->setSpacing( 5 );
96 //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
97 //aNameLayout->addWidget( myObjectName );
100 //QFrame* anObjectsFrame = new QFrame( aFrame );
102 //myGeomObjects = new QListWidget( anObjectsFrame );
103 myGeomObjects = new QListWidget( aPage );
104 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
105 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
106 myGeomObjects->setViewMode( QListWidget::ListMode );
108 QFrame* aBtnsFrame = new QFrame( aPage );
109 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
110 aBtnsLayout->setMargin( 5 );
111 aBtnsLayout->setSpacing( 5 );
112 aBtnsFrame->setLayout( aBtnsLayout );
113 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
114 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
115 aBtnsLayout->addWidget( anAddBtn );
116 aBtnsLayout->addWidget( aRemoveBtn );
117 aBtnsLayout->addStretch( 1 );
119 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
120 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
122 QGridLayout* aZonesLayout = new QGridLayout( aPage );
123 aZonesLayout->setMargin( 5 );
124 aZonesLayout->setSpacing( 5 );
125 aZonesLayout->setVerticalSpacing( 10 );
126 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
127 aZonesLayout->addWidget( myObjectName, 0, 1 );
128 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
129 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
130 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
132 //QBoxLayout* aMainLayout = new QVBoxLayout( aFrame );
133 //aMainLayout->setMargin( 0 );
134 //aMainLayout->setSpacing( 5 );
135 //aMainLayout->addWidget( myObjectNameGroup );
136 //aMainLayout->addWidget( anObjectsFrame );
137 //aMainLayout->addStretch();
139 //aPage->setLayout( aMainLayout );
140 aPage->setLayout( aZonesLayout );
145 void HYDROGUI_CalculationDlg::onEmptyName()
147 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
148 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
149 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
152 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
154 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
155 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
156 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
159 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
160 QWizardPage* aPage = new QWizardPage( wizard() );
161 QFrame* aFrame = new QFrame( aPage );
163 QGridLayout* aLayout = new QGridLayout( aPage );
164 //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
166 myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
167 myBrowser->setAutoOpenLevel( 3 );
168 aLayout->setMargin( 5 );
169 aLayout->setSpacing( 5 );
171 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
173 QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
174 myBathymetryChoice = new QComboBox( aFrame );
175 myBathymetryChoice->addItem( tr( "ZMIN" ) );
176 myBathymetryChoice->addItem( tr( "ZMAX" ) );
178 aLayout->addWidget( aBatimetryLabel, 1, 0 );
179 aLayout->addWidget( myBathymetryChoice, 1, 1 );
181 aPage->setLayout( aLayout );
186 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
188 myObjectName->setText( theName );
191 QString HYDROGUI_CalculationDlg::getObjectName() const
193 return myObjectName->text();
196 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
200 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
202 myGeomObjects->clear();
204 for ( int i = 0, n = theObjects.length(); i < n; ++i )
206 QString anObjName = theObjects.at( i );
208 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
209 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
213 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
215 QStringList aResList;
217 for ( int i = 0, n = myGeomObjects->count(); i < n; ++i )
219 QListWidgetItem* aListItem = myGeomObjects->item( i );
223 QString aSelObjName = aListItem->text();
224 aResList.append( aSelObjName );
230 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
232 myEditedObject = theCase;
233 myValidator->setEditedObject( theCase );
235 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
236 myBrowser->setRoot(anobj);
238 LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
239 myEditedObject, "", true );
240 myBrowser->updateTree();
241 myBrowser->openLevels();