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 "HYDROData_SinusX.h"
25 #include <HYDROData_PolylineXY.h>
26 #include <HYDROData_Bathymetry.h>
27 #include <HYDROData_Entity.h>
28 #include <HYDROData_Document.h>
29 #include <HYDROData_Profile.h>
30 #include <HYDROData_Iterator.h>
38 #include <QStringList>
40 HYDROData_SinusX::HYDROData_SinusX( )
44 HYDROData_SinusX::~HYDROData_SinusX()
48 void HYDROData_SinusX::CollectExistingNames(Handle_HYDROData_Document theDocument)
50 HYDROData_Iterator anIter( theDocument );
52 myExistingNames.clear();
53 std::vector<int> anAllowedIndexes;
54 for( ; anIter.More(); anIter.Next() )
55 myExistingNames.push_back(anIter.Current()->GetName());
58 QString HYDROData_SinusX::GetName(const QString& theName)
60 if (myExistingNames.contains(theName))
62 QString aName = theName;
63 while (myExistingNames.contains(aName))
65 QStringList aList = aName.split("_");
66 int aLastInd = aName.lastIndexOf("_");
69 anInd = aList.last().toInt(&IsNum);
72 aName = aName.left(aLastInd) + "_";
73 /*for (int i = 0; i < aList.size() - 1; i++ )
75 aName+= QString::number(++anInd);
78 aName = theName + "_0";
81 myExistingNames.push_back(aName);
86 myExistingNames.push_back(theName);
93 bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
95 if ( theFilePath.isEmpty() )
100 QString anExt = theFilePath.split('.', QString::SkipEmptyParts).back();
104 QFile aFile (theFilePath);
106 aFile.open(QIODevice::ReadOnly);
110 CollectExistingNames(theDocument);
111 SXToHydro(theDocument, theEntities);
122 void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
124 for ( size_t i = 0; i < myCurveBlocks.size(); i++ )
126 if (myCurveBlocks[i].myType == 4) /// scatter plot -> to bathy
128 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
129 HYDROData_Bathymetry::AltitudePoints aAPoints;
130 for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
131 aAPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
133 aBath->SetAltitudePoints(aAPoints);
134 aBath->SetName(GetName(myCurveBlocks[i].myName + "_bath"));
135 theEntities.Append(aBath);
137 if (myCurveBlocks[i].myType == 1 || myCurveBlocks[i].myType == 3)
139 NCollection_Sequence<gp_XYZ> aPoints;
140 for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
141 aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
142 if (myCurveBlocks[i].myIsClosed)
143 aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[0]));
144 Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( theDocument->CreateObject( KIND_PROFILEUZ ) );
145 Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
146 aPolyXY->AddSection( "", myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE, false );
147 aProfileUZ->CalculateAndAddPoints(aPoints, aPolyXY);
148 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
149 aProfile->SetParametricPoints(aProfileUZ->GetPoints());
150 aPolyXY->SetName(GetName(myCurveBlocks[i].myName + "_polyXY"));
151 aProfileUZ->SetName(GetName(myCurveBlocks[i].myName + "_profileUZ"));
152 aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
153 theEntities.Append(aPolyXY);
154 theEntities.Append(aProfileUZ);
155 theEntities.Append(aProfile);
157 if (myCurveBlocks[i].myType == 2)
159 if (myCurveBlocks[i].myCurvePlane == 2)
161 if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4)
163 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
164 HYDROData_ProfileUZ::PointsList aPointList;
165 for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
166 aPointList.Append(gp_XY (myCurveBlocks[i].myXYZPoints[j].X(), myCurveBlocks[i].myXYZPoints[j].Z()));
168 aProfile->SetParametricPoints(aPointList);
169 if ( ! (myCurveBlocks[i].myAdditionalCurveInfo[0] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[1] == 0 &&
170 myCurveBlocks[i].myAdditionalCurveInfo[2] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[3] == 0) )
172 aProfile->SetLeftPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[0], myCurveBlocks[i].myAdditionalCurveInfo[1]));
173 aProfile->SetRightPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[2], myCurveBlocks[i].myAdditionalCurveInfo[3]));
176 aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
177 theEntities.Append(aProfile);
180 if (myCurveBlocks[i].myCurvePlane == 0)
182 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
183 HYDROData_Profile::ProfilePoints aPointList;
184 for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
185 aPointList.Append(myCurveBlocks[i].myXYZPoints[j]);
186 aProfile->SetProfilePoints(aPointList);
187 aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
188 theEntities.Append(aProfile);
196 bool HYDROData_SinusX::Parse(QFile& theFile)
198 if ( !theFile.isOpen() )
205 myCurveBlocks.clear();
206 bool aTotStat = true;
208 aLine = theFile.readLine().simplified();
209 aList = aLine.split( ' ', QString::SkipEmptyParts );
211 for (;!theFile.atEnd();)
213 if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N" || aList[1] == "S" ))
215 HYDROGUI_CurveBlock aCurveBlockInfo;
217 aCurveBlockInfo.myType = 1;
218 else if (aList[1] == "P")
219 aCurveBlockInfo.myType = 2;
220 else if (aList[1] == "N")
221 aCurveBlockInfo.myType = 3;
222 else if (aList[1] == "S")
223 aCurveBlockInfo.myType = 4;
225 if (aList.size() == 9)
227 for (int j = 2; j < 8; j++)
228 aCurveBlockInfo.myRefCoords.push_back(aList[j].toDouble());
229 aCurveBlockInfo.myRefRatio = aList[8].toDouble();
235 aBLine = theFile.readLine().simplified();
236 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
238 if (aBList[0] == "CP")
240 if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
241 aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
242 else if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
244 aCurveBlockInfo.myIsClosed = aBList[1].toInt();
245 aCurveBlockInfo.myIsSpline = aBList[2].toInt();
249 for (int j = 1; j < aBList.size(); j++)
250 aCurveBlockInfo.myAdditionalCurveInfo.push_back(aBList[j].toDouble());
253 if (aBList[0] == "CN")
255 for (int i = 1; i < aBList.size(); i++)
256 Name += aBList[i] + "_";
257 Name.remove(Name.size() - 1, 1);
258 aCurveBlockInfo.myName = Name;
260 } while (!theFile.atEnd() && aBLine[0] == 'C' );
266 if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
268 anXYZ.SetX (aBList[0].toDouble(&aStat));
269 aTotStat = aTotStat && aStat;
270 anXYZ.SetY (aBList[1].toDouble(&aStat));
271 aTotStat = aTotStat && aStat;
272 anXYZ.SetZ (aBList[2].toDouble(&aStat));
273 aTotStat = aTotStat && aStat;
275 aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
277 aBLine = theFile.readLine().simplified();
278 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
283 } while (!theFile.atEnd() || !aBLine.isEmpty());
285 myCurveBlocks.push_back(aCurveBlockInfo);
293 aLine = theFile.readLine().simplified();
294 aList = aLine.split( ' ', QString::SkipEmptyParts );