aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend
blob: 2b42a8b151751b734fec9ef35a429566fb7b33c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation

import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
import java.util.HashMap
import java.util.Map
import java.util.Set

class PartialInterpretation2Gml {
	def private getElements(PartialInterpretation model) {
		return
			model.problem.elements +
			model.newElements +
			model.openWorldElements
	}
	
	def public transform(PartialInterpretation i) {
		val p = i.problem
		val Map<DefinedElement, Integer> objectToID = new HashMap
		val containmentRelations = p.containmentHierarchies.map[it.containmentRelations].flatten.toSet
		'''
		graph
		[
			«FOR object:i.elements SEPARATOR '\n'»
				«this.transformObject(object,object.typesOfElement(i),objectToID)»
			«ENDFOR»
			«FOR relation:i.partialrelationinterpretation»
				«FOR link:relation.relationlinks.filter(BinaryElementRelationLink)»
					«transformLink(relation,link,objectToID,containmentRelations)»
				«ENDFOR»
			«ENDFOR»
		]
		'''.toString
	}
	def typesOfElement(DefinedElement e, PartialInterpretation i) {
		val typesElementDefinedIn= i.problem.types.filter(TypeDefinition).filter[it.elements.contains(e)]
		val typesElementAddedDuringGeneration = i.partialtypeinterpratation.filter(PartialComplexTypeInterpretation).filter[it.elements.contains(e)].map[it.interpretationOf]
		return typesElementDefinedIn+typesElementAddedDuringGeneration
	}
	
	val protected titleSize = 16
	val protected attributeSize = 14
	val protected borderDistance = 6
	val protected attributeBorderDistance = 8
	val protected ratio = 11.0/20.0
	
	def protected transformObject(DefinedElement object,Iterable<Type> types,Map<DefinedElement, Integer> objectToID){
		val title = object.transormTitle
		val attributes = types.map[it.name]
		
		var double width = title.length*titleSize + borderDistance*2;
		for(x:attributes.map[length*attributeSize + borderDistance*2 + attributeBorderDistance*2])
			width = Math::max(width,x)
		width = width*ratio
		
		val height = Math::max(
			titleSize+4,
			(attributes.size+1)*attributeSize + borderDistance*2)
		
		val id = objectToID.size
		objectToID.put(object,id)
		
		'''
		node
			[
				id	«id»
				graphics
				[
					w	«width»
					h	«height»
					type	"rectangle"
					fill	"#FFFFFF"
					fill2	"#FFFFFF"
					outline	"#000000"
				]
				LabelGraphics
				[
					text	"«title»"
					outline	"#000000"
					fill	"#FFFFFF"
					fontSize	«titleSize»
					fontName	"Monospace"
					autoSizePolicy	"node_width"
					anchor	"t"
					borderDistance	0.0
				]
				LabelGraphics
				[
					text	"
		«FOR attribute : attributes»
		«attribute»
		«ENDFOR»"
					fontSize	«attributeSize»
					fontName	"Consolas"
					alignment	"left"
					anchor	"tl"
					borderDistance	«borderDistance»
				]
			]
		'''
	}
	
	def protected transormTitle(DefinedElement object) {
		if(object.name!= null)object.name
		else "null"
	}
	
	def protected transformLink(
		PartialRelationInterpretation reference,
		BinaryElementRelationLink link,
		Map<DefinedElement, Integer> objectToID,
		Set<Relation> containmentRelations)
	{
		'''
		edge
		[
			source	«objectToID.get(link.param1)»
			target	«objectToID.get(link.param2)»
			graphics
			[
				fill	"#000000"
				«IF containmentRelations.contains(reference.interpretationOf)»
					width	3
				«ENDIF»
				targetArrow	"standard"
			]
			LabelGraphics
			[
				text	"«reference.interpretationOf.name»"
				fontSize	14
				fontName	"Consolas"
				configuration	"AutoFlippingLabel"
				model	"six_pos"
				position	"thead"
			]
		]
		'''
	}
}