From: asl Date: Tue, 17 Nov 2015 12:43:10 +0000 (+0300) Subject: refs #707: correct filtering of objects for land cover X-Git-Tag: v1.5~26^2~3^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=29a2cc8bbebc7006da047d8a5ea78e7c55394756;p=modules%2Fhydro.git refs #707: correct filtering of objects for land cover --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 08c7da1f..549402ca 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -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 index 00000000..350e1df0 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.cxx @@ -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 +#include +#include +#include +#include + +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 index 00000000..6983837f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_LandCoverArgsFilter.h @@ -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 + +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 diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx index 57bcaff7..91f3a973 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx @@ -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() ) diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h index 62fd5601..968db225 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h @@ -16,14 +16,11 @@ // 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 +#include 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 diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 4762aafb..f9fb4518 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -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 diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index 9c245ce2..96fb4c6e 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -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 index 00000000..20ef1481 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.cxx @@ -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 +#include +#include +#include +#include +#include + +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 index 00000000..207624ec --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_LandCoverMapDlg.h @@ -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 + +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");