RMF
Toggle main menu visibility
rmf_xml.py
1
## \example rmf_xml.py
2
# This example converts an RMF file to xml, in order to display it in
3
# an XML viewer such as firefox. Its functionality is largely
4
# identical to the \c rmf_xml program. The secondary purpose it to
5
# provide an example of extracting all data from an RMF file and
6
# converting it to some other source. The data extracted here is
7
# completely uninterpreted (eg, cartesian coordinates are treated just
8
# the same as other values). See the source code of rmf_xml for a
9
# similar example in C++.
10
11
import
RMF
12
13
# don't bother with command line arguments, to keep in simple
14
file_name = RMF.get_example_path(
"simple.rmf3"
)
15
verbose =
True
16
17
# show the data with the specified key category
18
19
20
def
show_data_xml(nh, kc):
21
rh = nh.get_file()
22
# get all the keys, we could pull this up in the call stack
23
keys = rh.get_keys(kc)
24
opened =
False
25
for
k
in
keys:
26
v = nh.get_value(k)
27
if
v
is
not
None
:
28
if
not
opened:
29
print(
"<"
, rh.get_name(kc))
30
opened =
True
31
name = rh.get_name(k)
32
name.replace(
" "
,
"_"
)
33
print(name,
"=\""
+ str(v) +
"\""
)
34
if
opened:
35
print(
"/>"
)
36
37
38
def
show_xml(nh, kcs):
39
name = nh.get_name()
40
name.replace(
" "
,
"_"
)
41
print(
"<node name=\""
+ name +
"\" id=\""
+ str(nh.get_id().get_index())\
42
+
"\" type=\""
+ str(nh.get_type()) +
"\"/>"
)
43
if
verbose:
44
for
kc
in
kcs:
45
show_data_xml(nh, kc)
46
children = nh.get_children()
47
for
c
in
children:
48
print(
"<child>"
)
49
show_xml(c, kcs)
50
print(
"</child>"
)
51
52
# open the file, and don't clear the contents
53
rh =
RMF.open_rmf_file_read_only
(file_name)
54
rh.set_current_frame(
RMF.FrameID
(0))
55
print(
"<?xml version=\"1.0\"?>"
)
56
print(
"<rmf>"
)
57
print(
"<path>"
)
58
print(file_name)
59
print(
"</path>"
)
60
print(
"<description>"
)
61
print(rh.get_description())
62
print(
"</description>"
)
63
print(
"<path>"
)
64
print(input)
65
print(
"</path>"
)
66
kcs = rh.get_categories()
67
show_xml(rh.get_root_node(), kcs)
68
print(
"</rmf>"
)
RMF::ID< FrameTag >
RMF::open_rmf_file_read_only
FileConstHandle open_rmf_file_read_only(std::string path)