cpee-transformation 1.0.3 → 1.0.7
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 +73 -1
- data/cpee-transformation.gemspec +10 -2
- data/lib/cpee/transformation/bpmn2.rb +35 -2
- data/lib/cpee/transformation/cpee.rb +49 -5
- data/lib/cpee/transformation/graphviz.rb +190 -33
- data/lib/cpee/transformation/implementation.rb +6 -0
- data/lib/cpee/transformation/implementation.xml +4 -0
- data/lib/cpee/transformation/mermaid.rb +55 -18
- data/lib/cpee/transformation/ptml.rb +71 -68
- data/lib/cpee/transformation/structures.rb +41 -6
- data/lib/cpee/transformation/target.rb +14 -1
- data/lib/cpee/transformation/transformer.rb +1 -1
- data/server/trans.conf +1 -0
- data/tools/trans_bpmn2-to-graphviz +85 -0
- data/tools/{bpmn2_to_ptml.rb → trans_bpmn2-to-ptml} +1 -3
- data/tools/trans_cpee-to-bpmn2 +92 -0
- data/tools/trans_cpee-to-graphviz +85 -0
- data/tools/{cpee_to_ptml.rb → trans_cpee-to-ptml} +1 -3
- metadata +35 -24
- /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/{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_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: 05ee4c81d220cd2715128abc5300b30d1b2d67f6fc77917b192f8df72a70b829
|
|
4
|
+
data.tar.gz: 0dcab077fda611e0df946cf4161b1676e344126c0246067cc74961ace701938f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ce23a76f587df201178a0c309ebb878b5129a6f2947aa68e53b8ea4d868483271c94d75b2051d04757b10136b247c0cc7788f512dd3cc597f5348516a4e7547
|
|
7
|
+
data.tar.gz: ba6ba74143c9bb60e63c88985a4c8f8d53fe58595da55d2d7331c91d08b0c6688e483a8aad0304837157f3fc72e5f4a008b586395449b567f261ba65fc071e5d
|
data/README.md
CHANGED
|
@@ -1 +1,73 @@
|
|
|
1
|
-
# cpee-transformation
|
|
1
|
+
# cpee-transformation
|
|
2
|
+
|
|
3
|
+
## Dependencies
|
|
4
|
+
|
|
5
|
+
The Ruby dependencies (riddl, xml-smart, ...) are installed with the gem. The
|
|
6
|
+
BPMN2 target additionally needs
|
|
7
|
+
[cpee-layout](https://github.com/etm/cpee-layout) (Node.js >= 22.22), which is
|
|
8
|
+
not a gem dependency. By default it is run through `npx`, which fetches it on
|
|
9
|
+
first use (so the first BPMN2 request needs network access and is slow). To
|
|
10
|
+
avoid that, install it and point `trans.conf` to it (see BPMN2 target):
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install -g cpee-layout
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Without Node.js, everything except the `/bpmn2/...` routes works.
|
|
17
|
+
|
|
18
|
+
## Service
|
|
19
|
+
|
|
20
|
+
`cpee-trans new DIR` scaffolds the service into `DIR`: the server `trans` and
|
|
21
|
+
its config `trans.conf`, which is read from the same directory.
|
|
22
|
+
|
|
23
|
+
`trans` (port 9295) transforms process models. Routes are
|
|
24
|
+
`/TARGET/SOURCE`, POSTed with the model as `description` and `type` set to
|
|
25
|
+
`description` (the transformed model), `dataelements` or `endpoints` (lists of
|
|
26
|
+
name/value pairs, from BPMN2 sources only).
|
|
27
|
+
|
|
28
|
+
| Route | Source | Target |
|
|
29
|
+
| --------------------------- | -------- | -------------------------- |
|
|
30
|
+
| `/cpee/bpmn2` | BPMN2 | CPEE |
|
|
31
|
+
| `/cpee/mermaid` | mermaid | CPEE |
|
|
32
|
+
| `/cpee/graphviz` | graphviz | CPEE |
|
|
33
|
+
| `/bpmn2/cpee` | CPEE | BPMN2 |
|
|
34
|
+
| `/bpmn2/mermaid` | mermaid | BPMN2 |
|
|
35
|
+
| `/bpmn2/graphviz` | graphviz | BPMN2 |
|
|
36
|
+
| `/mermaid/cpee` | CPEE | mermaid |
|
|
37
|
+
| `/graphviz/cpee` | CPEE | graphviz |
|
|
38
|
+
| `/text-bf/cpee` | CPEE | text, text-bf |
|
|
39
|
+
| `/text-df-PO-extended/cpee` | CPEE | text, text-df-PO-extended |
|
|
40
|
+
| `/text-df-PO-reduced/cpee` | CPEE | text, text-df-PO-reduced |
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
curl -F 'description=@model.xml;type=text/xml' -F 'type=description' http://localhost:9295/bpmn2/cpee
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### BPMN2 target
|
|
47
|
+
|
|
48
|
+
The BPMN2 target generates the CPEE model and lays it out with `bpmnexport`
|
|
49
|
+
from [cpee-layout](https://github.com/etm/cpee-layout), so the result is BPMN
|
|
50
|
+
with diagram interchange, laid out as drawn by cpee-layout. How `bpmnexport` is
|
|
51
|
+
run is set in `trans.conf`. The default (also without a setting) is
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
:bpmnexport: npx -y -p cpee-layout@^1.2.0 bpmnexport
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
and after `npm install -g cpee-layout` it can be
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
:bpmnexport: bpmnexport
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A command name is searched in `PATH`, a path (containing `/`) is relative to
|
|
64
|
+
the directory of `trans`, `~` works too, e.g.
|
|
65
|
+
`~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow.
|
|
66
|
+
|
|
67
|
+
The layout direction follows the model: the cockpit sets `dir="lr"` or
|
|
68
|
+
`dir="td"` on the `<description>` root, depending on its theme, and `-lr` is
|
|
69
|
+
added for `dir="lr"`. Putting `-lr` into `trans.conf` makes every BPMN left to
|
|
70
|
+
right.
|
|
71
|
+
|
|
72
|
+
`tools/trans_cpee-to-bpmn2 FNAME` does the same on the command line, using the
|
|
73
|
+
`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.0.7"
|
|
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
|
|
|
@@ -25,5 +25,13 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.add_runtime_dependency 'xml-smart', '~> 0.4'
|
|
26
26
|
s.add_runtime_dependency 'typhoeus', '~> 1.4'
|
|
27
27
|
s.add_runtime_dependency 'highline', '~> 2.0'
|
|
28
|
+
|
|
29
|
+
s.post_install_message = <<~MSG
|
|
30
|
+
The BPMN2 target uses bpmnexport from cpee-layout (Node.js >= 22.22). By
|
|
31
|
+
default npx fetches it on first use. To avoid that, run
|
|
32
|
+
npm install -g cpee-layout
|
|
33
|
+
and set ":bpmnexport: bpmnexport" in trans.conf of your service
|
|
34
|
+
(scaffolded with cpee-trans new DIR).
|
|
35
|
+
MSG
|
|
28
36
|
end
|
|
29
37
|
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
# see <http://www.gnu.org/licenses/>.
|
|
18
18
|
|
|
19
19
|
require_relative 'structures'
|
|
20
|
+
require_relative 'target'
|
|
21
|
+
require_relative 'cpee'
|
|
20
22
|
require 'xml/smart'
|
|
23
|
+
require 'open3'
|
|
24
|
+
require 'shellwords'
|
|
21
25
|
|
|
22
26
|
module CPEE
|
|
23
27
|
|
|
@@ -73,11 +77,12 @@ module CPEE
|
|
|
73
77
|
end #}}}
|
|
74
78
|
|
|
75
79
|
def extract_nodelink(doc) #{{{
|
|
76
|
-
|
|
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|
|
|
77
82
|
type = e.qname.name.to_sym
|
|
78
83
|
### an end event with a terminate definition ends the whole process
|
|
79
84
|
type = :terminate if type == :endEvent && e.find('bm:terminateEventDefinition').any?
|
|
80
|
-
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)'))
|
|
81
86
|
|
|
82
87
|
if e.attributes['scriptFormat'] != ''
|
|
83
88
|
n.script_type = e.attributes['scriptFormat']
|
|
@@ -142,6 +147,34 @@ module CPEE
|
|
|
142
147
|
|
|
143
148
|
end
|
|
144
149
|
|
|
150
|
+
module Target #{{{
|
|
151
|
+
|
|
152
|
+
# bpmnexport from cpee-layout (npm install -g cpee-layout) lays out the
|
|
153
|
+
# generated CPEE model as drawn and writes it as BPMN with diagram
|
|
154
|
+
# interchange. opts[:bpmnexport] (trans.conf) is a command name, searched
|
|
155
|
+
# in PATH, or a path, relative to the server dir, optionally followed by
|
|
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).
|
|
158
|
+
class BPMN2 < Default
|
|
159
|
+
BPMNEXPORT = 'npx -y -p cpee-layout@^1.2.0 bpmnexport'
|
|
160
|
+
|
|
161
|
+
class << self
|
|
162
|
+
attr_accessor :opts
|
|
163
|
+
end
|
|
164
|
+
@opts = {}
|
|
165
|
+
|
|
166
|
+
def generate
|
|
167
|
+
opts = self.class.opts
|
|
168
|
+
cmd, *args = Shellwords.split(opts[:bpmnexport] || BPMNEXPORT)
|
|
169
|
+
cmd = File.expand_path(cmd, opts[:basepath] || Dir.pwd) if cmd.include?('/')
|
|
170
|
+
args << '-lr' if @dir == 'lr' && !args.include?('-lr')
|
|
171
|
+
out, err, st = Open3.capture3(cmd, *args, '-', stdin_data: Target::CPEE.new(@tree).generate)
|
|
172
|
+
raise "#{cmd}: #{err}" unless st.success?
|
|
173
|
+
out
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end #}}}
|
|
145
178
|
|
|
146
179
|
end
|
|
147
180
|
|
|
@@ -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'
|
|
@@ -119,6 +119,12 @@ module CPEE
|
|
|
119
119
|
n1 = no
|
|
120
120
|
when 'parallel'
|
|
121
121
|
bra = ele.find('d:parallel_branch')
|
|
122
|
+
if bra.empty? && ele.find('d:*').length == 1
|
|
123
|
+
### e.g. branches created in a loop: content is a sequence
|
|
124
|
+
n1 = dive_single(SingleParallel, ele, n1, condition, otherwise)
|
|
125
|
+
condition = nil
|
|
126
|
+
next
|
|
127
|
+
end
|
|
122
128
|
nid = id_find(ele.attributes['eid'])
|
|
123
129
|
ns = Node.new(self.object_id,nid,:parallelGateway,nil,1,bra.length)
|
|
124
130
|
ns.attributes[:wait] = ele.attributes['wait'] || -1
|
|
@@ -151,6 +157,10 @@ module CPEE
|
|
|
151
157
|
end
|
|
152
158
|
end
|
|
153
159
|
n1 = ne
|
|
160
|
+
when 'parallel_branch'
|
|
161
|
+
### only reached when not a direct child of a parallel
|
|
162
|
+
n1 = dive_single(SingleParallelBranch, ele, n1, condition, otherwise)
|
|
163
|
+
condition = nil
|
|
154
164
|
when 'escape'
|
|
155
165
|
nid = id_find(ele.attributes['eid'])
|
|
156
166
|
no = Node.new(self.object_id,nid,:break,'',1,1)
|
|
@@ -171,10 +181,29 @@ module CPEE
|
|
|
171
181
|
end
|
|
172
182
|
private :dive
|
|
173
183
|
|
|
184
|
+
### open marker, content as a sequence, close marker
|
|
185
|
+
def dive_single(klass,ele,n1,condition,otherwise)
|
|
186
|
+
attrs = {}
|
|
187
|
+
ele.attributes.each { |a| attrs[a.qname.name] = a.value unless a.qname.name == 'eid' }
|
|
188
|
+
nid = id_find(ele.attributes['eid'])
|
|
189
|
+
ns = klass.new(self.object_id,nid,true,attrs)
|
|
190
|
+
@graph.add_node ns
|
|
191
|
+
@graph.add_link Link.new(n1.id, ns.id, condition, otherwise)
|
|
192
|
+
bn = dive ele, ns
|
|
193
|
+
ne = klass.new(self.object_id,nid + 'e',false)
|
|
194
|
+
@graph.add_node ne
|
|
195
|
+
@graph.add_link Link.new(bn.id, ne.id)
|
|
196
|
+
ne
|
|
197
|
+
end
|
|
198
|
+
private :dive_single
|
|
199
|
+
|
|
174
200
|
def extract_original(text)
|
|
175
201
|
doc = XML::Smart::string(text)
|
|
176
202
|
doc.register_namespace :d, 'http://cpee.org/ns/description/1.0'
|
|
177
|
-
|
|
203
|
+
# a model (root description) or a testset, which contains it
|
|
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)
|
|
178
207
|
ne = Node.new(self.object_id,Digest::MD5.hexdigest(Kernel::rand().to_s),:endEvent,'',1,0)
|
|
179
208
|
@graph.add_node ne
|
|
180
209
|
@graph.add_link Link.new(bn.id, ne.id)
|
|
@@ -199,6 +228,21 @@ module CPEE
|
|
|
199
228
|
end
|
|
200
229
|
|
|
201
230
|
private
|
|
231
|
+
### open: everything up to the close marker goes inside
|
|
232
|
+
def print_single(name,node,res)
|
|
233
|
+
if node.open?
|
|
234
|
+
res.add(name, node.attributes.merge('a:alt_id' => node.id, 'eid' => "e#{(@eid += 1)}"))
|
|
235
|
+
else
|
|
236
|
+
res.parent
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
def print_SingleParallel(node,res)
|
|
240
|
+
print_single('parallel',node,res)
|
|
241
|
+
end
|
|
242
|
+
def print_SingleParallelBranch(node,res)
|
|
243
|
+
print_single('parallel_branch',node,res)
|
|
244
|
+
end
|
|
245
|
+
|
|
202
246
|
def print_Break(node,res)
|
|
203
247
|
res.add('escape', 'a:alt_id' => node.id)
|
|
204
248
|
res
|
|
@@ -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,214 @@ 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 ['component', _]; :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
|
|
|
71
|
+
def unescape(s) #{{{
|
|
72
|
+
s&.gsub(/\\(.)/m) { $1 == 'n' ? "\n" : $1 }
|
|
73
|
+
end #}}}
|
|
74
|
+
private :unescape
|
|
75
|
+
|
|
76
|
+
### key=value or key="value" pairs of an attribute list [...]
|
|
77
|
+
def attributes(text) #{{{
|
|
78
|
+
ret = {}
|
|
79
|
+
text.to_s.scan(/(\w+)\s*=\s*(?:#{GRAPHVIZ_STRING}|([^\s,;\]]+))/) do |k,q,v|
|
|
80
|
+
ret[k] = q.nil? ? v : unescape(q)
|
|
81
|
+
end
|
|
82
|
+
ret
|
|
83
|
+
end #}}}
|
|
84
|
+
private :attributes
|
|
85
|
+
|
|
64
86
|
def extract_nodelink(text) #{{{
|
|
87
|
+
first = nil
|
|
88
|
+
links = []
|
|
65
89
|
text.each_line do |line|
|
|
66
|
-
if line =~ /^\s*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
label
|
|
73
|
-
label
|
|
74
|
-
label.sub(/"$/,'')
|
|
90
|
+
if line =~ /^\s*#{GRAPHVIZ_STRING}\s*->\s*#{GRAPHVIZ_STRING}\s*(\[(.*)\])?\s*;?\s*$/
|
|
91
|
+
links << [unescape($1), unescape($2), attributes($4)['label']]
|
|
92
|
+
elsif line =~ /^\s*#{GRAPHVIZ_STRING}\s*\[(.*)\]\s*;?\s*$/
|
|
93
|
+
id = unescape($1)
|
|
94
|
+
attrs = attributes($2)
|
|
95
|
+
type = map_nodes(attrs['shape'],attrs['label'])
|
|
96
|
+
### without a label graphviz shows the id
|
|
97
|
+
label = attrs['label'] || id
|
|
75
98
|
|
|
76
|
-
n = Node.new(
|
|
99
|
+
n = Node.new(self.object_id,id,type,label,0,0)
|
|
77
100
|
@graph.add_node n
|
|
78
101
|
|
|
79
|
-
|
|
102
|
+
first = n if first.nil?
|
|
103
|
+
@start = n if n.type == :startEvent && @start.nil?
|
|
80
104
|
end
|
|
81
105
|
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
cond = $5
|
|
87
|
-
|
|
88
|
-
@graph.add_link Link.new(lid, rid, cond.nil? ? nil : cond)
|
|
89
|
-
end
|
|
106
|
+
links.each do |lid, rid, cond|
|
|
107
|
+
@graph.add_link Link.new(lid, rid, cond)
|
|
108
|
+
@graph.nodes[lid]&.inc_outgoing!
|
|
109
|
+
@graph.nodes[rid]&.inc_incoming!
|
|
90
110
|
end
|
|
111
|
+
@start = first if @start.nil?
|
|
91
112
|
end #}}}
|
|
92
113
|
|
|
93
114
|
end
|
|
94
115
|
|
|
95
|
-
end
|
|
116
|
+
end #}}}
|
|
117
|
+
|
|
118
|
+
module Target #{{{
|
|
119
|
+
|
|
120
|
+
class Graphviz < Default
|
|
121
|
+
|
|
122
|
+
def generate
|
|
123
|
+
@nids = []
|
|
124
|
+
@labels = {}
|
|
125
|
+
@fromto = []
|
|
126
|
+
@labels['se'] = node_def('se','circle','')
|
|
127
|
+
@labels['ee'] = node_def('ee','doublecircle','')
|
|
128
|
+
pn = generate_in_list(@tree,'se')
|
|
129
|
+
set_fromto pn, 'ee'
|
|
130
|
+
"digraph G {\n" +
|
|
131
|
+
" rankdir=LR;\n" +
|
|
132
|
+
@labels.values.map{ |e| " #{e};\n" }.join +
|
|
133
|
+
@fromto.map{ |e| " #{quote e[0]} -> #{quote e[1]}#{e.length == 3 ? "[label=#{quote e[2]}]" : ''};\n" }.join +
|
|
134
|
+
"}\n"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def id_find(nid)
|
|
138
|
+
### copy, next! would otherwise also change the node id and the entry in @nids
|
|
139
|
+
nid = nid ? nid.dup : 'g0'
|
|
140
|
+
while @nids.include?(nid)
|
|
141
|
+
nid.next!
|
|
142
|
+
end
|
|
143
|
+
@nids << nid
|
|
144
|
+
nid
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def quote(s)
|
|
150
|
+
'"' + s.to_s.gsub(/\\/,'\\\\\\\\').gsub(/"/,'\\"').gsub(/\n/,'\\n') + '"'
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def node_def(nid,shape,label,style=nil)
|
|
154
|
+
"#{quote nid}[shape=#{shape}#{style ? " style=#{style}" : ''} label=#{quote label}]"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def set_fromto(pn,nid)
|
|
158
|
+
if pn.is_a?(Array) && pn.length > 1
|
|
159
|
+
@fromto << [pn[0],nid,pn[1]]
|
|
160
|
+
else
|
|
161
|
+
@fromto << [pn,nid]
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def print_Node(node,pn)
|
|
166
|
+
nid = node.id
|
|
167
|
+
label = node.label.to_s.strip
|
|
168
|
+
if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
|
|
169
|
+
@labels[nid] = node_def(nid,'component',label)
|
|
170
|
+
else
|
|
171
|
+
@labels[nid] = node_def(nid,'box',label,'rounded')
|
|
172
|
+
end
|
|
173
|
+
set_fromto pn, nid
|
|
174
|
+
nid
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
### breaks and terminates all have the same node id, so make them unique
|
|
178
|
+
def print_Break(node,pn)
|
|
179
|
+
nid = id_find('b1')
|
|
180
|
+
@labels[nid] = node_def(nid,'circle','^')
|
|
181
|
+
set_fromto pn, nid
|
|
182
|
+
nid
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def print_Terminate(node,pn)
|
|
186
|
+
nid = id_find('t1')
|
|
187
|
+
@labels[nid] = node_def(nid,'doublecircle','terminate')
|
|
188
|
+
set_fromto pn, nid
|
|
189
|
+
nid
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def print_Parallel(node,pn)
|
|
193
|
+
nid = id_find(node.id)
|
|
194
|
+
set_fromto pn, "#{nid}s"
|
|
195
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','AND')
|
|
196
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','AND')
|
|
197
|
+
node.sub.each do |branch|
|
|
198
|
+
pn = generate_in_list(branch,"#{nid}s")
|
|
199
|
+
set_fromto pn, "#{nid}e"
|
|
200
|
+
end
|
|
201
|
+
"#{nid}e"
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def print_Conditional(node,pn)
|
|
205
|
+
nid = id_find(node.id)
|
|
206
|
+
set_fromto pn, "#{nid}s"
|
|
207
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','x')
|
|
208
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','x')
|
|
209
|
+
node.sub.each do |branch|
|
|
210
|
+
### branches without condition (incl. otherwise) are plain edges, the reader
|
|
211
|
+
### treats the last of them as otherwise
|
|
212
|
+
pn = if branch.condition.any?
|
|
213
|
+
generate_in_list(branch,["#{nid}s",branch.condition.join(' or ')])
|
|
214
|
+
else
|
|
215
|
+
generate_in_list(branch,"#{nid}s")
|
|
216
|
+
end
|
|
217
|
+
set_fromto pn, "#{nid}e"
|
|
218
|
+
end
|
|
219
|
+
"#{nid}e"
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def print_Loop(node,pn)
|
|
223
|
+
nid = id_find(node.id)
|
|
224
|
+
set_fromto pn, "#{nid}s"
|
|
225
|
+
|
|
226
|
+
@labels["#{nid}s"] = node_def("#{nid}s",'diamond','x')
|
|
227
|
+
@labels["#{nid}e"] = node_def("#{nid}e",'diamond','x')
|
|
228
|
+
|
|
229
|
+
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))
|
|
230
|
+
### if the conditional over all alternatives decides (break), loop forever
|
|
231
|
+
cond = !single || node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && ')
|
|
232
|
+
|
|
233
|
+
cn = if node.mode == :pre_test
|
|
234
|
+
set_fromto "#{nid}s", "#{nid}e"
|
|
235
|
+
[ ["#{nid}e", cond], "#{nid}s"]
|
|
236
|
+
else
|
|
237
|
+
set_fromto ["#{nid}e",cond], "#{nid}s"
|
|
238
|
+
["#{nid}s", "#{nid}e"]
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
pn = if single
|
|
242
|
+
generate_in_list(node.sub[0],cn[0])
|
|
243
|
+
else
|
|
244
|
+
print_Conditional(node,cn[0])
|
|
245
|
+
end
|
|
246
|
+
set_fromto pn, cn[1]
|
|
247
|
+
|
|
248
|
+
"#{nid}e"
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
96
252
|
|
|
253
|
+
end #}}}
|
|
97
254
|
|
|
98
255
|
end
|
|
99
256
|
|
|
@@ -50,8 +50,12 @@ module CPEE
|
|
|
50
50
|
mtype, target = case @h['RIDDL_DECLARATION_PATH'].split('/')[-2]
|
|
51
51
|
when 'cpee'
|
|
52
52
|
['text/xml', CPEE::Transformation::Target::CPEE]
|
|
53
|
+
when 'bpmn2'
|
|
54
|
+
['text/xml', CPEE::Transformation::Target::BPMN2]
|
|
53
55
|
when 'mermaid'
|
|
54
56
|
['text/plain', CPEE::Transformation::Target::Mermaid]
|
|
57
|
+
when 'graphviz'
|
|
58
|
+
['text/plain', CPEE::Transformation::Target::Graphviz]
|
|
55
59
|
when 'text-bf'
|
|
56
60
|
['text/plain', CPEE::Transformation::Target::Text_bf]
|
|
57
61
|
when 'text-df-PO-extended'
|
|
@@ -118,6 +122,8 @@ module CPEE
|
|
|
118
122
|
end #}}}
|
|
119
123
|
|
|
120
124
|
def self::implementation(opts)
|
|
125
|
+
# the hash itself, as --config is merged into it only afterwards
|
|
126
|
+
CPEE::Transformation::Target::BPMN2.opts = opts
|
|
121
127
|
Proc.new do
|
|
122
128
|
interface 'xml_cpee' do
|
|
123
129
|
run ExtractDescription if post 'xmldedesc'
|
|
@@ -31,13 +31,17 @@
|
|
|
31
31
|
<tile>
|
|
32
32
|
<layer name="xml_cpee">
|
|
33
33
|
<apply-to>/cpee/bpmn2</apply-to>
|
|
34
|
+
<apply-to>/bpmn2/cpee</apply-to>
|
|
34
35
|
</layer>
|
|
35
36
|
<layer name="text_cpee">
|
|
36
37
|
<apply-to>/cpee/mermaid</apply-to>
|
|
37
38
|
<apply-to>/cpee/graphviz</apply-to>
|
|
39
|
+
<apply-to>/bpmn2/mermaid</apply-to>
|
|
40
|
+
<apply-to>/bpmn2/graphviz</apply-to>
|
|
38
41
|
</layer>
|
|
39
42
|
<layer name="xml_text">
|
|
40
43
|
<apply-to>/mermaid/cpee</apply-to>
|
|
44
|
+
<apply-to>/graphviz/cpee</apply-to>
|
|
41
45
|
<apply-to>/text-bf/cpee</apply-to>
|
|
42
46
|
<apply-to>/text-df-PO-extended/cpee</apply-to>
|
|
43
47
|
<apply-to>/text-df-PO-reduced/cpee</apply-to>
|