Class: Import
- Inherits:
-
Qt::Widget
- Object
- Qt::Widget
- Import
- Defined in:
- lib/class/Import.rb
Instance Method Summary collapse
- #import ⇒ Object
- #import_chip ⇒ Object
- #import_commands ⇒ Object
- #import_file ⇒ Object
- #import_i2c_settings ⇒ Object
- #import_manufacturer ⇒ Object
- #import_package ⇒ Object
- #import_parallel_settings ⇒ Object
- #import_pins ⇒ Object
- #import_spi_settings ⇒ Object
- #import_swd_settings ⇒ Object
- #import_type ⇒ Object
- #import_uart_settings ⇒ Object
-
#initialize(cm, chip = 'none') ⇒ Import
constructor
A new instance of Import.
Constructor Details
#initialize(cm, chip = 'none') ⇒ Import
Returns a new instance of Import.
14 15 16 17 18 19 20 21 22 |
# File 'lib/class/Import.rb', line 14 def initialize(cm, chip = 'none') super() @import_ui = Ui_Import.new centerWindow(self) @import_ui.setupUi(self) @chip = chip @cm = cm @import_ui.lbl_import.setText("Import:") end |
Instance Method Details
#import ⇒ Object
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 |
# File 'lib/class/Import.rb', line 33 def import unless @filepath.nil? @file = File.read("#{@filepath}") data_hash = JSON.parse(@file) data_hash.each_with_index do |element, index| @data_chip = element[1]['chip'] @data_commands = element[1]['commands'] if @import_ui.rbn_both.isChecked import_chip import_commands elsif @import_ui.rbn_comp.isChecked import_chip else import_commands end end @cm.feed_chip_array Qt::MessageBox.new( Qt::MessageBox::Information, 'Import status', 'Import complete' ).exec self.close else Qt::MessageBox.new( Qt::MessageBox::Warning, 'File missing', 'Choose a file before importing' ).exec end end |
#import_chip ⇒ Object
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/Import.rb', line 101 def import_chip @chip = Chip.new @chip.from_json(@data_chip['characteristics'].to_json) if Chip.exists?(reference: @chip.reference) Qt::MessageBox.new( Qt::MessageBox::Warning, 'Import aborted', 'This component already exists' ).exec return 0 else Chip.last.nil? ? @chip.id = 1 : @chip.id = Chip.last.id.next @chip.package_id = import_package @chip.chip_type_id = import_type @chip.manufacturer_id = import_manufacturer @chip.save import_parallel_settings unless @data_chip['settings']['parallel'].nil? import_spi_settings unless @data_chip['settings']['spi'].empty? import_i2c_settings unless @data_chip['settings']['i2c'].empty? import_swd_settings unless @data_chip['settings']['swd'].empty? import_uart_settings unless @data_chip['settings']['uart'].empty? import_pins end end |
#import_commands ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/class/Import.rb', line 176 def import_commands return 0 if @data_commands.empty? @data_commands.each do |cmd_element| cmd = Command.new cmd.from_json(cmd_element[1]['characteristics'].to_json) Command.last.nil? ? cmd.id = 1 : cmd.id = Command.last.id.next cmd.chip_id = @chip.id cmd.save cmd_element[1]['bytes'].each do |byte_element| byte = Byte.new byte.from_json(byte_element.to_json) Byte.last.nil? ? byte.id = 1 : byte.id = Byte.last.id.next byte.command_id = cmd.id byte.save end end end |
#import_file ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/class/Import.rb', line 24 def import_file @filepath = Qt::FileDialog.getOpenFileName( self, tr('Select a file'), '/', tr('JSON file (*.json)') ) end |
#import_i2c_settings ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/class/Import.rb', line 152 def import_i2c_settings i2c_settings = I2cSetting.new i2c_settings.from_json(@data_chip['settings']['i2c'].to_json) i2c_settings.chip_id = @chip.id I2cSetting.last.nil? ? i2c_settings.id = 1 : i2c_settings.id = I2cSetting.last.id.next i2c_settings.save end |
#import_manufacturer ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/class/Import.rb', line 89 def import_manufacturer manufacturer = Manufacturer.new manufacturer.from_json(@data_chip['manufacturer'].to_json) if Manufacturer.exists?(name: manufacturer.name) return Manufacturer.find_by(name: manufacturer.name).id else Manufacturer.last.nil? ? manufacturer.id = 1 : manufacturer.id = Manufacturer.last.id.next manufacturer.save return manufacturer.id end end |
#import_package ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/class/Import.rb', line 65 def import_package package = Package.new package.from_json(@data_chip['package'].to_json) if Package.exists?(name: package.name) return Package.find_by(name: package.name).id else Package.last.nil? ? package.id = 1 : package.id = Package.last.id.next package.save return package.id end end |
#import_parallel_settings ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/class/Import.rb', line 136 def import_parallel_settings parallel_settings = ParallelSetting.new parallel_settings.from_json(@data_chip['settings']['parallel'].to_json) parallel_settings.chip_id = @chip.id ParallelSetting.last.nil? ? parallel_settings.id = 1 : parallel_settings.id = ParallelSetting.last.id.next parallel_settings.save end |
#import_pins ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/class/Import.rb', line 126 def import_pins @data_chip['pins'].each do |data_pin| pin = Pin.new pin.from_json(data_pin.to_json) pin.chip_id = @chip.id Pin.last.nil? ? pin.id = 1 : pin.id = Pin.last.id.next pin.save end end |
#import_spi_settings ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/class/Import.rb', line 144 def import_spi_settings spi_settings = SpiSetting.new spi_settings.from_json(@data_chip['settings']['spi'].to_json) spi_settings.chip_id = @chip.id SpiSetting.last.nil? ? spi_settings.id = 1 : spi_settings.id = SpiSetting.last.id.next spi_settings.save end |
#import_swd_settings ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/class/Import.rb', line 160 def import_swd_settings swd_settings = SwdSetting.new swd_settings.from_json(@data_chip['settings']['swd'].to_json) swd_settings.chip_id = @chip.id SwdSetting.last.nil? ? swd_settings.id = 1 : swd_settings.id = SwdSetting.last.id.next swd_settings.save end |
#import_type ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/class/Import.rb', line 77 def import_type chip_type = ChipType.new chip_type.from_json(@data_chip['chip_type'].to_json) if ChipType.exists?(name: chip_type.name) return ChipType.find_by(name: chip_type.name).id else ChipType.last.nil? ? chip_type.id = 1 : chip_type.id = ChipType.last.id.next chip_type.save return chip_type.id end end |
#import_uart_settings ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/class/Import.rb', line 168 def import_uart_settings uart_settings = UartSetting.new uart_settings.from_json(@data_chip['settings']['uart'].to_json) uart_settings.chip_id = @chip.id UartSetting.last.nil? ? uart_settings.id = 1 : uart_settings.id = UartSetting.last.id.next uart_settings.save end |