Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 17 / 0 / 17
Functions: -% 0 / 0 / 0
Branches: -% 0 / 0 / 0

OMCompiler/Compiler/Template/GraphMLDumpTpl.tpl
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 // This file defines templates for transforming a GraphML-Graph into a Yed *.graphml-File.
37 //
38 // 2014-02-04 mwalther
39
40 package GraphMLDumpTpl
41
42 import interface GraphMLDumpTplTV;
43
44
45 57 template dumpGraphInfo(GraphML.GraphInfo graphInfo, String fileName)
46 ::=
47 let()= textFile(dumpGraphInfoInternal(graphInfo), fileName)
48 ""
49 end dumpGraphInfo;
50
51 57 template dumpGraphInfoInternal(GraphML.GraphInfo graphInfo)
52 ::=
53 match graphInfo
54 case graphInfo as GRAPHINFOARR(__) then
55 let attDefDump = arrayList(attributes) |> att => dumpAttDef(att) ; separator="\n"
56 let edgeDump = edges |> edge => dumpEdge(edge, graphInfo.graphEdgeKey,attributes) ; separator="\n"
57 <<
58 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
59 <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
60
61 <key for="node" id="<%graphNodeKey%>" yfiles.type="nodegraphics"/>
62 <key attr.name="description" attr.type="string" for="node" id="ddesc" />
63 <key for="edge" id="<%graphEdgeKey%>" yfiles.type="edgegraphics"/>
64
65 <%attDefDump%>
66
67 <!-- Graph Idx: <%arrayLength(graphs)%> -->
68 <%dumpGraph(arrayGet(graphs,arrayLength(graphs)), graphs, nodes, edgeDump, graphNodeKey,attributes)%>
69 </graphml>
70 >>
71 end match
72 end dumpGraphInfoInternal;
73
74 105 template dumpGraph(GraphML.Graph graph, array<GraphML.Graph> allGraphs, array<GraphML.Node> allNodes, String edgeDesc, String graphNodeKey, array<Attribute> graphAttributes)
75 ::=
76 match graph
77 case GRAPH() then
78 let graphNodes = nodeIdc |> idc => dumpNode(arrayGet(allNodes,intAdd(1,intSub(arrayLength(allNodes),idc))),allGraphs,allNodes,graphNodeKey,graphAttributes) ; separator="\n"
79 let attKeys = attValues |> val => dumpAttKey(val,graphAttributes) ; separator="\n"
80 <<
81 <graph edgedefault="<%dumpDirected(directed)%>" id="<%id%>">
82 <%attKeys%>
83 <%graphNodes%>
84
85 <%edgeDesc%>
86 </graph>
87 >>
88 end match
89 end dumpGraph;
90
91 8603 template dumpNode(GraphML.Node node, array<GraphML.Graph> allGraphs, array<GraphML.Node> allNodes, String graphNodeKey, array<Attribute> graphAttributes)
92 ::=
93 match node
94 case NODE() then
95 let nodeLabelDump = nodeLabels |> label => dumpNodeLabel(label) ; separator="\n"
96 let attKeys = attValues |> val => dumpAttKey(val, graphAttributes) ; separator="\n"
97 <<
98 <node id="<%id%>">
99 <%attKeys%>
100 <data key="ddesc"><![CDATA[<%optDesc%>]]></data>
101 <data key="<%graphNodeKey%>">
102 <y:ShapeNode>
103 <y:Fill color="#<%color%>" transparent="false"/>
104 <y:BorderStyle color="#000000" type="line" width="<%border%>"/>
105 <%nodeLabelDump%>
106 <y:Shape type="<%dumpShapeType(shapeType)%>"/>
107 </y:ShapeNode>
108 </data>
109 </node>
110 >>
111 case GROUPNODE() then
112 let folderType = if isFolded then 'folder' else 'group'
113 let activeType = if isFolded then '1' else '0'
114 <<
115 <node id="<%id%>" yfiles.foldertype="<%folderType%>">
116 <data key="<%graphNodeKey%>">
117 <y:ProxyAutoBoundsNode>
118 <y:Realizers active="<%activeType%>">
119 <y:GroupNode>
120 <y:Fill color="#F5F5F5" transparent="false"/>
121 <y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#EBEBEB" borderDistance="0.0" fontFamily="Dialog" fontSize="15" fontStyle="plain" hasLineColor="false" modelName="internal" modelPosition="t" textColor="#000000" visible="true"><%header%></y:NodeLabel>
122 <y:Shape type="roundrectangle"/>
123 <y:State closed="false" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>
124 <y:Insets bottom="15" bottomF="15.0" left="15" leftF="15.0" right="15" rightF="15.0" top="15" topF="15.0"/>
125 <y:BorderInsets bottom="0" bottomF="0.0" left="0" leftF="0.0" right="0" rightF="0.0" top="0" topF="0.0"/>
126 </y:GroupNode>
127 <y:GroupNode>
128 <y:Geometry height="50.0" width="50.0" x="0.0" y="60.0"/>
129 <y:Fill color="#F5F5F5" transparent="false"/>
130 <y:BorderStyle color="#000000" type="dashed" width="1.0"/>
131 <y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#EBEBEB" borderDistance="0.0" fontFamily="Dialog" fontSize="15" fontStyle="plain" hasLineColor="false" height="22.37646484375" modelName="internal" modelPosition="t" textColor="#000000" visible="true"><%header%></y:NodeLabel>
132 <y:Shape type="roundrectangle"/>
133 <y:State closed="true" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>
134 <y:Insets bottom="5" bottomF="5.0" left="5" leftF="5.0" right="5" rightF="5.0" top="5" topF="5.0"/>
135 <y:BorderInsets bottom="0" bottomF="0.0" left="0" leftF="0.0" right="0" rightF="0.0" top="0" topF="0.0"/>
136 </y:GroupNode>
137 </y:Realizers>
138 </y:ProxyAutoBoundsNode>
139 </data>
140 <!-- Graph Idx: <%intAdd(1,intSub(arrayLength(allGraphs), internalGraphIdx))%> -->
141 <%dumpGraph(arrayGet(allGraphs,intAdd(1,intSub(arrayLength(allGraphs), internalGraphIdx))), allGraphs, allNodes, "", graphNodeKey, graphAttributes)%>
142 </node>
143 >>
144 end match
145 end dumpNode;
146
147 14426 template dumpEdge(GraphML.Edge edge, String graphEdgeKey, array<Attribute> graphAttributes)
148 ::=
149 match edge
150 case EDGE() then
151 let edgeLabelDump = edgeLabels |> label => dumpEdgeLabel(label) ; separator="\n"
152 let attKeys = attValues |> val => dumpAttKey(val,graphAttributes) ; separator="\n"
153 <<
154 <edge id="<%id%>" source="<%source%>" target="<%target%>">
155 <%attKeys%>
156 <data key="<%graphEdgeKey%>">
157 <y:PolyLineEdge>
158 <y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
159 <y:LineStyle color="#<%color%>" type="<%dumpLineType(lineType)%>" width="<%lineWidth%>"/>
160 <y:Arrows source="<%dumpArrowType(Util.tuple21(arrows))%>" target="<%dumpArrowType(Util.tuple22(arrows))%>"/>
161 <y:BendStyle smoothed="<%smooth%>"/>
162 <%edgeLabelDump%>
163 </y:PolyLineEdge>
164 </data>
165 </edge>
166 >>
167 end match
168 end dumpEdge;
169
170 8535 template dumpEdgeLabel(GraphML.EdgeLabel edgeLabel)
171 ::=
172 match edgeLabel
173 case EDGELABEL() then
174 let bgColor = dumpColorOpt(backgroundColor)
175 <<
176 <y:EdgeLabel alignment="center" distance="2.0" fontFamily="Dialog" <%bgColor%> fontSize="<%fontSize%>" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="side_slider" preferredPlacement="anywhere" visible="true"><%text%></y:EdgeLabel>
177 >>
178 end match
179 end dumpEdgeLabel;
180
181 8603 template dumpNodeLabel(GraphML.NodeLabel nodeLabel)
182 ::=
183 match nodeLabel
184 case NODELABEL_INTERNAL() then
185 let bgColor = dumpColorOpt(backgroundColor)
186 <<
187 <y:NodeLabel alignment="center" autoSizePolicy="content" <%bgColor%> fontFamily="Dialog" fontSize="12" fontStyle="<%dumpFontStyle(fontStyle)%>" hasLineColor="false" modelName="internal" modelPosition="c" textColor="#000000" visible="true"><%text%></y:NodeLabel>
188 >>
189 case NODELABEL_CORNER() then
190 let bgColor = dumpColorOpt(backgroundColor)
191 <<
192 <y:NodeLabel alignment="center" autoSizePolicy="content" <%bgColor%> fontFamily="Dialog" fontSize="12" fontStyle="<%dumpFontStyle(fontStyle)%>" hasLineColor="false" modelName="corners" modelPosition="<%position%>" textColor="#000000" visible="true"><%text%></y:NodeLabel>
193 >>
194 end match
195 end dumpNodeLabel;
196
197 107670 template dumpAttKey(tuple<Integer,String> key, array<Attribute> graphAttributes)
198 /* author: marcusw
199 Prints a attribute key-value-pair in a data element. If the attribute is a string, a CDATA-tag is added around the value. */
200 ::=
201 match key
202 case(idx,val) then
203 match arrayGet(graphAttributes, idx)
204 case ATTRIBUTE(attType=TYPE_STRING(__)) then
205 <<
206 <data key="cust<%idx%>"><![CDATA[<%val%>]]></data>
207 >>
208 else
209 <<
210 <data key="cust<%idx%>"><%val%></data>
211 >>
212 end match
213 end match
214 end dumpAttKey;
215
216 1067 template dumpAttDef(GraphML.Attribute attribute)
217 ::=
218 match attribute
219 case ATTRIBUTE() then
220 <<
221 <key attr.name="<%name%>" attr.type="<%dumpAttType(attType)%>" for="<%dumpAttTarget(attTarget)%>" id="cust<%attIdx%>">
222 <default><%defaultValue%></default>
223 </key>
224 >>
225 end match
226 end dumpAttDef;
227
228 395 template dumpAttType(GraphML.AttributeType type)
229 ::=
230 match type
231 case TYPE_STRING() then
232 <<
233 string
234 >>
235 case TYPE_BOOLEAN() then
236 <<
237 boolean
238 >>
239 case TYPE_INTEGER() then
240 <<
241 int
242 >>
243 case TYPE_DOUBLE() then
244 <<
245 double
246 >>
247 end match
248 end dumpAttType;
249
250 731 template dumpAttTarget(GraphML.AttributeTarget target)
251 ::=
252 match target
253 case TARGET_NODE() then
254 <<
255 node
256 >>
257 case TARGET_EDGE() then
258 <<
259 edge
260 >>
261 case TARGET_GRAPH() then
262 <<
263 graph
264 >>
265 end match
266 end dumpAttTarget;
267
268 105 template dumpDirected(Boolean directed)
269 ::=
270 match directed
271 case true then
272 <<
273 directed
274 >>
275 case false then
276 <<
277 undirected
278 >>
279 end match
280 end dumpDirected;
281
282 13218 template dumpColorOpt(Option<String> colorOpt)
283 ::=
284 match colorOpt
285 case SOME(col) then
286 <<
287 backgroundColor="#<%col%>"
288 >>
289 end match
290 end dumpColorOpt;
291
292 8603 template dumpFontStyle(GraphML.FontStyle fontStyle)
293 ::=
294 match fontStyle
295 case FONTPLAIN() then
296 <<
297 plain
298 >>
299 case FONTBOLD() then
300 <<
301 bold
302 >>
303 case FONTITALIC() then
304 <<
305 italic
306 >>
307 case FONTBOLDITALIC() then
308 <<
309 bolditalic
310 >>
311 end match
312 end dumpFontStyle;
313
314 14426 template dumpLineType(GraphML.LineType lineType)
315 ::=
316 match lineType
317 case LINE() then
318 <<
319 line
320 >>
321 case DASHED() then
322 <<
323 dashed
324 >>
325 case DASHEDDOTTED() then
326 <<
327 dasheddotted
328 >>
329 end match
330 end dumpLineType;
331
332 14537 template dumpArrowType(GraphML.ArrowType arrowType)
333 ::=
334 match arrowType
335 case ARROWSTANDART() then
336 <<
337 standard
338 >>
339 case ARROWNONE() then
340 <<
341 none
342 >>
343 case ARROWCONCAVE() then
344 <<
345 concave
346 >>
347 end match
348 end dumpArrowType;
349
350 4718 template dumpShapeType(GraphML.ShapeType shape)
351 ::=
352 match shape
353 case RECTANGLE() then
354 <<
355 rectangle
356 >>
357 case ROUNDRECTANGLE() then
358 <<
359 roundrectangle
360 >>
361 case ELLIPSE() then
362 <<
363 ellipse
364 >>
365 case PARALLELOGRAM() then
366 <<
367 parallelogram
368 >>
369 case HEXAGON() then
370 <<
371 hexagon
372 >>
373 case TRIANGLE() then
374 <<
375 triangle
376 >>
377 case OCTAGON() then
378 <<
379 octagon
380 >>
381 case DIAMOND() then
382 <<
383 diamond
384 >>
385 case TRAPEZOID() then
386 <<
387 trapezoid
388 >>
389 case TRAPEZOID2() then
390 <<
391 trapezoid2
392 >>
393 end match
394 end dumpShapeType;
395
396 annotation(__OpenModelica_Interface="codegen_graphml");
397 end GraphMLDumpTpl;
398