예제 #1
0
  /**
   * Draw the macro contents.
   *
   * @param g the graphic context.
   * @param coordSys the coordinate system.
   * @param layerV the vector containing all layers.
   */
  private void drawMacroContents(GraphicsInterface g, MapCoordinates coordSys, Vector layerV) {
    /* in the macro primitive, the the virtual point represents
    the position of the reference point of the macro to be drawn. */
    if (changed) {
      changed = false;
      x1 = virtualPoint[0].x;
      y1 = virtualPoint[0].y;

      macroCoord.setXMagnitude(coordSys.getXMagnitude());
      macroCoord.setYMagnitude(coordSys.getYMagnitude());

      macroCoord.setXCenter(coordSys.mapXr(x1, y1));
      macroCoord.setYCenter(coordSys.mapYr(x1, y1));
      macroCoord.setOrientation((o + coordSys.getOrientation()) % 4);
      macroCoord.mirror = m ^ coordSys.mirror;
      macroCoord.isMacro = true;
      macroCoord.resetMinMax();

      macro.setChanged(true);
    }

    if (getSelected()) {
      new SelectionActions(macro).setSelectionAll(true);
      selected = true;
    } else if (selected) {
      new SelectionActions(macro).setSelectionAll(false);
      selected = false;
    }

    macro.setDrawOnlyLayer(drawOnlyLayer);
    macro.setDrawOnlyPads(drawOnlyPads);

    drawingAgent = new Drawing(macro);
    drawingAgent.draw(g, macroCoord);

    if (macroCoord.getXMax() > macroCoord.getXMin()
        && macroCoord.getYMax() > macroCoord.getYMin()) {
      coordSys.trackPoint(macroCoord.getXMax(), macroCoord.getYMax());
      coordSys.trackPoint(macroCoord.getXMin(), macroCoord.getYMin());
    }
  }
예제 #2
0
  /**
   * Each graphic primitive should call the appropriate exporting method of the export interface
   * specified.
   *
   * @param exp the export interface that should be used.
   * @param cs the actual coordinate mapping.
   * @throws IOException if a problem occurs, such as it is impossible to write on the output file.
   */
  public void export(ExportInterface exp, MapCoordinates cs) throws IOException {
    if (alreadyExported) return;

    // Call the macro interface, to see if the macro should be expanded

    if (exp.exportMacro(
        cs.mapX(virtualPoint[0].x, virtualPoint[0].y),
        cs.mapY(virtualPoint[0].x, virtualPoint[0].y),
        m,
        o * 90,
        macroName,
        macroDesc,
        name,
        cs.mapX(virtualPoint[1].x, virtualPoint[1].y),
        cs.mapY(virtualPoint[1].x, virtualPoint[1].y),
        value,
        cs.mapX(virtualPoint[2].x, virtualPoint[2].y),
        cs.mapY(virtualPoint[2].x, virtualPoint[2].y),
        macroFont,
        (int) (cs.mapYr(getMacroFontSize(), getMacroFontSize()) - cs.mapYr(0, 0)),
        library)) {
      alreadyExported = true;
      return;
    }
    /* in the macro primitive, the virtual point represents
    the position of the reference point of the macro to be drawn. */

    int x1 = virtualPoint[0].x;
    int y1 = virtualPoint[0].y;

    MapCoordinates macroCoord = new MapCoordinates();

    macroCoord.setXMagnitude(cs.getXMagnitude());
    macroCoord.setYMagnitude(cs.getYMagnitude());

    macroCoord.setXCenter(cs.mapXr(x1, y1));
    macroCoord.setYCenter(cs.mapYr(x1, y1));

    macroCoord.setOrientation((o + cs.getOrientation()) % 4);
    macroCoord.mirror = m ^ cs.mirror;
    macroCoord.isMacro = true;

    macro.setDrawOnlyLayer(drawOnlyLayer);

    if (getSelected()) new SelectionActions(macro).setSelectionAll(true);

    macro.setDrawOnlyPads(drawOnlyPads);
    new Export(macro).exportDrawing(exp, false, exportInvisible, macroCoord);
    exportText(exp, cs, drawOnlyLayer);
  }
예제 #3
0
  /**
   * The printing interface.
   *
   * @param g the graphic context.
   * @param pf the page format.
   * @param page the page number.
   * @return PAGE_EXISTS if the page has to be printed.
   * @throws PrinterException if a printing error occurs.
   */
  public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    int npages = 0;

    // This might be explained as follows:
    // 1 - The Java printing system normally works with an internal
    // resolution which is 72 dpi (probably inspired by Postscript).
    // 2 - To have a sufficient resolution, this is increased by 16 times,
    // by using the scale method of the graphic object associated to the
    // printer. This gives a 72 dpi * 16=1152 dpi resolution.
    // 3 - The 0.127 mm pitch used in FidoCadJ corresponds to a 200 dpi
    // resolution. Calculating 1152 dpi / 200 dpi gives the 5.76 constant

    double xscale = 1.0 / 16; // Set 1152 logical units for an inch
    double yscale = 1.0 / 16; // as the standard resolution is 72
    double zoom = 5.76; // act in a 1152 dpi resolution as 1:1

    Graphics2D g2d = (Graphics2D) g;

    // User (0,0) is typically outside the imageable area, so we must
    // translate by the X and Y values in the PageFormat to avoid clipping

    if (printMirror) {
      g2d.translate(pf.getImageableX() + pf.getImageableWidth(), pf.getImageableY());
      g2d.scale(-xscale, yscale);

    } else {
      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.scale(xscale, yscale);
    }

    int printerWidth = (int) pf.getImageableWidth() * 16;

    // Perform an adjustement if we need to fit the drawing to the page.
    if (printFitToPage) {
      MapCoordinates zoomm =
          DrawingSize.calculateZoomToFit(
              cc.dmp, (int) pf.getImageableWidth() * 16, (int) pf.getImageableHeight() * 16, false);
      zoom = zoomm.getXMagnitude();
    }

    MapCoordinates m = new MapCoordinates();

    m.setMagnitudes(zoom, zoom);

    PointG o = new PointG(0, 0);

    int imageWidth = DrawingSize.getImageSize(cc.dmp, zoom, false, o).width;
    npages = (int) Math.floor((imageWidth - 1) / (double) printerWidth);

    // Check if we need more than one page
    if (printerWidth < imageWidth) {
      g2d.translate(-(printerWidth * page), 0);
    }

    // Check if printing is finished.
    if (page > npages) {
      return NO_SUCH_PAGE;
    }
    // Now we perform our rendering
    cc.drawingAgent.draw(new Graphics2DSwing(g2d), m);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
  }