lib/wx/shapes/shapes/ortho_shape.rb in wxruby3-shapes-0.9.0.pre.beta.3 vs lib/wx/shapes/shapes/ortho_shape.rb in wxruby3-shapes-0.9.5

- old
+ new

@@ -9,18 +9,16 @@ # user to create connection line orthogonal to base axis. class OrthoLineShape < LineShape SEGMENTCPS = ::Struct.new(:src, :trg) - # @overload initialize() - # default constructor - # @overload initialize(src, trg, path, manager) - # @param [Wx::SF::Serializable::ID] src ID of the source shape - # @param [Wx::SF::Serializable::ID] trg ID of the target shape - # @param [Array<Wx::RealPoint>] path List of the line control points (can be empty) - # @param [Diagram] diagram containing diagram - def initialize(*args) + # Constructor + # @param [Shape] src source shape + # @param [Shape] trg target shape + # @param [Array<Wx::RealPoint>] path List of the line control points (can be empty) + # @param [Diagram] diagram containing diagram + def initialize(src = nil, trg = nil, path: nil, diagram: nil) super end protected @@ -29,37 +27,37 @@ def draw_complete_line(dc) return unless @diagram src = trg = cp_src = cp_trg = nil - shape = @diagram.find_shape(@src_shape_id) - if shape - cp_src = shape.get_nearest_connection_point(get_mod_src_point) + if @src_shape + cp_src = @src_shape.get_nearest_connection_point(get_mod_src_point) end - shape = @diagram.find_shape(@trg_shape_id) - if shape - cp_trg = shape.get_nearest_connection_point(get_mod_trg_point) + if @trg_shape + cp_trg = @trg_shape.get_nearest_connection_point(get_mod_trg_point) end case @mode when LINEMODE::READY # draw basic line parts - line_segment_count.times do |i| + n = line_segment_count-1 + (0..n).each do |i| src, trg = get_line_segment(i) + # at starting (src) segment draw src arrow and get updated arrow connection point + if i == 0 && @src_arrow + asrc, atrg = get_first_subsegment(src, trg, get_used_connection_points(cp_src, cp_trg, 0)) + src = @src_arrow.draw(atrg, asrc, dc) + cp_src = nil + end + # at end (tgt) segment draw tgt arrow and get updated connection point + if i == n && @trg_arrow + asrc, atrg = get_last_subsegment(src, trg, get_used_connection_points(cp_src, cp_trg, @lst_points.size)) + trg = @trg_arrow.draw(asrc, atrg, dc) + cp_trg = nil + end draw_line_segment(dc, src, trg, get_used_connection_points(cp_src, cp_trg, i)) end - # draw target arrow - if @trg_arrow - asrc, atrg = get_last_subsegment(src, trg, get_used_connection_points(cp_src, cp_trg, @lst_points.size)) - @trg_arrow.draw(asrc, atrg, dc) - end - # draw source arrow - if @src_arrow - src, trg = get_line_segment(0) - asrc, atrg = get_first_subsegment(src, trg, get_used_connection_points(cp_src, cp_trg, 0)) - @src_arrow.draw(atrg, asrc, dc) - end when LINEMODE::UNDERCONSTRUCTION # draw basic line parts @lst_points.size.times do |i| src, trg = get_line_segment(i) @@ -69,15 +67,14 @@ # draw unfinished line segment if any (for interactive line creation) dc.with_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PenStyle::PENSTYLE_DOT)) do if @lst_points.size>1 draw_line_segment(dc, trg, @unfinished_point.to_real, get_used_connection_points(cp_src, cp_trg, @lst_points.size)) else - src_shape = @diagram.find_shape(@src_shape_id) - if src_shape - if src_shape.get_connection_points.empty? + if @src_shape + if @src_shape.get_connection_points.empty? draw_line_segment(dc, - src_shape.get_border_point(src_shape.get_center, @unfinished_point.to_real), + @src_shape.get_border_point(@src_shape.get_center, @unfinished_point.to_real), @unfinished_point.to_real, get_used_connection_points(cp_src, cp_trg, 0)) else draw_line_segment(dc, get_mod_src_point, @@ -131,16 +128,14 @@ return -1 unless get_bounding_box.inflate!(5, 5).contains?(pos) cp_src = nil cp_trg = nil - shape = @diagram.find_shape(@src_shape_id) - if shape - cp_src = shape.get_nearest_connection_point(get_mod_src_point) + if @src_shape + cp_src = @src_shape.get_nearest_connection_point(get_mod_src_point) end - shape = @diagram.find_shape(@trg_shape_id) - if shape - cp_trg = shape.get_nearest_connection_point(get_mod_trg_point) + if @trg_shape + cp_trg = @trg_shape.get_nearest_connection_point(get_mod_trg_point) end # Get all polyline segments line_segment_count.times do |i| pt_src, pt_trg = get_line_segment(i)