From: asl Date: Mon, 1 Jun 2015 12:31:36 +0000 (+0300) Subject: refs #561: the draft data model for Strickler table X-Git-Tag: v1.4.1~6^2~4^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=866c6471c93c9e9e12d1557d7224ff614dd17bff;p=modules%2Fhydro.git refs #561: the draft data model for Strickler table --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 188d4d2b..5447d280 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -41,6 +41,7 @@ set(PROJECT_HEADERS HYDROData_SplitToZonesTool.h HYDROData_Stream.h HYDROData_StreamAltitude.h + HYDROData_StricklerTable.h HYDROData_Tool.h HYDROData_Transform.h HYDROData_VisualState.h @@ -92,6 +93,7 @@ set(PROJECT_SOURCES HYDROData_SplitToZonesTool.cxx HYDROData_Stream.cxx HYDROData_StreamAltitude.cxx + HYDROData_StricklerTable.cxx HYDROData_Tool.cxx HYDROData_Transform.cxx HYDROData_VisualState.cxx @@ -141,6 +143,7 @@ if(SALOME_BUILD_TESTS) test_HYDROData_Iterator.h test_HYDROData_OperationsFactory.h test_HYDROData_PolylineXY.h + test_HYDROData_StricklerTable.h ) set(TEST_SOURCES @@ -154,6 +157,7 @@ if(SALOME_BUILD_TESTS) test_HYDROData_Iterator.cxx test_HYDROData_OperationsFactory.cxx test_HYDROData_PolylineXY.cxx + test_HYDROData_StricklerTable.cxx ) set(TEST_EXE test_HYDROData) diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index df9ad5e9..29036275 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -63,6 +63,7 @@ const ObjectKind KIND_SHAPES_GROUP = 22; const ObjectKind KIND_SPLITTED_GROUP = 23; const ObjectKind KIND_STREAM_ALTITUDE = 24; const ObjectKind KIND_OBSTACLE_ALTITUDE = 25; +const ObjectKind KIND_STRICKLER_TABLE = 26; const ObjectKind KIND_LAST = KIND_OBSTACLE_ALTITUDE; DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared) diff --git a/src/HYDROData/HYDROData_StricklerTable.cxx b/src/HYDROData/HYDROData_StricklerTable.cxx new file mode 100644 index 00000000..903b915a --- /dev/null +++ b/src/HYDROData/HYDROData_StricklerTable.cxx @@ -0,0 +1,82 @@ +// 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 + +IMPLEMENT_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity ) +IMPLEMENT_STANDARD_RTTIEXT( HYDROData_StricklerTable, HYDROData_Entity ) + +HYDROData_StricklerTable::HYDROData_StricklerTable() +{ +} + +HYDROData_StricklerTable::~HYDROData_StricklerTable() +{ +} + +const ObjectKind HYDROData_StricklerTable::GetKind() const +{ + return KIND_STRICKLER_TABLE; +} + +bool HYDROData_StricklerTable::Import( const TCollection_AsciiString& theFileName ) +{ + FILE* aFile = fopen( theFileName.ToCString(), "r" ); + if( !aFile ) + return false; + + const int aBufLen = 256; + char aBuf[aBufLen]; + while( !feof( aFile ) ) + { + fgets( aBuf, aBufLen, aFile ); + std::string aStr = aBuf; + } + return false; +} + +bool HYDROData_StricklerTable::Export( const TCollection_AsciiString& theFileName ) +{ + //TODO + return false; +} + +double HYDROData_StricklerTable::Get( const TCollection_ExtendedString& theType, double theDefault ) const +{ + Handle( TDataStd_NamedData ) aMap = Map(); + if( aMap->HasReal( theType ) ) + return aMap->GetReal( theType ); + else + return theDefault; +} + +void HYDROData_StricklerTable::Set( const TCollection_ExtendedString& theType, double theCoefficient ) +{ + Handle( TDataStd_NamedData ) aMap = Map(); + aMap->SetReal( theType, theCoefficient ); +} + +Handle( TDataStd_NamedData ) HYDROData_StricklerTable::Map() const +{ + TDF_Label aLabel = myLab.FindChild( DataTag_Table ); + Handle( TDataStd_NamedData ) aMap; + if( !aLabel.FindAttribute( TDataStd_NamedData::GetID(), aMap ) ) + aMap = TDataStd_NamedData::Set( aLabel ); + return aMap; +} diff --git a/src/HYDROData/HYDROData_StricklerTable.h b/src/HYDROData/HYDROData_StricklerTable.h new file mode 100644 index 00000000..35a8a452 --- /dev/null +++ b/src/HYDROData/HYDROData_StricklerTable.h @@ -0,0 +1,54 @@ +// 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 HYDROData_STRICKLERTABLE_HeaderFile +#define HYDROData_STRICKLERTABLE_HeaderFile + +#include + +class Handle( TDataStd_NamedData ); + +DEFINE_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity ) + +class HYDROData_StricklerTable : public HYDROData_Entity +{ +protected: + enum DataTag + { + DataTag_Table = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + }; + + HYDRODATA_EXPORT HYDROData_StricklerTable(); + HYDRODATA_EXPORT ~HYDROData_StricklerTable(); + +public: + DEFINE_STANDARD_RTTI( HYDROData_StricklerTable ); + + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const; + + bool Import( const TCollection_AsciiString& theFileName ); + bool Export( const TCollection_AsciiString& theFileName ); + + double Get( const TCollection_ExtendedString& theType, double theDefault ) const; + void Set( const TCollection_ExtendedString& theType, double theCoefficient ); + +private: + Handle( TDataStd_NamedData ) Map() const; +}; + +#endif diff --git a/src/HYDROData/test_HYDROData_StricklerTable.cxx b/src/HYDROData/test_HYDROData_StricklerTable.cxx new file mode 100644 index 00000000..4cf57989 --- /dev/null +++ b/src/HYDROData/test_HYDROData_StricklerTable.cxx @@ -0,0 +1,30 @@ +// 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 + +void test_HYDROData_StricklerTable::testImport() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject( KIND_STRICKLER_TABLE ); + TCollection_AsciiString aFileName = "test_name"; + + aDoc->Close(); +} diff --git a/src/HYDROData/test_HYDROData_StricklerTable.h b/src/HYDROData/test_HYDROData_StricklerTable.h new file mode 100644 index 00000000..fcd1a388 --- /dev/null +++ b/src/HYDROData/test_HYDROData_StricklerTable.h @@ -0,0 +1,40 @@ +// 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 +// + +#ifdef WIN32 + #pragma warning( disable: 4251 ) +#endif + +#include + +class test_HYDROData_StricklerTable : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_HYDROData_StricklerTable ); + CPPUNIT_TEST( testImport ); + CPPUNIT_TEST_SUITE_END(); + +public: + void testImport(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_StricklerTable ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_StricklerTable, "HYDROData_StricklerTable" ); + +#ifdef WIN32 + #pragma warning( default: 4251 ) +#endif diff --git a/src/HYDROGUI/resources/def_strickler_table.txt b/src/HYDROGUI/resources/def_strickler_table.txt new file mode 100644 index 00000000..39ee171b --- /dev/null +++ b/src/HYDROGUI/resources/def_strickler_table.txt @@ -0,0 +1,8 @@ +"Zones de champs, prairies, sans cultures" 20.0 +"Zones de champs cultivé à végétation basse" 17.5 +"Zones de champs cultivé à végétation haute" 12.5 +"Zones d'arbustes, de sous-bois" 10.0 +"Zones à faible urbanization (bourg)" 9.0 +"Zones à forte urbanization (agglomération)" 9.0 +"Canaux naturels" 35.0 +"Canaux artificiels en béton" 65.0