Moved Group updates to group branch.

This commit is contained in:
Giorgos Vyronos 2022-03-12 10:39:30 +00:00
parent c13b88b94d
commit 64f5654fdc
4 changed files with 195 additions and 175 deletions

View file

@ -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))

View file

@ -1,6 +1,4 @@
//MAIN TODO: STORE ROTATION TO USE WHEN LOADING THE SYMBOLS// //---------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------//
//--------------------AP1919 CODE SECTION STARTS-------------------------------------// //--------------------AP1919 CODE SECTION STARTS-------------------------------------//
//---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------//
@ -81,6 +79,7 @@ type Msg =
| FlipVSymbols of ComponentId list //First Attempt at implementing a way to flip symbol vertically. | FlipVSymbols of ComponentId list //First Attempt at implementing a way to flip symbol vertically.
| SymbolsHaveError of sIds: ComponentId list | SymbolsHaveError of sIds: ComponentId list
| ChangeLabel of sId : ComponentId * newLabel : string | ChangeLabel of sId : ComponentId * newLabel : string
| ChangePort of sId : ComponentId * portName: string * portSide:string
| PasteSymbols of sIds: ComponentId list | PasteSymbols of sIds: ComponentId list
| ColorSymbols of compList : ComponentId list * colour : HighLightColor | ColorSymbols of compList : ComponentId list * colour : HighLightColor
| ErrorSymbols of errorIds: ComponentId list * selectIds: ComponentId list * isDragAndDrop: bool | ErrorSymbols of errorIds: ComponentId list * selectIds: ComponentId list * isDragAndDrop: bool
@ -92,7 +91,7 @@ type Msg =
| WriteMemoryLine of ComponentId * int64 * int64 // For Issie Integration | WriteMemoryLine of ComponentId * int64 * int64 // For Issie Integration
| WriteMemoryType of ComponentId * ComponentType | WriteMemoryType of ComponentId * ComponentType
//---------------------------------helper types and functions----------------// //---------------------------------helper types and fuFnctions----------------//
let posDiff (a:XYPos) (b:XYPos) = let posDiff (a:XYPos) (b:XYPos) =
{X=a.X-b.X; Y=a.Y-b.Y} {X=a.X-b.X; Y=a.Y-b.Y}
@ -436,15 +435,17 @@ let rotatePortMap (map:Map<string,PortOrientationOffset>) (symbol:Symbol) =
|_ -> rotatePortMap' map symbol |_ -> rotatePortMap' map symbol
let flipHPortMap (map:Map<string,PortOrientationOffset>) (symbol:Symbol) = let flipHPortMap (map:Map<string,PortOrientationOffset>) (symbol:Symbol) =
map |> Map.map (fun key port -> map |> Map.map (fun key port ->
match port.Side with match port.Side with
|Right -> {port with Side=Left} |Right -> {port with Side=Left}
|Left -> {port with Side=Right} |Left -> {port with Side=Right}
|_ -> port |_ -> port)
)
let flipVPortMap (map:Map<string,PortOrientationOffset>) (symbol:Symbol) =
failwithf "Not implemented Yet"
let changePortSide (map:Map<string,PortOrientationOffset>) (portName: string) (newSide:PortOrientation) (symbol:Symbol) = let changePortSide (map:Map<string,PortOrientationOffset>) (portName: string) (newSide:PortOrientation) (symbol:Symbol) =
let rev map: Map<string,string> = let rev map: Map<string,string> =
@ -492,13 +493,13 @@ let getMaxPortNameLength (map:Map<string,string>) =
if List.isEmpty labelList then 0 //if a component has no inputs or outputs list max will fail if List.isEmpty labelList then 0 //if a component has no inputs or outputs list max will fail
else List.max labelList else List.max labelList
//find max name.length in all ports, not input + output //find max name.length in all ports, not input + output
//height is defined by (max_ton_ports_se_Right_kai_left + 2) => gap gia port names on top/bottom //height is defined by (max_ton_ports_se_Right_kai_left + 2) => gap gia port names on top/bottom
//width = max_name_size + max_name_size + (max_name_size) * max_ton_ports_se_top_kai_bottom //width = max_name_size + max_name_size + (max_name_size) * max_ton_ports_se_top_kai_bottom
////////// LEFT RIGTH TOP/BOTTOM ////////// LEFT RIGTH TOP/BOTTOM
//Rearrange map //Rearrange map
//otan allazei ena port thelei -> let symbol' = {symbol with map = changeportside} -> let symbol'' = {redefineCustomHW} -> {symbol'' with map = redefineportmap} //otan allazei ena port thelei -> let symbol' = {symbol with map = changeportside} -> let symbol'' = {redefineCustomHW} -> {symbol'' with map = redefineportmap}
let redefineCustomHW symbol = let redefineCustomHW symbol =
// let altercomponent comp nh nw = // let altercomponent comp nh nw =
@ -510,8 +511,8 @@ let redefineCustomHW symbol =
let r,b,l,t = countsides symbol.APortOffsetsMap let r,b,l,t = countsides symbol.APortOffsetsMap
let maxRL = max r l let maxRL = max r l
let maxTB = max t b let maxTB = max t b
let heightNew = GridSize + GridSize * maxRL let heightNew = 100 //GridSize + GridSize * maxRL
let widthNew = maxname*2 + maxname*maxTB let widthNew = max (maxname*2 + maxname*maxTB) (GridSize * 4) //maxname*2 + maxname*maxTB
let newcompo = {symbol.Compo with H = heightNew} let newcompo = {symbol.Compo with H = heightNew}
let newcompo'= {newcompo with W = widthNew} let newcompo'= {newcompo with W = widthNew}
{symbol with Compo = newcompo'} {symbol with Compo = newcompo'}
@ -529,6 +530,7 @@ let redefineCustomPorts symbol (map:Map<string,PortOrientationOffset>) : Map<str
let gap = 1.0 let gap = 1.0
let offY = (float(h))* (( float(index) + gap )/( float( all ) + 2.0*gap - 1.0)) // the ports are created so that they are equidistant let offY = (float(h))* (( float(index) + gap )/( float( all ) + 2.0*gap - 1.0)) // the ports are created so that they are equidistant
let offX = (float(w))* (( float(index) + gap )/( float( all ) + 2.0*gap - 1.0)) let offX = (float(w))* (( float(index) + gap )/( float( all ) + 2.0*gap - 1.0))
// {X=50.0;Y=50.0}
match side with match side with
|Left -> {X=0.0;Y=offY} |Left -> {X=0.0;Y=offY}
|Top -> {X=offX;Y=0.0} |Top -> {X=offX;Y=0.0}
@ -544,15 +546,27 @@ let redefineCustomPorts symbol (map:Map<string,PortOrientationOffset>) : Map<str
let mutable ib = 0 let mutable ib = 0
let r,b,l,t = countsides map let r,b,l,t = countsides map
let w,h = symbol.Compo.W, symbol.Compo.H //it needs the new height and width here based on spec above let w,h = symbol.Compo.W, symbol.Compo.H //it needs the new height and width here based on spec above
let valuesNew = [] let mutable valuesNew = []
for v in values do for v in values do
valuesNew @ [{Side=v.Side;Offset=(customOffsetHelper w h v.Side il ir it ib r l b t)}] |> ignore valuesNew <- (valuesNew @ [{Side=v.Side;Offset=(customOffsetHelper w h v.Side il ir it ib r l b t)}])
if v.Side = Right then ir <- ir+1 if v.Side = Right then ir <- ir+1
else if v.Side = Left then il <- il+1 else if v.Side = Left then il <- il+1
else if v.Side = Top then it <- it+1 else if v.Side = Top then it <- it+1
else ib <- ib+1 else ib <- ib+1
// printf $"IL: %i{il}"
// printf $"New Y Offset: %f{valuesNew[0].Offset.Y}"
// for i in valuesNew do
// printf $"New Y Offset: %f{i.Offset.Y}"
// valuesNew // valuesNew
(keys, valuesNew) ||> List.map2 (fun x y -> (x,y)) |> Map.ofList (keys, valuesNew) ||> List.map2 (fun x y -> (x,y)) |> Map.ofList
// map
//----------------------------------------ROTATION HELPERS----------------------------------------------- //----------------------------------------ROTATION HELPERS-----------------------------------------------
///Symbol Points rotation function ///Symbol Points rotation function
@ -1306,18 +1320,23 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> =
// The selected symbol is rotated by incrementing Stransform rotation and updating new APortOffsetsMap and Symbol Pos // The selected symbol is rotated by incrementing Stransform rotation and updating new APortOffsetsMap and Symbol Pos
List.fold (fun prevSymbols sId -> List.fold (fun prevSymbols sId ->
Map.add sId {model.Symbols[sId] with STransform = stransform_fsm(model.Symbols[sId].STransform); APortOffsetsMap = rotatePortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList Map.add sId {model.Symbols[sId] with STransform = stransform_fsm(model.Symbols[sId].STransform); APortOffsetsMap = rotatePortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList
let result = (canvasPortLocation(model.Symbols[compList[0]]))
//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 { model with Symbols = newSymbols }, Cmd.none
| FlipHSymbols compList -> // NEW: flip a symbol Horizontally | FlipHSymbols compList -> // NEW: flip a symbol Horizontally
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
{ model with Symbols = resetSymbols }, Cmd.none let newSymbols =
// The selected symbol is rotated by incrementing Stransform rotation and updating new APortOffsetsMap and Symbol Pos
List.fold (fun prevSymbols sId ->
Map.add sId {model.Symbols[sId] with STransform = stransform_fsm(stransform_fsm(model.Symbols[sId].STransform)); APortOffsetsMap = flipHPortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList
{ model with Symbols = newSymbols }, Cmd.none
| FlipVSymbols compList -> | FlipVSymbols compList ->
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
{ model with Symbols = resetSymbols }, Cmd.none let newSymbols =
// The selected symbol is rotated by incrementing Stransform rotation and updating new APortOffsetsMap and Symbol Pos
List.fold (fun prevSymbols sId ->
Map.add sId {model.Symbols[sId] with STransform = stransform_fsm(stransform_fsm(model.Symbols[sId].STransform)); APortOffsetsMap = flipVPortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList
{ model with Symbols = newSymbols }, Cmd.none
| ErrorSymbols (errorCompList,selectCompList,isDragAndDrop) -> | ErrorSymbols (errorCompList,selectCompList,isDragAndDrop) ->
let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols
@ -1339,6 +1358,24 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> =
let newcompo = {tempsym.Compo with Label = newLabel} let newcompo = {tempsym.Compo with Label = newLabel}
let addsym = {tempsym with Compo = newcompo} let addsym = {tempsym with Compo = newcompo}
{ model with Symbols = Map.add sId addsym model.Symbols }, Cmd.none { model with Symbols = Map.add sId addsym model.Symbols }, Cmd.none
| ChangePort (sId, portName, portSide) ->
let tempsym = Map.find sId model.Symbols
printf $"Selected Port: %s{portName}"
printf $"Selected Side: %s{portSide}"
let newSide =
match portSide with
| "Top" -> Top
| "Bottom" -> Bottom
| "Left" -> Left
| "Right" -> Right
| _ -> failwithf "Side not implemented"
let symbol' = {tempsym with APortOffsetsMap = (changePortSide tempsym.APortOffsetsMap portName newSide tempsym)}
//let symbol'' = {redefineCustomHW} ->
let symbol'' = redefineCustomHW symbol'
//{symbol'' with map = redefineportmap}
let symbol''' = {symbol'' with APortOffsetsMap = redefineCustomPorts symbol'' symbol'.APortOffsetsMap}
{ model with Symbols = Map.add sId symbol''' model.Symbols }, Cmd.none
| PasteSymbols compList -> | PasteSymbols compList ->
let newSymbols = let newSymbols =

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,7 +385,7 @@ 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)
@ -392,107 +394,81 @@ let viewSelectedComponent (model: ModelType.Model) dispatch =
|> 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 // Extract Component : function in Symbol.fs 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 sym = Symbol.extractSymbol model.Sheet.Wire.Symbol compId // Extract Symbol : function in Symbol.fs
let stransform = string sym.STransform let namesPortRaw = Symbol.portNamesMap comp
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] [ 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
) )
textFormField required "Component STransform" stransform (fun text -> // Control when the namesPortRaw map can be accessed else return normal name of port
// TODO: removed formatLabel for now let allowedDescription = match comp.Type with | NbitsAdder _ | Decode4 | Register _ |DFF| RegisterE _ |DFFE| ROM1 _ |AsyncROM1 _ | RAM1 _ | AsyncRAM1 _ | Mux2 | Demux2 | NbitsXor _ | Custom _ -> true | _ -> false
//setComponentLabel model sheetDispatch comp (formatLabel comp text) let ports =
match formatLabelText text with sym.APortOffsetsMap
| Some label -> |> Map.toList
setComponentLabel model sheetDispatch comp label //TODO: Fix this part to update STransform let portNameLst =
dispatch <| SetPopupDialogText (Some label) ports
| None -> () |> List.map fst
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch |> List.map (fun key -> if allowedDescription then namesPortRaw[key] else key)
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component let portSideLst = ["Top";"Left";"Bottom";"Right"]
)
textFormField required "Component Port" portName[0] (fun text -> //Already done for custom symbols
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text) // let portDescription (i:string) : ReactElement =
match formatLabelText text with // Label.label [] [ h2 [] [str i ]]
| Some label -> //
setComponentLabel model sheetDispatch comp label //
dispatch <| SetPopupDialogText (Some label) // Field.div [] [
| None -> () // Label.label [] [ str "Component Ports" ]
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch // g [] (Seq.map portDescription portNameLst)
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component // ]
) let mutable portName = ""
textFormField required "Component Port" portSide[0] (fun text -> let mutable portSide = ""
// TODO: removed formatLabel for now
//setComponentLabel model sheetDispatch comp (formatLabel comp text) let dropDown (available:bool) (name:string) (lst:string list): ReactElement =
match formatLabelText text with if available then
| Some label -> Field.div [] [
setComponentLabel model sheetDispatch comp label Label.label [] [ str name ]
dispatch <| SetPopupDialogText (Some label) Label.label [ ]
| None -> () [Select.select []
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch [ select [(OnChange(fun option ->
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component 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"
textFormField required "Component Port" portOffset[0] (fun text -> | "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"
// TODO: removed formatLabel for now | _ -> failwithf "Case not an option"
//setComponentLabel model sheetDispatch comp (formatLabel comp text) ))]
match formatLabelText text with
| Some label -> ([option [Value "";Selected true;Disabled true] [str ("Choose " + string name)]] @ List.map(fun value -> option [Value value] [str value]) lst)
setComponentLabel model sheetDispatch comp label ]
dispatch <| SetPopupDialogText (Some label) ]
| None -> () ]
//updateNames model (fun _ _ -> model.WaveSim.Ports) |> StartWaveSim |> dispatch else
dispatch (ReloadSelectedComponent model.LastUsedDialogWidth) // reload the new component Field.div [] []
) dropDown allowedDescription "Port" portNameLst
// let items = dropDown allowedDescription "Side" portSideLst
// 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." ] | _ -> div [] [ str "Select a component in the diagram to view or change its properties, for example number of bits." ]