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_ImportSinusXOp.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>
35 #include <HYDROData_Profile.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_FileDlg.h>
39 #include <LightApp_Application.h>
41 #include <QApplication>
44 #include <QMessageBox>
47 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
48 : HYDROGUI_Operation( theModule )
50 setName( tr( "IMPORT_SINUSX" ) );
53 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
57 void HYDROGUI_ImportSinusXOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
62 myFileDlg->setWindowTitle( getName() );
63 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
64 myFileDlg->setFilter( tr("SINUSX_FILTER") );
66 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
67 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
72 void HYDROGUI_ImportSinusXOp::onApply()
80 QString aFileName = myFileDlg->selectedFile();
81 if ( aFileName.isEmpty() )
87 QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
91 QFile aFile (aFileName);
92 aFile.open(QIODevice::ReadOnly);
96 QApplication::setOverrideCursor( Qt::WaitCursor );
102 commitDocOperation();
107 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
109 QApplication::restoreOverrideCursor();
112 void HYDROGUI_ImportSinusXOp::ProcessSX()
114 /*Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
116 Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
118 //TODO - move to hydro data
119 std::vector<Handle(HYDROData_Entity)> anEntities;
120 for ( int i = 0; i < myCurveBlocks.size(); i++ )
122 if (myCurveBlocks[i].myType == 4) /// scatter plot -> to bathy
124 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) );
125 HYDROData_Bathymetry::AltitudePoints aAPoints;
126 for (int j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
127 aAPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
129 aBath->SetAltitudePoints(aAPoints);
130 aBath->SetName(myCurveBlocks[i].myName);
131 anEntities.push_back(aBath);
133 if (myCurveBlocks[i].myType == 1 || myCurveBlocks[i].myType == 3)
135 NCollection_Sequence<gp_XYZ> aPoints;
136 for (int j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
137 aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
138 if (myCurveBlocks[i].myIsClosed)
139 aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[0]));
140 Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( doc()->CreateObject( KIND_PROFILEUZ ) );
141 Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
142 aPolyXY->AddSection( "", myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE, false );
143 aProfileUZ->CalculateAndAddPoints(aPoints, aPolyXY);
144 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
145 aProfile->SetParametricPoints(aProfileUZ->GetPoints());
146 aPolyXY->SetName(myCurveBlocks[i].myName + "_polyXY");
147 aProfileUZ->SetName(myCurveBlocks[i].myName + "_profileUZ");
148 aProfile->SetName(myCurveBlocks[i].myName + "_profile");
149 anEntities.push_back(aPolyXY);
150 anEntities.push_back(aProfileUZ);
151 anEntities.push_back(aProfile);
153 if (myCurveBlocks[i].myType == 2)
155 if (myCurveBlocks[i].myCurvePlane == 2)
157 if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4)
159 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
160 HYDROData_ProfileUZ::PointsList aPointList;
161 for (int j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
162 aPointList.Append(gp_XY (myCurveBlocks[i].myXYZPoints[j].X(), myCurveBlocks[i].myXYZPoints[j].Z()));
164 aProfile->SetParametricPoints(aPointList);
165 if ( ! (myCurveBlocks[i].myAdditionalCurveInfo[0] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[1] == 0 &&
166 myCurveBlocks[i].myAdditionalCurveInfo[2] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[3] == 0) )
168 aProfile->SetLeftPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[0], myCurveBlocks[i].myAdditionalCurveInfo[1]));
169 aProfile->SetRightPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[2], myCurveBlocks[i].myAdditionalCurveInfo[3]));
172 aProfile->SetName(myCurveBlocks[i].myName + "_profile");
173 anEntities.push_back(aProfile);
176 if (myCurveBlocks[i].myCurvePlane == 0)
178 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
179 HYDROData_Profile::ProfilePoints aPointList;
180 for (int j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
181 aPointList.Append(myCurveBlocks[i].myXYZPoints[j]);
182 aProfile->SetProfilePoints(aPointList);
183 aProfile->SetName(myCurveBlocks[i].myName + "_profile");
184 anEntities.push_back(aProfile);
191 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
192 if ( anActiveViewId == 0 )
193 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
195 for (int i = 0; i < anEntities.size() ; i++)
197 anEntities[i]->Update();
198 module()->setObjectVisible( anActiveViewId, anEntities[i], true );
199 module()->setIsToUpdate( anEntities[i] );
206 bool HYDROGUI_ImportSinusXOp::Parse( QFile& theFile)
208 if ( !theFile.isOpen() )
215 myCurveBlocks.clear();
216 bool aTotStat = true;
218 aLine = theFile.readLine().simplified();
219 aList = aLine.split( ' ', QString::SkipEmptyParts );
221 for (;!theFile.atEnd();)
223 if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N" || aList[1] == "S" ))
225 HYDROGUI_CurveBlock aCurveBlockInfo;
227 aCurveBlockInfo.myType = 1;
228 else if (aList[1] == "P")
229 aCurveBlockInfo.myType = 2;
230 else if (aList[1] == "N")
231 aCurveBlockInfo.myType = 3;
232 else if (aList[1] == "S")
233 aCurveBlockInfo.myType = 4;
235 if (aList.size() == 9)
237 for (int j = 2; j < 8; j++)
238 aCurveBlockInfo.myRefCoords.push_back(aList[j].toDouble());
239 aCurveBlockInfo.myRefRatio = aList[8].toDouble();
245 aBLine = theFile.readLine().simplified();
246 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
248 if (aBList[0] == "CP")
250 if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
251 aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
252 else if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
254 aCurveBlockInfo.myIsClosed = aBList[1].toInt();
255 aCurveBlockInfo.myIsSpline = aBList[2].toInt();
259 for (int j = 1; j < aBList.size(); j++)
260 aCurveBlockInfo.myAdditionalCurveInfo.push_back(aBList[j].toDouble());
263 if (aBList[0] == "CN")
265 for (int i = 1; i < aBList.size(); i++)
266 Name += aBList[i] + "_";
267 Name.remove(Name.size() - 1, 1);
268 aCurveBlockInfo.myName = Name;
270 } while (!theFile.atEnd() && aBLine[0] == 'C' );
276 if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
278 anXYZ.SetX (aBList[0].toDouble(&aStat));
279 aTotStat = aTotStat && aStat;
280 anXYZ.SetY (aBList[1].toDouble(&aStat));
281 aTotStat = aTotStat && aStat;
282 anXYZ.SetZ (aBList[2].toDouble(&aStat));
283 aTotStat = aTotStat && aStat;
285 aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
287 aBLine = theFile.readLine().simplified();
288 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
293 } while (!theFile.atEnd() || !aBLine.isEmpty());
295 myCurveBlocks.push_back(aCurveBlockInfo);
303 aLine = theFile.readLine().simplified();
304 aList = aLine.split( ' ', QString::SkipEmptyParts );