Skip to content

Commit

Permalink
fix: more wavesim bugs
Browse files Browse the repository at this point in the history
fix: exception in value column width estimation code
fix: possible oscillation when ShownCycles determination is not stable

Cosmetic changes to zoom button
  • Loading branch information
tomcl committed Aug 15, 2024
1 parent 747fa42 commit 638fa5b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<meta charset="utf-8" />
</head>
<body>
<div id="app"; style="overflow-y:hidden"></div>
<div id="app"; style="overflow-y:clip"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion src/Renderer/UI/MainView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ let displayView model dispatch =
UserSelect UserSelectOptions.None
BorderTop "2px solid lightgray"
BorderBottom "2px solid lightgray"
OverflowX OverflowOptions.Auto
CSSProp.Custom("Overflow", "clip clip")
Height "calc(100%-4px)"
]
] [
Expand Down
6 changes: 3 additions & 3 deletions src/Renderer/UI/WaveSim/WaveSim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ let rec refreshWaveSim (newSimulation: bool) (wsModel: WaveSimModel) (model: Mod
| Some sp ->
updateSpinner (fst sp) (snd sp) numToDo model
|> updateWSModel (fun _ -> ws)
model, Elmish.Cmd.none
|> TimeHelpers.instrumentInterval "refreshWaveSim" start)
model, Elmish.Cmd.none)
//|> TimeHelpers.instrumentInterval "refreshWaveSim" start)
//}

/// Refresh the state of the wave simulator according to the model and canvas state.
Expand Down Expand Up @@ -340,7 +340,7 @@ let viewWaveSim canvasState (model: Model) dispatch : ReactElement =
[WaveSimRams.ramTables wsModel]
)

div [] [
div [Style [OverflowX OverflowOptions.Clip]] [
WaveSimSelect.selectRamModal wsModel dispatch
WaveSimSelect.selectWavesModal wsModel dispatch
div [ viewWaveSimStyle ]
Expand Down
26 changes: 14 additions & 12 deletions src/Renderer/UI/WaveSim/WaveSimNavigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ let inline updateViewerWidthInWaveSim w (model:Model) =
let wholeCycles =
max 1 (int (float waveColWidth / singleWaveWidth wsModel))
|> min (Constants.maxLastClk / wsModel.CycleMultiplier) // make sure there can be no over-run when making viewer larger
// prevent oscilaltion when number of cycles changes continuously due to width changes in values (rare corner case)
|> (function | whole when abs (float (whole - wsModel.ShownCycles) / float wsModel.ShownCycles) < 0.1 -> wsModel.ShownCycles
| whole -> whole)

let singleCycleWidth = float waveColWidth / float wholeCycles
let finalWavesColWidth = singleCycleWidth * float wholeCycles

Expand Down Expand Up @@ -110,26 +114,21 @@ let inline setViewerWidthInWaveSim w dispatch =

let rec validateSimParas (ws: WaveSimModel) =
if ws.StartCycle < 0 then
printfn $"ERROR in Sim parameters: StartCycle {ws.StartCycle} < 0"
validateSimParas {ws with StartCycle = 0}
elif ws.CurrClkCycleDetail > Constants.maxLastClk then
validateSimParas {ws with CurrClkCycleDetail = Constants.maxLastClk}
elif (ws.StartCycle + ws.ShownCycles-1)*ws.CycleMultiplier > Constants.maxLastClk then
printfn $"Correcting sim paras by reducing StartCycle"
{ws with StartCycle = Constants.maxLastClk / ws.CycleMultiplier - ws.ShownCycles}
elif ws.CurrClkCycle < ws.StartCycle || ws.CurrClkCycle >= ws.StartCycle + ws.ShownCycles then
printfn $"Resetting CurClkCycle which {ws.CurrClkCycle} was too large with multiplier = {ws.CycleMultiplier}"
{ws with CurrClkCycle = ws.StartCycle; CurrClkCycleDetail = ws.StartCycle*ws.CycleMultiplier}
else ws
|> validateScrollBarInfo

let changeMultiplier newMultiplier (ws: WaveSimModel) =
let oldM = ws.CycleMultiplier
printfn $"Old: {oldM} shown {ws.ShownCycles} start={ws.StartCycle} NewM={newMultiplier}"
let sampsHalf = (float ws.ShownCycles - 1.) / 2.
let newShown = 1 + min ws.ShownCycles (Constants.maxLastClk / newMultiplier)
let newStart = int ((float ws.StartCycle + sampsHalf) * float oldM / float newMultiplier - (float newShown - 1.) / 2.)
printfn $"New: shown={newShown} start = {newStart}"
{ws with ShownCycles = newShown; StartCycle = newStart; CycleMultiplier = newMultiplier}
|> validateSimParas

Expand Down Expand Up @@ -319,7 +318,7 @@ let makeScrollbar (wsm: WaveSimModel) (dispatch: Msg->unit): ReactElement =
OnMouseDown tbMouseDownHandler; OnMouseUp tbMouseUpHandler; OnMouseMove tbMouseMoveHandler;
]

div [ Style [ MarginTop "5px"; MarginBottom "5px"; Height "25px"]] [
div [ Style [ WhiteSpace WhiteSpaceOptions.Nowrap; MarginTop "5px"; MarginBottom "5px"; Height "25px"; CSSProp.Custom("Overflow", "visible visible")]] [
button [ Button.Props [scrollbarClkCycleLeftStyle] ]
(fun _ -> scrollWaveformViewBy -1.0)
(str "")
Expand Down Expand Up @@ -438,25 +437,28 @@ let multiplierMenuButton(wsModel: WaveSimModel) (dispatch: Msg -> unit) =
/// key = 0 .. n-1 where there are n possible multipliers
let mulTable = Constants.multipliers
let menuItem (key) =
let itemLegend = str (match key with | 0 -> "Every Cycle (normal)" | _ -> $"Every {mulTable[key]} cycles")
let itemLegend = str (match key with | 0 -> "Every Cycle (normal X1)" | _ -> $"Every {mulTable[key]} cycles")
Menu.Item.li
[ Menu.Item.IsActive (Constants.multipliers[key] = wsModel.CycleMultiplier)
Menu.Item.OnClick (fun _ ->
dispatch <| ChangeWaveSimMultiplier (key);
dispatch ClosePopup)
]
[ itemLegend ]
let addSpaces n r = span [Style[PaddingLeft n; PaddingRight n]] [r]
let menu =
div []
[
p [Style[ Color IColor.IsDanger; FontWeight 600; FontSize "18px"]] [str "Warning: zoom greater than X1 will sample the waveform and lose information about fast-changing outputs"]
p [Style[ Color "darkred"; FontWeight 600; FontSize "18px"]] [str "Warning: zoom greater than X1 will sample the waveform and lose information about fast-changing outputs"]
br []
p [] [str "Use it to observe slow-changing signals when the normal zoom range is not enough."]
p [] [str "Use it this menu to zoom out slow-changing signals when the range of"; addSpaces 5 zoomOutSVG; str "is not enough."]
br []
Menu.menu [] [ Menu.list [] (List.map menuItem [0 .. mulTable.Length - 1 ])]
]

let buttonClick = Button.OnClick (fun _ ->
printfn $"Mul={wsModel.CycleMultiplier}"
dispatch <| ShowStaticInfoPopup("Extra Zoom Sampling Rate",menu,dispatch ))
Button.button ( buttonClick :: topHalfButtonProps IColor.IsDanger "ZoomButton" false) [str $"Extra zoom X{wsModel.CycleMultiplier}"]
dispatch <| ShowStaticInfoPopup("Zoom Sampling Rate",menu,dispatch ))
let expectedMaxShown = int (wsModel.WaveformColumnWidth / float Constants.minCycleWidth)
if wsModel.ShownCycles = expectedMaxShown || wsModel.CycleMultiplier > 1 then
Button.button ( buttonClick :: topHalfButtonProps IColor.IsDanger "ZoomButton" false) [str $"X{wsModel.CycleMultiplier}"]
else str ""
4 changes: 3 additions & 1 deletion src/Renderer/UI/WaveSim/WaveSimStyle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ let valuesColumnSize wsModel =
|> List.max
let sampleVals =
[maxValueBusWidth; min maxValueBusWidth NumberHelpers.Constants.maxBinaryDisplayWidth]
|> List.map (fun num ->
|> List.map (fun num ->
let num = min (max num 1) (SimulatorTypes.bigIntMaskA.Length - 2)
let worstCaseVal, extra =
match wsModel.Radix with
| CommonTypes.Hex | CommonTypes.Bin -> 0I, 2.
Expand Down Expand Up @@ -780,6 +781,7 @@ let radixTabAStyle = Style [
let radixTabsStyle = Style [
Height Constants.rowHeight
FontSize "80%"
OverflowX OverflowOptions.Clip
Display DisplayOptions.Inline
]

Expand Down
8 changes: 3 additions & 5 deletions src/Renderer/UI/WaveSim/WaveSimWaveforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ let namesColumn model wsModel dispatch : ReactElement =
nameRows model wsModel dispatch
div (namesColumnProps wsModel)
(List.concat [ topRow []; rows ])
|> TimeHelpers.instrumentInterval "namesColumn" start
//|> TimeHelpers.instrumentInterval "namesColumn" start


/// Create label of waveform value for each selected wave at a given clk cycle.
Expand Down Expand Up @@ -220,11 +220,9 @@ let private valuesColumn wsModel : ReactElement =
let width, rows = valueRows wsModel
let cursorClkNum = wsModel.CurrClkCycleDetail
let topRowNumber = [ div [Style [FontSize "10pt" ; VerticalAlign "bottom"; FontWeight "bold"; PaddingLeft "4pt"]] [str (string <| cursorClkNum)] ]
printfn "%A" topRowNumber

div [ HTMLAttr.Id "ValuesCol" ; valuesColumnStyle width]
(List.concat [ topRow topRowNumber ; rows ])
|> TimeHelpers.instrumentInterval "valuesColumn" start
//|> TimeHelpers.instrumentInterval "valuesColumn" start

/// Generate a column of waveforms corresponding to selected waves.
let waveformColumn (wsModel: WaveSimModel) dispatch : ReactElement =
Expand Down Expand Up @@ -270,7 +268,7 @@ let showWaveforms (model: Model) (wsModel: WaveSimModel) (dispatch: Msg -> unit)
else
$"min( calc(100vh - {fixedHeight}px) , {wHeight}px)"

div [ HTMLAttr.Id "Scroller"; Style [ Height cssHeight; Width "100%"; CSSProp.Custom("overflow", "auto")]] [
div [ HTMLAttr.Id "Scroller"; Style [ Height cssHeight; Width "100%"; CSSProp.Custom("overflow", "hidden auto")]] [
div [ HTMLAttr.Id "WaveCols" ;showWaveformsStyle ]
[
namesColumn model wsModel dispatch
Expand Down

0 comments on commit 638fa5b

Please sign in to comment.