Search in sources :

Example 1 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class PanelProfilMRB method DrawSlopeProfile.

/**
 * Draw the slope type profile
 *
 * @param g2d
 *            Graphic context
 * @param xmin
 *            Minimum x axis value
 * @param ymin
 *            Minimum y axis value
 * @param resx
 *            x axis resolution
 * @param resy
 *            y axis resolution
 * @param TabY
 *            Array of y value for each x pixel
 */
private void DrawSlopeProfile(Graphics2D g2d, Double xmin, Double ymin, double resx, double resy, int[] TabY) {
    double avrSlope = 0.0;
    int nbSlope = 0;
    g2d.setColor(Color.BLACK);
    // b = Brushes.Black;
    boolean first = true;
    int[] xCurvePts = { 0, 0, 0, 0 };
    int[] yCurvePts = { 0, 0, 0, 0 };
    CalcLineResult res = new CalcLineResult();
    CgData oldr = new CgData();
    oldr.setElevation(track.data.get(0).getElevation(CgConst.UNIT_METER));
    oldr.setTotal(track.data.get(0).getTotal(CgConst.UNIT_METER));
    // -- Draw the slope profile
    for (CgData r : track.data) {
        xCurvePts[0] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[0] = height - offy;
        xCurvePts[1] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[1] = (int) (height - offy - ((oldr.getElevation(settings.Unit) - ymin) * resy));
        xCurvePts[2] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[2] = (int) (height - offy - ((r.getElevation(settings.Unit) - ymin) * resy));
        xCurvePts[3] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[3] = height - offy;
        avrSlope += Math.abs(r.getSlope());
        nbSlope++;
        if (// Filtre
        (xCurvePts[2] - xCurvePts[0]) > track.CurveFilter) {
            double avr = avrSlope / nbSlope;
            if (avr < 5.0)
                g2d.setColor(track.clProfil_SlopeInf5);
            else if (avr < 10.0)
                g2d.setColor(track.clProfil_SlopeInf10);
            else if (avr < 15.0)
                g2d.setColor(track.clProfil_SlopeInf15);
            else if (avr >= 15.0)
                g2d.setColor(track.clProfil_SlopeSup15);
            g2d.fillPolygon(xCurvePts, yCurvePts, 4);
            res = Utils.CalcLine(xCurvePts[1], yCurvePts[1], xCurvePts[2], yCurvePts[2], res);
            for (int tf = xCurvePts[1]; tf < xCurvePts[2]; tf++) {
                TabY[(int) tf] = (int) (res.a * tf + res.b);
                // First pass. Allow to draw the first line
                if ((first) && (tf > 0)) {
                    TabY[(int) tf - 1] = TabY[(int) tf];
                    first = false;
                }
            }
            oldr.setElevation(r.getElevation(CgConst.UNIT_METER));
            oldr.setTotal(r.getTotal(CgConst.UNIT_METER));
            avrSlope = 0.0;
            nbSlope = 0;
        }
    }
    // -- Draw the line on the profile
    oldr.setElevation(track.data.get(0).getElevation(CgConst.UNIT_METER));
    oldr.setTotal(track.data.get(0).getTotal(CgConst.UNIT_METER));
    g2d.setColor(track.clProfil_SlopeBorder);
    g2d.setStroke(PenSlopeBorder);
    for (CgData r : track.data) {
        // Point on the bottom left (old point)
        xCurvePts[0] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[0] = height - offy;
        // Point on the top left (old point)
        xCurvePts[1] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[1] = (int) (height - offy - ((oldr.getElevation(settings.Unit) - ymin) * resy));
        // Point on top right (new point)
        xCurvePts[2] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[2] = (int) (height - offy - ((r.getElevation(settings.Unit) - ymin) * resy));
        // Point on bottom right (new point)
        xCurvePts[3] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[3] = height - offy;
        // Filter
        if ((xCurvePts[2] - xCurvePts[0]) > track.CurveFilter) {
            g2d.drawLine(xCurvePts[1], yCurvePts[1], (int) xCurvePts[2], (int) yCurvePts[2]);
            oldr.setElevation(r.getElevation(CgConst.UNIT_METER));
            oldr.setTotal(r.getTotal(CgConst.UNIT_METER));
        }
    }
    // for
    // Last point
    g2d.fillPolygon(xCurvePts, yCurvePts, 4);
    g2d.setStroke(PenSimpleBorder);
    g2d.drawLine(xCurvePts[1], yCurvePts[1], xCurvePts[2], yCurvePts[2]);
}
Also used : CalcLineResult(course_generator.utils.Utils.CalcLineResult) CgData(course_generator.CgData)

Example 2 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class PanelProfilMRB method DrawSimpleProfile.

/**
 * Draw the simple type profile
 *
 * @param g2d
 *            Graphic context
 * @param xmin
 *            Minimum x axis value
 * @param ymin
 *            Minimum y axis value
 * @param resx
 *            x axis resolution
 * @param resy
 *            y axis resolution
 * @param TabY
 *            Array of y value for each x pixel
 */
private void DrawSimpleProfile(Graphics2D g2d, double xmin, double ymin, double resx, double resy, int[] TabY) {
    boolean first = true;
    int[] xCurvePts = { 0, 0, 0, 0 };
    int[] yCurvePts = { 0, 0, 0, 0 };
    CalcLineResult res = new CalcLineResult();
    CgData oldr = new CgData();
    oldr.setElevation(track.data.get(0).getElevation(CgConst.UNIT_METER));
    oldr.setTotal(track.data.get(0).getTotal(CgConst.UNIT_METER));
    g2d.setPaint(track.clProfil_Simple_Fill);
    // -- Draw the profile with a unique color
    for (CgData r : track.data) {
        // Point on bottom left (old point)
        xCurvePts[0] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[0] = height - offy;
        // Point on top left (old point)
        xCurvePts[1] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[1] = height - offy - (int) ((oldr.getElevation(settings.Unit) - ymin) * resy);
        // Point on top right (new point)
        xCurvePts[2] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[2] = height - offy - (int) ((r.getElevation(settings.Unit) - ymin) * resy);
        // Point on bottom right (new point)
        xCurvePts[3] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[3] = height - offy;
        // Filter
        if ((xCurvePts[2] - xCurvePts[0]) > track.CurveFilter) {
            // -- Draw the polygon
            g2d.fillPolygon(xCurvePts, yCurvePts, 4);
            res = Utils.CalcLine(xCurvePts[1], yCurvePts[1], xCurvePts[2], yCurvePts[2], res);
            for (int tf = xCurvePts[1]; tf < xCurvePts[2]; tf++) {
                TabY[(int) tf] = (int) (res.a * tf + res.b);
                // First pass. Allow to draw the first line
                if ((first) && (tf > 0)) {
                    TabY[(int) tf - 1] = TabY[(int) tf];
                    first = false;
                }
            }
            oldr.setElevation(r.getElevation(CgConst.UNIT_METER));
            oldr.setTotal(r.getTotal(CgConst.UNIT_METER));
        }
    }
    // for
    // -- Draw the line on the profile
    oldr.setElevation(track.data.get(0).getElevation(CgConst.UNIT_METER));
    oldr.setTotal(track.data.get(0).getTotal(CgConst.UNIT_METER));
    g2d.setColor(track.clProfil_Simple_Border);
    g2d.setStroke(PenSimpleBorder);
    for (CgData r : track.data) {
        // Point on bottom left (old point)
        xCurvePts[0] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[0] = height - offy;
        // Point on top left (old point)
        xCurvePts[1] = (int) Math.round((offx + 1 + ((oldr.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[1] = (int) (height - offy - ((oldr.getElevation(settings.Unit) - ymin) * resy));
        // Point on top right (new point)
        xCurvePts[2] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[2] = (int) (height - offy - ((r.getElevation(settings.Unit) - ymin) * resy));
        // Point on bottom right (new point)
        xCurvePts[3] = (int) Math.round((offx + 1 + ((r.getTotal(settings.Unit) - xmin) * resx)));
        yCurvePts[3] = height - offy;
        if (// Filter
        (xCurvePts[2] - xCurvePts[0]) > track.CurveFilter) {
            g2d.drawLine(xCurvePts[1], yCurvePts[1], xCurvePts[2], yCurvePts[2]);
            oldr.setElevation(r.getElevation(CgConst.UNIT_METER));
            oldr.setTotal(r.getTotal(CgConst.UNIT_METER));
        }
    }
    // for
    // Last point
    g2d.fillPolygon(xCurvePts, yCurvePts, 4);
    g2d.drawLine(xCurvePts[1], yCurvePts[1], xCurvePts[2], yCurvePts[2]);
}
Also used : CalcLineResult(course_generator.utils.Utils.CalcLineResult) CgData(course_generator.CgData)

Example 3 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class PanelProfilMRB method paintComponent.

/**
 * Refresh the panel
 */
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // private void RefreshProfil(bool WithHighlight)
    int nbtag = 0;
    double[] stepval = { 1, 2, 2.5, 5 };
    double[] stepval2 = { 0.1, 0.1, 0.2, 0.1 };
    String s;
    double resx = 0.0;
    double resy = 0.0;
    // double tf = 0;
    // boolean first = false;
    int[] TabY = new int[width];
    for (int i = 0; i < width; i++) TabY[i] = 0;
    // Calculate the profile width
    wp = width - offx - rMargin;
    PixelPerHUnit = wp / ((int) (track.getTotalDistance(settings.Unit) / 1000.0));
    // Calculate the profile height
    Double dElev = track.getMaxElev(settings.Unit) - track.getMinElev(settings.Unit);
    if (dElev < 100) {
        dElev = Math.ceil(track.getMaxElev(settings.Unit) / 10.0) * 10.0;
    } else {
        dElev = (Math.ceil(track.getMaxElev(settings.Unit) / 100.0) * 100.0) - (Math.floor(track.getMinElev((settings.Unit)) / 100.0) * 100.0);
    }
    hp = height - offy - track.TopMargin;
    PixelPerVUnit = dElev / hp;
    // Font FontSmall = new Font("ARIAL", Font.PLAIN, 7);
    Font FontGraduation = new Font("ARIAL", Font.PLAIN, 10);
    // Font FontLabel = new Font("ARIAL", Font.PLAIN, 11);
    // CalcLineResult res = new CalcLineResult();
    // -- Main frame display with white background
    g2d.setPaint(Color.WHITE);
    g2d.fillRect(0, 0, width, height);
    g2d.setStroke(PenBlackS);
    g2d.setPaint(Color.BLACK);
    g2d.drawRect(0, 0, width - 1, height - 1);
    // -- Some tests in order to be sure that we have data
    if (data == null)
        return;
    if (settings == null)
        return;
    if (track == null)
        return;
    if (track.data.isEmpty())
        return;
    // -- Vertical axis drawing
    // Position of the arrow compare to the top of the profile
    int YPosArrow = 15;
    g2d.setStroke(PenBlackS);
    g2d.drawLine(offx, track.TopMargin - YPosArrow, offx, height - offy + 3);
    // -- End of the vertical axis drawing
    g2d.setPaint(Color.BLACK);
    int[] x = { offx - 5, offx, offx + 5 };
    int[] y = { track.TopMargin - YPosArrow - 1, track.TopMargin - YPosArrow - 10, track.TopMargin - YPosArrow - 1 };
    g2d.fillPolygon(x, y, 3);
    // -- Vertical unit drawing
    s = settings.getShortElevationUnitString();
    Dimension d = Utils.StringDimension(g2d, s);
    g2d.drawString(s, offx - d.width - 8, track.TopMargin - YPosArrow);
    // -- Horizontal axis drawing
    g2d.drawLine(offx - 3, height - offy, width - 10, height - offy);
    // -- End of the horizontal axis drawing
    int[] x1 = { width - 15, width - 7, width - 15 };
    int[] y1 = { height - 20, height - 25, height - 30 };
    g2d.fillPolygon(x1, y1, 3);
    // -- Horizontal unit drawing
    s = settings.getShortDistanceUnitString();
    d = Utils.StringDimension(g2d, s);
    g2d.drawString(s, width - d.width - 2, height - offy - 10);
    Double ymin = 0.0;
    Double ymax = 0.0;
    Double xmin = 0.0;
    Double xmax = 0.0;
    Double stepx = 0.0;
    Double stepy = 0.0;
    Double stepx2 = 0.0;
    Double stepy2 = 0.0;
    int NbGradX = 0;
    int NbGradY = 0;
    // -- Min and max of the X axis
    xmin = 0.0;
    xmax = track.getTotalDistance(settings.Unit);
    // -- X axis ticks calculation
    int ctab = 0;
    int cmul = 0;
    double p = 1.0;
    boolean ok = false;
    while (!ok) {
        ctab = 0;
        while (ctab < 4 && !ok) {
            cmul = 5;
            while (cmul <= 10 && !ok) {
                if (xmin + p * stepval[ctab] * cmul > xmax)
                    ok = true;
                else
                    cmul++;
            }
            if (!ok)
                ctab++;
        }
        if (!ok)
            p = p * 10;
    }
    stepx = stepval[ctab] * p;
    stepx2 = stepval2[ctab] * stepx;
    NbGradX = cmul;
    xmax = xmin + stepx * NbGradX;
    // -- Min and max of the y axis calculation
    if (track.getMaxElev(settings.Unit) - track.getMinElev(settings.Unit) < 100)
        ymin = 0.0;
    else
        ymin = Math.floor(track.getMinElev(settings.Unit) / 100.0) * 100.0;
    ymax = track.getMaxElev(settings.Unit);
    // -- Y axis ticks calculation
    ctab = 0;
    cmul = 0;
    p = 1.0;
    ok = false;
    while (!ok) {
        ctab = 0;
        while (ctab < 4 && !ok) {
            cmul = 5;
            while (cmul <= 10 && !ok) {
                if (ymin + p * stepval[ctab] * cmul > ymax)
                    ok = true;
                else
                    cmul++;
            }
            if (!ok)
                ctab++;
        }
        if (!ok)
            p = p * 10;
    }
    stepy = stepval[ctab] * p;
    stepy2 = stepval2[ctab] * stepy;
    NbGradY = cmul;
    ymax = ymin + stepy * NbGradY;
    resx = wp / (xmax - xmin);
    resy = hp / (ymax - ymin);
    // -- Night background
    if (track.bNightCoeff && track.bShowNightDay) {
        g2d.setStroke(PenBlackS);
        g2d.setPaint(Color.LIGHT_GRAY);
        int fs = 0;
        DateTime hour = new DateTime();
        Double total = 0.0;
        for (CgData r : track.data) {
            hour = r.getHour();
            total = r.getTotal(settings.Unit);
            int ts_val = hour.getSecondOfDay();
            int ts_start = track.StartNightTime.getSecondOfDay();
            int ts_end = track.EndNightTime.getSecondOfDay();
            if ((ts_val > ts_start) || (ts_val < ts_end)) {
                if (fs == 0)
                    fs = (int) Math.round((offx + 1 + ((total - xmin) * resx)));
            } else {
                if (fs != 0) {
                    int tx = (int) Math.round((offx + 1 + ((total - xmin) * resx)));
                    int ty = height - offy;
                    g2d.fillRect(fs, 0, tx - fs, ty);
                    fs = 0;
                }
            }
        }
        if (fs != 0) {
            int tx = (int) Math.round((offx + 1 + ((total - xmin) * resx)));
            int ty = height - offy;
            g2d.fillRect(fs, 0, tx - fs, ty);
            fs = 0;
        }
    }
    // -- Horizontal line --
    // -- Vertical grid drawing --
    g2d.setStroke(PenBlackS);
    g2d.setPaint(Color.BLACK);
    for (double i = xmin; i <= xmax; i += stepx2) {
        g2d.drawLine(offx + (int) (i * resx), height - offy + 2, offx + (int) (i * resx), height - offy);
    }
    for (double i = xmin; i <= xmax; i += stepx) {
        g2d.setStroke(myPenDot);
        g2d.drawLine(offx + (int) (i * resx), height - offy, offx + (int) (i * resx), height - offy - hp);
        g2d.setStroke(PenBlackS);
        g2d.drawLine(offx + (int) (i * resx), height - offy + 4, offx + (int) (i * resx), height - offy);
    }
    // -- Horizontal grid drawing --
    g2d.setStroke(PenBlackS);
    for (double i = ymin; i <= ymax; i += stepy2) {
        g.drawLine(offx - 2, height - offy - (int) ((i - ymin) * resy), offx, height - offy - (int) ((i - ymin) * resy));
    }
    for (double i = ymin; i <= ymax; i += stepy) {
        g2d.setStroke(myPenDot);
        g.drawLine(offx, height - offy - (int) ((i - ymin) * resy), offx + wp, height - offy - (int) ((i - ymin) * resy));
        g2d.setStroke(PenBlackS);
        g.drawLine(offx - 4, height - offy - (int) ((i - ymin) * resy), offx, height - offy - (int) ((i - ymin) * resy));
    }
    // -- Y axis value drawing
    g2d.setFont(FontGraduation);
    g2d.setPaint(Color.BLACK);
    for (int c = 0; c <= NbGradY; c++) {
        s = String.format("%1.0f", (ymin + c * stepy));
        d = Utils.StringDimension(g2d, s);
        g2d.drawString(s, offx - d.width - 5, (int) ((height - offy) - (c * stepy * resy)) + (d.height / 2));
    }
    // -- Draw the value of the X axis
    for (int c = 0; c <= NbGradX; c++) {
        s = String.format("%1.0f", (xmin + c * stepx) / 1000);
        // stringSize = g.MeasureString(s, FontAvr);
        d = Utils.StringDimension(g2d, s);
        g2d.drawString(s, (int) (offx + (c * stepx * resx) - (d.width / 2)), height - offy + 4 + d.height);
    }
    // -- Simple profile drawing --
    if (ProfileType == 0)
        DrawSimpleProfile(g2d, xmin, ymin, resx, resy, TabY);
    else // -- Road/path profile drawing --
    if (ProfileType == 1)
        DrawRoadPathProfile(g2d, xmin, ymin, resx, resy, TabY);
    else // -- Slope profile drawing--
    if (ProfileType == 2)
        DrawSlopeProfile(g2d, xmin, ymin, resx, resy, TabY);
    // -- Vertical line drawing --
    double dist = 0;
    int posx = 0;
    int posy = 0;
    int posy_s = 0;
    g2d.setStroke(myPenMoy);
    g2d.setColor(Color.BLACK);
    for (CgData r : data.data) {
        if ((r.OptionMiniRoadbook & CgConst.MRBOPT_SEL) != 0) {
            dist = r.getTotal(settings.Unit);
            posx = (int) (dist * resx);
            posy = height - offy - (hp + track.TopMargin - 7 - r.VPosMiniRoadbook);
            if (track.LabelToBottom)
                posy_s = height - offy;
            else
                posy_s = TabY[offx + posx];
            g2d.drawLine(offx + posx, posy_s, offx + posx, posy);
        }
    }
    // -- Text box drawing --
    int miniRoadBookGridIndex = 0;
    DrawStringMultiLine drawStringMulti = new DrawStringMultiLine();
    for (CgData r : data.data) {
        if ((r.OptionMiniRoadbook & CgConst.MRBOPT_SEL) != 0) {
            // -- Calc the number of tag
            nbtag = NbTag(r.getTag());
            g2d.setFont(new Font("ARIAL", Font.PLAIN, r.FontSizeMiniRoadbook));
            dist = r.getTotal(settings.Unit);
            posx = (int) (dist * resx);
            posy = hp + track.TopMargin - 0 - r.VPosMiniRoadbook;
            // -- Generate the text to display
            // s = "Les Contamines\n1083m - km:100\n10h23";
            // s = GenLabel("%N\n%Am - km:%D\n%H", r);
            // s = GenLabel(r.FmtLbMiniRoadbook, r);
            // s = Utils.GenLabel(r.FmtLbMiniRoadbook, r, track);
            // s = Utils.GenLabel("%N%L%Am - km:%D\n%H", r, track, settings);
            s = Utils.GenLabel(r.FmtLbMiniRoadbook, r, track, settings);
            drawStringMulti.setText(g2d, s);
            // -- Width calculation
            int w = drawStringMulti.getWidth() + 4 + 2;
            int w1 = (nbtag * 16) + ((nbtag - 1) * 2) + 4;
            if (w1 > w)
                w = w1;
            // -- Text height
            int htext = drawStringMulti.getHeight();
            // Left nothing change
            if ((r.OptionMiniRoadbook & CgConst.MRBOPT_CENTER) != 0) {
                posx = posx - (w + 4) / 2;
            }
            if ((r.OptionMiniRoadbook & CgConst.MRBOPT_RIGHT) != 0) {
                posx = posx - (w + 1);
            }
            // -- Size of the tags (with or without tags)
            int htags = 16;
            if (((r.OptionMiniRoadbook & CgConst.MRBOPT_SHOWTAGS) == 0) || (nbtag == 0))
                htags = 0;
            // -- Draw rectangle With or without selection
            if ((miniRoadBookGridIndex == SelLine) && (WithHighlight)) {
                g2d.setColor(new Color(0xFF, 0xEF, 0xBB));
                g2d.fillRect(offx + posx, height - offy - posy, w, drawStringMulti.getHeight() + htags + 4);
            } else {
                // myBrushWhite
                g2d.setColor(Color.WHITE);
                g2d.fillRect(offx + posx, height - offy - posy, w, drawStringMulti.getHeight() + htags + 4);
            }
            // PenBlackS
            g2d.setColor(Color.BLACK);
            g2d.drawRect(offx + posx, height - offy - posy, w, drawStringMulti.getHeight() + htags + 4);
            g2d.setClip(offx + posx, height - offy - posy, w, drawStringMulti.getHeight() + htags + 4);
            if (miniRoadBookGridIndex == SelLine) {
                xSel1 = offx + posx;
                ySel1 = height - offy - posy;
                xSel2 = xSel1 + w;
                ySel2 = ySel2 + htext + htags + 4;
            }
            // -- Draw the text
            g2d.setColor(Color.BLACK);
            // +
            drawStringMulti.draw(g2d, s, offx + posx + 2, height - offy - posy);
            // htext);
            // -- Set the clipping to the whole panel
            g2d.setClip(0, 0, width, height);
            if ((r.OptionMiniRoadbook & CgConst.MRBOPT_SHOWTAGS) != 0) {
                int m = 0;
                int lt = (int) ((w - w1) / 2);
                if ((r.getTag() & CgConst.TAG_HIGH_PT) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/high_point.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_LOW_PT) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/low_point.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_EAT_PT) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/eat.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_WATER_PT) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/drink.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_COOL_PT) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/photo.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_NOTE) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/note.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
                if ((r.getTag() & CgConst.TAG_INFO) != 0) {
                    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/info.png"));
                    g2d.drawImage(img, (offx + posx + 2 + m + lt), height - offy - posy + 1 + htext, this);
                    m += 18;
                }
            }
        }
        miniRoadBookGridIndex++;
    }
    // -- Copyright --
    Image img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/course_generator/images/copyright.png"));
    g2d.drawImage(img, width - 15, (height - offy - img.getHeight(null)) / 2, this);
    g2d.dispose();
}
Also used : Color(java.awt.Color) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) DateTime(org.joda.time.DateTime) CgData(course_generator.CgData) Graphics2D(java.awt.Graphics2D) DrawStringMultiLine(course_generator.utils.DrawStringMultiLine)

Example 4 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class JPanelResume method refresh.

/**
 * Refresh the resume grid
 *
 * @param force
 */
public void refresh() {
    // Exit if the tab is not displayed
    // if (TabbedPaneMain.getSelectedIndex() != 4) // Resume
    // return;
    // StatusBar.Items["Message"].Visible = true;
    // StatusBar.Items["Message"].Text = "Mise à jour resumé en cours...";
    // StatusBar.Refresh();
    int i = 0;
    int k = 0;
    int old = 0;
    CgData OldData;
    if (Track == null)
        return;
    if (Track.data.isEmpty())
        return;
    CalcClimbResult ccr = new CalcClimbResult();
    CalcAvrSlopeResult casr = new CalcAvrSlopeResult();
    CalcAvrSpeedResult speedResult = new CalcAvrSpeedResult();
    Resume.data.clear();
    OldData = Track.data.get(0);
    for (CgData src : Track.data) {
        if ((src.getTag() & 32) != 0) {
            k++;
            CgResume dst = new CgResume();
            // ResGrid.Rows.Add();
            dst.setNum(k);
            dst.setName(src.getName());
            dst.setLine(src.getNum());
            dst.setElevation(src.getElevation(CgConst.UNIT_METER));
            ccr = Track.CalcClimb(0, i, ccr);
            dst.setClimbP(ccr.cp);
            dst.setClimbM(ccr.cm);
            dst.setDist(src.getTotal(CgConst.UNIT_METER) / 1000.0);
            dst.setTime(src.getTime());
            dst.setHour(src.getHour());
            dst.setTimeLimit(src.getTimeLimit());
            dst.setStationTime(src.getStation());
            dst.setdTime_f(src.getTime() - OldData.getTime());
            dst.setdDist((src.getTotal(CgConst.UNIT_METER) - OldData.getTotal(CgConst.UNIT_METER)) / 1000.0);
            ccr = Track.CalcClimb(old, i, ccr);
            casr = Track.CalcAvrSlope(old, i, casr);
            speedResult = Track.CalcAvrSpeed(old, i, speedResult);
            dst.setdClimbP(ccr.cp);
            dst.setdClimbM(ccr.cm);
            dst.setSpeedP(ccr.cp * 3600 / Math.abs(ccr.tp));
            dst.setSpeedM(ccr.cm * 3600 / Math.abs(ccr.tm));
            // if ((AvrSlopeP == 0) || (Double.IsNaN(AvrSlopeP) ))
            dst.setAvgSlopeP(casr.AvrSlopeP);
            dst.setAvgSlopeM(casr.AvrSlopeM);
            dst.setAvgSpeed(speedResult.getAvrspeed(CgConst.UNIT_METER));
            dst.setComment(src.getComment());
            Resume.data.add(dst);
            OldData = src;
            old = i;
        }
        i++;
    }
    // -- Refresh the grid
    TableResume.invalidate();
}
Also used : CalcClimbResult(course_generator.TrackData.CalcClimbResult) CgResume(course_generator.CgResume) CalcAvrSpeedResult(course_generator.TrackData.CalcAvrSpeedResult) CalcAvrSlopeResult(course_generator.TrackData.CalcAvrSlopeResult) CgData(course_generator.CgData)

Example 5 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class JPanelAnalysisSpeed method Refresh.

/**
 * Update the Time/Distance chart
 */
public void Refresh(TrackData track, CgSettings settings) {
    if (track == null)
        return;
    if (track.data.isEmpty())
        return;
    this.track = track;
    this.settings = settings;
    // -- Calculate the speed regression
    /*
		 * y = ax + b a = the slope of the trend line. b = the intercept of the
		 * trend line.
		 */
    double xAvg = 0;
    double yAvg = 0;
    double v = 0;
    CgData r;
    for (int x = 0; x < track.data.size(); x++) {
        r = track.data.get(x);
        xAvg += x;
        yAvg += (r.getSpeed(settings.Unit) / (100 / r.getDiff())) / (100 / r.getCoeff());
    }
    xAvg = xAvg / track.data.size();
    yAvg = yAvg / track.data.size();
    double v1 = 0;
    double v2 = 0;
    for (int x = 0; x < track.data.size(); x++) {
        r = track.data.get(x);
        v = (r.getSpeed(settings.Unit) / (100 / r.getDiff())) / (100 / r.getCoeff());
        v1 += (x - xAvg) * (v - yAvg);
        v2 += Math.pow(x - xAvg, 2);
    }
    double a = v1 / v2;
    double b = yAvg - a * xAvg;
    // -- Clear all series
    if (datasetSpeedReg.getSeriesCount() > 0)
        datasetSpeedReg.removeAllSeries();
    if (datasetSpeed.getSeriesCount() > 0)
        datasetSpeed.removeAllSeries();
    XYPlot plot = chart.getXYPlot();
    plot.clearDomainMarkers();
    // -- Populate the serie
    XYSeries serie1 = new XYSeries("Speed regression/Distance");
    XYSeries serie2 = new XYSeries("Speed/Distance");
    startSpeed = 0.0;
    endSpeed = 0.0;
    double maxspeed = 0.0;
    double cmpt = 0.0;
    for (CgData d : track.data) {
        double x = d.getTotal(settings.Unit) / 1000;
        double y = d.getSpeed(settings.Unit);
        if (x < 0.001)
            x = 0;
        if (y > maxspeed)
            maxspeed = y;
        if (cmpt == 0)
            startSpeed = (b / (100 / d.getDiff())) / (100 / d.getCoeff());
        if (cmpt == track.data.size() - 1)
            endSpeed = ((a * x + b) / (100 / d.getDiff())) / (100 / d.getCoeff());
        cmpt++;
        serie1.add(x, y / (100.0 / d.getDiff()) / (100.0 / d.getCoeff()));
        serie2.add(x, a * cmpt + b);
    }
    // -- If there is no speed the exit (not already calculated)
    if (maxspeed == 0.0)
        return;
    datasetSpeedReg.addSeries(serie2);
    datasetSpeed.addSeries(serie1);
    ValueAxis axisY = plot.getRangeAxis(0);
    axisY.setRange(0.0, Math.ceil(maxspeed / 5.0) * 5.0);
    axisY = plot.getRangeAxis(1);
    axisY.setRange(0.0, Math.ceil(maxspeed / 5.0) * 5.0);
    chart = CreateChart(datasetSpeedReg, datasetSpeed);
    RefreshInfo(0);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) CgData(course_generator.CgData)

Aggregations

CgData (course_generator.CgData)16 ValueAxis (org.jfree.chart.axis.ValueAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 XYSeries (org.jfree.data.xy.XYSeries)4 CalcLineResult (course_generator.utils.Utils.CalcLineResult)3 Color (java.awt.Color)2 Font (java.awt.Font)2 BufferedImage (java.awt.image.BufferedImage)2 DateTime (org.joda.time.DateTime)2 CgResume (course_generator.CgResume)1 TrackData (course_generator.TrackData)1 CalcAvrSlopeResult (course_generator.TrackData.CalcAvrSlopeResult)1 CalcAvrSpeedResult (course_generator.TrackData.CalcAvrSpeedResult)1 CalcClimbResult (course_generator.TrackData.CalcClimbResult)1 CgSettings (course_generator.settings.CgSettings)1 DrawStringMultiLine (course_generator.utils.DrawStringMultiLine)1 BasicStroke (java.awt.BasicStroke)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1