1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_StricklerTableOp.h"
21 #include "HYDROGUI_StricklerTableDlg.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_DataObject.h"
25 #include <HYDROData_Document.h>
27 #include <LightApp_UpdateFlags.h>
31 HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit )
32 : HYDROGUI_Operation( theModule ),
35 setName( theIsEdit ? tr( "EDIT_STRICKLER_TABLE" ) : tr( "IMPORT_STRICKLER_TABLE" ) );
39 HYDROGUI_StricklerTableOp::~HYDROGUI_StricklerTableOp()
43 void HYDROGUI_StricklerTableOp::startOperation()
45 HYDROGUI_Operation::startOperation();
47 HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
49 aPanel->setIsEdit( myIsEdit );
53 if ( isApplyAndClose() )
54 myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
55 if ( !myEditedObject.IsNull() )
57 // Edit selected Strickler table
59 aPanel->setStricklerTableName( myEditedObject->GetName() );
61 // Get Strickler table data from the data model
64 // The code below is a sample of data filling Strickler table
65 HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData;
66 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef1( "Zones de champs, prairies, sans cultures", 20.0 );
67 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef2( "Zones de champs cultivé à végétation basse", 17.5 );
68 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef3( "Zones de champs cultivé à végétation haute", 12.5 );
69 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef4( "Zones d'arbustes, de sous-bois", 10.0 );
70 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef5( "Zones à faible urbanization (bourg)", 9.0 );
71 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef6( "Zones à forte urbanization (agglomération)", 9.0 );
72 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef7( "Canaux naturels", 35.0 );
73 HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef8( "Canaux artificiels en béton", 65.0 );
74 aData.append( aStricklerCoef1 );
75 aData.append( aStricklerCoef2 );
76 aData.append( aStricklerCoef3 );
77 aData.append( aStricklerCoef4 );
78 aData.append( aStricklerCoef5 );
79 aData.append( aStricklerCoef6 );
80 aData.append( aStricklerCoef7 );
81 aData.append( aStricklerCoef8 );
82 aPanel->setData(aData);
86 // Import Strickler table from file
91 void HYDROGUI_StricklerTableOp::abortOperation()
95 HYDROGUI_Operation::abortOperation();
98 void HYDROGUI_StricklerTableOp::commitOperation()
102 HYDROGUI_Operation::commitOperation();
105 HYDROGUI_InputPanel* HYDROGUI_StricklerTableOp::createInputPanel() const
107 HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName() );
108 connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) );
112 bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
113 QStringList& theBrowseObjectsEntries )
115 HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
122 aFilePath = aPanel->getFileName();
123 if ( aFilePath.isEmpty() )
125 theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
130 QString aStricklerTableName = aPanel->getStricklerTableName().simplified();
131 if ( aStricklerTableName.isEmpty() )
133 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
137 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aStricklerTableName ) )
139 // check that there are no other objects with the same name in the document
140 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aStricklerTableName );
141 if( !anObject.IsNull() )
143 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
148 Handle(HYDROData_StricklerTable) aStricklerTableObj;
150 aStricklerTableObj = myEditedObject;
153 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( doc()->CreateObject( KIND_STRICKLER_TABLE ) );
154 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
155 theBrowseObjectsEntries.append( anEntry );
158 if( aStricklerTableObj.IsNull() )
161 aStricklerTableObj->SetName( aStricklerTableName );
165 // Get data from input panel's table and save it into data model object
167 // Check, that type names are unique within the current
168 // Strickler table and show error message, if needed
174 // Import data from Strickler table file into data model object
175 aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
178 aStricklerTableObj->Update();
182 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
183 theBrowseObjectsEntries.append( anEntry );
186 theUpdateFlags |= UF_ObjBrowser;
191 void HYDROGUI_StricklerTableOp::onFileSelected()
193 HYDROGUI_StricklerTableDlg* aPanel =
194 ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
198 QString anStricklerTableName = aPanel->getStricklerTableName().simplified();
199 if ( anStricklerTableName.isEmpty() )
201 anStricklerTableName = aPanel->getFileName();
202 if ( !anStricklerTableName.isEmpty() ) {
203 anStricklerTableName = QFileInfo( anStricklerTableName ).baseName();
206 if ( anStricklerTableName.isEmpty() ) {
207 anStricklerTableName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
209 aPanel->setStricklerTableName( anStricklerTableName );