Skip to content

Commit

Permalink
Merge GUI work
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed Jan 14, 2021
1 parent 0cd84e1 commit 3d30c1c
Show file tree
Hide file tree
Showing 15 changed files with 971 additions and 74 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*.exe
/bbl2kml
/mission2kml
*.sh
mk*.sh
*.backup
go.sum
cmd/fl2kmlgtk/res.go
fl2kmlfyne
fl2kmlgtk
flightlog2kml
47 changes: 35 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
LDFLAGS ?= -s -w
prefix ?= /usr

_CAPP=flightlog2kml
_GAPP=fl2kmlgtk
_MAPP=mission2kml
_FAPP=fl2kmlfyne

ifndef DESTDIR
FAPP=flightlog2kml
CAPP=flightlog2kml
GAPP=fl2kmlgtk
MAPP=mission2kml
FAPP=fl2kmlfyne
else
FAPP=$(DESTDIR)/flightlog2kml
CAPP=$(DESTDIR)/flightlog2kml
MAPP=$(DESTDIR)/mission2kml
GAPP=$(DESTDIR)/fl2kmlgtk
FAPP=$(DESTDIR)/fl2kmlfyne
endif

ifeq ($(GOOS),windows)
EXT=.exe
LDEXTRA=-H=windowsgui
else
EXT=
endif

all: $(FAPP)$(EXT) $(MAPP)$(EXT)
all: $(_CAPP) $(_MAPP)

gui: $(_FAPP) $(_GAPP)

PKGCOMMON = $(wildcard pkg/api/*/*.go) $(wildcard pkg/mission/*.go) $(wildcard pkg/geo/*.go)
PKGOPT = $(wildcard pkg/options/*.go)
Expand All @@ -24,23 +36,34 @@ PKGOTX = $(wildcard pkg/otx/*.go)
PKGINAV = $(wildcard pkg/inav/*.go)
PKGKML = $(wildcard pkg/kmlgen/*.go)

FSRCS = $(wildcard cmd/flightlog2kml/*.go) $(PKGCOMMON) $(PKGBBL) $(PKGOTX) $(PKGINAV) $(PKGKML)
CSRCS = $(wildcard cmd/flightlog2kml/*.go) $(PKGCOMMON) $(PKGBBL) $(PKGOTX) $(PKGINAV) $(PKGKML)
MSRCS = $(wildcard cmd/mission2kml/*.go) $(PKGCOMMON)
GSRCS = cmd/fl2kmlgtk/main.go cmd/fl2kmlgtk/logkml.ui $(PKGCOMMON) $(PKGBBL) $(PKGOTX) $(PKGINAV) $(PKGKML)
FSRCS = cmd/fl2kmlfyne/main.go $(PKGCOMMON) $(PKGBBL) $(PKGOTX) $(PKGINAV) $(PKGKML)

$(FAPP)$(EXT): $(FSRCS)
go build -ldflags "$(LDFLAGS)" -o $(FAPP)$(EXT) cmd/flightlog2kml/main.go
$(_CAPP): $(CSRCS)
go build -ldflags "$(LDFLAGS)" -o $(CAPP)$(EXT) cmd/flightlog2kml/main.go

$(MAPP)$(EXT): $(MSRCS)
$(_MAPP): $(MSRCS)
go build -ldflags "$(LDFLAGS)" -o $(MAPP)$(EXT) cmd/mission2kml/main.go

$(_GAPP): $(GSRCS) cmd/fl2kmlgtk/res.go
go build -ldflags "$(LDFLAGS) $(LDEXTRA)" -o $(GAPP)$(EXT) cmd/fl2kmlgtk/main.go cmd/fl2kmlgtk/res.go

$(_FAPP): $(FSRCS)
go build -ldflags "$(LDFLAGS) $(LDEXTRA)" -o $(FAPP)$(EXT) cmd/fl2kmlfyne/main.go

cmd/fl2kmlgtk/res.go: cmd/fl2kmlgtk/logkml.ui
tools/packui.sh cmd/fl2kmlgtk/logkml.ui > cmd/fl2kmlgtk/res.go

clean:
@rm -f $(FAPP)$(EXT) $(MAPP)$(EXT)
@rm -f $(CAPP)$(EXT) $(MAPP)$(EXT) $(GAPP)$(EXT) $(FAPP)$(EXT)
@go clean

install: $(FAPP)$(EXE) $(MAPP)$(EXE)
install: $(CAPP)$(EXE) $(MAPP)$(EXE) $(GAPP)$(EXE)
@ install -d $(prefix)/bin
install -s $(FAPP)$(EXE) $(MAPP)$(EXE) $(prefix)/bin
install -s $(CAPP)$(EXE) $(MAPP)$(EXE) $(GAPP)$(EXE) $(prefix)/bin

install-local: $(FAPP) $(MAPP)
install-local: $(CAPP) $(MAPP) $(GAPP)
install -d $(HOME)/bin
install -s $(FAPP)$(EXE) $(MAPP)$(EXE) $(HOME)/bin/
install -s $(CAPP)$(EXE) $(MAPP)$(EXE) $(GAPP)$(EXE) $(HOME)/bin/
210 changes: 210 additions & 0 deletions cmd/fl2kmlfyne/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package main

import (
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/storage"
"fmt"
"path/filepath"
"os"
"strconv"
"strings"
options "github.com/stronnag/bbl2kml/pkg/options"
otx "github.com/stronnag/bbl2kml/pkg/otx"
bbl "github.com/stronnag/bbl2kml/pkg/bbl"
types "github.com/stronnag/bbl2kml/pkg/api/types"
geo "github.com/stronnag/bbl2kml/pkg/geo"
)

var GitCommit = "local"
var GitTag = "0.0.0"

func getVersion() string {
return fmt.Sprintf("%s %s, commit: %s", filepath.Base(os.Args[0]), GitTag, GitCommit)
}

func main() {
files := options.ParseCLI(getVersion)
if options.Dump {
fmt.Fprintln(os.Stderr, "Dump only supported via CLI")
return
}
var runbtn *widget.Button

a := app.New()
w := a.NewWindow("flightlog2kml")

var logfile, missionfile string

lfname := widget.NewLabel("")

mfname := widget.NewLabel("")
lbut := widget.NewButton("Log File", func() {
filter := storage.NewExtensionFileFilter([]string{".csv", ".TXT"})
fc := dialog.NewFileOpen(
func(cb fyne.URIReadCloser, err error) {
if cb != nil {
uri := cb.URI().String()
logfile = strings.Replace(uri, "file://", "", 1)
lfname.SetText(cb.URI().Name())
runbtn.Enable()
}
},
w)
fc.SetFilter(filter)
if len(logfile) > 0 {
df := filepath.Dir(logfile)
uri := storage.NewURI("file://" + df)
lsu, err := storage.ListerForURI(uri)
if err == nil {
fc.SetLocation(lsu)
}
}
fc.Show()
})

mbut := widget.NewButton("Mission File", func() {
fc := dialog.NewFileOpen(
func(cb fyne.URIReadCloser, err error) {
if cb != nil {
missionfile = cb.Name()
mfname.SetText(missionfile)
}
},
w)
fc.Show()
})

blank := widget.NewLabel(" ")
blankmax := fyne.NewContainerWithLayout(layout.NewMaxLayout())
blankmax.AddObject(blank)
lfmax := fyne.NewContainerWithLayout(layout.NewMaxLayout())
lfmax.AddObject(lfname)
mfmax := fyne.NewContainerWithLayout(layout.NewMaxLayout())
mfmax.AddObject(mfname)

idxentry := widget.NewEntry()
idxentry.SetText("0")
idxbox := fyne.NewContainerWithLayout(layout.NewFormLayout())
idxbox.AddObject(widget.NewLabel("Index"))
idxbox.AddObject(idxentry)

cols := 3
grid1 := fyne.NewContainerWithLayout(layout.NewGridLayout(cols))
grid1.AddObject(lbut)
grid1.AddObject(lfmax)
grid1.AddObject(idxbox)
grid1.AddObject(mbut)
grid1.AddObject(mfname)
cols = 2
grid2 := fyne.NewContainerWithLayout(layout.NewGridLayout(cols))
dmsck := widget.NewCheck("DMS", func(b bool) { options.Dms = b })
extck := widget.NewCheck("Extrude", func(b bool) { options.Extrude = b })
rssck := widget.NewCheck("RSSI is default", func(b bool) { options.Rssi = b })
effck := widget.NewCheck("Efficiency Layer", func(b bool) { options.Efficiency = b })
kmlck := widget.NewCheck("KML", func(b bool) { options.Kml = b })

var gopts []string = []string{"Red", "Red/Green", "Orange/Yellow/Red"}
gradcombo := widget.NewSelect(gopts, func(s string) {

})

n := 0
switch options.Gradset {
case "rdgn":
n = 1
case "yor":
n = 2
}
gradcombo.SetSelected(gopts[n])
gradbox := fyne.NewContainerWithLayout(layout.NewFormLayout())
gradbox.AddObject(widget.NewLabel("Gradient"))
gradbox.AddObject(gradcombo)

grid2.AddObject(dmsck)
grid2.AddObject(rssck)
grid2.AddObject(extck)
grid2.AddObject(kmlck)
grid2.AddObject(effck)
grid2.AddObject(gradbox)

rssck.SetChecked(options.Rssi)
extck.SetChecked(options.Extrude)
effck.SetChecked(options.Efficiency)
kmlck.SetChecked(options.Kml)
dmsck.SetChecked(options.Dms)

tg := widget.NewTextGrid()
sc := widget.NewScrollContainer(tg)
sc.SetMinSize(fyne.NewSize(640, 200))
tg.SetText("")
middle := fyne.NewContainerWithLayout(layout.NewMaxLayout())
middle.AddObject(sc)
runbtn = widget.NewButton("Run", func() {
idx_txt := idxentry.Text
idx, err := strconv.ParseInt(idx_txt, 10, 32)
if err != nil || idx < 0 || idx > 128 {
idx = 0
idxentry.SetText("0")
}
options.Idx = int(idx)
options.Dms = dmsck.Checked
options.Rssi = rssck.Checked
options.Extrude = extck.Checked
options.Efficiency = effck.Checked
geo.Frobnicate_init()
var lfr types.FlightLog
ext := filepath.Ext(logfile)
if strings.EqualFold(ext, ".csv") {
olfr := otx.NewOTXReader(logfile)
lfr = &olfr
} else {
blfr := bbl.NewBBLReader(logfile)
lfr = &blfr
}
metas, err := lfr.GetMetas()
if err == nil {
for _, b := range metas {
if (options.Idx == 0 || options.Idx == b.Index) && b.Flags&types.Is_Valid != 0 {
for k, v := range b.Summary() {
add_textview(tg, sc, fmt.Sprintf("%-8.8s : %s\n", k, v))
}
smap, res := lfr.Reader(b)
for k, v := range smap {
add_textview(tg, sc, fmt.Sprintf("%-8.8s : %s\n", k, v))
}
if s, ok := b.ShowDisarm(); ok {
add_textview(tg, sc, fmt.Sprintf("%-8.8s : %s\n\n", "Disarm", s))
}
if !res {
fmt.Fprintf(os.Stderr, "*** skipping KML/Z for log with no valid geospatial data\n")
dialog.ShowInformation("Error", "Failed to parse file", w)
}
}
}
} else {
dialog.ShowInformation("Error", err.Error(), w)
}
})

if len(files) > 0 {
logfile = files[0]
lfname.SetText(filepath.Base(logfile))
} else {
runbtn.Disable()
}
bottom := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, nil, nil, runbtn), runbtn)
vbox := widget.NewVBox(grid1, grid2, middle, bottom)
w.SetContent(vbox)
w.ShowAndRun()
}

func add_textview(tg *widget.TextGrid, sc *widget.ScrollContainer, s string) {
t := tg.Text()
t = t + s
tg.SetText(t)
sc.ScrollToBottom() // fyne 1.4.3 NEW API
}
Loading

0 comments on commit 3d30c1c

Please sign in to comment.