Updates for new branch

This commit is contained in:
Giorgos Vyronos 2022-03-10 11:41:00 +00:00
parent b20fd75579
commit c13b88b94d
4 changed files with 93 additions and 14 deletions

View file

@ -83,7 +83,7 @@ type SnapIndicator =
/// For Keyboard messages
type KeyboardMsg =
| CtrlS | CtrlC | CtrlV | CtrlZ | CtrlY | CtrlA | CtrlW | AltC | AltV | AltZ | AltShiftZ | ZoomIn | ZoomOut | DEL | ESC | Rotate
| CtrlS | CtrlC | CtrlV | CtrlZ | CtrlY | CtrlA | CtrlW | AltC | AltV | AltZ | AltShiftZ | ZoomIn | ZoomOut | DEL | ESC | Rotate | FlipV | FlipH
type Msg =
| Wire of BusWire.Msg
@ -863,6 +863,16 @@ let update (msg : Msg) (model : Model): Model*Cmd<Msg> =
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 ->
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

View file

@ -76,7 +76,9 @@ type Msg =
| MoveSymbols of compList: ComponentId list * move: XYPos
| ShowPorts of ComponentId list
| SelectSymbols of ComponentId list// Issie interface
| RotateSymbols of ComponentId list //First Attempt at implementing a way to rotate symbol.
| RotateSymbols of ComponentId list //First Attempt at implementing a way to rotate symbol.
| FlipHSymbols of ComponentId list //First Attempt at implementing a way to flip symbol horizontally.
| FlipVSymbols of ComponentId list //First Attempt at implementing a way to flip symbol vertically.
| SymbolsHaveError of sIds: ComponentId list
| ChangeLabel of sId : ComponentId * newLabel : string
| PasteSymbols of sIds: ComponentId list
@ -1308,7 +1310,15 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> =
//Used to print it Dev Tools Terminal list of ports global coordinates starting anticlockwise from inputs
printf "%A" result
{ model with Symbols = newSymbols }, Cmd.none
| FlipHSymbols compList -> // NEW: flip a symbol Horizontally
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
{ model with Symbols = resetSymbols }, Cmd.none
| FlipVSymbols compList ->
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
{ model with Symbols = resetSymbols }, Cmd.none
| ErrorSymbols (errorCompList,selectCompList,isDragAndDrop) ->
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
let selectSymbols =

View file

@ -149,6 +149,8 @@ let viewMenu dispatch =
makeItem "Diagram Zoom to Fit" (Some "CmdOrCtrl+W") (fun ev -> dispatch Sheet.KeyboardMsg.CtrlW)
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 _ ->
renderer.ipcRenderer.send("toggle-dev-tools", [||]) |> ignore)

View file

@ -396,10 +396,25 @@ let viewSelectedComponent (model: ModelType.Model) dispatch =
| [ compId ] ->
let comp = Symbol.extractComponent model.Sheet.Wire.Symbol compId // Extract Component : function in Symbol.fs
let sym = Symbol.extractSymbol model.Sheet.Wire.Symbol compId // Extract Symbol : function in Symbol.fs
let stransform = string sym.STransform
let ports =
sym.APortOffsetsMap
|> Map.toList
let portName =
ports
|> List.map fst
let portSide =
ports
|> List.map snd
|> List.map (fun i -> i.Side)
|> List.map (fun i -> string i)
let portOffset =
ports
|> List.map snd
|> List.map (fun i -> i.Offset)
|> List.map (fun i -> string i)
div [Key comp.Id] [
// let label' = extractLabelBase comp.Label
// TODO: normalise labels so they only contain allowed chars all uppercase
@ -418,24 +433,66 @@ let viewSelectedComponent (model: ModelType.Model) dispatch =
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
)
let items =
List.map (fun i ->
textFormField required "Component Rent" i (fun text ->
// TODO: removed formatLabel for now
textFormField required "Component STransform" stransform (fun text ->
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text)
match formatLabelText text with
| Some label ->
| Some label ->
setComponentLabel model sheetDispatch comp label //TODO: Fix this part to update STransform
dispatch <| SetPopupDialogText (Some label)
| None -> ()
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
)
textFormField required "Component Port" portName[0] (fun text ->
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text)
match formatLabelText text with
| Some label ->
setComponentLabel model sheetDispatch comp label
dispatch <| SetPopupDialogText (Some label)
| None -> ()
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
)) ports
printf "%A" items
match items with
| [x] -> x
| _ -> nothing
)
textFormField required "Component Port" portSide[0] (fun text ->
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text)
match formatLabelText text with
| Some label ->
setComponentLabel model sheetDispatch comp label
dispatch <| SetPopupDialogText (Some label)
| None -> ()
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
)
textFormField required "Component Port" portOffset[0] (fun text ->
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text)
match formatLabelText text with
| Some label ->
setComponentLabel model sheetDispatch comp label
dispatch <| SetPopupDialogText (Some label)
| None -> ()
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
)
// let items =
// List.map (fun i ->
// textFormField required "Component Rent" i (fun text ->
//// TODO: removed formatLabel for now
// //setComponentLabel model sheetDispatch comp (formatLabel comp text)
// match formatLabelText text with
// | Some label ->
// setComponentLabel model sheetDispatch comp label
// dispatch <| SetPopupDialogText (Some label)
// | None -> ()
// //updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch
// dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component
// )) ports
// match items with
// | [x] -> x
// | _ -> nothing
]
| _ -> div [] [ str "Select a component in the diagram to view or change its properties, for example number of bits." ]