-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtunePage.lua
120 lines (104 loc) · 4.55 KB
/
tunePage.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
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
-- Copyright (c) 2016 Thermo Fisher Scientific
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
-- (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
-- merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished
-- to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- tunePage.lua
-- a gridPage with the ability to display the tune parameters
-- Load necessary libraries
local gridPage = require("gridPage")
local properties = require("properties")
local trendPage = require("trendPage")
-- Get assemblies
luanet.load_assembly("System.Drawing")
-- Get constructors
local ContextMenuStrip = luanet.import_type("System.Windows.Forms.ContextMenuStrip")
local ToolStripMenuItem = luanet.import_type("System.Windows.Forms.ToolStripMenuItem")
-- Get enumerations
local AutoSizeColumnsMode = luanet.import_type("System.Windows.Forms.DataGridViewAutoSizeColumnsMode")
local MouseButtons = luanet.import_type("System.Windows.Forms.MouseButtons")
-- local variables
local clickedItem
-- Forward declaration for local helper functions
local CellMouseEnterCB, ShowTrendCB
-- local functions
local function AddMenu(self)
local menu = ContextMenuStrip() -- Get a ContextMenuStrip
self.gridControl.ContextMenuStrip = menu -- Set the grids ContextMenuStrip
local item = ToolStripMenuItem("Create Trend Page") -- Get a ToolStripMenuItem
item.Click:Add(ShowTrendCB) -- Add a callback
item.Tag = self -- Set tag to the page
menu.Items:Add(item) -- Add it to the menu
self.gridControl.CellMouseEnter:Add(CellMouseEnterCB) -- Add callback for cell enter
end
-- This has a forward declaration
function CellMouseEnterCB(sender, args)
-- Fetch entry in column 0, which will be the label
clickedItem = sender.Rows[args.RowIndex].Cells[0].Value
end
-- This has a forward declaration
-- Sender is the toolStripItem
function ShowTrendCB(sender, args)
local self = sender.Tag -- Previously set Tag to the Lua tunePage
if self.statusEntries[clickedItem] then
local noteBook = self:ParentNotebook()
--local name = self:UniqueName(noteBook)
local page = trendPage({name = noteBook:GetUniquePageName("Trend"), rawFile = self.rawFile})
local result = page:Plot(clickedItem)
if result then
noteBook:AddPage(page)
-- Set the new page as the selected page in the notebook
noteBook.tabControl.SelectedTab = page.pageControl
end
end
end
-- Start of tunePage Object
local tunePage = {}
tunePage.__index = tunePage
setmetatable(tunePage, {
__index = gridPage, -- this is the inheritance
__call = function(cls, ...)
local self = setmetatable({}, cls)
self:_init(...)
return self
end, })
function tunePage:_init(args)
args = args or {}
gridPage._init(self, args)
local grid = self.gridControl
grid.AutoGenerateColumns = false
grid.AutoSizeColumnsMode = AutoSizeColumnsMode.Fill
grid.ColumnHeadersVisible = false
grid.RowHeadersVisible = false
self.rawFile = args.rawFile
if not args.skipInit then self:ShowTune() end
end
function tunePage:ShowTune(args)
args = args or {}
if not self.rawFile then
print ("No rawFile available")
return nil
end
local rawFile = self.rawFile
local tune = rawFile:GetTuneData(1) -- '1' is for mass spectrometer tune file
-- Since this is a key/value table, the order is indeterminate
-- So alphabetize for consistent presentation
local sorted = {}
for key, value in pairs(tune) do
table.insert(sorted, {key, value})
end
table.sort(sorted, function(a,b) return a[1] < b[1] end)
if #sorted == 0 then
sorted[1] = {"No Tune Data"}
end
self:Fill(sorted)
end
return tunePage