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 <HYDROGUI_DataObject.h>
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
40 #include <SUIT_DataObject.h>
41 #include <SUIT_FileDlg.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_Study.h>
46 #include <LightApp_Application.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
54 #include <QListWidget>
56 #include <QPushButton>
57 #include <QToolButton>
58 #include <QWizardPage>
61 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
62 : HYDROGUI_Wizard( theModule, theTitle )
64 QWizard* aWizard = wizard();
65 aWizard->addPage( createObjectsPage() );
66 aWizard->addPage( createZonesPage() );
67 connect( aWizard->button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) );
71 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
75 void HYDROGUI_CalculationDlg::reset()
77 myObjectName->clear();
78 myGeomObjects->clear();
81 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
82 QWizardPage* aPage = new QWizardPage( wizard() );
83 QFrame* aFrame = new QFrame( aPage );
85 // myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
87 // myObjectName = new QLineEdit( myObjectNameGroup );
88 myObjectName = new QLineEdit( aPage );
89 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
90 myObjectName->setValidator( myValidator );
92 connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
93 connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
95 //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
96 //aNameLayout->setMargin( 5 );
97 //aNameLayout->setSpacing( 5 );
98 //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
99 //aNameLayout->addWidget( myObjectName );
102 //QFrame* anObjectsFrame = new QFrame( aFrame );
104 //myGeomObjects = new QListWidget( anObjectsFrame );
105 myGeomObjects = new QListWidget( aPage );
106 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
107 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
108 myGeomObjects->setViewMode( QListWidget::ListMode );
109 myGeomObjects->setSortingEnabled( true );
111 QFrame* aBtnsFrame = new QFrame( aPage );
112 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
113 aBtnsLayout->setMargin( 5 );
114 aBtnsLayout->setSpacing( 5 );
115 aBtnsFrame->setLayout( aBtnsLayout );
116 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
117 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
118 aBtnsLayout->addWidget( anAddBtn );
119 aBtnsLayout->addWidget( aRemoveBtn );
120 aBtnsLayout->addStretch( 1 );
122 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
123 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
125 QGridLayout* aZonesLayout = new QGridLayout( aPage );
126 aZonesLayout->setMargin( 5 );
127 aZonesLayout->setSpacing( 5 );
128 aZonesLayout->setVerticalSpacing( 10 );
129 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
130 aZonesLayout->addWidget( myObjectName, 0, 1 );
131 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
132 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
133 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
135 aPage->setLayout( aZonesLayout );
137 connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
138 connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
143 void HYDROGUI_CalculationDlg::onEmptyName()
145 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
146 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
147 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
150 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
152 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
153 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
154 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
157 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
158 QWizardPage* aPage = new QWizardPage( wizard() );
159 QFrame* aFrame = new QFrame( aPage );
161 QGridLayout* aLayout = new QGridLayout( aPage );
162 //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
164 myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
165 myBrowser->setAutoOpenLevel( 3 );
166 aLayout->setMargin( 5 );
167 aLayout->setSpacing( 5 );
169 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
171 myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
172 myBathymetryChoice = new QComboBox( aFrame );
173 myBathymetryChoice->addItem( tr( "ZMIN" ) );
174 myBathymetryChoice->addItem( tr( "ZMAX" ) );
176 myBathymetryChoice->setVisible( false );
177 myBatimetryLabel->setVisible( false );
179 aLayout->addWidget( myBatimetryLabel, 1, 0 );
180 aLayout->addWidget( myBathymetryChoice, 1, 1 );
182 aPage->setLayout( aLayout );
184 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
189 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
192 HYDROGUI_DataObject* anObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
195 doShow = anObject->isMergingNeed();
197 myBathymetryChoice->setVisible( doShow );
198 myBatimetryLabel->setVisible( doShow );
201 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
203 myObjectName->setText( theName );
206 QString HYDROGUI_CalculationDlg::getObjectName() const
208 return myObjectName->text();
211 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
215 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
217 myGeomObjects->clear();
219 for ( int i = 0, n = theObjects.length(); i < n; ++i )
221 QString anObjName = theObjects.at( i );
223 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
224 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
228 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
230 QStringList aResList;
231 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
232 for ( int i = 0, n = aList.length(); i < n; ++i )
234 aResList.append( aList.at( i )->text() );
239 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
241 myEditedObject = theCase;
242 myValidator->setEditedObject( theCase );
244 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
245 myBrowser->setRoot(anobj);
247 LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
248 myEditedObject, "", true );
249 myBrowser->updateTree();
250 myBrowser->openLevels();