Пример #1
0
 private boolean read_via_scope(ReadScopeParameter p_par) {
   try {
     board.FixedState fixed = board.FixedState.UNFIXED;
     // read the padstack name
     Object next_token = p_par.scanner.next_token();
     if (!(next_token instanceof String)) {
       System.out.println("Wiring.read_via_scope: padstack name expected");
       return false;
     }
     String padstack_name = (String) next_token;
     // read the location
     double[] location = new double[2];
     for (int i = 0; i < 2; ++i) {
       next_token = p_par.scanner.next_token();
       if (next_token instanceof Double) {
         location[i] = ((Double) next_token).doubleValue();
       } else if (next_token instanceof Integer) {
         location[i] = ((Integer) next_token).intValue();
       } else {
         System.out.println("Wiring.read_via_scope: number expected");
         return false;
       }
     }
     Net.Id net_id = null;
     String clearance_class_name = null;
     for (; ; ) {
       Object prev_token = next_token;
       next_token = p_par.scanner.next_token();
       if (next_token == null) {
         System.out.println("Wiring.read_via_scope: unexpected end of file");
         return false;
       }
       if (next_token == CLOSED_BRACKET) {
         // end of scope
         break;
       }
       if (prev_token == OPEN_BRACKET) {
         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);
         }
       }
     }
     RoutingBoard board = p_par.board_handling.get_routing_board();
     library.Padstack curr_padstack = board.library.padstacks.get(padstack_name);
     if (curr_padstack == null) {
       System.out.println("Wiring.read_via_scope: via padstack not found");
       return false;
     }
     rules.NetClass net_class = board.rules.get_default_net_class();
     Collection<rules.Net> found_nets = get_subnets(net_id, board.rules);
     if (net_id != null && found_nets.isEmpty()) {
       System.out.print("Wiring.read_via_scope: net with name ");
       System.out.print(net_id.name);
       System.out.println(" not found");
     }
     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();
     }
     int clearance_class_no = -1;
     if (clearance_class_name != null) {
       clearance_class_no = board.rules.clearance_matrix.get_no(clearance_class_name);
     }
     if (clearance_class_no < 0) {
       clearance_class_no =
           net_class.default_item_clearance_classes.get(
               rules.DefaultItemClearanceClasses.ItemClass.VIA);
     }
     IntPoint board_location = p_par.coordinate_transform.dsn_to_board(location).round();
     if (via_exists(board_location, curr_padstack, net_no_arr, board)) {
       System.out.print("Multiple via skipped at (");
       System.out.println(board_location.x + ", " + board_location.y + ")");
     } else {
       boolean attach_allowed = p_par.via_at_smd_allowed && curr_padstack.attach_allowed;
       board.insert_via(
           curr_padstack, board_location, net_no_arr, clearance_class_no, fixed, attach_allowed);
     }
     return true;
   } catch (java.io.IOException e) {
     System.out.println("Wiring.read_via_scope: IO error scanning file");
     return false;
   }
 }
Пример #2
0
  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;
  }