浏览代码

Move OML generation stuff to drawio2oml repo (this repo ONLY implements the Py <-> Draw.io interface)

Joeri Exelmans 2 年之前
父节点
当前提交
5e6c24bbb7
共有 10 个文件被更改,包括 9 次插入203 次删除
  1. 2 6
      README.md
  2. 1 3
      default.nix
  3. 0 0
      drawio2py/drawio2himesis.py.to_delete
  4. 0 19
      drawio2py/drawio2oml.py
  5. 0 41
      drawio2py/oml_generator.py
  6. 0 127
      drawio2py/template.oml
  7. 二进制
      overview.png
  8. 3 3
      setup.py
  9. 1 1
      test/data/overview.drawio
  10. 2 3
      test/run_tests.py

+ 2 - 6
README.md

@@ -6,10 +6,6 @@ Currently implemented transformations:
 
 As shown in the figure above, the transformation between `.drawio` files and a [Python in-memory datastructure](drawio2py/abstract_syntax.py) is bidirectional (but not incremental!).
 
-Additionally, an OML generator is included too, but it is only one-directional. The generated OML description will use the following vocabulary:
+Note: The generation of OML has been moved to this repo:
 
-https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/12a00b2ebf15802842b15ba3b9b2f5ceb38d369a/examples/oml/SystemDesignOntology2Layers/src/oml/ua.be/sdo2l/vocabulary/formalisms/drawio.oml
-
-An example of a generated OML file can be found here:
-
-https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/12a00b2ebf15802842b15ba3b9b2f5ceb38d369a/examples/oml/SystemDesignOntology2Layers/src/oml/ua.be/sdo2l/description/artifacts/my_drawio.oml
+https://msdl.uantwerpen.be/git/jexelmans/drawio2oml

+ 1 - 3
default.nix

@@ -6,7 +6,5 @@ pkgs.python3Packages.buildPythonPackage rec {
 
   src = ./.; # location of setup.py
 
-  propagatedBuildInputs = [
-    pkgs.python3Packages.jinja2
-  ];
+  # propagatedBuildInputs = [];
 }

drawio2py/drawio2himesis.py → drawio2py/drawio2himesis.py.to_delete


+ 0 - 19
drawio2py/drawio2oml.py

@@ -1,19 +0,0 @@
-import argparse
-
-if __name__ == "__main__":
-    argparser = argparse.ArgumentParser(
-        description = "Converts Draw.io files to OML.")
-    argparser.add_argument('inputfile')
-    argparser.add_argument('-o', '--output', metavar='FILE', nargs=1, help="OML output file. If not specified, output will be printed to stdout.")
-    args = argparser.parse_args() # exits on error
-
-    from drawio2py import parser, abstract_syntax, oml_generator
-
-    asyntax = parser.Parser.parse(args.inputfile)
-
-    if args.output == None:
-        import sys
-        oml_generator.write_oml(asyntax, sys.stdout)
-    else:
-        with open(args.output[0], 'wt') as f:
-            oml_generator.write_oml(asyntax, f)

+ 0 - 41
drawio2py/oml_generator.py

@@ -1,41 +0,0 @@
-import io
-from drawio2py import abstract_syntax
-
-CDF_NAMESPACES = {
-    "shorthand": "my_drawio",
-    "description": "http://flandersmake.be/cdf/description/my_drawio",
-    "drawio": "http://flandersmake.be/cdf/vocabulary/drawio",
-    "object_diagram": "http://flandersmake.be/cdf/vocabulary/object_diagram",
-    "dict": "http://flandersmake.be/cdf/vocabulary/dict",
-}
-
-DTDESIGN_NAMESPACES = {
-    "shorthand": "my_drawio",
-    "description": "http://ua.be/sdo2l/description/artifacts/my_drawio",
-    "drawio": "http://ua.be/sdo2l/vocabulary/formalisms/drawio",
-    "object_diagram": "http://ua.be/sdo2l/vocabulary/formalisms/object_diagram",
-    "dict": "http://ua.be/sdo2l/vocabulary/formalisms/dict",
-}
-
-def to_oml_string_literal(python_string):
-    # Not sure which characters to escape in OML.
-    # At the very least, quotes should be escaped:
-    return '"' + python_string.replace('"', '\\"') + '"'
-
-def write_oml(drawio_file: abstract_syntax.DrawIOFile, ostream: io.TextIOBase):
-    import jinja2
-    import os
-
-    environment = jinja2.Environment(
-        loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
-
-    environment.filters['to_oml_string_literal'] = to_oml_string_literal
-
-    template = environment.get_template("template.oml")
-
-
-    for piece in template.generate(
-            file=drawio_file,
-            enumerate=enumerate,
-            namespaces=DTDESIGN_NAMESPACES):
-        ostream.write(piece)

+ 0 - 127
drawio2py/template.oml

@@ -1,127 +0,0 @@
-// Warning: Generated code! Do not edit!
-// Input file: '{{file.filename}}'
-// Generator: https://msdl.uantwerpen.be/git/rparedis/DrawioConvert/src/library
-
-{%- macro point(p) -%}
-drawio:hasX {{p.x}}
-drawio:hasY {{p.y}}
-{%- endmacro -%}
-
-{%- macro write_cell(page_index, cell) %}
-  {%- set cell_iri = "p"+(page_index|string)+"_cell_"+(cell.id|string) -%}
-  ci {{cell_iri}} : drawio:{{cell.__class__.__name__}} [
-    drawio:hasDrawioId {{cell.id|to_oml_string_literal}}
-    {%- if cell.value != "" %}
-    drawio:hasValue {{cell.value|to_oml_string_literal}}
-    {%- endif %}
-    {%- if cell.parent != None %}
-    drawio:hasParent p{{page_index}}_cell_{{cell.parent.id}}
-    {%- else %}
-    drawio:isRootOf p{{page_index}}
-    {%- endif %}
-    object_diagram:inModel model
-
-    {%- if cell.__class__.__name__ == "Vertex" %}
-    drawio:hasVertexGeometry drawio:VertexGeometry [
-      {{ point(cell.geometry)|indent(6) }}
-      drawio:hasWidth {{cell.geometry.width}}
-      drawio:hasHeight {{cell.geometry.height}}
-    ]
-    {% endif -%}
-
-    {%- if cell.__class__.__name__ == "Edge" %}
-    drawio:hasEdgeGeometry drawio:EdgeGeometry [
-      {%- for p in cell.geometry.points -%}
-      drawio:hasPoint drawio:PointListItem [
-        drawio:hasListIndex {{loop.index0}}
-        {{ point(p)|indent(8) }}
-      ]
-      {%- endfor %}
-      {%- if cell.geometry.source_point != None %}
-      drawio:hasSourcePoint drawio:Point [
-        {{ point(cell.geometry.source_point)|indent(8) }}
-      ]
-      {%- endif %}
-      {%- if cell.geometry.target_point != None %}
-      drawio:hasTargetPoint drawio:Point [
-        {{ point(cell.geometry.target_point)|indent(8) }}
-      ]
-      {%- endif %}
-    ]
-    {%- if cell.source %}
-    drawio:hasSource p{{page_index}}_cell_{{cell.source.id}}
-    {%- endif -%}
-    {%- if cell.target %}
-    drawio:hasTarget p{{page_index}}_cell_{{cell.target.id}}
-    {%- endif -%}
-    {%- endif %}
-  ]
-  {# Cell properties #}
-  {%-for prop_key,prop_val in cell.properties.items() %}
-  ci {{cell_iri}}_prop_{{prop_key}} : drawio:CellProperty [
-    dict:hasKey {{prop_key|to_oml_string_literal}}
-    dict:hasValue {{prop_val|to_oml_string_literal}}
-    drawio:propertyOf {{cell_iri}}
-    object_diagram:inModel model
-  ]
-  {%- endfor %}
-  {# Cell style #}
-  {%- for style_key,style_val in cell.style.data.items() %}
-  ci {{cell_iri}}_sty_{{style_key}} : drawio:CellStyleEntry [
-    dict:hasKey {{style_key|to_oml_string_literal}}
-    dict:hasValue {{style_val|to_oml_string_literal}}
-    drawio:styleEntryOf {{cell_iri}}
-    object_diagram:inModel model
-  ]
-  {%- endfor %}
-  {# Cell attributes #}
-  {%- for attr_key,attr_val in cell.attributes.items() %}
-  ci {{cell_iri}}_attr_{{attr_key}} : drawio:CellAttribute [
-    dict:hasKey {{attr_key|to_oml_string_literal}}
-    dict:hasValue {{attr_val|to_oml_string_literal}}
-    drawio:attributeOf {{cell_iri}}
-    object_diagram:inModel model
-  ]
-  {%- endfor %}
-
-  {# Recursively write out children #}
-  {%- for child in cell.children %}
-  {{ write_cell(page_index, child) }}
-  {%- endfor -%}
-{%- endmacro %}
-
-description <{{namespaces.description}}#> as {{namespaces.shorthand}} {
-
-  uses <{{namespaces.drawio}}#> as drawio
-  uses <{{namespaces.object_diagram}}#> as object_diagram
-  uses <{{namespaces.dict}}#> as dict
-
-  ci model : drawio:Model [
-    drawio:isCompressed {{ "true" if file.compressed else "false"}}
-    drawio:hasDrawioVersion {{file.version|to_oml_string_literal}}
-  ]
-
-  {# Pages #}
-  {%- for page_index, page in enumerate(file.pages) %}
-  ci p{{page_index}} : drawio:Page [
-    drawio:ofModel model
-    drawio:hasDrawioId {{page.id|to_oml_string_literal}}
-    drawio:hasName {{page.name|to_oml_string_literal}}
-    object_diagram:inModel model
-  ]
-
-  {%- for attr_key, attr_val in page.attributes.items() %}
-  ci p{{page_index}}_a_{{attr_key}} : drawio:PageAttribute [
-    dict:hasKey {{attr_key|to_oml_string_literal}}
-    dict:hasValue {{attr_val|to_oml_string_literal}}
-    drawio:ofPage p{{page_index}}
-    object_diagram:inModel model
-  ]
-  {%- endfor %}
-
-  {# Cells #}
-  {{ write_cell(page_index, page.root) }}
-
-  {%- endfor %}
-
-}

二进制
overview.png


+ 3 - 3
setup.py

@@ -5,12 +5,12 @@ setup(
     version="1.0.0",
 
     install_requires=[
-        "jinja2",
+        # "jinja2",
     ],
 
     package_dir={"":"."},
     packages=["drawio2py"],
 
-    include_package_data=True,
-    package_data={"drawio2py": ["template.oml"]},
+    # include_package_data=True,
+    # package_data={"drawio2py": ["template.oml"]},
 )

文件差异内容过多而无法显示
+ 1 - 1
test/data/overview.drawio


+ 2 - 3
test/run_tests.py

@@ -1,7 +1,7 @@
 import os
 import sys
 import io
-from drawio2py import parser, abstract_syntax, oml_generator, generator
+from drawio2py import parser, abstract_syntax, generator
 import pprint
 import tempfile
 
@@ -41,8 +41,7 @@ if __name__ == "__main__":
             # print(csyntax.getvalue())
             # print(csyntax2.getvalue())
             raise Exception("Files differ after round-trip!")
-
-        oml_generator.write_oml(drawio_file=asyntax, ostream=DummyOutput())
+            
         print(filename, "OK")
 
     # Just see if these files parse without throwing an exception :)