Salome HOME
refs #1806 (lot 7)
authorisn <isn@opencascade.com>
Fri, 3 Aug 2018 13:03:00 +0000 (16:03 +0300)
committerisn <isn@opencascade.com>
Thu, 6 Sep 2018 14:27:03 +0000 (17:27 +0300)
Signed-off-by: isn <isn@opencascade.com>
12 files changed:
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_PolylineXY.h
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_PolyAttrDlg.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h [new file with mode: 0644]
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index a42898568419667417aa80746bac27e8b4aa92d2..17cc1e0bdec7df73443acf893b03d441b966d89f 100644 (file)
@@ -71,6 +71,7 @@
 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
 #include <TDataStd_RealList.hxx>
 #include <TDataStd_UAttribute.hxx>
+#include <TDataStd_ExtStringArray.hxx>
 
 #include <TopoDS_Iterator.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
@@ -1583,3 +1584,38 @@ void HYDROData_PolylineXY::Interpolate()
 {
   ImportShape( GetShape(), true, NULL );
 }
+
+void HYDROData_PolylineXY::SetDBFInfo( const QStringList& theDBFTable )   
+{ 
+  int i = 1;
+  Handle_TDataStd_ExtStringArray TExtStrArr = 
+    TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_DBFTableInfo), 1, theDBFTable.size() );
+  foreach (QString val, theDBFTable)
+  {
+    std::string StdVal = val.toStdString();
+    const char* aCVal = StdVal.c_str();
+    TExtStrArr->SetValue(i, TCollection_ExtendedString(aCVal));
+    i++;
+  }
+}
+
+bool HYDROData_PolylineXY::GetDBFInfo(QStringList& theDBFTable) const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_DBFTableInfo, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TDataStd_ExtStringArray) anExtStrArr;
+    if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
+    {
+      for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ )
+      {
+        Standard_ExtString str = anExtStrArr->Value(i).ToExtString();
+        TCollection_AsciiString aText (str);
+        theDBFTable << QString(aText.ToCString());
+      }
+    }
+  }
+  else
+    return false;
+  return true;
+}
index 8375616b912921c6e36b12f4aabca5daa9314387..14aeaff95a085f7f126ec9b1523fc7980c4b2e41 100644 (file)
@@ -42,6 +42,7 @@ protected:
   {
     DataTag_First = HYDROData_IPolyline::DataTag_First + 100, ///< first tag, to reserve
     DataTag_GeomObjectEntry,  ///< study entry of the imported GEOM object
+    DataTag_DBFTableInfo
   };
 
 public:
@@ -300,6 +301,10 @@ public:
    */
   HYDRODATA_EXPORT void Transform( const QTransform& theTrsf );
 
+  HYDRODATA_EXPORT void SetDBFInfo(const QStringList& theDBFTable);  
+
+  HYDRODATA_EXPORT bool GetDBFInfo(QStringList& theDBFTable) const;
+
 protected:
 
   /**
index a9605ebdf72614472658f3b0490621d94e2a5efc..ae49195687c5014f7099594e6b285e980692e344 100644 (file)
@@ -152,6 +152,8 @@ set(PROJECT_HEADERS
     HYDROGUI_ZoneTool.h
     HYDROGUI_RegenerateRegionColorsOp.h
     HYDROGUI_ZoneSetColorOp.h
+    HYDROGUI_PolyAttrDlg.h
+    HYDROGUI_ShowAttrPolyOp.h
 )
 
 QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
@@ -306,6 +308,8 @@ set(PROJECT_SOURCES
     HYDROGUI_ZoneTool.cxx
     HYDROGUI_RegenerateRegionColorsOp.cxx
     HYDROGUI_ZoneSetColorOp.cxx
+    HYDROGUI_PolyAttrDlg.cxx
+    HYDROGUI_ShowAttrPolyOp.cxx
 )
 
 add_definitions(
index e7faee118be82bfaa64f382d43cdcefd0092be0a..257352f1b1567c14699399e8aa1b0d80b2a72de5 100644 (file)
@@ -92,6 +92,80 @@ void HYDROGUI_ImportPolylineOp::onApply()
       NCollection_Sequence<Handle(HYDROData_Entity)> theEntities;
       int aShapeTypeOfFile = -1;
       int aStat = anImporter.ImportPolylines(doc(), aFileName, theEntities, aShapeTypeOfFile ); 
+      if (aStat == 1 || aStat == 2)
+      {
+        //try to import DBF
+        QString aDBFFileName;
+        aDBFFileName = aFileName.simplified().replace( aFileName.simplified().size() - 4, 4, ".dbf");
+        bool DBF_Stat = anImporter.DBF_OpenDBF(aDBFFileName);
+        if (DBF_Stat)
+        {
+          QStringList aFieldList = anImporter.DBF_GetFieldList();
+          int nbRecords = anImporter.DBF_GetNbRecords();
+          assert (theEntities.Length() == nbRecords);
+          if (theEntities.Length() == nbRecords)
+          {
+            int indNameAttrFound = -1;
+            int k = 0;
+            bool bUseNameAttrFound = false;
+            for (QStringList::iterator it = aFieldList.begin(); it != aFieldList.end(); it++, k++)
+              if (QString::compare(*it, "name", Qt::CaseInsensitive) == 0)
+              {
+                indNameAttrFound = k;
+                break;
+              }
+
+              if (indNameAttrFound != -1)
+                bUseNameAttrFound = SUIT_MessageBox::question( module()->getApp()->desktop(),
+                               tr( "IMPORT_POLYLINE" ),
+                               tr( "IMPORT_POLYLINE_USE_NAME_ATTR" ),
+                               QMessageBox::Yes | QMessageBox::No, 
+                               SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
+  
+            std::vector<std::vector<HYDROData_ShapeFile::DBF_AttrValue>> anAttrVV;
+            for (int i = 0; i < aFieldList.size(); i++)
+            {
+              std::vector<HYDROData_ShapeFile::DBF_AttrValue> anAttrV;
+              anAttrVV.push_back(anAttrV);
+              anImporter.DBF_GetAttributeList(i, anAttrVV[i] );
+            }
+
+            int indNULL = 1;
+            for (int i = 1; i <= theEntities.Length(); i++)
+            {
+              Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theEntities(i) );
+              QStringList aDBFinfo;
+              aDBFinfo << aFieldList; //first, the table header
+              for (int j = 0; j < aFieldList.size(); j++)
+              {
+                QString attr;
+                const HYDROData_ShapeFile::DBF_AttrValue& attrV = anAttrVV[j][i-1];
+                if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_String)
+                  aDBFinfo << attrV.myStrVal;
+                else if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_Integer)
+                  aDBFinfo << QString::number(attrV.myIntVal);
+                else if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_Double)
+                  aDBFinfo << QString::number(attrV.myDoubleVal);
+                else 
+                  aDBFinfo << "";
+              }
+              assert (aDBFinfo.size() / 2 == aFieldList.size());
+              aPolylineXY->SetDBFInfo(aDBFinfo);
+              if (bUseNameAttrFound)
+              {
+                QString nameOfPoly = aDBFinfo[aDBFinfo.size() / 2 + indNameAttrFound];
+                if (!nameOfPoly.isEmpty())
+                  aPolylineXY->SetName(nameOfPoly);
+                else
+                {
+                  aPolylineXY->SetName("null_name_" + QString::number(indNULL));
+                  indNULL++;
+                }
+              }
+            }
+          }
+        }        
+      }
       if (aStat == 1)
         UpdateView(theEntities);
       else if (aStat == 2)
index 03a78832368f51deb1616c17644940f9052df243..54d2a851049d52a4fdabb436b279281abcaf460e 100644 (file)
@@ -662,6 +662,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitPolylinesId ) );
         theMenu->addAction( action( MergePolylinesId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( ShowAttrPolylinesId ) );
+        theMenu->addSeparator();
       }
       else if( anIsPolyline3D )
       {
index a3631f1a46c2d133331979c07516c6d457b4694b..b5d318aae43de52c4cb3b593fe193fe764a576ef 100644 (file)
@@ -75,6 +75,7 @@
 #include "HYDROGUI_RegenerateRegionColorsOp.h"
 #include "HYDROGUI_PolylineStyleOp.h"
 #include "HYDROGUI_ZoneSetColorOp.h"
+#include <HYDROGUI_ShowAttrPolyOp.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_Obstacle.h>
 #include <HYDROData_SplitToZonesTool.h>
@@ -245,6 +246,8 @@ void HYDROGUI_Module::createActions()
   createAction( SplitPolylinesId, "SPLIT_POLYLINES", "SPLIT_POLYLINES_ICO" );
   createAction( MergePolylinesId, "MERGE_POLYLINES", "MERGE_POLYLINES_ICO" );
 
+  createAction( ShowAttrPolylinesId, "SHOWATTR_POLYLINES");
+
   createAction( LandCoverScalarMapModeOnId, "LC_SCALARMAP_COLORING_ON" );
   createAction( LandCoverScalarMapModeOffId, "LC_SCALARMAP_COLORING_OFF" );
 
@@ -797,6 +800,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case MergePolylinesId:
     anOp = new HYDROGUI_MergePolylinesOp( aModule );
     break;
+  case ShowAttrPolylinesId:
+    anOp = new HYDROGUI_ShowAttrPolyOp( aModule );
+    break;
   case LandCoverScalarMapModeOnId:
   case LandCoverScalarMapModeOffId:
     anOp = new HYDROGUI_LandCoverColoringOp( aModule, theId );
index 519c68a7d754c90979d014897777b990421b20b2..42e9ab9d37aa98dd2fcf20d84cde5da16825a059 100644 (file)
@@ -135,6 +135,8 @@ enum OperationId
   SplitPolylinesId,
   MergePolylinesId,
 
+  ShowAttrPolylinesId,
+
   LandCoverScalarMapModeOnId,
   LandCoverScalarMapModeOffId,
 
diff --git a/src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx
new file mode 100644 (file)
index 0000000..aaade7c
--- /dev/null
@@ -0,0 +1,62 @@
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PolyAttrDlg.h"
+#include <QVBoxLayout>
+#include <QPushButton>
+
+HYDROGUI_PolyAttrDlg::HYDROGUI_PolyAttrDlg( QWidget* theParent, const QStringList& theDBFData )
+  : QDialog( theParent )
+{
+  QVBoxLayout* aMainLayout = new QVBoxLayout( this );
+  aMainLayout->setMargin(5);
+  aMainLayout->setSpacing(5);
+  int nbcol = theDBFData.size()/2;
+  myDBFDataTable = new QTableWidget(1, nbcol);
+  //myDBFDataTable->setEditTriggers(QAbstractItemView:NoEditTriggers);
+
+  QStringList header;
+  for (int i = 0; i < nbcol; i++)
+    header << theDBFData[i];
+  myDBFDataTable->setHorizontalHeaderLabels(header);
+  myDBFDataTable->setShowGrid(true);
+
+  for (int i = theDBFData.size()/2; i < theDBFData.size(); i++)
+  {
+    QTableWidgetItem* item = new QTableWidgetItem(theDBFData[i]);
+    item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+    myDBFDataTable->setItem(0, i-theDBFData.size()/2, item);
+  }
+
+  aMainLayout->addWidget(myDBFDataTable);
+
+  QPushButton* anOkButton = new QPushButton( tr("OK"), this );
+  anOkButton->setDefault( true ); 
+  aMainLayout->addWidget( anOkButton );
+
+  connect( anOkButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+
+  setLayout(aMainLayout);  
+
+}
+
+HYDROGUI_PolyAttrDlg::~HYDROGUI_PolyAttrDlg()
+{
+}
+
+
diff --git a/src/HYDROGUI/HYDROGUI_PolyAttrDlg.h b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.h
new file mode 100644 (file)
index 0000000..dad41e5
--- /dev/null
@@ -0,0 +1,41 @@
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+
+
+#ifndef HYDROGUI_POLYATTRDLG_H
+#define HYDROGUI_POLYATTRDLG_H
+
+#include <QTableWidget>
+#include <QDialog>
+
+class HYDROGUI_PolyAttrDlg : public QDialog
+{
+  Q_OBJECT
+
+public:
+
+  HYDROGUI_PolyAttrDlg( QWidget* theParent, const QStringList& theDBFData );
+  virtual ~HYDROGUI_PolyAttrDlg();
+  
+private:
+  QTableWidget* myDBFDataTable;
+
+};
+
+#endif
diff --git a/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx
new file mode 100644 (file)
index 0000000..3429e91
--- /dev/null
@@ -0,0 +1,66 @@
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ShowAttrPolyOp.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Module.h"
+
+#include <HYDROData_Object.h>
+#include <HYDROData_IPolyline.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_UpdateFlags.h>
+
+#include <SUIT_Desktop.h>
+#include <HYDROGUI_Tool2.h>
+#include <HYDROGUI_PolyAttrDlg.h>
+#include <HYDROData_PolylineXY.h>
+#include <SUIT_MessageBox.h>
+
+HYDROGUI_ShowAttrPolyOp::HYDROGUI_ShowAttrPolyOp( HYDROGUI_Module* theModule )
+: HYDROGUI_Operation( theModule ),
+  myPolyAttrDlg( 0 )
+{
+  setName( tr( "SHOWATTR_POLYLINE" ) );
+}
+
+HYDROGUI_ShowAttrPolyOp::~HYDROGUI_ShowAttrPolyOp()
+{
+}
+
+void HYDROGUI_ShowAttrPolyOp::startOperation()
+{
+  HYDROGUI_Operation::startOperation();
+
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects(module());
+  Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(aSeq(1));  
+  QStringList aDbflist;
+  if (aPolyXY->GetDBFInfo(aDbflist))
+  {
+    myPolyAttrDlg = new HYDROGUI_PolyAttrDlg( module()->getApp()->desktop(), aDbflist );
+    myPolyAttrDlg->setModal( true );
+    myPolyAttrDlg->setWindowTitle(getName());
+    myPolyAttrDlg->exec();
+  }
+  else
+    SUIT_MessageBox::information( module()->getApp()->desktop(), getName(), tr("SHOWATTR_POLY_NO_ATTR")); 
+
+  HYDROGUI_Operation::abort();
+}
+
diff --git a/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h
new file mode 100644 (file)
index 0000000..71d147d
--- /dev/null
@@ -0,0 +1,44 @@
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_SHOWATTRPOLYOP_H
+#define HYDROGUI_SHOWATTRPOLYOP_H
+
+#include "HYDROGUI_Operation.h"
+
+#include <HYDROData_Entity.h>
+
+class HYDROGUI_PolyAttrDlg;
+
+class HYDROGUI_ShowAttrPolyOp : public HYDROGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_ShowAttrPolyOp( HYDROGUI_Module* theModule );
+  virtual ~HYDROGUI_ShowAttrPolyOp();
+
+protected:
+  virtual void startOperation();
+
+private:
+  HYDROGUI_PolyAttrDlg* myPolyAttrDlg;
+};
+
+#endif
\ No newline at end of file
index 0ca06e8a1cba01b80176c06d96a63b44cbfe2e48..0ba175c38dd5a34615b70f52c98fc49df484f3ac 100644 (file)
@@ -1079,6 +1079,10 @@ Would you like to remove all references from the image?</translation>
       <source>DSK_MERGE_POLYLINES</source>
       <translation>Merge polylines</translation>
     </message>
+    <message>
+      <source>DSK_SHOWATTR_POLYLINES</source>
+      <translation>Show DBF attributes</translation>
+    </message>
     <message>
       <source>DSK_UNDO</source>
       <translation>Undo</translation>
@@ -1468,6 +1472,10 @@ Would you like to remove all references from the image?</translation>
       <source>MEN_MERGE_POLYLINES</source>
       <translation>Merge polylines</translation>
     </message>
+    <message>
+      <source>MEN_SHOWATTR_POLYLINES</source>
+      <translation>Show DBF attributes</translation>
+    </message>
     <message>
       <source>MEN_UNDO</source>
       <translation>Undo</translation>
@@ -1808,6 +1816,10 @@ Would you like to remove all references from the image?</translation>
       <source>STB_MERGE_POLYLINES</source>
       <translation>Merge polylines</translation>
     </message>
+    <message>
+      <source>STB_SHOWATTR_POLYLINES</source>
+      <translation>Show DBF attributes</translation>
+    </message>
     <message>
       <source>STB_UNDO</source>
       <translation>Undo</translation>
@@ -2480,6 +2492,10 @@ file cannot be correctly imported for an Obstacle definition.</translation>
       <source>IMPORT_POLYLINE</source>
       <translation>Import Polyline</translation>
     </message>
+    <message>
+      <source>IMPORT_POLYLINE_USE_NAME_ATTR</source>
+      <translation>DBF file contains 'name' field. Would you like to use the value of this field as a name of polyline?</translation>
+    </message>
     <message>
       <source>POLYLINE_FILTER</source>
       <translation>Shape files (*.shp)</translation>
@@ -3486,6 +3502,18 @@ Polyline should consist from one not closed curve.</translation>
     </message>
   </context>
 
+  <context>
+    <name>HYDROGUI_ShowAttrPolyOp</name>
+    <message>
+      <source>SHOWATTR_POLYLINE</source>
+      <translation>DBF attributes of polyline</translation>
+    </message>
+    <message>
+      <source>SHOWATTR_POLY_NO_ATTR</source>
+      <translation>This polyline does not contain DBF information</translation>
+    </message>
+  </context>
+
   <context>
     <name>HYDROGUI_SplitPolylinesDlg</name>
     <message>