Skip to content

Commit

Permalink
Merge branch 'main' into 5-retroreflectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensLinnhoff committed Sep 17, 2024
2 parents 7f7fde7 + 89d2146 commit 07ad0f8
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .antora/modules/specification/nav_openmaterial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* Material
** xref:material/Introduction.adoc[]
** xref:material/Fileformat.adoc[]
** xref:material/Metadata.adoc[]
** xref:material/Material-parameters.adoc[]
** xref:material/metadata.adoc[]
** xref:material/material-properties.adoc[Material properties]
** xref:material/lookup-tables.adoc[]
13 changes: 9 additions & 4 deletions .github/workflows/antora-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ jobs:

- name: Generate AsciiDoc from JSON
working-directory: scripts
run: python3 json2asciidoc.py ../schemas/asset_schema.json metadata

- name: Copy generated AsciiDoc
run: cp scripts/metadata.adoc content/geometry/metadata.adoc
run: |
python3 json2asciidoc.py ../schemas/asset_schema.json metadata
mv metadata.adoc ../content/geometry/
python3 json2asciidoc.py ../schemas/material_schema.json metadata
mv metadata.adoc ../content/material/
python3 json2asciidoc.py ../schemas/material_schema.json material_properties
mv material_properties.adoc ../content/material/material-properties.adoc
python3 json2asciidoc.py ../schemas/material_emp_schema.json electromagnetic_properties
mv electromagnetic_properties.adoc ../content/material/electromagnetic-properties.adoc
- name: Configure Pages
uses: actions/configure-pages@v4
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# IDE specific files
.vscode/
.idea/
.idea/

# Autogenerated files
content/geometry/metadata.adoc
content/material/metadata.adoc
content/material/material-properties.adoc
content/material/electromagnetic-properties.adoc
1 change: 0 additions & 1 deletion content/material/Material-parameters.adoc

This file was deleted.

1 change: 0 additions & 1 deletion content/material/Metadata.adoc

This file was deleted.

6 changes: 0 additions & 6 deletions content/material/general-structure-index.adoc

This file was deleted.

3 changes: 3 additions & 0 deletions content/material/lookup-tables.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= Lookup tables

include::electromagnetic-properties.adoc[leveloffset=+1]
7 changes: 7 additions & 0 deletions content/material/material-index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= Material

include::Introduction.adoc[leveloffset=+1]
include::Fileformat.adoc[leveloffset=+1]
include::metadata.adoc[leveloffset=+1]
include::material-properties.adoc[leveloffset=+1]
include::lookup-tables.adoc[leveloffset=+1]
11 changes: 10 additions & 1 deletion examples/example_material.xomp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
"name": "aluminum",
"description": "aluminum material"
},
"materials_properties": {
"material_properties": {
"surface_roughness": {
"surface_height_rms": 0.8,
"surface_correlation_length": 1.0
},
"elasticity_data": {
"youngs_modulus": 70e9,
"poissons_ratio": 0.35,
"source": "internet: https://en.wikipedia.org/wiki/Aluminium"
},
"density_data": {
"density": 2699.0,
"source": "internet: https://en.wikipedia.org/wiki/Aluminium"
},
"electromagnetic_properties_uri": "example_material_emp.xompt"
}
}
57 changes: 50 additions & 7 deletions schemas/material_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"description"
]
},
"materials_properties": {
"material_properties": {
"type": "object",
"description": "Properties related to the material.",
"properties": {
Expand All @@ -82,6 +82,52 @@
"surface_correlation_length"
]
},
"elasticity_data": {
"type": "object",
"description": "Information about the elasticity of the material.",
"properties": {
"youngs_modulus": {
"type": "number",
"description": "Young's modulus of the material in Pa."
},
"poissons_ratio": {
"type": "number",
"description": "Poisson's ratio of the material."
},
"source": {
"type": "string",
"description": "Source of the elasticity data."
}
},
"required": [
"youngs_modulus",
"poissons_ratio",
"source"
]
},
"density_data": {
"type": "object",
"description": "Information about the density of the material.",
"properties": {
"density": {
"type": "number",
"description": "Density of the material in kg/m^3."
},
"source": {
"type": "string",
"description": "Source of the density data."
}
},
"required": [
"density",
"source"
]
},
"electromagnetic_properties_uri": {
"type": "string",
"description": "Relative path to a property lookup table file with electromagnetic material properties.",
"pattern": ".*_emp\\.xompt$"
},
"retroreflectivity_data": {
"type": "object",
"description": "Information about the retro-reflective properties of the material in the visible light spectrum.",
Expand All @@ -99,21 +145,18 @@
"coefficient_of_retroreflection",
"source"
]
},
"electromagnetic_properties_uri": {
"type": "string",
"description": "Relative path to a property lookup table file with electromagnetic material properties.",
"pattern": ".*_emp\\.xompt$"
}
},
"required": [
"surface_roughness",
"elasticity_data",
"density_data",
"electromagnetic_properties_uri"
]
}
},
"required": [
"metadata",
"materials_properties"
"material_properties"
]
}
104 changes: 90 additions & 14 deletions scripts/json2asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
def escape_special_chars(pattern):
"""
Escape special characters in the pattern string for AsciiDoc compatibility.
Args:
pattern (str): The pattern string to be escaped.
Returns:
str: The escaped pattern string.
"""
Expand All @@ -17,25 +17,60 @@ def escape_special_chars(pattern):
return pattern


def generate_asciidoc(field_name, schema, required_fields):
def generate_asciidoc_array_of_arrays(items, description):
"""
Generate AsciiDoc content for the specified field based on the JSON schema.
Generate AsciiDoc content for an array of arrays, listing each item as a column.
Args:
field_name (str): The name of the field to generate documentation for.
schema (dict): The JSON schema dictionary.
required_fields (list): List of required fields for the specified field.
items (list): The list of item schemas in the array.
description (str): The description of the array.
Returns:
str: The generated AsciiDoc content describing the columns.
"""
content = ""
if description:
content += f"{description}\n"

content += "\nColumns of the table:\n\n"

for idx, item in enumerate(items, start=1):
item_description = item.get('description', 'No description')
content += f"- Column {idx}: {item_description}\n"

return content


def generate_asciidoc_properties(properties, required_fields, level=2):
"""
Recursively generate AsciiDoc content for a dictionary of properties.
Args:
properties (dict): The dictionary of properties from the JSON schema.
required_fields (list): The list of required fields.
level (int): The current heading level in the AsciiDoc file.
Returns:
str: The generated AsciiDoc content.
str: The generated AsciiDoc content for the properties.
"""
asciidoc_content = f"= {field_name.capitalize()}\n\n"
field_data = schema['properties'][field_name]
asciidoc_content += field_data.get("description", "") + "\n\n"
asciidoc_content = ""

for prop_name, prop_data in field_data['properties'].items():
asciidoc_content += f"== {prop_name}\n"
for prop_name, prop_data in properties.items():
heading_prefix = "=" * level # Create heading based on level
asciidoc_content += f"{heading_prefix} {prop_name}\n"
asciidoc_content += f"{prop_data.get('description', 'No description')}\n"

# Handle array types and generate description for array of arrays
if prop_data.get('type') == "array":
if isinstance(prop_data['items'], dict) and 'items' in prop_data['items']:
# Generate list for array of arrays
asciidoc_content += generate_asciidoc_array_of_arrays(prop_data['items']['items'], prop_data['items'].get('description', '')) + "\n"
elif isinstance(prop_data['items'], list):
# If it's a list of items, generate columns description directly
asciidoc_content += generate_asciidoc_array_of_arrays(prop_data['items'], prop_data.get('description', '')) + "\n"
else:
# Simple array, include the description of the array
asciidoc_content += f"\n{prop_data['items'].get('description', 'No description')}\n"

# Add pattern inline and handle escaping of backslashes and curly braces
if "pattern" in prop_data:
Expand All @@ -49,7 +84,48 @@ def generate_asciidoc(field_name, schema, required_fields):
asciidoc_content += "\n*Required:* No\n"

asciidoc_content += "\n"

# If there are nested properties, recursively generate content for them
if "properties" in prop_data:
nested_required_fields = prop_data.get('required', [])
asciidoc_content += generate_asciidoc_properties(
prop_data['properties'], nested_required_fields, level + 1
)

return asciidoc_content


def generate_asciidoc(field_name, schema, required_fields):
"""
Generate AsciiDoc content for the specified field based on the JSON schema.
Args:
field_name (str): The name of the field to generate documentation for.
schema (dict): The JSON schema dictionary.
required_fields (list): List of required fields for the specified field.
Returns:
str: The generated AsciiDoc content.
"""
asciidoc_content = f"= {field_name.capitalize()}\n\n"
field_data = schema['properties'][field_name]
asciidoc_content += field_data.get("description", "") + "\n\n"

# Generate the content for the properties, recursively handling nested properties
if 'properties' in field_data:
asciidoc_content += generate_asciidoc_properties(field_data['properties'], required_fields, level=2)
elif field_data.get('type') == 'array':
# Handle array fields directly
if 'items' in field_data and isinstance(field_data['items'], dict) and 'items' in field_data['items']:
# Array of arrays, generate list of columns
asciidoc_content += generate_asciidoc_array_of_arrays(field_data['items']['items'], field_data['items'].get('description', '')) + "\n"
elif isinstance(field_data['items'], list):
# Array of simple types, generate columns description
asciidoc_content += generate_asciidoc_array_of_arrays(field_data['items'], field_data.get('description', '')) + "\n"
else:
# Handle single item in array
asciidoc_content += f"\n{field_data['items'].get('description', 'No description')}\n"

return asciidoc_content


Expand Down

0 comments on commit 07ad0f8

Please sign in to comment.