Updated Rotation Shortcut for keyboard.

This commit is contained in:
Giorgos Vyronos 2022-02-21 21:33:46 +00:00
parent 6c066b4754
commit 429e038ad5
4 changed files with 579 additions and 15077 deletions

15627
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
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
type Msg =
| Wire of BusWire.Msg
@ -856,6 +856,11 @@ 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.
wireCmd (BusWire.CopyWires model.SelectedWires)
]
| KeyPress Rotate ->
model,
Cmd.batch [
symbolCmd (Symbol.RotateSymbols model.SelectedComponents) // Rotate 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

@ -3,6 +3,8 @@ This module draws schematics component symbols. Each symbol is associated with a
*)
module Symbol
open Electron
open ElectronAPI
open Fable.React
open Fable.React.Props
open Elmish
@ -19,6 +21,7 @@ let GridSize = 30
type Symbol =
{
Pos: XYPos
STransform: int // Describes how symbol is rotated/flipped (0 -> 0 deg, 1 -> 90 deg, 2 -> 180 deg, -> 3 -> 270 deg).
InWidth0: int option
InWidth1: int option
Id : ComponentId
@ -30,6 +33,11 @@ type Symbol =
Moving: bool
}
type PortOrientation = {
side: int // Designated which side of symbol port is on (0 -> right, 1 -> top, 2 -> left, 3 -> bottom). to have coherency with STransform.
}
type Model = {
Symbols: Map<ComponentId, Symbol>
CopiedSymbols: Map<ComponentId, Symbol>
@ -53,6 +61,7 @@ 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.
| SymbolsHaveError of sIds: ComponentId list
| ChangeLabel of sId : ComponentId * newLabel : string
| PasteSymbols of sIds: ComponentId list
@ -248,6 +257,7 @@ let createNewSymbol (pos: XYPos) (comptype: ComponentType) (label:string) =
let comp = makeComp pos comptype id label
{
Pos = { X = pos.X - float comp.W / 2.0; Y = pos.Y - float comp.H / 2.0 }
STransform = 0;
ShowInputPorts = false
ShowOutputPorts = false
InWidth0 = None // set by BusWire
@ -919,6 +929,15 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> =
(List.fold (fun prevSymbols sId -> Map.add sId {resetSymbols[sId] with Colour = "lightgreen"} prevSymbols) resetSymbols compList)
{ model with Symbols = newSymbols }, Cmd.none
| RotateSymbols compList -> //select a symbol to Rotate
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
let newSymbols =
// if ctrl is pressed make yellow initially, then try to change STransform for every time ctrl+R is pressed
List.fold (fun prevSymbols sId ->
Map.add sId {model.Symbols[sId] with STransform = model.Symbols[sId].STransform + 1} prevSymbols) resetSymbols compList
printf "Rotated"
{ model with Symbols = newSymbols }, Cmd.none
| ErrorSymbols (errorCompList,selectCompList,isDragAndDrop) ->
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
let selectSymbols =
@ -983,6 +1002,7 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> =
comp.H, comp.W
ComponentId comp.Id,
{ Pos = xyPos
STransform = 0
ShowInputPorts = false //do not show input ports initially
ShowOutputPorts = false //do not show output ports initially
Colour = "lightgrey" // initial color

View file

@ -148,6 +148,8 @@ let viewMenu dispatch =
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)
menuSeparator
makeItem "Rotate Symbol" (Some "Shift+R") (fun ev -> dispatch Sheet.KeyboardMsg.Rotate)
menuSeparator
makeCondItem (JSHelpers.debugLevel <> 0) "Toggle Dev Tools" (Some devToolsKey) (fun _ ->
renderer.ipcRenderer.send("toggle-dev-tools", [||]) |> ignore)
]