From: isn Date: Tue, 12 Feb 2019 17:59:53 +0000 (+0300) Subject: Lots 4 & 5 X-Git-Tag: SH_V2_2_0~99^2~28^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d994b88802ec196f7cf64705da8e959be7c421fd;p=modules%2Fhydro.git Lots 4 & 5 --- diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index 858a0a6c..ce4bb667 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -153,14 +153,14 @@ void HYDROData_Polyline3D::Update() bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 ); HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 ); - NCollection_Sequence aResPoints = GetProfilePoints3D(); + NCollection_Sequence aResPoints = GetProfilePoints3D(false); TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints ); SetTopShape( aResWire ); SetShape3D( aResWire ); } -HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetProfilePoints3D() +HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetProfilePoints3D(bool IsConvertToGlobal) { Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY(); if ( aPolylineXY.IsNull() ) @@ -213,6 +213,15 @@ HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetProfilePoints3D( // Add last point as is aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) ); + if (IsConvertToGlobal) + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab ); + for (int i=1;i<=aResPoints.Size();i++) + { + gp_XYZ& point = aResPoints.ChangeValue(i); + aDoc->Transform( point, false ); + } + } return aResPoints; } diff --git a/src/HYDROData/HYDROData_Polyline3D.h b/src/HYDROData/HYDROData_Polyline3D.h index 1666a459..3f0c7517 100644 --- a/src/HYDROData/HYDROData_Polyline3D.h +++ b/src/HYDROData/HYDROData_Polyline3D.h @@ -132,7 +132,7 @@ public: */ HYDRODATA_EXPORT virtual void RemoveAltitudeObject(); - HYDRODATA_EXPORT Polyline3DPoints GetProfilePoints3D(); + HYDRODATA_EXPORT Polyline3DPoints GetProfilePoints3D(bool IsConvertToGlobal); /** * Returns the child u,z profile which has been generated from bathymetry. diff --git a/src/HYDROData/HYDROData_ProfileUZ.cxx b/src/HYDROData/HYDROData_ProfileUZ.cxx index 5dccf20c..8ef3dfb6 100644 --- a/src/HYDROData/HYDROData_ProfileUZ.cxx +++ b/src/HYDROData/HYDROData_ProfileUZ.cxx @@ -278,14 +278,19 @@ HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theS return aResList; } -void HYDROData_ProfileUZ::CalculateAndAddPoints(const NCollection_Sequence& theXYZPoints, Handle(HYDROData_PolylineXY)& thePolylineXY) +void HYDROData_ProfileUZ::CalculateAndAddPoints(const NCollection_Sequence& theXYZPoints, + Handle(HYDROData_PolylineXY)& thePolylineXY, + bool fillPolyXY) { // Fill 2D polyline - for ( int i = 1; i <= theXYZPoints.Size(); i++ ) { - const HYDROData_Profile::ProfilePoint& aBottomPoint = theXYZPoints.Value( i ); - thePolylineXY->AddPoint( 0, HYDROData_PolylineXY::Point( aBottomPoint.X(), aBottomPoint.Y() ) ); + if (fillPolyXY) + { + for ( int i = 1; i <= theXYZPoints.Size(); i++ ) { + const HYDROData_Profile::ProfilePoint& aBottomPoint = theXYZPoints.Value( i ); + thePolylineXY->AddPoint( 0, HYDROData_PolylineXY::Point( aBottomPoint.X(), aBottomPoint.Y() ) ); + } } - + // Calculate profile UZ points // First point diff --git a/src/HYDROData/HYDROData_ProfileUZ.h b/src/HYDROData/HYDROData_ProfileUZ.h index 2fcb3899..7e889c6b 100644 --- a/src/HYDROData/HYDROData_ProfileUZ.h +++ b/src/HYDROData/HYDROData_ProfileUZ.h @@ -169,7 +169,7 @@ public: HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1, bool IsConvertToGlobal = false ) const; HYDRODATA_EXPORT virtual void CalculateAndAddPoints(const NCollection_Sequence& theXYZPoints, - Handle(HYDROData_PolylineXY)& thePolylineXY); + Handle(HYDROData_PolylineXY)& thePolylineXY, bool fillPolyXY); protected: diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index fdcb4a59..4d7519ac 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -193,7 +193,7 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(Handle(HYDROData_Document) theDocumen if (thePoly->GetPolylineXY()->GetSectionType(0) == HYDROData_IPolyline::SECTION_SPLINE) return -1; - HYDROData_Polyline3D::Polyline3DPoints aPointList3D = thePoly->GetProfilePoints3D(); + HYDROData_Polyline3D::Polyline3DPoints aPointList3D = thePoly->GetProfilePoints3D(true); for (int j = 1; j <= aPointList3D.Size(); j++) { const gp_XYZ& P = aPointList3D(j); @@ -368,12 +368,12 @@ void HYDROData_ShapeFile::ProcessFace(Handle(HYDROData_Document) theDocument, } -bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile) +bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) { int aShapeType; mySHPObjects.clear(); SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); - theShapeTypeOfFile = aShapeType; + //theShapeTypeOfFile = aShapeType; bool ToRead = (theType == ShapeType_Polyline && (aShapeType == 3 || aShapeType == 13 || aShapeType == 23 || aShapeType == 5)) || (theType == ShapeType_Polygon && aShapeType == 5); @@ -516,7 +516,7 @@ int HYDROData_ShapeFile::ImportPolygons(Handle(HYDROData_Document) theDocument, if (Stat != 0) return Stat; myHSHP = SHPOpen( theFileName.toLatin1().data(), "rb" ); - if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon, theShapeTypeOfFile)) + if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon)) return 0; for (size_t i = 0; i < mySHPObjects.size(); i++) thePolygonsList.append("polygon_" + QString::number(i + 1)); @@ -560,7 +560,6 @@ void HYDROData_ShapeFile::Free() void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, int theInd, NCollection_Sequence& theEntities, bool bReadAsPolyline) { - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); int nParts = anObj->nParts; @@ -609,17 +608,79 @@ void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, aPolylineXY->Update(); theEntities.Append(aPolylineXY); +} + + +void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, + const Handle(HYDROData_PolylineXY)& aPolylineXY, + NCollection_Sequence& theEntities) +{ + Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) ); + Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) ); + + HYDROData_Bathymetry::AltitudePoints aAPoints; + + int nParts = anObj->nParts; + for ( int i = 0 ; i < nParts ; i++ ) + { + //bool aSectClosure = true; + int StartIndex = anObj->panPartStart[i]; + int EndIndex; + if (i != nParts - 1) + EndIndex = anObj->panPartStart[i + 1]; + else + EndIndex = anObj->nVertices; + + HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; + if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && + anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] && + anObj->padfZ[StartIndex] == anObj->padfZ[EndIndex - 1]) + EndIndex--; + for ( int k = StartIndex ; k < EndIndex ; k++ ) + { + gp_XYZ xyz(anObj->padfX[k], anObj->padfY[k], anObj->padfZ[k]); + theDocument->Transform(xyz, true); + HYDROData_Bathymetry::AltitudePoint p; + p.X = xyz.X(); + p.Y = xyz.Y(); + p.Z = xyz.Z(); + aAPoints.push_back(p); + } + } + + QString PolyXYName = aPolylineXY->GetName(); + QString aPoly3DName = PolyXYName, aBathyName = PolyXYName; + aPoly3DName.replace(PolyXYName.lastIndexOf("_PolyXY_"), 8, "_Poly3D_"); + aBathyName.replace(PolyXYName.lastIndexOf("_Bath_"), 6, "_Poly3D_"); + + aBath->SetAltitudePoints(aAPoints); + aBath->SetName( aBathyName ); + + aPolylineObj->SetPolylineXY (aPolylineXY, false); + aPolylineObj->SetAltitudeObject(aBath); + + aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() ); + aPolylineObj->SetName( aPoly3DName ); + + aPolylineObj->Update(); + theEntities.Append(aPolylineObj); } +/* void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities) + int theInd, bool XYOnly, NCollection_Sequence& theEntities) { Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); - Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) ); + Handle(HYDROData_Polyline3D) aPolylineObj; + Handle(HYDROData_Bathymetry) aBath; + if (!XYOnly) + { + Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) ); + Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) ); + } - Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) ); HYDROData_Bathymetry::AltitudePoints aAPoints; int nParts = anObj->nParts; @@ -652,11 +713,14 @@ void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, HYDROData_PolylineXY::Point aSectPoint = gp_XY(anObj->padfX[k], anObj->padfY[k]); theDocument->Transform(aSectPoint, true); aPolylineXY->AddPoint( i, aSectPoint ); - HYDROData_Bathymetry::AltitudePoint p; - p.X = aSectPoint.X(); - p.Y = aSectPoint.Y(); - p.Z = anObj->padfZ[k]; - aAPoints.push_back(p); + if (!XYOnly) + { + HYDROData_Bathymetry::AltitudePoint p; + p.X = aSectPoint.X(); + p.Y = aSectPoint.Y(); + p.Z = anObj->padfZ[k]; + aAPoints.push_back(p); + } } } @@ -668,21 +732,27 @@ void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, aPolylineXY->SetName( aPolyXYName ); aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); aPolylineXY->Update(); - - aBath->SetAltitudePoints(aAPoints); - aBath->SetName( aBathName ); - aPolylineObj->SetPolylineXY (aPolylineXY, false); - aPolylineObj->SetAltitudeObject(aBath); + if (!XYOnly) + { + aBath->SetAltitudePoints(aAPoints); + aBath->SetName( aBathName ); + + aPolylineObj->SetPolylineXY (aPolylineXY, false); + aPolylineObj->SetAltitudeObject(aBath); + + aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() ); + aPolylineObj->SetName( aPoly3DName ); + + aPolylineObj->Update(); + } - aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() ); - aPolylineObj->SetName( aPoly3DName ); - - aPolylineObj->Update(); theEntities.Append(aPolylineXY); - theEntities.Append(aPolylineObj); -} + if (!XYOnly) + theEntities.Append(aPolylineObj); + +}*/ void HYDROData_ShapeFile::GetFreeIndices(std::vector& theAllowedIndexes, QString strName, size_t theObjsSize, QStringList theExistingNames, QString theBaseFileName) @@ -700,14 +770,34 @@ void HYDROData_ShapeFile::GetFreeIndices(std::vector& theAllowedIndexes, QS } } -int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, - NCollection_Sequence& theEntities, int& theShapeTypeOfFile, ImportShapeType theShapeTypesToImport) +int HYDROData_ShapeFile::OpenAndParse(const QString& theFileName) { //Free(); int aStat = TryOpenShapeFile(theFileName); if (aStat != 0) return aStat; + //SHPHandle aHSHP; + myHSHP = SHPOpen( theFileName.toLatin1().data(), "rb" ); + if (myHSHP == NULL) + return -1; + + if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polyline)) + return -1; + + return 1; + //sh_type = aHSHP->nShapeType; +} + +int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, + const QString& theFileName, + NCollection_IndexedDataMap& theEntitiesToSHPObj, + ImportShapeType theShapeTypesToImport) +{ + int aStat = -1; + int sh_type = myHSHP->nShapeType; + QFileInfo aFileInfo(theFileName); + QString aBaseFileName = aFileInfo.baseName(); HYDROData_Iterator anIter( theDocument ); int anInd = 0; QStringList anExistingNames; @@ -715,17 +805,7 @@ int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, for( ; anIter.More(); anIter.Next() ) anExistingNames.push_back(anIter.Current()->GetName()); - SHPHandle aHSHP; - aHSHP = SHPOpen( theFileName.toLatin1().data(), "rb" ); - - QFileInfo aFileInfo(theFileName); - QString aBaseFileName = aFileInfo.baseName(); - - if (!Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline, theShapeTypeOfFile)) - return 0; - - int sh_type = aHSHP->nShapeType; - + NCollection_Sequence Ents; if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All || theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polyline) && (sh_type == 3 || sh_type == 23)) @@ -735,7 +815,9 @@ int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, for (size_t i = 0; i < mySHPObjects.size(); i++ ) { - ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities, false); + ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, false); + for (int k=1;k<=Ents.Size();k++) + theEntitiesToSHPObj.Add(Ents(k), mySHPObjects[i]); } aStat = 1; } @@ -757,7 +839,10 @@ int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, } for (size_t i = 0; i < mySHPObjects.size(); i++ ) { - ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); + //ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], false, theEntities); + ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, false); //TODO check Z coord on closeness + for (int k=1;k<=Ents.Size();k++) + theEntitiesToSHPObj.Add(Ents(k), mySHPObjects[i]); } aStat = 1; } @@ -770,7 +855,9 @@ int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, for (size_t i = 0; i < mySHPObjects.size(); i++ ) { - ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities, true); + ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, true); + for (int k=1;k<=Ents.Size();k++) + theEntitiesToSHPObj.Add(Ents(k), mySHPObjects[i]); } aStat = 2; } @@ -779,14 +866,42 @@ int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, aStat = 0; } - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - free (mySHPObjects[i]); + return aStat; +} - mySHPObjects.clear(); - SHPClose(aHSHP); +int HYDROData_ShapeFile::GetShapeType() const +{ + if (myHSHP != NULL) + return myHSHP->nShapeType; + else + return -1; +} + +int HYDROData_ShapeFile::ImportPolylines3D(Handle(HYDROData_Document) theDocument, + NCollection_IndexedDataMap thePolyXYToObj, + NCollection_Sequence& theEntities, + ImportShapeType theShapeTypesToImport) +{ + int aStat = -1; + int sh_type = myHSHP->nShapeType; + if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All || + theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polyline3D) && sh_type == 13) + { + //for (size_t i = 0; i < mySHPObjects.size(); i++ ) + for (int i = 1; i <= thePolyXYToObj.Extent(); i++ ) + { + Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( thePolyXYToObj.FindKey(i) ); + ReadSHPPoly3D(theDocument, thePolyXYToObj(i), aPolylineXY, theEntities); + } + aStat = 1; + } + else + aStat = 0; + return aStat; } + QString HYDROData_ShapeFile::GetShapeTypeName(int theType) { switch (theType) @@ -910,7 +1025,7 @@ QStringList HYDROData_ShapeFile::DBF_GetFieldList() void HYDROData_ShapeFile::DBF_GetFieldTypeList(std::vector& FTVect) { - int nWidth, nDecimals; + int nWidth, nDecimals; char chField[12]; DBF_FieldType FT; for( int i = 0; i < DBFGetFieldCount(myHDBF); i++ ) diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index b546bd23..586c5c20 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -24,12 +24,11 @@ #include #include - +#include #include #include - //extern "C" { #include //}; @@ -116,7 +115,7 @@ public: int WriteObjectPolygon(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle, const TopoDS_Shape& theInputShape, bool bUseDiscr, double theDefl ); //Import - bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile); + bool Parse(SHPHandle theHandle, ShapeType theType); //Import Landcover void ReadSHPPolygon(Handle(HYDROData_Document) theDocument, SHPObject* anObj, int i, TopoDS_Face& F); @@ -133,15 +132,27 @@ public: int theInd, NCollection_Sequence& theEntities, bool bReadAsPolylin = false); - void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities); + void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, + const Handle(HYDROData_PolylineXY)& aPolylineXY, + NCollection_Sequence& theEntities); HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, - NCollection_Sequence& theEntities, int& theShapeTypeOfFile, + NCollection_IndexedDataMap& theEntitiesToSHPObj, ImportShapeType theShapeTypesToImport); + HYDRODATA_EXPORT int ImportPolylines3D(Handle(HYDROData_Document) theDocument, + NCollection_IndexedDataMap thePolyXYToObj, + NCollection_Sequence& theEntities, + ImportShapeType theShapeTypesToImport); + + HYDRODATA_EXPORT int OpenAndParse(const QString& theFileName); + + HYDRODATA_EXPORT QString GetShapeTypeName(int theType); + HYDRODATA_EXPORT int GetShapeType() const; + + //DBF I/O Methods HYDRODATA_EXPORT bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile); HYDRODATA_EXPORT bool DBF_OpenDBF(const QString& thePathToDBFFile); @@ -168,7 +179,7 @@ private: private: std::vector mySHPObjects; - SHPHandle myHSHP; + SHPHandle myHSHP; DBFHandle myHDBF; friend class test_HYDROData_ShapeFile; diff --git a/src/HYDROData/HYDROData_SinusX.cxx b/src/HYDROData/HYDROData_SinusX.cxx index a18d59eb..4e936852 100644 --- a/src/HYDROData/HYDROData_SinusX.cxx +++ b/src/HYDROData/HYDROData_SinusX.cxx @@ -86,8 +86,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() ) { @@ -103,10 +102,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; @@ -116,104 +111,136 @@ 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 + 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; - size_t n = myCurveBlocks[i].myXYZPoints.size(); - aAPoints.reserve( n ); - for (size_t j = 0; j < n; j++) + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsBathy == true)) { - 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); - } + 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); + aBath->SetAltitudePoints(aAPoints); + aBath->SetName(GetName(myCurveBlocks[i].myName)); + theEntities.Append(aBath); + } } 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++) + if (!importOptions || (importOptions && (*importOptions)[i].ImportAsPolyXY == true)) { - 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 ) ); - 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)); - 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); + 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); + } + + 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); + aPolyXY->SetName(GetName(myCurveBlocks[i].myName)); + aPolyXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); + + for ( int k = 1; k <= aPoints.Size(); k++ ) { + const HYDROData_Profile::ProfilePoint& aBottomPoint = aPoints.Value( k ); + aPolyXY->AddPoint( 0, HYDROData_PolylineXY::Point( aBottomPoint.X(), aBottomPoint.Y() ) ); + } + + theEntities.Append(aPolyXY); + 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) // XYZ profile { - if (myCurveBlocks[i].myCurvePlane == 2) // plane XoZ + 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())); + { + 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->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->SetProfilePoints(aPointList); 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_Profile::ProfilePoints aPointList; - for (size_t j = 0; j < myCurveBlocks[i].myXYZPoints.size(); 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)); - theEntities.Append(aProfile); - } } } @@ -433,3 +460,10 @@ void HYDROData_SinusX::HydroToSX(QFile& theFile, const NCollection_Sequence HYDROData_SinusX::GetCurveBlocks() const +{ + return myCurveBlocks; +} + + diff --git a/src/HYDROData/HYDROData_SinusX.h b/src/HYDROData/HYDROData_SinusX.h index 03899572..564676ad 100644 --- a/src/HYDROData/HYDROData_SinusX.h +++ b/src/HYDROData/HYDROData_SinusX.h @@ -20,6 +20,7 @@ #define HYDRODATA_SINUSX_H #include +#include #include #include #include @@ -47,15 +48,30 @@ struct HYDROGUI_CurveBlock class HYDRODATA_EXPORT HYDROData_SinusX { +public: + struct ImportOptions + { + ImportOptions() : ImportAsBathy(false), ImportAsProfile(false), ImportAsPolyXY(false) + {}; + bool ImportAsBathy; + bool ImportAsProfile; + bool ImportAsPolyXY; + }; public: HYDROData_SinusX( ); virtual ~HYDROData_SinusX(); - bool Import (const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities); + + bool OpenAndParse(const QString& theFilePath); + void Import(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities, + std::vector* importOptions = NULL); + bool Export(const QString& theFilePath, const NCollection_Sequence& theEntities); + std::vector GetCurveBlocks() const; private: - void SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities); + void SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities, + std::vector* importOptions); bool Parse( QFile& theFile ); void CollectExistingNames(Handle(HYDROData_Document) theDocument); QString GetName(const QString& theName); diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 2cf71165..6ecd009f 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -977,7 +977,7 @@ bool HYDROData_Stream::GenerateBottomPolyline() aProfileUZ->RemoveSection( 0 ); - aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY); + aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY, true); return true; } diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 17441f3a..ba89018f 100755 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -161,6 +161,8 @@ set(PROJECT_HEADERS HYDROGUI_MeasurementToolDlg.h HYDROGUI_SIProgressIndicator.h HYDROGUI_ZIProgressIndicator.h + HYDROGUI_ImportPolylineDlg.h + HYDROGUI_ImportSinusXDlg.h ) QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -324,6 +326,8 @@ set(PROJECT_SOURCES HYDROGUI_MeasurementToolDlg.cxx HYDROGUI_SIProgressIndicator.cxx HYDROGUI_ZIProgressIndicator.cxx + HYDROGUI_ImportPolylineDlg.cxx + HYDROGUI_ImportSinusXDlg.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.cxx new file mode 100644 index 00000000..2c80c085 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.cxx @@ -0,0 +1,112 @@ +// 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 +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_ImportPolylineDlg.h" +#include +#include +#include + +HYDROGUI_ImportPolylineDlg::HYDROGUI_ImportPolylineDlg( QWidget* theParent, + const NCollection_Sequence& PolyEnts ) + : QDialog( theParent ) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin(5); + aMainLayout->setSpacing(5); + + QLabel* gLabel = new QLabel(); + gLabel->setText(tr("POLYLINES_3D_IN_FILES")); + + myPolylineTable = new QTableWidget(PolyEnts.Size(), 2); + + myPolyEnts = PolyEnts; + + QStringList header; + header << tr("POLYLINE_NAME") << tr("FULL_IMPORT"); + myPolylineTable->setHorizontalHeaderLabels(header); + myPolylineTable->setShowGrid(true); + + for (int i = 1; i <= myPolyEnts.Size(); i++) + { + QTableWidgetItem* item = new QTableWidgetItem(myPolyEnts(i)->GetName()); + item->setFlags(item->flags() ^ Qt::ItemIsEditable); + myPolylineTable->setItem(i-1, 0, item); + + QTableWidgetItem* itemCheckbox = new QTableWidgetItem(""); + itemCheckbox->setFlags(itemCheckbox->flags() ^ Qt::ItemIsEditable); + itemCheckbox->setCheckState(Qt::Unchecked); + myPolylineTable->setItem(i-1, 1, itemCheckbox); + } + + aMainLayout->addWidget(gLabel); + aMainLayout->addWidget(myPolylineTable); + + QPushButton* CheckAllButton = new QPushButton( tr("CHECK_ALL"), this ); + QPushButton* UncheckAllButton = new QPushButton( tr("UNCHECK_ALL"), this ); + + QPushButton* anOkButton = new QPushButton( tr("OK"), this ); + anOkButton->setDefault( true ); + + aMainLayout->addWidget( CheckAllButton ); + aMainLayout->addWidget( UncheckAllButton ); + aMainLayout->addWidget( anOkButton ); + + connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( CheckAllButton, SIGNAL( clicked() ), this, SLOT( onCheckAll() ) ); + connect( UncheckAllButton, SIGNAL( clicked() ), this, SLOT( onUncheckAll() ) ); + + setLayout(aMainLayout); +} + +HYDROGUI_ImportPolylineDlg::~HYDROGUI_ImportPolylineDlg() +{ +} + +void HYDROGUI_ImportPolylineDlg::onCheckAll() +{ + for (int i = 1; i <= myPolyEnts.Size(); i++) + { + QTableWidgetItem* itemCheckbox = myPolylineTable->item(i-1, 1); + itemCheckbox->setCheckState(Qt::Checked); + } +} + +void HYDROGUI_ImportPolylineDlg::onUncheckAll() +{ + for (int i = 1; i <= myPolyEnts.Size(); i++) + { + QTableWidgetItem* itemCheckbox = myPolylineTable->item(i-1, 1); + itemCheckbox->setCheckState(Qt::Unchecked); + } +} + +NCollection_Sequence HYDROGUI_ImportPolylineDlg::GetCheckedPolylines() const +{ + NCollection_Sequence checkedPolys; + for (int i = 1; i <= myPolyEnts.Size(); i++) + { + QTableWidgetItem* itemCheckbox = myPolylineTable->item(i-1, 1); + if (itemCheckbox->checkState() == Qt::CheckState::Checked) + checkedPolys.Append(myPolyEnts(i)); + } + return checkedPolys; +} + + + + diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.h b/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.h new file mode 100644 index 00000000..f845e17c --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineDlg.h @@ -0,0 +1,50 @@ +// 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 +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + + +#ifndef HYDROGUI_IMPORTPOLYLINEDLG_H +#define HYDROGUI_IMPORTPOLYLINEDLG_H + +#include +#include +#include +#include + +class HYDROGUI_ImportPolylineDlg : public QDialog +{ + Q_OBJECT + +public: + + HYDROGUI_ImportPolylineDlg( QWidget* theParent, const NCollection_Sequence& PolyEnts ); + virtual ~HYDROGUI_ImportPolylineDlg(); + + NCollection_Sequence GetCheckedPolylines() const; + +private slots: + void onCheckAll(); + void onUncheckAll(); + +private: + QTableWidget* myPolylineTable; + NCollection_Sequence myPolyEnts; + +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx index 8889bd5c..e4ffa108 100644 --- a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx @@ -41,7 +41,9 @@ #include #include #include - +#include +#include +#include HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -91,11 +93,22 @@ NCollection_Sequence HYDROGUI_ImportPolylineOp::Import } if (anExt == "shp") { + QApplication::setOverrideCursor( Qt::WaitCursor ); HYDROData_ShapeFile anImporter; - NCollection_Sequence theEntities; + NCollection_IndexedDataMap theEntitiesToSHPObj; + NCollection_Sequence PolyEnt; int aShapeTypeOfFile = -1; - int aStat = anImporter.ImportPolylines(theDocument, aFileName, theEntities, - aShapeTypeOfFile, theShapeTypesToImport ); + int aStat = anImporter.OpenAndParse(aFileName); + QApplication::restoreOverrideCursor(); + if (aStat == 1) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + aStat = anImporter.ImportPolylines(theDocument, aFileName, theEntitiesToSHPObj, theShapeTypesToImport); + QApplication::restoreOverrideCursor(); + for (int k=1;k<=theEntitiesToSHPObj.Extent();k++) + { + PolyEnt.Append(theEntitiesToSHPObj.FindKey(k)); + } if (aStat == 1 || aStat == 2) { //try to import DBF @@ -106,8 +119,8 @@ NCollection_Sequence HYDROGUI_ImportPolylineOp::Import { QStringList aFieldList = anImporter.DBF_GetFieldList(); int nbRecords = anImporter.DBF_GetNbRecords(); - assert (theEntities.Length() == nbRecords); - if (theEntities.Length() == nbRecords) + assert (theEntitiesToSHPObj.Extent() == nbRecords); + if (theEntitiesToSHPObj.Extent() == nbRecords) { int indNameAttrFound = -1; int k = 0; @@ -135,9 +148,9 @@ NCollection_Sequence HYDROGUI_ImportPolylineOp::Import } int indNULL = 1; - for (int i = 1; i <= theEntities.Length(); i++) + for (int i = 1; i <= theEntitiesToSHPObj.Extent(); i++) { - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theEntities(i) ); + Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theEntitiesToSHPObj.FindKey(i) ); QStringList aDBFinfo; aDBFinfo << aFieldList; //first, the table header for (int j = 0; j < aFieldList.size(); j++) @@ -170,11 +183,35 @@ NCollection_Sequence HYDROGUI_ImportPolylineOp::Import } } } + + if (anImporter.GetShapeType() == 13) //Polyline 3D + { + HYDROGUI_ImportPolylineDlg* aDLG = new HYDROGUI_ImportPolylineDlg( module->getApp()->desktop(), PolyEnt ); + aDLG->setModal( true ); + aDLG->setWindowTitle(tr("IMPORT_POLYLINE")); + //QApplication::restoreOverrideCursor(); + if( aDLG->exec()==QDialog::Accepted ) + { + NCollection_Sequence CheckedPolylines = aDLG->GetCheckedPolylines(); + NCollection_IndexedDataMap CheckedEntitiesToSHPObj; + for (int k=1;k<=CheckedPolylines.Size();k++) + { + SHPObject* const* SHPObkP = theEntitiesToSHPObj.Seek(CheckedPolylines(k)); + if (SHPObkP != NULL) + CheckedEntitiesToSHPObj.Add(CheckedPolylines(k), *SHPObkP); + } + NCollection_Sequence theEntitiesPoly3D; + anImporter.ImportPolylines3D(theDocument, CheckedEntitiesToSHPObj, theEntitiesPoly3D, theShapeTypesToImport); + PolyEnt.Append(theEntitiesPoly3D); + } + } + anImporter.Free(); + } if (aStat == 1) - UpdateView(module, theEntities); + UpdateView(module, PolyEnt); else if (aStat == 2) { - UpdateView(module, theEntities); + UpdateView(module, PolyEnt); if (theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All) //if other flag = > no need to show this messagebox SUIT_MessageBox::information(module->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), tr ("POLYGON_IMPORTED_AS_POLYLINE")); @@ -195,7 +232,7 @@ NCollection_Sequence HYDROGUI_ImportPolylineOp::Import aMess += tr ("SHAPE_TYPE_IS") + anImporter.GetShapeTypeName(aShapeTypeOfFile); SUIT_MessageBox::warning( module->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), aMess); } - importedEntities.Append(theEntities); + importedEntities.Append(PolyEnt); } else if ( anExt == "xy" || (importXY && anExt == "xyz")) { @@ -221,7 +258,7 @@ void HYDROGUI_ImportPolylineOp::onApply() QStringList aFileNames = myFileDlg->selectedFiles(); - QApplication::setOverrideCursor( Qt::WaitCursor ); + //QApplication::setOverrideCursor( Qt::WaitCursor ); startDocOperation(); ImportPolyOp(aFileNames, doc(), module(), HYDROData_ShapeFile::ImportShapeType_All); diff --git a/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.cxx new file mode 100644 index 00000000..8957c2de --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.cxx @@ -0,0 +1,164 @@ +// 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 +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_ImportSinusXDlg.h" +#include +#include +#include +#include +#include +#include +#include + +HYDROGUI_ImportSinusXDlg::HYDROGUI_ImportSinusXDlg( QWidget* theParent, const QStringList& theNames, + const std::vector& theTypes ) + : QDialog( theParent ) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin(5); + aMainLayout->setSpacing(5); + this->resize(600, 500); + + QLabel* gLabel = new QLabel(); + gLabel->setText(tr("ENTITIES_TO_IMPORT")); + + assert (theNames.size() == theTypes.size()); + myTable = new QTableWidget(theNames.size(), 5); + + QStringList header; + header << tr("NAME") << tr("TYPE") << tr("AS_BATHY") << tr("AS_POLYXY") << tr("AS_PROFILE"); + myTable->setHorizontalHeaderLabels(header); + + myTable->setShowGrid(true); + myTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + for (int i = 0; i < theNames.size(); i++) + { + QTableWidgetItem* item_name = new QTableWidgetItem(theNames[i]); + item_name->setFlags(item_name->flags() ^ Qt::ItemIsEditable); + myTable->setItem(i, 0, item_name); + + QString TypeName; + if (theTypes[i] == 1) + TypeName = tr("XYZ_CURVE"); + else if (theTypes[i] == 2) + TypeName = tr("XYZ_PROFILE"); + else if (theTypes[i] == 3) + TypeName = tr("ISOCONTOUR"); + else if (theTypes[i] == 4) + TypeName = tr("SCATTER"); + + QTableWidgetItem* item_type = new QTableWidgetItem(TypeName); + item_type->setFlags(item_type->flags() ^ Qt::ItemIsEditable); + myTable->setItem(i, 1, item_type); + + QTableWidgetItem* itemCheckbox1 = new QTableWidgetItem(""); //as bathy + itemCheckbox1->setFlags(itemCheckbox1->flags() ^ Qt::ItemIsEditable); + itemCheckbox1->setCheckState(Qt::Checked); + myTable->setItem(i, 2, itemCheckbox1); + + QTableWidgetItem* itemCheckbox2 = new QTableWidgetItem(""); ; //as polyXY + itemCheckbox2->setFlags(itemCheckbox2->flags() ^ Qt::ItemIsEditable); + itemCheckbox2->setCheckState(Qt::Checked); + myTable->setItem(i, 3, itemCheckbox2); + + QTableWidgetItem* itemCheckbox3 = new QTableWidgetItem(""); ; //as profile + itemCheckbox3->setFlags(itemCheckbox3->flags() ^ Qt::ItemIsEditable); + itemCheckbox3->setCheckState(Qt::Checked); + myTable->setItem(i, 4, itemCheckbox3); + + if (theTypes[i] == 1 || theTypes[i] == 3) ///XYZ curve + { + itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); //disable bathy + itemCheckbox1->setCheckState(Qt::Unchecked); + } + else if (theTypes[i] == 2) + { + itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); + itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); + itemCheckbox1->setCheckState(Qt::Unchecked); + itemCheckbox2->setCheckState(Qt::Unchecked); + } + else if (theTypes[i] == 4) + { + //as bathy only + itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); + itemCheckbox3->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); + itemCheckbox2->setCheckState(Qt::Unchecked); + itemCheckbox3->setCheckState(Qt::Unchecked); + } + } + + aMainLayout->addWidget(gLabel); + aMainLayout->addWidget(myTable); + + //QPushButton* CheckAllButton = new QPushButton( tr("CHECK_ALL"), this ); + //QPushButton* UncheckAllButton = new QPushButton( tr("UNCHECK_ALL"), this ); + + QPushButton* anOkButton = new QPushButton( tr("OK"), this ); + anOkButton->setDefault( true ); + + //aMainLayout->addWidget( CheckAllButton ); + //aMainLayout->addWidget( UncheckAllButton ); + aMainLayout->addWidget( anOkButton ); + + connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + //connect( CheckAllButton, SIGNAL( clicked() ), this, SLOT( onCheckAll() ) ); + //connect( UncheckAllButton, SIGNAL( clicked() ), this, SLOT( onUncheckAll() ) ); + + connect(myTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCheckChecked(int, int))); + + setLayout(aMainLayout); +} + +HYDROGUI_ImportSinusXDlg::~HYDROGUI_ImportSinusXDlg() +{ +} + +void HYDROGUI_ImportSinusXDlg::onCheckChecked(int r, int c) +{ + ///if it's "as POLYLINE" column and now it's unchecked => disable "as PROFILE" checkbox + if (c == 3 && myTable->item(r, 3)->checkState() == Qt::Unchecked) + { + QString text = myTable->item(r, 1)->text(); + if (text == tr("XYZ_CURVE") || text == tr("ISOCONTOUR")) + myTable->item(r, 4)->setCheckState(Qt::Unchecked); + } +} + +std::vector HYDROGUI_ImportSinusXDlg::GetImportOptions() const +{ + std::vector options; + int size = myTable->rowCount(); + for (int i = 0; i < size; i++) + { + HYDROData_SinusX::ImportOptions option; + if (myTable->item(i, 2)->checkState() == Qt::CheckState::Checked) + option.ImportAsBathy = true; + if (myTable->item(i, 3)->checkState() == Qt::CheckState::Checked) + option.ImportAsPolyXY = true; + if (myTable->item(i, 4)->checkState() == Qt::CheckState::Checked) + option.ImportAsProfile = true; + options.push_back(option); + } + return options; +} + + + + diff --git a/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.h b/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.h new file mode 100644 index 00000000..83e89136 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportSinusXDlg.h @@ -0,0 +1,54 @@ +// 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 +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + + +#ifndef HYDROGUI_IMPORTSINUSXDLG_H +#define HYDROGUI_IMPORTSINUSXDLG_H + +#include +#include +#include +#include +#include + +class HYDROGUI_ImportSinusXDlg : public QDialog +{ + Q_OBJECT + +public: + + HYDROGUI_ImportSinusXDlg( QWidget* theParent, const QStringList& theNames, + const std::vector& theTypes); + virtual ~HYDROGUI_ImportSinusXDlg(); + + std::vector GetImportOptions() const; + +private slots: + void onCheckChecked(int r, int c); + + //private slots: +// void onCheckAll(); +// void onUncheckAll(); + +private: + QTableWidget* myTable; + //NCollection_Sequence myPolyEnts; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ImportSinusXOp.cxx b/src/HYDROGUI/HYDROGUI_ImportSinusXOp.cxx index 38b5cf4c..73125df6 100644 --- a/src/HYDROGUI/HYDROGUI_ImportSinusXOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportSinusXOp.cxx @@ -40,6 +40,7 @@ #include #include +#include HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule ) @@ -77,8 +78,7 @@ void HYDROGUI_ImportSinusXOp::onApply() QStringList aFileNames = myFileDlg->selectedFiles(); bool IsImported = false; - - QApplication::setOverrideCursor( Qt::WaitCursor ); + startDocOperation(); foreach (QString aFileName, aFileNames) @@ -92,10 +92,33 @@ void HYDROGUI_ImportSinusXOp::onApply() { HYDROData_SinusX aSinusXImporter; NCollection_Sequence anEntities; - if (aSinusXImporter.Import(aFileName, doc(), anEntities)) + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool ParseStat = aSinusXImporter.OpenAndParse(aFileName); + QApplication::restoreOverrideCursor(); + if (ParseStat) { - UpdateView(anEntities); - IsImported = true; + std::vector aCurveBlocks = aSinusXImporter.GetCurveBlocks(); + QStringList names; + std::vector types; + for (int i=0;igetApp()->desktop(), names, types ); + aDLG->setModal( true ); + aDLG->setWindowTitle(tr("ENTITIES_TO_IMPORT_FROM_SX")); + //QApplication::restoreOverrideCursor(); + if( aDLG->exec()==QDialog::Accepted ) //?? + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + std::vector options = aDLG->GetImportOptions(); + aSinusXImporter.Import(doc(), anEntities, &options); + UpdateView(anEntities); + QApplication::restoreOverrideCursor(); + IsImported = true; + } } } } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 73582eb4..4b0824d9 100755 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2803,6 +2803,11 @@ file cannot be correctly imported for an Obstacle definition. NO_ONE_ENTITY_IMPORTED Entities cant be read + + ENTITIES_TO_IMPORT_FROM_SX + SinusX file entities + + @@ -3800,6 +3805,62 @@ Polyline should consist from one not closed curve. Measurement Tool + + + HYDROGUI_ImportSinusXDlg + + ENTITIES_TO_IMPORT + The file contains the entities listed below. Check the entities which you wish to import and their importing type + + + NAME + Entity name + + + TYPE + Type + + + AS_BATHY + As bathymetry + + + AS_BATHY + As bathymetry + + + AS_POLYXY + As PolylineXY + + + AS_BATHY + As bathymetry + + + AS_PROFILE + As profile + + + XYZ_CURVE + XYZ curve + + + XYZ_PROFILE + XYZ profile + + + ISOCONTOUR + Isocontour + + + SCATTER + Scatter plot + + + OK + Ok + + HYDROGUI_SIProgressIndicator @@ -3853,4 +3914,39 @@ Polyline should consist from one not closed curve. + + + HYDROGUI_ImportPolylineDlg + + POLYLINES_3D_IN_FILES + The shp file contains polyline3D objects (ARCZ). +They have been imported as polylineXY only, +but can be imported with Z part (additional profile and bathymetry). +If checkbox of corresponding polyline in the table below is checked +then it will be imported with Z part, otherwise as PolylineXY only + + + POLYLINE_NAME + Polyline name + + + FULL_IMPORT + Full import + + + CHECK_ALL + Check all + + + UNCHECK_ALL + Uncheck all + + + OK + Ok + + + + +