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_ImportBathymetryOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ImportBathymetryDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
31 #include <HYDROData_Bathymetry.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_UpdateFlags.h>
38 HYDROGUI_ImportBathymetryOp::HYDROGUI_ImportBathymetryOp( HYDROGUI_Module* theModule )
39 : HYDROGUI_Operation( theModule )
41 setName( tr( "IMPORT_BATHYMETRY" ) );
44 HYDROGUI_ImportBathymetryOp::~HYDROGUI_ImportBathymetryOp()
48 void HYDROGUI_ImportBathymetryOp::startOperation()
50 HYDROGUI_Operation::startOperation();
52 HYDROGUI_ImportBathymetryDlg* aPanel =
53 ::qobject_cast<HYDROGUI_ImportBathymetryDlg*>( inputPanel() );
60 void HYDROGUI_ImportBathymetryOp::abortOperation()
62 HYDROGUI_Operation::abortOperation();
65 void HYDROGUI_ImportBathymetryOp::commitOperation()
67 HYDROGUI_Operation::commitOperation();
70 HYDROGUI_InputPanel* HYDROGUI_ImportBathymetryOp::createInputPanel() const
72 HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportBathymetryDlg( module(), getName() );
74 connect ( aPanel, SIGNAL( FileSelected( const QString& ) ), SLOT( onFileSelected() ) );
79 bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags,
80 QString& theErrorMsg )
82 HYDROGUI_ImportBathymetryDlg* aPanel =
83 ::qobject_cast<HYDROGUI_ImportBathymetryDlg*>( inputPanel() );
87 QString anObjectName = aPanel->getObjectName().simplified();
88 if ( anObjectName.isEmpty() )
90 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
94 QString aFileName = aPanel->getFileName().simplified();
95 if ( aFileName.isEmpty() )
97 theErrorMsg = tr( "INCORRECT_FILE_NAME" );
101 QFileInfo aFileInfo( aFileName );
102 if ( !aFileInfo.exists() || !aFileInfo.isReadable() )
104 theErrorMsg = tr( "FILE_NOT_EXISTS_OR_CANT_BE_READ" ).arg( aFileName );
108 // check that there are no other objects with the same name in the document
109 Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
110 if ( !anObject.IsNull() )
112 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
116 Handle(HYDROData_Bathymetry) aBathymetryObj =
117 Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) );
118 if ( aBathymetryObj.IsNull() )
121 if ( !aBathymetryObj->ImportFromFile( aFileName ) )
123 theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileName );
127 aBathymetryObj->SetName( anObjectName );
129 theUpdateFlags = UF_Model;
133 void HYDROGUI_ImportBathymetryOp::onFileSelected()
135 HYDROGUI_ImportBathymetryDlg* aPanel =
136 ::qobject_cast<HYDROGUI_ImportBathymetryDlg*>( inputPanel() );
140 QString anObjectName = aPanel->getObjectName().simplified();
141 if ( anObjectName.isEmpty() )
143 anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Bathymetry" );
144 aPanel->setObjectName( anObjectName );