-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from 3MFConsortium/3djan/implicit_improvements
Improvements to the volumetric spec
- Loading branch information
Showing
10 changed files
with
1,876 additions
and
1,459 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import re | ||
import sys | ||
|
||
def change_namespace_prefix_md(md_file, elements, new_prefix): | ||
# Read the Markdown file | ||
with open(md_file, 'r') as f: | ||
content = f.read() | ||
|
||
# Find XML snippets | ||
snippets = re.findall(r'```xml(.*?)```', content, re.DOTALL) | ||
|
||
for snippet in snippets: | ||
original_snippet = snippet | ||
print (f"Snippet: {snippet}") | ||
# Replace the namespace prefix in the XML snippet | ||
for element in elements: | ||
snippet = re.sub(rf'<{element} ', f'<{new_prefix}:{element} ', snippet, flags=re.IGNORECASE) | ||
snippet = re.sub(rf'</{element}>', f'</{new_prefix}:{element}>', snippet, flags=re.IGNORECASE) | ||
snippet = re.sub(rf'<{element}>', f'<{new_prefix}:{element}>', snippet, flags=re.IGNORECASE) | ||
snippet = re.sub(rf'</{element} ', f'</{new_prefix}:{element} ', snippet, flags=re.IGNORECASE) | ||
|
||
|
||
|
||
print (f"New snippet: {snippet}") | ||
print("-" * 80) | ||
# Replace the original XML snippet with the modified one | ||
content = content.replace(original_snippet, f'\n{snippet}\n') | ||
|
||
# Write the modified Markdown back to the file | ||
with open(md_file, 'w') as f: | ||
f.write(content) | ||
|
||
f.close() | ||
|
||
def change_namespace_prefix_md_from_file(md_file, elements_file, new_prefix): | ||
# Read the elements file | ||
with open(elements_file, 'r') as f: | ||
elements = [line.strip() for line in f] | ||
|
||
change_namespace_prefix_md(md_file, elements, new_prefix) | ||
|
||
def apply_implicit_prefix(md_file): | ||
prefix = "i" | ||
elements = [ | ||
"implicitfunction", | ||
"scalar", | ||
"vector", | ||
"matrix", | ||
"resourceid", | ||
"in", | ||
"out", | ||
"scalarref", | ||
"vectorref", | ||
"matrixref", | ||
"resourceref", | ||
"addition", | ||
"subtraction", | ||
"multiplication", | ||
"division", | ||
"constant", | ||
"constvec", | ||
"constmat", | ||
"composevector", | ||
"vectorfromscalar", | ||
"decomposevector", | ||
"composematrix", | ||
"matrixfromcolumns", | ||
"matrixfromrows", | ||
"dot", | ||
"cross", | ||
"matvecmultiplication", | ||
"transpose", | ||
"inverse", | ||
"sin", | ||
"cos", | ||
"tan", | ||
"arcsin", | ||
"arccos", | ||
"arctan", | ||
"arctan2", | ||
"min", | ||
"max", | ||
"abs", | ||
"fmod", | ||
"pow", | ||
"sqrt", | ||
"exp", | ||
"log", | ||
"log2", | ||
"log10", | ||
"select", | ||
"clamp", | ||
"cosh", | ||
"sinh", | ||
"tanh", | ||
"round", | ||
"ceil", | ||
"floor", | ||
"sign", | ||
"fract", | ||
"functioncall", | ||
"unsignedmesh", | ||
"length", | ||
"constresourceid", | ||
"mod" | ||
] | ||
|
||
change_namespace_prefix_md(md_file, elements, prefix) | ||
|
||
def apply_volumetric_prefix(md_file): | ||
prefix = "v" | ||
elements = [ | ||
"image3d", | ||
"imagestack", | ||
"imagesheet", | ||
"functionfromimage3d", | ||
"volumedata", | ||
"composite", | ||
"materialmapping", | ||
"color", | ||
"property", | ||
"levelset" | ||
] | ||
|
||
change_namespace_prefix_md(md_file, elements, prefix) | ||
|
||
def apply_prefixes(md_file): | ||
apply_implicit_prefix(md_file) | ||
#apply_volumetric_prefix(md_file) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 1: | ||
print("Usage: python apply_prefixes.py md_file") | ||
# print number of arguments | ||
print(len(sys.argv)) | ||
sys.exit(1) | ||
|
||
md_file = sys.argv[1] | ||
|
||
apply_prefixes(md_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import re | ||
|
||
# Read the content of the markdown file | ||
with open('3MF Volumetric Extension Template.md', 'r', encoding='utf-8') as file: | ||
content = file.read() | ||
|
||
# Define a regular expression pattern to match any XML tag starting with a backslash, excluding those enclosed in ** ** | ||
pattern = r'(?<!\*\*)\\<([\w]+)>(?!\*\*)' | ||
|
||
# Replace the matched XML tags with the desired format | ||
modified_content = re.sub(pattern, r'`<\1>`', content) | ||
|
||
# Write the modified content back to the file | ||
with open('3MF Volumetric Extension Template.md', 'w', encoding='utf-8') as file: | ||
file.write(modified_content) | ||
|
||
print("XML tags starting with a backslash have been replaced successfully, excluding those enclosed in ** **.") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters