예제 #1
0
  private void plot(Graphics2D g, Material material, Shape shape, boolean subdued) {
    final Stroke savedStroke = g.getStroke();
    g.setStroke(plotStroke);
    double yTensile = Inventory.tensileStrength(material, shape);
    final int iy = yPlotAreaBottom - (int) Math.round((yTensile / yMax) * heightPlotArea);
    g.setColor(subdued ? subduedBlue : Color.BLUE);
    g.drawLine(xPlotAreaLeft, iy, xPlotAreaRight, iy);

    final int nPlotPoints = 32;
    double yCompressive = Inventory.compressiveStrength(material, shape, 0.0);
    int iy0 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea);
    int ix0 = xPlotAreaLeft;
    g.setColor(subdued ? subduedRed : Color.RED);
    for (int i = 1; i <= nPlotPoints; i++) {
      double t = (double) i / nPlotPoints;
      double x = t * xMax;
      int ix1 = xPlotAreaLeft + (int) Math.round(t * widthPlotArea);
      yCompressive = Inventory.compressiveStrength(material, shape, x);
      int iy1 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea);
      g.drawLine(ix0, iy0, ix1, iy1);
      ix0 = ix1;
      iy0 = iy1;
    }
    g.setStroke(savedStroke);
    g.setColor(Color.BLACK);
  }
예제 #2
0
  private void plot1MemberLength(Graphics2D g, Member member, boolean subdued) {
    double length = member.getLength();
    double t = length / xMax;
    if (t <= 1) {
      Stroke savedStroke = g.getStroke();
      double tensileStrength = Inventory.tensileStrength(member.getMaterial(), member.getShape());
      int iyTensileStrength =
          yPlotAreaBottom - (int) Math.round((tensileStrength / yMax) * heightPlotArea);
      double compressiveStrength =
          Inventory.compressiveStrength(member.getMaterial(), member.getShape(), length);
      int iyCompressiveStrength =
          yPlotAreaBottom - (int) Math.round((compressiveStrength / yMax) * heightPlotArea);

      // Find x-coordinate for the member getLength and plot a vertical line there.
      int ix = xPlotAreaLeft + (int) Math.round(t * widthPlotArea);
      g.setColor(subdued ? Color.LIGHT_GRAY : Color.BLACK);
      g.setStroke(lengthTicksStroke);
      g.drawLine(ix, yPlotAreaBottom, ix, yPlotAreaTop - tickSize);

      // Label with member number.
      g.setStroke(savedStroke);
      if (!subdued) {
        Labeler.drawJustified(
            g,
            Integer.toString(member.getNumber()),
            ix,
            yPlotAreaTop - tickSize,
            Labeler.JUSTIFY_CENTER,
            Labeler.JUSTIFY_BOTTOM,
            Member.labelBackground);
      }

      if (analysis != null) {
        g.setColor(subdued ? subduedRed : Color.RED);
        if (!subdued) {
          g.fillRect(
              ix - dotRadius,
              iyCompressiveStrength - dotRadius,
              2 * dotRadius + 1,
              2 * dotRadius + 1);
        }
        if (analysis != null) {
          plotBracket(
              g,
              member.getNumber(),
              analysis.getMemberCompressiveForce(member.getIndex()),
              ix,
              iyCompressiveStrength,
              subdued);
        }
        g.setColor(subdued ? subduedBlue : Color.BLUE);
        if (!subdued) {
          g.fillRect(
              ix - dotRadius, iyTensileStrength - dotRadius, 2 * dotRadius + 1, 2 * dotRadius + 1);
        }
        if (analysis != null) {
          plotBracket(
              g,
              member.getNumber(),
              analysis.getMemberTensileForce(member.getIndex()),
              ix,
              iyTensileStrength,
              subdued);
        }
      }
      g.setStroke(savedStroke);
    }
  }
예제 #3
0
  /**
   * Paint the strength curve(s).
   *
   * @param g0 java graphics context
   */
  @Override
  protected void paintComponent(Graphics g0) {
    Graphics2D g = (Graphics2D) g0;
    final Stroke savedStroke = g.getStroke();
    // Calculate font metrics one time.
    if (widthYLabel < 0) {
      FontRenderContext frc = g.getFontRenderContext();
      Font font = Labeler.getFont();
      LineMetrics metrics = font.getLineMetrics(longestYLabel, frc);
      widthYLabel = (float) font.getStringBounds(longestYLabel, frc).getWidth();
      heightText = metrics.getAscent() + metrics.getDescent();
    }
    // Clear background.
    int w = getWidth();
    int h = getHeight();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, w, h);

    // Draw the title.
    g.setColor(Color.BLACK);
    /*
    Labeler.drawJustified(g0, resourceMap.getString("title.text"), w/2, heightPad,
    Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null);
    */

    // Compute the plot area boundaries and sizes.
    yPlotAreaTop = Math.round(heightPad + heightText + labelTickSep + tickSize);
    yPlotAreaBottom =
        Math.round(
            h - 1 - heightPad - heightText - titleLabelSep - heightText - labelTickSep - tickSize);
    xPlotAreaLeft =
        Math.round(widthPad + heightText + titleLabelSep + widthYLabel + labelTickSep + tickSize);
    xPlotAreaRight = w - 1 - widthPad;
    heightPlotArea = yPlotAreaBottom - yPlotAreaTop;
    widthPlotArea = xPlotAreaRight - xPlotAreaLeft;

    // Draw the axes.
    g.drawLine(xPlotAreaLeft, yPlotAreaBottom + tickSize, xPlotAreaLeft, yPlotAreaTop - tickSize);
    g.drawLine(
        xPlotAreaLeft - tickSize, yPlotAreaBottom, xPlotAreaRight + tickSize, yPlotAreaBottom);

    // Decide what we are plotting and able to plot based on caller-provided data.
    boolean doShowAll = showAll && memberLists != null && memberLists.length > 0;
    boolean doShowOne = material != null && shape != null;

    // If we can't plot anything at all, we're done.
    if (!doShowAll && !doShowOne) {
      return;
    }

    // Find the maximum coordinate of the y-axis.
    yMax = 0;
    if (doShowAll) {
      for (int i = 0; i < memberLists.length; i++) {
        Member member = memberLists[i][0];
        yMax = Math.max(yMax, Inventory.tensileStrength(member.getMaterial(), member.getShape()));
      }
    }
    if (doShowOne) {
      yMax = Math.max(yMax, Inventory.tensileStrength(material, shape));
    }
    if (analysis != null && members != null) {
      for (int i = 0; i < members.length; i++) {
        yMax = Math.max(yMax, analysis.getMemberCompressiveForce(members[i].getIndex()));
        yMax = Math.max(yMax, analysis.getMemberTensileForce(members[i].getIndex()));
      }
    }

    // Determine the geometry of ticks and grid lines on the y-axis.  Adjust y max upward to top of
    // scale.
    final double dyTick = getDivisionSize(yMax, (yPlotAreaBottom - yPlotAreaTop) / 50);
    final int nYTicks = (int) Math.ceil(yMax / dyTick);
    yMax = nYTicks * dyTick;

    // Draw ticks and labels on the y-axis.  Keep track of actual label width so we can set the
    // title.
    int actualLabelWidth = 0;
    int ix = xPlotAreaLeft - tickSize - titleLabelSep;
    for (int i = 0; i <= nYTicks; i++) {
      double t = (double) i / nYTicks;
      double y = t * yMax;
      int iy = yPlotAreaBottom - (int) Math.round(t * heightPlotArea);
      if (i > 0) {
        g.setColor(Color.GRAY);
        g.setStroke(gridStroke);
        g.drawLine(xPlotAreaLeft, iy, xPlotAreaRight, iy);
        g.setStroke(savedStroke);
      }
      g.setColor(Color.BLACK);
      g.drawLine(xPlotAreaLeft, iy, xPlotAreaLeft - tickSize, iy);
      Labeler.drawJustified(
          g0,
          labelFormatter.format(y),
          ix,
          iy,
          Labeler.JUSTIFY_RIGHT,
          Labeler.JUSTIFY_CENTER,
          null,
          bounds);
      actualLabelWidth = Math.max(actualLabelWidth, bounds.width);
    }

    // Determine x-coordinate of the rotated y-axis title and draw it.
    ix -= (actualLabelWidth + titleLabelSep);
    Labeler.drawRotatedAndJustified(
        g0,
        resourceMap.getString("yAxisTitle.text"),
        90,
        ix,
        (yPlotAreaBottom + yPlotAreaTop) / 2,
        Labeler.JUSTIFY_CENTER,
        Labeler.JUSTIFY_TOP,
        null,
        null,
        null);

    // Determine a good width and scale for the x-axis.  For now just fix at 12.
    xMax = 12.0;
    // Not currently needed: final double dxTick = 1.0;
    final double nXTicks = 12;

    // Determine top of label coordinate and draw x-axis ticks and vertical grid lines.
    int iy = yPlotAreaBottom + tickSize + titleLabelSep;
    for (int i = 0; i <= nXTicks; i++) {
      double t = (double) i / nXTicks;
      double x = t * xMax;
      ix = xPlotAreaLeft + (int) Math.round(t * widthPlotArea);
      if (i > 0) {
        g.setColor(Color.GRAY);
        g.setStroke(gridStroke);
        g.drawLine(ix, yPlotAreaBottom, ix, yPlotAreaTop);
        g.setStroke(savedStroke);
      }
      g.setColor(Color.BLACK);
      g.drawLine(ix, yPlotAreaBottom, ix, yPlotAreaBottom + tickSize);
      Labeler.drawJustified(
          g0, labelFormatter.format(x), ix, iy, Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null);
    }

    // Draw the x-axis title.
    iy += heightText + titleLabelSep;
    Labeler.drawJustified(
        g0,
        resourceMap.getString("xAxisTitle.text"),
        (xPlotAreaLeft + xPlotAreaRight) / 2,
        iy,
        Labeler.JUSTIFY_CENTER,
        Labeler.JUSTIFY_TOP,
        null);

    if (doShowAll) {
      for (int i = 0; i < memberLists.length; i++) {
        Member member = memberLists[i][0];
        if (member.getMaterial() != material || member.getShape() != shape) {
          plot(g, member.getMaterial(), member.getShape(), true);
        }
      }
    }
    if (doShowOne) {
      if (members != null) {
        plotMemberLengths(g, members);
      }
      plot(g, material, shape, false);
    }
  }