#pragma warning( disable: 4996 )
#endif
-//SHP->TFaces (Import)
+//SHP->TFaces (Import)
#define OSD_TIMER
HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL)
-{
+{
}
HYDROData_ShapeFile::~HYDROData_ShapeFile()
SHPHandle hSHPHandle;
if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
{
- hSHPHandle = SHPCreate( aFileName.toLatin1().data(), SHPT_ARC );
+ hSHPHandle = SHPCreate( aFileName.toLatin1().data(), SHPT_ARC );
for (int i = 1; i <= aPolyXYSeq.Size(); i++)
if (WriteObjectPolyXY(theDocument, hSHPHandle, aPolyXYSeq(i)) != 1)
aNonExpList.append(aPolyXYSeq(i)->GetName());
SHPObject *aSHPObj;
std::vector<double> x, y;
std::vector<int> anPartStart;
-
- for (int i = 0; i < thePoly->NbSections(); i++)
+
+ for (int i = 0; i < thePoly->NbSections(); i++)
if (thePoly->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
return -1;
y.push_back( P.Y());
}
}
-
+
aSHPObj = SHPCreateObject (SHPT_ARC, -1, thePoly->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
SHPWriteObject( theShpHandle, -1, aSHPObj );
SHPDestroyObject( aSHPObj );
anPartStart.push_back(0); //one section only
if (thePoly->GetPolylineXY()->GetSectionType(0) == HYDROData_IPolyline::SECTION_SPLINE)
- return -1;
+ return -1;
HYDROData_Polyline3D::Polyline3DPoints aPointList3D = thePoly->GetProfilePoints3D(true);
for (int j = 1; j <= aPointList3D.Size(); j++)
else if (theInputShape.ShapeType() == TopAbs_COMPOUND)
{
TopExp_Explorer Ex(theInputShape, TopAbs_FACE);
- for (; Ex.More(); Ex.Next())
+ for (; Ex.More(); Ex.Next())
{
- TopoDS_Face aF = TopoDS::Face(Ex.Current());
+ TopoDS_Face aF = TopoDS::Face(Ex.Current());
if (aF.IsNull())
continue;
ProcessFace(theDocument, aF, theShpHandle, bUseDiscr, theDefl);
return 0;
return 1;
-
+
}
void HYDROData_ShapeFile::ProcessFace(Handle(HYDROData_Document) theDocument,
NCollection_Sequence<TopoDS_Wire> aWires;
//write an outer wire first
- aWires.Append(OuterW);
- TopExp_Explorer Ex(theFace, TopAbs_WIRE);
- for (; Ex.More(); Ex.Next())
+ aWires.Append(OuterW);
+ TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ for (; Ex.More(); Ex.Next())
{
TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
if (aW.IsEqual(OuterW))
continue;
- aWires.Append(aW);
+ aWires.Append(aW);
}
int NbWires = 0;
- for (int k = 1; k <= aWires.Length(); k++)
+ for (int k = 1; k <= aWires.Length(); k++)
{
- TopoDS_Wire aW = aWires(k);
+ TopoDS_Wire aW = aWires(k);
if (aW.IsNull())
continue;
NbWires++;
if (aW.Orientation() == TopAbs_INTERNAL)
//cant write internal wires/edges
- continue;
+ continue;
// Try to reorder edges
Handle(ShapeFix_Wire) aSFW = new ShapeFix_Wire( aW, theFace, Precision::Confusion() );
aSFW->ModifyTopologyMode() = Standard_False;
aNPnts.Append(aPnts.First());
for (int j = 1; j <= aPnts.Size() - 1; j++)
{
- if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion()))
+ if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion()))
aNPnts.Append(aPnts(j + 1));
}
//External wire will be written in clockwise direction
//any other wires (holes) - in anticlockwise direction
for (int j = aNPnts.Size(); j >= 1; j--)
- {
+ {
gp_XY P = gp_XY(aNPnts(j).X(), aNPnts(j).Y());
theDocument->Transform(P, false);
x.push_back( P.X());
y.push_back( P.Y());
}
-
+
aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
SHPWriteObject( theShpHandle, -1, aSHPObj );
SHPDestroyObject( aSHPObj );
mySHPObjects.clear();
SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
//theShapeTypeOfFile = aShapeType;
- bool ToRead = (theType == ShapeType_Polyline &&
+ bool ToRead = (theType == ShapeType_Polyline &&
(aShapeType == 3 || aShapeType == 13 || aShapeType == 23 || aShapeType == 5)) ||
(theType == ShapeType_Polygon && aShapeType == 5);
- if (ToRead)
+ if (ToRead)
{
- for (int i = 0; i < theHandle->nRecords; i++)
+ for (int i = 0; i < theHandle->nRecords; i++)
mySHPObjects.push_back(SHPReadObject(theHandle, i));
return true;
}
{
if (!anObj)
return;
- TopoDS_Edge E;
+ TopoDS_Edge E;
int nParts = anObj->nParts;
Handle(Geom_Plane) aPlaneSur = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
TopTools_SequenceOfShape aWires;
for ( int i = 0 ; i < nParts ; i++ )
- {
+ {
BRepBuilderAPI_MakeWire aBuilder;
int StartIndex = anObj->panPartStart[i];
int EndIndex;
TopoDS_Wire W;
BB.MakeWire(W);
- //First point is same as the last point
+ //First point is same as the last point
int NbPnts = EndIndex - StartIndex - 1;
NCollection_Array1<TopoDS_Vertex> VPoints(0, NbPnts);
int j = NbPnts;
VPoints.ChangeValue(j) = BRepLib_MakeVertex(P).Vertex();
j--;
}
-
+
for ( int k = 0; k < VPoints.Size() - 1; k++ )
{
gp_Pnt P1 = BRep_Tool::Pnt(VPoints(k));
Standard_Real jXmax, jXmin, jYmax, jYmin;
BBs(i).Get(iXmin, iYmin, z0, iXmax, iYmax, z1);
BBs(j).Get(jXmin, jYmin, z0, jXmax, jYmax, z1);
- if (!(iXmin > jXmin &&
+ if (!(iXmin > jXmin &&
iYmin > jYmin &&
iXmax < jXmax &&
iYmax < jYmax))
BB.UpdateFace(DF, aPlaneSur, TopLoc_Location(), Precision::Confusion());
//
BRepTopAdaptor_FClass2d FClass(DF, Precision::PConfusion());
- if ( i == OutWIndex && FClass.PerformInfinitePoint() == TopAbs_IN)
+ if ( i == OutWIndex && FClass.PerformInfinitePoint() == TopAbs_IN)
W.Reverse();
- if ( i != OutWIndex && FClass.PerformInfinitePoint() == TopAbs_OUT)
+ if ( i != OutWIndex && FClass.PerformInfinitePoint() == TopAbs_OUT)
W.Reverse();
//
BB.Add(F, W);
}
-
+
//Add surface to the face
BB.UpdateFace(F, aPlaneSur, TopLoc_Location(), Precision::Confusion());
F.Closed(Standard_True);
}
-int HYDROData_ShapeFile::ImportPolygons(Handle(HYDROData_Document) theDocument, const QString theFileName,
+int HYDROData_ShapeFile::ImportPolygons(Handle(HYDROData_Document) theDocument, const QString theFileName,
QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces)
{
Free();
return 0;
for (size_t i = 0; i < mySHPObjects.size(); i++)
thePolygonsList.append("polygon_" + QString::number(i + 1));
-
+
TopoDS_Face aF;
if (myHSHP->nShapeType == 5)
{
OSD_Timer timer;
timer.Start();
#endif
- for (size_t i = 0; i < mySHPObjects.size(); i++)
+ for (size_t i = 0; i < mySHPObjects.size(); i++)
{
ReadSHPPolygon(theDocument, mySHPObjects[i], i, aF);
theFaces.Append(aF);
}
void HYDROData_ShapeFile::Free()
-{
+{
for (size_t i = 0; i < mySHPObjects.size(); i++ )
free (mySHPObjects[i]);
if (myHSHP != NULL)
{
SHPClose(myHSHP);
- myHSHP = NULL;
+ myHSHP = NULL;
}
}
-void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities, bool bReadAsPolyline)
{
Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
-
+
int nParts = anObj->nParts;
for ( int i = 0 ; i < nParts ; i++ )
{
else
EndIndex = anObj->nVertices;
- HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
if (!bReadAsPolyline)
{
bool IsClosed = false;
}
}
-
+
aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) );
-
+
aPolylineXY->Update();
theEntities.Append(aPolylineXY);
}
-void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj,
- const Handle(HYDROData_PolylineXY)& aPolylineXY,
+void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj,
+ const Handle(HYDROData_PolylineXY)& aPolylineXY,
NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
{
Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) );
else
EndIndex = anObj->nVertices;
- HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ 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])
+ anObj->padfZ[StartIndex] == anObj->padfZ[EndIndex - 1])
EndIndex--;
for ( int k = StartIndex ; k < EndIndex ; k++ )
{
p.X = xyz.X();
p.Y = xyz.Y();
p.Z = xyz.Z();
- aAPoints.push_back(p);
+ aAPoints.push_back(p);
}
}
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 );
}
/*
-void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, bool XYOnly, NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities)
{
Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
EndIndex = anObj->nVertices;
bool IsClosed = false;
- HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ 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])
}
else
aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, false );
-
+
if (IsClosed)
EndIndex--;
for ( int k = StartIndex ; k < EndIndex ; k++ )
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<Handle(HYDROData_Entity), SHPObject*>& theEntitiesToSHPObj,
+int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument,
+ const QString& theFileName,
+ NCollection_IndexedDataMap<Handle(HYDROData_Entity), SHPObject*>& theEntitiesToSHPObj,
ImportShapeType theShapeTypesToImport)
{
int aStat = -1;
anExistingNames.push_back(anIter.Current()->GetName());
NCollection_Sequence<Handle(HYDROData_Entity)> Ents;
- if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
- theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polyline)
+ if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
+ theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polyline)
&& (sh_type == 3 || sh_type == 23))
{
size_t anObjsSize = mySHPObjects.size();
GetFreeIndices(anAllowedIndexes, "_PolyXY_", anObjsSize, anExistingNames, aBaseFileName);
-
+
for (size_t i = 0; i < mySHPObjects.size(); i++ )
{
ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, false);
}
aStat = 1;
}
- else if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
+ else if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polyline3D) && sh_type == 13)
{
anInd = 0;
}
for (size_t i = 0; i < mySHPObjects.size(); i++ )
{
- //ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], false, theEntities);
- ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, false); //TODO check Z coord on closeness
+ //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;
}
- else if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
+ else if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_Polygon) && sh_type == 5)
{
//import polygon's contours as polylines
size_t anObjsSize = mySHPObjects.size();
GetFreeIndices(anAllowedIndexes, "_PolyXY_", anObjsSize, anExistingNames, aBaseFileName);
-
+
for (size_t i = 0; i < mySHPObjects.size(); i++ )
{
ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], Ents, true);
}
aStat = 2;
}
- else
+ else
{
aStat = 0;
}
-
+
return aStat;
}
{
if (myHSHP != NULL)
return myHSHP->nShapeType;
- else
+ else
return -1;
}
-int HYDROData_ShapeFile::ImportPolylines3D(Handle(HYDROData_Document) theDocument,
- NCollection_IndexedDataMap<Handle(HYDROData_Entity), SHPObject*> thePolyXYToObj,
+int HYDROData_ShapeFile::ImportPolylines3D(Handle(HYDROData_Document) theDocument,
+ NCollection_IndexedDataMap<Handle(HYDROData_Entity), SHPObject*> thePolyXYToObj,
NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities,
ImportShapeType theShapeTypesToImport)
{
int aStat = -1;
int sh_type = myHSHP->nShapeType;
- if ((theShapeTypesToImport == HYDROData_ShapeFile::ImportShapeType_All ||
+ 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);
+ ReadSHPPoly3D(theDocument, thePolyXYToObj(i), aPolylineXY, theEntities);
}
aStat = 1;
}
- else
+ else
aStat = 0;
-
+
return aStat;
}
if (pFileSHX == NULL)
return -2;
}
-
+
fclose (pFileSHP);
fclose (pFileSHX);
return 0;
{
return false;
}
-
+
fclose (pFileDBF);
thePathToDBFFile = aDBFfile;
return true;
{
int nWidth, nDecimals;
char chField[12];
-
+
for( int i = 0; i < DBFGetRecordCount(myHDBF); i++ )
- {
+ {
DBFFieldType eType;
DBF_AttrValue anAttr;
eType = DBFGetFieldInfo( myHDBF, theIndexOfField, chField, &nWidth, &nDecimals );
anAttr.myStrVal = QString(chAttr);
break;
}
-
+
case FTInteger:
{
int iAttr = DBFReadIntegerAttribute( myHDBF, i, theIndexOfField );
anAttr.myIntVal = iAttr;
break;
}
-
+
case FTDouble:
{
double dAttr = DBFReadDoubleAttribute( myHDBF, i, theIndexOfField );
hDBF = DBFCreate( theFileName.toStdString().c_str() );
if( hDBF == NULL )
return false;
-
- if (theType != DBF_FieldType_String && theType != DBF_FieldType_Integer && theType != DBF_FieldType_Double)
+
+ if (theType != DBF_FieldType_String && theType != DBF_FieldType_Integer && theType != DBF_FieldType_Double)
{
DBFClose( hDBF );
return false; //cant handle any other cases
DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTString, nWidth, 0);
break;
}
-
+
case DBF_FieldType_Integer:
{
DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTInteger, nWidth, 0);
break;
}
-
+
case DBF_FieldType_Double:
{
DBFAddField (hDBF, theFieldName.toStdString().c_str(), FTDouble, nWidth, 0);
break;
}
- if (DBFGetFieldCount( hDBF ) != 1)
+ if (DBFGetFieldCount( hDBF ) != 1)
{
DBFClose( hDBF );
return false;
stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myStrVal.toStdString().c_str());
break;
}
-
+
case DBF_FieldType_Integer:
{
stat = DBFWriteIntegerAttribute(hDBF, (int)i, 0, theAttrV[i].myIntVal);
break;
}
-
+
case DBF_FieldType_Double:
{
stat = DBFWriteDoubleAttribute(hDBF, (int)i, 0, theAttrV[i].myDoubleVal);