cpee-transformation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +2 -0
  3. data/LICENSE +165 -0
  4. data/README.md +1 -0
  5. data/Rakefile +21 -0
  6. data/cpee-transformation.gemspec +29 -0
  7. data/lib/cpee/transformation/beautiful.rb +182 -0
  8. data/lib/cpee/transformation/bpmn2.rb +144 -0
  9. data/lib/cpee/transformation/cpee.rb +309 -0
  10. data/lib/cpee/transformation/dataflow.rb +127 -0
  11. data/lib/cpee/transformation/graphviz.rb +100 -0
  12. data/lib/cpee/transformation/implementation.rb +144 -0
  13. data/lib/cpee/transformation/implementation.xml +47 -0
  14. data/lib/cpee/transformation/mermaid.rb +242 -0
  15. data/lib/cpee/transformation/ptml.rb +316 -0
  16. data/lib/cpee/transformation/structures.rb +570 -0
  17. data/lib/cpee/transformation/target.rb +58 -0
  18. data/lib/cpee/transformation/text-bf.rb +201 -0
  19. data/lib/cpee/transformation/text-df-PO-extended.rb +221 -0
  20. data/lib/cpee/transformation/text-df-PO-reduced.rb +211 -0
  21. data/lib/cpee/transformation/transformation_text_cpee.xml +49 -0
  22. data/lib/cpee/transformation/transformation_xml_cpee.xml +49 -0
  23. data/lib/cpee/transformation/transformation_xml_text.xml +49 -0
  24. data/lib/cpee/transformation/transformer.rb +300 -0
  25. data/server/trans +38 -0
  26. data/tools/bpmn2_to_cpee.rb +84 -0
  27. data/tools/bpmn2_to_mermaid.rb +85 -0
  28. data/tools/bpmn2_to_ptml.rb +87 -0
  29. data/tools/cpee-trans +74 -0
  30. data/tools/cpee_to_cpee.rb +83 -0
  31. data/tools/cpee_to_dataflow.rb +83 -0
  32. data/tools/cpee_to_mermaid.rb +85 -0
  33. data/tools/cpee_to_ptml.rb +87 -0
  34. data/tools/cpee_to_text_bf.rb +85 -0
  35. data/tools/cpee_to_text_df-poe.rb +85 -0
  36. data/tools/cpee_to_text_df-por.rb +85 -0
  37. data/tools/mermaid_to_cpee.rb +85 -0
  38. data/tools/ptml_to_cpee.rb +87 -0
  39. metadata +160 -0
@@ -0,0 +1,49 @@
1
+ <!--
2
+ This file is part of CPEE-TRANSFORMATION.
3
+
4
+ CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or (at your
7
+ option) any later version.
8
+
9
+ CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12
+ for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
16
+ see <http://www.gnu.org/licenses/>.
17
+ -->
18
+
19
+ <description datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://riddl.org/ns/description/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
20
+
21
+ <message name="xmldescription">
22
+ <parameter name="description" mimetype="text/xml"/>
23
+ </message>
24
+ <message name="list">
25
+ <zeroOrMore>
26
+ <parameter name="name" type="string"/>
27
+ <parameter name="value" type="string"/>
28
+ </zeroOrMore>
29
+ </message>
30
+
31
+ <message name="xmldedesc">
32
+ <parameter name="description" mimetype="text/xml"/>
33
+ <parameter name="type" fixed="description"/>
34
+ </message>
35
+ <message name="xmldadesc">
36
+ <parameter name="description" mimetype="text/xml"/>
37
+ <parameter name="type" fixed="dataelements"/>
38
+ </message>
39
+ <message name="xmlendesc">
40
+ <parameter name="description" mimetype="text/xml"/>
41
+ <parameter name="type" fixed="endpoints"/>
42
+ </message>
43
+
44
+ <resource>
45
+ <post in="xmldedesc" out="xmldescription"/>
46
+ <post in="xmldadesc" out="list"/>
47
+ <post in="xmlendesc" out="list"/>
48
+ </resource>
49
+ </description>
@@ -0,0 +1,49 @@
1
+ <!--
2
+ This file is part of CPEE-TRANSFORMATION.
3
+
4
+ CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or (at your
7
+ option) any later version.
8
+
9
+ CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12
+ for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
16
+ see <http://www.gnu.org/licenses/>.
17
+ -->
18
+
19
+ <description datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://riddl.org/ns/description/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
20
+
21
+ <message name="plaindescription">
22
+ <parameter name="description" mimetype="text/plain"/>
23
+ </message>
24
+ <message name="list">
25
+ <zeroOrMore>
26
+ <parameter name="name" type="string"/>
27
+ <parameter name="value" type="string"/>
28
+ </zeroOrMore>
29
+ </message>
30
+
31
+ <message name="xmldedesc">
32
+ <parameter name="description" mimetype="text/xml"/>
33
+ <parameter name="type" fixed="description"/>
34
+ </message>
35
+ <message name="xmldadesc">
36
+ <parameter name="description" mimetype="text/xml"/>
37
+ <parameter name="type" fixed="dataelements"/>
38
+ </message>
39
+ <message name="xmlendesc">
40
+ <parameter name="description" mimetype="text/xml"/>
41
+ <parameter name="type" fixed="endpoints"/>
42
+ </message>
43
+
44
+ <resource>
45
+ <post in="xmldedesc" out="plaindescription"/>
46
+ <post in="xmldadesc" out="list"/>
47
+ <post in="xmlendesc" out="list"/>
48
+ </resource>
49
+ </description>
@@ -0,0 +1,300 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # This file is part of CPEE-TRANSFORMATION.
4
+ #
5
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
17
+ # see <http://www.gnu.org/licenses/>.
18
+
19
+ require_relative 'structures'
20
+ require 'rubygems'
21
+ require 'highline'
22
+
23
+ module CPEE
24
+
25
+ module Transformation
26
+
27
+ class Transformer
28
+ def initialize(source)
29
+ @hl = HighLine.new
30
+ @source = source
31
+
32
+ ### fix ids, dont do it, we save the id's in alt_id which is much safer
33
+ # ids = [0]
34
+ # nodes = []
35
+ # source.graph.nodes.each do |k,v|
36
+ # if v.id =~ /^a(\d+)$/
37
+ # v.niceid = $1.to_i
38
+ # ids << v.niceid
39
+ # nodes << v.id
40
+ # end
41
+ # end
42
+ # source.graph.nodes.each do |k,v|
43
+ # unless nodes.include?(v.id)
44
+ # v.niceid = ids.max + 1
45
+ # ids << v.niceid
46
+ # end
47
+ # end
48
+ end
49
+
50
+ def build_traces #{{{
51
+ build_extraces @source.traces, @source.start
52
+ @source.traces
53
+ end #}}}
54
+ def build_tree(debug=false) #{{{
55
+ build_ttree @source.tree, @source.traces.dup, nil, debug
56
+ debug_print debug, 'Tree finished'
57
+ @source.tree
58
+ end #}}}
59
+
60
+ def build_extraces(traces, node) #{{{
61
+ dupt = traces.last.dup
62
+ @source.graph.next_nodes(node).each_with_index do |n,i|
63
+ traces << dupt.dup if i > 0
64
+ if traces.last.include?(n)
65
+ traces.last << n
66
+ else
67
+ traces.last << n
68
+ build_extraces(traces,n)
69
+ end
70
+ end
71
+ end #}}}
72
+ private :build_extraces
73
+
74
+ def map_node(node,flat) #{{{
75
+ case node.type
76
+ when :parallelGateway
77
+ flat ? nil : Parallel.new(node.id,node.type,node.attributes[:wait].nil? ? '-1' : node.attributes[:wait],node.attributes[:cancel].nil? ? 'last' : node.attributes[:cancel])
78
+ when :exclusiveGateway
79
+ flat ? nil : Conditional.new(node.id,:exclusive,node.type,node.label)
80
+ when :eventBasedGateway
81
+ flat ? nil : Parallel.new(node.id,node.type,1)
82
+ when :inclusiveGateway
83
+ flat ? nil : Conditional.new(node.id,:inclusive,node.type,node.label)
84
+ when :break
85
+ flat ? Break.new(node.id) : Break.new(node.id)
86
+ when :endEvent, :startEvent, nil
87
+ nil
88
+ else
89
+ node
90
+ end
91
+ end #}}}
92
+ private :map_node
93
+
94
+ def print_node(niceid)
95
+ @source.graph.find_node(niceid)
96
+ end
97
+
98
+ def build_ttree(branch,traces,enode=nil,debug=false,down=0)
99
+ while not traces.finished?
100
+ ### if traces exist more than once, make it so they exist only once
101
+ ### if somebody creates a modell with an inclusive/exclusive that
102
+ ### has identical branches with different conditions, we are fucked
103
+ ### but how are the odds? right? right?
104
+ traces.uniq!
105
+ puts '--> now on ' + down.to_s if debug
106
+ debug_print debug, traces
107
+ if node = traces.same_first
108
+ if branch.empty? && branch.respond_to?(:id)
109
+ li = if (branch.id == traces.first_node.id)
110
+ ### for tail controlled loops, use the link from this to next
111
+ ### if a tasks loops to itself, then second_nodes returns the first
112
+ @source.graph.link(branch.id,traces.second_nodes.first.id)
113
+ else
114
+ ### if traces.all_tail? && traces.length > 1 && !traces.all_loops?
115
+ ### we had traces.all_tail? here. why?
116
+ if !traces.all_tail? && traces.length > 1 && !traces.all_loops?
117
+ @source.graph.link(traces.first[-2].id,traces.first[-1].id)
118
+ else
119
+ @source.graph.link(branch.id,traces.first_node.id)
120
+ end
121
+ end
122
+ unless li.nil?
123
+ if branch.condition?
124
+ branch.condition << li.condition if !li.condition.nil? && !li.condition&.strip&.empty?
125
+ branch.otherwise = li.otherwise if li.condition.nil?
126
+ branch.condition.uniq!
127
+ branch.condition_type = "text/x-ruby"
128
+ end
129
+ if branch.respond_to?(:attributes)
130
+ branch.attributes.merge!(li.attributes)
131
+ li.attributes.delete_if{true}
132
+ end
133
+ end
134
+ end
135
+
136
+ if node == enode
137
+ traces.shift_all
138
+ elsif traces.incoming(node) == 1
139
+ traces.shift_all
140
+ n = map_node(node,traces.same_first)
141
+ if !n.nil? && !(n.container? && traces.finished?)
142
+ (branch << n).compact!
143
+ end
144
+ else
145
+ if debug
146
+ p "Type: #{node.type}"
147
+ p " All Loops: #{traces.all_loops?}"
148
+ p " All Loops Head Controlled: #{traces.all_front?}"
149
+ p " All Loops Tail Controlled: #{traces.all_tail?}"
150
+ end
151
+ if traces.all_loops? && traces.all_front?
152
+ loops = traces.loops_only
153
+ traces.remove(loops)
154
+
155
+ ### an infinite loop that can only be left by break is created
156
+ ### at the output time it is decided wether this can be optimized
157
+ branch << Loop.new(node.id)
158
+ branch.last.mode = :post_test if loops.all_tail?
159
+ ### remove the exclusive gateway because we no longer need it
160
+ ### if there is non (tail controlled, remove the loop target (last)
161
+ if node.type == :exclusiveGateway
162
+ loops.shift_all
163
+ traces.shift_all
164
+ else
165
+ loops.pop_all
166
+ end
167
+ ### add the blank conditional to get a break
168
+ puts '--> down head_loop to ' + (down + 1).to_s if debug
169
+ if loops.same_first
170
+ build_ttree branch.last.new_branch, loops, nil, debug, down + 1
171
+ else
172
+ build_ttree branch, loops, nil, debug, down + 1
173
+ end
174
+ puts '--> up head_loop from ' + (down + 1).to_s if debug
175
+ elsif node.type == :exclusiveGateway && !traces.all_loops? && traces.all_front?
176
+ loops = traces.loops_only
177
+ traces.remove(loops)
178
+ traces.eliminate_front(loops)
179
+ build_ttree branch, loops, nil, debug, down + 1
180
+ elsif node.type == :exclusiveGateway && !traces.all_loops? && !traces.all_front?
181
+ loops = traces.loops_and_partial_loops
182
+ traces.remove(loops)
183
+
184
+ ### an infinite loop that can only be left by break is created
185
+ ### at the output time it is decided wether this can be optimized
186
+ branch << Loop.new(node.id)
187
+ ### duplicate because we need it later to remove all the shit from traces
188
+ loops.add_breaks(self.object_id,node.type == :exclusiveGateway)
189
+ ### remove the exclusive gateway because we no longer need it
190
+ ### if there is non (tail controlled, remove the loop target (last)
191
+ if node.type == :exclusiveGateway
192
+ loops.shift_all
193
+ traces.shift_all
194
+ else
195
+ loops.pop_all
196
+ end
197
+ ### add the blank conditional to get a break
198
+ puts '--> down head_loop to ' + (down + 1).to_s if debug
199
+ if loops.same_first
200
+ build_ttree branch.last.new_branch, loops, nil, debug, down + 1
201
+ else
202
+ build_ttree branch, loops, nil, debug, down + 1
203
+ end
204
+ puts '--> up head_loop from ' + (down + 1).to_s if debug
205
+ elsif node.type != :exclusiveGateway && traces.all_loops? && !traces.all_front?
206
+ # same as below
207
+ endnode = traces.find_endnode || enode
208
+ puts "--> endnode #{endnode.nil? ? 'nil' : endnode.niceid}" if debug
209
+ tracesgroup, endnode = traces.segment_by endnode
210
+ tracesgroup.each do |trcs|
211
+ next unless branch.last.respond_to?(:new_branch)
212
+ nb = branch.last.new_branch
213
+ unless trcs.finished?
214
+ puts '--> branch down to ' + (down + 1).to_s if debug
215
+ build_ttree nb, trcs, endnode, debug, down + 1
216
+ puts '--> branch up from ' + (down + 1).to_s if debug
217
+ end
218
+ end
219
+ # remove all traces that don't start with endnode to account for loops
220
+ if endnode.nil?
221
+ traces.empty!
222
+ else
223
+ traces.remove_by_endnode(endnode)
224
+ end
225
+ elsif node.type != :exclusiveGateway && !traces.all_loops? && !traces.all_front?
226
+ traces.extend
227
+ traces.shift_all
228
+ n = map_node(node,traces.same_first)
229
+ if !n.nil? && !(n.container? && traces.finished?)
230
+ (branch << n).compact!
231
+ end
232
+ elsif node.type != :exclusiveGateway && !traces.all_loops? && traces.all_front?
233
+ traces.extend
234
+ traces.shift_all
235
+ n = map_node(node,traces.same_first)
236
+ if !n.nil? && !(n.container? && traces.finished?)
237
+ (branch << n).compact!
238
+ end
239
+ else
240
+ loops = traces.loops_and_partial_loops
241
+
242
+ ### throw away the loop traces, remove loop traces from front of all other traces
243
+ traces.remove(loops)
244
+ traces.eliminate(loops)
245
+ loops.extend
246
+
247
+ branch << Loop.new(node.id)
248
+
249
+ puts '--> down tail_loop to ' + (down + 1).to_s if debug
250
+ if loops.same_first
251
+ build_ttree branch.last.new_branch, loops.dup, nil, debug, down + 1
252
+ else
253
+ build_ttree branch, loops.dup, nil, debug, down + 1
254
+ end
255
+ puts '--> up tail_loop from ' + (down + 1).to_s if debug
256
+ end
257
+ traces.remove_empty
258
+ end
259
+ else
260
+ endnode = traces.find_endnode || enode
261
+ puts "--> endnode #{endnode.nil? ? 'nil' : endnode.niceid}" if debug
262
+ tracesgroup, endnode = traces.segment_by endnode
263
+ tracesgroup.each do |trcs|
264
+ branch << Conditional.new(0,:exclusive,:exclusiveGateway) unless branch.last.respond_to?(:new_branch)
265
+ nb = branch.last.new_branch
266
+ unless trcs.finished?
267
+ puts '--> ebranch down to ' + (down + 1).to_s if debug
268
+ build_ttree nb, trcs, endnode, debug, down + 1
269
+ puts '--> ebranch up from ' + (down + 1).to_s if debug
270
+ end
271
+ end
272
+ # remove all traces that don't start with endnode to account for loops
273
+ if endnode.nil?
274
+ traces.empty!
275
+ else
276
+ traces.remove_by_endnode(endnode)
277
+ end
278
+ end
279
+ end
280
+ end
281
+ private :build_ttree
282
+
283
+ def debug_print(debug,traces) #{{{
284
+ if debug
285
+ puts '-' * @hl.output_cols, @source.tree.to_s
286
+ puts traces.to_s
287
+ @hl.ask('Continue ... ')#{ |q| q.echo = false }
288
+ end
289
+ end #}}}
290
+ private :debug_print
291
+
292
+ def generate_model(formater) #{{{
293
+ formater.new(@source.tree).generate
294
+ end #}}}
295
+
296
+ end
297
+
298
+ end
299
+
300
+ end
data/server/trans ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # This file is part of CPEE-TRANSFORMATION.
4
+ #
5
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
17
+ # see <http://www.gnu.org/licenses/>.
18
+
19
+ if File.exist?(File.join(__dir__,'..','lib','cpee','transformation','implementation.rb'))
20
+ require_relative File.join(__dir__,'..','lib','cpee','transformation','implementation')
21
+ elsif File.exist?(File.join(Dir.home,'Projects','cpee-transformation','lib','cpee','transformation','implementation.rb'))
22
+ require_relative File.join(Dir.home, 'Projects','cpee-transformation','lib','cpee','transformation','implementation')
23
+ else
24
+ require 'cpee/transformation/implementation'
25
+ end
26
+
27
+ options = {
28
+ :host => 'localhost',
29
+ :port => 9295,
30
+ :secure => false,
31
+ }
32
+
33
+ Riddl::Server.new(CPEE::Transformation::Service::SERVER, options) do
34
+ accessible_description true
35
+ cross_site_xhr true
36
+
37
+ use CPEE::Transformation::Service::implementation(@riddl_opts)
38
+ end.loop!
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # This file is part of CPEE-TRANSFORMATION.
5
+ #
6
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
18
+ # see <http://www.gnu.org/licenses/>.
19
+
20
+ def wrap(s1, s2, width=78, indent=ARGV.options.summary_width + 3)
21
+ lines = []
22
+ s = ARGV.options.summary_indent + s1 + ' ' * (indent - s1.length - ARGV.options.summary_indent.length) + s2
23
+ line, s = s[0..indent-2], s[indent..-1]
24
+ s.split(/\n/).each do |ss|
25
+ ss.split(/[ \t]+/).each do |word|
26
+ if line.size + word.size >= width
27
+ lines << line
28
+ line = (" " * (indent)) + word
29
+ else
30
+ line << " " << word
31
+ end
32
+ end
33
+ lines << line if line
34
+ line = (" " * (indent-1))
35
+ end
36
+ return lines.join("\n")
37
+ end
38
+
39
+ require 'optparse'
40
+
41
+ require_relative '../lib/cpee/transformation/transformer' rescue nil
42
+ require_relative '../lib/cpee/transformation/cpee' rescue nil
43
+ require_relative '../lib/cpee/transformation/bpmn2' rescue nil
44
+
45
+ interactive = false
46
+ printtree = false
47
+
48
+ ARGV.options { |opt|
49
+ opt.summary_indent = ' ' * 2
50
+ opt.summary_width = 18
51
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} FNAME\n"
52
+ opt.on("Options:")
53
+ opt.on("--help", "-h", "This text") { puts opt; exit }
54
+ opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
55
+ opt.on("--tree", "-t", "Print tree") { printtree = true }
56
+ opt.on("")
57
+ opt.on(wrap("[FNAME]","convert BPMN2 in file FNAME to cpee tree and output to console."))
58
+ opt.parse!
59
+ }
60
+
61
+ if ARGV.length != 1
62
+ puts ARGV.options
63
+ exit
64
+ else
65
+ f = ARGV[0]
66
+ end
67
+
68
+ model = CPEE::Transformation::Source::BPMN2.new(File.read(f))
69
+
70
+ trans = CPEE::Transformation::Transformer.new(model)
71
+ traces = trans.build_traces
72
+
73
+ if interactive
74
+ puts traces.legend
75
+ tree = trans.build_tree(true)
76
+ else
77
+ tree = trans.build_tree(false)
78
+ end
79
+
80
+ if printtree
81
+ puts tree.to_s
82
+ else
83
+ puts trans.generate_model(CPEE::Transformation::Target::CPEE)
84
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # This file is part of CPEE-TRANSFORMATION.
5
+ #
6
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
18
+ # see <http://www.gnu.org/licenses/>.
19
+
20
+ def wrap(s1, s2, width=78, indent=ARGV.options.summary_width + 3)
21
+ lines = []
22
+ s = ARGV.options.summary_indent + s1 + ' ' * (indent - s1.length - ARGV.options.summary_indent.length) + s2
23
+ line, s = s[0..indent-2], s[indent..-1]
24
+ s.split(/\n/).each do |ss|
25
+ ss.split(/[ \t]+/).each do |word|
26
+ if line.size + word.size >= width
27
+ lines << line
28
+ line = (" " * (indent)) + word
29
+ else
30
+ line << " " << word
31
+ end
32
+ end
33
+ lines << line if line
34
+ line = (" " * (indent-1))
35
+ end
36
+ return lines.join("\n")
37
+ end
38
+
39
+ require 'optparse'
40
+
41
+ require_relative '../lib/cpee/transformation/transformer' rescue nil
42
+ require_relative '../lib/cpee/transformation/bpmn2' rescue nil
43
+ require_relative '../lib/cpee/transformation/mermaid' rescue nil
44
+
45
+ interactive = false
46
+ printtree = false
47
+
48
+ ARGV.options { |opt|
49
+ opt.summary_indent = ' ' * 2
50
+ opt.summary_width = 18
51
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} FNAME\n"
52
+ opt.on("Options:")
53
+ opt.on("--help", "-h", "This text") { puts opt; exit }
54
+ opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
55
+ opt.on("--tree", "-t", "Print tree") { printtree = true }
56
+ opt.on("")
57
+ opt.on(wrap("[FNAME]","convert cpee bpmn2 in file FNAME to mermaid and output to console."))
58
+ opt.parse!
59
+ }
60
+
61
+ if ARGV.length != 1
62
+ puts ARGV.options
63
+ exit
64
+ else
65
+ f = ARGV[0]
66
+ end
67
+
68
+ model = CPEE::Transformation::Source::BPMN2.new(File.read(f))
69
+
70
+ trans = CPEE::Transformation::Transformer.new(model)
71
+ traces = trans.build_traces
72
+
73
+ if interactive
74
+ puts traces.legend
75
+ puts
76
+ tree = trans.build_tree(true)
77
+ else
78
+ tree = trans.build_tree(false)
79
+ end
80
+
81
+ if printtree
82
+ puts tree.to_s
83
+ else
84
+ puts trans.generate_model(CPEE::Transformation::Target::Mermaid)
85
+ end