ソースを参照

Updated whishlist to converter-specific items

rparedis 5 年 前
コミット
d2c81a18d5
10 ファイル変更274 行追加122 行削除
  1. 1 0
      .idea/.name
  2. 1 1
      .idea/drawio2star.iml
  3. 1 1
      .idea/modules.xml
  4. 19 0
      doc/Makefile
  5. 179 0
      doc/conf.py
  6. 20 0
      doc/index.rst
  7. 35 0
      doc/make.bat
  8. 0 0
      formalisms/index
  9. 13 3
      parser.py
  10. 5 117
      whishlist.txt

+ 1 - 0
.idea/.name

@@ -0,0 +1 @@
+DrawioConvert

+ 1 - 1
.idea/drawio2star.iml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
+    <content url="file://$MODULE_DIR$/../DrawioConvert" />
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>

+ 1 - 1
.idea/modules.xml

@@ -2,7 +2,7 @@
 <project version="4">
   <component name="ProjectModuleManager">
     <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/drawio2star.iml" filepath="$PROJECT_DIR$/.idea/drawio2star.iml" />
+      <module fileurl="file://$PROJECT_DIR$/../DrawioConvert/.idea/DrawioConvert.iml" filepath="$PROJECT_DIR$/../DrawioConvert/.idea/DrawioConvert.iml" />
     </modules>
   </component>
 </project>

+ 19 - 0
doc/Makefile

@@ -0,0 +1,19 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+SOURCEDIR     = .
+BUILDDIR      = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

+ 179 - 0
doc/conf.py

@@ -0,0 +1,179 @@
+# -*- coding: utf-8 -*-
+#
+# Configuration file for the Sphinx documentation builder.
+#
+# This file does only contain a selection of the most common options. For a
+# full list see the documentation:
+# http://www.sphinx-doc.org/en/master/config
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'DrawioConvert'
+copyright = '2020, Randy Paredis'
+author = 'Randy Paredis'
+
+# The short X.Y version
+version = ''
+# The full version, including alpha/beta/rc tags
+release = '0.2'
+
+
+# -- General configuration ---------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+# needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+    'sphinx.ext.autodoc',
+    'sphinx.ext.mathjax',
+    'sphinx.ext.viewcode',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'index'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = None
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#
+# html_theme_options = {}
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# Custom sidebar templates, must be a dictionary that maps document names
+# to template names.
+#
+# The default sidebars (for documents that don't match any pattern) are
+# defined by theme itself.  Builtin themes are using these templates by
+# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
+# 'searchbox.html']``.
+#
+# html_sidebars = {}
+
+
+# -- Options for HTMLHelp output ---------------------------------------------
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'DrawioConvertdoc'
+
+
+# -- Options for LaTeX output ------------------------------------------------
+
+latex_elements = {
+    # The paper size ('letterpaper' or 'a4paper').
+    #
+    # 'papersize': 'letterpaper',
+
+    # The font size ('10pt', '11pt' or '12pt').
+    #
+    # 'pointsize': '10pt',
+
+    # Additional stuff for the LaTeX preamble.
+    #
+    # 'preamble': '',
+
+    # Latex figure (float) alignment
+    #
+    # 'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+#  author, documentclass [howto, manual, or own class]).
+latex_documents = [
+    (master_doc, 'DrawioConvert.tex', 'DrawioConvert Documentation',
+     'Randy Paredis', 'manual'),
+]
+
+
+# -- Options for manual page output ------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    (master_doc, 'drawioconvert', 'DrawioConvert Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output ----------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+    (master_doc, 'DrawioConvert', 'DrawioConvert Documentation',
+     author, 'DrawioConvert', 'One line description of project.',
+     'Miscellaneous'),
+]
+
+
+# -- Options for Epub output -------------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = project
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#
+# epub_identifier = ''
+
+# A unique identification for the text.
+#
+# epub_uid = ''
+
+# A list of files that should not be packed into the epub file.
+epub_exclude_files = ['search.html']
+
+
+# -- Extension configuration -------------------------------------------------

+ 20 - 0
doc/index.rst

@@ -0,0 +1,20 @@
+.. DrawioConvert documentation master file, created by
+   sphinx-quickstart on Tue Dec 29 15:01:45 2020.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to DrawioConvert's documentation!
+=========================================
+
+.. toctree::
+   :maxdepth: 2
+   :caption: Contents:
+
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`

+ 35 - 0
doc/make.bat

@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=_build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+	echo.
+	echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+	echo.installed, then set the SPHINXBUILD environment variable to point
+	echo.to the full path of the 'sphinx-build' executable. Alternatively you
+	echo.may add the Sphinx directory to PATH.
+	echo.
+	echo.If you don't have Sphinx installed, grab it from
+	echo.http://sphinx-doc.org/
+	exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
+
+:end
+popd

+ 0 - 0
formalisms/index


+ 13 - 3
parser.py

@@ -2,6 +2,7 @@ import xml.etree.ElementTree as ET
 from urllib.parse import unquote
 import base64
 import zlib
+import re
 
 IGNORE = ['id', 'label', 'placeholders', 'signal', 'class_name']
 """Properties to ignore when parsing."""
@@ -65,6 +66,8 @@ class Parser:
 		self.__signals = {}
 		self.__imports = []
 
+		self.__class_names = set()
+
 	@staticmethod
 	def decode_and_deflate(data):
 		"""Draw.io compresses each page as follows:
@@ -126,9 +129,16 @@ class Parser:
 		return self.__imports
 
 	def create_node(self, root, attr):
-		# TODO: detect duplicate class names
-		# TODO: detect spaces in class names
-		node = Node(attr["id"], attr["class_name"], attr)
+		class_name = attr["class_name"]
+		# detect duplicate class names
+		if class_name in self.__class_names:
+			raise ParseException(f"Class '{class_name}' already defined.")
+		# detect spaces in class names
+		if re.search(r"\s", class_name) is not None:
+			raise ParseException(f"Invalid class '{class_name}': Class names may not contain spaces.")
+
+		node = Node(attr["id"], class_name, attr)
+		self.__class_names.add(class_name)
 
 		# Find the children of the node
 		_rect = root.findall(".//*[@parent='%s']" % node.id)[1]

+ 5 - 117
whishlist.txt

@@ -3,74 +3,15 @@ A list of features that are wanted in this tool:
 * More flags:
     -g/--file: only generate specific file(s)
     -i/--ignore: don't generate specific file(s)
-* Allow Renaming of files? => Via tabs?
-* Allow global variables/code? => Model specific; so no flag
-* Allow setting of drawio xpath => Formalism-specific; set in setup file
-
-
-
-* inverterblock: change symbol \frac{1}{N} to 1/
-  N is confusing as the input is IN1. Furthermore,
-  N seems to indicate that the input must be an integer.
-  Is this the same for the rootblock?
-  ---> Maybe use UTF-8 icons instead of LaTeX? MathJax does
-       not render in the sidebar/library panel (I opened
-       a feature request at drawio for this), so for now
-       using icons may be a better way to go?
-       OK
-  ---> fallback for complex symbols: render/draw and take snapshot
-
-* make the use (and inclusion!) of bokeh dependent 
-  on (1) whether there are any signals to plot and 
-  (2) whether the library can be loaded (with try:)
-  ---> Done!
-
-* low priority: allow the use of matplotlib instead of bokeh.
-  More generally, make it easy to (1) not plot at all,
-  but only save the date for those OutputPortBlocks
-  with a 'signal' property in a standard (.csv, .xml) format,
-  (2) use matplotlib, or (3) use bokeh.
-  ---> matplotlib (or mpl) is now the default for plotting,
-       a commandline argument (-P or --plot) can now switch
-       between mpl, bokeh and csv, or it can disable plotting
-       as a whole.
-  ---> I don't know what the structure of an XML would look like,
-       so it's not implemented (yet).
-       NOT IMPORTANT (for the time being)
+    -p/--print: print everything to the console instead of to files
 
-* The CBD simulator assumes that all blocks have a unique name. 
-  In what scope?
-  ---> In the scope of each individual CBD itself. This is clarified in the docs.
-  - within the scope of each CBD definition, blocks have a unique name (check this)
-  - CBD definitions must have unique class_name (check this)
-
-* Optionally, additional class parameters can be provided 
-  by adding more properties. 
-  These will be passed on as-is, allowing for complex values.
-  As-is? Indentation? Or declaring local variable?
-  ---> Indentation is now removed from the values.
-  ---> The property values should be expressions/rvalues. This should
-       be clearer in the docs now.
-
-* Otherwise, one may use a single input, as long as the 
-  'numberOfInputs' property is set to a value that is at least the total
-  number of incoming links. ???
-  ---> Unintentional 'feature' caused by the CBD-simulator's 'addConnection'
-       behaviour when 'input_port_name' is not defined. On the one hand, this
-       may add a shorthand for what could be a painful issue. On the other hand,
-       it causes less clean modeling.
+* Allow Renaming of files? => Via tabs?
 
-* When this option is set, even those ports will explicitly be set.??
-  ---> See previous answer. When set, this parameter will always add the
-       'input_port_name' and 'output_port_name' argument, even if it can be
-       deduced from the context. Counteracts the previous 'feature'.
+* Allow global variables/code? => Model specific; so no flag
 
-* Function block (e.g., sin()): GenericBlock?
-  ---> See 'examples/SinGen/' example
+* Allow setting of drawio xpath => Formalism-specific; set in setup file
 
-* Property 'block_name' is the name of the block if this class is the top-level CBD?
-  OK? Property 'block_name' is the name of an instance of this hierarchical CBD model.
-  ---> ONLY if this class/CBD is marked as 'entry' by the commandline arguments.
+* Sphinx documentation
 
 * multiple pages: unique names?
   ---> I agree, it should be nice to actually split up these models graphically, yet
@@ -81,56 +22,3 @@ A list of features that are wanted in this tool:
        it is now page-independent.
        TODO: ask Joeri
 
-* online documentation using 
-  https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html
-  ---> Done!
-
-* be printed to the console --> stdio?
-  ---> Currently, it uses the 'print' function. Using 'sys.stdout' shouldn't be an issue.
-
-* represents an input file (uncompressed or compressed XML) ?OK compressed?
-  ---> I removed that from the documentation. Either is fine, though the compressed might be
-       better performance-wise (and space-wise on your system).
-
-* Generation of LaTeX ... in drawio2cdf and/or in generated "simulator"?
-  ---> In the generated file only. Though, I am not fully convinced the current syntax/way
-       of doing it is 'clean'.
-       TODO: LaTeX functions must be checked/altered (they must be ordered)
-  ---> Add LaTeX generation of the flattened CBDs!
-
-* Generate FMU (in the near future)
-
-* Restructure simulator based on Claudio's version
-
-* In the future: refactor simulator to use internal (graph) structure from ModelverseState (MvS).
-  This is the first step to full integration with the Modelverse. drawio will then be 
-  one possible visual interface for formalism-specific syntax-directed editing of Modelverse models
-
-* currently, remove graphViz (or keep for dependency graph)
-
-* Re-add the "plotting" module, but provide functionality for bokeh, matplotlib, gnuplot, csv, xml... that way
-
-* Move "get_block" function from generated scripts to "CBD" module
-  ---> Done!
-
-* Move __docstring__ attribute to custom shape (Text/Textbox/...) in drawio?
-
-* Add possibility to import other libraries into your custom library, allowing multiple files.
-
-* Custom LaTeX representation for custom blocks?
-
-* RootBlock: is linear if its root is <= 1
-
-* Don't override "if __name__ == '__main__':" option?
-  ---> Maybe only override the classes?
-
-* Reduce the amount of whitespaces for imports
-  ---> Use a list of all import statements instead of making it variable
-       with the file generation.
-
-* Have multiple entry points for the ports possible
-
-* Cleaner/better code generation, that is easily expandible to other frameworks (C [FMU], Java...)
-
-* Fix issues that appear in "troublesome.xml" -- Thank you Nils Charlet for pointing this out!
-