コード例 #1
0
ファイル: Wiring.java プロジェクト: nick-less/freerouting
 /**
  * Maybe trace of type turret without net in Mentor design. Try to assig the net by calculating
  * the overlaps.
  */
 private void try_correct_net(Item p_item) {
   if (!(p_item instanceof Trace)) {
     return;
   }
   Trace curr_trace = (Trace) p_item;
   java.util.Set<Item> contacts = curr_trace.get_normal_contacts(curr_trace.first_corner(), true);
   contacts.addAll(curr_trace.get_normal_contacts(curr_trace.last_corner(), true));
   int corrected_net_no = 0;
   for (Item curr_contact : contacts) {
     if (curr_contact.net_count() == 1) {
       corrected_net_no = curr_contact.get_net_no(0);
       break;
     }
   }
   if (corrected_net_no != 0) {
     p_item.assign_net_no(corrected_net_no);
   }
 }
コード例 #2
0
ファイル: Wiring.java プロジェクト: nick-less/freerouting
  private Item read_wire_scope(ReadScopeParameter p_par) {
    Net.Id net_id = null;
    String clearance_class_name = null;
    board.FixedState fixed = board.FixedState.UNFIXED;
    Path path = null; // Used, if a trace is read.
    Shape border_shape = null; // Used, if a conduction area is read.
    Collection<Shape> hole_list = new LinkedList<Shape>();
    Object next_token = null;
    for (; ; ) {
      Object prev_token = next_token;
      try {
        next_token = p_par.scanner.next_token();
      } catch (java.io.IOException e) {
        System.out.println("Wiring.read_wire_scope: IO error scanning file");
        return null;
      }
      if (next_token == null) {
        System.out.println("Wiring.read_wire_scope: unexpected end of file");
        return null;
      }
      if (next_token == CLOSED_BRACKET) {
        // end of scope
        break;
      }
      if (prev_token == OPEN_BRACKET) {
        if (next_token == Keyword.POLYGON_PATH) {
          path = Shape.read_polygon_path_scope(p_par.scanner, p_par.layer_structure);
        } else if (next_token == Keyword.POLYLINE_PATH) {
          path = Shape.read_polyline_path_scope(p_par.scanner, p_par.layer_structure);
        } else if (next_token == Keyword.RECTANGLE) {

          border_shape = Shape.read_rectangle_scope(p_par.scanner, p_par.layer_structure);
        } else if (next_token == Keyword.POLYGON) {

          border_shape = Shape.read_polygon_scope(p_par.scanner, p_par.layer_structure);
        } else if (next_token == Keyword.CIRCLE) {

          border_shape = Shape.read_circle_scope(p_par.scanner, p_par.layer_structure);
        } else if (next_token == Keyword.WINDOW) {
          Shape hole_shape = Shape.read_scope(p_par.scanner, p_par.layer_structure);
          hole_list.add(hole_shape);
          // overread the closing bracket
          try {
            next_token = p_par.scanner.next_token();
          } catch (java.io.IOException e) {
            System.out.println("Wiring.read_wire_scope: IO error scanning file");
            return null;
          }
          if (next_token != Keyword.CLOSED_BRACKET) {
            System.out.println("Wiring.read_wire_scope: closing bracket expected");
            return null;
          }
        } else if (next_token == Keyword.NET) {
          net_id = read_net_id(p_par.scanner);
        } else if (next_token == Keyword.CLEARANCE_CLASS) {
          clearance_class_name = DsnFile.read_string_scope(p_par.scanner);
        } else if (next_token == Keyword.TYPE) {
          fixed = calc_fixed(p_par.scanner);
        } else {
          skip_scope(p_par.scanner);
        }
      }
    }
    if (path == null && border_shape == null) {
      System.out.println("Wiring.read_wire_scope: shape missing");
      return null;
    }
    RoutingBoard board = p_par.board_handling.get_routing_board();

    rules.NetClass net_class = board.rules.get_default_net_class();
    Collection<rules.Net> found_nets = get_subnets(net_id, board.rules);
    int[] net_no_arr = new int[found_nets.size()];
    int curr_index = 0;
    for (rules.Net curr_net : found_nets) {
      net_no_arr[curr_index] = curr_net.net_number;
      net_class = curr_net.get_class();
      ++curr_index;
    }
    int clearance_class_no = -1;
    if (clearance_class_name != null) {
      clearance_class_no = board.rules.clearance_matrix.get_no(clearance_class_name);
    }
    int layer_no;
    int half_width;
    if (path != null) {
      layer_no = path.layer.no;
      half_width = (int) Math.round(p_par.coordinate_transform.dsn_to_board(path.width / 2));
    } else {
      layer_no = border_shape.layer.no;
      half_width = 0;
    }
    if (layer_no < 0 || layer_no >= board.get_layer_count()) {
      System.out.print("Wiring.read_wire_scope: unexpected layer ");
      if (path != null) {
        System.out.println(path.layer.name);
      } else {
        System.out.println(border_shape.layer.name);
      }
      return null;
    }

    IntBox bounding_box = board.get_bounding_box();

    Item result = null;
    if (border_shape != null) {
      if (clearance_class_no < 0) {
        clearance_class_no =
            net_class.default_item_clearance_classes.get(
                rules.DefaultItemClearanceClasses.ItemClass.AREA);
      }
      Collection<Shape> area = new LinkedList<Shape>();
      area.add(border_shape);
      area.addAll(hole_list);
      geometry.planar.Area conduction_area =
          Shape.transform_area_to_board(area, p_par.coordinate_transform);
      result =
          board.insert_conduction_area(
              conduction_area, layer_no, net_no_arr, clearance_class_no, false, fixed);
    } else if (path instanceof PolygonPath) {
      if (clearance_class_no < 0) {
        clearance_class_no =
            net_class.default_item_clearance_classes.get(
                rules.DefaultItemClearanceClasses.ItemClass.TRACE);
      }
      IntPoint[] corner_arr = new IntPoint[path.coordinate_arr.length / 2];
      double[] curr_point = new double[2];
      for (int i = 0; i < corner_arr.length; ++i) {
        curr_point[0] = path.coordinate_arr[2 * i];
        curr_point[1] = path.coordinate_arr[2 * i + 1];
        FloatPoint curr_corner = p_par.coordinate_transform.dsn_to_board(curr_point);
        if (!bounding_box.contains(curr_corner)) {
          System.out.println("Wiring.read_wire_scope: wire corner outside board");
          return null;
        }
        corner_arr[i] = curr_corner.round();
      }
      Polyline trace_polyline = new Polyline(corner_arr);
      // Traces are not yet normalized here because cycles may be removed premature.
      result =
          board.insert_trace_without_cleaning(
              trace_polyline, layer_no, half_width, net_no_arr, clearance_class_no, fixed);
    } else if (path instanceof PolylinePath) {
      if (clearance_class_no < 0) {
        clearance_class_no =
            net_class.default_item_clearance_classes.get(
                rules.DefaultItemClearanceClasses.ItemClass.TRACE);
      }
      Line[] line_arr = new Line[path.coordinate_arr.length / 4];
      double[] curr_point = new double[2];
      for (int i = 0; i < line_arr.length; ++i) {
        curr_point[0] = path.coordinate_arr[4 * i];
        curr_point[1] = path.coordinate_arr[4 * i + 1];
        FloatPoint curr_a = p_par.coordinate_transform.dsn_to_board(curr_point);
        curr_point[0] = path.coordinate_arr[4 * i + 2];
        curr_point[1] = path.coordinate_arr[4 * i + 3];
        FloatPoint curr_b = p_par.coordinate_transform.dsn_to_board(curr_point);
        line_arr[i] = new Line(curr_a.round(), curr_b.round());
      }
      Polyline trace_polyline = new Polyline(line_arr);
      result =
          board.insert_trace_without_cleaning(
              trace_polyline, layer_no, half_width, net_no_arr, clearance_class_no, fixed);
    } else {
      System.out.println("Wiring.read_wire_scope: unexpected Path subclass");
      return null;
    }
    if (result != null && result.net_count() == 0) {
      try_correct_net(result);
    }
    return result;
  }