From 92661e7aa6c150e74dcdc767b5d06bc6a1242e08 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Fri, 14 Jun 2024 04:05:48 -0700 Subject: [PATCH] first pass update of netview for new core --- egui/README.md | 2 +- egui/grids.go | 18 +- egui/gui.go | 18 +- egui/plots.go | 36 ++-- elog/README.md | 2 +- elog/stditems.go | 2 +- estats/plots.go | 20 +-- estats/stats.go | 14 +- netview/events.go | 21 +-- netview/laymesh.go | 20 +-- netview/layraster.go | 11 -- netview/netdata.go | 8 +- netview/netview.go | 419 +++++++++++++++++++++++-------------------- netview/params.go | 7 +- netview/typegen.go | 119 +----------- netview/viewupdt.go | 8 +- params/apply.go | 6 +- 17 files changed, 321 insertions(+), 410 deletions(-) diff --git a/egui/README.md b/egui/README.md index 225f0672..a2fe7ea3 100644 --- a/egui/README.md +++ b/egui/README.md @@ -91,7 +91,7 @@ Here's an `ActiveRunning` case: ## Tensor Grid (e.g., of an Image) ```Go - tg := ss.GUI.TabView.AddNewTab(tensorview.KiT_TensorGrid, "Image").(*tensorview.TensorGrid) + tg := ss.GUI.TabView.AddNewTab(tensorcore.KiT_TensorGrid, "Image").(*tensorcore.TensorGrid) tg.SetStretchMax() ss.GUI.SetGrid("Image", tg) tg.SetTensor(&ss.TrainEnv.Img.Tsr) diff --git a/egui/grids.go b/egui/grids.go index 6d443d4e..34023458 100644 --- a/egui/grids.go +++ b/egui/grids.go @@ -7,34 +7,34 @@ package egui import ( "cogentcore.org/core/core" "cogentcore.org/core/tensor" - "cogentcore.org/core/tensor/tensorview" + "cogentcore.org/core/tensor/tensorcore" "github.com/emer/emergent/v2/actrf" ) // Grid gets tensor grid view of given name, creating if not yet made -func (gui *GUI) Grid(name string) *tensorview.TensorGrid { +func (gui *GUI) Grid(name string) *tensorcore.TensorGrid { if gui.Grids == nil { - gui.Grids = make(map[string]*tensorview.TensorGrid) + gui.Grids = make(map[string]*tensorcore.TensorGrid) } tsr, ok := gui.Grids[name] if !ok { - tsr = &tensorview.TensorGrid{} + tsr = &tensorcore.TensorGrid{} gui.Grids[name] = tsr } return tsr } // SetGrid sets tensor grid view to given name -func (gui *GUI) SetGrid(name string, tg *tensorview.TensorGrid) { +func (gui *GUI) SetGrid(name string, tg *tensorcore.TensorGrid) { if gui.Grids == nil { - gui.Grids = make(map[string]*tensorview.TensorGrid) + gui.Grids = make(map[string]*tensorcore.TensorGrid) } gui.Grids[name] = tg } // ConfigRasterGrid configures a raster grid for given layer name. // Uses Raster_laynm and given Tensor that has the raster data. -func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Float32) *tensorview.TensorGrid { +func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Float32) *tensorcore.TensorGrid { tg := gui.Grid(laynm) tg.SetName(laynm + "Raster") core.NewText(lay, laynm, laynm+":") @@ -47,7 +47,7 @@ func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Fl // SaveActRFGrid stores the given TensorGrid in Grids under given name, // and configures the grid view for ActRF viewing. -func (gui *GUI) SaveActRFGrid(tg *tensorview.TensorGrid, name string) { +func (gui *GUI) SaveActRFGrid(tg *tensorcore.TensorGrid, name string) { gui.SetGrid(name, tg) } @@ -56,7 +56,7 @@ func (gui *GUI) AddActRFGridTabs(arfs *actrf.RFs) { for _, rf := range arfs.RFs { nm := rf.Name tf := gui.Tabs.NewTab(nm) - tg := tensorview.NewTensorGrid(tf) + tg := tensorcore.NewTensorGrid(tf) gui.SaveActRFGrid(tg, nm) } } diff --git a/egui/gui.go b/egui/gui.go index a1d307cc..67f5b7fb 100644 --- a/egui/gui.go +++ b/egui/gui.go @@ -8,9 +8,8 @@ package egui import ( "cogentcore.org/core/core" - "cogentcore.org/core/plot/plotview" - "cogentcore.org/core/tensor/tensorview" - "cogentcore.org/core/views" + "cogentcore.org/core/plot/plotcore" + "cogentcore.org/core/tensor/tensorcore" "github.com/emer/emergent/v2/etime" "github.com/emer/emergent/v2/netview" // _ "cogentcore.org/core/vgpu/gosl/slboolview" // include to get gui views @@ -32,13 +31,13 @@ type GUI struct { StopNow bool `view:"-"` // plots by scope - Plots map[etime.ScopeKey]*plotview.PlotView + Plots map[etime.ScopeKey]*plotcore.PlotEditor // plots by scope - TableViews map[etime.ScopeKey]*tensorview.TableView + TableViews map[etime.ScopeKey]*tensorcore.Table // tensor grid views by name -- used e.g., for Rasters or ActRFs -- use Grid(name) to access - Grids map[string]*tensorview.TensorGrid + Grids map[string]*tensorcore.TensorGrid // the view update for managing updates of netview ViewUpdate *netview.ViewUpdate `view:"-"` @@ -47,7 +46,7 @@ type GUI struct { NetData *netview.NetData `view:"-"` // displays Sim fields on left - StructView *views.StructView `view:"-"` + StructView *core.Form `view:"-"` // tabs for different view elements: plots, rasters Tabs *core.Tabs `view:"-"` @@ -98,12 +97,13 @@ func (gui *GUI) Stopped() { // MakeBody returns default window Body content func (gui *GUI) MakeBody(sim any, appname, title, about string) { - views.NoSentenceCaseFor = append(views.NoSentenceCaseFor, "github.com/emer") + core.NoSentenceCaseFor = append(core.NoSentenceCaseFor, "github.com/emer") gui.Body = core.NewBody(appname).SetTitle(title) // gui.Body.App().About = about split := core.NewSplits(gui.Body, "split") - gui.StructView = views.NewStructView(split, "sv").SetStruct(sim) + gui.StructView = core.NewForm(split).SetStruct(sim) + gui.StructView.Name = "sv" if tb, ok := sim.(core.Toolbarer); ok { gui.Body.AddAppBar(tb.ConfigToolbar) } diff --git a/egui/plots.go b/egui/plots.go index 17b36830..cc1f9e19 100644 --- a/egui/plots.go +++ b/egui/plots.go @@ -10,8 +10,8 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/colors" - "cogentcore.org/core/plot/plotview" - "cogentcore.org/core/tensor/tensorview" + "cogentcore.org/core/plot/plotcore" + "cogentcore.org/core/tensor/tensorcore" "github.com/emer/emergent/v2/elog" "github.com/emer/emergent/v2/etime" ) @@ -19,7 +19,7 @@ import ( // AddPlots adds plots based on the unique tables we have, // currently assumes they should always be plotted func (gui *GUI) AddPlots(title string, lg *elog.Logs) { - gui.Plots = make(map[etime.ScopeKey]*plotview.PlotView) + gui.Plots = make(map[etime.ScopeKey]*plotcore.PlotEditor) // for key, table := range Log.Tables { for _, key := range lg.TableOrder { modes, times := key.ModesAndTimes() @@ -41,7 +41,7 @@ func (gui *GUI) AddPlots(title string, lg *elog.Logs) { } } -func ConfigPlotFromLog(title string, plt *plotview.PlotView, lg *elog.Logs, key etime.ScopeKey) { +func ConfigPlotFromLog(title string, plt *plotcore.PlotEditor, lg *elog.Logs, key etime.ScopeKey) { _, times := key.ModesAndTimes() time := times[0] lt := lg.Tables[key] // LogTable struct @@ -74,12 +74,12 @@ func ConfigPlotFromLog(title string, plt *plotview.PlotView, lg *elog.Logs, key } // Plot returns plot for mode, time scope -func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *plotview.PlotView { +func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *plotcore.PlotEditor { return gui.PlotScope(etime.Scope(mode, time)) } // PlotScope returns plot for given scope -func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotview.PlotView { +func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotcore.PlotEditor { if !gui.Active { return nil } @@ -92,15 +92,15 @@ func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotview.PlotView { } // SetPlot stores given plot in Plots map -func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *plotview.PlotView) { +func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *plotcore.PlotEditor) { if gui.Plots == nil { - gui.Plots = make(map[etime.ScopeKey]*plotview.PlotView) + gui.Plots = make(map[etime.ScopeKey]*plotcore.PlotEditor) } gui.Plots[scope] = plt } // UpdatePlot updates plot for given mode, time scope -func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotview.PlotView { +func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotcore.PlotEditor { plot := gui.Plot(mode, time) if plot != nil { plot.GoUpdatePlot() @@ -109,7 +109,7 @@ func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotview.PlotVie } // UpdatePlotScope updates plot at given scope -func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotview.PlotView { +func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotcore.PlotEditor { plot := gui.PlotScope(scope) if plot != nil { plot.GoUpdatePlot() @@ -119,7 +119,7 @@ func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotview.PlotView { // UpdateCyclePlot updates cycle plot for given mode. // only updates every CycleUpdateInterval -func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotview.PlotView { +func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotcore.PlotEditor { plot := gui.Plot(mode, etime.Cycle) if plot == nil { return plot @@ -133,17 +133,17 @@ func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotview.PlotView // NewPlotTab adds a new plot with given key for Plots lookup // and using given tab label. For ad-hoc plots, you can // construct a ScopeKey from any two strings using etime.ScopeStr. -func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *plotview.PlotView { - plt := plotview.NewSubPlot(gui.Tabs.NewTab(tabLabel)) +func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *plotcore.PlotEditor { + plt := plotcore.NewSubPlot(gui.Tabs.NewTab(tabLabel)) gui.Plots[key] = plt return plt } // AddTableView adds a table view of given log, // typically particularly useful for Debug logs. -func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) *tensorview.TableView { +func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) *tensorcore.Table { if gui.TableViews == nil { - gui.TableViews = make(map[etime.ScopeKey]*tensorview.TableView) + gui.TableViews = make(map[etime.ScopeKey]*tensorcore.Table) } key := etime.Scope(mode, time) @@ -154,7 +154,7 @@ func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) } tt := gui.Tabs.NewTab(mode.String() + " " + time.String() + " ") - tv := tensorview.NewTableView(tt) + tv := tensorcore.NewTableView(tt) gui.TableViews[key] = tv tv.SetReadOnly(true) tv.SetTable(lt.Table) @@ -162,7 +162,7 @@ func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) } // TableView returns TableView for mode, time scope -func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorview.TableView { +func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorcore.Table { if !gui.Active { return nil } @@ -176,7 +176,7 @@ func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorview.TableV } // UpdateTableView updates TableView for given mode, time scope -func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *tensorview.TableView { +func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *tensorcore.Table { tv := gui.TableView(mode, time) if tv != nil { tv.GoUpdateView() diff --git a/elog/README.md b/elog/README.md index 0ca1187f..70a8c80b 100644 --- a/elog/README.md +++ b/elog/README.md @@ -404,7 +404,7 @@ First, initialize the ActRFs in the `ConfigLogs` function, using strings that sp To add tabs in the gui to visualize the resulting RFs, add this in your `ConfigGUI` (note also adding a tab to visualize the input Image that is being presented to the network): ```Go - tg := ss.GUI.TabView.AddNewTab(tensorview.KiT_TensorGrid, "Image").(*tensorview.TensorGrid) + tg := ss.GUI.TabView.AddNewTab(tensorcore.KiT_TensorGrid, "Image").(*tensorcore.TensorGrid) tg.SetStretchMax() ss.GUI.SetGrid("Image", tg) tg.SetTensor(&ss.TrainEnv.Vis.ImgTsr) diff --git a/elog/stditems.go b/elog/stditems.go index 0da1237b..0e6788a3 100644 --- a/elog/stditems.go +++ b/elog/stditems.go @@ -279,7 +279,7 @@ func (lg *Logs) RunStats(stats ...string) { lt := lg.TableDetailsScope(sk) ix, _ := lt.NamedIndexView("RunStats") - spl := split.GroupBy(ix, []string{"RunName"}) + spl := split.GroupBy(ix, "RunName") for _, st := range stats { split.DescColumn(spl, st) } diff --git a/estats/plots.go b/estats/plots.go index 64581e2e..59524561 100644 --- a/estats/plots.go +++ b/estats/plots.go @@ -5,14 +5,14 @@ package estats import ( - "cogentcore.org/core/plot/plotview" + "cogentcore.org/core/plot/plotcore" "cogentcore.org/core/tensor/stats/clust" "cogentcore.org/core/tensor/stats/metric" "cogentcore.org/core/tensor/stats/simat" "cogentcore.org/core/tensor/table" ) -func ConfigPCAPlot(plt *plotview.PlotView, dt *table.Table, nm string) { +func ConfigPCAPlot(plt *plotcore.PlotEditor, dt *table.Table, nm string) { plt.Params.Title = nm col1 := dt.ColumnName(1) plt.Params.XAxisColumn = col1 @@ -20,25 +20,25 @@ func ConfigPCAPlot(plt *plotview.PlotView, dt *table.Table, nm string) { plt.Params.Lines = false plt.Params.Points = true // order of params: on, fixMin, min, fixMax, max - plt.SetColParams(dt.ColumnName(0), plotview.On, plotview.FloatMin, 0, plotview.FloatMax, 0) - plt.SetColParams(col1, plotview.Off, plotview.FloatMin, -3, plotview.FloatMax, 3) - plt.SetColParams(dt.ColumnName(2), plotview.On, plotview.FloatMin, -3, plotview.FloatMax, 3) + plt.SetColParams(dt.ColumnName(0), plotcore.On, plotcore.FloatMin, 0, plotcore.FloatMax, 0) + plt.SetColParams(col1, plotcore.Off, plotcore.FloatMin, -3, plotcore.FloatMax, 3) + plt.SetColParams(dt.ColumnName(2), plotcore.On, plotcore.FloatMin, -3, plotcore.FloatMax, 3) } // ClustPlot does one cluster plot on given table column name // and label name -func ClustPlot(plt *plotview.PlotView, ix *table.IndexView, colNm, lblNm string) { +func ClustPlot(plt *plotcore.PlotEditor, ix *table.IndexView, colNm, lblNm string) { nm, _ := ix.Table.MetaData["name"] smat := &simat.SimMat{} smat.TableCol(ix, colNm, lblNm, false, metric.Euclidean64) pt := &table.Table{} clust.Plot(pt, clust.Glom(smat, clust.ContrastDist), smat) - plt.InitName(plt, colNm) + plt.Name = colNm plt.Params.Title = "Cluster Plot of: " + nm + " " + colNm plt.Params.XAxisColumn = "X" plt.SetTable(pt) // order of params: on, fixMin, min, fixMax, max - plt.SetColParams("X", plotview.Off, plotview.FixMin, 0, plotview.FloatMax, 0) - plt.SetColParams("Y", plotview.On, plotview.FixMin, 0, plotview.FloatMax, 0) - plt.SetColParams("Label", plotview.On, plotview.FixMin, 0, plotview.FloatMax, 0) + plt.SetColParams("X", plotcore.Off, plotcore.FixMin, 0, plotcore.FloatMax, 0) + plt.SetColParams("Y", plotcore.On, plotcore.FixMin, 0, plotcore.FloatMax, 0) + plt.SetColParams("Label", plotcore.On, plotcore.FixMin, 0, plotcore.FloatMax, 0) } diff --git a/estats/stats.go b/estats/stats.go index f5c3e371..d83f90ba 100644 --- a/estats/stats.go +++ b/estats/stats.go @@ -10,7 +10,7 @@ import ( "fmt" "cogentcore.org/core/base/timer" - "cogentcore.org/core/plot/plotview" + "cogentcore.org/core/plot/plotcore" "cogentcore.org/core/tensor" "cogentcore.org/core/tensor/stats/pca" "cogentcore.org/core/tensor/stats/simat" @@ -42,7 +42,7 @@ type Stats struct { SimMats map[string]*simat.SimMat // analysis plots -- created by analysis routines - Plots map[string]*plotview.PlotView + Plots map[string]*plotcore.PlotEditor // one PCA object can be reused for all PCA computations PCA pca.PCA @@ -75,7 +75,7 @@ func (st *Stats) Init() { st.F64Tensors = make(map[string]*tensor.Float64) st.IntTensors = make(map[string]*tensor.Int) st.SimMats = make(map[string]*simat.SimMat) - st.Plots = make(map[string]*plotview.PlotView) + st.Plots = make(map[string]*plotcore.PlotEditor) st.LinDecoders = make(map[string]*decoder.Linear) st.SoftMaxDecoders = make(map[string]*decoder.SoftMax) st.Timers = make(map[string]*timer.Time) @@ -385,12 +385,12 @@ func (st *Stats) SimMat(name string) *simat.SimMat { return sm } -// Plot returns an plotview.PlotView of given name, creating if not yet made -func (st *Stats) Plot(name string) *plotview.PlotView { +// Plot returns an plotcore.PlotEditor of given name, creating if not yet made +func (st *Stats) Plot(name string) *plotcore.PlotEditor { pl, has := st.Plots[name] if !has { - pl = &plotview.PlotView{} - pl.InitName(pl, name) // any Ki obj needs this + pl = plotcore.NewPlotEditor() + pl.Name = name // any Ki obj needs this st.Plots[name] = pl } return pl diff --git a/netview/events.go b/netview/events.go index 46b525e7..7b8db4b7 100644 --- a/netview/events.go +++ b/netview/events.go @@ -8,23 +8,23 @@ import ( "fmt" "image" + "cogentcore.org/core/core" "cogentcore.org/core/events" "cogentcore.org/core/math32" - "cogentcore.org/core/views" "cogentcore.org/core/xyz" - "cogentcore.org/core/xyz/xyzview" + "cogentcore.org/core/xyz/xyzcore" "github.com/emer/emergent/v2/emer" ) // Scene is a Widget for managing the 3D Scene of the NetView type Scene struct { - xyzview.Scene + xyzcore.Scene NetView *NetView } -func (sw *Scene) OnInit() { - sw.Scene.OnInit() +func (sw *Scene) Init() { + sw.Scene.Init() sw.HandleEvents() } @@ -41,7 +41,7 @@ func (sw *Scene) HandleEvents() { sw.SceneXYZ().KeyChordEvent(e) sw.NeedsRender() }) - sw.HandleSlideEvents() + // sw.HandleSlideEvents() // TODO: need this } func (sw *Scene) MouseDownEvent(e events.Event) { @@ -52,7 +52,7 @@ func (sw *Scene) MouseDownEvent(e events.Event) { if ok { lay := ln.NetView.Net.LayerByName(ln.Text) if lay != nil { - views.StructViewDialog(sw, lay, "Layer: "+lay.Name(), true) + core.FormDialog(sw, lay, "Layer: "+lay.Name(), true) } e.SetHandled() return @@ -110,10 +110,11 @@ func (sw *Scene) WidgetTooltip(pos image.Point) (string, image.Point) { func (sw *Scene) LayerUnitAtPoint(pos image.Point) (lay emer.Layer, lx, ly, unIndex int) { pos = pos.Sub(sw.Geom.ContentBBox.Min) sc := sw.SceneXYZ() - laysGp := sc.ChildByName("Layers", 0) - if laysGp == nil { + laysGpi := sc.ChildByName("Layers", 0) + if laysGpi == nil { return } + _, laysGp := xyz.AsNode(laysGpi) nv := sw.NetView nmin, nmax := nv.Net.Bounds() nsz := nmax.Sub(nmin).Sub(math32.Vec3(1, 1, 0)).Max(math32.Vec3(1, 1, 1)) @@ -121,7 +122,7 @@ func (sw *Scene) LayerUnitAtPoint(pos image.Point) (lay emer.Layer, lx, ly, unIn szc := math32.Max(nsc.X, nsc.Y) poff := math32.Vector3Scalar(0.5) poff.Y = -0.5 - for li, lgi := range *laysGp.Children() { + for li, lgi := range laysGp.Children { lay = nv.Net.Layer(li) lg := lgi.(*xyz.Group) lp := lay.Pos() diff --git a/netview/laymesh.go b/netview/laymesh.go index 18f6e5a9..09d4c248 100644 --- a/netview/laymesh.go +++ b/netview/laymesh.go @@ -35,15 +35,15 @@ func NewLayMesh(sc *xyz.Scene, nv *NetView, lay emer.Layer) *LayMesh { lm := &LayMesh{} lm.View = nv lm.Lay = lay - lm.Nm = lay.Name() + lm.Name = lay.Name() sc.AddMesh(lm) return lm } func (lm *LayMesh) Sizes() (nVtx, nIndex int, hasColor bool) { - lm.Trans = true + lm.Transparent = true lm.Dynamic = true - lm.Color = true + lm.HasColor = true if lm.Lay == nil { return 0, 0, true } @@ -51,18 +51,18 @@ func (lm *LayMesh) Sizes() (nVtx, nIndex int, hasColor bool) { lm.Shape.CopyShape(shp) if lm.View.Params.Raster.On { if shp.NumDims() == 4 { - lm.NVtx, lm.NIndex = lm.RasterSize4D() + lm.NumVertex, lm.NumIndex = lm.RasterSize4D() } else { - lm.NVtx, lm.NIndex = lm.RasterSize2D() + lm.NumVertex, lm.NumIndex = lm.RasterSize2D() } } else { if shp.NumDims() == 4 { - lm.NVtx, lm.NIndex = lm.Size4D() + lm.NumVertex, lm.NumIndex = lm.Size4D() } else { - lm.NVtx, lm.NIndex = lm.Size2D() + lm.NumVertex, lm.NumIndex = lm.Size2D() } } - return lm.NVtx, lm.NIndex, lm.Color + return lm.NumVertex, lm.NumIndex, lm.HasColor } func (lm *LayMesh) Size2D() (nVtx, nIndex int) { @@ -202,9 +202,7 @@ func (lm *LayMesh) Set2D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA } lm.View.ReadUnlock() - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) - lm.BBoxMu.Unlock() } func (lm *LayMesh) Set4D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32) { @@ -273,7 +271,5 @@ func (lm *LayMesh) Set4D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA } lm.View.ReadUnlock() - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpz*fnuz), math32.Vec3(fnpx*fnux, 0.5, 0)) - lm.BBoxMu.Unlock() } diff --git a/netview/layraster.go b/netview/layraster.go index 2a9993f4..928814c6 100644 --- a/netview/layraster.go +++ b/netview/layraster.go @@ -120,9 +120,7 @@ func (lm *LayMesh) RasterSet2DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr } lm.View.ReadUnlock() - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) - lm.BBoxMu.Unlock() } func (lm *LayMesh) RasterSet2DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32) { @@ -202,10 +200,7 @@ func (lm *LayMesh) RasterSet2DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr } } lm.View.ReadUnlock() - - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) - lm.BBoxMu.Unlock() } func (lm *LayMesh) RasterSet4DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32) { @@ -306,10 +301,7 @@ func (lm *LayMesh) RasterSet4DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr } } lm.View.ReadUnlock() - - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpoz*fnuz), math32.Vec3(fnpox*fnux, 0.5, 0)) - lm.BBoxMu.Unlock() } func (lm *LayMesh) RasterSet4DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32) { @@ -410,8 +402,5 @@ func (lm *LayMesh) RasterSet4DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr } } lm.View.ReadUnlock() - - lm.BBoxMu.Lock() lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpoz*fnuz), math32.Vec3(fnpox*fnux, 0.5, 0)) - lm.BBoxMu.Unlock() } diff --git a/netview/netdata.go b/netview/netdata.go index cf3aed3f..cec93b2a 100644 --- a/netview/netdata.go +++ b/netview/netdata.go @@ -19,7 +19,7 @@ import ( "cogentcore.org/core/core" "cogentcore.org/core/math32" - "cogentcore.org/core/plot/plotview" + "cogentcore.org/core/plot/plotcore" "cogentcore.org/core/tensor/table" "github.com/emer/emergent/v2/emer" "github.com/emer/emergent/v2/ringidx" @@ -624,7 +624,7 @@ func (nd *NetData) WriteJSON(w io.Writer) error { // PlotSelectedUnit opens a window with a plot of all the data for the // currently selected unit. // Useful for replaying detailed trace for units of interest. -func (nv *NetView) PlotSelectedUnit() (*table.Table, *plotview.PlotView) { //types:add +func (nv *NetView) PlotSelectedUnit() (*table.Table, *plotcore.PlotEditor) { //types:add nd := &nv.Data if nd.PathLay == "" || nd.PathUnIndex < 0 { fmt.Printf("NetView:PlotSelectedUnit -- no unit selected\n") @@ -634,11 +634,11 @@ func (nv *NetView) PlotSelectedUnit() (*table.Table, *plotview.PlotView) { //typ selnm := nd.PathLay + fmt.Sprintf("[%d]", nd.PathUnIndex) b := core.NewBody("netview-selectedunit").SetTitle("NetView SelectedUnit Plot: " + selnm) - plt := plotview.NewPlotView(b) + plt := plotcore.NewPlotEditor(b) plt.Params.Title = "NetView " + selnm plt.Params.XAxisColumn = "Rec" - b.AddAppBar(plt.ConfigToolbar) + b.AddAppBar(plt.MakeToolbar) dt := nd.SelectedUnitTable(nv.Di) plt.SetTable(dt) diff --git a/netview/netview.go b/netview/netview.go index 141b9d78..7ecbc573 100644 --- a/netview/netview.go +++ b/netview/netview.go @@ -29,7 +29,6 @@ import ( "cogentcore.org/core/styles/abilities" "cogentcore.org/core/texteditor" "cogentcore.org/core/tree" - "cogentcore.org/core/views" "cogentcore.org/core/xyz" "github.com/emer/emergent/v2/emer" ) @@ -37,7 +36,7 @@ import ( // NetView is a Cogent Core Widget that provides a 3D network view using the Cogent Core gi3d // 3D framework. type NetView struct { - core.Layout + core.Frame // the network that we're viewing Net emer.Network `set:"-"` @@ -70,7 +69,7 @@ type NetView struct { ColorMap *colormap.Map // color map value representing ColorMap - ColorMapVal *views.ColorMapValue + ColorMapButton *core.ColorMapButton // record number to display -- use -1 to always track latest, otherwise in range RecNo int @@ -85,16 +84,49 @@ type NetView struct { DataMu sync.RWMutex `view:"-" copier:"-" json:"-" xml:"-"` } -func (nv *NetView) OnInit() { - nv.Layout.OnInit() +func (nv *NetView) Init() { + nv.Frame.Init() nv.Params.NetView = nv nv.Params.Defaults() nv.ColorMap = colormap.AvailableMaps[string(nv.Params.ColorMap)] nv.RecNo = -1 - nv.Style(func(s *styles.Style) { + nv.Styler(func(s *styles.Style) { s.Direction = styles.Column s.Grow.Set(1, 1) }) + + core.AddChildAt(nv, "tbar", func(w *core.Toolbar) { + nv.ConfigToolbar(w) + }) + core.AddChildAt(nv, "nframe", func(w *core.Frame) { + w.Styler(func(s *styles.Style) { + s.Direction = styles.Row + s.Grow.Set(1, 1) + }) + core.AddChildAt(w, "vars", func(w *core.Frame) { + w.Styler(func(s *styles.Style) { + s.Display = styles.Grid + s.Columns = nv.Params.NVarCols + s.Grow.Set(0, 1) + s.Overflow.Y = styles.OverflowAuto + s.Background = colors.C(colors.Scheme.SurfaceContainerLow) + }) + w.Maker(nv.makeVars) + }) + core.AddChildAt(w, "scene", func(w *Scene) { + w.NetView = nv + nv.ViewConfig() + }) + }) + core.AddChildAt(nv, "counters", func(w *core.Text) { + w.SetText("Counters: " + strings.Repeat(" ", 200)) + }) + core.AddChildAt(nv, "vbar", func(w *core.Toolbar) { + nv.ConfigViewbar(w) + }) + + nv.Data.Init(nv.Net, nv.Params.MaxRecs, nv.Params.NoSynData, nv.Net.MaxParallelData()) + nv.ReconfigMeshes() } // SetNet sets the network to view and updates view @@ -178,7 +210,7 @@ func (nv *NetView) GoUpdateView() { sc := sw.SceneXYZ() sw.Scene.AsyncLock() nv.UpdateImpl() - sc.NeedsRender() + sc.NeedsRender = true sw.Scene.AsyncUnlock() } @@ -189,7 +221,7 @@ func (nv *NetView) UpdateView() { } sw := nv.SceneWidget() nv.UpdateImpl() - sw.XYZ.NeedsRender() + sw.XYZ.NeedsRender = true sw.NeedsRender() } @@ -209,7 +241,7 @@ func (nv *NetView) UpdateImpl() { vp, ok := nv.VarParams[nv.Var] if !ok { nv.DataMu.Unlock() - log.Printf("NetView: %v variable: %v not found\n", nv.Nm, nv.Var) + log.Printf("NetView: %v variable: %v not found\n", nv.Name, nv.Var) return } nv.CurVarParams = vp @@ -251,53 +283,44 @@ func (nv *NetView) UpdateImpl() { } se := nv.SceneXYZ() - laysGp := se.ChildByName("Layers", 0) - if laysGp == nil || laysGp.NumChildren() != nv.Net.NLayers() { - nv.ConfigNetView() - } + // laysGp := se.ChildByName("Layers", 0).AsTree() + // if laysGp == nil || laysGp.NumChildren() != nv.Net.NLayers() { + // nv.ConfigNetView() + // } nv.SetCounters(nv.Data.CounterRec(nv.RecNo)) nv.UpdateRecNo() nv.DataMu.Unlock() se.UpdateMeshes() } -func (nv *NetView) Config() { - nv.ConfigNetView() -} - +/* // ConfigNetView configures the overall view widget func (nv *NetView) ConfigNetView() { - cmap, ok := colormap.AvailableMaps[string(nv.Params.ColorMap)] - if ok { - nv.ColorMap = cmap - } else { - log.Printf("NetView: %v ColorMap named: %v not found in colormap.AvailMaps\n", nv.Nm, nv.Params.ColorMap) - } - if !nv.HasChildren() { - tb := core.NewToolbar(nv, "tbar") - nlay := core.NewLayout(nv, "net") - nlay.Style(func(s *styles.Style) { - s.Direction = styles.Row - s.Grow.Set(1, 1) - }) - core.NewText(nv, "counters").SetText(strings.Repeat(" ", 200)) - vb := core.NewToolbar(nv, "vbar") - - vlay := core.NewFrame(nlay, "vars") - vlay.Style(func(s *styles.Style) { - s.Display = styles.Grid - s.Columns = nv.Params.NVarCols - s.Grow.Set(0, 1) - s.Overflow.Y = styles.OverflowAuto - s.Background = colors.C(colors.Scheme.SurfaceContainerLow) - }) + tb := core.NewToolbar(nv) + tb.SetName("tbar") + nlay := core.NewFrame(nv) + nlay.SetName("net") + nlay.Styler(func(s *styles.Style) { + s.Direction = styles.Row + s.Grow.Set(1, 1) + }) + core.NewText(nv).SetName("counters").SetText(strings.Repeat(" ", 200)) + vb := core.NewToolbar(nv, "vbar") + + vlay := core.NewFrame(nlay, "vars") + vlay.Styler(func(s *styles.Style) { + s.Display = styles.Grid + s.Columns = nv.Params.NVarCols + s.Grow.Set(0, 1) + s.Overflow.Y = styles.OverflowAuto + s.Background = colors.C(colors.Scheme.SurfaceContainerLow) + }) - sw := NewScene(nlay, "scene") - sw.NetView = nv + sw := NewScene(nlay, "scene") + sw.NetView = nv - nv.ConfigToolbar(tb) - nv.ConfigViewbar(vb) - } + nv.ConfigToolbar(tb) + nv.ConfigViewbar(vb) nv.VarsConfig() nv.ViewConfig() @@ -311,21 +334,22 @@ func (nv *NetView) ConfigNetView() { nv.ReconfigMeshes() nv.NeedsLayout() } +*/ // ReconfigMeshes reconfigures the layer meshes func (nv *NetView) ReconfigMeshes() { se := nv.SceneXYZ() - if se.IsConfiged() { - se.ReconfigMeshes() - } + // if se.IsConfiged() { + se.ReconfigMeshes() + // } } func (nv *NetView) Toolbar() *core.Toolbar { return nv.ChildByName("tbar", 0).(*core.Toolbar) } -func (nv *NetView) NetLay() *core.Layout { - return nv.ChildByName("net", 1).(*core.Layout) +func (nv *NetView) NetLay() *core.Frame { + return nv.ChildByName("net", 1).(*core.Frame) } func (nv *NetView) Counters() *core.Text { @@ -510,11 +534,11 @@ func (nv *NetView) VarsListUpdate() { // and the view range state too func (nv *NetView) VarsUpdate() { vl := nv.VarsLay() - for _, vbi := range *vl.Children() { + for _, vbi := range vl.Children { vb := vbi.(*core.Button) vb.SetSelected(vb.Text == nv.Var) } - nv.ColorMapVal.Update() + nv.ColorMapButton.Update() vl.NeedsRender() } @@ -572,37 +596,30 @@ func (nv *NetView) VarScaleUpdate(varNm string) bool { return mod } -// VarsConfig configures the variables -func (nv *NetView) VarsConfig() { - vl := nv.VarsLay() +// makeVars configures the variables +func (nv *NetView) makeVars(p *core.Plan) { nv.VarsListUpdate() - if len(nv.Vars) == 0 { - vl.DeleteChildren() - return - } - if len(vl.Kids) == len(nv.Vars) { - return - } unprops := nv.Net.UnitVarProps() pathprops := nv.Net.SynVarProps() for _, vn := range nv.Vars { - vn := vn - vb := core.NewButton(vl).SetText(vn).SetType(core.ButtonAction) - pstr := "" - if strings.HasPrefix(vn, "r.") || strings.HasPrefix(vn, "s.") { - pstr = pathprops[vn[2:]] - } else { - pstr = unprops[vn] - } - if pstr != "" { - rstr := reflect.StructTag(pstr) - if desc, ok := rstr.Lookup("desc"); ok { - vb.Tooltip = vn + ": " + desc + core.AddAt(p, vn, func(w *core.Button) { + w.SetText(vn).SetType(core.ButtonAction) + pstr := "" + if strings.HasPrefix(vn, "r.") || strings.HasPrefix(vn, "s.") { + pstr = pathprops[vn[2:]] + } else { + pstr = unprops[vn] } - } - vb.SetSelected(vn == nv.Var) - vb.OnClick(func(e events.Event) { - nv.SetVar(vn) + if pstr != "" { + rstr := reflect.StructTag(pstr) + if desc, ok := rstr.Lookup("desc"); ok { + w.Tooltip = vn + ": " + desc + } + } + w.SetSelected(vn == nv.Var) + w.OnClick(func(e events.Event) { + nv.SetVar(vn) + }) }) } } @@ -623,11 +640,15 @@ func (nv *NetView) ViewConfig() { // todo: // vs.BgColor = core.Prefs.Colors.Background // reset in case user changes nlay := nv.Net.NLayers() - laysGp := se.ChildByName("Layers", 0) - if laysGp == nil { - laysGp = xyz.NewGroup(se, "Layers") + laysGpi := se.ChildByName("Layers", 0) + var laysGp *xyz.Group + if laysGpi == nil { + laysGp = xyz.NewGroup(se) + laysGp.Name = "Layers" + } else { + laysGp = laysGpi.(*xyz.Group) } - layConfig := tree.Config{} + layConfig := tree.TypePlan{} for li := 0; li < nlay; li++ { lay := nv.Net.Layer(li) lmesh := se.MeshByName(lay.Name()) @@ -638,11 +659,11 @@ func (nv *NetView) ViewConfig() { } layConfig.Add(xyz.GroupType, lay.Name()) } - gpConfig := tree.Config{} + gpConfig := tree.TypePlan{} gpConfig.Add(LayObjType, "layer") gpConfig.Add(LayNameType, "name") - laysGp.ConfigChildren(layConfig) + tree.Update(laysGp, layConfig) nmin, nmax := nv.Net.Bounds() nsz := nmax.Sub(nmin).Sub(math32.Vec3(1, 1, 0)).Max(math32.Vec3(1, 1, 1)) @@ -650,10 +671,10 @@ func (nv *NetView) ViewConfig() { szc := math32.Max(nsc.X, nsc.Y) poff := math32.Vector3Scalar(0.5) poff.Y = -0.5 - for li, lgi := range *laysGp.Children() { + for li, lgi := range laysGp.Children { ly := nv.Net.Layer(li) lg := lgi.(*xyz.Group) - lg.ConfigChildren(gpConfig) // won't do update b/c of above + tree.Update(lg, gpConfig) lp := ly.Pos() lp.Y = -lp.Y // reverse direction lp = lp.Sub(nmin).Mul(nsc).Sub(poff) @@ -666,15 +687,15 @@ func (nv *NetView) ViewConfig() { lo.LayName = ly.Name() lo.NetView = nv lo.SetMeshName(ly.Name()) - lo.Mat.Color = colors.FromRGB(255, 100, 255) - lo.Mat.Reflective = 8 - lo.Mat.Bright = 8 - lo.Mat.Shiny = 30 + lo.Material.Color = colors.FromRGB(255, 100, 255) + lo.Material.Reflective = 8 + lo.Material.Bright = 8 + lo.Material.Shiny = 30 // note: would actually be better to NOT cull back so you can view underneath // but then the front and back fight against each other, causing flickering txt := lg.Child(1).(*LayName) - txt.Nm = "layname:" + ly.Name() + txt.Name = "layname:" + ly.Name() txt.Defaults() txt.NetView = nv txt.SetText(ly.Name()) @@ -683,7 +704,7 @@ func (nv *NetView) ViewConfig() { txt.Styles.Text.Align = styles.Start txt.Styles.Text.AlignV = styles.Start } - sw.XYZ.NeedsConfig() + sw.XYZ.NeedsConfig = true sw.NeedsRender() } @@ -792,6 +813,15 @@ func (nv *NetView) UnitValColor(lay emer.Layer, idx1d int, raw float32, hasval b return } +func (nv *NetView) Labels() *xyz.Group { + se := nv.SceneXYZ() + lgpi := se.ChildByName("Labels", 1) + if lgpi == nil { + return nil + } + return lgpi.(*xyz.Group) +} + // ConfigLabels ensures that given label xyz.Text2D objects are created and initialized // in a top-level group called Labels. Use LabelByName() to get a given label, and // LayerByName() to get a Layer group, whose Pose can be copied to put a label in @@ -799,16 +829,17 @@ func (nv *NetView) UnitValColor(lay emer.Layer, idx1d int, raw float32, hasval b // Returns true set of labels was changed (mods). func (nv *NetView) ConfigLabels(labs []string) bool { se := nv.SceneXYZ() - lgp := se.ChildByName("Labels", 1) + lgp := nv.Labels() if lgp == nil { - lgp = xyz.NewGroup(se, "Labels") + lgp = xyz.NewGroup(se) + lgp.Name = "Labels" } - lbConfig := tree.Config{} + lbConfig := tree.TypePlan{} for _, ls := range labs { lbConfig.Add(xyz.Text2DType, ls) } - if lgp.ConfigChildren(lbConfig) { + if tree.Update(lgp, lbConfig) { for i, ls := range labs { lb := lgp.ChildByName(ls, i).(*xyz.Text2D) // lb.Defaults() @@ -826,11 +857,7 @@ func (nv *NetView) ConfigLabels(labs []string) bool { // LabelByName returns given Text2D label (see ConfigLabels). // nil if not found. func (nv *NetView) LabelByName(lab string) *xyz.Text2D { - se := nv.SceneXYZ() - lgp := se.ChildByName("Labels", 1) - if lgp == nil { - return nil - } + lgp := nv.Labels() txt := lgp.ChildByName(lab, 0) if txt == nil { return nil @@ -841,11 +868,7 @@ func (nv *NetView) LabelByName(lab string) *xyz.Text2D { // LayerByName returns the xyz.Group that represents layer of given name. // nil if not found. func (nv *NetView) LayerByName(lay string) *xyz.Group { - se := nv.SceneXYZ() - lgp := se.ChildByName("Layers", 0) - if lgp == nil { - return nil - } + lgp := nv.Labels() ly := lgp.ChildByName(lay, 0) if ly == nil { return nil @@ -854,36 +877,39 @@ func (nv *NetView) LayerByName(lay string) *xyz.Group { } func (nv *NetView) ConfigToolbar(tb *core.Toolbar) { - views.NewFuncButton(tb, nv.Update).SetText("Init").SetIcon(icons.Update) - views.NewFuncButton(tb, nv.Current).SetIcon(icons.Update) + core.NewFuncButton(tb, nv.Update).SetText("Init").SetIcon(icons.Update) + core.NewFuncButton(tb, nv.Current).SetIcon(icons.Update) core.NewButton(tb).SetText("Config").SetIcon(icons.Settings). SetTooltip("set parameters that control display (font size etc)"). OnClick(func(e events.Event) { - views.StructViewDialog(nv, &nv.Params, nv.Nm+" Params", true) + core.FormDialog(nv, &nv.Params, nv.Name+" Params", true) }) core.NewSeparator(tb) core.NewButton(tb).SetText("Weights").SetType(core.ButtonAction).SetMenu(func(m *core.Scene) { - fb := views.NewFuncButton(m, nv.SaveWeights).SetIcon(icons.Save) - fb.Args[0].SetTag("ext", ".wts,.wts.gz") - fb = views.NewFuncButton(m, nv.OpenWeights).SetIcon(icons.Open) - fb.Args[0].SetTag("ext", ".wts,.wts.gz") + fb := core.NewFuncButton(m, nv.SaveWeights) + fb.SetIcon(icons.Save) + fb.Args[0].SetTag(`"ext:".wts,.wts.gz"`) + fb = core.NewFuncButton(m, nv.OpenWeights) + fb.SetIcon(icons.Open) + fb.Args[0].SetTag(`"ext:".wts,.wts.gz"`) }) core.NewButton(tb).SetText("Params").SetIcon(icons.Info).SetMenu(func(m *core.Scene) { - views.NewFuncButton(m, nv.ShowNonDefaultParams).SetIcon(icons.Info) - views.NewFuncButton(m, nv.ShowAllParams).SetIcon(icons.Info) - views.NewFuncButton(m, nv.ShowKeyLayerParams).SetIcon(icons.Info) - views.NewFuncButton(m, nv.ShowKeyPathParams).SetIcon(icons.Info) + core.NewFuncButton(m, nv.ShowNonDefaultParams).SetIcon(icons.Info) + core.NewFuncButton(m, nv.ShowAllParams).SetIcon(icons.Info) + core.NewFuncButton(m, nv.ShowKeyLayerParams).SetIcon(icons.Info) + core.NewFuncButton(m, nv.ShowKeyPathParams).SetIcon(icons.Info) }) core.NewButton(tb).SetText("Net Data").SetIcon(icons.Save).SetMenu(func(m *core.Scene) { - views.NewFuncButton(m, nv.Data.SaveJSON).SetText("Save Net Data").SetIcon(icons.Save) - views.NewFuncButton(m, nv.Data.OpenJSON).SetText("Open Net Data").SetIcon(icons.Open) + core.NewFuncButton(m, nv.Data.SaveJSON).SetText("Save Net Data").SetIcon(icons.Save) + core.NewFuncButton(m, nv.Data.OpenJSON).SetText("Open Net Data").SetIcon(icons.Open) core.NewSeparator(m) - views.NewFuncButton(m, nv.PlotSelectedUnit).SetIcon(icons.Open) + core.NewFuncButton(m, nv.PlotSelectedUnit).SetIcon(icons.Open) }) core.NewSeparator(tb) ditp := "data parallel index -- for models running multiple input patterns in parallel, this selects which one is viewed" core.NewText(tb).SetText("Di:").SetTooltip(ditp) - dis := core.NewSpinner(tb).SetTooltip(ditp).SetMin(0).SetStep(1).SetValue(float32(nv.Di)) + dis := core.NewSpinner(tb) + dis.SetMin(0).SetStep(1).SetValue(float32(nv.Di)).SetTooltip(ditp) dis.OnChange(func(e events.Event) { maxData := nv.Net.MaxParallelData() md := int(dis.Value) @@ -894,21 +920,21 @@ func (nv *NetView) ConfigToolbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewSeparator(tb) - rchk := core.NewSwitch(tb).SetText("Raster"). - SetTooltip("Toggles raster plot mode -- displays values on one axis (Z by default) and raster counter (time) along the other (X by default)"). - SetChecked(nv.Params.Raster.On) + rchk := core.NewSwitch(tb) + rchk.SetText("Raster").SetChecked(nv.Params.Raster.On). + SetTooltip("Toggles raster plot mode -- displays values on one axis (Z by default) and raster counter (time) along the other (X by default)") rchk.OnChange(func(e events.Event) { nv.Params.Raster.On = rchk.IsChecked() nv.ReconfigMeshes() nv.UpdateView() }) - xchk := core.NewSwitch(tb).SetText("X").SetType(core.SwitchCheckbox). + xchk := core.NewSwitch(tb) + xchk.SetText("X").SetType(core.SwitchCheckbox).SetChecked(nv.Params.Raster.XAxis). SetTooltip("If checked, the raster (time) dimension is plotted along the X (horizontal) axis of the layers, otherwise it goes in the depth (Z) dimension"). - SetChecked(nv.Params.Raster.XAxis) - xchk.OnChange(func(e events.Event) { - nv.Params.Raster.XAxis = xchk.IsChecked() - nv.UpdateView() - }) + OnChange(func(e events.Event) { + nv.Params.Raster.XAxis = xchk.IsChecked() + nv.UpdateView() + }) vp, ok := nv.VarParams[nv.Var] if !ok { @@ -917,53 +943,58 @@ func (nv *NetView) ConfigToolbar(tb *core.Toolbar) { } core.NewSeparator(tb) - mnsw := core.NewSwitch(tb, "mnsw").SetText("Min").SetType(core.SwitchCheckbox). - SetTooltip("Fix the minimum end of the displayed value range to value shown in next box. Having both min and max fixed is recommended where possible for speed and consistent interpretability of the colors."). - SetChecked(vp.Range.FixMin) - mnsw.OnChange(func(e events.Event) { + mnsw := core.NewSwitch(tb) + mnsw.Name = "mnsw" + mnsw.SetText("Min").SetType(core.SwitchCheckbox).SetChecked(vp.Range.FixMin). + SetTooltip("Fix the minimum end of the displayed value range to value shown in next box. Having both min and max fixed is recommended where possible for speed and consistent interpretability of the colors.").OnChange(func(e events.Event) { vp := nv.VarParams[nv.Var] vp.Range.FixMin = mnsw.IsChecked() nv.VarScaleUpdate(nv.Var) // todo: before update? nv.UpdateView() }) - mnsp := core.NewSpinner(tb, "mnsp").SetValue(vp.Range.Min) - mnsp.OnChange(func(e events.Event) { - vp := nv.VarParams[nv.Var] - vp.Range.SetMin(mnsp.Value) - if vp.ZeroCtr && vp.Range.Min < 0 && vp.Range.FixMax { - vp.Range.SetMax(-vp.Range.Min) - } - nv.VarScaleUpdate(nv.Var) - nv.UpdateView() - }) + mnsp := core.NewSpinner(tb) + mnsp.Name = "mnsp" + mnsp.SetValue(vp.Range.Min). + OnChange(func(e events.Event) { + vp := nv.VarParams[nv.Var] + vp.Range.SetMin(mnsp.Value) + if vp.ZeroCtr && vp.Range.Min < 0 && vp.Range.FixMax { + vp.Range.SetMax(-vp.Range.Min) + } + nv.VarScaleUpdate(nv.Var) + nv.UpdateView() + }) - nv.ColorMapVal = views.NewValue(tb, &nv.Params.ColorMap, "cmap").(*views.ColorMapValue) - cmap := nv.ColorMapVal.AsWidget() - cmap.AsWidget().SetTooltip("Color map for translating values into colors -- click to select alternative."). - Style(func(s *styles.Style) { + cmb := core.NewColorMapButton(tb) + nv.ColorMapButton = cmb + cmb.MapName = string(nv.Params.ColorMap) + cmb.Name = "cmap" + cmb.SetTooltip("Color map for translating values into colors -- click to select alternative."). + Styler(func(s *styles.Style) { s.Min.X.Em(10) s.Min.Y.Em(1.2) s.Grow.Set(0, 1) - }) - nv.ColorMapVal.OnChange(func(e events.Event) { - cmap, ok := colormap.AvailableMaps[string(nv.Params.ColorMap)] + }).OnChange(func(e events.Event) { + cmap, ok := colormap.AvailableMaps[string(nv.ColorMapButton.MapName)] if ok { nv.ColorMap = cmap } nv.UpdateView() }) - mxsw := core.NewSwitch(tb, "mxsw").SetText("Max").SetType(core.SwitchCheckbox). + mxsw := core.NewSwitch(tb) + mxsw.Name = "mxsw" + mxsw.SetText("Max").SetType(core.SwitchCheckbox).SetChecked(vp.Range.FixMax). SetTooltip("Fix the maximum end of the displayed value range to value shown in next box. Having both min and max fixed is recommended where possible for speed and consistent interpretability of the colors."). - SetChecked(vp.Range.FixMax) - mxsw.OnChange(func(e events.Event) { - vp := nv.VarParams[nv.Var] - vp.Range.FixMax = mxsw.IsChecked() - nv.VarScaleUpdate(nv.Var) - nv.UpdateView() - }) - mxsp := core.NewSpinner(tb, "mxsp").SetValue(vp.Range.Max) - mxsp.OnChange(func(e events.Event) { + OnChange(func(e events.Event) { + vp := nv.VarParams[nv.Var] + vp.Range.FixMax = mxsw.IsChecked() + nv.VarScaleUpdate(nv.Var) + nv.UpdateView() + }) + mxsp := core.NewSpinner(tb) + mxsp.Name = "mxsp" + mxsp.SetValue(vp.Range.Max).OnChange(func(e events.Event) { vp := nv.VarParams[nv.Var] vp.Range.SetMax(mxsp.Value) if vp.ZeroCtr && vp.Range.Max > 0 && vp.Range.FixMin { @@ -972,15 +1003,16 @@ func (nv *NetView) ConfigToolbar(tb *core.Toolbar) { nv.VarScaleUpdate(nv.Var) nv.UpdateView() }) - zcsw := core.NewSwitch(tb, "zcsw").SetText("ZeroCtr"). + zcsw := core.NewSwitch(tb) + zcsw.Name = "zcsw" + zcsw.SetText("ZeroCtr").SetChecked(vp.ZeroCtr). SetTooltip("keep Min - Max centered around 0, and use negative heights for units -- else use full min-max range for height (no negative heights)"). - SetChecked(vp.ZeroCtr) - zcsw.OnChange(func(e events.Event) { - vp := nv.VarParams[nv.Var] - vp.ZeroCtr = zcsw.IsChecked() - nv.VarScaleUpdate(nv.Var) - nv.UpdateView() - }) + OnChange(func(e events.Event) { + vp := nv.VarParams[nv.Var] + vp.ZeroCtr = zcsw.IsChecked() + nv.VarScaleUpdate(nv.Var) + nv.UpdateView() + }) } func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { @@ -990,7 +1022,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.ZoomIn).SetTooltip("zoom in"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -998,7 +1030,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.ZoomOut).SetTooltip("zoom out"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1008,7 +1040,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { core.NewSeparator(tb) core.NewText(tb).SetText("Rot:").SetTooltip("rotate display") core.NewButton(tb).SetIcon(icons.KeyboardArrowLeft). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1016,7 +1048,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowUp). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1024,7 +1056,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowDown). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1032,7 +1064,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowRight). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1043,7 +1075,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { core.NewText(tb).SetText("Pan:").SetTooltip("pan display") core.NewButton(tb).SetIcon(icons.KeyboardArrowLeft). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1051,7 +1083,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowUp). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1059,7 +1091,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowDown). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1067,7 +1099,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { nv.UpdateView() }) core.NewButton(tb).SetIcon(icons.KeyboardArrowRight). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1102,8 +1134,9 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { core.NewText(tb).SetText("Time:"). SetTooltip("states are recorded over time -- last N can be reviewed using these buttons") - core.NewText(tb, "rec").SetText(fmt.Sprintf("%4d ", nv.RecNo)). - SetTooltip("current view record: -1 means latest, 0 = earliest") + rec := core.NewText(tb).SetText(fmt.Sprintf("%4d ", nv.RecNo)) + rec.Name = "rec" + rec.SetTooltip("current view record: -1 means latest, 0 = earliest") core.NewButton(tb).SetIcon(icons.FirstPage).SetTooltip("move to first record (start of history)"). OnClick(func(e events.Event) { if nv.RecFullBkwd() { @@ -1111,7 +1144,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { } }) core.NewButton(tb).SetIcon(icons.FastRewind).SetTooltip("move earlier by N records (default 10)"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1120,7 +1153,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { } }) core.NewButton(tb).SetIcon(icons.SkipPrevious).SetTooltip("move earlier by 1"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1135,7 +1168,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { } }) core.NewButton(tb).SetIcon(icons.SkipNext).SetTooltip("move later by 1"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1144,7 +1177,7 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { } }) core.NewButton(tb).SetIcon(icons.FastForward).SetTooltip("move later by N (default 10)"). - Style(func(s *styles.Style) { + Styler(func(s *styles.Style) { s.SetAbilities(true, abilities.RepeatClickable) }). OnClick(func(e events.Event) { @@ -1160,14 +1193,12 @@ func (nv *NetView) ConfigViewbar(tb *core.Toolbar) { }) } -// SaveWeights saves the network weights -- when called with views.CallMethod -// it will auto-prompt for filename +// SaveWeights saves the network weights. func (nv *NetView) SaveWeights(filename core.Filename) { //types:add nv.Net.SaveWtsJSON(filename) } -// OpenWeights opens the network weights -- when called with views.CallMethod -// it will auto-prompt for filename +// OpenWeights opens the network weights. func (nv *NetView) OpenWeights(filename core.Filename) { //types:add nv.Net.OpenWtsJSON(filename) } @@ -1176,14 +1207,14 @@ func (nv *NetView) OpenWeights(filename core.Filename) { //types:add // are not at their default values in the network. Useful for setting params. func (nv *NetView) ShowNonDefaultParams() string { //types:add nds := nv.Net.NonDefaultParams() - texteditor.TextDialog(nv, "Non Default Params: "+nv.Nm, nds) + texteditor.TextDialog(nv, "Non Default Params: "+nv.Name, nds) return nds } // ShowAllParams shows a dialog of all the parameters in the network. func (nv *NetView) ShowAllParams() string { //types:add nds := nv.Net.AllParams() - texteditor.TextDialog(nv, "All Params: "+nv.Nm, nds) + texteditor.TextDialog(nv, "All Params: "+nv.Name, nds) return nds } @@ -1191,7 +1222,7 @@ func (nv *NetView) ShowAllParams() string { //types:add // of the most important layer-level params (specific to each algorithm) func (nv *NetView) ShowKeyLayerParams() string { //types:add nds := nv.Net.KeyLayerParams() - texteditor.TextDialog(nv, "Key Layer Params: "+nv.Nm, nds) + texteditor.TextDialog(nv, "Key Layer Params: "+nv.Name, nds) return nds } @@ -1199,6 +1230,6 @@ func (nv *NetView) ShowKeyLayerParams() string { //types:add // of the most important pathway-level params (specific to each algorithm) func (nv *NetView) ShowKeyPathParams() string { //types:add nds := nv.Net.KeyPathParams() - texteditor.TextDialog(nv, "Key Path Params: "+nv.Nm, nds) + texteditor.TextDialog(nv, "Key Path Params: "+nv.Name, nds) return nds } diff --git a/netview/params.go b/netview/params.go index f8bb708e..9ce003c0 100644 --- a/netview/params.go +++ b/netview/params.go @@ -9,8 +9,8 @@ import ( "reflect" "strconv" + "cogentcore.org/core/core" "cogentcore.org/core/math32/minmax" - "cogentcore.org/core/views" ) // NVarCols is the default number of variable columns in the NetView @@ -72,7 +72,7 @@ type Params struct { //types:add LayNmSize float32 `min:"0.01" max:".1" step:"0.01" default:"0.05"` // name of color map to use - ColorMap views.ColorMapName + ColorMap core.ColorMapName // opacity (0-1) of zero values -- greater magnitude values become increasingly opaque on either side of this minimum ZeroAlpha float32 `min:"0" max:"1" step:"0.1" default:"0.5"` @@ -102,7 +102,7 @@ func (nv *Params) Defaults() { nv.ZeroAlpha = 0.5 } if nv.ColorMap == "" { - nv.ColorMap = views.ColorMapName("ColdHot") + nv.ColorMap = core.ColorMapName("ColdHot") } if nv.NFastSteps == 0 { nv.NFastSteps = 10 @@ -112,7 +112,6 @@ func (nv *Params) Defaults() { // Update satisfies the core.Updater interface and will trigger display update on edits func (nv *Params) Update() { if nv.NetView != nil { - nv.NetView.Config() nv.NetView.Update() } } diff --git a/netview/typegen.go b/netview/typegen.go index 7a473be0..8dd599e5 100644 --- a/netview/typegen.go +++ b/netview/typegen.go @@ -3,14 +3,8 @@ package netview import ( - "sync" - - "cogentcore.org/core/colors/colormap" "cogentcore.org/core/tree" "cogentcore.org/core/types" - "cogentcore.org/core/views" - "cogentcore.org/core/xyz" - "cogentcore.org/core/xyz/xyzview" ) var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.LayData", IDName: "lay-data", Doc: "LayData maintains a record of all the data for a given layer", Fields: []types.Field{{Name: "LayName", Doc: "the layer name"}, {Name: "NUnits", Doc: "cached number of units"}, {Name: "Data", Doc: "the full data, in that order"}, {Name: "RecvPaths", Doc: "receiving pathway data -- shared with SendPaths"}, {Name: "SendPaths", Doc: "sending pathway data -- shared with RecvPaths"}}}) @@ -20,11 +14,9 @@ var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.Pat // SceneType is the [types.Type] for [Scene] var SceneType = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.Scene", IDName: "scene", Doc: "Scene is a Widget for managing the 3D Scene of the NetView", Embeds: []types.Field{{Name: "Scene"}}, Fields: []types.Field{{Name: "NetView"}}, Instance: &Scene{}}) -// NewScene adds a new [Scene] with the given name to the given parent: +// NewScene returns a new [Scene] with the given optional parent: // Scene is a Widget for managing the 3D Scene of the NetView -func NewScene(parent tree.Node, name ...string) *Scene { - return parent.NewChild(SceneType, name...).(*Scene) -} +func NewScene(parent ...tree.Node) *Scene { return tree.New[*Scene](parent...) } // NodeType returns the [*types.Type] of [Scene] func (t *Scene) NodeType() *types.Type { return SceneType } @@ -35,31 +27,14 @@ func (t *Scene) New() tree.Node { return &Scene{} } // SetNetView sets the [Scene.NetView] func (t *Scene) SetNetView(v *NetView) *Scene { t.NetView = v; return t } -// SetTooltip sets the [Scene.Tooltip] -func (t *Scene) SetTooltip(v string) *Scene { t.Tooltip = v; return t } - -// SetSelectionMode sets the [Scene.SelectionMode] -func (t *Scene) SetSelectionMode(v xyzview.SelectionModes) *Scene { t.SelectionMode = v; return t } - -// SetCurrentSelected sets the [Scene.CurrentSelected] -func (t *Scene) SetCurrentSelected(v xyz.Node) *Scene { t.CurrentSelected = v; return t } - -// SetCurrentManipPoint sets the [Scene.CurrentManipPoint] -func (t *Scene) SetCurrentManipPoint(v *xyzview.ManipPoint) *Scene { t.CurrentManipPoint = v; return t } - -// SetSelectionParams sets the [Scene.SelectionParams] -func (t *Scene) SetSelectionParams(v xyzview.SelectionParams) *Scene { t.SelectionParams = v; return t } - var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.LayMesh", IDName: "lay-mesh", Doc: "LayMesh is a xyz.Mesh that represents a layer -- it is dynamically updated using the\nUpdate method which only resets the essential Vertex elements.\nThe geometry is literal in the layer size: 0,0,0 lower-left corner and increasing X,Z\nfor the width and height of the layer, in unit (1) increments per unit..\nNetView applies an overall scaling to make it fit within the larger view.", Embeds: []types.Field{{Name: "MeshBase"}}, Fields: []types.Field{{Name: "Lay", Doc: "layer that we render"}, {Name: "Shape", Doc: "current shape that has been constructed -- if same, just update"}, {Name: "View", Doc: "netview that we're in"}}}) // LayObjType is the [types.Type] for [LayObj] var LayObjType = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.LayObj", IDName: "lay-obj", Doc: "LayObj is the Layer 3D object within the NetView", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Embeds: []types.Field{{Name: "Solid"}}, Fields: []types.Field{{Name: "LayName", Doc: "name of the layer we represent"}, {Name: "NetView", Doc: "our netview"}}, Instance: &LayObj{}}) -// NewLayObj adds a new [LayObj] with the given name to the given parent: +// NewLayObj returns a new [LayObj] with the given optional parent: // LayObj is the Layer 3D object within the NetView -func NewLayObj(parent tree.Node, name ...string) *LayObj { - return parent.NewChild(LayObjType, name...).(*LayObj) -} +func NewLayObj(parent ...tree.Node) *LayObj { return tree.New[*LayObj](parent...) } // NodeType returns the [*types.Type] of [LayObj] func (t *LayObj) NodeType() *types.Type { return LayObjType } @@ -75,17 +50,12 @@ func (t *LayObj) SetLayName(v string) *LayObj { t.LayName = v; return t } // our netview func (t *LayObj) SetNetView(v *NetView) *LayObj { t.NetView = v; return t } -// SetMat sets the [LayObj.Mat] -func (t *LayObj) SetMat(v xyz.Material) *LayObj { t.Mat = v; return t } - // LayNameType is the [types.Type] for [LayName] var LayNameType = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.LayName", IDName: "lay-name", Doc: "LayName is the Layer name as a Text2D within the NetView", Embeds: []types.Field{{Name: "Text2D"}}, Fields: []types.Field{{Name: "NetView", Doc: "our netview"}}, Instance: &LayName{}}) -// NewLayName adds a new [LayName] with the given name to the given parent: +// NewLayName returns a new [LayName] with the given optional parent: // LayName is the Layer name as a Text2D within the NetView -func NewLayName(parent tree.Node, name ...string) *LayName { - return parent.NewChild(LayNameType, name...).(*LayName) -} +func NewLayName(parent ...tree.Node) *LayName { return tree.New[*LayName](parent...) } // NodeType returns the [*types.Type] of [LayName] func (t *LayName) NodeType() *types.Type { return LayNameType } @@ -97,84 +67,9 @@ func (t *LayName) New() tree.Node { return &LayName{} } // our netview func (t *LayName) SetNetView(v *NetView) *LayName { t.NetView = v; return t } -// SetMat sets the [LayName.Mat] -func (t *LayName) SetMat(v xyz.Material) *LayName { t.Mat = v; return t } - -// SetText sets the [LayName.Text] -func (t *LayName) SetText(v string) *LayName { t.Text = v; return t } - var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.NetData", IDName: "net-data", Doc: "NetData maintains a record of all the network data that has been displayed\nup to a given maximum number of records (updates), using efficient ring index logic\nwith no copying to store in fixed-sized buffers.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Methods: []types.Method{{Name: "OpenJSON", Doc: "OpenJSON opens colors from a JSON-formatted file.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}, {Name: "SaveJSON", Doc: "SaveJSON saves colors to a JSON-formatted file.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}}, Fields: []types.Field{{Name: "Net", Doc: "the network that we're viewing"}, {Name: "NoSynData", Doc: "copied from Params -- do not record synapse level data -- turn this on for very large networks where recording the entire synaptic state would be prohibitive"}, {Name: "PathLay", Doc: "name of the layer with unit for viewing pathways (connection / synapse-level values)"}, {Name: "PathUnIndex", Doc: "1D index of unit within PathLay for for viewing pathways"}, {Name: "PathType", Doc: "copied from NetView Params: if non-empty, this is the type pathway to show when there are multiple pathways from the same layer -- e.g., Inhib, Lateral, Forward, etc"}, {Name: "UnVars", Doc: "the list of unit variables saved"}, {Name: "UnVarIndexes", Doc: "index of each variable in the Vars slice"}, {Name: "SynVars", Doc: "the list of synaptic variables saved"}, {Name: "SynVarIndexes", Doc: "index of synaptic variable in the SynVars slice"}, {Name: "Ring", Doc: "the circular ring index -- Max here is max number of values to store, Len is number stored, and Index(Len-1) is the most recent one, etc"}, {Name: "MaxData", Doc: "max data parallel data per unit"}, {Name: "LayData", Doc: "the layer data -- map keyed by layer name"}, {Name: "UnMinPer", Doc: "unit var min values for each Ring.Max * variable"}, {Name: "UnMaxPer", Doc: "unit var max values for each Ring.Max * variable"}, {Name: "UnMinVar", Doc: "min values for unit variables"}, {Name: "UnMaxVar", Doc: "max values for unit variables"}, {Name: "SynMinVar", Doc: "min values for syn variables"}, {Name: "SynMaxVar", Doc: "max values for syn variables"}, {Name: "Counters", Doc: "counter strings"}, {Name: "RasterCtrs", Doc: "raster counter values"}, {Name: "RasterMap", Doc: "map of raster counter values to record numbers"}, {Name: "RastCtr", Doc: "dummy raster counter when passed a -1 -- increments and wraps around"}}}) -// NetViewType is the [types.Type] for [NetView] -var NetViewType = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.NetView", IDName: "net-view", Doc: "NetView is a Cogent Core Widget that provides a 3D network view using the Cogent Core gi3d\n3D framework.", Methods: []types.Method{{Name: "PlotSelectedUnit", Doc: "PlotSelectedUnit opens a window with a plot of all the data for the\ncurrently selected unit.\nUseful for replaying detailed trace for units of interest.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"Table", "PlotView"}}, {Name: "Current", Doc: "Current records the current state of the network, including synaptic values,\nand updates the display. Use this when switching to NetView tab after network\nhas been running while viewing another tab, because the network state\nis typically not recored then.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}}, {Name: "SaveWeights", Doc: "SaveWeights saves the network weights -- when called with views.CallMethod\nit will auto-prompt for filename", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}}, {Name: "OpenWeights", Doc: "OpenWeights opens the network weights -- when called with views.CallMethod\nit will auto-prompt for filename", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}}, {Name: "ShowNonDefaultParams", Doc: "ShowNonDefaultParams shows a dialog of all the parameters that\nare not at their default values in the network. Useful for setting params.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowAllParams", Doc: "ShowAllParams shows a dialog of all the parameters in the network.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowKeyLayerParams", Doc: "ShowKeyLayerParams shows a dialog with a listing for all layers in the network,\nof the most important layer-level params (specific to each algorithm)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowKeyPathParams", Doc: "ShowKeyPathParams shows a dialog with a listing for all Recv pathways in the network,\nof the most important pathway-level params (specific to each algorithm)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}}, Embeds: []types.Field{{Name: "Layout"}}, Fields: []types.Field{{Name: "Net", Doc: "the network that we're viewing"}, {Name: "Var", Doc: "current variable that we're viewing"}, {Name: "Di", Doc: "current data parallel index di, for networks capable of processing input patterns in parallel."}, {Name: "Vars", Doc: "the list of variables to view"}, {Name: "SynVars", Doc: "list of synaptic variables"}, {Name: "SynVarsMap", Doc: "map of synaptic variable names to index"}, {Name: "VarParams", Doc: "parameters for the list of variables to view"}, {Name: "CurVarParams", Doc: "current var params -- only valid during Update of display"}, {Name: "Params", Doc: "parameters controlling how the view is rendered"}, {Name: "ColorMap", Doc: "color map for mapping values to colors -- set by name in Params"}, {Name: "ColorMapVal", Doc: "color map value representing ColorMap"}, {Name: "RecNo", Doc: "record number to display -- use -1 to always track latest, otherwise in range"}, {Name: "LastCtrs", Doc: "last non-empty counters string provided -- re-used if no new one"}, {Name: "Data", Doc: "contains all the network data with history"}, {Name: "DataMu", Doc: "mutex on data access"}}, Instance: &NetView{}}) - -// NewNetView adds a new [NetView] with the given name to the given parent: -// NetView is a Cogent Core Widget that provides a 3D network view using the Cogent Core gi3d -// 3D framework. -func NewNetView(parent tree.Node, name ...string) *NetView { - return parent.NewChild(NetViewType, name...).(*NetView) -} - -// NodeType returns the [*types.Type] of [NetView] -func (t *NetView) NodeType() *types.Type { return NetViewType } - -// New returns a new [*NetView] value -func (t *NetView) New() tree.Node { return &NetView{} } - -// SetDi sets the [NetView.Di]: -// current data parallel index di, for networks capable of processing input patterns in parallel. -func (t *NetView) SetDi(v int) *NetView { t.Di = v; return t } - -// SetVars sets the [NetView.Vars]: -// the list of variables to view -func (t *NetView) SetVars(v ...string) *NetView { t.Vars = v; return t } - -// SetSynVars sets the [NetView.SynVars]: -// list of synaptic variables -func (t *NetView) SetSynVars(v ...string) *NetView { t.SynVars = v; return t } - -// SetSynVarsMap sets the [NetView.SynVarsMap]: -// map of synaptic variable names to index -func (t *NetView) SetSynVarsMap(v map[string]int) *NetView { t.SynVarsMap = v; return t } - -// SetVarParams sets the [NetView.VarParams]: -// parameters for the list of variables to view -func (t *NetView) SetVarParams(v map[string]*VarParams) *NetView { t.VarParams = v; return t } - -// SetCurVarParams sets the [NetView.CurVarParams]: -// current var params -- only valid during Update of display -func (t *NetView) SetCurVarParams(v *VarParams) *NetView { t.CurVarParams = v; return t } - -// SetParams sets the [NetView.Params]: -// parameters controlling how the view is rendered -func (t *NetView) SetParams(v Params) *NetView { t.Params = v; return t } - -// SetColorMap sets the [NetView.ColorMap]: -// color map for mapping values to colors -- set by name in Params -func (t *NetView) SetColorMap(v *colormap.Map) *NetView { t.ColorMap = v; return t } - -// SetColorMapVal sets the [NetView.ColorMapVal]: -// color map value representing ColorMap -func (t *NetView) SetColorMapVal(v *views.ColorMapValue) *NetView { t.ColorMapVal = v; return t } - -// SetRecNo sets the [NetView.RecNo]: -// record number to display -- use -1 to always track latest, otherwise in range -func (t *NetView) SetRecNo(v int) *NetView { t.RecNo = v; return t } - -// SetLastCtrs sets the [NetView.LastCtrs]: -// last non-empty counters string provided -- re-used if no new one -func (t *NetView) SetLastCtrs(v string) *NetView { t.LastCtrs = v; return t } - -// SetData sets the [NetView.Data]: -// contains all the network data with history -func (t *NetView) SetData(v NetData) *NetView { t.Data = v; return t } - -// SetDataMu sets the [NetView.DataMu]: -// mutex on data access -func (t *NetView) SetDataMu(v sync.RWMutex) *NetView { t.DataMu = v; return t } - -// SetTooltip sets the [NetView.Tooltip] -func (t *NetView) SetTooltip(v string) *NetView { t.Tooltip = v; return t } +var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.NetView", IDName: "net-view", Doc: "NetView is a Cogent Core Widget that provides a 3D network view using the Cogent Core gi3d\n3D framework.", Methods: []types.Method{{Name: "PlotSelectedUnit", Doc: "PlotSelectedUnit opens a window with a plot of all the data for the\ncurrently selected unit.\nUseful for replaying detailed trace for units of interest.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"Table", "PlotEditor"}}, {Name: "Current", Doc: "Current records the current state of the network, including synaptic values,\nand updates the display. Use this when switching to NetView tab after network\nhas been running while viewing another tab, because the network state\nis typically not recored then.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}}, {Name: "SaveWeights", Doc: "SaveWeights saves the network weights.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}}, {Name: "OpenWeights", Doc: "OpenWeights opens the network weights.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}}, {Name: "ShowNonDefaultParams", Doc: "ShowNonDefaultParams shows a dialog of all the parameters that\nare not at their default values in the network. Useful for setting params.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowAllParams", Doc: "ShowAllParams shows a dialog of all the parameters in the network.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowKeyLayerParams", Doc: "ShowKeyLayerParams shows a dialog with a listing for all layers in the network,\nof the most important layer-level params (specific to each algorithm)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}, {Name: "ShowKeyPathParams", Doc: "ShowKeyPathParams shows a dialog with a listing for all Recv pathways in the network,\nof the most important pathway-level params (specific to each algorithm)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Returns: []string{"string"}}}, Embeds: []types.Field{{Name: "invalid type"}}, Fields: []types.Field{{Name: "Net", Doc: "the network that we're viewing"}, {Name: "Var", Doc: "current variable that we're viewing"}, {Name: "Di", Doc: "current data parallel index di, for networks capable of processing input patterns in parallel."}, {Name: "Vars", Doc: "the list of variables to view"}, {Name: "SynVars", Doc: "list of synaptic variables"}, {Name: "SynVarsMap", Doc: "map of synaptic variable names to index"}, {Name: "VarParams", Doc: "parameters for the list of variables to view"}, {Name: "CurVarParams", Doc: "current var params -- only valid during Update of display"}, {Name: "Params", Doc: "parameters controlling how the view is rendered"}, {Name: "ColorMap", Doc: "color map for mapping values to colors -- set by name in Params"}, {Name: "ColorMapButton", Doc: "color map value representing ColorMap"}, {Name: "RecNo", Doc: "record number to display -- use -1 to always track latest, otherwise in range"}, {Name: "LastCtrs", Doc: "last non-empty counters string provided -- re-used if no new one"}, {Name: "Data", Doc: "contains all the network data with history"}, {Name: "DataMu", Doc: "mutex on data access"}}}) var _ = types.AddType(&types.Type{Name: "github.com/emer/emergent/v2/netview.RasterParams", IDName: "raster-params", Doc: "RasterParams holds parameters controlling the raster plot view", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Fields: []types.Field{{Name: "On", Doc: "if true, show a raster plot over time, otherwise units"}, {Name: "XAxis", Doc: "if true, the raster counter (time) is plotted across the X axis -- otherwise the Z depth axis"}, {Name: "Max", Doc: "maximum count for the counter defining the raster plot"}, {Name: "UnitSize", Doc: "size of a single unit, where 1 = full width and no space.. 1 default"}, {Name: "UnitHeight", Doc: "height multiplier for units, where 1 = full height.. 0.2 default"}}}) diff --git a/netview/viewupdt.go b/netview/viewupdt.go index 72b6e484..3ce76ed9 100644 --- a/netview/viewupdt.go +++ b/netview/viewupdt.go @@ -7,7 +7,6 @@ package netview import ( "strings" - "cogentcore.org/core/core" "github.com/emer/emergent/v2/etime" ) @@ -107,9 +106,10 @@ func (vu *ViewUpdate) UpdateWhenStopped() { if !vu.View.Params.Raster.On { // always record when not in raster mode vu.View.Record(vu.Text, -1) // -1 = use a dummy counter } - if vu.View.Scene.Is(core.ScUpdating) { - return - } + // todo: updating is not available here -- needed? + // if vu.View.Scene.Is(core.ScUpdating) { + // return + // } vu.View.GoUpdateView() } diff --git a/params/apply.go b/params/apply.go index fbf2b17f..d185476b 100644 --- a/params/apply.go +++ b/params/apply.go @@ -12,8 +12,8 @@ import ( "reflect" "strings" + "cogentcore.org/core/base/labels" "cogentcore.org/core/base/reflectx" - "cogentcore.org/core/core" ) // PathAfterType returns the portion of a path string after the initial @@ -51,7 +51,7 @@ func (pr *Params) Apply(obj any, setMsg bool) error { if styob, has := obj.(StylerObj); has { obj = styob.Object() } - } else if lblr, has := obj.(core.Labeler); has { + } else if lblr, has := obj.(labels.Labeler); has { objNm = lblr.Label() } var errs []error @@ -109,7 +109,7 @@ func (pr *Hypers) Apply(obj any, setMsg bool) error { if styob, has := obj.(StylerObj); has { obj = styob.Object() } - } else if lblr, has := obj.(core.Labeler); has { + } else if lblr, has := obj.(labels.Labeler); has { objNm = lblr.Label() } if hv, ok := obj.(Hypers); ok {