Sha256: 66d978779934ab491797d5c026fd83c90dc2cb6b174ea05ce41ae487f3c31cb2

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

# encoding: ascii-8bit

# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos/tools/tlm_viewer/widgets/widget'

module Cosmos
  # Display a circle on the canvas of specified color and width
  class CanvasdotWidget
    include Widget

    def initialize(parent_layout, x, y, color = 'black', width = 3)
      super()
      if is_numeric?(x)
        @x = x.to_i
      else
        @x = x.to_s
      end

      if is_numeric?(y)
        @y = y.to_i
      else
        @y = y.to_s
      end

      @point = Qt::Point.new(0, 0)
      @width = width.to_i
      @color = Cosmos::getColor(color)
      parent_layout.add_repaint(self)
    end

    def update_point
      if is_numeric?(@x)
        @point.x = @x
      else
        @point.x = eval_str(@x)
      end

      if is_numeric?(@y)
        @point.y = @y
      else
        @point.y = eval_str(@y)
      end
    end

    def is_numeric?(obj)
      obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
    end

    def paint(painter)
      painter.save
      painter.setBrush(@color)
      painter.drawEllipse(@point, @width, @width)
      painter.restore
    end

    def eval_str(string_to_eval)
      # Fortify: Dynamic Code Evaluation: Code Injection
      # TODO: Not sure how to sanitize this string
      @screen.instance_eval(string_to_eval)
    end

    def update_widget
      update_point
    end

    def dispose
      super()
      @point.dispose
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cosmos-4.5.2-java lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb
cosmos-4.5.2 lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb
cosmos-4.5.1-java lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb
cosmos-4.5.1 lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb