Search in sources :

Example 1 with CalcLineResult

use of course_generator.utils.Utils.CalcLineResult 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 CalcLineResult

use of course_generator.utils.Utils.CalcLineResult 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 CalcLineResult

use of course_generator.utils.Utils.CalcLineResult in project Course_Generator by patrovite.

the class TrackData method Calculate.

/**
 * Calculate the time for each position of the track
 */
public void Calculate() {
    int j = 0;
    int k = 0;
    double ts = 0.0;
    double x = 0.0;
    double x1 = 0.0;
    double y1 = 0.0;
    double x2 = 0.0;
    double y2 = 0.0;
    double y = 0.0;
    double tmp = 0.0;
    double night = 0.0;
    double dt = 0.0;
    double ef = 1.0;
    boolean ok;
    if (param == null) {
        return;
    }
    isTimeLoaded = false;
    String sParamfile = Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + Paramfile + ".par";
    try {
        param.Load(sParamfile);
    } catch (Exception e) {
        return;
    }
    ef = 1;
    dt = 0;
    // -- Calculation loop --
    for (CgData r : data) {
        x = r.getSlope();
        if (x > CgConst.MAX_CLIMB) {
            x = CgConst.MAX_CLIMB;
        }
        if (x < CgConst.MIN_CLIMB) {
            x = CgConst.MIN_CLIMB;
        }
        ok = false;
        for (// -2
        j = 0; // -2
        j <= param.data.size() - 1; // -2
        j++) {
            tmp = param.data.get(j).Slope;
            if (tmp >= x) {
                k = j - 1;
                if (j == 0) {
                    k = 0;
                }
                x1 = param.data.get(k).Slope;
                y1 = param.data.get(k).Speed;
                x2 = param.data.get(j).Slope;
                y2 = param.data.get(j).Speed;
                ok = true;
                break;
            }
        }
        if (ok) {
            // "b" from the line equation
            if (x1 != x2) {
                Utils.CalcLineResult res = new CalcLineResult();
                res = Utils.CalcLine(x1, y1, x2, y2, res);
                // We calculate the line equation. "Y"=speed in km/h
                // and "X"=slope
                y = res.a * x + res.b;
            } else {
                y = y1;
            }
        } else {
            y = (double) param.data.get(param.data.size() - 2).Speed;
        }
        // --Night coeff --
        DateTime t = r.getHour();
        if (bNightCoeff && ((Utils.CompareHMS(t, StartNightTime) >= 0) || (Utils.CompareHMS(t, EndNightTime) <= 0))) {
            if (r.getSlope() < -2.0) {
                night = 100.0 / NightCoeffDesc;
            } else {
                night = 100.0 / NightCoeffAsc;
            }
        } else {
            night = 1;
        }
        // --Elev effect --
        if (bElevEffect && ((double) r.getElevation(CgConst.UNIT_METER) > 1500.0)) {
            ef = 1.0 + (Math.round(((double) r.getElevation(CgConst.UNIT_METER) - 1500.0) / 100.0) / 100.0);
        } else {
            ef = 1.0;
        }
        // --
        double dist = r.getDist(CgConst.UNIT_METER);
        double coeff = 100.0;
        double diff = 100.0;
        if (coeff != 0.0) {
            coeff = 100.0 / r.getCoeff();
        }
        if (diff != 0) {
            diff = 100.0 / r.getDiff();
        }
        double station = (double) (r.getStation());
        if (y != 0.0) {
            // Calculate the travel time in second in a part of the track
            ts = (dist / (y / 3.6)) * coeff * diff * night * ef + station;
        } else {
            ts = 0.0;
        }
        dt = dt + ts;
        r.setdTime_f(ts);
        r.setTime((int) Math.round(dt));
        if (ts != 0.0) {
            r.setSpeed(dist * 3.6 / ts);
        } else {
            r.setSpeed(0.0);
        }
        r.setHour(StartTime.plusSeconds((int) (Math.round(dt))));
    }
    // End of the calculation loop --
    TotalTime = (int) Math.round(dt);
    isCalculated = true;
    isModified = true;
}
Also used : CalcLineResult(course_generator.utils.Utils.CalcLineResult) Utils(course_generator.utils.Utils) CalcLineResult(course_generator.utils.Utils.CalcLineResult) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) DateTime(org.joda.time.DateTime)

Example 4 with CalcLineResult

use of course_generator.utils.Utils.CalcLineResult in project Course_Generator by patrovite.

the class frmMain method Create_MainToolbar.

/**
 * Create the Main toolbar
 */
private void Create_MainToolbar() {
    ToolBarMain = new javax.swing.JToolBar();
    ToolBarMain.setFloatable(false);
    ToolBarMain.setRollover(true);
    // -- Open GPX
    // ----------------------------------------------------------
    btOpenGPX = new javax.swing.JButton();
    btOpenGPX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/openGPX.png")));
    btOpenGPX.setToolTipText(bundle.getString("frmMain.btOpenGPX.toolTipText"));
    btOpenGPX.setFocusable(false);
    btOpenGPX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            OpenGPXDialog();
        }
    });
    ToolBarMain.add(btOpenGPX);
    // -- Open CGX
    // ----------------------------------------------------------
    btOpenCGX = new javax.swing.JButton();
    btOpenCGX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/openCGX.png")));
    btOpenCGX.setToolTipText(bundle.getString("frmMain.btOpenCGX.toolTipText"));
    btOpenCGX.setFocusable(false);
    btOpenCGX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            OpenCGXDialog();
        }
    });
    ToolBarMain.add(btOpenCGX);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Save CGX
    // ----------------------------------------------------------
    btSaveCGX = new javax.swing.JButton();
    btSaveCGX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/saveCGX.png")));
    btSaveCGX.setToolTipText(bundle.getString("frmMain.btSaveCGX.toolTipText"));
    btSaveCGX.setFocusable(false);
    btSaveCGX.setEnabled(false);
    btSaveCGX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveCGX();
        }
    });
    ToolBarMain.add(btSaveCGX);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Undo
    // --------------------------------------------------------------
    btUndo = new javax.swing.JButton();
    btUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/undo.png")));
    btUndo.setToolTipText(bundle.getString("frmMain.btUndo.toolTipText"));
    btUndo.setFocusable(false);
    btUndo.setEnabled(false);
    btUndo.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            RestoreInCGX();
        }
    });
    ToolBarMain.add(btUndo);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Search
    // ------------------------------------------------------------
    btSearch = new javax.swing.JButton();
    btSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/search.png")));
    btSearch.setToolTipText(bundle.getString("frmMain.btSearch.toolTipText"));
    btSearch.setFocusable(false);
    btSearch.setEnabled(false);
    btSearch.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SearchPointDialog();
        }
    });
    ToolBarMain.add(btSearch);
    // -- Previous mark
    // -----------------------------------------------------
    btGotoPreviousMark = new javax.swing.JButton();
    btGotoPreviousMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/prev.png")));
    btGotoPreviousMark.setToolTipText(bundle.getString("frmMain.btGotoPreviousMark.toolTipText"));
    btGotoPreviousMark.setFocusable(false);
    btGotoPreviousMark.setEnabled(false);
    btGotoPreviousMark.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            int p = GoToPreviousMark();
            if ((p >= 0) && (p < Track.data.size())) {
                panelMap.RefreshCurrentPosMarker(Track.data.get(p).getLatitude(), Track.data.get(p).getLongitude());
            }
        }
    });
    ToolBarMain.add(btGotoPreviousMark);
    // -- Next mark
    // ---------------------------------------------------------
    btGotoNextMark = new javax.swing.JButton();
    btGotoNextMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/next.png")));
    btGotoNextMark.setToolTipText(bundle.getString("frmMain.btGotoNextMark.toolTipText"));
    btGotoNextMark.setFocusable(false);
    btGotoNextMark.setEnabled(false);
    btGotoNextMark.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            int p = GoToNextMark();
            if ((p >= 0) && (p < Track.data.size())) {
                panelMap.RefreshCurrentPosMarker(Track.data.get(p).getLatitude(), Track.data.get(p).getLongitude());
            }
        }
    });
    ToolBarMain.add(btGotoNextMark);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Mini roadbook
    // ------------------------------------------------
    btMiniRoadbook = new javax.swing.JButton();
    btMiniRoadbook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/profil.png")));
    btMiniRoadbook.setToolTipText(bundle.getString("frmMain.btMiniRoadbook.toolTipText"));
    btMiniRoadbook.setFocusable(false);
    btMiniRoadbook.setEnabled(false);
    btMiniRoadbook.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            ShowMRB();
        }
    });
    ToolBarMain.add(btMiniRoadbook);
    // -- Display S/S curves
    // ------------------------------------------------
    btDisplaySSCurves = new javax.swing.JButton();
    btDisplaySSCurves.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/curve.png")));
    btDisplaySSCurves.setToolTipText(bundle.getString("frmMain.btDisplaySSCurves.toolTipText"));
    btDisplaySSCurves.setFocusable(false);
    btDisplaySSCurves.setEnabled(false);
    btDisplaySSCurves.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EditSSCurves();
        }
    });
    ToolBarMain.add(btDisplaySSCurves);
    // -- Track settings
    // ----------------------------------------------------
    btTrackSettings = new javax.swing.JButton();
    btTrackSettings.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/settings.png")));
    btTrackSettings.setToolTipText(bundle.getString("frmMain.btTrackSettings.toolTipText"));
    btTrackSettings.setFocusable(false);
    btTrackSettings.setEnabled(false);
    btTrackSettings.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            TrackSettings();
        }
    });
    ToolBarMain.add(btTrackSettings);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Fill difficulty
    // ----------------------------------------------------
    btFillDiff = new javax.swing.JButton();
    btFillDiff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/fill_diff.png")));
    btFillDiff.setToolTipText(bundle.getString("frmMain.btFillDiff.toolTipText"));
    btFillDiff.setFocusable(false);
    btFillDiff.setEnabled(false);
    btFillDiff.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (Track.data.isEmpty())
                return;
            int start = panelTrackData.getSelectedRow();
            int end = start + panelTrackData.getSelectedRowCount();
            frmFillDiff frm = new frmFillDiff();
            EditDiffResult res = frm.showDialog(Settings, Track, start, end);
            if (res.Valid) {
                BackupInCGX();
                for (int i = res.Start; i <= res.End; i++) {
                    Track.data.get(i).setDiff(res.Difficulty);
                }
                Track.isCalculated = false;
                Track.isModified = true;
                panelTrackData.refresh();
                panelProfil.RefreshProfilChart();
                jPanelTimeDist.Refresh(Track, Settings);
                jPanelSpeed.Refresh(Track, Settings);
                jPanelSpeedSlope.Refresh(Track, Settings);
                RefreshStatusbar(Track);
            }
        }
    });
    ToolBarMain.add(btFillDiff);
    // -- Fill coeff
    // ----------------------------------------------------
    btFillCoeff = new javax.swing.JButton();
    btFillCoeff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/tiredness.png")));
    btFillCoeff.setToolTipText(bundle.getString("frmMain.btFillCoeff.toolTipText"));
    btFillCoeff.setFocusable(false);
    btFillCoeff.setEnabled(false);
    btFillCoeff.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (Track.data.size() <= 0)
                return;
            int start = panelTrackData.getSelectedRow();
            int end = start + panelTrackData.getSelectedRowCount();
            frmFillCoeff frm = new frmFillCoeff();
            EditCoeffResult res = frm.showDialog(Settings, Track, start, end);
            if (res.Valid) {
                BackupInCGX();
                if (res.Start == res.End) {
                    Track.data.get(res.Start).setCoeff(res.Start_Coeff);
                } else {
                    double x1 = Track.data.get(res.Start).getTotal(// cd.data[frm.start].Total;
                    CgConst.UNIT_METER);
                    // frm.startval;
                    double y1 = res.Start_Coeff;
                    double x2 = Track.data.get(res.End).getTotal(// cd.data[frm.end].Total;
                    CgConst.UNIT_METER);
                    // frm.endval;
                    double y2 = res.End_Coeff;
                    CalcLineResult rc = new CalcLineResult();
                    rc = Utils.CalcLine(x1, y1, x2, y2, rc);
                    // Line equation calc with "Y"=distance and "X"=Coeff
                    double x = 0.0;
                    double offset = 0.0;
                    double coeff = 0;
                    for (int i = res.Start; i <= res.End; i++) {
                        x = Track.data.get(i).getTotal(CgConst.UNIT_METER);
                        offset = offset + Track.data.get(i).getRecovery();
                        coeff = (rc.a * x + rc.b) + offset;
                        // Validity tests
                        if (coeff > CgConst.MAX_COEFF)
                            coeff = CgConst.MAX_COEFF;
                        if (coeff < 0)
                            coeff = 0;
                        Track.data.get(i).setCoeff(coeff);
                    }
                }
                Track.isCalculated = false;
                Track.isModified = true;
                panelTrackData.refresh();
                panelProfil.RefreshProfilChart();
                jPanelTimeDist.Refresh(Track, Settings);
                jPanelSpeed.Refresh(Track, Settings);
                jPanelSpeedSlope.Refresh(Track, Settings);
                RefreshStatusbar(Track);
            }
        }
    });
    ToolBarMain.add(btFillCoeff);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Calculate track time
    // ----------------------------------------------
    btCalculateTrackTime = new javax.swing.JButton();
    btCalculateTrackTime.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/refresh.png")));
    btCalculateTrackTime.setToolTipText(bundle.getString("frmMain.btCalculateTrackTime.toolTipText"));
    btCalculateTrackTime.setFocusable(false);
    btCalculateTrackTime.setEnabled(false);
    btCalculateTrackTime.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            CalcTrackTime();
        }
    });
    ToolBarMain.add(btCalculateTrackTime);
}
Also used : EditDiffResult(course_generator.dialogs.frmFillDiff.EditDiffResult) JButton(javax.swing.JButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) course_generator.dialogs.frmFillCoeff(course_generator.dialogs.frmFillCoeff) EditCoeffResult(course_generator.dialogs.frmFillCoeff.EditCoeffResult) ImageIcon(javax.swing.ImageIcon) CalcLineResult(course_generator.utils.Utils.CalcLineResult) course_generator.dialogs.frmFillDiff(course_generator.dialogs.frmFillDiff)

Example 5 with CalcLineResult

use of course_generator.utils.Utils.CalcLineResult in project Course_Generator by patrovite.

the class PanelProfilMRB method DrawRoadPathProfile.

/**
 * Draw the road/path 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 DrawRoadPathProfile(Graphics2D g2d, Double xmin, Double ymin, double resx, double resy, int[] TabY) {
    int cmpt = 0;
    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));
    // path
    for (CgData r : track.data) {
        // Point on botton 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;
        g2d.setColor(track.clProfil_RS_Path);
        if (r.getDiff() == 100)
            cmpt++;
        if (// Filtre
        (xCurvePts[2] - xCurvePts[0]) > track.CurveFilter) {
            if (cmpt > 0)
                g2d.setColor(track.clProfil_RS_Road);
            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));
            cmpt = 0;
        }
    }
    // 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));
    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;
        g2d.setColor(track.clProfil_RS_Path);
        g2d.setColor(track.clProfil_RS_Border);
        g2d.setStroke(PenRP_Border);
        if (// Filtre
        (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)

Aggregations

CalcLineResult (course_generator.utils.Utils.CalcLineResult)5 CgData (course_generator.CgData)3 course_generator.dialogs.frmFillCoeff (course_generator.dialogs.frmFillCoeff)1 EditCoeffResult (course_generator.dialogs.frmFillCoeff.EditCoeffResult)1 course_generator.dialogs.frmFillDiff (course_generator.dialogs.frmFillDiff)1 EditDiffResult (course_generator.dialogs.frmFillDiff.EditDiffResult)1 Utils (course_generator.utils.Utils)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DateTime (org.joda.time.DateTime)1