wxruby3-shapes 0.9.0.pre.beta.3 → 0.9.6

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +5 -7
  3. data/README.md +38 -6
  4. data/assets/logo.svg +339 -0
  5. data/assets/logo.xpm +60 -0
  6. data/assets/screenshot.png +0 -0
  7. data/assets/social.png +0 -0
  8. data/bin/wx-shapes +1 -1
  9. data/lib/wx/shapes/arrow_base.rb +4 -11
  10. data/lib/wx/shapes/arrows/circle_arrow.rb +22 -11
  11. data/lib/wx/shapes/arrows/circle_prong_arrow.rb +48 -0
  12. data/lib/wx/shapes/arrows/cross_bar_arrow.rb +57 -0
  13. data/lib/wx/shapes/arrows/cross_bar_circle_arrow.rb +56 -0
  14. data/lib/wx/shapes/arrows/cross_bar_prong_arrow.rb +49 -0
  15. data/lib/wx/shapes/arrows/crossed_circle.rb +46 -0
  16. data/lib/wx/shapes/arrows/cup_arrow.rb +65 -0
  17. data/lib/wx/shapes/arrows/diamond_arrow.rb +8 -13
  18. data/lib/wx/shapes/arrows/double_cross_bar_arrow.rb +27 -0
  19. data/lib/wx/shapes/arrows/filled_arrow.rb +60 -0
  20. data/lib/wx/shapes/arrows/line_arrow.rb +67 -0
  21. data/lib/wx/shapes/arrows/open_arrow.rb +22 -23
  22. data/lib/wx/shapes/arrows/prong_arrow.rb +42 -0
  23. data/lib/wx/shapes/arrows/solid_arrow.rb +21 -35
  24. data/lib/wx/shapes/arrows/square_arrow.rb +37 -0
  25. data/lib/wx/shapes/auto_layout.rb +2 -2
  26. data/lib/wx/shapes/base.rb +1 -1
  27. data/lib/wx/shapes/canvas_history.rb +20 -0
  28. data/lib/wx/shapes/connection_point.rb +10 -6
  29. data/lib/wx/shapes/diagram.rb +98 -78
  30. data/lib/wx/shapes/events.rb +8 -8
  31. data/lib/wx/shapes/printout.rb +3 -16
  32. data/lib/wx/shapes/serializable.rb +2 -436
  33. data/lib/wx/shapes/serialize/wx.rb +30 -18
  34. data/lib/wx/shapes/shape.rb +211 -168
  35. data/lib/wx/shapes/shape_canvas.rb +728 -267
  36. data/lib/wx/shapes/shape_data_object.rb +99 -18
  37. data/lib/wx/shapes/shape_handle.rb +18 -11
  38. data/lib/wx/shapes/shape_list.rb +34 -67
  39. data/lib/wx/shapes/shapes/bitmap_shape.rb +23 -24
  40. data/lib/wx/shapes/shapes/box_shape.rb +389 -0
  41. data/lib/wx/shapes/shapes/circle_shape.rb +19 -22
  42. data/lib/wx/shapes/shapes/control_shape.rb +77 -41
  43. data/lib/wx/shapes/shapes/curve_shape.rb +38 -31
  44. data/lib/wx/shapes/shapes/diamond_shape.rb +7 -17
  45. data/lib/wx/shapes/shapes/edit_text_shape.rb +6 -9
  46. data/lib/wx/shapes/shapes/ellipse_shape.rb +12 -15
  47. data/lib/wx/shapes/shapes/flex_grid_shape.rb +58 -33
  48. data/lib/wx/shapes/shapes/grid_shape.rb +259 -161
  49. data/lib/wx/shapes/shapes/line_shape.rb +155 -161
  50. data/lib/wx/shapes/shapes/manager_shape.rb +77 -0
  51. data/lib/wx/shapes/shapes/multi_sel_rect.rb +8 -8
  52. data/lib/wx/shapes/shapes/ortho_shape.rb +31 -36
  53. data/lib/wx/shapes/shapes/polygon_shape.rb +23 -29
  54. data/lib/wx/shapes/shapes/rect_shape.rb +95 -53
  55. data/lib/wx/shapes/shapes/round_ortho_shape.rb +6 -8
  56. data/lib/wx/shapes/shapes/round_rect_shape.rb +20 -24
  57. data/lib/wx/shapes/shapes/square_shape.rb +14 -17
  58. data/lib/wx/shapes/shapes/text_shape.rb +95 -53
  59. data/lib/wx/shapes/version.rb +1 -1
  60. data/lib/wx/shapes/wx.rb +16 -7
  61. data/lib/wx/wx-shapes/cmd/test.rb +1 -1
  62. data/samples/demo/arrows.json +1 -0
  63. data/samples/demo/arrows.yaml +793 -0
  64. data/samples/demo/art/HBox.xpm +22 -0
  65. data/samples/demo/art/VBox.xpm +22 -0
  66. data/samples/demo/art/logo.xpm +60 -0
  67. data/samples/demo/class.json +1 -0
  68. data/samples/demo/class.yaml +5631 -0
  69. data/samples/demo/demo.rb +301 -91
  70. data/samples/demo/dialogs.rb +1405 -0
  71. data/samples/demo/erd.json +1 -0
  72. data/samples/demo/erd.yaml +4072 -0
  73. data/samples/demo/frame_canvas.rb +409 -33
  74. data/samples/sample1/art/logo.xpm +60 -0
  75. data/samples/sample1/sample.rb +11 -11
  76. data/samples/sample2/art/logo.xpm +60 -0
  77. data/samples/sample2/sample.rb +2 -2
  78. data/samples/sample2/sample_shape.rb +15 -15
  79. data/samples/sample3/art/logo.xpm +60 -0
  80. data/samples/sample3/sample.rb +3 -3
  81. data/samples/sample4/art/logo.xpm +60 -0
  82. data/samples/sample4/sample.rb +2 -2
  83. data/tests/lib/wxapp_runner.rb +4 -0
  84. data/tests/serializer_tests.rb +8 -441
  85. data/tests/test_grid_shapes.rb +2 -2
  86. data/tests/test_serialize_xml.rb +17 -0
  87. data/tests/test_serialize_yaml.rb +2 -2
  88. metadata +78 -28
  89. data/lib/wx/shapes/serialize/core.rb +0 -40
  90. data/lib/wx/shapes/serialize/id.rb +0 -82
  91. data/lib/wx/shapes/serializer/json.rb +0 -258
  92. data/lib/wx/shapes/serializer/yaml.rb +0 -125
  93. data/samples/demo/art/sample.xpm +0 -251
  94. data/samples/sample1/art/sample.xpm +0 -251
  95. data/samples/sample2/art/sample.xpm +0 -251
  96. data/samples/sample3/art/sample.xpm +0 -251
  97. data/samples/sample4/art/sample.xpm +0 -251
@@ -9,11 +9,10 @@ module Wx::SF
9
9
 
10
10
  # Default values
11
11
  module DEFAULT
12
- # Default value of undefined ID.
13
- UNKNOWNID = nil
14
- # Default value of LineShape @pen data member.
15
- PEN = Wx::Pen.new(Wx::BLACK) if Wx::App.is_main_loop_running
16
- Wx.add_delayed_constant(self, :PEN) { Wx::Pen.new(Wx::BLACK) }
12
+ class << self
13
+ # Default value of LineShape @pen data member.
14
+ def pen; @pen ||= Wx::BLACK_PEN.dup; end
15
+ end
17
16
  # Default value of LineShape @dock_point data member.
18
17
  DOCKPOINT = 0
19
18
  # Default value of LineShape @dock_point data member (start line point).
@@ -21,7 +20,7 @@ module Wx::SF
21
20
  # Default value of LineShape @dock_point data member (end line point).
22
21
  DOCKPOINT_END = -2
23
22
  # Default value of LineShape @dock_point data member (middle dock point).
24
- DOCKPOINT_CENTER = 2**64
23
+ DOCKPOINT_CENTER = (2**64).to_i
25
24
  # Default value of LineShape @src_offset and LineShape @trg_offset data members.
26
25
  OFFSET = Wx::RealPoint.new(-1, -1)
27
26
  # Default value of LineShape @src_point and LineShape @trg_point data members.
@@ -38,58 +37,50 @@ module Wx::SF
38
37
  TRGCHANGE = self.new(3)
39
38
  end
40
39
 
41
- property :src_shape_id, :trg_shape_id
42
- property src_point: :serialize_src_point, trg_point: :serialize_trg_point
40
+ property :src_shape, :trg_shape, optional: true
41
+ property({ src_point: :serialize_src_point, trg_point: :serialize_trg_point },
42
+ optional: ->(obj, _id) { obj.src_shape.nil? && obj.trg_shape.nil? ? nil : DEFAULT::POINT})
43
43
  property :stand_alone, :src_arrow, :trg_arrow, :src_offset, :trg_offset,
44
- :dock_point, :line_pen, :control_points
45
-
46
- # @overload initialize()
47
- # default constructor
48
- # @overload initialize(src, trg, path, manager)
49
- # @param [Wx::SF::Serializable::ID] src ID of the source shape
50
- # @param [Wx::SF::Serializable::ID] trg ID of the target shape
51
- # @param [Array<Wx::RealPoint>] path List of the line control points (can be empty)
44
+ :dock_point, :control_points
45
+ property({ line_pen: :serialize_line_pen }, optional: true)
46
+
47
+ # @overload initialize(src = nil, trg = nil, path: nil, manager: nil)
48
+ # Constructor for connecting two shapes.
49
+ # @param [Shape] src source shape
50
+ # @param [Shape] trg target shape
51
+ # @param [Array<Wx::RealPoint>,nil] path List of the line control points (can be empty or nil)
52
52
  # @param [Diagram] diagram containing diagram
53
- # @overload initialize(src, trg, path, manager)
54
- # @param [Wx::RealPoint] src starting line point
55
- # @param [Wx::RealPoint] trg end line point
53
+ # @overload initialize(src, trg, path: nil, manager: nil)
54
+ # Constructor for standalone line.
55
+ # @param [Wx::RealPoint,Wx::Point] src starting line point
56
+ # @param [Wx::RealPoint,Wx::Point] trg end line point
56
57
  # @param [Array<Wx::RealPoint>,nil] path List of the line control points (can be empty or nil)
57
58
  # @param [Diagram] diagram containing diagram
58
- def initialize(*args)
59
- if args.empty?
60
- super()
61
- @src_shape_id = @trg_shape_id = DEFAULT::UNKNOWNID
59
+ def initialize(src = nil, trg = nil, path: nil, diagram: nil)
60
+ super(diagram: diagram)
61
+ if src.respond_to?(:to_real_point) && trg.respond_to?(:to_real_point)
62
+ @src_point = Wx::Point === src ? src.to_real_point : src.dup
63
+ @trg_point = Wx::Point === trg ? trg.to_real_point : trg.dup
64
+ @src_shape = @trg_shape = nil
65
+ @stand_alone = true
66
+ elsif (src.nil? && trg.nil?) || (src.is_a?(Shape) && trg.is_a?(Shape))
62
67
  @src_point = DEFAULT::POINT.dup
63
68
  @trg_point = DEFAULT::POINT.dup
64
- @stand_alone = DEFAULT::STANDALONE
65
- @lst_points = []
69
+ @src_shape = src
70
+ @trg_shape = trg
71
+ @stand_alone = false
66
72
  else
67
- src, trg, path, diagram = args
68
- super(Shape::DEFAULT::POSITION.dup, diagram)
69
- if src.respond_to?(:to_real_point) && trg.respond_to?(:to_real_point)
70
- @src_point = src.to_real_point
71
- @trg_point = trg.to_real_point
72
- @src_shape_id = @trg_shape_id = DEFAULT::UNKNOWNID
73
- @stand_alone = true
74
- elsif src.is_a?(Wx::SF::Serializable::ID) && trg.is_a?(Wx::SF::Serializable::ID)
75
- @src_point = DEFAULT::POINT.dup
76
- @trg_point = DEFAULT::POINT.dup
77
- @src_shape_id = src
78
- @trg_shape_id = trg
79
- @stand_alone = false
80
- else
81
- ::Kernel.raise ArgumentError, "Invalid arguments #{args}"
82
- end
83
- path ||= []
84
- @lst_points = path.select { |pt| pt.respond_to?(:to_real_point) }.collect { |pt| pt.to_real_point }
85
- ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless path.size == @lst_points.size
73
+ ::Kernel.raise ArgumentError, "Invalid arguments #{args}"
86
74
  end
75
+ path ||= []
76
+ @lst_points = path.select { |pt| pt.respond_to?(:to_real_point) }.collect { |pt| pt.to_real_point }
77
+ ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless path.size == @lst_points.size
87
78
 
88
79
  @src_arrow = nil
89
80
  @trg_arrow = nil
90
81
 
91
82
  @dock_point = DEFAULT::DOCKPOINT
92
- @pen = DEFAULT::PEN
83
+ @pen = nil
93
84
 
94
85
  @src_offset = DEFAULT::OFFSET.dup
95
86
  @trg_offset = DEFAULT::OFFSET.dup
@@ -99,43 +90,41 @@ module Wx::SF
99
90
  @unfinished_point = Wx::Point.new
100
91
  end
101
92
 
102
- # Get source shape id.
103
- # @return [Wx::SF::Serializable::ID]
104
- def get_src_shape_id
105
- @src_shape_id
93
+ # Get source shape
94
+ # @return [Shape, nil]
95
+ def get_src_shape
96
+ @src_shape
106
97
  end
107
- alias :src_shape_id :get_src_shape_id
98
+ alias :src_shape :get_src_shape
108
99
 
109
- # Set source shape id.
110
- # @param [Wx::SF::Serializable::ID] id
111
- def set_src_shape_id(id)
112
- @src_shape_id = id
100
+ # Set source shape.
101
+ # @param [Shape, nil] shape
102
+ def set_src_shape(shape)
103
+ @src_shape = shape
113
104
  end
114
- alias :src_shape_id= :set_src_shape_id
105
+ alias :src_shape= :set_src_shape
115
106
 
116
- # Get target shape id.
117
- # @return [Wx::SF::Serializable::ID]
118
- def get_trg_shape_id
119
- @trg_shape_id
107
+ # Get target shape.
108
+ # @return [Shape, nil]
109
+ def get_trg_shape
110
+ @trg_shape
120
111
  end
121
- alias :trg_shape_id :get_trg_shape_id
112
+ alias :trg_shape :get_trg_shape
122
113
 
123
- # Set target shape id.
124
- # @param [Wx::SF::Serializable::ID] id
125
- def set_trg_shape_id(id)
126
- @trg_shape_id = id
114
+ # Set target shape.
115
+ # @param [Shape, nil] shape
116
+ def set_trg_shape(shape)
117
+ @trg_shape = shape
127
118
  end
128
- alias :trg_shape_id= :set_trg_shape_id
119
+ alias :trg_shape= :set_trg_shape
129
120
 
130
121
  # Get source point.
131
122
  # @return [Wx::RealPoint]
132
123
  def get_src_point
133
124
  unless @stand_alone
134
- src_shape = @diagram.find_shape(@src_shape_id)
135
-
136
- if src_shape && !@lst_points.empty?
137
- if src_shape.get_connection_points.empty?
138
- return src_shape.get_border_point(get_mod_src_point, @lst_points.first)
125
+ if @src_shape && !@lst_points.empty?
126
+ if @src_shape.get_connection_points.empty?
127
+ return @src_shape.get_border_point(get_mod_src_point, @lst_points.first)
139
128
  else
140
129
  return get_mod_src_point
141
130
  end
@@ -147,8 +136,6 @@ module Wx::SF
147
136
  end
148
137
  return pt1
149
138
  end
150
-
151
- return Wx::RealPoint.new
152
139
  end
153
140
  @src_point
154
141
  end
@@ -164,11 +151,9 @@ module Wx::SF
164
151
  # @return [Wx::RealPoint]
165
152
  def get_trg_point
166
153
  unless @stand_alone
167
- trg_shape = @diagram.find_shape(@trg_shape_id)
168
-
169
- if trg_shape && !@lst_points.empty?
170
- if trg_shape.get_connection_points.empty?
171
- return trg_shape.get_border_point(get_mod_trg_point, @lst_points.last)
154
+ if @trg_shape && !@lst_points.empty?
155
+ if @trg_shape.get_connection_points.empty?
156
+ return @trg_shape.get_border_point(get_mod_trg_point, @lst_points.last)
172
157
  else
173
158
  return get_mod_trg_point
174
159
  end
@@ -180,8 +165,6 @@ module Wx::SF
180
165
  end
181
166
  return pt2
182
167
  end
183
-
184
- return Wx::RealPoint.new
185
168
  end
186
169
  @trg_point
187
170
  end
@@ -194,7 +177,7 @@ module Wx::SF
194
177
  end
195
178
 
196
179
  # Get source arrow.
197
- # @return [Wx::SF::ArrowBase]
180
+ # @return [Wx::SF::ArrowBase, nil]
198
181
  def get_src_arrow
199
182
  @src_arrow
200
183
  end
@@ -202,22 +185,23 @@ module Wx::SF
202
185
 
203
186
  # Set source arrow
204
187
  # @overload set_src_arrow(arrow)
205
- # @param [Wx::SF::ArrowBase] arrow
206
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
188
+ # @param [Wx::SF::ArrowBase, nil] arrow
189
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
207
190
  # @overload set_src_arrow(arrow_klass)
208
191
  # @param [Class] arrow_klass
209
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
192
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
210
193
  def set_src_arrow(arg)
211
- if (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
212
- @src_arrow = arg.is_a?(ArrowBase) ? arg : arg.new
213
- @src_arrow.set_parent_shape(self)
194
+ if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
195
+ @src_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new
196
+ @src_arrow.set_parent_shape(self) if @src_arrow
197
+ return @src_arrow
214
198
  end
215
199
  nil
216
200
  end
217
201
  alias :src_arrow= :set_src_arrow
218
202
 
219
203
  # Get target arrow.
220
- # @return [Wx::SF::ArrowBase]
204
+ # @return [Wx::SF::ArrowBase, nil]
221
205
  def get_trg_arrow
222
206
  @trg_arrow
223
207
  end
@@ -225,15 +209,16 @@ module Wx::SF
225
209
 
226
210
  # Set target arrow
227
211
  # @overload set_trg_arrow(arrow)
228
- # @param [Wx::SF::ArrowBase] arrow
229
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
212
+ # @param [Wx::SF::ArrowBase, nil] arrow
213
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
230
214
  # @overload set_trg_arrow(arrow_klass)
231
215
  # @param [Class] arrow_klass
232
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
216
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
233
217
  def set_trg_arrow(arg)
234
- if (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
235
- @trg_arrow = arg.is_a?(ArrowBase) ? arg : arg.new
236
- @trg_arrow.set_parent_shape(self)
218
+ if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
219
+ @trg_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new
220
+ @trg_arrow.set_parent_shape(self) if @trg_arrow
221
+ return @trg_arrow
237
222
  end
238
223
  nil
239
224
  end
@@ -242,14 +227,23 @@ module Wx::SF
242
227
  # Get line type
243
228
  # @return [Wx::Pen]
244
229
  def get_line_pen
245
- @pen
230
+ @pen || (@diagram&.shape_canvas ? @diagram.shape_canvas.line_pen : DEFAULT.pen)
246
231
  end
247
232
  alias :line_pen :get_line_pen
248
233
 
249
234
  # Set line type
250
- # @param [Wx::Pen] pen line type
251
- def set_line_pen(pen)
252
- @pen = pen
235
+ # @overload set_line_pen(pen)
236
+ # @param [Wx::Pen] pen
237
+ # @overload set_line_pen(color, width=1, style=Wx::PenStyle::PENSTYLE_SOLID)
238
+ # @param [Wx::Colour,String,Symbol] color
239
+ # @param [Integer] width
240
+ # @param [Wx::PenStyle] style
241
+ def set_line_pen(*args)
242
+ @pen = if args.size == 1 && Wx::Pen === args.first
243
+ args.first
244
+ else
245
+ Wx::Pen.new(*args)
246
+ end
253
247
  end
254
248
  alias :line_pen= :set_line_pen
255
249
 
@@ -288,16 +282,13 @@ module Wx::SF
288
282
  if @stand_alone
289
283
  return [@src_point, @trg_point]
290
284
  else
291
- src_shape = get_diagram.find_shape(@src_shape_id)
292
- trg_shape = get_diagram.find_shape(@trg_shape_id)
293
-
294
- if src_shape && trg_shape
285
+ if @src_shape && @trg_shape
295
286
  trg_center = get_mod_trg_point
296
287
  src_center = get_mod_src_point
297
288
 
298
- if src_shape.get_parent_shape == trg_shape || trg_shape.get_parent_shape == src_shape
299
- trg_bb = trg_shape.get_bounding_box
300
- src_bb = src_shape.get_bounding_box
289
+ if @src_shape.get_parent_shape == @trg_shape || @trg_shape.get_parent_shape == @src_shape
290
+ trg_bb = @trg_shape.get_bounding_box
291
+ src_bb = @src_shape.get_bounding_box
301
292
 
302
293
  if trg_bb.contains?(src_center.x.to_i, src_center.y.to_i)
303
294
  if src_center.y > trg_center.y
@@ -320,21 +311,21 @@ module Wx::SF
320
311
  end
321
312
  end
322
313
 
323
- if src_shape.get_connection_points.empty?
324
- src = src_shape.get_border_point(src_center, trg_center)
314
+ if @src_shape.get_connection_points.empty?
315
+ src = @src_shape.get_border_point(src_center, trg_center)
325
316
  else
326
317
  src = src_center
327
318
  end
328
319
 
329
- if trg_shape.get_connection_points.empty?
330
- trg = trg_shape.get_border_point(trg_center, src_center)
320
+ if @trg_shape.get_connection_points.empty?
321
+ trg = @trg_shape.get_border_point(trg_center, src_center)
331
322
  else
332
323
  trg = trg_center
333
324
  end
334
325
  return [src, trg]
335
326
  end
336
327
  end
337
- nil # should not happen
328
+ raise SFException, 'Missing src and/or trg for line'
338
329
  end
339
330
 
340
331
  # Get a list of the line's control points (their positions).
@@ -367,7 +358,7 @@ module Wx::SF
367
358
  # Initialize line's starting point with existing fixed connection point.
368
359
  # @param [Wx::SF::ConnectionPoint] cp Pointer to connection point
369
360
  def set_starting_connection_point(cp)
370
- if cp && cp.get_parent_shape
361
+ if cp&.get_parent_shape
371
362
  pos_cp = cp.get_connection_point
372
363
  rct_bb = cp.get_parent_shape.get_bounding_box
373
364
 
@@ -379,7 +370,7 @@ module Wx::SF
379
370
  # Initialize line's ending point with existing fixed connection point.
380
371
  # @param [Wx::SF::ConnectionPoint] cp Pointer to connection point
381
372
  def set_ending_connection_point(cp)
382
- if cp && cp.get_parent_shape
373
+ if cp&.get_parent_shape
383
374
  pos_cp = cp.get_connection_point
384
375
  rct_bb = cp.get_parent_shape.get_bounding_box
385
376
 
@@ -404,11 +395,11 @@ module Wx::SF
404
395
  return get_direct_line if index == 0
405
396
  else
406
397
  if index == 0
407
- return [get_src_point, @lst_points.first.dup]
398
+ return [get_src_point, @lst_points.first]
408
399
  elsif index == @lst_points.size
409
- return [@lst_points.last.dup, get_trg_point]
400
+ return [@lst_points.last, get_trg_point]
410
401
  elsif index > 0 && index < @lst_points.size
411
- return @lst_points[index-1, 2].collect {|p| p.dup}
402
+ return @lst_points[index-1, 2].collect {|p| p}
412
403
  end
413
404
  end
414
405
  [Wx::RealPoint.new, Wx::RealPoint.new]
@@ -421,18 +412,19 @@ module Wx::SF
421
412
 
422
413
  # calculate control points area if they exist
423
414
  if !@lst_points.empty?
424
- prev_pt = get_src_point
415
+ prev_pt = get_src_point.to_point
425
416
 
426
417
  @lst_points.each do |pt|
418
+ pt = pt.to_point
427
419
  if line_rct.nil?
428
- line_rct = Wx::Rect.new(prev_pt.to_point, pt.to_point)
420
+ line_rct = Wx::Rect.new(prev_pt, pt)
429
421
  else
430
- line_rct.union!(Wx::Rect.new(prev_pt.to_point, pt.to_point))
422
+ line_rct.union!(Wx::Rect.new(prev_pt, pt))
431
423
  end
432
424
  prev_pt = pt
433
425
  end
434
426
 
435
- line_rct.union!(Wx::Rect.new(prev_pt.to_point, get_trg_point.to_point))
427
+ line_rct.union!(Wx::Rect.new(prev_pt, get_trg_point.to_point))
436
428
  else
437
429
  # include starting point
438
430
  pt = get_src_point
@@ -558,19 +550,22 @@ module Wx::SF
558
550
  def on_end_handle(handle)
559
551
  # update percentual offset of the line's ending points
560
552
  parent = get_parent_canvas.get_shape_under_cursor
561
-
553
+ # propagate request for interactive connection editing if requested
554
+ while parent && parent.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION)
555
+ parent = parent.get_parent_shape
556
+ end
557
+
562
558
  if parent && !@stand_alone
563
559
  bb_rect = parent.get_bounding_box
564
-
565
560
  case handle.type
566
561
  when Shape::Handle::TYPE::LINESTART
567
- if parent.id == @src_shape_id
562
+ if parent == @src_shape
568
563
  @src_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width
569
564
  @src_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height
570
565
  end
571
566
 
572
567
  when Shape::Handle::TYPE::LINEEND
573
- if parent.id == @trg_shape_id
568
+ if parent == @trg_shape
574
569
  @trg_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width
575
570
  @trg_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height
576
571
  end
@@ -587,7 +582,7 @@ module Wx::SF
587
582
  # @param [Wx::Point] pos Current mouse position
588
583
  # @see Wx::SF::ShapeCanvas
589
584
  def on_begin_drag(pos)
590
- @prev_position = get_absolute_position
585
+ @prev_position = get_absolute_position.dup
591
586
 
592
587
  super
593
588
  end
@@ -608,7 +603,7 @@ module Wx::SF
608
603
  if handle && handle.get_parent_shape == self
609
604
  if handle.type == Shape::Handle::TYPE::LINECTRL
610
605
  if has_style?(STYLE::EMIT_EVENTS)
611
- evt = Wx::SF::ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_REMOVE, id)
606
+ evt = Wx::SF::ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_REMOVE, self.object_id)
612
607
  evt.set_shape(self)
613
608
  evt.set_handle(handle)
614
609
  get_parent_canvas.get_event_handler.process_event(evt)
@@ -630,7 +625,7 @@ module Wx::SF
630
625
  if has_style?(STYLE::EMIT_EVENTS)
631
626
  handle = get_parent_canvas.get_topmost_handle_at_position(pos)
632
627
  if handle
633
- evt = ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_ADD, id)
628
+ evt = ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_ADD, self.object_id)
634
629
  evt.set_shape(this)
635
630
  evt.set_handle(handle)
636
631
  get_parent_canvas.get_event_handler.process_event(evt)
@@ -646,7 +641,7 @@ module Wx::SF
646
641
  # @param [Float] x Horizontal scale factor
647
642
  # @param [Float] y Vertical scale factor
648
643
  # @param [Boolean] children true if the shape's children should be scaled as well, otherwise the shape will be updated after scaling via update() function.
649
- def scale(x, y, children = WITHCHILDREN)
644
+ def scale(x, y, children: WITHCHILDREN)
650
645
  @lst_points.each do |pt|
651
646
  pt.x *= x
652
647
  pt.y *= y
@@ -668,16 +663,16 @@ module Wx::SF
668
663
  # Draw the shape in the normal way. The function can be overridden if necessary.
669
664
  # @param [Wx::DC] dc Reference to device context where the shape will be drawn to
670
665
  def draw_normal(dc)
671
- dc.with_pen(@pen) do
666
+ dc.with_pen(line_pen) do
672
667
  draw_complete_line(dc)
673
668
  end
674
669
  end
675
670
 
676
- # Draw the shape in the hower mode (the mouse cursor is above the shape).
671
+ # Draw the shape in the hover mode (the mouse cursor is above the shape).
677
672
  # The function can be overridden if necessary.
678
673
  # @param [Wx::DC] dc Reference to device context where the shape will be drawn to
679
674
  def draw_hover(dc)
680
- dc.with_pen(Wx::Pen.new(@hover_color, 1)) do
675
+ dc.with_pen(Wx::Pen.new(hover_colour, 1)) do
681
676
  draw_complete_line(dc)
682
677
  end
683
678
  end
@@ -687,7 +682,7 @@ module Wx::SF
687
682
  # The function can be overridden if necessary.
688
683
  # @param [Wx::DC] dc Reference to device context where the shape will be drawn to
689
684
  def draw_highlighted(dc)
690
- dc.with_pen(Wx::Pen.new(@hover_color, 2)) do
685
+ dc.with_pen(Wx::Pen.new(hover_colour, 2)) do
691
686
  draw_complete_line(dc)
692
687
  end
693
688
  end
@@ -699,23 +694,21 @@ module Wx::SF
699
694
 
700
695
  case @mode
701
696
  when LINEMODE::READY
702
- # draw basic line parts
703
- src = trg = nil
704
- line_segment_count.times do |i|
697
+ # draw line parts
698
+ n = line_segment_count-1
699
+ (0..n).each do |i|
705
700
  src, trg = get_line_segment(i)
701
+ # at starting (src) segment draw src arrow and get updated arrow connection point
702
+ src = @src_arrow.draw(trg, src, dc) if i == 0 && @src_arrow
703
+ # at end (tgt) segment draw tgt arrow and get updated connection point
704
+ trg = @trg_arrow.draw(src, trg, dc) if i == n && @trg_arrow
705
+ # draw line segment
706
706
  dc.draw_line(src.to_point, trg.to_point)
707
707
  end
708
- # draw target arrow
709
- @trg_arrow.draw(src, trg, dc) if @trg_arrow
710
- # draw source arrow
711
- if @src_arrow
712
- src, trg = get_line_segment(0)
713
- @src_arrow.draw(trg, src, dc)
714
- end
715
708
 
716
709
  when LINEMODE::UNDERCONSTRUCTION
717
710
  # draw basic line parts
718
- src = trg = nil
711
+ trg = nil
719
712
  @lst_points.size.times do |i|
720
713
  src, trg = get_line_segment(i)
721
714
  dc.draw_line(src.to_point, trg.to_point)
@@ -723,12 +716,11 @@ module Wx::SF
723
716
  # draw unfinished line segment if any (for interactive line creation)
724
717
  dc.with_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) do
725
718
  if @lst_points.size > 0
726
- dc.draw_line(trg, @unfinished_point)
719
+ dc.draw_line(trg.to_point, @unfinished_point)
727
720
  else
728
- src_shape = diagram.find_shape(@src_shape_id)
729
- if src_shape
730
- if src_shape.get_connection_points.empty?
731
- dc.draw_line((src_shape.get_border_point(src_shape.get_center, @unfinished_point.to_real)).to_point,
721
+ if @src_shape
722
+ if @src_shape.get_connection_points.empty?
723
+ dc.draw_line((@src_shape.get_border_point(@src_shape.get_center, @unfinished_point.to_real)).to_point,
732
724
  @unfinished_point)
733
725
  else
734
726
  dc.draw_line(get_mod_src_point.to_point, @unfinished_point)
@@ -739,14 +731,13 @@ module Wx::SF
739
731
 
740
732
  when LINEMODE::SRCCHANGE
741
733
  # draw basic line parts
742
- src = trg = nil
743
734
  @lst_points.size.times do |i|
744
735
  src, trg = get_line_segment(i+1)
745
736
  dc.draw_line(src.to_point, trg.to_point)
746
737
  end
747
738
 
748
739
  # draw linesegment being updated
749
- src, trg = get_line_segment(0)
740
+ _, trg = get_line_segment(0)
750
741
 
751
742
  dc.set_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) unless @stand_alone
752
743
  dc.draw_line(@unfinished_point, trg.to_point)
@@ -754,7 +745,7 @@ module Wx::SF
754
745
 
755
746
  when LINEMODE::TRGCHANGE
756
747
  # draw basic line parts
757
- src = trg = nil
748
+ trg = nil
758
749
  if @lst_points.empty?
759
750
  trg = get_src_point
760
751
  else
@@ -817,20 +808,19 @@ module Wx::SF
817
808
  # Get modified starting line point .
818
809
  # @return [Wx::RealPoint] Modified starting line point
819
810
  def get_mod_src_point
820
- src_shape = diagram.find_shape(@src_shape_id)
821
- return Wx::RealPoint.new unless src_shape
811
+ return Wx::RealPoint.new unless @src_shape
822
812
 
823
813
  if @src_offset != DEFAULT::OFFSET
824
- bb_rct = src_shape.get_bounding_box
825
- mod_point = src_shape.get_absolute_position
814
+ bb_rct = @src_shape.get_bounding_box
815
+ mod_point = @src_shape.get_absolute_position.dup
826
816
 
827
817
  mod_point.x += bb_rct.width.to_f * @src_offset.x
828
818
  mod_point.y += bb_rct.height.to_f * @src_offset.y
829
819
  else
830
- mod_point = src_shape.get_center
820
+ mod_point = @src_shape.get_center
831
821
  end
832
822
 
833
- conn_pt = src_shape.get_nearest_connection_point(mod_point)
823
+ conn_pt = @src_shape.get_nearest_connection_point(mod_point)
834
824
  mod_point = conn_pt.get_connection_point if conn_pt
835
825
 
836
826
  mod_point
@@ -839,20 +829,19 @@ module Wx::SF
839
829
  # Get modified ending line point .
840
830
  # @return [Wx::RealPoint] Modified ending line point
841
831
  def get_mod_trg_point
842
- trg_shape = diagram.find_shape(@trg_shape_id)
843
- return Wx::RealPoint.new unless trg_shape
832
+ return Wx::RealPoint.new unless @trg_shape
844
833
 
845
834
  if @trg_offset != DEFAULT::OFFSET
846
- bb_rct = trg_shape.get_bounding_box
847
- mod_point = trg_shape.get_absolute_position
835
+ bb_rct = @trg_shape.get_bounding_box
836
+ mod_point = @trg_shape.get_absolute_position.dup
848
837
 
849
838
  mod_point.x += bb_rct.width.to_f * @trg_offset.x
850
839
  mod_point.y += bb_rct.height.to_f * @trg_offset.y
851
840
  else
852
- mod_point = trg_shape.get_center
841
+ mod_point = @trg_shape.get_center
853
842
  end
854
843
 
855
- conn_pt = trg_shape.get_nearest_connection_point(mod_point)
844
+ conn_pt = @trg_shape.get_nearest_connection_point(mod_point)
856
845
  mod_point = conn_pt.get_connection_point if conn_pt
857
846
 
858
847
  mod_point
@@ -902,6 +891,11 @@ module Wx::SF
902
891
  @trg_point
903
892
  end
904
893
 
894
+ def serialize_line_pen(*val)
895
+ @pen = val.first unless val.empty?
896
+ @pen
897
+ end
898
+
905
899
  end
906
900
 
907
901
  end