cpee-transformation 1.0.6 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/cpee-transformation.gemspec +2 -2
- data/lib/cpee/transformation/bpmn2.rb +6 -3
- data/lib/cpee/transformation/cpee.rb +7 -5
- data/lib/cpee/transformation/graphviz.rb +230 -33
- data/lib/cpee/transformation/implementation.rb +7 -0
- data/lib/cpee/transformation/implementation.xml +3 -0
- data/lib/cpee/transformation/mermaid.rb +57 -20
- data/lib/cpee/transformation/pnml.rb +243 -0
- data/lib/cpee/transformation/target.rb +2 -1
- data/lib/cpee/transformation/transformer.rb +1 -1
- data/tools/trans_bpmn2-to-graphviz +85 -0
- data/tools/trans_cpee-to-graphviz +85 -0
- data/tools/trans_cpee-to-pnml +85 -0
- data/tools/trans_cpee-to-pnml-with-lifecycle +85 -0
- metadata +31 -27
- data/server/trans.pid +0 -1
- /data/tools/{bpmn2_to_cpee.rb → trans_bpmn2-to-cpee} +0 -0
- /data/tools/{bpmn2_to_mermaid.rb → trans_bpmn2-to-mermaid} +0 -0
- /data/tools/{bpmn2_to_ptml.rb → trans_bpmn2-to-ptml} +0 -0
- /data/tools/{cpee_to_bpmn2.rb → trans_cpee-to-bpmn2} +0 -0
- /data/tools/{cpee_to_cpee.rb → trans_cpee-to-cpee} +0 -0
- /data/tools/{cpee_to_dataflow.rb → trans_cpee-to-dataflow} +0 -0
- /data/tools/{cpee_to_mermaid.rb → trans_cpee-to-mermaid} +0 -0
- /data/tools/{cpee_to_ptml.rb → trans_cpee-to-ptml} +0 -0
- /data/tools/{cpee_to_text_bf.rb → trans_cpee-to-text-bf} +0 -0
- /data/tools/{cpee_to_text_df-poe.rb → trans_cpee-to-text-df-poe} +0 -0
- /data/tools/{cpee_to_text_df-por.rb → trans_cpee-to-text-df-por} +0 -0
- /data/tools/{mermaid_to_cpee.rb → trans_mermaid-to-cpee} +0 -0
- /data/tools/{ptml_to_cpee.rb → trans_ptml-to-cpee} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6511a19521470370c2ab83b0434cff42b5690cfee3fa081cd7db01567a11441f
|
|
4
|
+
data.tar.gz: '0811bb24cf24e6a6a8f594a4a21e2d05e36de3ee7e266c5175c2e9940225e434'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c0e038139f024a80c0b84f39047bbf63be391644873dd966abf0ab253377bae48a8ea3be8319bd72ac20dd241556774354e5c0b538d0fad10ad3376396004151
|
|
7
|
+
data.tar.gz: f1e1dd5f77be6a13064045bc2276b70c9e95af9b9850de09077da28404252c76e44d4781a2d75479e80692ada31a9509cbee0cca7374780734ce75c0e9cd933b
|
data/README.md
CHANGED
|
@@ -34,6 +34,9 @@ name/value pairs, from BPMN2 sources only).
|
|
|
34
34
|
| `/bpmn2/mermaid` | mermaid | BPMN2 |
|
|
35
35
|
| `/bpmn2/graphviz` | graphviz | BPMN2 |
|
|
36
36
|
| `/mermaid/cpee` | CPEE | mermaid |
|
|
37
|
+
| `/graphviz/cpee` | CPEE | graphviz |
|
|
38
|
+
| `/pnml/cpee` | CPEE | PNML |
|
|
39
|
+
| `/pnml-with-lifecycle/cpee` | CPEE | PNML, calling/receiving/done |
|
|
37
40
|
| `/text-bf/cpee` | CPEE | text, text-bf |
|
|
38
41
|
| `/text-df-PO-extended/cpee` | CPEE | text, text-df-PO-extended |
|
|
39
42
|
| `/text-df-PO-reduced/cpee` | CPEE | text, text-df-PO-reduced |
|
|
@@ -61,8 +64,12 @@ and after `npm install -g cpee-layout` it can be
|
|
|
61
64
|
|
|
62
65
|
A command name is searched in `PATH`, a path (containing `/`) is relative to
|
|
63
66
|
the directory of `trans`, `~` works too, e.g.
|
|
64
|
-
`~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow
|
|
65
|
-
right layout.
|
|
67
|
+
`~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow.
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
The layout direction follows the model: the cockpit sets `dir="lr"` or
|
|
70
|
+
`dir="td"` on the `<description>` root, depending on its theme, and `-lr` is
|
|
71
|
+
added for `dir="lr"`. Putting `-lr` into `trans.conf` makes every BPMN left to
|
|
72
|
+
right.
|
|
73
|
+
|
|
74
|
+
`tools/trans_cpee-to-bpmn2 FNAME` does the same on the command line, using the
|
|
68
75
|
`server/trans.conf` of the gem. If `bpmnexport` can't be run or fails, the request returns 500.
|
data/cpee-transformation.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "cpee-transformation"
|
|
3
|
-
s.version = "1.0
|
|
3
|
+
s.version = "1.1.0"
|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
|
5
5
|
s.license = "LGPL-3.0-or-later"
|
|
6
6
|
s.summary = "CPEE Transformation between different formats"
|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.require_path = 'lib'
|
|
12
12
|
s.extra_rdoc_files = ['README.md']
|
|
13
13
|
s.bindir = 'tools'
|
|
14
|
-
s.executables = ['
|
|
14
|
+
s.executables = ['trans_bpmn2-to-cpee', 'trans_bpmn2-to-mermaid', 'trans_bpmn2-to-ptml', 'trans_cpee-to-bpmn2', 'trans_cpee-to-cpee', 'trans_cpee-to-mermaid', 'trans_cpee-to-ptml', 'trans_cpee-to-text-bf', 'trans_cpee-to-text-df-poe', 'trans_cpee-to-text-df-por', 'cpee-trans', 'trans_mermaid-to-cpee', 'trans_ptml-to-cpee']
|
|
15
15
|
|
|
16
16
|
s.required_ruby_version = '>=3.2'
|
|
17
17
|
|
|
@@ -77,11 +77,12 @@ module CPEE
|
|
|
77
77
|
end #}}}
|
|
78
78
|
|
|
79
79
|
def extract_nodelink(doc) #{{{
|
|
80
|
-
|
|
80
|
+
nonflow = %w{sequenceFlow laneSet textAnnotation association group dataObject dataObjectReference dataStoreReference property}
|
|
81
|
+
doc.find("/bm:definitions/bm:process/bm:*[@id and not(@itemSubjectRef) and not(#{nonflow.map{ |t| "local-name()='#{t}'" }.join(' or ')})]").each do |e|
|
|
81
82
|
type = e.qname.name.to_sym
|
|
82
83
|
### an end event with a terminate definition ends the whole process
|
|
83
84
|
type = :terminate if type == :endEvent && e.find('bm:terminateEventDefinition').any?
|
|
84
|
-
n = Node.new(self.object_id,e.attributes['id'],type,e.attributes['name'].strip,e.find('count(bm:incoming)'),e.find('count(bm:outgoing)'))
|
|
85
|
+
n = Node.new(self.object_id,e.attributes['id'],type,e.attributes['name'].to_s.strip,e.find('count(bm:incoming)'),e.find('count(bm:outgoing)'))
|
|
85
86
|
|
|
86
87
|
if e.attributes['scriptFormat'] != ''
|
|
87
88
|
n.script_type = e.attributes['scriptFormat']
|
|
@@ -152,7 +153,8 @@ module CPEE
|
|
|
152
153
|
# generated CPEE model as drawn and writes it as BPMN with diagram
|
|
153
154
|
# interchange. opts[:bpmnexport] (trans.conf) is a command name, searched
|
|
154
155
|
# in PATH, or a path, relative to the server dir, optionally followed by
|
|
155
|
-
# arguments
|
|
156
|
+
# arguments. By default npx fetches cpee-layout on first use. -lr is added
|
|
157
|
+
# when the source model has dir="lr" (set by the cockpit from its theme).
|
|
156
158
|
class BPMN2 < Default
|
|
157
159
|
BPMNEXPORT = 'npx -y -p cpee-layout@^1.2.0 bpmnexport'
|
|
158
160
|
|
|
@@ -165,6 +167,7 @@ module CPEE
|
|
|
165
167
|
opts = self.class.opts
|
|
166
168
|
cmd, *args = Shellwords.split(opts[:bpmnexport] || BPMNEXPORT)
|
|
167
169
|
cmd = File.expand_path(cmd, opts[:basepath] || Dir.pwd) if cmd.include?('/')
|
|
170
|
+
args << '-lr' if @dir == 'lr' && !args.include?('-lr')
|
|
168
171
|
out, err, st = Open3.capture3(cmd, *args, '-', stdin_data: Target::CPEE.new(@tree).generate)
|
|
169
172
|
raise "#{cmd}: #{err}" unless st.success?
|
|
170
173
|
out
|
|
@@ -26,7 +26,7 @@ module CPEE
|
|
|
26
26
|
module Source #{{{
|
|
27
27
|
|
|
28
28
|
class CPEE
|
|
29
|
-
attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces
|
|
29
|
+
attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces, :dir
|
|
30
30
|
|
|
31
31
|
def initialize(text)
|
|
32
32
|
@tree = Tree.new
|
|
@@ -56,13 +56,13 @@ module CPEE
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def dive(node,n1=nil,condition=nil,otherwise=false)
|
|
59
|
-
if node.children.empty? || node.text_only?
|
|
60
|
-
return n1
|
|
61
|
-
end
|
|
62
59
|
if n1.nil?
|
|
63
60
|
nid = id_find(node.attributes['id'] || node.attributes['eid'])
|
|
64
61
|
n1 = @start = Node.new(self.object_id,nid,:startEvent,'',0,1)
|
|
65
62
|
end
|
|
63
|
+
if node.children.empty? || node.text_only?
|
|
64
|
+
return n1
|
|
65
|
+
end
|
|
66
66
|
node.children.each do |ele|
|
|
67
67
|
case ele.qname.name
|
|
68
68
|
when 'loop'
|
|
@@ -201,7 +201,9 @@ module CPEE
|
|
|
201
201
|
doc = XML::Smart::string(text)
|
|
202
202
|
doc.register_namespace :d, 'http://cpee.org/ns/description/1.0'
|
|
203
203
|
# a model (root description) or a testset, which contains it
|
|
204
|
-
|
|
204
|
+
root = doc.find('//d:description').first || doc.root
|
|
205
|
+
@dir = root.attributes['dir'] == 'lr' ? 'lr' : 'td' # layout direction of the cockpit theme
|
|
206
|
+
bn = dive(root)
|
|
205
207
|
ne = Node.new(self.object_id,Digest::MD5.hexdigest(Kernel::rand().to_s),:endEvent,'',1,0)
|
|
206
208
|
@graph.add_node ne
|
|
207
209
|
@graph.add_link Link.new(bn.id, ne.id)
|
|
@@ -17,12 +17,16 @@
|
|
|
17
17
|
# see <http://www.gnu.org/licenses/>.
|
|
18
18
|
|
|
19
19
|
require_relative 'structures'
|
|
20
|
+
require_relative 'target'
|
|
20
21
|
|
|
21
22
|
module CPEE
|
|
22
23
|
|
|
23
24
|
module Transformation
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
### a double quoted dot string, with \" and \\ inside
|
|
27
|
+
GRAPHVIZ_STRING = /"((?:[^"\\]|\\.)*)"/
|
|
28
|
+
|
|
29
|
+
module Source #{{{
|
|
26
30
|
|
|
27
31
|
class Graphviz
|
|
28
32
|
attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces
|
|
@@ -39,61 +43,254 @@ module CPEE
|
|
|
39
43
|
|
|
40
44
|
extract_nodelink(text)
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
if @start.nil?
|
|
47
|
+
@traces = Traces.new [[]]
|
|
48
|
+
else
|
|
49
|
+
@traces = Traces.new [[@start]]
|
|
50
|
+
end
|
|
43
51
|
end #}}}
|
|
44
52
|
|
|
45
53
|
def map_nodes(shape,label)
|
|
46
54
|
case [shape,label]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
when ['doublecircle',nil]; :endEvent
|
|
55
|
+
in ['box' | 'rect' | 'rectangle', _]; :task
|
|
56
|
+
in ['record' | 'Mrecord', _]; :scriptTask
|
|
57
|
+
in ['diamond', 'AND' | 'and' | '+']; :parallelGateway
|
|
58
|
+
in ['diamond', 'X' | 'x']; :exclusiveGateway
|
|
59
|
+
in ['diamond', '*']; :eventBasedGateway
|
|
60
|
+
in ['diamond', 'o' | 'O']; :inclusiveGateway
|
|
61
|
+
in ['circle', '' | nil]; :startEvent
|
|
62
|
+
in ['circle', '^']; :break
|
|
63
|
+
in ['circle' | 'doublecircle', 'terminate']; :terminate
|
|
64
|
+
in ['doublecircle', '' | nil]; :endEvent
|
|
58
65
|
else
|
|
59
66
|
nil
|
|
60
67
|
end
|
|
61
68
|
end
|
|
62
69
|
private :map_nodes
|
|
63
70
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
type = map_nodes($2,$4)
|
|
69
|
-
label = id
|
|
71
|
+
def unescape(s) #{{{
|
|
72
|
+
s&.gsub(/\\(.)/m) { $1 == 'n' ? "\n" : $1 }
|
|
73
|
+
end #}}}
|
|
74
|
+
private :unescape
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
def record_fields(raw) #{{{
|
|
77
|
+
raw = raw.strip
|
|
78
|
+
raw = raw[1..-2] if raw.start_with?('{') && raw =~ /(?<!\\)\}\z/
|
|
79
|
+
fields = ['']
|
|
80
|
+
raw.scan(/\\.|./m) do |c|
|
|
81
|
+
c == '|' ? fields << '' : fields.last << c
|
|
82
|
+
end
|
|
83
|
+
fields.map { |f| unescape(f.sub(/\A\s*<[^>]*>/,'')).strip }
|
|
84
|
+
end #}}}
|
|
85
|
+
private :record_fields
|
|
75
86
|
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
def record_label(raw) #{{{
|
|
88
|
+
fields = record_fields(raw)
|
|
89
|
+
fields.shift if fields.length > 1 && fields.first == 'S'
|
|
90
|
+
fields.join(' | ')
|
|
91
|
+
end #}}}
|
|
92
|
+
private :record_label
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
### key=value or key="value" pairs of an attribute list [...]
|
|
95
|
+
def attributes(text) #{{{
|
|
96
|
+
ret = {}
|
|
97
|
+
text.to_s.scan(/(\w+)\s*=\s*(?:#{GRAPHVIZ_STRING}|([^\s,;\]]+))/) do |k,q,v|
|
|
98
|
+
ret[k] = q.nil? ? v : q
|
|
81
99
|
end
|
|
100
|
+
ret
|
|
101
|
+
end #}}}
|
|
102
|
+
private :attributes
|
|
103
|
+
|
|
104
|
+
def extract_nodelink(text) #{{{
|
|
105
|
+
first = nil
|
|
106
|
+
links = []
|
|
82
107
|
text.each_line do |line|
|
|
83
|
-
if line =~ /^\s
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
if line =~ /^\s*#{GRAPHVIZ_STRING}\s*->\s*#{GRAPHVIZ_STRING}\s*(\[(.*)\])?\s*;?\s*$/
|
|
109
|
+
links << [unescape($1), unescape($2), unescape(attributes($4)['label'])]
|
|
110
|
+
elsif line =~ /^\s*#{GRAPHVIZ_STRING}\s*\[(.*)\]\s*;?\s*$/
|
|
111
|
+
id = unescape($1)
|
|
112
|
+
attrs = attributes($2)
|
|
113
|
+
### without a label graphviz shows the id
|
|
114
|
+
label = if attrs['label'].nil?
|
|
115
|
+
id
|
|
116
|
+
elsif attrs['shape'] =~ /^M?record$/
|
|
117
|
+
record_label(attrs['label'])
|
|
118
|
+
else
|
|
119
|
+
unescape(attrs['label'])
|
|
120
|
+
end
|
|
121
|
+
type = map_nodes(attrs['shape'],label)
|
|
122
|
+
|
|
123
|
+
n = Node.new(self.object_id,id,type,label,0,0)
|
|
124
|
+
@graph.add_node n
|
|
87
125
|
|
|
88
|
-
|
|
126
|
+
first = n if first.nil?
|
|
127
|
+
@start = n if n.type == :startEvent && @start.nil?
|
|
89
128
|
end
|
|
90
129
|
end
|
|
130
|
+
links.each do |lid, rid, cond|
|
|
131
|
+
@graph.add_link Link.new(lid, rid, cond)
|
|
132
|
+
@graph.nodes[lid]&.inc_outgoing!
|
|
133
|
+
@graph.nodes[rid]&.inc_incoming!
|
|
134
|
+
end
|
|
135
|
+
@start = first if @start.nil?
|
|
91
136
|
end #}}}
|
|
92
137
|
|
|
93
138
|
end
|
|
94
139
|
|
|
95
|
-
end
|
|
140
|
+
end #}}}
|
|
141
|
+
|
|
142
|
+
module Target #{{{
|
|
143
|
+
|
|
144
|
+
class Graphviz < Default
|
|
145
|
+
|
|
146
|
+
def generate
|
|
147
|
+
@nids = []
|
|
148
|
+
@labels = {}
|
|
149
|
+
@fromto = []
|
|
150
|
+
@labels['se'] = node_def('se','circle','')
|
|
151
|
+
@labels['ee'] = node_def('ee','doublecircle','')
|
|
152
|
+
pn = generate_in_list(@tree,'se')
|
|
153
|
+
set_fromto pn, 'ee'
|
|
154
|
+
"digraph G {\n" +
|
|
155
|
+
" rankdir=LR;\n" +
|
|
156
|
+
@labels.values.map{ |e| " #{e};\n" }.join +
|
|
157
|
+
@fromto.map{ |e| " #{quote e[0]} -> #{quote e[1]}#{edge_attrs e[2]};\n" }.join +
|
|
158
|
+
"}\n"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def id_find(nid)
|
|
162
|
+
### copy, next! would otherwise also change the node id and the entry in @nids
|
|
163
|
+
nid = nid ? nid.dup : 'g0'
|
|
164
|
+
while @nids.include?(nid)
|
|
165
|
+
nid.next!
|
|
166
|
+
end
|
|
167
|
+
@nids << nid
|
|
168
|
+
nid
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
private
|
|
172
|
+
|
|
173
|
+
def quote(s)
|
|
174
|
+
'"' + s.to_s.gsub(/\\/,'\\\\\\\\').gsub(/"/,'\\"').gsub(/\n/,'\\n') + '"'
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def edge_attrs(label)
|
|
178
|
+
case label
|
|
179
|
+
when nil then ''
|
|
180
|
+
when :default then '[taillabel="/" labelangle=0 labeldistance=1]'
|
|
181
|
+
else "[label=#{quote label}]"
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def node_def(nid,shape,label,style=nil)
|
|
186
|
+
"#{quote nid}[shape=#{shape}#{style ? " style=#{style}" : ''} label=#{quote label}]"
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def script_def(nid,label)
|
|
190
|
+
fields = label.to_s.gsub(/[\\"{}|<>]/) { |c| "\\#{c}" }.gsub(/\n/,'\\n')
|
|
191
|
+
"#{quote nid}[shape=record style=rounded label=\"{S|#{fields}}\"]"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def set_fromto(pn,nid)
|
|
195
|
+
if pn.is_a?(Array) && pn.length > 1
|
|
196
|
+
@fromto << [pn[0],nid,pn[1]]
|
|
197
|
+
else
|
|
198
|
+
@fromto << [pn,nid]
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def print_Node(node,pn)
|
|
203
|
+
nid = node.id
|
|
204
|
+
label = node.label.to_s.strip
|
|
205
|
+
if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
|
|
206
|
+
@labels[nid] = script_def(nid,label)
|
|
207
|
+
else
|
|
208
|
+
@labels[nid] = node_def(nid,'box',label,'rounded')
|
|
209
|
+
end
|
|
210
|
+
set_fromto pn, nid
|
|
211
|
+
nid
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
### breaks and terminates all have the same node id, so make them unique
|
|
215
|
+
def print_Break(node,pn)
|
|
216
|
+
nid = id_find('b1')
|
|
217
|
+
@labels[nid] = node_def(nid,'circle','^')
|
|
218
|
+
set_fromto pn, nid
|
|
219
|
+
nid
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def print_Terminate(node,pn)
|
|
223
|
+
nid = id_find('t1')
|
|
224
|
+
@labels[nid] = node_def(nid,'doublecircle','terminate')
|
|
225
|
+
set_fromto pn, nid
|
|
226
|
+
nid
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def print_Parallel(node,pn)
|
|
230
|
+
nid = id_find(node.id)
|
|
231
|
+
set_fromto pn, "#{nid}s"
|
|
232
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','+')
|
|
233
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','+')
|
|
234
|
+
node.sub.each do |branch|
|
|
235
|
+
pn = generate_in_list(branch,"#{nid}s")
|
|
236
|
+
set_fromto pn, "#{nid}e"
|
|
237
|
+
end
|
|
238
|
+
"#{nid}e"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def print_Conditional(node,pn)
|
|
242
|
+
nid = id_find(node.id)
|
|
243
|
+
set_fromto pn, "#{nid}s"
|
|
244
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','x')
|
|
245
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','x')
|
|
246
|
+
conditional = node.sub.any? { |branch| branch.condition.any? }
|
|
247
|
+
node.sub.each do |branch|
|
|
248
|
+
### branches without condition (incl. otherwise) are plain edges, the reader
|
|
249
|
+
### treats the last of them as otherwise
|
|
250
|
+
pn = if branch.condition.any?
|
|
251
|
+
generate_in_list(branch,["#{nid}s",branch.condition.join(' or ')])
|
|
252
|
+
elsif conditional
|
|
253
|
+
generate_in_list(branch,["#{nid}s",:default])
|
|
254
|
+
else
|
|
255
|
+
generate_in_list(branch,"#{nid}s")
|
|
256
|
+
end
|
|
257
|
+
set_fromto pn, "#{nid}e"
|
|
258
|
+
end
|
|
259
|
+
"#{nid}e"
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def print_Loop(node,pn)
|
|
263
|
+
nid = id_find(node.id)
|
|
264
|
+
set_fromto pn, "#{nid}s"
|
|
265
|
+
|
|
266
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','x')
|
|
267
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','x')
|
|
268
|
+
|
|
269
|
+
single = node.sub.length == 1 || (node.sub.length == 2 && node.sub[1].condition.empty? && ((node.sub[1].length == 1 && node.sub[1][0].class.name.gsub(/\w+:+/,'') == 'Break') || node.sub[1].length == 0))
|
|
270
|
+
### if the conditional over all alternatives decides (break), loop forever
|
|
271
|
+
cond = !single || node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && ')
|
|
272
|
+
|
|
273
|
+
cn = if node.mode == :pre_test
|
|
274
|
+
set_fromto "#{nid}s", "#{nid}e"
|
|
275
|
+
[ ["#{nid}e", cond], "#{nid}s"]
|
|
276
|
+
else
|
|
277
|
+
set_fromto ["#{nid}e",cond], "#{nid}s"
|
|
278
|
+
["#{nid}s", "#{nid}e"]
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
pn = if single
|
|
282
|
+
generate_in_list(node.sub[0],cn[0])
|
|
283
|
+
else
|
|
284
|
+
print_Conditional(node,cn[0])
|
|
285
|
+
end
|
|
286
|
+
set_fromto pn, cn[1]
|
|
287
|
+
|
|
288
|
+
"#{nid}e"
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
end
|
|
96
292
|
|
|
293
|
+
end #}}}
|
|
97
294
|
|
|
98
295
|
end
|
|
99
296
|
|
|
@@ -22,6 +22,7 @@ require 'timeout'
|
|
|
22
22
|
require_relative 'bpmn2'
|
|
23
23
|
require_relative 'mermaid'
|
|
24
24
|
require_relative 'graphviz'
|
|
25
|
+
require_relative 'pnml'
|
|
25
26
|
require_relative 'transformer'
|
|
26
27
|
require_relative 'cpee'
|
|
27
28
|
|
|
@@ -54,6 +55,12 @@ module CPEE
|
|
|
54
55
|
['text/xml', CPEE::Transformation::Target::BPMN2]
|
|
55
56
|
when 'mermaid'
|
|
56
57
|
['text/plain', CPEE::Transformation::Target::Mermaid]
|
|
58
|
+
when 'graphviz'
|
|
59
|
+
['text/plain', CPEE::Transformation::Target::Graphviz]
|
|
60
|
+
when 'pnml'
|
|
61
|
+
['text/xml', CPEE::Transformation::Target::PNML]
|
|
62
|
+
when 'pnml-with-lifecycle'
|
|
63
|
+
['text/xml', CPEE::Transformation::Target::PNML_with_lifecycle]
|
|
57
64
|
when 'text-bf'
|
|
58
65
|
['text/plain', CPEE::Transformation::Target::Text_bf]
|
|
59
66
|
when 'text-df-PO-extended'
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
<layer name="xml_cpee">
|
|
33
33
|
<apply-to>/cpee/bpmn2</apply-to>
|
|
34
34
|
<apply-to>/bpmn2/cpee</apply-to>
|
|
35
|
+
<apply-to>/pnml/cpee</apply-to>
|
|
36
|
+
<apply-to>/pnml-with-lifecycle/cpee</apply-to>
|
|
35
37
|
</layer>
|
|
36
38
|
<layer name="text_cpee">
|
|
37
39
|
<apply-to>/cpee/mermaid</apply-to>
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
</layer>
|
|
42
44
|
<layer name="xml_text">
|
|
43
45
|
<apply-to>/mermaid/cpee</apply-to>
|
|
46
|
+
<apply-to>/graphviz/cpee</apply-to>
|
|
44
47
|
<apply-to>/text-bf/cpee</apply-to>
|
|
45
48
|
<apply-to>/text-df-PO-extended/cpee</apply-to>
|
|
46
49
|
<apply-to>/text-df-PO-reduced/cpee</apply-to>
|
|
@@ -64,6 +64,42 @@ module CPEE
|
|
|
64
64
|
end
|
|
65
65
|
private :map_nodes
|
|
66
66
|
|
|
67
|
+
ENTITIES = { 'quot' => '"', 'amp' => '&', 'lt' => '<', 'gt' => '>', 'apos' => "'", 'nbsp' => " " }
|
|
68
|
+
|
|
69
|
+
### mermaid entity codes (#quot; #35;) and <br>, in one pass, so that
|
|
70
|
+
### decoded text is not decoded again
|
|
71
|
+
def decode(text) #{{{
|
|
72
|
+
text.gsub(/<br\s*\/?>|#(\d+|[a-zA-Z]+);/i) do |m|
|
|
73
|
+
code = $1 ### the =~ below would overwrite $1
|
|
74
|
+
if code.nil?
|
|
75
|
+
"\n"
|
|
76
|
+
elsif code =~ /^\d+$/
|
|
77
|
+
code.to_i.chr(Encoding::UTF_8)
|
|
78
|
+
else
|
|
79
|
+
ENTITIES[code] || m
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end #}}}
|
|
83
|
+
private :decode
|
|
84
|
+
|
|
85
|
+
### only double quotes delimit a mermaid string, single quotes are text
|
|
86
|
+
def unquote(text) #{{{
|
|
87
|
+
text = text.to_s.strip
|
|
88
|
+
if text =~ /\A"(.*)"\z/m
|
|
89
|
+
decode($1).strip
|
|
90
|
+
else
|
|
91
|
+
### older output escaped brackets instead of quoting
|
|
92
|
+
decode(text.gsub(/\\([()])/,'\1'))
|
|
93
|
+
end
|
|
94
|
+
end #}}}
|
|
95
|
+
private :unquote
|
|
96
|
+
|
|
97
|
+
### strip one pair of brackets and unquote: ( ) -> '', (" ") -> '', ("B") -> B, ('B') -> 'B'
|
|
98
|
+
def clean_label(label) #{{{
|
|
99
|
+
unquote(label.to_s.sub(/^\(/,'').sub(/\)$/,''))
|
|
100
|
+
end #}}}
|
|
101
|
+
private :clean_label
|
|
102
|
+
|
|
67
103
|
def extract_nodelink(text) #{{{
|
|
68
104
|
first = nil
|
|
69
105
|
text.each_line do |line|
|
|
@@ -91,22 +127,14 @@ module CPEE
|
|
|
91
127
|
rlabel = $3
|
|
92
128
|
end
|
|
93
129
|
|
|
94
|
-
llabel =
|
|
95
|
-
rlabel =
|
|
96
|
-
llabel.sub(/^'/,'')
|
|
97
|
-
llabel.sub(/'$/,'')
|
|
98
|
-
llabel.sub(/^"/,'')
|
|
99
|
-
llabel.sub(/"$/,'')
|
|
100
|
-
rlabel.sub(/^'/,'')
|
|
101
|
-
rlabel.sub(/'$/,'')
|
|
102
|
-
rlabel.sub(/^"/,'')
|
|
103
|
-
rlabel.sub(/"$/,'')
|
|
130
|
+
llabel = clean_label(llabel)
|
|
131
|
+
rlabel = clean_label(rlabel)
|
|
104
132
|
|
|
105
133
|
# every line contains a link
|
|
106
|
-
@graph.add_link Link.new(lid, rid, c.nil? ? nil : c
|
|
134
|
+
@graph.add_link Link.new(lid, rid, c.nil? ? nil : unquote(c))
|
|
107
135
|
|
|
108
|
-
n1 = Node.new(self.object_id,lid,map_nodes(ltype),llabel
|
|
109
|
-
n2 = Node.new(self.object_id,rid,map_nodes(rtype),rlabel
|
|
136
|
+
n1 = Node.new(self.object_id,lid,map_nodes(ltype),llabel,0,1)
|
|
137
|
+
n2 = Node.new(self.object_id,rid,map_nodes(rtype),rlabel,1,0)
|
|
110
138
|
|
|
111
139
|
@graph.add_node n1, :outgoing
|
|
112
140
|
@graph.add_node n2, :incoming
|
|
@@ -149,6 +177,15 @@ module CPEE
|
|
|
149
177
|
|
|
150
178
|
private
|
|
151
179
|
|
|
180
|
+
### always a double quoted mermaid string, with entity codes for what mermaid
|
|
181
|
+
### (html, quotes) or the reader (-->, |) would interpret. "" is a mermaid
|
|
182
|
+
### syntax error, so empty becomes " "
|
|
183
|
+
def text(s)
|
|
184
|
+
s = s.to_s.strip
|
|
185
|
+
s = s.empty? ? ' ' : s.gsub(/[#"&<>|]/) { |c| c == '"' ? '#quot;' : "##{c.ord};" }.gsub(/\r?\n/,'<br>')
|
|
186
|
+
"\"#{s}\""
|
|
187
|
+
end
|
|
188
|
+
|
|
152
189
|
def set_fromto(pn,nid)
|
|
153
190
|
if pn.is_a?(Array) && pn.length > 1
|
|
154
191
|
@fromto << [pn[0],nid,pn[1]]
|
|
@@ -160,9 +197,9 @@ module CPEE
|
|
|
160
197
|
def print_Node(node,pn)
|
|
161
198
|
nid = node.id
|
|
162
199
|
if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
|
|
163
|
-
@labels[nid] = "#{nid}:script:(#{node.label
|
|
200
|
+
@labels[nid] = "#{nid}:script:(#{text node.label})"
|
|
164
201
|
else
|
|
165
|
-
@labels[nid] = "#{nid}:task:(#{node.label
|
|
202
|
+
@labels[nid] = "#{nid}:task:(#{text node.label})"
|
|
166
203
|
end
|
|
167
204
|
set_fromto pn, nid
|
|
168
205
|
nid
|
|
@@ -186,8 +223,8 @@ module CPEE
|
|
|
186
223
|
def print_Parallel(node,pn)
|
|
187
224
|
nid = id_find(node.id)
|
|
188
225
|
set_fromto pn, "#{nid}s"
|
|
189
|
-
@labels["#{nid}s"] = "#{nid}s:parallelgateway:{
|
|
190
|
-
@labels["#{nid}e"] = "#{nid}e:parallelgateway:{
|
|
226
|
+
@labels["#{nid}s"] = "#{nid}s:parallelgateway:{+}"
|
|
227
|
+
@labels["#{nid}e"] = "#{nid}e:parallelgateway:{+}"
|
|
191
228
|
node.sub.each do |branch|
|
|
192
229
|
pn = generate_in_list(branch,"#{nid}s")
|
|
193
230
|
set_fromto pn, "#{nid}e"
|
|
@@ -204,7 +241,7 @@ module CPEE
|
|
|
204
241
|
### branches without condition (incl. otherwise) are plain edges, the reader
|
|
205
242
|
### treats the last of them as otherwise
|
|
206
243
|
pn = if branch.condition.any?
|
|
207
|
-
generate_in_list(branch,["#{nid}s","
|
|
244
|
+
generate_in_list(branch,["#{nid}s","|#{text branch.condition.join(' or ')}|"])
|
|
208
245
|
else
|
|
209
246
|
generate_in_list(branch,"#{nid}s")
|
|
210
247
|
end
|
|
@@ -226,9 +263,9 @@ module CPEE
|
|
|
226
263
|
|
|
227
264
|
cn = if node.mode == :pre_test
|
|
228
265
|
set_fromto "#{nid}s", "#{nid}e"
|
|
229
|
-
[ ["#{nid}e", "
|
|
266
|
+
[ ["#{nid}e", "|#{text cond}|"], "#{nid}s"]
|
|
230
267
|
else
|
|
231
|
-
set_fromto ["#{nid}e","
|
|
268
|
+
set_fromto ["#{nid}e","|#{text cond}|"], "#{nid}s"
|
|
232
269
|
["#{nid}s", "#{nid}e"]
|
|
233
270
|
end
|
|
234
271
|
|