Class: Wire_helper

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/class/Wire_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(chip, api) ⇒ Wire_helper

Returns a new instance of Wire_helper.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/class/Wire_helper.rb', line 14

def initialize(chip, api)
  super()
  @wire_helper_gui = Ui_Wire_helper.new
  centerWindow(self)
  @wire_helper_gui.setupUi(self)
  @chip = chip
  @api = api

  # Default led position
  api.setWiringLeds(0x0000000000000000)

  # Draw the chip
  scene = Qt::GraphicsScene.new
  @wire_helper_gui.lbl_chip.setText("Your chip (#{chip.chip_reference}):")

  # Get the pin total number
  # UniqPin parameters: (scene, pinNum, pinChip, xSig, ySig, xNum, yNum, xRect, yRect, wRect, hRect, rotation)
  total_pin_nbr = Pin.where(pin_chip: @chip.chip_id).count
  # If it's a square
  if Package.find_by(package_id: chip.chip_package).package_shape == 0
    pin_by_side = total_pin_nbr / 4
    cHeight = 14*(pin_by_side + 4)  # Chip's height (+4 because we add a space equal to one pin for each corner)
    scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
    y = 32
    y2 = cHeight - 38
    x = 32
    x2 = cHeight - 38
    (1..total_pin_nbr).each do |i|
      # Face 1
      if i <= pin_by_side
        ySig = y
        yNum = y
        UniqPin.new(scene, i, @chip.chip_id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false, api)
        y = y + 14 # Space between each pin
      elsif i > pin_by_side && i <= total_pin_nbr / 2
      # Face 2
        xSig2 = x
        xNum2 = x
        UniqPin.new(scene, i, @chip.chip_id, xSig2 - 12, cHeight + 55, xNum2 - 12, cHeight, x, cHeight, 6, 20, true, api)
        x = x + 14
      elsif i > total_pin_nbr / 2 && i <= (total_pin_nbr - (pin_by_side))
      # Face 3
        xSig = cHeight + 24
        ySig = y2
        yNum = y2

        if i < 10
          xNum = cHeight - 20
        elsif i >= 10 && i < 100
          xNum = cHeight - 25
        else
          xNum = cHeight - 35
        end
        UniqPin.new(scene, i, @chip.chip_id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false, api)
        y2 = y2 - 14
      else
      # Face 4
        xSig2 = x2
        xNum2 = x2

        if i < 10
          yNum2 = 20
        elsif i >= 10 && i < 100
          yNum2 = 30
        else
          yNum2 = 40
        end
        UniqPin.new(scene, i, @chip.chip_id, xSig2 - 12, -20, xNum2 - 12, yNum2, x2, 0, 6, -20, true, api)
        x2 = x2 - 14
      end
    end
  # If it's a rectangle
  else
    pin_by_side = total_pin_nbr / 2
    cHeight = 14 * (pin_by_side + 2) # +2 because we add a space equal to one pin for each corner
    scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
    # Add the pins + text
    y = 18
    y2 = cHeight - 24
    (1..total_pin_nbr).each do |i|
      # Face 1
      if i <= total_pin_nbr / 2
        ySig = y
        yNum = y
        UniqPin.new(scene, i, @chip.chip_id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false, api)
        y = y + 14
      # Face 2
      else
        xSig = cHeight + 24
        ySig = y2
        yNum = y2

        if i < 10
          xNum = cHeight - 20
        elsif i >= 10 && i < 100
          xNum = cHeight - 25
        else
          xNum = cHeight - 35
        end
        UniqPin.new(scene, i, @chip.chip_id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false, api)
        y2 = y2 - 14
      end
    end
  end
  # Draw!
  @wire_helper_gui.gView.setScene(scene)
rescue Exception => msg
  Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while drawing the chip. Consult the logs for more details').exec
  logger = Logger.new($logFilePath)
  logger.error msg
end

Instance Method Details

#closeEvent(event) ⇒ Object



126
127
128
# File 'lib/class/Wire_helper.rb', line 126

def closeEvent(event)
  @api.setWiringLeds(0xFF00FF00FF00FF00)
end

#rotate_sceneObject



130
131
132
# File 'lib/class/Wire_helper.rb', line 130

def rotate_scene
  @wire_helper_gui.gView.rotate(90)
end