]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #707: correct filtering of objects for land cover
authorasl <asl@opencascade.com>
Tue, 17 Nov 2015 12:43:10 +0000 (15:43 +0300)
committerasl <asl@opencascade.com>
Tue, 17 Nov 2015 12:43:10 +0000 (15:43 +0300)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/ExternalFiles.cmake
src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.cxx [new file with mode: 0644]
src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.h [new file with mode: 0644]

index 08c7da1f49831e3a5be51074e62df823be7deee4..549402caaa3e8a87aafa81a93864f3fff8a779fe 100644 (file)
@@ -45,6 +45,7 @@ set(PROJECT_HEADERS
     HYDROGUI_ExportSinusXDlg.h
     HYDROGUI_ExportLandCoverMapDlg.h
     HYDROGUI_InputPanel.h
+    HYDROGUI_LandCoverArgsFilter.h
     HYDROGUI_LandCoverMapDlg.h
     HYDROGUI_LandCoverMapOp.h
     HYDROGUI_LandCoverMapPrs.h
@@ -188,6 +189,7 @@ set(PROJECT_SOURCES
     HYDROGUI_ExportSinusXDlg.cxx
     HYDROGUI_ExportLandCoverMapDlg.cxx
     HYDROGUI_InputPanel.cxx
+    HYDROGUI_LandCoverArgsFilter.cxx
     HYDROGUI_LandCoverMapDlg.cxx
     HYDROGUI_LandCoverMapOp.cxx
     HYDROGUI_LandCoverMapPrs.cxx
diff --git a/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.cxx b/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.cxx
new file mode 100644 (file)
index 0000000..350e1df
--- /dev/null
@@ -0,0 +1,59 @@
+// 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_LandCoverArgsFilter.h>
+#include <HYDROGUI_Operations.h>
+#include <HYDROData_ArtificialObject.h>
+#include <HYDROData_NaturalObject.h>
+#include <HYDROData_PolylineXY.h>
+
+HYDROGUI_LandCoverArgsFilter::HYDROGUI_LandCoverArgsFilter( int theOperationId )
+  : myOperationId( theOperationId )
+{
+}
+
+HYDROGUI_LandCoverArgsFilter::~HYDROGUI_LandCoverArgsFilter()
+{
+}
+
+bool HYDROGUI_LandCoverArgsFilter::isOk( const Handle(HYDROData_Entity)& theEntity ) const
+{
+  if( theEntity.IsNull() )
+    return false;
+
+  ObjectKind aKind = theEntity->GetKind();
+  if( aKind==KIND_POLYLINEXY )
+  {
+    Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theEntity );
+    switch( myOperationId )
+    {
+    case CreateLandCoverMapId:
+    case AddLandCoverId:
+      return aPolylineXY->IsClosed();  // only closed polylines are allowed
+    case SplitLandCoverId:
+      return true;  // any polylines are allowed
+    default:
+      return false;
+    }
+  }
+
+  Handle(HYDROData_NaturalObject) aNaturalObject = Handle(HYDROData_NaturalObject)::DownCast( theEntity );
+  Handle(HYDROData_ArtificialObject) anArtificialObject = Handle(HYDROData_ArtificialObject)::DownCast( theEntity );
+  bool isOK = !aNaturalObject.IsNull() || !anArtificialObject.IsNull();
+  return isOK;
+}
diff --git a/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.h b/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.h
new file mode 100644 (file)
index 0000000..6983837
--- /dev/null
@@ -0,0 +1,36 @@
+// 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_LANDCOVER_ARGS_FILTER_H
+#define HYDROGUI_LANDCOVER_ARGS_FILTER_H
+
+#include <HYDROGUI_ObjComboBox.h>
+
+class HYDROGUI_LandCoverArgsFilter : public HYDROGUI_ObjComboBoxFilter
+{
+public:
+  HYDROGUI_LandCoverArgsFilter( int theOperationId );
+  virtual ~HYDROGUI_LandCoverArgsFilter();
+
+  virtual bool isOk( const Handle(HYDROData_Entity)& theEntity ) const;
+
+private:
+  int myOperationId;
+};
+
+#endif
index 57bcaff7f1760f529b5ee8e4ebbbdfa7ce3cef70..91f3a973326ef6b36d0623fbeb809959c7955345 100644 (file)
@@ -34,8 +34,8 @@ HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule,
                                                     const QString& theTitle,
                                                     const int theOperationId )
 : HYDROGUI_InputPanel( theModule, theTitle ),
-  HYDROGUI_ObjComboBoxFilter(),
-  myOperationId( theOperationId )
+  myOperationId( theOperationId ),
+  myFilter( theOperationId )
 {
   // Land Cover Map name
   myObjectNameGroup = new QGroupBox( tr( "LAND_COVER_MAP_NAME" ), mainFrame() );
@@ -60,7 +60,7 @@ HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule,
   myPolylinesFacesLabel = new QLabel( tr( "LAND_COVER_MAP_POLYLINE_FACE" ) );
   aParamLayout->addWidget( myPolylinesFacesLabel, 0, 0, 1, 1 );
   aParamLayout->addWidget( myPolylinesFaces = new HYDROGUI_ObjComboBox( theModule, "", KIND_UNKNOWN, myParamGroup ), 0, 1, 1, 1 );
-  myPolylinesFaces->setObjectFilter( this );
+  myPolylinesFaces->setObjectFilter( &myFilter );
 
   // Strickler type name
   myStricklerTypesLabel = new QLabel( tr( "LAND_COVER_MAP_STRICKLER_TYPE" ), myParamGroup );
@@ -147,15 +147,6 @@ QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const
   return myStricklerTypes->getSelectedStricklerTypeName();
 }
 
-bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
-{
-  Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast(theEntity);
-  Handle(HYDROData_Object) anObject2d3dPrs = Handle(HYDROData_Object)::DownCast(theEntity);  
-  return ( !anObject2d3dPrs.IsNull() ||
-           ( !aPolylineXY.IsNull() && ( ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId ) && aPolylineXY->IsClosed() ||
-                                        myOperationId == SplitLandCoverId ) ) );
-}
-
 void HYDROGUI_LandCoverMapDlg::onLandCoverMapChanged()
 {
   if ( signalsBlocked() )
index 62fd560189cbe13d4ea2ac8008bac54dacd6e649..968db2252061f41230c501e0192799e26e5129b8 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-// REMOVED FROM THE PROJECT, BUT KEPT AS A REFERENCE FILE. TO BE DELETED LATER.
-
 #ifndef HYDROGUI_LANDCOVERMAPDLG_H
 #define HYDROGUI_LANDCOVERMAPDLG_H
 
-#include "HYDROGUI_InputPanel.h"
-
-#include "HYDROGUI_ObjComboBox.h"
+#include <HYDROGUI_InputPanel.h>
+#include <HYDROGUI_LandCoverArgsFilter.h>
 
 class HYDROGUI_StricklerTypeComboBox;
 
@@ -31,7 +28,7 @@ class QGroupBox;
 class QLineEdit;
 class QLabel;
 
-class HYDROGUI_LandCoverMapDlg : public HYDROGUI_InputPanel, public HYDROGUI_ObjComboBoxFilter
+class HYDROGUI_LandCoverMapDlg : public HYDROGUI_InputPanel
 {
   Q_OBJECT
 
@@ -52,8 +49,6 @@ public:
   void                     setSelectedStricklerTypeName( const QString& theName );
   QString                  getSelectedStricklerTypeName() const;
 
-  virtual bool             isOk( const Handle(HYDROData_Entity)& ) const;
-
 signals:
   void                     landCoverMapChanged( const QString& theName );
 
@@ -75,6 +70,7 @@ private:
   HYDROGUI_ObjComboBox*           myPolylinesFaces;
   QLabel*                         myStricklerTypesLabel;
   HYDROGUI_StricklerTypeComboBox* myStricklerTypes;
+  HYDROGUI_LandCoverArgsFilter    myFilter;
 };
 
 #endif
index 4762aafb443efcb21e33a14e25853f9d45b0e97d..f9fb451832086fdb37bf8e14ef581035f821f2b7 100644 (file)
@@ -16,6 +16,7 @@ set(PROJECT_HEADERS
   test_HYDROData_StricklerTable.h
   test_HYDROGUI_ListModel.h
   test_HYDROGUI_Shape.h
+  test_HYDROGUI_LandCoverMapDlg.h
   test_Dependencies.h
 
   TestShape.h
@@ -40,6 +41,7 @@ set(PROJECT_SOURCES
   test_HYDROData_StricklerTable.cxx
   test_HYDROGUI_ListModel.cxx
   test_HYDROGUI_Shape.cxx
+  test_HYDROGUI_LandCoverMapDlg.cxx
   test_Dependencies.cxx
 
   TestShape.cxx
index 9c245ce2294ae6909c6d3ece6393673fa831a2ec..96fb4c6ef34e40b657f24f4f056f893374d76367 100644 (file)
@@ -56,6 +56,7 @@ set( EXTERNAL_FILES
   ../HYDROGUI/HYDROGUI_ListModel.cxx
   ../HYDROGUI/HYDROGUI_DataObject.cxx
   ../HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx
+  ../HYDROGUI/HYDROGUI_LandCoverArgsFilter.cxx
   ../HYDROGUI/HYDROGUI_Polyline.cxx
   ../HYDROGUI/HYDROGUI_AISShape.cxx
   ../HYDROGUI/HYDROGUI_Shape.cxx
diff --git a/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.cxx b/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.cxx
new file mode 100644 (file)
index 0000000..20ef148
--- /dev/null
@@ -0,0 +1,91 @@
+// 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
+//
+
+#undef HYDROGUI_EXPORTS
+
+#include <test_HYDROGUI_LandCoverMapDlg.h>
+#include <HYDROGUI_LandCoverArgsFilter.h>
+#include <HYDROGUI_Operations.h>
+#include <HYDROData_Document.h>
+#include <HYDROData_PolylineXY.h>
+#include <gp_XY.hxx>
+
+bool isOK( const HYDROGUI_LandCoverArgsFilter& theFilter, 
+           const Handle(HYDROData_Document)& theDocument,
+           ObjectKind theKind )
+{
+  Handle(HYDROData_Entity) anEntity = theDocument->CreateObject( theKind );
+  return theFilter.isOk( anEntity );
+}
+
+void test_HYDROGUI_LandCoverMapDlg::test_objects_filtering_refs_707()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+  
+  HYDROGUI_LandCoverArgsFilter f( AddLandCoverId );
+
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_IMAGE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_POLYLINE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_BATHYMETRY ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_ALTITUDE ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_IMMERSIBLE_ZONE ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_RIVER ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_STREAM ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_CONFLUENCE ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_CHANNEL ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_OBSTACLE ) );
+  CPPUNIT_ASSERT_EQUAL( true,  isOK( f, aDoc, KIND_DIGUE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_PROFILE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_PROFILEUZ ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_CALCULATION ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_ZONE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_REGION ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_VISUAL_STATE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_ARTIFICIAL_OBJECT ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_NATURAL_OBJECT ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_DUMMY_3D ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_SHAPES_GROUP ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_SPLITTED_GROUP ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_STREAM_ALTITUDE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_OBSTACLE_ALTITUDE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_STRICKLER_TABLE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_LAND_COVER_OBSOLETE ) );
+  CPPUNIT_ASSERT_EQUAL( false, isOK( f, aDoc, KIND_LAND_COVER_MAP ) );
+
+  Handle(HYDROData_PolylineXY) aClosedPoly = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  aClosedPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, true );
+  aClosedPoly->AddPoint( 0, gp_XY( 0, 0 ) );
+  aClosedPoly->AddPoint( 0, gp_XY( 20, 0 ) );
+  aClosedPoly->AddPoint( 0, gp_XY( 10, 10 ) );
+  aClosedPoly->Update();
+  CPPUNIT_ASSERT_EQUAL( true, f.isOk( aClosedPoly ) );
+
+  Handle(HYDROData_PolylineXY) anOpenPoly = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  anOpenPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
+  anOpenPoly->AddPoint( 0, gp_XY( 0, 0 ) );
+  anOpenPoly->AddPoint( 0, gp_XY( 20, 0 ) );
+  anOpenPoly->AddPoint( 0, gp_XY( 10, 10 ) );
+  anOpenPoly->Update();
+  CPPUNIT_ASSERT_EQUAL( false, f.isOk( anOpenPoly ) );
+
+  HYDROGUI_LandCoverArgsFilter fs( SplitLandCoverId );
+  CPPUNIT_ASSERT_EQUAL( true, fs.isOk( aClosedPoly ) );
+  CPPUNIT_ASSERT_EQUAL( true, fs.isOk( anOpenPoly ) );
+
+  aDoc->Close();
+}
diff --git a/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.h b/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.h
new file mode 100644 (file)
index 0000000..207624e
--- /dev/null
@@ -0,0 +1,32 @@
+// 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 <cppunit/extensions/HelperMacros.h>
+
+class test_HYDROGUI_LandCoverMapDlg : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE(test_HYDROGUI_LandCoverMapDlg);
+  CPPUNIT_TEST(test_objects_filtering_refs_707);
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+  void test_objects_filtering_refs_707();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_LandCoverMapDlg);
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_LandCoverMapDlg, "HYDROGUI_LandCoverMapDlg");