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_ImportSinusXOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_UpdateFlags.h"
24 #include "HYDROGUI_Tool2.h"
25 #include <HYDROData_PolylineXY.h>
26 #include <HYDROData_Polyline3D.h>
27 #include <HYDROGUI_DataObject.h>
28 #include <HYDROData_Bathymetry.h>
29 #include <HYDROData_Iterator.h>
31 #include <HYDROData_Profile.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
35 #include <LightApp_Application.h>
37 #include <QApplication>
40 #include <QMessageBox>
42 #include <HYDROData_SinusX.h>
43 #include <HYDROGUI_ImportSinusXDlg.h>
46 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
47 : HYDROGUI_Operation( theModule )
49 setName( tr( "IMPORT_SINUSX" ) );
52 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
56 void HYDROGUI_ImportSinusXOp::startOperation()
58 HYDROGUI_Operation::startOperation();
60 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
61 myFileDlg->setWindowTitle( getName() );
62 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
63 myFileDlg->setNameFilter( tr("SINUSX_FILTER") );
65 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
66 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
71 void HYDROGUI_ImportSinusXOp::onApply()
79 QStringList aFileNames = myFileDlg->selectedFiles();
80 bool IsImported = false;
84 foreach (QString aFileName, aFileNames)
86 if ( aFileName.isEmpty() )
89 QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
93 HYDROData_SinusX aSinusXImporter;
94 NCollection_Sequence<Handle(HYDROData_Entity)> anEntities;
95 QApplication::setOverrideCursor( Qt::WaitCursor );
96 bool ParseStat = aSinusXImporter.OpenAndParse(aFileName);
97 QApplication::restoreOverrideCursor();
100 std::vector<HYDROGUI_CurveBlock> aCurveBlocks = aSinusXImporter.GetCurveBlocks();
102 std::vector<int> types;
103 for (int i=0;i<aCurveBlocks.size();i++)
105 HYDROGUI_CurveBlock CurveBlock = aCurveBlocks[i];
106 types.push_back(CurveBlock.myType);
107 names << CurveBlock.myName;
109 HYDROGUI_ImportSinusXDlg* aDLG = new HYDROGUI_ImportSinusXDlg( module()->getApp()->desktop(), names, types );
110 aDLG->setModal( true );
111 aDLG->setWindowTitle(tr("ENTITIES_TO_IMPORT_FROM_SX"));
112 //QApplication::restoreOverrideCursor();
113 if( aDLG->exec()==QDialog::Accepted ) //??
115 QApplication::setOverrideCursor( Qt::WaitCursor );
116 std::vector<HYDROData_SinusX::ImportOptions> options = aDLG->GetImportOptions();
117 aSinusXImporter.Import(doc(), anEntities, &options);
118 UpdateView(anEntities);
119 QApplication::restoreOverrideCursor();
128 commitDocOperation();
134 module()->update( UF_Model | UF_VTKViewer | UF_OCCViewer );
135 QApplication::restoreOverrideCursor();
138 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle(HYDROData_Entity)>& anEntities)
140 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
141 if ( anActiveViewId == 0 )
142 anActiveViewId = HYDROGUI_Tool::GetActiveViewId( module() );
144 for (int i = 1; i <= anEntities.Size() ; i++)
146 anEntities(i)->Update();
147 module()->setObjectVisible( anActiveViewId, anEntities(i), true );
148 module()->setIsToUpdate( anEntities(i) );