#include <HYDROData_Bathymetry.h>
#include <HYDROData_LandCover.h>
#include <HYDROData_Profile.h>
+#include <HYDROData_Iterator.h>
#include <QFile>
#include <QFileInfo>
#include <BRepLib.hxx>
#include <ShapeFix_Shape.hxx>
#include <TopTools_SequenceOfShape.hxx>
+#include <QColor>
+
HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL)
{
return;
}
-void HYDROData_ShapeFile::Parse(SHPHandle theHandle)
+void HYDROData_ShapeFile::Parse1(SHPHandle theHandle)
{
int aShapeType;
mySHPObjects.clear();
{
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));
SHPClose(myHSHP);
myHSHP = NULL;
}
+}
+
+
+void HYDROData_ShapeFile::ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+ int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& 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<Handle_HYDROData_Entity>& 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<Handle_HYDROData_Entity>& theEntities)
+{
+ HYDROData_Iterator anIter( theDocument );
+ int anInd = 0;
+ QStringList anExistingNames;
+ std::vector<int> 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
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
{
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<Handle_HYDROData_Entity>& theEntities);
+ void ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+ int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+ HYDRODATA_EXPORT bool ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName,
+ NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
private:
void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
private:
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Bathymetry.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_ShapeFile.h>
#include <HYDROData_Profile.h>
if (anExt == "shp")
{
- SHPHandle aHSHP;
- aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
- Parse(aHSHP);
-
- HYDROData_Iterator anIter( doc() );
- int anInd = 0;
- QStringList anExistingNames;
- std::vector<int> 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<Handle_HYDROData_Entity> 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())
QApplication::restoreOverrideCursor();
}
-void HYDROGUI_ImportPolylineOp::ProcessSHPPolyXY(SHPObject* anObj, QString theFileName, int theInd)
+void HYDROGUI_ImportPolylineOp::UpdateView( NCollection_Sequence<Handle_HYDROData_Entity>& 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
#include "HYDROGUI_Operation.h"
#include <vector>
-//extern "C" {
-#include <shapefil.h>
-//};
+#include <NCollection_Sequence.hxx>
class SUIT_FileDlg;
+class Handle_HYDROData_Entity;
class HYDROGUI_ImportPolylineOp : public HYDROGUI_Operation
{
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<Handle_HYDROData_Entity>& anEntities);
+
private:
SUIT_FileDlg* myFileDlg;
- std::vector<SHPObject*> mySHPObjects;
};
#endif