Skip to content

Commit c169b7a

Browse files
authored
Update FMI headers and schema to 3.0.1 (#425)
1 parent 609b2ec commit c169b7a

File tree

6 files changed

+4185
-3034
lines changed

6 files changed

+4185
-3034
lines changed

fmusim/FMIModelDescription.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
#include "structured_variable_name.tab.h"
1616

17+
// to regenerate run
18+
//
19+
// python xsdflatten.py fmi3ModelDescription.xsd > fmi3Merged.xsd
20+
//
21+
// and
22+
//
23+
// xxd -i xxd -i fmi3Merged.xsd > fmi3schema.h
1724
#include "fmi1schema.h"
1825
#include "fmi2schema.h"
1926
#include "fmi3schema.h"

fmusim/fmi3schema.h

Lines changed: 4107 additions & 3031 deletions
Large diffs are not rendered by default.

include/fmi3FunctionTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This header file defines the data and function types of FMI 3.0.
88
It must be used when compiling an FMU or an FMI importer.
99
1010
Copyright (C) 2011 MODELISAR consortium,
11-
2012-2022 Modelica Association Project "FMI"
11+
2012-2023 Modelica Association Project "FMI"
1212
All rights reserved.
1313
1414
This file is licensed by the copyright holders under the 2-Clause BSD License

include/fmi3Functions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static link library. For FMUs compiled in a DLL/sharedObject, the "actual" funct
2121
names are used and "FMI3_FUNCTION_PREFIX" must not be defined.
2222
2323
Copyright (C) 2008-2011 MODELISAR consortium,
24-
2012-2022 Modelica Association Project "FMI"
24+
2012-2023 Modelica Association Project "FMI"
2525
All rights reserved.
2626
2727
This file is licensed by the copyright holders under the 2-Clause BSD License

include/fmi3PlatformTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This header file defines the data types of FMI 3.0.
66
It must be used by both FMU and FMI master.
77
88
Copyright (C) 2008-2011 MODELISAR consortium,
9-
2012-2022 Modelica Association Project "FMI"
9+
2012-2023 Modelica Association Project "FMI"
1010
All rights reserved.
1111
1212
This file is licensed by the copyright holders under the 2-Clause BSD License

xsdflatten.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
3+
""" Adapted from https://github.com/esunder/xsdflatten """
4+
5+
import sys
6+
import re
7+
import copy
8+
from lxml import etree
9+
10+
11+
def get_includes_from_file(filename):
12+
pattern = re.compile('(<xs:include schemaLocation)')
13+
lines = [line.strip() for line in open(filename).readlines()]
14+
includes = [line.split('=')[1].split('"')[1] for line in lines if pattern.match(line)]
15+
16+
# sanity check
17+
for inc in includes:
18+
if not inc.endswith('.xsd'):
19+
pass #print 'There is a problem with include %s in file %s' % (inc, filename)
20+
21+
return includes
22+
23+
24+
def get_includes_recurse(filename, include_set):
25+
includes = get_includes_from_file(filename)
26+
include_set.update(includes)
27+
for inc in includes:
28+
get_includes_recurse(inc, include_set)
29+
30+
31+
def get_xml_tree_from_file(filename):
32+
tree = etree.parse(filename)
33+
return tree.getroot()
34+
35+
36+
def remove_includes(root):
37+
# Find and remove the includes
38+
includes = root.findall('xs:include', root.nsmap)
39+
for inc in includes:
40+
root.remove(inc)
41+
return root
42+
43+
44+
def flatten_file(filename):
45+
include_set = set()
46+
get_includes_recurse(filename, include_set)
47+
48+
# Get the main document
49+
root = get_xml_tree_from_file(filename)
50+
root = remove_includes(root)
51+
52+
# Merge in the elements of the includes
53+
for inc_file in include_set:
54+
inc_root = get_xml_tree_from_file(inc_file)
55+
inc_root = remove_includes(inc_root)
56+
root.append(etree.Comment('Imported from %s' % inc_file))
57+
for child in inc_root:
58+
root.append(copy.deepcopy(child))
59+
60+
print(etree.tostring(root, pretty_print=True).decode('utf-8'))
61+
62+
63+
def main(filename):
64+
flatten_file(filename)
65+
66+
67+
if __name__ == "__main__":
68+
main(sys.argv[1])

0 commit comments

Comments
 (0)