From 4f654973e5139f14d6fa63357a274ad0e3cbb202 Mon Sep 17 00:00:00 2001 From: sam-anthony Date: Sat, 9 Apr 2022 12:05:19 -0230 Subject: selecteable compressor and add BW K03 --- compressor/compressor.go | 41 ++++++++++++++++++++++++++++++++++-- compressor/res/GarrettG25660.jpg | Bin 833764 -> 0 bytes compressor/res/borgwarner/k/03.jpg | Bin 0 -> 185706 bytes compressor/res/garrett/g/25-660.jpg | Bin 0 -> 833764 bytes main.go | 21 ++++++++++++++---- ui.go | 29 ++++++++++++++++++++++++- 6 files changed, 84 insertions(+), 7 deletions(-) delete mode 100644 compressor/res/GarrettG25660.jpg create mode 100644 compressor/res/borgwarner/k/03.jpg create mode 100644 compressor/res/garrett/g/25-660.jpg diff --git a/compressor/compressor.go b/compressor/compressor.go index a3ac4bf..940d6fa 100644 --- a/compressor/compressor.go +++ b/compressor/compressor.go @@ -8,6 +8,7 @@ import ( ) type Compressor struct { + Name string FileName string // MinX is the distance of the y-axis from left of image in pixels. MinX int @@ -26,7 +27,23 @@ type Compressor struct { MaxPressureRatio float32 } -func GarrettG25660() Compressor { +var compressors = make(map[string]map[string]map[string]Compressor) + +func init() { + compressors["Garrett"] = make(map[string]map[string]Compressor) + compressors["Garrett"]["G"] = make(map[string]Compressor) + compressors["Garrett"]["G"]["25-660"] = garrettG25660() + + compressors["BorgWarner"] = make(map[string]map[string]Compressor) + compressors["BorgWarner"]["K"] = make(map[string]Compressor) + compressors["BorgWarner"]["K"]["03"] = borgwarnerK03() +} + +func Compressors() map[string]map[string]map[string]Compressor { + return compressors +} + +func garrettG25660() Compressor { maxFlow, err := mass.NewFlowRate( mass.Mass{70, mass.Pound}, time.Minute, @@ -34,7 +51,8 @@ func GarrettG25660() Compressor { ) util.Check(err) return Compressor{ - "compressor/res/GarrettG25660.jpg", + "Garrett G25-660", + "compressor/res/garrett/g/25-660.jpg", 204, 1885, 1665, @@ -43,3 +61,22 @@ func GarrettG25660() Compressor { 4.0, } } + +func borgwarnerK03() Compressor { + maxFlow, err := mass.NewFlowRate( + mass.Mass{0.13, mass.Kilogram}, + time.Second, + mass.KilogramsPerSecond, + ) + util.Check(err) + return Compressor{ + "BorgWarner K03", + "compressor/res/borgwarner/k/03.jpg", + 30, + 714, + 876, + 4, + maxFlow, + 2.8, + } +} diff --git a/compressor/res/GarrettG25660.jpg b/compressor/res/GarrettG25660.jpg deleted file mode 100644 index aa8d12a..0000000 Binary files a/compressor/res/GarrettG25660.jpg and /dev/null differ diff --git a/compressor/res/borgwarner/k/03.jpg b/compressor/res/borgwarner/k/03.jpg new file mode 100644 index 0000000..3464331 Binary files /dev/null and b/compressor/res/borgwarner/k/03.jpg differ diff --git a/compressor/res/garrett/g/25-660.jpg b/compressor/res/garrett/g/25-660.jpg new file mode 100644 index 0000000..aa8d12a Binary files /dev/null and b/compressor/res/garrett/g/25-660.jpg differ diff --git a/main.go b/main.go index 49ff70f..228d611 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" g "github.com/AllenDang/giu" "image" "image/draw" @@ -103,6 +104,7 @@ func loop() { Columns( columns()..., ), + selectCompressor(), g.Custom(compressorWidget), ) } @@ -113,10 +115,8 @@ var ( selectedCompressor compressor.Compressor ) -func init() { - selectedCompressor = compressor.GarrettG25660() - - f, err := os.Open(selectedCompressor.FileName) +func setCompressor(c compressor.Compressor) { + f, err := os.Open(c.FileName) util.Check(err) defer f.Close() @@ -127,7 +127,20 @@ func init() { m := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(m, m.Bounds(), j, b.Min, draw.Src) + selectedCompressor = c compressorImage = m + + go updateCompImg() +} + +func init() { + c, ok := compressor.Compressors()["Garrett"]["G"]["25-660"] + if !ok { + fmt.Println("Garrett G25-660 not in compressor.Compressors().") + os.Exit(1) + } + + setCompressor(c) } func main() { diff --git a/ui.go b/ui.go index 8d56f87..74a3fd5 100644 --- a/ui.go +++ b/ui.go @@ -8,6 +8,7 @@ import ( "image/draw" "strconv" + "github.com/sam-anthony/volute/compressor" "github.com/sam-anthony/volute/mass" "github.com/sam-anthony/volute/pressure" "github.com/sam-anthony/volute/temperature" @@ -272,6 +273,32 @@ func columns() []*g.TableColumnWidget { return widgets } +var compressorTree []g.Widget + +func init() { + compressors := compressor.Compressors() + for manufacturer := range compressors { + manufacturerNode := g.TreeNode(manufacturer) + for series := range compressors[manufacturer] { + seriesNode := g.TreeNode(series) + for model, c := range compressors[manufacturer][series] { + seriesNode = seriesNode.Layout( + g.Selectable(model).OnClick(func() { + go setCompressor(c) + }), + ) + } + manufacturerNode = manufacturerNode.Layout(seriesNode) + } + compressorTree = append(compressorTree, manufacturerNode) + } +} + +func selectCompressor() g.Widget { + return g.ComboCustom("Compressor", selectedCompressor.Name). + Layout(compressorTree...) +} + var updatedCompImg = make(chan image.Image) func updateCompImg() { @@ -321,7 +348,7 @@ func compressorWidget() { winWidth, winHeight := g.GetAvailableRegion() canvas.AddImage( compressorTexture, - image.Pt(0, 225), + image.Pt(0, 250), image.Pt(int(winWidth), int(winHeight)), ) } -- cgit v1.2.3