Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modeltype FA uses "http://www.example.org/fireAlarm";
- modeltype GVIZ uses "http://www.fujaba.de/graphviz/0.1.0";
- transformation FireAlarmToGraphViz(in fa:FA, out gv:GVIZ);
- main() {
- fa.rootObjects()[FireAlarmInstallation] -> map FireAlarmToGraphViz();
- }
- mapping FA::FireAlarmInstallation::FireAlarmToGraphViz(): GVIZ::dot::DotGraph{
- id := self.name;
- directedGraph := false;
- nodes := self->collect(f | f.domain) -> map ConvertDomain();
- nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map ConvertOperationZones();
- nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(oz | oz.detectionzones) -> map ConvertDetectionZones();
- nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(az | az.alarmzones) -> map ConvertAlarmZones();
- edges += self.domain -> map CreateEdges()->flatten();
- edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map CreateSubZoneEdges() -> flatten();
- edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map CreateEdges() -> flatten();
- //edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(az | az.alarmzones) -> map CreateEdgesActivation() -> flatten();
- }
- query FA::OperationZones::collectOperationZones() : Set(FA::OperationZones){
- return self->closure(operationzones)->including(self);
- }
- query FA::OperationZones::closureSubZones() : Set(FA::OperationZones){
- return self->closure(operationzones)->including(self);
- }
- mapping FA::Domain::ConvertDomain(): GVIZ::dot::DotNode{
- name := self.name;
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
- }
- mapping FA::OperationZones::ConvertOperationZones(): GVIZ::dot::DotNode{
- name := self.name;
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
- }
- mapping FA::DetectionZones::ConvertDetectionZones(): GVIZ::dot::DotNode{
- name :=self.name;
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
- }
- mapping FA::AlarmZones::ConvertAlarmZones(): GVIZ::dot::DotNode{
- name :=self.name;
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
- }
- mapping FA::Domain::CreateEdges(): Set(GVIZ::dot::DotEdge){
- init {
- self.operationzones ->forEach(oz){
- result += object GVIZ::dot::DotEdge{
- source := self.resolveone(GVIZ::dot::DotNode);
- target := oz.resolveoneIn(FA::OperationZones::ConvertOperationZones,GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := "OperationZone"};
- settings+= object GVIZ::dot::Setting{attribute := "penwidth"; value := oz.PenwidthDomain()};
- };
- };
- }
- }
- query FA::OperationZones::PenwidthDomain():String{
- var sum = 1;
- sum := sum + self.operationzones->collectOperationZones()->flatten()->size();
- sum := sum + self-> collectOperationZones()->flatten()-> collect(oz | oz.detectionzones)->size();
- sum := sum + self-> collectOperationZones()->flatten()-> collect(oz | oz.alarmzones)->size();
- log("Domain Zone Penwidth",self.name,sum);
- return sum.toString();
- }
- mapping FA::OperationZones::CreateSubZoneEdges(): Set(GVIZ::dot::DotEdge){
- init {
- self.operationzones ->forEach(oz){
- result += object GVIZ::dot::DotEdge{
- source := self.resolveone(GVIZ::dot::DotNode);
- target := oz.resolveoneIn(FA::OperationZones::ConvertOperationZones,GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := "Subzone"};
- settings+= object GVIZ::dot::Setting{attribute := "penwidth"; value := oz.Penwidth()};
- };
- };
- }
- }
- query FA::OperationZones::Penwidth():String{
- var sum = 1;
- sum := sum + self->closureSubZones()->flatten()->size();
- sum := sum + self-> closureSubZones()->flatten()-> collect(oz | oz.detectionzones)->size();
- sum := sum + self-> closureSubZones()->flatten()-> collect(oz | oz.alarmzones)->size();
- log("Operation Zone Penwidth",self.name,sum);
- return sum.toString();
- }
- mapping FA::OperationZones::CreateEdges(): List(GVIZ::dot::DotEdge){
- self.detectionzones ->forEach(dz){
- result->add (object GVIZ::dot::DotEdge{
- source := self.resolveone(GVIZ::dot::DotNode);
- target := dz.resolveoneIn(FA::DetectionZones::ConvertDetectionZones,GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := "DetectionZone"};
- });
- };
- self.alarmzones ->forEach(az){
- result->add(object GVIZ::dot::DotEdge{
- source := self.resolveone(GVIZ::dot::DotNode);
- target := az.resolveoneIn(FA::AlarmZones::ConvertAlarmZones,GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := "AlarmZone"};
- });
- //Add neighbor edge
- az.neighbors->forEach(n){
- result->add(object GVIZ::dot::DotEdge{
- source := az.resolveone(GVIZ::dot::DotNode);
- target := n->resolveoneIn(FA::AlarmZones::ConvertAlarmZones,GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "label"; value := "neighbor"};
- });
- };
- };
- }
- mapping FA::AlarmZones::CreateEdgesActivation(): List(GVIZ::dot::DotEdge){
- init {
- log("Alarm Zone",self.name);
- var detZones = self.activationExpression-> Traverse();
- log("Number of detection Zones ",detZones->size());
- detZones->forEach(dz){
- result->add(object GVIZ::dot::DotEdge{
- source := self.resolveone(GVIZ::dot::DotNode);
- target := dz.resolveone(GVIZ::dot::DotNode);
- settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"}
- });
- }
- }
- }
- mapping FA::AbstractExpression::Traverse(): Set(FA::AbstractExpression){
- init {
- log("Traversing");
- if (self.oclIsTypeOf(FA::NOT)){
- self.oclAsType(NOT).right->Traverse();
- log("Traverse NOT");
- }
- else{
- if (self.oclIsTypeOf(FA::BinaryExpression)){
- self.oclAsType(BinaryExpression).left->Traverse()->union(self.oclAsType(BinaryExpression).right->Traverse());
- log("Traverse AND");
- }
- else{
- self.oclAsSet();
- log("Traverse Terminal");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement