소스 검색

refactor enumerations

Bert Temme 1 년 전
부모
커밋
1b6a1cb697
2개의 변경된 파일26개의 추가작업 그리고 20개의 파일을 삭제
  1. 15 7
      src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs
  2. 11 13
      tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

+ 15 - 7
src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs

@@ -1207,7 +1207,7 @@ namespace SharpGLTF.Schema2
             public string EnumType
             {
                 get => _enumType;
-                set => _enumType = value;
+                // set => _enumType = value;
             }
 
             public DATATYPE? ComponentType
@@ -1277,17 +1277,25 @@ namespace SharpGLTF.Schema2
                 return this;
             }
 
-            public StructuralMetadataClassProperty WithEnumArrayType(StructuralMetadataEnum enumType, int? count = null)
+            public StructuralMetadataClassProperty WithEnumArrayType(StructuralMetadataEnum enumeration, int? count = null)
             {
-                return WithEnumArrayType(enumType.LogicalKey, count);
+                Type = ELEMENTTYPE.ENUM;
+                _enumType = enumeration.LogicalKey;
+                Array = true;
+                Count = count;
+                return this;
             }
 
-            public StructuralMetadataClassProperty WithEnumArrayType(string enumType, int? count = null)
+            public StructuralMetadataClassProperty WithEnumeration(StructuralMetadataEnum enumeration)
             {
                 Type = ELEMENTTYPE.ENUM;
-                EnumType = enumType;                
-                Array = true;
-                Count = count;
+                _enumType = enumeration.LogicalKey;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithRequired(bool required)
+            {
+                Required = required;
                 return this;
             }
 

+ 11 - 13
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -150,10 +150,10 @@ namespace SharpGLTF.Schema2.Tiles3D
             // species property
             var speciesProperty = treeClass
                 .UseProperty("species")
-                .WithDescription("Type of tree.");
+                .WithDescription("Type of tree.")
+                .WithEnumeration(speciesEnum)
+                .WithRequired(true);
             
-            speciesProperty.Type = ElementType.ENUM;
-            speciesProperty.EnumType = "speciesEnum";
             speciesProperty.Required = true;
                
             // age property
@@ -596,14 +596,14 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .SetArrayValues(bools);
 
             var strings = new List<List<string>>();
-            strings.Add(new List<string>() { "Example string 1", "Example string 2", "Example string 3" });
+            strings.Add(["Example string 1", "Example string 2", "Example string 3"]);
             examplePropertyTable
                 .UseProperty(variableLengthStringArrayProperty)
                 .SetArrayValues(strings);
 
             // Fill property table with enum values
             var shorts = new List<List<short>>();
-            shorts.Add(new List<short>() { 0, 1 });
+            shorts.Add([0, 1]);
             examplePropertyTable
                 .UseProperty(fixed_length_ARRAY_ENUM)
                 .SetArrayValues(shorts);
@@ -737,20 +737,18 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .WithName("Example metadata class")
                 .WithDescription("An example metadata class for property attributes");
 
-            var intensityProperty = classA.UseProperty("intensity")
+            classA.UseProperty("intensity")
                 .WithName("Example intensity property")
                 .WithDescription("An example property for the intensity, with component type FLOAT32")
                 .WithValueType(ElementType.SCALAR, DataType.FLOAT32);
 
-            var classificationProperty = classA
+            var speciesEnum = schema.UseEnumMetadata("classificationEnumType", ("MediumVegetation", 0), ("Buildings", 1));
+
+            classA
                 .UseProperty("classification")
                 .WithName("Example classification property")
-                .WithDescription("An example property for the classification, with the classificationEnumType");
-
-            classificationProperty.Type = ElementType.ENUM;
-            classificationProperty.EnumType = "classificationEnumType";
-
-            var speciesEnum = schema.UseEnumMetadata("classificationEnumType", ("MediumVegetation", 0), ("Buildings", 1));
+                .WithDescription("An example property for the classification, with the classificationEnumType")
+                .WithEnumeration(speciesEnum);
 
             // todo: add propertyAttributes