Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. modeltype FA uses "http://www.example.org/fireAlarm";
  2. modeltype GVIZ uses "http://www.fujaba.de/graphviz/0.1.0";
  3.  
  4. transformation FireAlarmToGraphViz(in fa:FA, out gv:GVIZ);
  5.  
  6. main() {
  7.  
  8. fa.rootObjects()[FireAlarmInstallation] -> map FireAlarmToGraphViz();
  9.  
  10. }
  11.  
  12.  
  13. mapping FA::FireAlarmInstallation::FireAlarmToGraphViz(): GVIZ::dot::DotGraph{
  14.  
  15. id := self.name;
  16. directedGraph := false;
  17.  
  18. nodes := self->collect(f | f.domain) -> map ConvertDomain();
  19.  
  20. nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map ConvertOperationZones();
  21.  
  22. nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(oz | oz.detectionzones) -> map ConvertDetectionZones();
  23.  
  24. nodes += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(az | az.alarmzones) -> map ConvertAlarmZones();
  25.  
  26.  
  27.  
  28. edges += self.domain -> map CreateEdges()->flatten();
  29.  
  30. edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map CreateSubZoneEdges() -> flatten();
  31.  
  32. edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> map CreateEdges() -> flatten();
  33.  
  34. //edges += self.domain.operationzones -> map collectOperationZones() -> flatten() -> collect(az | az.alarmzones) -> map CreateEdgesActivation() -> flatten();
  35.  
  36.  
  37. }
  38.  
  39. query FA::OperationZones::collectOperationZones() : Set(FA::OperationZones){
  40. return self->closure(operationzones)->including(self);
  41. }
  42.  
  43. query FA::OperationZones::closureSubZones() : Set(FA::OperationZones){
  44. return self->closure(operationzones)->including(self);
  45. }
  46.  
  47.  
  48. mapping FA::Domain::ConvertDomain(): GVIZ::dot::DotNode{
  49. name := self.name;
  50. settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
  51. }
  52.  
  53. mapping FA::OperationZones::ConvertOperationZones(): GVIZ::dot::DotNode{
  54. name := self.name;
  55. settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
  56. }
  57.  
  58.  
  59. mapping FA::DetectionZones::ConvertDetectionZones(): GVIZ::dot::DotNode{
  60. name :=self.name;
  61. settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
  62. }
  63.  
  64. mapping FA::AlarmZones::ConvertAlarmZones(): GVIZ::dot::DotNode{
  65. name :=self.name;
  66. settings+= object GVIZ::dot::Setting{attribute := "label"; value := self.name}
  67. }
  68.  
  69. mapping FA::Domain::CreateEdges(): Set(GVIZ::dot::DotEdge){
  70. init {
  71. self.operationzones ->forEach(oz){
  72. result += object GVIZ::dot::DotEdge{
  73. source := self.resolveone(GVIZ::dot::DotNode);
  74. target := oz.resolveoneIn(FA::OperationZones::ConvertOperationZones,GVIZ::dot::DotNode);
  75. settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
  76. settings+= object GVIZ::dot::Setting{attribute := "label"; value := "OperationZone"};
  77. settings+= object GVIZ::dot::Setting{attribute := "penwidth"; value := oz.PenwidthDomain()};
  78. };
  79. };
  80. }
  81. }
  82.  
  83. query FA::OperationZones::PenwidthDomain():String{
  84. var sum = 1;
  85. sum := sum + self.operationzones->collectOperationZones()->flatten()->size();
  86. sum := sum + self-> collectOperationZones()->flatten()-> collect(oz | oz.detectionzones)->size();
  87. sum := sum + self-> collectOperationZones()->flatten()-> collect(oz | oz.alarmzones)->size();
  88. log("Domain Zone Penwidth",self.name,sum);
  89. return sum.toString();
  90. }
  91.  
  92.  
  93.  
  94.  
  95. mapping FA::OperationZones::CreateSubZoneEdges(): Set(GVIZ::dot::DotEdge){
  96. init {
  97. self.operationzones ->forEach(oz){
  98. result += object GVIZ::dot::DotEdge{
  99. source := self.resolveone(GVIZ::dot::DotNode);
  100. target := oz.resolveoneIn(FA::OperationZones::ConvertOperationZones,GVIZ::dot::DotNode);
  101. settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
  102. settings+= object GVIZ::dot::Setting{attribute := "label"; value := "Subzone"};
  103. settings+= object GVIZ::dot::Setting{attribute := "penwidth"; value := oz.Penwidth()};
  104. };
  105. };
  106. }
  107. }
  108.  
  109. query FA::OperationZones::Penwidth():String{
  110. var sum = 1;
  111. sum := sum + self->closureSubZones()->flatten()->size();
  112. sum := sum + self-> closureSubZones()->flatten()-> collect(oz | oz.detectionzones)->size();
  113. sum := sum + self-> closureSubZones()->flatten()-> collect(oz | oz.alarmzones)->size();
  114. log("Operation Zone Penwidth",self.name,sum);
  115. return sum.toString();
  116. }
  117.  
  118. mapping FA::OperationZones::CreateEdges(): List(GVIZ::dot::DotEdge){
  119. self.detectionzones ->forEach(dz){
  120. result->add (object GVIZ::dot::DotEdge{
  121. source := self.resolveone(GVIZ::dot::DotNode);
  122. target := dz.resolveoneIn(FA::DetectionZones::ConvertDetectionZones,GVIZ::dot::DotNode);
  123. settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
  124. settings+= object GVIZ::dot::Setting{attribute := "label"; value := "DetectionZone"};
  125. });
  126. };
  127. self.alarmzones ->forEach(az){
  128. result->add(object GVIZ::dot::DotEdge{
  129. source := self.resolveone(GVIZ::dot::DotNode);
  130. target := az.resolveoneIn(FA::AlarmZones::ConvertAlarmZones,GVIZ::dot::DotNode);
  131. settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"};
  132. settings+= object GVIZ::dot::Setting{attribute := "label"; value := "AlarmZone"};
  133. });
  134. //Add neighbor edge
  135. az.neighbors->forEach(n){
  136. result->add(object GVIZ::dot::DotEdge{
  137. source := az.resolveone(GVIZ::dot::DotNode);
  138. target := n->resolveoneIn(FA::AlarmZones::ConvertAlarmZones,GVIZ::dot::DotNode);
  139. settings+= object GVIZ::dot::Setting{attribute := "label"; value := "neighbor"};
  140. });
  141. };
  142. };
  143. }
  144.  
  145.  
  146. mapping FA::AlarmZones::CreateEdgesActivation(): List(GVIZ::dot::DotEdge){
  147.  
  148. init {
  149. log("Alarm Zone",self.name);
  150. var detZones = self.activationExpression-> Traverse();
  151. log("Number of detection Zones ",detZones->size());
  152. detZones->forEach(dz){
  153. result->add(object GVIZ::dot::DotEdge{
  154. source := self.resolveone(GVIZ::dot::DotNode);
  155. target := dz.resolveone(GVIZ::dot::DotNode);
  156. settings+= object GVIZ::dot::Setting{attribute := "dir"; value := "forward"}
  157. });
  158. }
  159. }
  160. }
  161.  
  162. mapping FA::AbstractExpression::Traverse(): Set(FA::AbstractExpression){
  163. init {
  164. log("Traversing");
  165. if (self.oclIsTypeOf(FA::NOT)){
  166. self.oclAsType(NOT).right->Traverse();
  167. log("Traverse NOT");
  168. }
  169. else{
  170. if (self.oclIsTypeOf(FA::BinaryExpression)){
  171. self.oclAsType(BinaryExpression).left->Traverse()->union(self.oclAsType(BinaryExpression).right->Traverse());
  172. log("Traverse AND");
  173. }
  174. else{
  175. self.oclAsSet();
  176. log("Traverse Terminal");
  177. }
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement