From c13b88b94d4c2837b1fb1b187613570c998a91ff Mon Sep 17 00:00:00 2001 From: Giorgos Vyronos Date: Thu, 10 Mar 2022 11:41:00 +0000 Subject: [PATCH] Updates for new branch --- src/Renderer/DrawBlock/Sheet.fs | 12 +++- src/Renderer/DrawBlock/Symbol.fs | 14 ++++- src/Renderer/Renderer.fs | 2 + src/Renderer/UI/SelectedComponentView.fs | 79 ++++++++++++++++++++---- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/Renderer/DrawBlock/Sheet.fs b/src/Renderer/DrawBlock/Sheet.fs index d4d8db5..ed697ce 100644 --- a/src/Renderer/DrawBlock/Sheet.fs +++ b/src/Renderer/DrawBlock/Sheet.fs @@ -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 = 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 diff --git a/src/Renderer/DrawBlock/Symbol.fs b/src/Renderer/DrawBlock/Symbol.fs index d8b3ea3..5371804 100644 --- a/src/Renderer/DrawBlock/Symbol.fs +++ b/src/Renderer/DrawBlock/Symbol.fs @@ -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 = diff --git a/src/Renderer/Renderer.fs b/src/Renderer/Renderer.fs index 3aeea96..cf3e36e 100644 --- a/src/Renderer/Renderer.fs +++ b/src/Renderer/Renderer.fs @@ -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) diff --git a/src/Renderer/UI/SelectedComponentView.fs b/src/Renderer/UI/SelectedComponentView.fs index fc10f05..2ccefc8 100644 --- a/src/Renderer/UI/SelectedComponentView.fs +++ b/src/Renderer/UI/SelectedComponentView.fs @@ -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." ]