diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation')
1 files changed, 136 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend new file mode 100644 index 00000000..819cae00 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend | |||
@@ -0,0 +1,136 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
5 | import java.util.Map | ||
6 | import java.util.HashMap | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | ||
12 | import java.util.Set | ||
13 | |||
14 | class PartialInterpretation2Gml { | ||
15 | def public transform(PartialInterpretation i) { | ||
16 | val p = i.problem | ||
17 | val Map<DefinedElement, Integer> objectToID = new HashMap | ||
18 | val containmentRelations = p.containmentHierarchies.map[it.containmentRelations].flatten.toSet | ||
19 | ''' | ||
20 | graph | ||
21 | [ | ||
22 | «FOR object:p.elements + i.newElements SEPARATOR '\n'» | ||
23 | «this.transformObject(object,object.typesOfElement(i),objectToID)» | ||
24 | «ENDFOR» | ||
25 | «FOR relation:i.partialrelationinterpretation» | ||
26 | «FOR link:relation.relationlinks.filter(BinaryElementRelationLink)» | ||
27 | «transformLink(relation,link,objectToID,containmentRelations)» | ||
28 | «ENDFOR» | ||
29 | «ENDFOR» | ||
30 | ] | ||
31 | '''.toString | ||
32 | } | ||
33 | def typesOfElement(DefinedElement e, PartialInterpretation i) { | ||
34 | i.problem.types.filter(TypeDefinition).filter[it.elements.contains(e)] + | ||
35 | i.partialtypeinterpratation.filter[it.elements.contains(e)].map[it.interpretationOf] | ||
36 | } | ||
37 | |||
38 | val protected titleSize = 16 | ||
39 | val protected attributeSize = 14 | ||
40 | val protected borderDistance = 6 | ||
41 | val protected attributeBorderDistance = 8 | ||
42 | val protected ratio = 11.0/20.0 | ||
43 | |||
44 | def protected transformObject(DefinedElement object,Iterable<Type> types,Map<DefinedElement, Integer> objectToID){ | ||
45 | val title = object.transormTitle | ||
46 | val attributes = types.map[it.name] | ||
47 | |||
48 | var double width = title.length*titleSize + borderDistance*2; | ||
49 | for(x:attributes.map[length*attributeSize + borderDistance*2 + attributeBorderDistance*2]) | ||
50 | width = Math::max(width,x) | ||
51 | width = width*ratio | ||
52 | |||
53 | val height = Math::max( | ||
54 | titleSize+4, | ||
55 | (attributes.size+1)*attributeSize + borderDistance*2) | ||
56 | |||
57 | val id = objectToID.size | ||
58 | objectToID.put(object,id) | ||
59 | |||
60 | ''' | ||
61 | node | ||
62 | [ | ||
63 | id «id» | ||
64 | graphics | ||
65 | [ | ||
66 | w «width» | ||
67 | h «height» | ||
68 | type "rectangle" | ||
69 | fill "#FFFFFF" | ||
70 | fill2 "#FFFFFF" | ||
71 | outline "#000000" | ||
72 | ] | ||
73 | LabelGraphics | ||
74 | [ | ||
75 | text "«title»" | ||
76 | outline "#000000" | ||
77 | fill "#FFFFFF" | ||
78 | fontSize «titleSize» | ||
79 | fontName "Monospace" | ||
80 | autoSizePolicy "node_width" | ||
81 | anchor "t" | ||
82 | borderDistance 0.0 | ||
83 | ] | ||
84 | LabelGraphics | ||
85 | [ | ||
86 | text " | ||
87 | «FOR attribute : attributes» | ||
88 | «attribute» | ||
89 | «ENDFOR»" | ||
90 | fontSize «attributeSize» | ||
91 | fontName "Consolas" | ||
92 | alignment "left" | ||
93 | anchor "tl" | ||
94 | borderDistance «borderDistance» | ||
95 | ] | ||
96 | ] | ||
97 | ''' | ||
98 | } | ||
99 | |||
100 | def protected transormTitle(DefinedElement object) { | ||
101 | if(object.name!= null)object.name | ||
102 | else "null" | ||
103 | } | ||
104 | |||
105 | def protected transformLink( | ||
106 | PartialRelationInterpretation reference, | ||
107 | BinaryElementRelationLink link, | ||
108 | Map<DefinedElement, Integer> objectToID, | ||
109 | Set<Relation> containmentRelations) | ||
110 | { | ||
111 | ''' | ||
112 | edge | ||
113 | [ | ||
114 | source «objectToID.get(link.param1)» | ||
115 | target «objectToID.get(link.param2)» | ||
116 | graphics | ||
117 | [ | ||
118 | fill "#000000" | ||
119 | «IF containmentRelations.contains(reference.interpretationOf)» | ||
120 | width 3 | ||
121 | «ENDIF» | ||
122 | targetArrow "standard" | ||
123 | ] | ||
124 | LabelGraphics | ||
125 | [ | ||
126 | text "«reference.interpretationOf.name»" | ||
127 | fontSize 14 | ||
128 | fontName "Consolas" | ||
129 | configuration "AutoFlippingLabel" | ||
130 | model "six_pos" | ||
131 | position "thead" | ||
132 | ] | ||
133 | ] | ||
134 | ''' | ||
135 | } | ||
136 | } \ No newline at end of file | ||