From bd1ab116860f7bbcd9fbcf90ae632ef630cd9d6b Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 14 Jul 2022 13:47:39 -0400 Subject: [PATCH] #79 water cooling only support, dynamic height, changed 2 turbine 1 boiler layout --- coordinator/startup.lua | 2 +- coordinator/ui/components/boiler.lua | 1 - coordinator/ui/components/reactor.lua | 1 - coordinator/ui/components/turbine.lua | 1 - coordinator/ui/components/unit_overview.lua | 168 ++++++++++++-------- coordinator/ui/layout/main_view.lua | 20 ++- graphics/element.lua | 10 ++ 7 files changed, 129 insertions(+), 74 deletions(-) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index e6cadc9..0ef6814 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -13,7 +13,7 @@ local config = require("coordinator.config") local coordinator = require("coordinator.coordinator") local renderer = require("coordinator.renderer") -local COORDINATOR_VERSION = "alpha-v0.3.2" +local COORDINATOR_VERSION = "alpha-v0.3.3" local print = util.print local println = util.println diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index f45585b..8deace3 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -2,7 +2,6 @@ local core = require("graphics.core") local style = require("coordinator.ui.style") -local Div = require("graphics.elements.div") local DataIndicator = require("graphics.elements.indicators.data") local StateIndicator = require("graphics.elements.indicators.state") local Rectangle = require("graphics.elements.rectangle") diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index 05d27dd..d7d35f5 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -2,7 +2,6 @@ local core = require("graphics.core") local style = require("coordinator.ui.style") -local Div = require("graphics.elements.div") local HorizontalBar = require("graphics.elements.indicators.hbar") local DataIndicator = require("graphics.elements.indicators.data") local StateIndicator = require("graphics.elements.indicators.state") diff --git a/coordinator/ui/components/turbine.lua b/coordinator/ui/components/turbine.lua index 9498524..f1ffea0 100644 --- a/coordinator/ui/components/turbine.lua +++ b/coordinator/ui/components/turbine.lua @@ -2,7 +2,6 @@ local core = require("graphics.core") local style = require("coordinator.ui.style") -local Div = require("graphics.elements.div") local DataIndicator = require("graphics.elements.indicators.data") local StateIndicator = require("graphics.elements.indicators.state") local Rectangle = require("graphics.elements.rectangle") diff --git a/coordinator/ui/components/unit_overview.lua b/coordinator/ui/components/unit_overview.lua index 6819930..2ddedc7 100644 --- a/coordinator/ui/components/unit_overview.lua +++ b/coordinator/ui/components/unit_overview.lua @@ -1,3 +1,7 @@ +-- +-- Basic Unit Overview +-- + local core = require("graphics.core") local style = require("coordinator.ui.style") @@ -21,116 +25,152 @@ local pipe = core.graphics.pipe ---@param y integer ---@param unit coord_db_entry local function make(parent, x, y, unit) + local height = 0 + local num_boilers = #unit.boiler_data_tbl + local num_turbines = #unit.turbine_data_tbl + + assert(num_boilers >= 0 and num_boilers <= 2, "minimum 0 boilers, maximum 2 boilers") + assert(num_turbines >= 1 and num_turbines <= 3, "minimum 1 turbine, maximum 3 turbines") + + if num_boilers == 0 and num_turbines == 1 then + height = 9 + elseif num_boilers == 1 and num_turbines <= 2 then + height = 17 + else + height = 25 + end + -- bounding box div - local root = Div{parent=parent,x=x,y=y,width=80,height=25} + local root = Div{parent=parent,x=x,y=y,width=80,height=height,fg_bg=cpair(colors.black,colors.black)} -- unit header message TextBox{parent=root,text="Unit #" .. unit.unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} - local num_boilers = #unit.boiler_data_tbl - local num_turbines = #unit.turbine_data_tbl - ------------- -- REACTOR -- ------------- reactor_view(root, 1, 3, unit.reactor_ps) - local coolant_pipes = {} + if num_boilers > 0 then + local coolant_pipes = {} - if num_boilers == 2 then - table.insert(coolant_pipes, pipe(0, 0, 11, 12, colors.lightBlue)) + if num_boilers >= 2 then + table.insert(coolant_pipes, pipe(0, 0, 11, 12, colors.lightBlue)) + end + + table.insert(coolant_pipes, pipe(0, 0, 11, 3, colors.lightBlue)) + table.insert(coolant_pipes, pipe(2, 0, 11, 2, colors.orange)) + + if num_boilers >= 2 then + table.insert(coolant_pipes, pipe(2, 0, 11, 11, colors.orange)) + end + + PipeNetwork{parent=root,x=4,y=10,pipes=coolant_pipes,bg=colors.lightGray} end - table.insert(coolant_pipes, pipe(0, 0, 11, 3, colors.lightBlue)) - table.insert(coolant_pipes, pipe(2, 0, 11, 2, colors.orange)) - - if num_boilers == 2 then - table.insert(coolant_pipes, pipe(2, 0, 11, 11, colors.orange)) - end - - PipeNetwork{parent=root,x=4,y=10,pipes=coolant_pipes,bg=colors.lightGray} - ------------- -- BOILERS -- ------------- - boiler_view(root, 16, 11, unit.boiler_ps_tbl[1]) - if num_boilers == 2 then boiler_view(root, 16, 19, unit.boiler_ps_tbl[2]) end + if num_boilers >= 1 then boiler_view(root, 16, 11, unit.boiler_ps_tbl[1]) end + if num_boilers >= 2 then boiler_view(root, 16, 19, unit.boiler_ps_tbl[2]) end -------------- -- TURBINES -- -------------- local t_idx = 1 + local no_boilers = num_boilers == 0 - if num_turbines == 3 then + if (num_turbines >= 3) or no_boilers or (num_boilers == 1 and num_turbines >= 2) then turbine_view(root, 58, 3, unit.turbine_ps_tbl[t_idx]) t_idx = t_idx + 1 end - if num_turbines >= 1 then + if (num_turbines >= 1 and not no_boilers) or num_turbines >= 2 then turbine_view(root, 58, 11, unit.turbine_ps_tbl[t_idx]) t_idx = t_idx + 1 end - if num_turbines >= 2 then turbine_view(root, 58, 19, unit.turbine_ps_tbl[t_idx]) end - - local steam_pipes_a = { - -- boiler 1 steam/water pipes - pipe(0, 1, 6, 1, colors.white, false, true), -- steam boiler 1 to turbine junction - pipe(0, 2, 6, 2, colors.blue, false, true) -- water boiler 1 to turbine junction - } - - if num_boilers == 2 then - -- boiler 2 steam/water pipes - table.insert(steam_pipes_a, pipe(0, 9, 6, 9, colors.white, false, true)) -- steam boiler 2 to turbine junction - table.insert(steam_pipes_a, pipe(0, 10, 6, 10, colors.blue, false, true)) -- water boiler 2 to turbine junction + if (num_turbines >= 2 and num_boilers >= 2) or num_turbines >= 3 then + turbine_view(root, 58, 19, unit.turbine_ps_tbl[t_idx]) end local steam_pipes_b = {} - if num_turbines == 3 then - table.insert(steam_pipes_b, pipe(0, 9, 1, 2, colors.white, false, true)) -- steam boiler 1 to turbine 1 junction start - table.insert(steam_pipes_b, pipe(1, 1, 3, 1, colors.white, false, false)) -- steam boiler 1 to turbine 1 junction end - end + if no_boilers then + table.insert(steam_pipes_b, pipe(0, 1, 3, 1, colors.white)) -- steam to turbine 1 + table.insert(steam_pipes_b, pipe(0, 2, 3, 2, colors.blue)) -- water to turbine 1 - table.insert(steam_pipes_b, pipe(0, 9, 3, 9, colors.white, false, true)) -- steam boiler 1 to turbine 2 - - if num_turbines == 3 then - table.insert(steam_pipes_b, pipe(0, 10, 2, 3, colors.blue, false, true)) -- water boiler 1 to turbine 1 junction start - table.insert(steam_pipes_b, pipe(2, 2, 3, 2, colors.blue, false, false)) -- water boiler 1 to turbine 1 junction end - end - - table.insert(steam_pipes_b, pipe(0, 10, 3, 10, colors.blue, false, true)) -- water boiler 1 to turbine 2 - - if num_turbines >= 2 then - if num_boilers == 2 then - table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction - table.insert(steam_pipes_b, pipe(0, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 - else - table.insert(steam_pipes_b, pipe(1, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction - table.insert(steam_pipes_b, pipe(1, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + if num_turbines >= 2 then + table.insert(steam_pipes_b, pipe(1, 2, 3, 9, colors.white)) -- steam to turbine 2 + table.insert(steam_pipes_b, pipe(2, 3, 3, 10, colors.blue)) -- water to turbine 2 end - if num_boilers == 2 then - table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 - table.insert(steam_pipes_b, pipe(0, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction - else - table.insert(steam_pipes_b, pipe(2, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 - table.insert(steam_pipes_b, pipe(2, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + if num_turbines >= 3 then + table.insert(steam_pipes_b, pipe(1, 9, 3, 17, colors.white)) -- steam boiler 1 to turbine 1 junction end + table.insert(steam_pipes_b, pipe(2, 10, 3, 18, colors.blue)) -- water boiler 1 to turbine 1 junction start end - elseif num_turbines == 1 and num_boilers == 2 then - table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction - table.insert(steam_pipes_b, pipe(0, 17, 1, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + else + -- boiler side pipes - table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 - table.insert(steam_pipes_b, pipe(0, 18, 2, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + local steam_pipes_a = { + -- boiler 1 steam/water pipes + pipe(0, 1, 6, 1, colors.white, false, true), -- steam boiler 1 to turbine junction + pipe(0, 2, 6, 2, colors.blue, false, true) -- water boiler 1 to turbine junction + } + + if num_boilers >= 2 then + -- boiler 2 steam/water pipes + table.insert(steam_pipes_a, pipe(0, 9, 6, 9, colors.white, false, true)) -- steam boiler 2 to turbine junction + table.insert(steam_pipes_a, pipe(0, 10, 6, 10, colors.blue, false, true)) -- water boiler 2 to turbine junction + end + + -- turbine side pipes + + if num_turbines >= 3 or (num_boilers == 1 and num_turbines == 2) then + table.insert(steam_pipes_b, pipe(0, 9, 1, 2, colors.white, false, true)) -- steam boiler 1 to turbine 1 junction start + table.insert(steam_pipes_b, pipe(1, 1, 3, 1, colors.white, false, false)) -- steam boiler 1 to turbine 1 junction end + end + + table.insert(steam_pipes_b, pipe(0, 9, 3, 9, colors.white, false, true)) -- steam boiler 1 to turbine 2 + + if num_turbines >= 3 or (num_boilers == 1 and num_turbines == 2) then + table.insert(steam_pipes_b, pipe(0, 10, 2, 3, colors.blue, false, true)) -- water boiler 1 to turbine 1 junction start + table.insert(steam_pipes_b, pipe(2, 2, 3, 2, colors.blue, false, false)) -- water boiler 1 to turbine 1 junction end + end + + table.insert(steam_pipes_b, pipe(0, 10, 3, 10, colors.blue, false, true)) -- water boiler 1 to turbine 2 + + if num_turbines >= 3 or (num_turbines >= 2 and num_boilers >= 2) then + if num_boilers >= 2 then + table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(0, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + + table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(0, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + else + table.insert(steam_pipes_b, pipe(1, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(1, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + + table.insert(steam_pipes_b, pipe(2, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(2, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + end + elseif num_turbines == 1 and num_boilers >= 2 then + table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(0, 17, 1, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + + table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(0, 18, 2, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + end + + PipeNetwork{parent=root,x=47,y=11,pipes=steam_pipes_a,bg=colors.lightGray} end - PipeNetwork{parent=root,x=47,y=11,pipes=steam_pipes_a,bg=colors.lightGray} PipeNetwork{parent=root,x=54,y=3,pipes=steam_pipes_b,bg=colors.lightGray} + return root end return make diff --git a/coordinator/ui/layout/main_view.lua b/coordinator/ui/layout/main_view.lua index f45413c..ee096ce 100644 --- a/coordinator/ui/layout/main_view.lua +++ b/coordinator/ui/layout/main_view.lua @@ -2,8 +2,6 @@ -- Main SCADA Coordinator GUI -- -local log = require("scada-common.log") - local database = require("coordinator.database") local style = require("coordinator.ui.style") @@ -24,11 +22,21 @@ local function init(monitor) local db = database.get() + local uo_1, uo_2, uo_3, uo_4 ---@type graphics_element + -- unit overviews - if db.facility.num_units >= 1 then unit_overview(main, 2, 3, db.units[1]) end - if db.facility.num_units >= 2 then unit_overview(main, 84, 3, db.units[2]) end - if db.facility.num_units >= 3 then unit_overview(main, 2, 29, db.units[3]) end - if db.facility.num_units == 4 then unit_overview(main, 84, 29, db.units[4]) end + if db.facility.num_units >= 1 then uo_1 = unit_overview(main, 2, 3, db.units[1]) end + if db.facility.num_units >= 2 then uo_2 = unit_overview(main, 84, 3, db.units[2]) end + + if db.facility.num_units >= 3 then + -- base offset 3, spacing 1, max height of units 1 and 2 + local row_2_offset = 3 + 1 + math.max(uo_1.height(), uo_2.height()) + + uo_3 = unit_overview(main, 2, row_2_offset, db.units[3]) + if db.facility.num_units == 4 then uo_4 = unit_overview(main, 84, row_2_offset, db.units[4]) end + end + + -- command & control return main end diff --git a/graphics/element.lua b/graphics/element.lua index 5e58ec1..274681e 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -148,6 +148,16 @@ function element.new(args) return self.child_offset.x, self.child_offset.y end + -- get element width + function public.width() + return protected.frame.w + end + + -- get element height + function public.height() + return protected.frame.h + end + -- handle a monitor touch ---@param event monitor_touch monitor touch event function public.handle_touch(event)