diff --git a/.antora/modules/specification/nav_openmaterial.adoc b/.antora/modules/specification/nav_openmaterial.adoc index 000c775c..5da36699 100644 --- a/.antora/modules/specification/nav_openmaterial.adoc +++ b/.antora/modules/specification/nav_openmaterial.adoc @@ -17,6 +17,5 @@ ** xref:material/Introduction.adoc[] ** xref:material/Fileformat.adoc[] ** xref:material/metadata.adoc[] -** xref:material/Material-parameters.adoc[] - - +** xref:material/material-properties.adoc[Material properties] +** xref:material/lookup-tables.adoc[] diff --git a/.github/workflows/antora-build.yml b/.github/workflows/antora-build.yml index 3b20adb2..81e2025a 100644 --- a/.github/workflows/antora-build.yml +++ b/.github/workflows/antora-build.yml @@ -32,6 +32,10 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index 9beb6353..5edd0aef 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ # Autogenerated files content/geometry/metadata.adoc -content/material/metadata.adoc \ No newline at end of file +content/material/metadata.adoc +content/material/material-properties.adoc +content/material/electromagnetic-properties.adoc diff --git a/content/material/Material-parameters.adoc b/content/material/Material-parameters.adoc deleted file mode 100644 index b57b2fa7..00000000 --- a/content/material/Material-parameters.adoc +++ /dev/null @@ -1 +0,0 @@ -= Material parameters \ No newline at end of file diff --git a/content/material/lookup-tables.adoc b/content/material/lookup-tables.adoc new file mode 100644 index 00000000..656e7ccb --- /dev/null +++ b/content/material/lookup-tables.adoc @@ -0,0 +1,3 @@ += Lookup tables + +include::electromagnetic-properties.adoc[leveloffset=+1] \ No newline at end of file diff --git a/content/material/general-structure-index.adoc b/content/material/material-index.adoc similarity index 58% rename from content/material/general-structure-index.adoc rename to content/material/material-index.adoc index 77016227..6b290bbd 100644 --- a/content/material/general-structure-index.adoc +++ b/content/material/material-index.adoc @@ -3,4 +3,5 @@ include::Introduction.adoc[leveloffset=+1] include::Fileformat.adoc[leveloffset=+1] include::metadata.adoc[leveloffset=+1] -include::Material-parameters.adoc[leveloffset=+1] +include::material-properties.adoc[leveloffset=+1] +include::lookup-tables.adoc[leveloffset=+1] diff --git a/examples/example_material.xomp b/examples/example_material.xomp index 97712223..3ef2c793 100644 --- a/examples/example_material.xomp +++ b/examples/example_material.xomp @@ -10,7 +10,7 @@ "name": "aluminum", "description": "aluminum material" }, - "materials_properties": { + "material_properties": { "surface_roughness": { "surface_height_rms": 0.8, "surface_correlation_length": 1.0 diff --git a/schemas/material_schema.json b/schemas/material_schema.json index b25f967d..3a431823 100644 --- a/schemas/material_schema.json +++ b/schemas/material_schema.json @@ -60,7 +60,7 @@ "description" ] }, - "materials_properties": { + "material_properties": { "type": "object", "description": "Properties related to the material.", "properties": { @@ -139,6 +139,6 @@ }, "required": [ "metadata", - "materials_properties" + "material_properties" ] } diff --git a/scripts/json2asciidoc.py b/scripts/json2asciidoc.py index 1a14c031..5f642a5a 100644 --- a/scripts/json2asciidoc.py +++ b/scripts/json2asciidoc.py @@ -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. """ @@ -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: @@ -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