cpee-transformation 1.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e864c92b6f08671c7597c20f38324a63aabfaf8c4fb4a0faf13bf0673ffede3a
4
- data.tar.gz: ff4e121e613c2cfa9989febfe4ef347d48771349769f57d3f473d83893b7d444
3
+ metadata.gz: 05ee4c81d220cd2715128abc5300b30d1b2d67f6fc77917b192f8df72a70b829
4
+ data.tar.gz: 0dcab077fda611e0df946cf4161b1676e344126c0246067cc74961ace701938f
5
5
  SHA512:
6
- metadata.gz: 005ccfff1028e4f76549c4fb02e8c45a99aab234ab29e6c314066e772d12e798eaf8b67c5598c1d447ae31fd00a8894afa5ed6a30e4bc9a78818ed31a65a18c0
7
- data.tar.gz: 343c9853cbb58c160fe6883f5f94e96cf6484010139aef4309e310d506728ec5d3bb7600767919b10c622a8ca9e6e84d9eedd43153c4069bb35b93d26604af1f
6
+ metadata.gz: 7ce23a76f587df201178a0c309ebb878b5129a6f2947aa68e53b8ea4d868483271c94d75b2051d04757b10136b247c0cc7788f512dd3cc597f5348516a4e7547
7
+ data.tar.gz: ba6ba74143c9bb60e63c88985a4c8f8d53fe58595da55d2d7331c91d08b0c6688e483a8aad0304837157f3fc72e5f4a008b586395449b567f261ba65fc071e5d
data/README.md CHANGED
@@ -34,6 +34,7 @@ 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 |
37
38
  | `/text-bf/cpee` | CPEE | text, text-bf |
38
39
  | `/text-df-PO-extended/cpee` | CPEE | text, text-df-PO-extended |
39
40
  | `/text-df-PO-reduced/cpee` | CPEE | text, text-df-PO-reduced |
@@ -61,8 +62,12 @@ and after `npm install -g cpee-layout` it can be
61
62
 
62
63
  A command name is searched in `PATH`, a path (containing `/`) is relative to
63
64
  the directory of `trans`, `~` works too, e.g.
64
- `~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow, e.g. `bpmnexport -lr` for a left to
65
- right layout.
65
+ `~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow.
66
66
 
67
- `tools/cpee_to_bpmn2.rb FNAME` does the same on the command line, using the
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
68
73
  `server/trans.conf` of the gem. If `bpmnexport` can't be run or fails, the request returns 500.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-transformation"
3
- s.version = "1.0.6"
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 = ['bpmn2_to_cpee.rb', 'bpmn2_to_mermaid.rb', 'bpmn2_to_ptml.rb', 'cpee_to_bpmn2.rb', 'cpee_to_cpee.rb', 'cpee_to_mermaid.rb', 'cpee_to_ptml.rb', 'cpee_to_text_bf.rb', 'cpee_to_text_df-poe.rb', 'cpee_to_text_df-por.rb', 'cpee-trans', 'mermaid_to_cpee.rb', 'ptml_to_cpee.rb']
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
- doc.find("/bm:definitions/bm:process/bm:*[@id and @name and not(@itemSubjectRef) and not(name()='sequenceFlow')]").each do |e|
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 (e.g. -lr). By default npx fetches cpee-layout on first use.
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
- bn = dive(doc.find('//d:description').first || doc.root)
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
- module Source
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
- @traces = Traces.new [[@start]]
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
- when ['rectangle',nil]; :task
48
- when ['diamond','AND']; :parallelGateway
49
- when ['diamond','and']; :parallelGateway
50
- when ['diamond','X']; :exclusiveGateway
51
- when ['diamond','x']; :exclusiveGateway
52
- when ['diamond','*']; :eventBasedGateway
53
- when ['diamond','o']; :inclusiveGateway
54
- when ['circle','']; :startEvent
55
- when ['circle',nil]; :startEvent
56
- when ['doublecircle','']; :endEvent
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*"([^"]+)"\[shape=([a-z]+)(\slabel="([^"]*)")?\]\s*;?/
67
- id = $1
68
- type = map_nodes($2,$4)
69
- label = id
70
-
71
- label.sub(/^'/,'')
72
- label.sub(/'$/,'')
73
- label.sub(/^"/,'')
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(0,id,type,label,0,1)
99
+ n = Node.new(self.object_id,id,type,label,0,0)
77
100
  @graph.add_node n
78
101
 
79
- @start = n if n.type == :startEvent && @start == nil
102
+ first = n if first.nil?
103
+ @start = n if n.type == :startEvent && @start.nil?
80
104
  end
81
105
  end
82
- text.each_line do |line|
83
- if line =~ /^\s*"([^"]+)"\s+->\s+"([^"]+)"(\s*\[(label="([^"]*)")?\])?\s*;?/
84
- lid = $1
85
- rid = $2
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
 
@@ -54,6 +54,8 @@ module CPEE
54
54
  ['text/xml', CPEE::Transformation::Target::BPMN2]
55
55
  when 'mermaid'
56
56
  ['text/plain', CPEE::Transformation::Target::Mermaid]
57
+ when 'graphviz'
58
+ ['text/plain', CPEE::Transformation::Target::Graphviz]
57
59
  when 'text-bf'
58
60
  ['text/plain', CPEE::Transformation::Target::Text_bf]
59
61
  when 'text-df-PO-extended'
@@ -41,6 +41,7 @@
41
41
  </layer>
42
42
  <layer name="xml_text">
43
43
  <apply-to>/mermaid/cpee</apply-to>
44
+ <apply-to>/graphviz/cpee</apply-to>
44
45
  <apply-to>/text-bf/cpee</apply-to>
45
46
  <apply-to>/text-df-PO-extended/cpee</apply-to>
46
47
  <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 = '' if llabel.nil?
95
- rlabel = '' if rlabel.nil?
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.to_s.gsub(/(^"|"$)/, ''))
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.sub(/^\(/,'').sub(/\)$/,''),0,1)
109
- n2 = Node.new(self.object_id,rid,map_nodes(rtype),rlabel.sub(/^\(/,'').sub(/\)$/,''),1,0)
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.gsub(/\(/,"\\(").gsub(/\)/,"\\)")})"
200
+ @labels[nid] = "#{nid}:script:(#{text node.label})"
164
201
  else
165
- @labels[nid] = "#{nid}:task:(#{node.label.gsub(/\(/,"\\(").gsub(/\)/,"\\)")})"
202
+ @labels[nid] = "#{nid}:task:(#{text node.label})"
166
203
  end
167
204
  set_fromto pn, nid
168
205
  nid
@@ -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","|\"#{branch.condition.join(' or ')}\"|"])
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", "|\"#{cond}\"|"], "#{nid}s"]
266
+ [ ["#{nid}e", "|#{text cond}|"], "#{nid}s"]
230
267
  else
231
- set_fromto ["#{nid}e","|\"#{cond}\"|"], "#{nid}s"
268
+ set_fromto ["#{nid}e","|#{text cond}|"], "#{nid}s"
232
269
  ["#{nid}s", "#{nid}e"]
233
270
  end
234
271
 
@@ -23,8 +23,9 @@ module CPEE
23
23
  module Target
24
24
 
25
25
  class Default
26
- def initialize(tree)
26
+ def initialize(tree,dir=nil)
27
27
  @tree = tree
28
+ @dir = dir # layout direction of the source model (td, lr), if known
28
29
  end
29
30
 
30
31
  ### SingleParallel markers are only printed by targets that know them
@@ -308,7 +308,7 @@ module CPEE
308
308
  private :debug_print
309
309
 
310
310
  def generate_model(formater) #{{{
311
- formater.new(@source.tree).generate
311
+ formater.new(@source.tree, @source.respond_to?(:dir) ? @source.dir : nil).generate
312
312
  end #}}}
313
313
 
314
314
  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 LICENSE 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/graphviz' 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 graphviz 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::Graphviz)
85
+ 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 LICENSE 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/graphviz' 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 tree in file FNAME to graphviz 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::CPEE.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::Graphviz)
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-transformation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
@@ -83,19 +83,19 @@ dependencies:
83
83
  description: see http://cpee.org
84
84
  email: juergen.mangler@gmail.com
85
85
  executables:
86
- - bpmn2_to_cpee.rb
87
- - bpmn2_to_mermaid.rb
88
- - bpmn2_to_ptml.rb
89
86
  - cpee-trans
90
- - cpee_to_bpmn2.rb
91
- - cpee_to_cpee.rb
92
- - cpee_to_mermaid.rb
93
- - cpee_to_ptml.rb
94
- - cpee_to_text_bf.rb
95
- - cpee_to_text_df-poe.rb
96
- - cpee_to_text_df-por.rb
97
- - mermaid_to_cpee.rb
98
- - ptml_to_cpee.rb
87
+ - trans_bpmn2-to-cpee
88
+ - trans_bpmn2-to-mermaid
89
+ - trans_bpmn2-to-ptml
90
+ - trans_cpee-to-bpmn2
91
+ - trans_cpee-to-cpee
92
+ - trans_cpee-to-mermaid
93
+ - trans_cpee-to-ptml
94
+ - trans_cpee-to-text-bf
95
+ - trans_cpee-to-text-df-poe
96
+ - trans_cpee-to-text-df-por
97
+ - trans_mermaid-to-cpee
98
+ - trans_ptml-to-cpee
99
99
  extensions: []
100
100
  extra_rdoc_files:
101
101
  - README.md
@@ -125,21 +125,22 @@ files:
125
125
  - lib/cpee/transformation/transformer.rb
126
126
  - server/trans
127
127
  - server/trans.conf
128
- - server/trans.pid
129
- - tools/bpmn2_to_cpee.rb
130
- - tools/bpmn2_to_mermaid.rb
131
- - tools/bpmn2_to_ptml.rb
132
128
  - tools/cpee-trans
133
- - tools/cpee_to_bpmn2.rb
134
- - tools/cpee_to_cpee.rb
135
- - tools/cpee_to_dataflow.rb
136
- - tools/cpee_to_mermaid.rb
137
- - tools/cpee_to_ptml.rb
138
- - tools/cpee_to_text_bf.rb
139
- - tools/cpee_to_text_df-poe.rb
140
- - tools/cpee_to_text_df-por.rb
141
- - tools/mermaid_to_cpee.rb
142
- - tools/ptml_to_cpee.rb
129
+ - tools/trans_bpmn2-to-cpee
130
+ - tools/trans_bpmn2-to-graphviz
131
+ - tools/trans_bpmn2-to-mermaid
132
+ - tools/trans_bpmn2-to-ptml
133
+ - tools/trans_cpee-to-bpmn2
134
+ - tools/trans_cpee-to-cpee
135
+ - tools/trans_cpee-to-dataflow
136
+ - tools/trans_cpee-to-graphviz
137
+ - tools/trans_cpee-to-mermaid
138
+ - tools/trans_cpee-to-ptml
139
+ - tools/trans_cpee-to-text-bf
140
+ - tools/trans_cpee-to-text-df-poe
141
+ - tools/trans_cpee-to-text-df-por
142
+ - tools/trans_mermaid-to-cpee
143
+ - tools/trans_ptml-to-cpee
143
144
  homepage: http://github.com/etm/cpee-transformation/
144
145
  licenses:
145
146
  - LGPL-3.0-or-later
data/server/trans.pid DELETED
@@ -1 +0,0 @@
1
- 1235950
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes