From 60f01f46ba232ed6416054f0a6115cb2a9b70b4e Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Sat, 10 Jun 2017 19:05:05 +0200 Subject: Migrating Additional projects --- .../visualisation/PartialInterpretation2Gml.xtend | 136 +++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation') 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 @@ +package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation + +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement +import java.util.Map +import java.util.HashMap +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation +import java.util.Set + +class PartialInterpretation2Gml { + def public transform(PartialInterpretation i) { + val p = i.problem + val Map objectToID = new HashMap + val containmentRelations = p.containmentHierarchies.map[it.containmentRelations].flatten.toSet + ''' + graph + [ + «FOR object:p.elements + i.newElements 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) { + i.problem.types.filter(TypeDefinition).filter[it.elements.contains(e)] + + i.partialtypeinterpratation.filter[it.elements.contains(e)].map[it.interpretationOf] + } + + 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 types,Map 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 objectToID, + Set 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" + ] + ] + ''' + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf