Salome HOME
Use discretization to write non-linear borders of LCM to SHP file // p.4
authorisn <isn@opencascade.com>
Tue, 17 Nov 2015 13:17:20 +0000 (16:17 +0300)
committerisn <isn@opencascade.com>
Tue, 17 Nov 2015 19:13:37 +0000 (22:13 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 33a705cd434ca9dc6ba2940c3d3350c118eb910d..3976299fddf3a769e6cef9c1914b846cbbe5a5d4 100644 (file)
 #include <BRepCheck_Shell.hxx>
 #include <BRepCheck_ListOfStatus.hxx>
 #include <TopTools_SequenceOfShape.hxx>
+#include <Handle_Geom_Curve.hxx>
+#include <Handle_Geom_Line.hxx>
+#include <Handle_Geom_TrimmedCurve.hxx>
+#include <Geom_TrimmedCurve.hxx>
 
 
 #include <QFile>
@@ -828,6 +832,10 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
     QString aSType = anIt.StricklerType();
     //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
     TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
+
+    //
+    TopTools_ListOfShape aGen = aBuilder.Generated( anIt.Face() );
+    //
     if( aModified.Extent() == 0 )
       aModified.Append( anIt.Face() );
 
@@ -1059,3 +1067,28 @@ bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUse
     return false;
 }
 
+bool HYDROData_LandCoverMap::CheckLinear()
+{
+  TopoDS_Shape InpShape = GetShape();
+  TopExp_Explorer anEdgeEx(InpShape, TopAbs_EDGE);
+  for (; anEdgeEx.More(); anEdgeEx.Next()) 
+  {
+    TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
+    double aFP, aLP;
+    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+    Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
+    if (aLine.IsNull())
+    {
+      Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
+      if (!aTC.IsNull())
+      {
+        Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
+        if (aLine.IsNull())
+          return false;
+      }
+      else
+        return false;
+    }
+  }
+  return true;
+}
index c2437d8c7c978f37e05e5a6493c3ba1d9dbf5171..c6535eecbc321c69a61b93e7b0c9ad4cd9774bf7 100644 (file)
@@ -143,6 +143,8 @@ public:
 
   HYDRODATA_EXPORT TopoDS_Shape RemoveInternal(const TopoDS_Shape& InSh);
 
+  HYDRODATA_EXPORT bool CheckLinear();
+
 protected:
   void SetShape( const TopoDS_Shape& );
 
index 8b0711f86ec36cc975e18a465e0e722f8c228616..508ddec77747b1422227cde446e36cc74364e38b 100644 (file)
@@ -105,8 +105,11 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
 }
 
 void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, 
-                                 QStringList& aNonExpList, bool bUseDiscr, double theDefl)
+                                 QStringList& aNonExpList, bool bCheckLinear, bool bUseDiscr, double theDefl)
 {
+  if (bCheckLinear && !aLCM->CheckLinear())
+    return;
+  //
   SHPHandle hSHPHandle;
   if ( !aLCM.IsNull() && !aLCM->IsEmpty())
   {
@@ -204,9 +207,6 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
   if (theInputShape.IsNull())
     return 0;
 
-  if (!bUseDiscr && !CheckLinear(theInputShape))
-    return -1;
-
   if (theInputShape.ShapeType() == TopAbs_FACE)
   {
     ProcessFace(TopoDS::Face(theInputShape), theShpHandle, bUseDiscr, theDefl);
@@ -990,27 +990,3 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
 
 }
 
-bool HYDROData_ShapeFile::CheckLinear(const TopoDS_Shape& theInpShape)
-{
-  TopExp_Explorer anEdgeEx(theInpShape, TopAbs_EDGE);
-  for (; anEdgeEx.More(); anEdgeEx.Next()) 
-  {
-    TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
-    double aFP, aLP;
-    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
-    Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
-    if (aLine.IsNull())
-    {
-      Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
-      if (!aTC.IsNull())
-      {
-        Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
-        if (aLine.IsNull())
-          return false;
-      }
-      else
-        return false;
-    }
-  }
-  return true;
-}
\ No newline at end of file
index 95a8b1752fa32dc7aac108a6beadc5c1a491af29..16d92ad1c544cf4951ab85ddda9aa018dc408456 100644 (file)
@@ -89,6 +89,7 @@ public:
   HYDRODATA_EXPORT void Export(const QString& aFileName,
                                const Handle_HYDROData_LandCoverMap& aLCM,
                                QStringList& aNonExpList,
+                               bool bCheckLinear = true,
                                bool bUseDiscr = false, 
                                double theDefl = 0.1);
 
index bd4825e3449723c3b465d359f484a6a9aa1c1f80..9b17e6a721ede70653bd2765d073f0d4f374c927 100644 (file)
@@ -132,12 +132,13 @@ void HYDROGUI_ExportFileOp::startOperation()
           return; 
 
         //
-        HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), anAttrNames.toList());
+        Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
+        bool IsLinear = aLCM->CheckLinear();
+        HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), IsLinear, anAttrNames.toList());
         if ( aDlg.exec() == HYDROGUI_ExportLandCoverMapDlg::Accepted )
         { 
           //In our case :  aSeq.Size() == 1
           //Export of multiple landcover maps into the one shp-file is disallowed.
-          Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
           QString aCItem = aDlg.getCurrentItem();
           Handle(HYDROData_StricklerTable) aStricklerTableObj;
           {
@@ -151,7 +152,7 @@ void HYDROGUI_ExportFileOp::startOperation()
           }
 
           //export shape-data
-          anExporter.Export(aFileName, aLCM, aNonExpList);
+          anExporter.Export(aFileName, aLCM, aNonExpList, false, !IsLinear, aDlg.getDeflValue());
           QString aDBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive);
           //Even if attribute-checkbox is unchecked, the .dbf-file should be removed. 
           //otherwise it may be used with wrong .shp-file. This is an incorrect behaivor.
index 9da8db3674602c94459d2b946aef82c704690fec..28533ef7e4e75cbecbdac33b07cbfc214359c34a 100644 (file)
 #include <QCheckBox>
 #include <QVBoxLayout>
 #include <QComboBox>
+#include <QLabel>
+#include <QDoubleSpinBox>
 
-HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& theAttrItems )
+HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, bool IsLinear, const QStringList& theAttrItems )
   : QtxDialog( theParent, false, true, QtxDialog::OKCancel )
 {
   setWindowTitle( tr( "EXPORT_LANDCOVERMAP" ) );
@@ -43,6 +45,19 @@ HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* thePare
   aLayout->addWidget( myAttrCheckBox, 0, 0 );
   aLayout->addWidget( myAvFields, 1, 0, 1, 2 );
 
+  if(!IsLinear)
+  {
+    myDiscrLabel = new QLabel( tr( "LCM_DISCR_LABEL" ), mainFrame() );
+    myDeflSpinBox = new QDoubleSpinBox( mainFrame() );
+    myDeflSpinBox->setRange(0.001, 2); 
+    myDeflSpinBox->setDecimals(3);
+    myDeflSpinBox->setSingleStep(0.001);
+    myDeflLabel = new QLabel ( tr( "LCM_DEFL_LABEL" ), mainFrame() );
+    aLayout->addWidget( myDiscrLabel, 2, 0 );
+    aLayout->addWidget( myDeflLabel, 3, 0, 1, 1 );
+    aLayout->addWidget( myDeflSpinBox, 3, 1, 2, 2 );
+  }
+
   setMinimumSize( 300, 100 );
 
   connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool)));
@@ -70,3 +85,8 @@ bool HYDROGUI_ExportLandCoverMapDlg::getAttrCheckBoxState()
 {
   return myAttrCheckBox->isChecked();
 }
+
+double HYDROGUI_ExportLandCoverMapDlg::getDeflValue() const
+{
+  return myDeflSpinBox->value();
+}
index eda646f58bac964a455eb84fe994275394da957a..005914f2957124c3375ae1b4dac06eaa1e27832e 100644 (file)
 
 class QCheckBox;
 class QComboBox;
+class QLabel;
+class QDoubleSpinBox;
 
 class HYDROGUI_ExportLandCoverMapDlg : public QtxDialog
 {
   Q_OBJECT
 
 public:
-  HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent = 0, const QStringList& theAttrItems = QStringList());
+  HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent = 0, bool IsLinear = false, const QStringList& theAttrItems = QStringList());
   virtual ~HYDROGUI_ExportLandCoverMapDlg();
 
 protected slots:
@@ -39,10 +41,14 @@ protected slots:
 public:
   QString          getCurrentItem() const; 
   bool             getAttrCheckBoxState();
+  double           getDeflValue() const;
 
 private:
   QCheckBox*       myAttrCheckBox;
   QComboBox*       myAvFields;
+  QLabel*          myDiscrLabel;
+  QLabel*          myDeflLabel;
+  QDoubleSpinBox*  myDeflSpinBox;
 };
 
 #endif
index 16d67a97c45b854ea73aa941cbe363ed2ad6f3de..b6fe4bde7eacdbe4fadd3bcbedf3ab7f868457ed 100644 (file)
@@ -2433,6 +2433,15 @@ file cannot be correctly imported for an Obstacle definition.</translation>
       <source>WRITE_ST_AS_ATTRS_TO_DBF</source>
       <translation>Write Strickler Types as attributes values to DBF file</translation>
     </message>
+    <message>
+      <source>LCM_DISCR_LABEL</source>
+      <translation>Current Land Cover Map contains at least one non-linear border. It will be exported in the discretization mode</translation>
+    </message>
+    <message>
+      <source>LCM_DEFL_LABEL</source>
+      <translation>Enter a deflection value:</translation>
+    </message>
+
   </context>