Skip to content

Commit

Permalink
Automatically generate API functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Jun 14, 2015
1 parent 815abe8 commit cb404bc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 544 deletions.
19 changes: 14 additions & 5 deletions usersguide-sphinx/Makefile
Expand Up @@ -6,7 +6,7 @@ SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
ALLDEP = source/openmodelica.bib
ALLDEP = source/openmodelica.bib source/interface.inc

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
Expand Down Expand Up @@ -54,18 +54,24 @@ clean:

html: dvisvgm.sh $(ALLDEP)
test -f dvisvgm.sh
$(SPHINXBUILD) -b html -D pngmath_dvipng="`pwd`"/dvisvgm.sh $(ALLSPHINXOPTS) $(BUILDDIR)/html
$(SPHINXBUILD) -b html -t nomathjax -D pngmath_dvipng="`pwd`"/dvisvgm.sh $(ALLSPHINXOPTS) $(BUILDDIR)/html
sed -i 's,\(_images/math/.*[.]\)png,\1svg,' build/html/*.html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

htmlmathjax: $(ALLDEP)
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/htmlmathjax
sed -i 's,\(_images/math/.*[.]\)png,\1svg,' build/html/*.html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/htmlmathjax."

dirhtml: $(ALLDEP)
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
$(SPHINXBUILD) -b dirhtml -t nomathjax $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

singlehtml: $(ALLDEP)
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
$(SPHINXBUILD) -b singlehtml -t nomathjax $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

Expand Down Expand Up @@ -112,7 +118,7 @@ devhelp: $(ALLDEP)
@echo "# devhelp"

epub: $(ALLDEP)
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
$(SPHINXBUILD) -b epub -t nomathjax $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

Expand Down Expand Up @@ -214,3 +220,6 @@ source/media/omedit-connect-mode.pdf: source/media/omedit-connect-mode.svg
FNAME=`echo $@ | sed "s/[.]/-/g" | sed "s/-pdf/.pdf/g"`; if test "$$FNAME" != "$@"; then cp -a "$@" "$$FNAME"; fi
source/openmodelica.bib: resolve-crossref.py $(OPENMODELICAHOME)/../doc/bibliography/openmodelica.bib
python resolve-crossref.py "$(OPENMODELICAHOME)/../doc/bibliography/openmodelica.bib" source/openmodelica.bib
source/interface.inc: interface.mos
$(OPENMODELICAHOME)/bin/omc +g=MetaModelica +d=nogen interface.mos
mv interface.inc $@
34 changes: 34 additions & 0 deletions usersguide-sphinx/interface.mos
@@ -0,0 +1,34 @@
s := "
function trim
input String s;
output String o;
protected
String a[1];
algorithm
(,a) := OpenModelica.Scripting.regex(s, \"[^ ].*\");
o := a[1];
end trim;

function reSTInterface
input OpenModelica.Scripting.TypeName cl;
output String out;
protected
String s;
String strs[:] = OpenModelica.Scripting.typeNameStrings(cl);
String doc[2] = OpenModelica.Scripting.getDocumentationAnnotation(cl);
String doc1 = doc[1];
algorithm
out := \"\\n\" + strs[end] + \"\\n\" + sum(\"^\" for c in 1:stringLength(strs[end])) + \"\\n\";
out := out + sum(\"\" + trim(l) + \"\\n\" for l in OpenModelica.Scripting.strtok(OpenModelica.Scripting.getClassComment(cl), \"\\n\"));
OpenModelica.Scripting.writeFile(\"interface.inc.tmp\", doc1, false);
OpenModelica.Scripting.system(\"pandoc -t rst -f html -o interface.inc.tmp.rst interface.inc.tmp\");
out := out + \"\\n\" + sum(\"\" + l + \"\\n\" for l in OpenModelica.Scripting.stringSplit(OpenModelica.Scripting.readFile(\"interface.inc.tmp.rst\"), \"\\n\")) + \" \\n\";
out := out + \"\\n.. code-block :: modelica\\n\\n\";
s := OpenModelica.Scripting.list(cl, interfaceOnly=true);
out := out + sum(\" \" + l + \"\\n\" for l in OpenModelica.Scripting.strtok(s, \"\\n\")) + \" \\n\";
end reSTInterface;
";
loadString(s);
getErrorString();

writeFile("interface.inc", sum(reSTInterface(cl) for cl guard isFunction(cl) and not isPartial(cl) and not regexBool(typeNameString(cl), "Internal") in getClassNames(OpenModelica.Scripting, sort=true, recursive=true)));getErrorString();
4 changes: 4 additions & 0 deletions usersguide-sphinx/source/conf.py
Expand Up @@ -36,9 +36,13 @@
'sphinx.ext.pngmath',
'sphinx.ext.ifconfig',
'sphinxcontrib.bibtex',
'sphinxcontrib.inlinesyntaxhighlight',
'sphinxcontribopenmodelica'
]

# As long as we are not generating with the epub tag it is save to use MathJax.
if 'nomathjax' not in tags: extensions.append('sphinx.ext.mathjax')

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
6 changes: 1 addition & 5 deletions usersguide-sphinx/source/modelica3d.rst
Expand Up @@ -74,11 +74,7 @@ If everything goes fine a visualization window will pop-up. To visualize
any models from the MultiBody library you can use this script and change
the extends to point to the model you want. Note that you will need to
add visualisers to your model similarly to what Modelica.MultiBody
library has. The documentation of the visualizers is available `here <https://build.openmodelica.org/Documentation/Modelica.Mechanics.MultiBody.Visualizers.html>`__

.. omc-mos ::
loadModelica3D()
library has. The documentation of the visualizers is available `here <https://build.openmodelica.org/Documentation/Modelica.Mechanics.MultiBody.Visualizers.html>`__.

.. omc-loadstring ::
Expand Down

0 comments on commit cb404bc

Please sign in to comment.