diff --git a/src/Renderer/DrawBlock/BusWire.fs b/src/Renderer/DrawBlock/BusWire.fs index 4750e8c..e6902d2 100644 --- a/src/Renderer/DrawBlock/BusWire.fs +++ b/src/Renderer/DrawBlock/BusWire.fs @@ -404,8 +404,8 @@ let initialWireVerticesFromPorts (startPort:XYPos) (endPort:XYPos) (routetype:ro {X = endX; Y = endY-Wire.stickLength}; {X = endX; Y = endY} ], false - |Sameside -> - if endX-startX >= Wire.stickLength*2.0 && endY >= startY then + | Sameside -> + if abs (endX-startX) >= Wire.stickLength*2.0 && endY >= startY then [ {X = startX; Y = startY}; {X = startX ; Y = startY- Wire.stickLength}; @@ -416,7 +416,7 @@ let initialWireVerticesFromPorts (startPort:XYPos) (endPort:XYPos) (routetype:ro {X = endX ; Y = endY-Wire.stickLength} {X = endX; Y = endY} ], true - elif endX-startX >= Wire.stickLength*2.0 then + elif abs (endX-startX) >= Wire.stickLength*2.0 then [ {X = startX; Y = startY}; {X = startX ; Y = startY- Wire.stickLength}; @@ -715,7 +715,7 @@ let makeInitialASegList (hostId: ConnectionId) xyPairs |> convertVerticesToASegs hostId isLeftToRight routetype rotation yreflect outputPortPos // TODO: native RISeg implementation -/// Initial list of rotation invariant segments based on positions of ports to be connected +// Initial list of rotation invariant segments based on positions of ports to be connected // let makeInitialRISegList (hostId: ConnectionId) (portCoords: XYPos * XYPos) : RISeg list = // makeInitialASegList hostId portCoords // |> List.map aSegToRISeg diff --git a/src/Renderer/DrawBlock/Sheet.fs b/src/Renderer/DrawBlock/Sheet.fs index 6ff69c1..e5bf688 100644 --- a/src/Renderer/DrawBlock/Sheet.fs +++ b/src/Renderer/DrawBlock/Sheet.fs @@ -171,7 +171,8 @@ type Model = { /// Change the Port Side of Component specified by compId to lbl member this.ChangePort (dispatch: Dispatch) (compId: ComponentId) (portName: string) (portSide: string) = - dispatch <| (Wire (BusWire.Symbol (Symbol.ChangePort (compId, portName,portSide) ) ) ) + dispatch <| (Wire (BusWire.Symbol (Symbol.ChangePort (compId, portName,portSide) ) ) ) + dispatch <| (Wire (BusWire.UpdateWires ([compId], {X = 0.0; Y = 0.0}))) /// Run Bus Width Inference check member this.DoBusWidthInference dispatch = @@ -862,6 +863,7 @@ let update (msg : Msg) (model : Model): Model*Cmd = model, Cmd.batch [ symbolCmd (Symbol.RotateSymbols model.SelectedComponents) // Rotate Symbol using keyboard combination + wireCmd (BusWire.UpdateWires (model.SelectedComponents, {X = 0.0; Y = 0.0})) ] | KeyPress FlipV -> model, diff --git a/src/Renderer/DrawBlock/Symbol.fs b/src/Renderer/DrawBlock/Symbol.fs index 87b60b8..d643fa5 100644 --- a/src/Renderer/DrawBlock/Symbol.fs +++ b/src/Renderer/DrawBlock/Symbol.fs @@ -114,14 +114,19 @@ let posAdd (a:XYPos) (b:XYPos) = let posOf x y = {X=x;Y=y} //STransform Finite State Machine -let stransform_fsm(prev_state:Rotation):Rotation = - match prev_state with - | R0 -> R90 - | R90 -> R180 - | R180 -> R270 - | R270 -> R0 +let stransform_fsm (prev_state:Rotation) (comp: ComponentType) : Rotation = + let stransformUpdate(prev_state:Rotation):Rotation = + match prev_state with + | R0 -> R90 + | R90 -> R180 + | R180 -> R270 + | R270 -> R0 + match comp with + |Custom _ |MergeWires |SplitWire _ -> prev_state + |_ -> stransformUpdate prev_state + let orientationEncoder (orientation:PortOrientation) : int = match orientation with | Right -> 0 @@ -683,7 +688,7 @@ let DrawPorts (portMap: Map) o (showInput:bool) (s match key,port with |k,{Side=side;Offset={X=x;Y=y}} -> if (k[0] = 'I' && showInput) || (k[0]='O' && showOutput) then makeCircle x y portCircle else nothing ) - mid |> Map.values |> List.ofSeq + mid |> Map.toList |> List.map snd ///Draw the corresponding text of all ports contained in APortOffsetMap let DrawPortsText (portMap:Map) (comp: Component) symbol orientation = @@ -698,7 +703,7 @@ let DrawPortsText (portMap:Map) (comp: Component) |Bottom -> (addText (port.Offset.X) (port.Offset.Y-20.0) name "Middle" "normal" "12px")[0] //they are added in a list at the end |Left-> (addText (port.Offset.X+5.0) (port.Offset.Y-7.0) name "start" "normal" "12px")[0] |Top -> (addText (port.Offset.X) (port.Offset.Y+7.0) name "Middle" "normal" "12px")[0] ) - mid |> Map.values |> List.ofSeq + mid |> Map.toList |> List.map snd let private createPolygon points colour opacity = @@ -805,8 +810,8 @@ let drawSymbol (symbol:Symbol) (comp:Component) (colour:string) (showInputPorts: | Input _ -> rotatePoints [0.0; 0.0; (w*0.66); 0.0; w; h/2.0; (w*0.66); h; 0.0; h] rotation | Constant1 _ -> rotatePoints [0.0; 0.0; (w/2.0); (h/2.0); 0.0; h] rotation | IOLabel -> rotatePoints [(w*0.33); 0.0; (w*0.66); 0.0; w; (h/2.0); (w*0.66); h; (w*0.33); h; 0.0; (h/2.0)] rotation - | Output _ -> rotatePoints [0.0; 0.0; (w*0.66); 0.0; w; (h/2.0); (w*0.66); h; 0.0; h] (stransform_fsm(stransform_fsm(rotation))) //hack for rotation to work -> same as input but rotated twice - | Viewer _ -> rotatePoints [0.0; 0.0; (w*0.8); 0.0; w; (h/2.0); (w*0.8); h; 0.0; h] (stransform_fsm(stransform_fsm(rotation))) //hack for rotation to work -> same as input (resized) but rotated twice + | Output _ -> rotatePoints [0.0; 0.0; (w*0.66); 0.0; w; (h/2.0); (w*0.66); h; 0.0; h] (stransform_fsm(stransform_fsm rotation comp.Type) comp.Type) //hack for rotation to work -> same as input but rotated twice + | Viewer _ -> rotatePoints [0.0; 0.0; (w*0.8); 0.0; w; (h/2.0); (w*0.8); h; 0.0; h] (stransform_fsm(stransform_fsm rotation comp.Type) comp.Type) //hack for rotation to work -> same as input (resized) but rotated twice | MergeWires -> [(w/2.0); ((1.0/6.0)*h); (w/2.0); ((5.0/6.0)*h)] //add it to rotatePoints function when implemented | SplitWire _ -> [(w/2.0); ((1.0/6.0)*h); (w/2.0); ((5.0/6.0)*h); 0.0] //add it to rotatePoints function when implemented | Demux2 -> rotatePoints [0.0; (h*0.2); w; 0.0; w; h; 0.0; (h*0.8)] rotation @@ -814,6 +819,7 @@ let drawSymbol (symbol:Symbol) (comp:Component) (colour:string) (showInputPorts: // EXTENSION: |Mux4|Mux8 ->(sprintf "%i,%i %i,%f %i,%f %i,%i" 0 0 w (float(h)*0.2) w (float(h)*0.8) 0 h ) // EXTENSION: | Demux4 |Demux8 -> (sprintf "%i,%f %i,%f %i,%i %i,%i" 0 (float(h)*0.2) 0 (float(h)*0.8) w h w 0) | BusSelection _ |BusCompare _ -> rotatePoints [0.0; 0.0; (0.6*w); 0.0; (0.8*w); (0.3*h); w; (0.3*h); w; (0.7*h); (0.8*w); (0.7*h); (0.6*w); h; 0.0; h] rotation + | Custom _ -> [0.0; 0.0; w; 0.0; w; h; 0.0; h] | _ -> rotatePoints [0.0; 0.0; w; 0.0; w; h; 0.0; h] rotation // Helper function to add certain characteristics on specific symbols (inverter, enables, clocks) @@ -1372,23 +1378,39 @@ let update (msg : Msg) (model : Model): Model*Cmd<'a> = List.fold (fun prevSymbols sId -> let compo = model.Symbols[sId].Compo // let hR,wR = match stransform_fsm(model.Symbols[sId].STransform) with |R90|R270 -> compo.W,compo.H |_ -> compo.H,compo.W - let newcompo = {compo with R = stransform_fsm (model.Symbols[sId].STransform);} - Map.add sId {model.Symbols[sId] with Compo = newcompo ; STransform = stransform_fsm(model.Symbols[sId].STransform); APortOffsetsMap = rotatePortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList + let newcompo = {compo with R = stransform_fsm model.Symbols[sId].STransform compo.Type ;} + Map.add sId {model.Symbols[sId] with Compo = newcompo ; STransform = stransform_fsm model.Symbols[sId].STransform compo.Type ; APortOffsetsMap = rotatePortMap model.Symbols[sId].APortOffsetsMap model.Symbols[sId]} prevSymbols) resetSymbols compList { model with Symbols = newSymbols }, Cmd.none + //////////////PENDING/////////////////// + + // | FlipHSymbols compList -> // NEW: flip a symbol Horizontally + // let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols + // 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 -> + // let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols + // 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 + | FlipHSymbols compList -> // NEW: flip a symbol Horizontally let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols 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 + Map.add sId model.Symbols[sId] prevSymbols) resetSymbols compList //NEED TO DO APPROPRIATE CHANGES HERE, SEE ROTATION FOR INSPIRATION { model with Symbols = newSymbols }, Cmd.none | FlipVSymbols compList -> let resetSymbols = Map.map (fun _ sym -> { sym with Colour = "Lightgray"; Opacity = 1.0 }) model.Symbols 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 + Map.add sId model.Symbols[sId] prevSymbols) resetSymbols compList //NEED TO DO APPROPRIATE CHANGES HERE, SEE ROTATION FOR INSPIRATION { model with Symbols = newSymbols }, Cmd.none | ErrorSymbols (errorCompList,selectCompList,isDragAndDrop) ->