]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1456: correct Python name on dump ECW images
authorasl <asl@opencascade.com>
Fri, 1 Dec 2017 09:25:34 +0000 (12:25 +0300)
committerasl <asl@opencascade.com>
Fri, 1 Dec 2017 09:25:34 +0000 (12:25 +0300)
src/HYDROData/HYDROData_Entity.cxx
src/HYDROData/HYDROData_Entity.h
src/HYDRO_tests/test_HYDROData_Entity.cxx
src/HYDRO_tests/test_HYDROData_Entity.h

index 62a7095e0f181f97a07fb36c24cf8628555d0ea5..32670b80f3da324fd1237f8c05b5c3cb2ac10c92 100644 (file)
@@ -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;
 }
 
index ddd2ae8a831f04b080ebd8dcb1725dd5e6d3362b..2396654f6623f463f049d5b2069229627b742ec5 100644 (file)
@@ -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<QString,Handle(Standard_Transient)>
 {
@@ -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.
    */
index 9bdeb4c5380d230aaf0954d8021cddc5d53d97ed..ca377c32f91a62bdba62ec72241d3759bf0f851f 100644 (file)
@@ -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<KIND_LAST; i++ )
+  {
+    CPPUNIT_ASSERT_EQUAL( false, HYDROData_Entity::Type( (ObjectKind)i ).isEmpty() );
+    CPPUNIT_ASSERT_EQUAL( false, HYDROData_Entity::Type( (ObjectKind)i ).contains(' ') );
+  }
+}
index 8a0dec7e4a380e44e42dd51c3b071abb99cd58f6..f206ae7c805f902d25a209b67fc94fd526833e29 100644 (file)
@@ -23,6 +23,8 @@ class test_HYDROData_Entity : public CppUnit::TestFixture {
   CPPUNIT_TEST(testName);
   CPPUNIT_TEST(testRemove);
   CPPUNIT_TEST(testCopy);
+  CPPUNIT_TEST(testPythonNameChoice);
+  CPPUNIT_TEST(testTypes);
   CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -41,6 +43,9 @@ public:
 
   // checks the copying of object
   void testCopy();
+
+  void testPythonNameChoice();
+  void testTypes();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Entity);