]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_SinusX.cxx
Salome HOME
sinusX p.3
[modules/hydro.git] / src / HYDROData / HYDROData_SinusX.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROData_SinusX.h"
24
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
31 #include <gp_XYZ.hxx>
32 #include <gp_XY.hxx>
33
34 #include <QFile>
35 #include <QFileInfo>
36 #include <QString>
37 #include <QStringList>
38
39 HYDROData_SinusX::HYDROData_SinusX( ) 
40 {
41 }
42
43 HYDROData_SinusX::~HYDROData_SinusX()
44 {
45 }
46
47
48 bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
49 {
50   if ( theFilePath.isEmpty() )
51   { 
52     return false;
53   }
54
55   QString anExt = theFilePath.split('.', QString::SkipEmptyParts).back();
56
57   if (anExt == "sx")
58   {
59     QFile aFile (theFilePath);
60     
61     aFile.open(QIODevice::ReadOnly);
62
63     Parse(aFile);
64    
65     SXToHydro(theDocument, theEntities);
66     
67     aFile.close();
68     
69     return true;
70   }
71   else
72     return false;
73
74 }
75
76 void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
77
78   for ( size_t i = 0; i < myCurveBlocks.size(); i++ )
79   {
80     if (myCurveBlocks[i].myType == 4) ///  scatter plot -> to bathy
81     {
82       Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
83       HYDROData_Bathymetry::AltitudePoints aAPoints;
84       for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
85         aAPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
86
87       aBath->SetAltitudePoints(aAPoints);
88       aBath->SetName(myCurveBlocks[i].myName);
89       theEntities.Append(aBath);
90     }
91     if (myCurveBlocks[i].myType == 1 || myCurveBlocks[i].myType == 3)
92     {
93       NCollection_Sequence<gp_XYZ> aPoints;
94       for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
95         aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
96       if (myCurveBlocks[i].myIsClosed)
97         aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[0]));
98       Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( theDocument->CreateObject( KIND_PROFILEUZ ) );
99       Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
100       aPolyXY->AddSection( "",  myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE, false ); 
101       aProfileUZ->CalculateAndAddPoints(aPoints, aPolyXY);
102       Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
103       aProfile->SetParametricPoints(aProfileUZ->GetPoints());
104       aPolyXY->SetName(myCurveBlocks[i].myName + "_polyXY");
105       aProfileUZ->SetName(myCurveBlocks[i].myName + "_profileUZ");
106       aProfile->SetName(myCurveBlocks[i].myName + "_profile");
107       theEntities.Append(aPolyXY);
108       theEntities.Append(aProfileUZ);
109       theEntities.Append(aProfile);
110     }
111     if (myCurveBlocks[i].myType == 2)
112     {
113       if (myCurveBlocks[i].myCurvePlane == 2)
114       {
115         if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4)
116         {
117           Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
118           HYDROData_ProfileUZ::PointsList aPointList;
119           for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
120             aPointList.Append(gp_XY (myCurveBlocks[i].myXYZPoints[j].X(), myCurveBlocks[i].myXYZPoints[j].Z()));
121            
122           aProfile->SetParametricPoints(aPointList);
123           if ( ! (myCurveBlocks[i].myAdditionalCurveInfo[0] == 0 &&  myCurveBlocks[i].myAdditionalCurveInfo[1] == 0 && 
124             myCurveBlocks[i].myAdditionalCurveInfo[2] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[3] == 0) )
125           {
126             aProfile->SetLeftPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[0], myCurveBlocks[i].myAdditionalCurveInfo[1]));
127             aProfile->SetRightPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[2], myCurveBlocks[i].myAdditionalCurveInfo[3]));
128             aProfile->Update();
129           }
130           aProfile->SetName(myCurveBlocks[i].myName + "_profile");
131           theEntities.Append(aProfile);
132         }
133       }
134       if (myCurveBlocks[i].myCurvePlane == 0)
135       {
136         Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
137         HYDROData_Profile::ProfilePoints aPointList;
138         for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
139           aPointList.Append(myCurveBlocks[i].myXYZPoints[j]);
140         aProfile->SetProfilePoints(aPointList);
141         aProfile->SetName(myCurveBlocks[i].myName + "_profile");
142         theEntities.Append(aProfile);
143       }
144     }
145   }
146
147 }
148  
149
150
151
152 bool HYDROData_SinusX::Parse(QFile& theFile)
153 {
154   if ( !theFile.isOpen() )
155     return false;
156
157   QString aLine;
158   QString aBLine;
159   QStringList aList;
160   QStringList aBList;
161   myCurveBlocks.clear();
162   bool aTotStat = true;
163
164   aLine = theFile.readLine().simplified();
165   aList = aLine.split( ' ', QString::SkipEmptyParts );
166
167   for (;!theFile.atEnd();) 
168   {
169     if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N" || aList[1] == "S" ))
170     {  
171       HYDROGUI_CurveBlock aCurveBlockInfo;
172       if (aList[1] == "C")
173         aCurveBlockInfo.myType = 1;
174       else if (aList[1] == "P")
175         aCurveBlockInfo.myType = 2;
176       else if (aList[1] == "N")
177         aCurveBlockInfo.myType = 3;
178       else if (aList[1] == "S")
179         aCurveBlockInfo.myType = 4;
180
181       if (aList.size() == 9)
182       {
183         for (int j = 2; j < 8; j++)
184           aCurveBlockInfo.myRefCoords.push_back(aList[j].toDouble());
185         aCurveBlockInfo.myRefRatio = aList[8].toDouble();
186       }
187
188       QString Name;
189       do
190       {
191         aBLine = theFile.readLine().simplified();
192         aBList = aBLine.split( ' ', QString::SkipEmptyParts );
193          
194         if (aBList[0] == "CP")
195         {
196           if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
197             aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
198           else if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
199           {
200             aCurveBlockInfo.myIsClosed = aBList[1].toInt();
201             aCurveBlockInfo.myIsSpline = aBList[2].toInt();
202           }
203           else
204           {
205             for (int j = 1; j < aBList.size(); j++)
206               aCurveBlockInfo.myAdditionalCurveInfo.push_back(aBList[j].toDouble());
207           }
208         }
209         if (aBList[0] == "CN")
210         {
211            for (int i = 1; i < aBList.size(); i++)
212              Name += aBList[i] + "_"; 
213            Name.remove(Name.size() - 1, 1);
214            aCurveBlockInfo.myName = Name;
215         }
216       } while (!theFile.atEnd() && aBLine[0] == 'C' );
217
218       bool aStat;
219       aTotStat = true;
220       do
221       {
222         if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
223           gp_XYZ anXYZ;
224           anXYZ.SetX (aBList[0].toDouble(&aStat));  
225           aTotStat = aTotStat && aStat;
226           anXYZ.SetY (aBList[1].toDouble(&aStat));
227           aTotStat = aTotStat && aStat;
228           anXYZ.SetZ (aBList[2].toDouble(&aStat));
229           aTotStat = aTotStat && aStat;
230
231           aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
232           
233           aBLine = theFile.readLine().simplified();
234           aBList = aBLine.split( ' ', QString::SkipEmptyParts );
235         }
236         else 
237           break;
238     
239       } while (!theFile.atEnd() || !aBLine.isEmpty());
240       if (aTotStat)
241         myCurveBlocks.push_back(aCurveBlockInfo);
242
243       aLine = aBLine;
244       aList = aBList;
245
246     }
247     else
248     {
249       aLine = theFile.readLine().simplified();
250       aList = aLine.split( ' ', QString::SkipEmptyParts );
251     }
252
253   }
254
255   return true;
256
257 }
258