Salome HOME
comp.errors on linux
[modules/hydro.git] / src / HYDROData / HYDROData_SinusX.cxx
index 86a5b1518e092ef95e35b6753b4cd1037093f376..a18d59eb6e8617732fca8a2eee0705c20a079185 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -37,6 +33,7 @@
 #include <QString>
 #include <QStringList>
 #include <QTextStream>
+#include <QColor>
 
 HYDROData_SinusX::HYDROData_SinusX( ) 
 {
@@ -46,7 +43,7 @@ HYDROData_SinusX::~HYDROData_SinusX()
 {
 }
 
-void HYDROData_SinusX::CollectExistingNames(Handle_HYDROData_Document theDocument)
+void HYDROData_SinusX::CollectExistingNames(Handle(HYDROData_Document) theDocument)
 {
   HYDROData_Iterator anIter( theDocument );
   int anInd = 0;
@@ -89,7 +86,8 @@ QString HYDROData_SinusX::GetName(const QString& theName)
 }
 
 
-bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Document) theDocument,
+  NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
 {
   if ( theFilePath.isEmpty() )
   { 
@@ -118,7 +116,7 @@ bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Docum
 
 }
 
-void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
 { 
   for ( size_t i = 0; i < myCurveBlocks.size(); i++ )
   {
@@ -126,18 +124,32 @@ void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollec
     {
       Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
       HYDROData_Bathymetry::AltitudePoints aAPoints;
-      for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
-        aAPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
+      size_t n = myCurveBlocks[i].myXYZPoints.size();
+      aAPoints.reserve( n );
+      for (size_t j = 0; j < n; j++)
+      {
+        gp_XYZ aLocalPoint = gp_XYZ (myCurveBlocks[i].myXYZPoints[j]);
+        theDocument->Transform(aLocalPoint, true);
+        HYDROData_Bathymetry::AltitudePoint p;
+        p.X = aLocalPoint.X();
+        p.Y = aLocalPoint.Y();
+        p.Z = aLocalPoint.Z();
+        aAPoints.push_back(p);
+      }
 
       aBath->SetAltitudePoints(aAPoints);
-      aBath->SetName(GetName(myCurveBlocks[i].myName + "_bath"));
+      aBath->SetName(GetName(myCurveBlocks[i].myName));
       theEntities.Append(aBath);
     }
-    if (myCurveBlocks[i].myType == 1 || myCurveBlocks[i].myType == 3)
+    if (myCurveBlocks[i].myType == 1 || myCurveBlocks[i].myType == 3) // XYZ curve or isocontour
     {
       NCollection_Sequence<gp_XYZ> aPoints;
       for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
-        aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j]));
+      {
+        gp_XYZ aLocalPoint = gp_XYZ (myCurveBlocks[i].myXYZPoints[j]);
+        theDocument->Transform(aLocalPoint, true);
+        aPoints.Append(aLocalPoint);
+      }
       /*if (myCurveBlocks[i].myIsClosed)
         aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[0]));*/
       Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( theDocument->CreateObject( KIND_PROFILEUZ ) );
@@ -148,16 +160,17 @@ void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollec
       aProfileUZ->CalculateAndAddPoints(aPoints, aPolyXY);
       Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
       aProfile->SetParametricPoints(aProfileUZ->GetPoints());
-      aPolyXY->SetName(GetName(myCurveBlocks[i].myName + "_polyXY"));
-      aProfileUZ->SetName(GetName(myCurveBlocks[i].myName + "_profileUZ"));
-      aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
+      aPolyXY->SetName(GetName(myCurveBlocks[i].myName));
+      aProfileUZ->SetName(GetName(myCurveBlocks[i].myName));
+      aProfile->SetName(GetName(myCurveBlocks[i].myName));
+      aPolyXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
       theEntities.Append(aPolyXY);
       theEntities.Append(aProfileUZ);
       theEntities.Append(aProfile);
     }
-    if (myCurveBlocks[i].myType == 2)
+    if (myCurveBlocks[i].myType == 2) // XYZ profile
     {
-      if (myCurveBlocks[i].myCurvePlane == 2)
+      if (myCurveBlocks[i].myCurvePlane == 2) // plane XoZ
       {
         if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4)
         {
@@ -170,25 +183,35 @@ void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollec
           aProfile->SetParametricPoints(aPointList);
           if ( ! (myCurveBlocks[i].myAdditionalCurveInfo[0] == 0 &&  myCurveBlocks[i].myAdditionalCurveInfo[1] == 0 && 
             myCurveBlocks[i].myAdditionalCurveInfo[2] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[3] == 0) )
-          {
-            aProfile->SetLeftPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[0], myCurveBlocks[i].myAdditionalCurveInfo[1]));
-            aProfile->SetRightPoint(gp_XY(myCurveBlocks[i].myAdditionalCurveInfo[2], myCurveBlocks[i].myAdditionalCurveInfo[3]));
+          { // georeferenced profile
+            double xl = myCurveBlocks[i].myAdditionalCurveInfo[0];
+            double yl = myCurveBlocks[i].myAdditionalCurveInfo[1];
+            double xr = myCurveBlocks[i].myAdditionalCurveInfo[2];
+            double yr = myCurveBlocks[i].myAdditionalCurveInfo[3];
+            theDocument->Transform(xl, yl , true);
+            theDocument->Transform(xr, yr , true);
+            aProfile->SetLeftPoint(gp_XY(xl, yl));
+            aProfile->SetRightPoint(gp_XY(xr, yr));
             aProfile->Update();
           }
-          aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
+          aProfile->SetName(GetName(myCurveBlocks[i].myName));
           theEntities.Append(aProfile);
         }
       }
-      if (myCurveBlocks[i].myCurvePlane == 0)
+      if (myCurveBlocks[i].myCurvePlane == 0) // plane XoY
       {
         Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) );
         HYDROData_Profile::ProfilePoints aPointList;
         for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++)
-          aPointList.Append(myCurveBlocks[i].myXYZPoints[j]);
+        {
+          gp_XYZ aLocalPoint = gp_XYZ (myCurveBlocks[i].myXYZPoints[j]);
+          theDocument->Transform(aLocalPoint, true);
+          aPointList.Append(aLocalPoint);
+        }
         aProfile->GetProfileUZ()->SetSectionType(0,  myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE);
         aProfile->GetProfileUZ()->SetSectionClosed(0, myCurveBlocks[i].myIsClosed ? true : false);
         aProfile->SetProfilePoints(aPointList);
-        aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile"));
+        aProfile->SetName(GetName(myCurveBlocks[i].myName));
         theEntities.Append(aProfile);
       }
     }
@@ -218,13 +241,13 @@ bool HYDROData_SinusX::Parse(QFile& theFile)
     {  
       HYDROGUI_CurveBlock aCurveBlockInfo;
       if (aList[1] == "C")
-        aCurveBlockInfo.myType = 1;
+        aCurveBlockInfo.myType = 1; // XYZ curve
       else if (aList[1] == "P")
-        aCurveBlockInfo.myType = 2;
+        aCurveBlockInfo.myType = 2; // XYZ profile
       else if (aList[1] == "N")
-        aCurveBlockInfo.myType = 3;
+        aCurveBlockInfo.myType = 3; // isocontour
       else if (aList[1] == "S")
-        aCurveBlockInfo.myType = 4;
+        aCurveBlockInfo.myType = 4; // Scatter plot
 
       if (aList.size() == 9)
       {
@@ -257,7 +280,9 @@ bool HYDROData_SinusX::Parse(QFile& theFile)
         if (aBList[0] == "CN")
         {
            for (int i = 1; i < aBList.size(); i++)
-             Name += aBList[i] + "_"; 
+             Name += aBList[i] + "_";
+           if (Name.size() <= 1)
+             Name = "noname_";
            Name.remove(Name.size() - 1, 1);
            aCurveBlockInfo.myName = Name;
         }
@@ -304,7 +329,7 @@ bool HYDROData_SinusX::Parse(QFile& theFile)
 
 }
 
-bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
 {
   if ( theFilePath.isEmpty() )
   { 
@@ -330,7 +355,7 @@ bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequ
 
 }
 
-void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
 {
   QTextStream aTextStream(&theFile);
   aTextStream << "C  Generated by HYDRO Module\n";
@@ -338,20 +363,20 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence<Hand
 
   for (int i = 1; i <= theEntities.Size(); i++)
   {
-    Handle_HYDROData_Entity anEnt = theEntities.Value(i);
+    Handle(HYDROData_Entity) anEnt = theEntities.Value(i);
     if (anEnt->IsKind( STANDARD_TYPE(HYDROData_Bathymetry) ))
     {
-       Handle(HYDROData_Bathymetry) aBathy = Handle(HYDROData_Bathymetry)::DownCast( anEnt );
-       HYDROData_Bathymetry::AltitudePoints anXYZPoints = aBathy->GetAltitudePoints();
-       //Write to stream
-       aTextStream << "B S\n";
-       aTextStream << "CN " << aBathy->GetName() << "\n";
-       aTextStream << "CP 0 0\n";
-       aTextStream << "CP 0\n";
-       for (int j = anXYZPoints.Lower(); j <= anXYZPoints.Upper(); j++)
-         aTextStream << " " << QString::number(anXYZPoints(j).X(), 'f', 3)  
-                     << " " << QString::number(anXYZPoints(j).Y(), 'f', 3)  
-                     << " " << QString::number(anXYZPoints(j).Z(), 'f', 3) << "\n"; 
+      Handle(HYDROData_Bathymetry) aBathy = Handle(HYDROData_Bathymetry)::DownCast( anEnt );
+      HYDROData_Bathymetry::AltitudePoints anXYZPoints = aBathy->GetAltitudePoints(true);
+      //Write to stream
+      aTextStream << "B S\n";
+      aTextStream << "CN " << aBathy->GetName() << "\n";
+      aTextStream << "CP 0 0\n";
+      aTextStream << "CP 0\n";
+      for (size_t j = 0, m = anXYZPoints.size(); j < m; j++)
+        aTextStream << " " << QString::number(anXYZPoints[j].X, 'f', 3)  
+                    << " " << QString::number(anXYZPoints[j].Y, 'f', 3)  
+                    << " " << QString::number(anXYZPoints[j].Z, 'f', 3) << "\n"; 
     }
     else if (anEnt->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ))
     {
@@ -363,7 +388,7 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence<Hand
         bool IsSpline = false;
         if (aPolyXY->GetSectionType(j) == HYDROData_PolylineXY::SECTION_SPLINE)
           IsSpline = true;
-        HYDROData_PolylineXY::PointsList anXYPoints = aPolyXY->GetPoints(j);
+        HYDROData_PolylineXY::PointsList anXYPoints = aPolyXY->GetPoints(j, true);
         //Write to stream
         aTextStream << "B N\n";
         aTextStream << "CN " << aPolyXY->GetName() << "\n";
@@ -407,4 +432,4 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence<Hand
                      << QString::number(aPointList(k).Y(), 'f', 3) << "\n";  
     }
   }
-}
\ No newline at end of file
+}