Changeset af50685 in git


Ignore:
Timestamp:
08/03/15 09:36:41 (5 years ago)
Author:
Olly Betts <olly@…>
Branches:
line_contents, master, stereo, travis-osx
Children:
69f54b0, db71ab5
Parents:
be28d00
Message:

lib/survex.pot,src/: Add "Colour by Length".

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rbe28d00 raf50685  
     1Sun Mar 08 09:35:59 GMT 2015  Olly Betts <olly@survex.com>
     2
     3        * lib/survex.pot,src/: Add "Colour by Length".
     4
    15Sun Mar 08 09:30:16 GMT 2015  Olly Betts <olly@survex.com>
    26
  • lib/survex.pot

    rbe28d00 raf50685  
    19371937#: n:289
    19381938msgid "Colour by E&rror"
     1939msgstr ""
     1940
     1941#: ../src/gfxcore.cc:3410
     1942#: ../src/mainfrm.cc:915
     1943#: n:82
     1944msgid "Colour by &Length"
    19391945msgstr ""
    19401946
  • src/gfxcore.cc

    rbe28d00 raf50685  
    5656// Any error value higher than this is clamped to this.
    5757#define MAX_ERROR 12.0
     58
     59// Any length greater than pow(10, LOG_LEN_MAX) will be clamped to this.
     60const Double LOG_LEN_MAX = 1.5;
    5861
    5962// How many bins per letter height to use when working out non-overlapping
     
    221224    InvalidateList(LIST_DATE_KEY);
    222225    InvalidateList(LIST_ERROR_KEY);
     226    InvalidateList(LIST_LENGTH_KEY);
    223227    InvalidateList(LIST_UNDERGROUND_LEGS);
    224228    InvalidateList(LIST_TUBES);
     
    10741078}
    10751079
     1080void GfxCore::DrawLengthKey()
     1081{
     1082    int num_bands;
     1083    // Use fixed colours for each length so it's directly visually comparable
     1084    // between surveys.
     1085    num_bands = GetNumColourBands();
     1086    for (int band = 0; band < num_bands; ++band) {
     1087        double len = pow(10, LOG_LEN_MAX * band / (num_bands - 1));
     1088        int units = /*m*/424;
     1089        if (!m_Metric) {
     1090            len /= METRES_PER_FOOT;
     1091            units = /*ft*/428;
     1092        }
     1093        key_legends[band].Printf(wxT("%.2f%s"), len, wmsg(units));
     1094    }
     1095
     1096    DrawColourKey(num_bands, wxString(), wxString());
     1097}
     1098
    10761099void GfxCore::DrawScaleBar()
    10771100{
     
    21962219            DrawErrorKey();
    21972220            break;
     2221        case LIST_LENGTH_KEY:
     2222            DrawLengthKey();
     2223            break;
    21982224        case LIST_UNDERGROUND_LEGS:
    21992225            GenerateDisplayList();
     
    23722398        } else if (m_ColourBy == COLOUR_BY_ERROR) {
    23732399            DrawList2D(LIST_ERROR_KEY, GetXSize() - KEY_OFFSET_X,
     2400                       GetYSize() - KEY_OFFSET_Y, 0);
     2401        } else if (m_ColourBy == COLOUR_BY_LENGTH) {
     2402            DrawList2D(LIST_LENGTH_KEY, GetXSize() - KEY_OFFSET_X,
    23742403                       GetYSize() - KEY_OFFSET_Y, 0);
    23752404        }
     
    27622791    }
    27632792    EndPolyline();
     2793}
     2794
     2795void GfxCore::SetColourFromLength(double length, Double factor)
     2796{
     2797    // Set the drawing colour based on log(length_of_leg).
     2798
     2799    Double log_len = log10(length);
     2800    Double how_far = log_len / LOG_LEN_MAX;
     2801    how_far = max(how_far, 0.0);
     2802    how_far = min(how_far, 1.0);
     2803
     2804    int band = int(floor(how_far * (GetNumColourBands() - 1)));
     2805    GLAPen pen1 = GetPen(band);
     2806    if (band < GetNumColourBands() - 1) {
     2807        const GLAPen& pen2 = GetPen(band + 1);
     2808
     2809        Double interval = LOG_LEN_MAX / (GetNumColourBands() - 1);
     2810        Double into_band = log_len / interval - band;
     2811
     2812        assert(into_band >= 0.0);
     2813        assert(into_band <= 1.0);
     2814
     2815        pen1.Interpolate(pen2, into_band);
     2816    }
     2817    SetColour(pen1, factor);
     2818}
     2819
     2820void GfxCore::AddPolylineLength(const traverse & centreline)
     2821{
     2822    vector<PointInfo>::const_iterator i, prev_i;
     2823    i = centreline.begin();
     2824    prev_i = i;
     2825    while (++i != centreline.end()) {
     2826        Double len = (*i - *prev_i).magnitude();
     2827        BeginPolyline();
     2828        SetColourFromLength(len, 1.0);
     2829        PlaceVertex(*prev_i);
     2830        PlaceVertex(*i);
     2831        prev_i = i;
     2832        EndPolyline();
     2833    }
     2834}
     2835
     2836static double static_length_hack; // FIXME
     2837
     2838void GfxCore::AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
     2839                                     const Vector3 &c, const Vector3 &d)
     2840{
     2841    Vector3 normal = (a - c) * (d - b);
     2842    normal.normalise();
     2843    Double factor = dot(normal, light) * .3 + .7;
     2844    int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2));
     2845    int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2));
     2846    // FIXME: should plot triangles instead to avoid rendering glitches.
     2847    BeginQuadrilaterals();
     2848////    PlaceNormal(normal);
     2849    SetColourFromLength(static_length_hack, factor);
     2850    PlaceVertex(a, 0, 0);
     2851    PlaceVertex(b, w, 0);
     2852    PlaceVertex(c, w, h);
     2853    PlaceVertex(d, 0, h);
     2854    EndQuadrilaterals();
    27642855}
    27652856
     
    29563047
    29573048        if (draw) {
     3049            static_length_hack = (pt_v - prev_pt_v).magnitude();
    29583050            if (segment > 0) {
    29593051                (this->*AddQuad)(v[0], v[1], U[1], U[0]);
     
    30813173            AddQuad = &GfxCore::AddQuadrilateralError;
    30823174            AddPoly = &GfxCore::AddPolylineError;
     3175            break;
     3176        case COLOUR_BY_LENGTH:
     3177            AddQuad = &GfxCore::AddQuadrilateralLength;
     3178            AddPoly = &GfxCore::AddPolylineLength;
    30833179            break;
    30843180        default: // case COLOUR_BY_NONE:
     
    33243420        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
    33253421        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
     3422        menu.AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
    33263423        menu.AppendSeparator();
    33273424        /* TRANSLATORS: Menu item which turns off the colour key.
  • src/gfxcore.h

    rbe28d00 raf50685  
    9292    COLOUR_BY_DATE,
    9393    COLOUR_BY_ERROR,
     94    COLOUR_BY_LENGTH,
    9495    COLOUR_BY_LIMIT_ // Leave this last.
    9596};
     
    124125        LIST_DATE_KEY,
    125126        LIST_ERROR_KEY,
     127        LIST_LENGTH_KEY,
    126128        LIST_UNDERGROUND_LEGS,
    127129        LIST_TUBES,
     
    242244    void SetColourFromDate(int date, Double factor);
    243245    void SetColourFromError(double E, Double factor);
     246    void SetColourFromLength(double len, Double factor);
    244247
    245248    int GetClinoOffset() const;
     
    266269    void DrawDateKey();
    267270    void DrawErrorKey();
     271    void DrawLengthKey();
    268272    void DrawCompass();
    269273    void DrawClino();
     
    500504    void AddPolylineDate(const traverse & centreline);
    501505    void AddPolylineError(const traverse & centreline);
     506    void AddPolylineLength(const traverse & centreline);
    502507    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
    503508                          const Vector3 &c, const Vector3 &d);
     
    509514    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
    510515                               const Vector3 &c, const Vector3 &d);
     516    void AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
     517                                const Vector3 &c, const Vector3 &d);
    511518    void MoveViewer(double forward, double up, double right);
    512519
  • src/guicontrol.cc

    rbe28d00 raf50685  
    545545}
    546546
     547void GUIControl::OnColourByLength()
     548{
     549    if (m_View->ColouringBy() == COLOUR_BY_LENGTH) {
     550        m_View->SetColourBy(COLOUR_BY_NONE);
     551    } else {
     552        m_View->SetColourBy(COLOUR_BY_LENGTH);
     553    }
     554}
     555
    547556void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
    548557{
     
    561570    cmd.Enable(m_View->HasData());
    562571    cmd.Check(m_View->ColouringBy() == COLOUR_BY_ERROR);
     572}
     573
     574void GUIControl::OnColourByLengthUpdate(wxUpdateUIEvent& cmd)
     575{
     576    cmd.Enable(m_View->HasData());
     577    cmd.Check(m_View->ColouringBy() == COLOUR_BY_LENGTH);
    563578}
    564579
  • src/guicontrol.h

    rbe28d00 raf50685  
    7676    void OnColourByDate();
    7777    void OnColourByError();
     78    void OnColourByLength();
    7879    void OnShowCrosses();
    7980    void OnShowStationNames();
     
    125126    void OnColourByDateUpdate(wxUpdateUIEvent&);
    126127    void OnColourByErrorUpdate(wxUpdateUIEvent&);
     128    void OnColourByLengthUpdate(wxUpdateUIEvent&);
    127129    void OnShowCrossesUpdate(wxUpdateUIEvent&);
    128130    void OnShowStationNamesUpdate(wxUpdateUIEvent&);
  • src/mainfrm.cc

    rbe28d00 raf50685  
    593593    EVT_MENU(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDate)
    594594    EVT_MENU(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByError)
     595    EVT_MENU(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLength)
    595596    EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
    596597    EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
     
    655656    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
    656657    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
     658    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate)
    657659    EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
    658660    EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate)
     
    911913    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
    912914    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
     915    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
    913916    viewmenu->AppendSeparator();
    914917    viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294));
  • src/mainfrm.h

    rbe28d00 raf50685  
    118118    menu_VIEW_COLOUR_BY_DATE,
    119119    menu_VIEW_COLOUR_BY_ERROR,
     120    menu_VIEW_COLOUR_BY_LENGTH,
    120121    menu_IND_COMPASS,
    121122    menu_IND_CLINO,
     
    321322    void OnColourByDateUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByDateUpdate(event); }
    322323    void OnColourByErrorUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByErrorUpdate(event); }
     324    void OnColourByLengthUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnColourByLengthUpdate(event); }
    323325    void OnShowCrossesUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnShowCrossesUpdate(event); }
    324326    void OnShowEntrancesUpdate(wxUpdateUIEvent& event) { if (m_Control) m_Control->OnShowEntrancesUpdate(event); }
     
    372374    void OnColourByDate(wxCommandEvent&) { if (m_Control) m_Control->OnColourByDate(); }
    373375    void OnColourByError(wxCommandEvent&) { if (m_Control) m_Control->OnColourByError(); }
     376    void OnColourByLength(wxCommandEvent&) { if (m_Control) m_Control->OnColourByLength(); }
    374377    void OnShowCrosses(wxCommandEvent&) { if (m_Control) m_Control->OnShowCrosses(); }
    375378    void OnShowEntrances(wxCommandEvent&) { if (m_Control) m_Control->OnShowEntrances(); }
Note: See TracChangeset for help on using the changeset viewer.