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>
29 HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit )
30 : HYDROGUI_Operation( theModule ),
33 setName( theIsEdit ? tr( "EDIT_STRICKLER_TABLE" ) : tr( "IMPORT_STRICKLER_TABLE" ) );
37 HYDROGUI_StricklerTableOp::~HYDROGUI_StricklerTableOp()
41 void HYDROGUI_StricklerTableOp::startOperation()
43 HYDROGUI_Operation::startOperation();
45 HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
47 //aPanel->setIsEdit( myIsEdit );
51 if ( isApplyAndClose() )
52 myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
53 if ( !myEditedObject.IsNull() )
55 // Edit selected Strickler table
59 // Import Strickler table from file
64 void HYDROGUI_StricklerTableOp::abortOperation()
68 HYDROGUI_Operation::abortOperation();
71 void HYDROGUI_StricklerTableOp::commitOperation()
75 HYDROGUI_Operation::commitOperation();
78 HYDROGUI_InputPanel* HYDROGUI_StricklerTableOp::createInputPanel() const
80 HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName() );
81 connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) );
85 bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
86 QStringList& theBrowseObjectsEntries )
88 HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
95 aFilePath = aPanel->getFileName();
96 if ( aFilePath.isEmpty() )
98 theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
103 QString aStricklerTableName = aPanel->getStricklerTableName().simplified();
104 if ( aStricklerTableName.isEmpty() )
106 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
110 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aStricklerTableName ) )
112 // check that there are no other objects with the same name in the document
113 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aStricklerTableName );
114 if( !anObject.IsNull() )
116 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
121 Handle(HYDROData_StricklerTable) aStricklerTableObj;
123 aStricklerTableObj = myEditedObject;
126 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( doc()->CreateObject( KIND_STRICKLER_TABLE ) );
127 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
128 theBrowseObjectsEntries.append( anEntry );
131 if( aStricklerTableObj.IsNull() )
134 aStricklerTableObj->SetName( aStricklerTableName );
138 // Get data from input panel's table and save it into data model object
142 // Import data from Strickler table file into data model model object
143 aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
146 aStricklerTableObj->Update();
150 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
151 theBrowseObjectsEntries.append( anEntry );
157 void HYDROGUI_StricklerTableOp::onFileSelected()
159 HYDROGUI_StricklerTableDlg* aPanel =
160 ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
164 QString anStricklerTableName = aPanel->getStricklerTableName().simplified();
165 if ( anStricklerTableName.isEmpty() )
167 anStricklerTableName = aPanel->getFileName();
168 if ( !anStricklerTableName.isEmpty() ) {
169 anStricklerTableName = QFileInfo( anStricklerTableName ).baseName();
172 if ( anStricklerTableName.isEmpty() ) {
173 anStricklerTableName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
175 aPanel->setStricklerTableName( anStricklerTableName );