lib/wx/shapes/shapes/line_shape.rb in wxruby3-shapes-0.9.0.pre.beta.3 vs lib/wx/shapes/shapes/line_shape.rb in wxruby3-shapes-0.9.5
- old
+ new
@@ -7,23 +7,22 @@
class LineShape < Shape
# Default values
module DEFAULT
- # Default value of undefined ID.
- UNKNOWNID = nil
- # Default value of LineShape @pen data member.
- PEN = Wx::Pen.new(Wx::BLACK) if Wx::App.is_main_loop_running
- Wx.add_delayed_constant(self, :PEN) { Wx::Pen.new(Wx::BLACK) }
+ class << self
+ # Default value of LineShape @pen data member.
+ def pen; @pen ||= Wx::BLACK_PEN.dup; end
+ end
# Default value of LineShape @dock_point data member.
DOCKPOINT = 0
# Default value of LineShape @dock_point data member (start line point).
DOCKPOINT_START = -1
# Default value of LineShape @dock_point data member (end line point).
DOCKPOINT_END = -2
# Default value of LineShape @dock_point data member (middle dock point).
- DOCKPOINT_CENTER = 2**64
+ DOCKPOINT_CENTER = (2**64).to_i
# Default value of LineShape @src_offset and LineShape @trg_offset data members.
OFFSET = Wx::RealPoint.new(-1, -1)
# Default value of LineShape @src_point and LineShape @trg_point data members.
POINT = Wx::RealPoint.new(0, 0)
# Default value of LineShape @stand_alone data member.
@@ -36,108 +35,98 @@
UNDERCONSTRUCTION = self.new(1)
SRCCHANGE = self.new(2)
TRGCHANGE = self.new(3)
end
- property :src_shape_id, :trg_shape_id
- property src_point: :serialize_src_point, trg_point: :serialize_trg_point
+ property :src_shape, :trg_shape, optional: true
+ property({ src_point: :serialize_src_point, trg_point: :serialize_trg_point },
+ optional: ->(obj, _id) { obj.src_shape.nil? && obj.trg_shape.nil? ? nil : DEFAULT::POINT})
property :stand_alone, :src_arrow, :trg_arrow, :src_offset, :trg_offset,
- :dock_point, :line_pen, :control_points
+ :dock_point, :control_points
+ property({ line_pen: :serialize_line_pen }, optional: true)
- # @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)
+ # @overload initialize(src = nil, trg = nil, path: nil, manager: nil)
+ # Constructor for connecting two shapes.
+ # @param [Shape] src source shape
+ # @param [Shape] trg target shape
+ # @param [Array<Wx::RealPoint>,nil] path List of the line control points (can be empty or nil)
# @param [Diagram] diagram containing diagram
- # @overload initialize(src, trg, path, manager)
- # @param [Wx::RealPoint] src starting line point
- # @param [Wx::RealPoint] trg end line point
+ # @overload initialize(src, trg, path: nil, manager: nil)
+ # Constructor for standalone line.
+ # @param [Wx::RealPoint,Wx::Point] src starting line point
+ # @param [Wx::RealPoint,Wx::Point] trg end line point
# @param [Array<Wx::RealPoint>,nil] path List of the line control points (can be empty or nil)
# @param [Diagram] diagram containing diagram
- def initialize(*args)
- if args.empty?
- super()
- @src_shape_id = @trg_shape_id = DEFAULT::UNKNOWNID
+ def initialize(src = nil, trg = nil, path: nil, diagram: nil)
+ super(diagram: diagram)
+ if src.respond_to?(:to_real_point) && trg.respond_to?(:to_real_point)
+ @src_point = Wx::Point === src ? src.to_real_point : src.dup
+ @trg_point = Wx::Point === trg ? trg.to_real_point : trg.dup
+ @src_shape = @trg_shape = nil
+ @stand_alone = true
+ elsif (src.nil? && trg.nil?) || (src.is_a?(Shape) && trg.is_a?(Shape))
@src_point = DEFAULT::POINT.dup
@trg_point = DEFAULT::POINT.dup
- @stand_alone = DEFAULT::STANDALONE
- @lst_points = []
+ @src_shape = src
+ @trg_shape = trg
+ @stand_alone = false
else
- src, trg, path, diagram = args
- super(Shape::DEFAULT::POSITION.dup, diagram)
- if src.respond_to?(:to_real_point) && trg.respond_to?(:to_real_point)
- @src_point = src.to_real_point
- @trg_point = trg.to_real_point
- @src_shape_id = @trg_shape_id = DEFAULT::UNKNOWNID
- @stand_alone = true
- elsif src.is_a?(Wx::SF::Serializable::ID) && trg.is_a?(Wx::SF::Serializable::ID)
- @src_point = DEFAULT::POINT.dup
- @trg_point = DEFAULT::POINT.dup
- @src_shape_id = src
- @trg_shape_id = trg
- @stand_alone = false
- else
- ::Kernel.raise ArgumentError, "Invalid arguments #{args}"
- end
- path ||= []
- @lst_points = path.select { |pt| pt.respond_to?(:to_real_point) }.collect { |pt| pt.to_real_point }
- ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless path.size == @lst_points.size
+ ::Kernel.raise ArgumentError, "Invalid arguments #{args}"
end
+ path ||= []
+ @lst_points = path.select { |pt| pt.respond_to?(:to_real_point) }.collect { |pt| pt.to_real_point }
+ ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless path.size == @lst_points.size
@src_arrow = nil
@trg_arrow = nil
@dock_point = DEFAULT::DOCKPOINT
- @pen = DEFAULT::PEN
+ @pen = nil
@src_offset = DEFAULT::OFFSET.dup
@trg_offset = DEFAULT::OFFSET.dup
@mode = LINEMODE::READY
@prev_position = Wx::RealPoint.new
@unfinished_point = Wx::Point.new
end
- # Get source shape id.
- # @return [Wx::SF::Serializable::ID]
- def get_src_shape_id
- @src_shape_id
+ # Get source shape
+ # @return [Shape, nil]
+ def get_src_shape
+ @src_shape
end
- alias :src_shape_id :get_src_shape_id
+ alias :src_shape :get_src_shape
- # Set source shape id.
- # @param [Wx::SF::Serializable::ID] id
- def set_src_shape_id(id)
- @src_shape_id = id
+ # Set source shape.
+ # @param [Shape, nil] shape
+ def set_src_shape(shape)
+ @src_shape = shape
end
- alias :src_shape_id= :set_src_shape_id
+ alias :src_shape= :set_src_shape
- # Get target shape id.
- # @return [Wx::SF::Serializable::ID]
- def get_trg_shape_id
- @trg_shape_id
+ # Get target shape.
+ # @return [Shape, nil]
+ def get_trg_shape
+ @trg_shape
end
- alias :trg_shape_id :get_trg_shape_id
+ alias :trg_shape :get_trg_shape
- # Set target shape id.
- # @param [Wx::SF::Serializable::ID] id
- def set_trg_shape_id(id)
- @trg_shape_id = id
+ # Set target shape.
+ # @param [Shape, nil] shape
+ def set_trg_shape(shape)
+ @trg_shape = shape
end
- alias :trg_shape_id= :set_trg_shape_id
+ alias :trg_shape= :set_trg_shape
# Get source point.
# @return [Wx::RealPoint]
def get_src_point
unless @stand_alone
- src_shape = @diagram.find_shape(@src_shape_id)
-
- if src_shape && !@lst_points.empty?
- if src_shape.get_connection_points.empty?
- return src_shape.get_border_point(get_mod_src_point, @lst_points.first)
+ if @src_shape && !@lst_points.empty?
+ if @src_shape.get_connection_points.empty?
+ return @src_shape.get_border_point(get_mod_src_point, @lst_points.first)
else
return get_mod_src_point
end
else
if @mode != LINEMODE::UNDERCONSTRUCTION
@@ -145,12 +134,10 @@
else
pt1 = get_mod_src_point
end
return pt1
end
-
- return Wx::RealPoint.new
end
@src_point
end
alias :src_point :get_src_point
@@ -162,15 +149,13 @@
# Get target point.
# @return [Wx::RealPoint]
def get_trg_point
unless @stand_alone
- trg_shape = @diagram.find_shape(@trg_shape_id)
-
- if trg_shape && !@lst_points.empty?
- if trg_shape.get_connection_points.empty?
- return trg_shape.get_border_point(get_mod_trg_point, @lst_points.last)
+ if @trg_shape && !@lst_points.empty?
+ if @trg_shape.get_connection_points.empty?
+ return @trg_shape.get_border_point(get_mod_trg_point, @lst_points.last)
else
return get_mod_trg_point
end
else
if @mode != LINEMODE::UNDERCONSTRUCTION
@@ -178,12 +163,10 @@
else
pt2 = @unfinished_point.to_real
end
return pt2
end
-
- return Wx::RealPoint.new
end
@trg_point
end
alias :trg_point :get_trg_point
@@ -192,66 +175,77 @@
def set_trg_point(pt)
@trg_point = pt.to_real_point
end
# Get source arrow.
- # @return [Wx::SF::ArrowBase]
+ # @return [Wx::SF::ArrowBase, nil]
def get_src_arrow
@src_arrow
end
alias :src_arrow :get_src_arrow
# Set source arrow
# @overload set_src_arrow(arrow)
- # @param [Wx::SF::ArrowBase] arrow
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
+ # @param [Wx::SF::ArrowBase, nil] arrow
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
# @overload set_src_arrow(arrow_klass)
# @param [Class] arrow_klass
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
def set_src_arrow(arg)
- if (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
- @src_arrow = arg.is_a?(ArrowBase) ? arg : arg.new
- @src_arrow.set_parent_shape(self)
+ if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
+ @src_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new
+ @src_arrow.set_parent_shape(self) if @src_arrow
+ return @src_arrow
end
nil
end
alias :src_arrow= :set_src_arrow
# Get target arrow.
- # @return [Wx::SF::ArrowBase]
+ # @return [Wx::SF::ArrowBase, nil]
def get_trg_arrow
@trg_arrow
end
alias :trg_arrow :get_trg_arrow
# Set target arrow
# @overload set_trg_arrow(arrow)
- # @param [Wx::SF::ArrowBase] arrow
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
+ # @param [Wx::SF::ArrowBase, nil] arrow
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
# @overload set_trg_arrow(arrow_klass)
# @param [Class] arrow_klass
- # @return [Wx::SF::ArrowBase,nil] the new source arrow object if invalid
+ # @return [Wx::SF::ArrowBase,nil] the new source arrow object if valid
def set_trg_arrow(arg)
- if (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
- @trg_arrow = arg.is_a?(ArrowBase) ? arg : arg.new
- @trg_arrow.set_parent_shape(self)
+ if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase)
+ @trg_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new
+ @trg_arrow.set_parent_shape(self) if @trg_arrow
+ return @trg_arrow
end
nil
end
alias :trg_arrow= :set_trg_arrow
# Get line type
# @return [Wx::Pen]
def get_line_pen
- @pen
+ @pen || (@diagram&.shape_canvas ? @diagram.shape_canvas.line_pen : DEFAULT.pen)
end
alias :line_pen :get_line_pen
# Set line type
- # @param [Wx::Pen] pen line type
- def set_line_pen(pen)
- @pen = pen
+ # @overload set_line_pen(pen)
+ # @param [Wx::Pen] pen
+ # @overload set_line_pen(color, width=1, style=Wx::PenStyle::PENSTYLE_SOLID)
+ # @param [Wx::Colour,String,Symbol] color
+ # @param [Integer] width
+ # @param [Wx::PenStyle] style
+ def set_line_pen(*args)
+ @pen = if args.size == 1 && Wx::Pen === args.first
+ args.first
+ else
+ Wx::Pen.new(*args)
+ end
end
alias :line_pen= :set_line_pen
# Set the line dock point. It is a zero based index of the line
# control point which will act as the shape position (value returned by Shape#get_relative_position function).
@@ -286,20 +280,17 @@
# @return [Array(Wx::RealPoint, Wx::RealPoint)] starting line point and ending line point
def get_direct_line
if @stand_alone
return [@src_point, @trg_point]
else
- src_shape = get_diagram.find_shape(@src_shape_id)
- trg_shape = get_diagram.find_shape(@trg_shape_id)
-
- if src_shape && trg_shape
+ if @src_shape && @trg_shape
trg_center = get_mod_trg_point
src_center = get_mod_src_point
- if src_shape.get_parent_shape == trg_shape || trg_shape.get_parent_shape == src_shape
- trg_bb = trg_shape.get_bounding_box
- src_bb = src_shape.get_bounding_box
+ if @src_shape.get_parent_shape == @trg_shape || @trg_shape.get_parent_shape == @src_shape
+ trg_bb = @trg_shape.get_bounding_box
+ src_bb = @src_shape.get_bounding_box
if trg_bb.contains?(src_center.x.to_i, src_center.y.to_i)
if src_center.y > trg_center.y
src = Wx::RealPoint.new(src_center.x, src_bb.bottom.to_f)
trg = Wx::RealPoint.new(src_center.x, trg_bb.bottom.to_f)
@@ -318,25 +309,25 @@
end
return [src, trg]
end
end
- if src_shape.get_connection_points.empty?
- src = src_shape.get_border_point(src_center, trg_center)
+ if @src_shape.get_connection_points.empty?
+ src = @src_shape.get_border_point(src_center, trg_center)
else
src = src_center
end
- if trg_shape.get_connection_points.empty?
- trg = trg_shape.get_border_point(trg_center, src_center)
+ if @trg_shape.get_connection_points.empty?
+ trg = @trg_shape.get_border_point(trg_center, src_center)
else
trg = trg_center
end
return [src, trg]
end
end
- nil # should not happen
+ raise SFException, 'Missing src and/or trg for line'
end
# Get a list of the line's control points (their positions).
# @return [Array<Wx::RealPoint>] List of control points' positions
def get_control_points
@@ -365,11 +356,11 @@
end
# Initialize line's starting point with existing fixed connection point.
# @param [Wx::SF::ConnectionPoint] cp Pointer to connection point
def set_starting_connection_point(cp)
- if cp && cp.get_parent_shape
+ if cp&.get_parent_shape
pos_cp = cp.get_connection_point
rct_bb = cp.get_parent_shape.get_bounding_box
@src_offset.x = (pos_cp.x - rct_bb.left).to_f / rct_bb.width
@src_offset.y = (pos_cp.y - rct_bb.top).to_f / rct_bb.height
@@ -377,11 +368,11 @@
end
# Initialize line's ending point with existing fixed connection point.
# @param [Wx::SF::ConnectionPoint] cp Pointer to connection point
def set_ending_connection_point(cp)
- if cp && cp.get_parent_shape
+ if cp&.get_parent_shape
pos_cp = cp.get_connection_point
rct_bb = cp.get_parent_shape.get_bounding_box
@trg_offset.x = (pos_cp.x - rct_bb.left).to_f / rct_bb.width
@trg_offset.y = (pos_cp.y - rct_bb.top).to_f / rct_bb.height
@@ -402,15 +393,15 @@
def get_line_segment(index)
if @lst_points.empty?
return get_direct_line if index == 0
else
if index == 0
- return [get_src_point, @lst_points.first.dup]
+ return [get_src_point, @lst_points.first]
elsif index == @lst_points.size
- return [@lst_points.last.dup, get_trg_point]
+ return [@lst_points.last, get_trg_point]
elsif index > 0 && index < @lst_points.size
- return @lst_points[index-1, 2].collect {|p| p.dup}
+ return @lst_points[index-1, 2].collect {|p| p}
end
end
[Wx::RealPoint.new, Wx::RealPoint.new]
end
@@ -419,22 +410,23 @@
def get_bounding_box
line_rct = nil
# calculate control points area if they exist
if !@lst_points.empty?
- prev_pt = get_src_point
+ prev_pt = get_src_point.to_point
@lst_points.each do |pt|
+ pt = pt.to_point
if line_rct.nil?
- line_rct = Wx::Rect.new(prev_pt.to_point, pt.to_point)
+ line_rct = Wx::Rect.new(prev_pt, pt)
else
- line_rct.union!(Wx::Rect.new(prev_pt.to_point, pt.to_point))
+ line_rct.union!(Wx::Rect.new(prev_pt, pt))
end
prev_pt = pt
end
- line_rct.union!(Wx::Rect.new(prev_pt.to_point, get_trg_point.to_point))
+ line_rct.union!(Wx::Rect.new(prev_pt, get_trg_point.to_point))
else
# include starting point
pt = get_src_point
line_rct = Wx::Rect.new(pt.x.to_i, pt.y.to_i, 1, 1)
@@ -556,23 +548,26 @@
# Default implementation does nothing.
# @param [Wx::SF::Shape::Handle] handle Reference to dragged handle
def on_end_handle(handle)
# update percentual offset of the line's ending points
parent = get_parent_canvas.get_shape_under_cursor
-
+ # propagate request for interactive connection editing if requested
+ while parent && parent.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION)
+ parent = parent.get_parent_shape
+ end
+
if parent && !@stand_alone
bb_rect = parent.get_bounding_box
-
case handle.type
when Shape::Handle::TYPE::LINESTART
- if parent.id == @src_shape_id
+ if parent == @src_shape
@src_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width
@src_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height
end
when Shape::Handle::TYPE::LINEEND
- if parent.id == @trg_shape_id
+ if parent == @trg_shape
@trg_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width
@trg_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height
end
end
end
@@ -585,11 +580,11 @@
#
# The function is called by the framework (by the shape canvas).
# @param [Wx::Point] pos Current mouse position
# @see Wx::SF::ShapeCanvas
def on_begin_drag(pos)
- @prev_position = get_absolute_position
+ @prev_position = get_absolute_position.dup
super
end
# Event handler called when the shape is double-clicked by
@@ -606,11 +601,11 @@
# given position
handle = get_parent_canvas.get_topmost_handle_at_position(pos)
if handle && handle.get_parent_shape == self
if handle.type == Shape::Handle::TYPE::LINECTRL
if has_style?(STYLE::EMIT_EVENTS)
- evt = Wx::SF::ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_REMOVE, id)
+ evt = Wx::SF::ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_REMOVE, self.object_id)
evt.set_shape(self)
evt.set_handle(handle)
get_parent_canvas.get_event_handler.process_event(evt)
end
@@ -628,11 +623,11 @@
show_handles(true)
if has_style?(STYLE::EMIT_EVENTS)
handle = get_parent_canvas.get_topmost_handle_at_position(pos)
if handle
- evt = ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_ADD, id)
+ evt = ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_ADD, self.object_id)
evt.set_shape(this)
evt.set_handle(handle)
get_parent_canvas.get_event_handler.process_event(evt)
end
end
@@ -644,11 +639,11 @@
# Scale the shape size by in both directions. The function can be overridden if necessary
# (new implementation should call default one or scale shape's children manually if necessary).
# @param [Float] x Horizontal scale factor
# @param [Float] y Vertical scale factor
# @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.
- def scale(x, y, children = WITHCHILDREN)
+ def scale(x, y, children: WITHCHILDREN)
@lst_points.each do |pt|
pt.x *= x
pt.y *= y
end
@@ -666,30 +661,30 @@
protected
# Draw the shape in the normal way. The function can be overridden if necessary.
# @param [Wx::DC] dc Reference to device context where the shape will be drawn to
def draw_normal(dc)
- dc.with_pen(@pen) do
+ dc.with_pen(line_pen) do
draw_complete_line(dc)
end
end
- # Draw the shape in the hower mode (the mouse cursor is above the shape).
+ # Draw the shape in the hover mode (the mouse cursor is above the shape).
# The function can be overridden if necessary.
# @param [Wx::DC] dc Reference to device context where the shape will be drawn to
def draw_hover(dc)
- dc.with_pen(Wx::Pen.new(@hover_color, 1)) do
+ dc.with_pen(Wx::Pen.new(hover_colour, 1)) do
draw_complete_line(dc)
end
end
# Draw the shape in the highlighted mode (another shape is dragged over this
# shape and this shape will accept the dragged one if it will be dropped on it).
# The function can be overridden if necessary.
# @param [Wx::DC] dc Reference to device context where the shape will be drawn to
def draw_highlighted(dc)
- dc.with_pen(Wx::Pen.new(@hover_color, 2)) do
+ dc.with_pen(Wx::Pen.new(hover_colour, 2)) do
draw_complete_line(dc)
end
end
# Draw completed line.
@@ -697,66 +692,62 @@
def draw_complete_line(dc)
return unless diagram
case @mode
when LINEMODE::READY
- # draw basic line parts
- src = trg = nil
- line_segment_count.times do |i|
+ # draw line parts
+ 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
+ src = @src_arrow.draw(trg, src, dc) if i == 0 && @src_arrow
+ # at end (tgt) segment draw tgt arrow and get updated connection point
+ trg = @trg_arrow.draw(src, trg, dc) if i == n && @trg_arrow
+ # draw line segment
dc.draw_line(src.to_point, trg.to_point)
end
- # draw target arrow
- @trg_arrow.draw(src, trg, dc) if @trg_arrow
- # draw source arrow
- if @src_arrow
- src, trg = get_line_segment(0)
- @src_arrow.draw(trg, src, dc)
- end
when LINEMODE::UNDERCONSTRUCTION
# draw basic line parts
- src = trg = nil
+ trg = nil
@lst_points.size.times do |i|
src, trg = get_line_segment(i)
dc.draw_line(src.to_point, trg.to_point)
end
# draw unfinished line segment if any (for interactive line creation)
dc.with_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) do
if @lst_points.size > 0
- dc.draw_line(trg, @unfinished_point)
+ dc.draw_line(trg.to_point, @unfinished_point)
else
- src_shape = diagram.find_shape(@src_shape_id)
- if src_shape
- if src_shape.get_connection_points.empty?
- dc.draw_line((src_shape.get_border_point(src_shape.get_center, @unfinished_point.to_real)).to_point,
+ if @src_shape
+ if @src_shape.get_connection_points.empty?
+ dc.draw_line((@src_shape.get_border_point(@src_shape.get_center, @unfinished_point.to_real)).to_point,
@unfinished_point)
else
dc.draw_line(get_mod_src_point.to_point, @unfinished_point)
end
end
end
end
when LINEMODE::SRCCHANGE
# draw basic line parts
- src = trg = nil
@lst_points.size.times do |i|
src, trg = get_line_segment(i+1)
dc.draw_line(src.to_point, trg.to_point)
end
# draw linesegment being updated
- src, trg = get_line_segment(0)
+ _, trg = get_line_segment(0)
dc.set_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) unless @stand_alone
dc.draw_line(@unfinished_point, trg.to_point)
dc.set_pen(Wx::NULL_PEN) unless @stand_alone
when LINEMODE::TRGCHANGE
# draw basic line parts
- src = trg = nil
+ trg = nil
if @lst_points.empty?
trg = get_src_point
else
@lst_points.size.times do |i|
src, trg = get_line_segment(i)
@@ -815,46 +806,44 @@
end
# Get modified starting line point .
# @return [Wx::RealPoint] Modified starting line point
def get_mod_src_point
- src_shape = diagram.find_shape(@src_shape_id)
- return Wx::RealPoint.new unless src_shape
+ return Wx::RealPoint.new unless @src_shape
if @src_offset != DEFAULT::OFFSET
- bb_rct = src_shape.get_bounding_box
- mod_point = src_shape.get_absolute_position
+ bb_rct = @src_shape.get_bounding_box
+ mod_point = @src_shape.get_absolute_position.dup
mod_point.x += bb_rct.width.to_f * @src_offset.x
mod_point.y += bb_rct.height.to_f * @src_offset.y
else
- mod_point = src_shape.get_center
+ mod_point = @src_shape.get_center
end
- conn_pt = src_shape.get_nearest_connection_point(mod_point)
+ conn_pt = @src_shape.get_nearest_connection_point(mod_point)
mod_point = conn_pt.get_connection_point if conn_pt
mod_point
end
# Get modified ending line point .
# @return [Wx::RealPoint] Modified ending line point
def get_mod_trg_point
- trg_shape = diagram.find_shape(@trg_shape_id)
- return Wx::RealPoint.new unless trg_shape
+ return Wx::RealPoint.new unless @trg_shape
if @trg_offset != DEFAULT::OFFSET
- bb_rct = trg_shape.get_bounding_box
- mod_point = trg_shape.get_absolute_position
+ bb_rct = @trg_shape.get_bounding_box
+ mod_point = @trg_shape.get_absolute_position.dup
mod_point.x += bb_rct.width.to_f * @trg_offset.x
mod_point.y += bb_rct.height.to_f * @trg_offset.y
else
- mod_point = trg_shape.get_center
+ mod_point = @trg_shape.get_center
end
- conn_pt = trg_shape.get_nearest_connection_point(mod_point)
+ conn_pt = @trg_shape.get_nearest_connection_point(mod_point)
mod_point = conn_pt.get_connection_point if conn_pt
mod_point
end
@@ -898,9 +887,14 @@
# (De-)Serialization only
def serialize_trg_point(*arg)
@trg_point = arg.shift unless arg.empty?
@trg_point
+ end
+
+ def serialize_line_pen(*val)
+ @pen = val.first unless val.empty?
+ @pen
end
end
end