Salome HOME
write dbf with Hydro shapefiles, attribute string "PartName" with polyline name
authorPaul RASCLE <paul.rascle@openfields.fr>
Fri, 2 Oct 2020 07:06:44 +0000 (09:06 +0200)
committerYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Fri, 30 Oct 2020 16:09:38 +0000 (17:09 +0100)
src/HYDROData/HYDROData_ShapeFile.cxx

index 3e7b348697c3acc8221d92139c18bac006b2f5f2..12cb1106146d58551c0d5980ac728349fa16c927 100644 (file)
@@ -62,6 +62,9 @@
 #include <BRepBndLib.hxx>
 #include <Bnd_Box.hxx>
 
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 #ifdef WIN32
   #pragma warning( disable: 4996 )
 #endif
@@ -84,13 +87,20 @@ void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument,
                                  NCollection_Sequence<Handle(HYDROData_Polyline3D)> aPoly3DSeq,
                                  QStringList& aNonExpList)
 {
+  DEBTRACE("aFileName " << aFileName.toStdString());
   SHPHandle hSHPHandle;
+  QStringList anExpList;
   if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
   {
     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());
+      else
+      {
+       anExpList.append(aPolyXYSeq(i)->GetName());
+       DEBTRACE("  aName: " << aPolyXYSeq(i)->GetName().toStdString());
+      }
   }
   else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
   {
@@ -98,9 +108,28 @@ void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument,
     for (int i = 1; i <= aPoly3DSeq.Size(); i++)
       if (WriteObjectPoly3D(theDocument, hSHPHandle, aPoly3DSeq(i)) != 1)
         aNonExpList.append(aPoly3DSeq(i)->GetName());
+      else
+      {
+       anExpList.append(aPoly3DSeq(i)->GetName());
+       DEBTRACE("  aName: " << aPoly3DSeq(i)->GetName().toStdString());
+      }
   }
   if (hSHPHandle->nRecords > 0)
+  {
     SHPClose( hSHPHandle );
+    std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+    for (int i=0; i<anExpList.size(); i++)
+    {
+       HYDROData_ShapeFile::DBF_AttrValue aCurAttrV;
+               aCurAttrV.myStrVal = anExpList[i];
+               aCurAttrV.myFieldType = HYDROData_ShapeFile::DBF_FieldType_String;
+               aCurAttrV.myIsNull = false;
+               theAttrV.push_back(aCurAttrV);
+    }
+    QString theDBFFileName = aFileName.section('.',0,-2) + ".dbf";
+    DEBTRACE("theDBFFileName " << theDBFFileName.toStdString());
+    DBF_WriteFieldAndValues(theDBFFileName, "PartName", HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
+  }
   else
   {
     SHPClose( hSHPHandle );
@@ -118,7 +147,7 @@ void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument,
 {
   if (bCheckLinear && !aLCM->CheckLinear())
     return;
-  //
+
   SHPHandle hSHPHandle = NULL;
   if ( !aLCM.IsNull() && !aLCM->IsEmpty())
   {
@@ -150,11 +179,6 @@ int HYDROData_ShapeFile::WriteObjectPolyXY(Handle(HYDROData_Document) theDocumen
   SHPObject    *aSHPObj;
   std::vector<double> x, y;
   std::vector<int> anPartStart;
-
-//  for (int i = 0; i < thePoly->NbSections(); i++)
-//    if (thePoly->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
-//      return -1;
-
   for (int i = 0; i < thePoly->NbSections(); i++)
   {
     anPartStart.push_back(x.size());
@@ -190,9 +214,6 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(Handle(HYDROData_Document) theDocumen
   std::vector<int> anPartStart;
   anPartStart.push_back(0); //one section only
 
-  if (thePoly->GetPolylineXY()->GetSectionType(0) == HYDROData_IPolyline::SECTION_SPLINE)
-    return -1;
-
   HYDROData_Polyline3D::Polyline3DPoints aPointList3D = thePoly->GetProfilePoints3D(true);
   for (int j = 1; j <= aPointList3D.Size(); j++)
   {
@@ -1164,6 +1185,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
     default:
       break;
   }
+  DEBTRACE("theAttrV.size() " << theAttrV.size());
 
   if (DBFGetFieldCount( hDBF ) != 1)
   {
@@ -1181,6 +1203,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
   {
     for (size_t i = 0; i < theAttrV.size(); i++)
     {
+      DEBTRACE("  rawValue");
       if (!theAttrV[i].myIsNull)
         stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myRawValue.c_str());
       else
@@ -1197,11 +1220,13 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
   {
     for (size_t i = 0; i < theAttrV.size(); i++)
     {
+      DEBTRACE("  typeValue " << theAttrV[i].myIsNull);
       if (!theAttrV[i].myIsNull)
         switch( theType )
         {
           case DBF_FieldType_String:
           {
+               DEBTRACE("  write dbf " << i << " " << theAttrV[i].myStrVal.toStdString());
             stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myStrVal.toStdString().c_str());
             break;
           }
@@ -1222,7 +1247,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
         }
       else
         stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 );
-
+      DEBTRACE("  stat " << stat);
       if (stat != 1)
       {
         DBFClose( hDBF );