From: isn Date: Mon, 29 Jun 2015 08:51:28 +0000 (+0300) Subject: Import/Export // API revision. p2 X-Git-Tag: v1.4.2~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1b1584e859342a3e5759a77575f099369d54fd95;p=modules%2Fhydro.git Import/Export // API revision. p2 --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 5dfc724a..42b452b7 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,8 @@ #include #include #include +#include + HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL) { @@ -258,7 +261,7 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl return; } -void HYDROData_ShapeFile::Parse(SHPHandle theHandle) +void HYDROData_ShapeFile::Parse1(SHPHandle theHandle) { int aShapeType; mySHPObjects.clear(); @@ -323,7 +326,7 @@ bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringLis { Free(); myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" ); - Parse(myHSHP); + Parse1(myHSHP); for (int i = 0; i < mySHPObjects.size(); i++) thePolygonsList.append("polygon_" + QString::number(i + 1)); @@ -352,4 +355,202 @@ void HYDROData_ShapeFile::Free() SHPClose(myHSHP); myHSHP = NULL; } +} + + +void HYDROData_ShapeFile::ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + int theInd, NCollection_Sequence& theEntities) +{ + + Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); + + int nParts = anObj->nParts; + for ( int i = 0 ; i < nParts ; i++ ) + { + int StartIndex = anObj->panPartStart[i]; + int EndIndex; + if (i != nParts - 1) + EndIndex = anObj->panPartStart[i + 1]; + else + EndIndex = anObj->nVertices; + + bool IsClosed = false; + HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; + if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && + anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] ) + { + IsClosed = true; + aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true); + } + else + aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false); + + if (IsClosed) + EndIndex--; + for ( int k = StartIndex; k < EndIndex ; k++ ) + { + HYDROData_PolylineXY::Point aSectPoint; + aSectPoint.SetX( anObj->padfX[k] ); + aSectPoint.SetY( anObj->padfY[k] ); + aPolylineXY->AddPoint( i, aSectPoint ); + } + + } + + aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); + aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) ); + + aPolylineXY->Update(); + theEntities.Append(aPolylineXY); + +} + +void HYDROData_ShapeFile::ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + int theInd, 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_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; + + bool IsClosed = false; + 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]) + { + IsClosed = true; + aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true ); + } + else + aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false ); + + if (IsClosed) + EndIndex--; + for ( int k = StartIndex ; k < EndIndex ; k++ ) + { + HYDROData_PolylineXY::Point aSectPoint; + aSectPoint.SetX( anObj->padfX[k] ); + aSectPoint.SetY( anObj->padfY[k] ); + aPolylineXY->AddPoint( i, aSectPoint ); + aAPoints.Append(gp_XYZ (anObj->padfX[k], anObj->padfY[k], anObj->padfZ[k])); + } + } + + + QString aBathName = theFileName + "_bath_" + QString::number(theInd); + QString aPolyXYName = theFileName + "_polyXY_" + QString::number(theInd); + QString aPoly3DName = theFileName + "_poly3D_" + QString::number(theInd); + + aPolylineXY->SetName( aPolyXYName ); + aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); + aPolylineXY->Update(); + + aBath->SetAltitudePoints(aAPoints); + aBath->SetName( aBathName ); + + aPolylineObj->SetPolylineXY (aPolylineXY, false); + aPolylineObj->SetAltitudeObject(aBath); + + aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() ); + aPolylineObj->SetName( aPoly3DName ); + + aPolylineObj->Update(); + theEntities.Append(aPolylineXY); + theEntities.Append(aPolylineObj); + +} + +void HYDROData_ShapeFile::Parse2(SHPHandle theHandle) +{ + int aShapeType; + mySHPObjects.clear(); + SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); + if (aShapeType == 3 || aShapeType == 13 || aShapeType == 23) + { + for (int i = 0; i < theHandle->nRecords; i++) + mySHPObjects.push_back(SHPReadObject(theHandle, i)); + } +} + +bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence& theEntities) +{ + HYDROData_Iterator anIter( theDocument ); + int anInd = 0; + QStringList anExistingNames; + std::vector anAllowedIndexes; + for( ; anIter.More(); anIter.Next() ) + anExistingNames.push_back(anIter.Current()->GetName()); + + SHPHandle aHSHP; + aHSHP = SHPOpen( theFileName.toAscii().data(), "rb" ); + + QFileInfo aFileInfo(theFileName); + QString aBaseFileName = aFileInfo.baseName(); + + Parse2(aHSHP); + bool aStat = false; + if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) + { + anInd = 0; + for (;anAllowedIndexes.size() < mySHPObjects.size();) + { + if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd))) + { + anAllowedIndexes.push_back(anInd); + anInd++; + } + else + anInd++; + } + + for (size_t i = 0; i < mySHPObjects.size(); i++ ) + { + ProcessSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); + } + aStat = true; + } + else if (aHSHP->nShapeType == 13) + { + anInd = 0; + for (;anAllowedIndexes.size() < mySHPObjects.size();) + { + if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) && + !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) && + !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd))) + { + anAllowedIndexes.push_back(anInd); + anInd++; + } + else + anInd++; + } + for (size_t i = 0; i < mySHPObjects.size(); i++ ) + ProcessSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); + aStat = true; + } + else + { + aStat = false; + } + + for (size_t i = 0; i < mySHPObjects.size(); i++ ) + free (mySHPObjects[i]); + + mySHPObjects.clear(); + SHPClose(aHSHP); + return aStat; } \ No newline at end of file diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index 3fef48ff..1dc0922b 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -36,8 +36,10 @@ class gp_XYZ; class Handle_HYDROData_PolylineXY; class Handle_HYDROData_Polyline3D; class Handle_HYDROData_LandCover; +class Handle(HYDROData_Document); class TopTools_SequenceOfShape; class TopoDS_Face; +class Handle_HYDROData_Entity; class HYDROData_ShapeFile { @@ -57,11 +59,18 @@ public: int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ); int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC ); //Import Landcover - void Parse(SHPHandle theHandle); + void Parse1(SHPHandle theHandle); void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F); HYDRODATA_EXPORT bool ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces); HYDRODATA_EXPORT void Free(); - /// + //Import Polyline + void Parse2( SHPHandle theHandle); + void ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + int theInd, NCollection_Sequence& theEntities); + void ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + int theInd, NCollection_Sequence& theEntities); + HYDRODATA_EXPORT bool ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, + NCollection_Sequence& theEntities); private: void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle); private: diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx index a3c7f833..7ebba03d 100644 --- a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -91,67 +92,12 @@ void HYDROGUI_ImportPolylineOp::onApply() if (anExt == "shp") { - SHPHandle aHSHP; - aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" ); - Parse(aHSHP); - - HYDROData_Iterator anIter( doc() ); - int anInd = 0; - QStringList anExistingNames; - std::vector anAllowedIndexes; - for( ; anIter.More(); anIter.Next() ) - anExistingNames.push_back(anIter.Current()->GetName()); - - QFileInfo aFileInfo(aFileName); - QString aBaseFileName = aFileInfo.baseName(); - - if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) - { - anInd = 0; - for (;anAllowedIndexes.size() < mySHPObjects.size();) - { - if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd))) - { - anAllowedIndexes.push_back(anInd); - anInd++; - } - else - anInd++; - } - - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - { - ProcessSHPPolyXY(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]); - } - } - else if (aHSHP->nShapeType == 13) - { - anInd = 0; - for (;anAllowedIndexes.size() < mySHPObjects.size();) - { - if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) && - !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) && - !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd))) - { - anAllowedIndexes.push_back(anInd); - anInd++; - } - else - anInd++; - } - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - ProcessSHPPoly3D(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]); - } - else - { + HYDROData_ShapeFile anImporter; + NCollection_Sequence theEntities; + if (anImporter.ImportPolylines(doc(), aFileName, theEntities )) + UpdateView(theEntities); + else SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), "Cannot import polyline;\nThe shape type is incorrect" ); - } - - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - free (mySHPObjects[i]); - - mySHPObjects.clear(); - SHPClose(aHSHP); } } if (!aFileNames.empty()) @@ -166,141 +112,16 @@ void HYDROGUI_ImportPolylineOp::onApply() QApplication::restoreOverrideCursor(); } -void HYDROGUI_ImportPolylineOp::ProcessSHPPolyXY(SHPObject* anObj, QString theFileName, int theInd) +void HYDROGUI_ImportPolylineOp::UpdateView( NCollection_Sequence& anEntities) { - //if (anObj->nSHPType != SHPT_ARC && anObj->nSHPType != SHPT_ARCM) - // return false; - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); - - int nParts = anObj->nParts; - for ( int i = 0 ; i < nParts ; i++ ) - { - int StartIndex = anObj->panPartStart[i]; - int EndIndex; - if (i != nParts - 1) - EndIndex = anObj->panPartStart[i + 1]; - else - EndIndex = anObj->nVertices; - - bool IsClosed = false; - HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; - if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && - anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] ) - { - IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true); - } - else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false); - - if (IsClosed) - EndIndex--; - for ( int k = StartIndex; k < EndIndex ; k++ ) - { - HYDROData_PolylineXY::Point aSectPoint; - aSectPoint.SetX( anObj->padfX[k] ); - aSectPoint.SetY( anObj->padfY[k] ); - aPolylineXY->AddPoint( i, aSectPoint ); - } - - } - - aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); - aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) ); - - aPolylineXY->Update(); - size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); if ( anActiveViewId == 0 ) anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); - - module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); - - module()->setIsToUpdate( aPolylineXY ); -} - -void HYDROGUI_ImportPolylineOp::ProcessSHPPoly3D(SHPObject* anObj, QString theFileName, int theInd) -{ - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); - - Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) ); - - Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) ); - HYDROData_Bathymetry::AltitudePoints aAPoints; - int nParts = anObj->nParts; - for ( int i = 0 ; i < nParts ; i++ ) + for (int i = 1; i <= anEntities.Size() ; i++) { - //bool aSectClosure = true; - int StartIndex = anObj->panPartStart[i]; - int EndIndex; - if (i != nParts - 1) - EndIndex = anObj->panPartStart[i + 1]; - else - EndIndex = anObj->nVertices; - - bool IsClosed = false; - 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]) - { - IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true ); - } - else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false ); - - if (IsClosed) - EndIndex--; - for ( int k = StartIndex ; k < EndIndex ; k++ ) - { - HYDROData_PolylineXY::Point aSectPoint; - aSectPoint.SetX( anObj->padfX[k] ); - aSectPoint.SetY( anObj->padfY[k] ); - aPolylineXY->AddPoint( i, aSectPoint ); - aAPoints.Append(gp_XYZ (anObj->padfX[k], anObj->padfY[k], anObj->padfZ[k])); - } + anEntities(i)->Update(); + module()->setObjectVisible( anActiveViewId, anEntities(i), true ); + module()->setIsToUpdate( anEntities(i) ); } - - - QString aBathName = theFileName + "_bath_" + QString::number(theInd); - QString aPolyXYName = theFileName + "_polyXY_" + QString::number(theInd); - QString aPoly3DName = theFileName + "_poly3D_" + QString::number(theInd); - - aPolylineXY->SetName( aPolyXYName ); - aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); - aPolylineXY->Update(); - - aBath->SetAltitudePoints(aAPoints); - aBath->SetName( aBathName ); - - aPolylineObj->SetPolylineXY (aPolylineXY, false); - aPolylineObj->SetAltitudeObject(aBath); - - aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() ); - aPolylineObj->SetName( aPoly3DName ); - - aPolylineObj->Update(); - - size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); - if ( anActiveViewId == 0 ) - anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); - - module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); - module()->setObjectVisible( anActiveViewId, aPolylineObj, true ); - - module()->setIsToUpdate( aPolylineObj ); } - -void HYDROGUI_ImportPolylineOp::Parse(SHPHandle theHandle) -{ - int aShapeType; - mySHPObjects.clear(); - SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); - if (aShapeType == 3 || aShapeType == 13 || aShapeType == 23) - { - for (int i = 0; i < theHandle->nRecords; i++) - mySHPObjects.push_back(SHPReadObject(theHandle, i)); - } -} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h index 203b8c8f..01ea70a7 100644 --- a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.h @@ -26,11 +26,10 @@ #include "HYDROGUI_Operation.h" #include -//extern "C" { -#include -//}; +#include class SUIT_FileDlg; +class Handle_HYDROData_Entity; class HYDROGUI_ImportPolylineOp : public HYDROGUI_Operation { @@ -43,12 +42,10 @@ public: protected: virtual void startOperation(); virtual void onApply(); - void Parse( SHPHandle theHandle); - void ProcessSHPPolyXY(SHPObject* anObj, QString theFileName, int theInd); - void ProcessSHPPoly3D(SHPObject* anObj, QString theFileName, int theInd); + void UpdateView( NCollection_Sequence& anEntities); + private: SUIT_FileDlg* myFileDlg; - std::vector mySHPObjects; }; #endif