X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_SinusX.cxx;h=e9e376f49f19c03947baf8df1f06d7708571ad6d;hb=7ab1a585bb3c17efb1cc89fa4c29b20dff44420b;hp=3927c0a348a1d9e2c7b833d1ffc074d5268298b9;hpb=fcf6bb94aa4bb389b1e4b2150d631048ef89e1ad;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_SinusX.cxx b/src/HYDROData/HYDROData_SinusX.cxx index 3927c0a3..e9e376f4 100644 --- a/src/HYDROData/HYDROData_SinusX.cxx +++ b/src/HYDROData/HYDROData_SinusX.cxx @@ -34,6 +34,10 @@ #include #include #include +#include + +//#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" HYDROData_SinusX::HYDROData_SinusX( ) { @@ -43,7 +47,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; @@ -86,7 +90,7 @@ QString HYDROData_SinusX::GetName(const QString& theName) } -bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities) +bool HYDROData_SinusX::OpenAndParse(const QString& theFilePath) { if ( theFilePath.isEmpty() ) { @@ -102,10 +106,6 @@ bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Docum aFile.open(QIODevice::ReadOnly); Parse(aFile); - - CollectExistingNames(theDocument); - SXToHydro(theDocument, theEntities); - aFile.close(); return true; @@ -115,80 +115,147 @@ bool HYDROData_SinusX::Import(const QString& theFilePath, Handle(HYDROData_Docum } -void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities) +void HYDROData_SinusX::Import(Handle(HYDROData_Document) theDocument, + NCollection_Sequence& theEntities, std::vector* importOptions) +{ + CollectExistingNames(theDocument); + SXToHydro(theDocument, theEntities, importOptions); +} + + +void HYDROData_SinusX::SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities, + std::vector* importOptions ) { + if (importOptions && (myCurveBlocks.size() != importOptions->size())) + importOptions = NULL; //incorrect input + + QMap polyMap; + for ( size_t i = 0; i < myCurveBlocks.size(); i++ ) { if (myCurveBlocks[i].myType == 4) /// scatter plot -> to bathy { - 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])); - - aBath->SetAltitudePoints(aAPoints); - aBath->SetName(GetName(myCurveBlocks[i].myName + "_bath")); - theEntities.Append(aBath); + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsBathy == true)) + { + Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) ); + HYDROData_Bathymetry::AltitudePoints aAPoints; + 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)); + 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 aPoints; - for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++) - aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[j])); - /*if (myCurveBlocks[i].myIsClosed) - aPoints.Append(gp_XYZ (myCurveBlocks[i].myXYZPoints[0]));*/ - Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( theDocument->CreateObject( KIND_PROFILEUZ ) ); - Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); - aPolyXY->AddSection( "", - myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE, - myCurveBlocks[i].myIsClosed ? true : false); - 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->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); - theEntities.Append(aPolyXY); - theEntities.Append(aProfileUZ); - theEntities.Append(aProfile); + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsPolyXY == true)) + { + NCollection_Sequence aPoints; + for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++) + { + gp_XYZ aLocalPoint = gp_XYZ (myCurveBlocks[i].myXYZPoints[j]); + theDocument->Transform(aLocalPoint, true); + aPoints.Append(aLocalPoint); + } + + QString polyName = myCurveBlocks[i].myName; + Handle(HYDROData_PolylineXY) aPolyXY; + if (polyMap.contains(polyName)) + aPolyXY = polyMap[polyName]; + else + { + aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); + polyMap[polyName] = aPolyXY; + aPolyXY->SetName(GetName(myCurveBlocks[i].myName)); + aPolyXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); + theEntities.Append(aPolyXY); + } + aPolyXY->AddSection( "", + myCurveBlocks[i].myIsSpline ? HYDROData_PolylineXY::SECTION_SPLINE : HYDROData_PolylineXY::SECTION_POLYLINE, + myCurveBlocks[i].myIsClosed ? true : false); + int numSec = aPolyXY->NbSections() -1; + + for ( int k = 1; k <= aPoints.Size(); k++ ) { + const HYDROData_Profile::ProfilePoint& aBottomPoint = aPoints.Value( k ); + aPolyXY->AddPoint( numSec, HYDROData_PolylineXY::Point( aBottomPoint.X(), aBottomPoint.Y() ) ); + } + + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsProfile == true)) + { + Handle(HYDROData_ProfileUZ) aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( theDocument->CreateObject( KIND_PROFILEUZ ) ); + aProfileUZ->CalculateAndAddPoints(aPoints, aPolyXY, false); + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) ); + aProfile->SetParametricPoints(aProfileUZ->GetPoints()); + + aProfileUZ->SetName(GetName(myCurveBlocks[i].myName)); + aProfile->SetName(GetName(myCurveBlocks[i].myName)); + + theEntities.Append(aProfileUZ); + theEntities.Append(aProfile); + } + } + } - if (myCurveBlocks[i].myType == 2) + if (myCurveBlocks[i].myType == 2) // XYZ profile { - if (myCurveBlocks[i].myCurvePlane == 2) + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsProfile == true)) { - if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4) + if (myCurveBlocks[i].myCurvePlane == 2) // plane XoZ + { + if (myCurveBlocks[i].myAdditionalCurveInfo.size() == 4) + { + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) ); + HYDROData_ProfileUZ::PointsList aPointList; + for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++) + aPointList.Append(gp_XY (myCurveBlocks[i].myXYZPoints[j].X(), myCurveBlocks[i].myXYZPoints[j].Z())); + 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->SetParametricPoints(aPointList); + if ( ! (myCurveBlocks[i].myAdditionalCurveInfo[0] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[1] == 0 && + myCurveBlocks[i].myAdditionalCurveInfo[2] == 0 && myCurveBlocks[i].myAdditionalCurveInfo[3] == 0) ) + { // 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)); + theEntities.Append(aProfile); + } + } + if (myCurveBlocks[i].myCurvePlane == 0) // plane XoY { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( theDocument->CreateObject( KIND_PROFILE ) ); - HYDROData_ProfileUZ::PointsList aPointList; + HYDROData_Profile::ProfilePoints aPointList; for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); j++) - aPointList.Append(gp_XY (myCurveBlocks[i].myXYZPoints[j].X(), myCurveBlocks[i].myXYZPoints[j].Z())); - 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->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])); - aProfile->Update(); + gp_XYZ aLocalPoint = gp_XYZ (myCurveBlocks[i].myXYZPoints[j]); + theDocument->Transform(aLocalPoint, true); + aPointList.Append(aLocalPoint); } - aProfile->SetName(GetName(myCurveBlocks[i].myName + "_profile")); + 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, false); + aProfile->SetName(GetName(myCurveBlocks[i].myName)); theEntities.Append(aProfile); } } - if (myCurveBlocks[i].myCurvePlane == 0) - { - 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]); - 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")); - theEntities.Append(aProfile); - } } } @@ -216,13 +283,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) { @@ -255,7 +322,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; } @@ -302,7 +371,7 @@ bool HYDROData_SinusX::Parse(QFile& theFile) } -bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequence& theEntities) +bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequence& theEntities) { if ( theFilePath.isEmpty() ) { @@ -328,7 +397,7 @@ bool HYDROData_SinusX::Export(const QString& theFilePath, const NCollection_Sequ } -void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence& theEntities) +void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence& theEntities) { QTextStream aTextStream(&theFile); aTextStream << "C Generated by HYDRO Module\n"; @@ -336,7 +405,7 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_SequenceIsKind( STANDARD_TYPE(HYDROData_Bathymetry) )) { Handle(HYDROData_Bathymetry) aBathy = Handle(HYDROData_Bathymetry)::DownCast( anEnt ); @@ -346,10 +415,10 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_SequenceGetName() << "\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"; + 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) )) { @@ -405,4 +474,11 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence HYDROData_SinusX::GetCurveBlocks() const +{ + return myCurveBlocks; +} + +