From 926110b557c276a493e3b6066bb0a598b124d36b Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 1 Dec 2017 12:25:34 +0300 Subject: [PATCH] refs #1456: correct Python name on dump ECW images --- src/HYDROData/HYDROData_Entity.cxx | 78 +++++++++++++++++++++++ src/HYDROData/HYDROData_Entity.h | 5 +- src/HYDRO_tests/test_HYDROData_Entity.cxx | 36 +++++++++++ src/HYDRO_tests/test_HYDROData_Entity.h | 5 ++ 4 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index 62a7095e..32670b80 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -77,11 +77,89 @@ QString HYDROData_Entity::GetName() const return QString(); } +QString HYDROData_Entity::GetType() const +{ + return Type( GetKind() ); +} + +QString HYDROData_Entity::Type( ObjectKind theKind ) +{ + switch( theKind ) + { + case KIND_UNKNOWN: + return "Unknown"; + case KIND_IMAGE: + return "Image"; + case KIND_POLYLINE: + return "Polyline"; + case KIND_BATHYMETRY: + return "Bathymetry"; + case KIND_ALTITUDE: + return "Altitude"; + case KIND_IMMERSIBLE_ZONE: + return "Immersible_zone"; + case KIND_RIVER: + return "River"; + case KIND_STREAM: + return "Stream"; + case KIND_CONFLUENCE: + return "Confluence"; + case KIND_CHANNEL: + return "Channel"; + case KIND_OBSTACLE: + return "Obstacle"; + case KIND_DIGUE: + return "Digue"; + case KIND_PROFILE: + return "Profile"; + case KIND_PROFILEUZ: + return "Profile_UZ"; + case KIND_POLYLINEXY: + return "Polyline_XY"; + case KIND_CALCULATION: + return "Calculation_case"; + case KIND_ZONE: + return "Zone"; + case KIND_REGION: + return "Region"; + case KIND_VISUAL_STATE: + return "Visual_state"; + case KIND_ARTIFICIAL_OBJECT: + return "Artificial_object"; + case KIND_NATURAL_OBJECT: + return "Natural_object"; + case KIND_DUMMY_3D: + return "Dummy_3d"; + case KIND_SHAPES_GROUP: + return "Shapes_group"; + case KIND_SPLIT_GROUP: + return "Split_group"; + case KIND_STREAM_ALTITUDE: + return "Stream_altitude"; + case KIND_OBSTACLE_ALTITUDE: + return "Obstacle_altitude"; + case KIND_STRICKLER_TABLE: + return "Strickler_table"; + case KIND_LAND_COVER_OBSOLETE: + return "Land_cover"; + case KIND_CHANNEL_ALTITUDE: + return "Channel_altitude"; + case KIND_LAND_COVER_MAP: + return "Land_cover_map"; + case KIND_DTM: + return "DTM"; + } + return ""; +} + QString HYDROData_Entity::GetObjPyName() const { QString aName = GetName(); aName.replace(QRegExp("[\\W]"), "_"); + if( aName[0].isDigit() ) + aName = GetType() + "_" + aName; + return aName; } diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index ddd2ae8a..2396654f 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -76,7 +76,7 @@ const ObjectKind KIND_LAND_COVER_OBSOLETE = 27; const ObjectKind KIND_CHANNEL_ALTITUDE = 28; const ObjectKind KIND_LAND_COVER_MAP = 29; const ObjectKind KIND_DTM = 30; -const ObjectKind KIND_LAST = KIND_DTM; +const ObjectKind KIND_LAST = KIND_DTM+1; class MapOfTreatedObjects : public QMap { @@ -130,6 +130,9 @@ public: public: DEFINE_STANDARD_RTTIEXT(HYDROData_Entity, MMgt_TShared); + HYDRODATA_EXPORT static QString Type( ObjectKind ); + HYDRODATA_EXPORT virtual QString GetType() const; + /** * Returns the kind of this object. Must be redefined in all objects of known type. */ diff --git a/src/HYDRO_tests/test_HYDROData_Entity.cxx b/src/HYDRO_tests/test_HYDROData_Entity.cxx index 9bdeb4c5..ca377c32 100644 --- a/src/HYDRO_tests/test_HYDROData_Entity.cxx +++ b/src/HYDRO_tests/test_HYDROData_Entity.cxx @@ -64,3 +64,39 @@ void test_HYDROData_Entity::testCopy() aDoc->Close(); } + +void test_HYDROData_Entity::testPythonNameChoice() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object + + anObj->SetName("test"); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test" ) ); + + anObj->SetName("test_1"); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test_1" ) ); + + anObj->SetName("test 1"); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test_1" ) ); + + anObj->SetName(" test abc hello "); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "__test_abc____hello_____" ) ); + + anObj->SetName("123"); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "Image_123" ) ); + + anObj->SetName(" 123"); + CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "__123" ) ); + + aDoc->Close(); +} + +void test_HYDROData_Entity::testTypes() +{ + for( int i=0; i