Merge branch 'Symbol-Group-Work' into buswire-merge-yhp19

This commit is contained in:
Philip Puk 2022-03-16 00:31:33 +00:00
commit ee145a288c
6 changed files with 1322 additions and 462 deletions

772
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -83,7 +83,7 @@ type SnapIndicator =
/// For Keyboard messages /// For Keyboard messages
type KeyboardMsg = type KeyboardMsg =
| CtrlS | CtrlC | CtrlV | CtrlZ | CtrlY | CtrlA | CtrlW | AltC | AltV | AltZ | AltShiftZ | ZoomIn | ZoomOut | DEL | ESC | CtrlS | CtrlC | CtrlV | CtrlZ | CtrlY | CtrlA | CtrlW | AltC | AltV | AltZ | AltShiftZ | ZoomIn | ZoomOut | DEL | ESC | Rotate | FlipV | FlipH
type Msg = type Msg =
| Wire of BusWire.Msg | Wire of BusWire.Msg
@ -169,6 +169,10 @@ type Model = {
member this.ChangeLabel (dispatch: Dispatch<Msg>) (compId: ComponentId) (lbl: string) = member this.ChangeLabel (dispatch: Dispatch<Msg>) (compId: ComponentId) (lbl: string) =
dispatch <| (Wire (BusWire.Symbol (Symbol.ChangeLabel (compId, lbl) ) ) ) dispatch <| (Wire (BusWire.Symbol (Symbol.ChangeLabel (compId, lbl) ) ) )
/// Change the Port Side of Component specified by compId to lbl
member this.ChangePort (dispatch: Dispatch<Msg>) (compId: ComponentId) (portName: string) (portSide: string) =
dispatch <| (Wire (BusWire.Symbol (Symbol.ChangePort (compId, portName,portSide) ) ) )
/// Run Bus Width Inference check /// Run Bus Width Inference check
member this.DoBusWidthInference dispatch = member this.DoBusWidthInference dispatch =
dispatch <| (Wire (BusWire.BusWidths)) dispatch <| (Wire (BusWire.BusWidths))
@ -422,8 +426,9 @@ let findNearbyPorts (model: Model) =
/// Returns what is located at pos /// Returns what is located at pos
/// Priority Order: InputPort -> OutputPort -> Component -> Wire -> Canvas /// Priority Order: InputPort -> OutputPort -> Component -> Wire -> Canvas
let mouseOn (model: Model) (pos: XYPos) : MouseOn = let mouseOn (model: Model) (pos: XYPos) : MouseOn =
let inputPorts, outputPorts = findNearbyPorts model let inputPortsWithSide, outputPortsWithSide = findNearbyPorts model
let inputPorts = List.map(fun (outPort,(orient,location)) -> outPort,location) inputPortsWithSide
let outputPorts = List.map(fun (outPort,(orient,location)) -> outPort,location) outputPortsWithSide
//TODO FIX THIS - QUICK FIX TO MAKE WORK, NOT IDEAL //TODO FIX THIS - QUICK FIX TO MAKE WORK, NOT IDEAL
//The ports/wires are being loaded in the correct place but the detection is not working //The ports/wires are being loaded in the correct place but the detection is not working
//Something is wrong with the mouse coordinates somewhere, might be caused by zoom? not sure //Something is wrong with the mouse coordinates somewhere, might be caused by zoom? not sure
@ -681,7 +686,8 @@ let mDragUpdate (model: Model) (mMsg: MouseT) : Model * Cmd<Msg> =
moveSymbols model mMsg moveSymbols model mMsg
| ConnectingInput _ -> | ConnectingInput _ ->
let nearbyComponents = findNearbyComponents model mMsg.Pos let nearbyComponents = findNearbyComponents model mMsg.Pos
let _, nearbyOutputPorts = findNearbyPorts model let _, nearbyOutputPortsWithSide = findNearbyPorts model
let nearbyOutputPorts = List.map(fun (outPort,(orient,location)) -> outPort,location)nearbyOutputPortsWithSide
let targetPort, drawLineTarget = let targetPort, drawLineTarget =
match mouseOnPort nearbyOutputPorts mMsg.Pos 12.5 with match mouseOnPort nearbyOutputPorts mMsg.Pos 12.5 with
@ -697,8 +703,8 @@ let mDragUpdate (model: Model) (mMsg: MouseT) : Model * Cmd<Msg> =
, Cmd.ofMsg CheckAutomaticScrolling , Cmd.ofMsg CheckAutomaticScrolling
| ConnectingOutput _ -> | ConnectingOutput _ ->
let nearbyComponents = findNearbyComponents model mMsg.Pos let nearbyComponents = findNearbyComponents model mMsg.Pos
let nearbyInputPorts, _ = findNearbyPorts model let nearbyInputPortsWithSide, _ = findNearbyPorts model
let nearbyInputPorts = List.map(fun (outPort,(orient,location)) -> outPort,location) nearbyInputPortsWithSide
let targetPort, drawLineTarget = let targetPort, drawLineTarget =
match mouseOnPort nearbyInputPorts mMsg.Pos 12.5 with match mouseOnPort nearbyInputPorts mMsg.Pos 12.5 with
| Some (InputPortId portId, portLoc) -> (portId, portLoc) // If found target, snap target of the line to the port | Some (InputPortId portId, portLoc) -> (portId, portLoc) // If found target, snap target of the line to the port
@ -852,6 +858,21 @@ let update (msg : Msg) (model : Model): Model*Cmd<Msg> =
symbolCmd (Symbol.CopySymbols model.SelectedComponents) // Better to have Symbol keep track of clipboard as symbols can get deleted before pasting. symbolCmd (Symbol.CopySymbols model.SelectedComponents) // Better to have Symbol keep track of clipboard as symbols can get deleted before pasting.
wireCmd (BusWire.CopyWires model.SelectedWires) wireCmd (BusWire.CopyWires model.SelectedWires)
] ]
| KeyPress Rotate ->
model,
Cmd.batch [
symbolCmd (Symbol.RotateSymbols model.SelectedComponents) // Rotate Symbol using keyboard combination
]
| KeyPress FlipV ->
model,
Cmd.batch [
symbolCmd (Symbol.FlipVSymbols model.SelectedComponents) // Flip Vertically Symbol using keyboard combination
]
| KeyPress FlipH ->
model,
Cmd.batch [
symbolCmd (Symbol.FlipHSymbols model.SelectedComponents) // Flip Vertically Symbol using keyboard combination
]
| KeyPress CtrlV -> | KeyPress CtrlV ->
let newSymbolModel, pastedCompIds = Symbol.pasteSymbols model.Wire.Symbol model.LastMousePos // Symbol has Copied Symbols stored let newSymbolModel, pastedCompIds = Symbol.pasteSymbols model.Wire.Symbol model.LastMousePos // Symbol has Copied Symbols stored
let newBusWireModel, pastedConnIds = BusWire.pasteWires { model.Wire with Symbol = newSymbolModel } pastedCompIds let newBusWireModel, pastedConnIds = BusWire.pasteWires { model.Wire with Symbol = newSymbolModel } pastedCompIds

File diff suppressed because it is too large Load diff

View file

@ -148,6 +148,10 @@ let viewMenu dispatch =
makeItem "Diagram Zoom Out" (Some "Shift+-") (fun ev -> dispatch Sheet.KeyboardMsg.ZoomOut) makeItem "Diagram Zoom Out" (Some "Shift+-") (fun ev -> dispatch Sheet.KeyboardMsg.ZoomOut)
makeItem "Diagram Zoom to Fit" (Some "CmdOrCtrl+W") (fun ev -> dispatch Sheet.KeyboardMsg.CtrlW) makeItem "Diagram Zoom to Fit" (Some "CmdOrCtrl+W") (fun ev -> dispatch Sheet.KeyboardMsg.CtrlW)
menuSeparator menuSeparator
makeItem "Rotate Symbol" (Some "Shift+R") (fun ev -> dispatch Sheet.KeyboardMsg.Rotate)
makeItem "Flip Horizontally Symbol" (Some "Shift+H") (fun ev -> dispatch Sheet.KeyboardMsg.FlipH)
makeItem "Flip Vertically Symbol" (Some "Shift+V") (fun ev -> dispatch Sheet.KeyboardMsg.FlipV)
menuSeparator
makeCondItem (JSHelpers.debugLevel <> 0) "Toggle Dev Tools" (Some devToolsKey) (fun _ -> makeCondItem (JSHelpers.debugLevel <> 0) "Toggle Dev Tools" (Some devToolsKey) (fun _ ->
renderer.ipcRenderer.send("toggle-dev-tools", [||]) |> ignore) renderer.ipcRenderer.send("toggle-dev-tools", [||]) |> ignore)
] ]

View file

@ -90,7 +90,10 @@ let setComponentLabel model (sheetDispatch) (comp:Component) (text:string) =
model.Sheet.ChangeLabel sheetDispatch (ComponentId comp.Id) label model.Sheet.ChangeLabel sheetDispatch (ComponentId comp.Id) label
//model.Diagram.EditComponentLabel comp.Id label //model.Diagram.EditComponentLabel comp.Id label
let setComponentPortUpdate model sheetDispatch (comp:Component) (portName:string) (portSide:string) =
model.Sheet.ChangePort sheetDispatch (ComponentId comp.Id) portName portSide
//model.Diagram.EditComponentLabel comp.Id label
//========// //========//

View file

@ -6,6 +6,7 @@
module SelectedComponentView module SelectedComponentView
open EEExtensions
open Fulma open Fulma
open Fable.React open Fable.React
open Fable.React.Props open Fable.React.Props
@ -17,6 +18,7 @@ open MemoryEditorView
open PopupView open PopupView
open Notifications open Notifications
let private readOnlyFormField name body = let private readOnlyFormField name body =
Field.div [] [ Field.div [] [
Label.label [] [ str name ] Label.label [] [ str name ]
@ -383,34 +385,90 @@ let private makeExtraInfo model (comp:Component) text dispatch =
| _ -> div [] [] | _ -> div [] []
let viewSelectedComponent (model: ModelType.Model) dispatch = let viewSelectedComponent (model: ModelType.Model) dispatch : ReactElement =
let sheetDispatch sMsg = dispatch (Sheet sMsg) let sheetDispatch sMsg = dispatch (Sheet sMsg)
let formatLabelText (txt: string) = let formatLabelText (txt: string) =
txt.ToUpper() txt.ToUpper()
|> Seq.filter (function | ch when System.Char.IsLetterOrDigit ch -> true | '.' -> true | '_' -> true | _ -> false) |> Seq.filter (function | ch when System.Char.IsLetterOrDigit ch -> true | '.' -> true | '_' -> true | _ -> false)
|> Seq.skipWhile (System.Char.IsLetter >> not) |> Seq.skipWhile (System.Char.IsLetter >> not)
|> (fun chars -> match Seq.length chars with | 0 -> None | _ -> Some (String.concat "" (Seq.map string chars))) |> (fun chars -> match Seq.length chars with | 0 -> None | _ -> Some (String.concat "" (Seq.map string chars)))
match model.Sheet.SelectedComponents with match model.Sheet.SelectedComponents with
| [ compId ] -> | [ compId ] ->
let comp = Symbol.extractComponent model.Sheet.Wire.Symbol compId let comp = Symbol.extractComponent model.Sheet.Wire.Symbol compId // Extract Component : function in Symbol.fs
div [Key comp.Id] [ let sym = Symbol.extractSymbol model.Sheet.Wire.Symbol compId // Extract Symbol : function in Symbol.fs
let namesPortRaw = Symbol.portNamesMap comp
div [Style [ Margin 0 ];Key comp.Id] [
// let label' = extractLabelBase comp.Label // let label' = extractLabelBase comp.Label
// TODO: normalise labels so they only contain allowed chars all uppercase // TODO: normalise labels so they only contain allowed chars all uppercase
let label' = Option.defaultValue "L" (formatLabelText comp.Label) // No formatting atm let label' = Option.defaultValue "L" (formatLabelText comp.Label) // No formatting atm
readOnlyFormField "Description" <| makeDescription comp model dispatch readOnlyFormField "Description" <| makeDescription comp model dispatch
makeExtraInfo model comp label' dispatch makeExtraInfo model comp label' dispatch
let required = match comp.Type with | SplitWire _ | MergeWires | BusSelection _ -> false | _ -> true let required = match comp.Type with | SplitWire _ | MergeWires | BusSelection _ -> false | _ -> true
div [Key comp.Id] [
textFormField required "Component Name" label' (fun text -> textFormField required "Component Name" label' (fun text ->
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text)
match formatLabelText text with match formatLabelText text with
| Some label -> | Some label ->
setComponentLabel model sheetDispatch comp label setComponentLabel model sheetDispatch comp label
dispatch <| SetPopupDialogText (Some label) dispatch <| SetPopupDialogText (Some label)
| None -> () | None -> ()
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
) )
// Control when the namesPortRaw map can be accessed else return normal name of port
let allowedDescription = match comp.Type with | NbitsAdder _ | Decode4 | Register _ |DFF| RegisterE _ |DFFE| ROM1 _ |AsyncROM1 _ | RAM1 _ | AsyncRAM1 _ | Mux2 | Demux2 | NbitsXor _ | Custom _ -> true | _ -> false
let ports =
sym.APortOffsetsMap
|> Map.toList
let portNameLst =
ports
|> List.map fst
|> List.map (fun key -> if allowedDescription then namesPortRaw[key] else key)
let portSideLst = ["Top";"Left";"Bottom";"Right"]
//Already done for custom symbols
// let portDescription (i:string) : ReactElement =
// Label.label [] [ h2 [] [str i ]]
//
//
// Field.div [] [
// Label.label [] [ str "Component Ports" ]
// g [] (Seq.map portDescription portNameLst)
// ]
let mutable portName = ""
let mutable portSide = ""
let dropDown (available:bool) (name:string) (lst:string list): ReactElement =
if available then
Field.div [] [
Label.label [] [ str name ]
Label.label [ ]
[Select.select []
[ select [(OnChange(fun option ->
match name with
| "Port" -> portName <- option.Value; if (portName <> "" && portSide <> "") then setComponentPortUpdate model sheetDispatch comp portName portSide; dispatch <| SetPopupDialogText (Some portName);dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) else printf "Not yet"
| "Side" -> portSide <- option.Value; if (portName <> "" && portSide <> "") then setComponentPortUpdate model sheetDispatch comp portName portSide; dispatch <| SetPopupDialogText (Some portSide);dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) else printf "Not yet"
| _ -> failwithf "Case not an option"
))]
([option [Value "";Selected true;Disabled true] [str ("Choose " + string name)]] @ List.map(fun value -> option [Value value] [str value]) lst)
]
]
]
else
Field.div [] []
dropDown allowedDescription "Port" portNameLst
dropDown allowedDescription "Side" portSideLst
]
] ]
| _ -> div [] [ str "Select a component in the diagram to view or change its properties, for example number of bits." ] | _ -> div [] [ str "Select a component in the diagram to view or change its properties, for example number of bits." ]