1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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_ImportPolylineOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROGUI_Tool.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_Polyline3D.h>
31 #include <HYDROGUI_DataObject.h>
32 #include <HYDROData_Bathymetry.h>
33 #include <HYDROData_Iterator.h>
34 #include <HYDROData_ShapeFile.h>
36 #include <HYDROData_Profile.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_FileDlg.h>
40 #include <LightApp_Application.h>
42 #include <QApplication>
45 #include <SUIT_MessageBox.h>
48 HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
49 : HYDROGUI_Operation( theModule )
51 setName( tr( "IMPORT_POLYLINE" ) );
54 HYDROGUI_ImportPolylineOp::~HYDROGUI_ImportPolylineOp()
58 void HYDROGUI_ImportPolylineOp::startOperation()
60 HYDROGUI_Operation::startOperation();
62 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
63 myFileDlg->setWindowTitle( getName() );
64 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
65 myFileDlg->setFilter( tr("POLYLINE_FILTER") );
67 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
68 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
73 void HYDROGUI_ImportPolylineOp::onApply()
81 QStringList aFileNames = myFileDlg->selectedFiles();
83 QApplication::setOverrideCursor( Qt::WaitCursor );
86 foreach (QString aFileName, aFileNames)
88 if ( aFileName.isEmpty() )
91 QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
95 HYDROData_ShapeFile anImporter;
96 NCollection_Sequence<Handle_HYDROData_Entity> theEntities;
97 int aShapeTypeOfFile = -1;
98 int aStat = anImporter.ImportPolylines(doc(), aFileName, theEntities, aShapeTypeOfFile );
100 UpdateView(theEntities);
103 QString aMess = "Cannot import polyline;\n";
105 aMess += "Cannot open SHP file";
106 else if (aStat == -2)
107 aMess += "Cannot open SHX file";
109 aMess += "The shape type of file is " + anImporter.GetShapeTypeName(aShapeTypeOfFile);
110 SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), aMess);
114 if (!aFileNames.empty())
116 commitDocOperation();
118 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
123 QApplication::restoreOverrideCursor();
126 void HYDROGUI_ImportPolylineOp::UpdateView( NCollection_Sequence<Handle_HYDROData_Entity>& anEntities)
128 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
129 if ( anActiveViewId == 0 )
130 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
132 for (int i = 1; i <= anEntities.Size() ; i++)
134 anEntities(i)->Update();
135 module()->setObjectVisible( anActiveViewId, anEntities(i), true );
136 module()->setIsToUpdate( anEntities(i) );