~cypheon/kicad2spice

f7dc604c385847a61a110ccc4c8f4a529d5406b0 — Johann Rudloff 4 years ago 82eecfd
Fix net joining logic.
2 files changed, 19 insertions(+), 8 deletions(-)

M lib/connectiongraph.ml
M lib/dune
M lib/connectiongraph.ml => lib/connectiongraph.ml +19 -7
@@ 31,8 31,8 @@ module Netlist = struct
  }

  let show n =
    Hashtbl.to_seq n.nets
    |> Seq.map (fun (net, sg) -> Printf.sprintf "Net \"%s\":\n%s" net (Subgraph.show sg))
    Hashtbl.to_seq n.point_net_map
    |> Seq.map (fun (pt, net) -> Printf.sprintf "Net \"%s\" @ (%s):\n%s" net (show_point2i pt) (Subgraph.show (Hashtbl.find n.nets net)))
    |> of_seq
    |> String.concat "\n===\n"



@@ 101,8 101,8 @@ let get_pins comp =
let rec get_minpoint (netmap: (point2i, point2i) Hashtbl.t) (pt : point2i) =
  match Hashtbl.find_opt netmap pt with
  | Some minpoint -> (
      if minpoint = pt then pt
      else (assert ((Stdlib.compare minpoint pt) = -1); get_minpoint netmap minpoint)
    if minpoint = pt then (Printf.printf "TRACE minpoint: %s == %s\n" (show_point2i pt) (show_point2i minpoint); pt)
      else (Printf.printf "TRACE minpoint: %s -> %s\n" (show_point2i pt) (show_point2i minpoint);assert ((Stdlib.compare minpoint pt) = -1); get_minpoint netmap minpoint)
  )
  | None -> pt



@@ 120,16 120,27 @@ let make_netmap schematic : (point2i, point2i) Hashtbl.t =
        Hashtbl.replace minpoint_map startp minpoint;
        Hashtbl.replace minpoint_map endp minpoint;
        Printf.printf "processing wire: %s\n" (Wire.show _w);
        Printf.printf "join: (%s) -> (%s)\n" (show_point2i startp) (show_point2i minpoint);
        Printf.printf "join: (%s) -> (%s)\n" (show_point2i endp) (show_point2i minpoint)
        Printf.printf "join: (%s) -> (%s) [oldmin_start]\n" (show_point2i old_minpoint_start) (show_point2i minpoint);
        Printf.printf "join: (%s) -> (%s) [oldmin_end]\n" (show_point2i old_minpoint_end) (show_point2i minpoint);
        Printf.printf "join: (%s) -> (%s) [start]\n" (show_point2i startp) (show_point2i minpoint);
        Printf.printf "join: (%s) -> (%s) [end]\n" (show_point2i endp) (show_point2i minpoint)
    | Item.Comp c when c.part.power ->
        assert (length c.part.pins = 1);
        let pin = (nth (get_pins c) 0) in
        let net_point = Stdlib.Option.value (Hashtbl.find_opt named_nets pin.name) ~default:pin.pos in
        let new_minpoint = min (get_minpoint minpoint_map net_point) (get_minpoint minpoint_map pin.pos) in
        let old_minpoint = get_minpoint minpoint_map pin.pos in
        let old_net_minpoint = get_minpoint minpoint_map net_point in
        let new_minpoint = min old_net_minpoint old_minpoint in
        Hashtbl.replace minpoint_map old_minpoint new_minpoint;
        Hashtbl.replace minpoint_map old_net_minpoint new_minpoint;
        Hashtbl.replace minpoint_map net_point new_minpoint;
        Hashtbl.replace minpoint_map pin.pos new_minpoint;
        Hashtbl.replace named_nets pin.name new_minpoint;
        Printf.printf "processing power pin: %s\n" (Comp.show c);
        Printf.printf "join: (%s) -> (%s) [old_minpoint]\n" (show_point2i old_minpoint) (show_point2i new_minpoint);
        Printf.printf "join: (%s) -> (%s) [net_point]\n" (show_point2i net_point) (show_point2i new_minpoint);
        Printf.printf "join: (%s) -> (%s) [pin.pos]\n" (show_point2i pin.pos) (show_point2i new_minpoint);
        Printf.printf "join: (%s) -> (%s) [named_nets]\n" (pin.name) (show_point2i new_minpoint)
    | _ -> ()
    ) schematic.items;
  minpoint_map


@@ 142,6 153,7 @@ let connection schematic =
  iter ( fun item -> match item with
    | Item.Comp c ->
        iter ( fun pin ->
          Printf.printf "connectiongraph processing component pin: %s %s\n" (Comp.show c) (Pin.show pin);
          (* TODO: this is not correct! We need to insert a comp*pin pair *)
          Hashtbl.replace point_map pin.Pin.pos (Item.Comp c);
          let minpoint = get_minpoint netmap pin.Pin.pos in

M lib/dune => lib/dune +0 -1
@@ 5,7 5,6 @@
  (preprocess (pps ppx_deriving.show ppx_compare))
  )
(menhir
  (flags --trace)
  (modules sch_legacy parse_lib parse_sexp))
(ocamllex lex_sch_legacy)
(ocamllex lex_tokenize)