Ejemplo n.º 1
0
 /**
  * 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);
   }
 }
Ejemplo n.º 2
0
  /**
   * Returns a new instance of this state, if a item to drag was found at the input location; null
   * otherwise.
   *
   * @param p_location a {@link geometry.planar.FloatPoint} object.
   * @param p_parent_state a {@link interactive.InteractiveState} object.
   * @param p_board_handling a {@link interactive.BoardHandling} object.
   * @param p_logfile a {@link interactive.Logfile} object.
   * @return a {@link interactive.DragState} object.
   */
  public static DragState get_instance(
      FloatPoint p_location,
      InteractiveState p_parent_state,
      BoardHandling p_board_handling,
      Logfile p_logfile) {
    p_board_handling.display_layer_messsage();
    Item item_to_move = null;
    int try_count = 1;
    if (p_board_handling.settings.select_on_all_visible_layers) {
      try_count += p_board_handling.get_layer_count();
    }
    int curr_layer = p_board_handling.settings.layer;
    int pick_layer = curr_layer;
    boolean item_found = false;

    for (int i = 0; i < try_count; ++i) {
      if (i == 0
          || pick_layer != curr_layer
              && (p_board_handling.graphics_context.get_layer_visibility(pick_layer)) > 0) {
        java.util.Collection<Item> found_items =
            p_board_handling
                .get_routing_board()
                .pick_items(
                    p_location.round(),
                    pick_layer,
                    p_board_handling.settings.item_selection_filter);
        Iterator<Item> it = found_items.iterator();
        while (it.hasNext()) {
          item_found = true;
          Item curr_item = it.next();
          if (curr_item instanceof Trace) {
            continue; // traces are not moved
          }
          if (!p_board_handling.settings.drag_components_enabled
              && curr_item.get_component_no() != 0) {
            continue;
          }
          item_to_move = curr_item;
          if (curr_item instanceof DrillItem) {
            break; // drill items are preferred
          }
        }
        if (item_to_move != null) {
          break;
        }
      }
      // nothing found on settings.layer, try all visible layers
      pick_layer = i;
    }
    DragState result;
    if (item_to_move != null) {
      result =
          new DragItemState(item_to_move, p_location, p_parent_state, p_board_handling, p_logfile);
    } else if (!item_found) {
      result = new MakeSpaceState(p_location, p_parent_state, p_board_handling, p_logfile);
    } else {
      result = null;
    }
    if (result != null) {
      p_board_handling.hide_ratsnest();
    }
    return result;
  }
Ejemplo n.º 3
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;
  }