-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// 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
#include <HYDROData_PolylineXY.h>
#include <HYDROData_Polyline3D.h>
#include <HYDROData_Bathymetry.h>
-#include <HYDROData_LandCover.h>
#include <HYDROData_Profile.h>
#include <HYDROData_Iterator.h>
#include <QColor>
#include <BRepTopAdaptor_FClass2d.hxx>
+#ifdef WIN32
+ #pragma warning( disable: 4996 )
+#endif
+
HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL)
{
}
void HYDROData_ShapeFile::Export(const QString& aFileName,
NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
- NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq,
+ const Handle_HYDROData_LandCoverMap& aLCSeq,
QStringList& aNonExpList)
{
+ /*TODO
SHPHandle hSHPHandle;
if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
{
QString aFN = aFileName.simplified();
remove (aFN.toStdString().c_str());
remove (aFN.replace( ".shp", ".shx", Qt::CaseInsensitive).toStdString().c_str());
- }
+ }*/
}
int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
return 1;
}
-int HYDROData_ShapeFile::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
+/*TODO:int HYDROData_ShapeFile::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
{
TopoDS_Shape aSh = theLC->GetShape();
if (aSh.IsNull())
return 1;
}
-
+*/
void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
{
SHPObject *aSHPObj;
if( DBFIsAttributeNULL( myHDBF, i, theIndexOfField ) )
{
anAttr.myIsNull = true;
+ DBF_FieldType FT = DBF_FieldType_None;
+ if( eType == FTString )
+ FT = DBF_FieldType_String;
+ else if( eType == FTInteger )
+ FT = DBF_FieldType_Integer;
+ else if( eType == FTDouble )
+ FT = DBF_FieldType_Double;
+ else if( eType == FTInvalid )
+ FT = DBF_FieldType_Invalid;
+ anAttr.myFieldType = FT;
}
else
{
anAttr.myIsNull = false;
anAttr.myFieldType = DBF_FieldType_Integer;
anAttr.myRawValue = DBFReadStringAttribute( myHDBF, i, theIndexOfField );
- anAttr.myStrVal = QString::number(iAttr);
+ anAttr.myIntVal = iAttr;
break;
}
anAttr.myIsNull = false;
anAttr.myFieldType = DBF_FieldType_Double;
anAttr.myRawValue = DBFReadStringAttribute( myHDBF, i, theIndexOfField );
- anAttr.myStrVal = QString::number(dAttr, 'g', 20);
+ anAttr.myDoubleVal = dAttr;
break;
}
default:
theAttrV.push_back(anAttr);
}
+}
+
+bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector<DBF_AttrValue>& theAttrV, bool bUseRawValue)
+{
+ // Check that given field type is equal to field types of attributes values
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (theAttrV[i].myFieldType != theType)
+ return false;
+ }
+
+ DBFHandle hDBF;
+ hDBF = DBFCreate( theFileName.toStdString().c_str() );
+ if( hDBF == NULL )
+ return false;
+
+ if (theType != DBF_FieldType_String && theType != DBF_FieldType_Integer && theType != DBF_FieldType_Double)
+ {
+ DBFClose( hDBF );
+ return false; //cant handle any other cases
+ }
+
+ int nWidth = 20;
+ switch( theType )
+ {
+ case DBF_FieldType_String:
+ {
+ 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;
+ }
+ default:
+ break;
+ }
+
+ if (DBFGetFieldCount( hDBF ) != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ if (DBFGetRecordCount( hDBF ) != 0)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ int stat = -1;
+
+ if (bUseRawValue)
+ {
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (!theAttrV[i].myIsNull)
+ stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myRawValue.c_str());
+ else
+ stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 );
+
+ if (stat != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ }
+ }
+ else
+ {
+ for (size_t i = 0; i < theAttrV.size(); i++)
+ {
+ if (!theAttrV[i].myIsNull)
+ switch( theType )
+ {
+ case DBF_FieldType_String:
+ {
+ 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);
+ break;
+ }
+ default:
+ break;
+ }
+ else
+ stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 );
+
+ if (stat != 1)
+ {
+ DBFClose( hDBF );
+ return false;
+ }
+ }
+ }
+
+ DBFClose( hDBF );
+ return true;
+
}
\ No newline at end of file