Example #1
0
void Route::DrawGL( ViewPort &VP, OCPNRegion &region )
{
#ifdef ocpnUSE_GL
    if( m_nPoints < 1 || !m_bVisible ) return;
    
    if(m_hiliteWidth) {
        wxColour y = GetGlobalColor( _T ( "YELO1" ) );
        wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 );

        wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID );

        ocpnDC dc;
        dc.SetPen( HiPen );
        DrawGLLines(VP, &dc);
    }
    
    /* determine color and width */
    wxColour col;

    int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width;
    if( m_width != wxPENSTYLE_INVALID )
        width = m_width;
    if(m_bIsTrack)
        width = g_pRouteMan->GetTrackPen()->GetWidth();
    
    if( m_bRtIsActive )
    {
        col = g_pRouteMan->GetActiveRoutePen()->GetColour();
    } else if( m_bRtIsSelected ) {
        col = g_pRouteMan->GetSelectedRoutePen()->GetColour();
    } else {
        if( m_Colour == wxEmptyString ) {
            col = g_pRouteMan->GetRoutePen()->GetColour();
            
            //  For tracks, establish colour based on first icon name
            if(m_bIsTrack){
                wxRoutePointListNode *node = pRoutePointList->GetFirst();
                RoutePoint *prp = node->GetData();
                
                if( prp->GetIconName().StartsWith( _T("xmred") ) ) 
                    col = GetGlobalColor( _T ( "URED" ) );
                else if( prp->GetIconName().StartsWith( _T("xmblue") ) ) 
                    col = GetGlobalColor( _T ( "BLUE3" ) );
                else if( prp->GetIconName().StartsWith( _T("xmgreen") ) ) 
                    col = GetGlobalColor( _T ( "UGREN" ) );
                else 
                    col = GetGlobalColor( _T ( "CHMGD" ) );
            }
        } else {
            for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) {
                if( m_Colour == ::GpxxColorNames[i] ) {
                    col = ::GpxxColors[i];
                    break;
                }
            }
        }
    }
        
    glColor3ub(col.Red(), col.Green(), col.Blue());
    glLineWidth(wxMax( g_GLMinSymbolLineWidth, width ));

#ifndef ocpnUSE_GLES // linestipple is emulated poorly
    if( m_style != wxPENSTYLE_INVALID )
        glEnable( GL_LINE_STIPPLE );

    switch( m_style ) {
    case wxDOT:        glLineStipple( 1, 0x3333 ); break;
    case wxLONG_DASH:  glLineStipple( 1, 0xFFF8 ); break;
    case wxSHORT_DASH: glLineStipple( 1, 0x3F3F ); break;
    case wxDOT_DASH:   glLineStipple( 1, 0x8FF1 ); break;
    default: break;
    }
#endif

    DrawGLLines(VP, NULL);

    glDisable (GL_LINE_STIPPLE);
    
    /* direction arrows.. could probably be further optimized for opengl */
    if( !m_bIsTrack ) {
        wxRoutePointListNode *node = pRoutePointList->GetFirst();
        wxPoint2DDouble rpt1, rpt2;
        while(node) {
            RoutePoint *prp = node->GetData();
//            cc1->GetDoubleCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 );
            rpt2 = prp->m_screen_pos;
            if(node != pRoutePointList->GetFirst() && prp->m_pos_on_screen)
                RenderSegmentArrowsGL( rpt1.m_x, rpt1.m_y, rpt2.m_x, rpt2.m_y, cc1->GetVP() );
            rpt1 = rpt2;
            node = node->GetNext();
        }
    }

    /*  Route points  */
    for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) {
        RoutePoint *prp = node->GetData();
        if ( m_bVisible || prp->m_bKeepXRoute )
            prp->DrawGL( VP, region, true );
    }        
#endif
}
Example #2
0
void Route::DrawGLRouteLines( ViewPort &vp )
{
#ifdef ocpnUSE_GL
    //  Hiliting first
    //  Being special case to draw something for a 1 point route....
    ocpnDC dc;
    if(m_hiliteWidth) {
        wxColour y = GetGlobalColor( _T ( "YELO1" ) );
        wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 );

        wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID );

        ocpnDC dc;
        dc.SetPen( HiPen );

        DrawGLLines(vp, &dc);
    }

    /* determine color and width */
    wxColour col;

    int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width;
    if( m_width != wxPENSTYLE_INVALID )
        width = m_width;

    if( m_bRtIsActive )
    {
        col = g_pRouteMan->GetActiveRoutePen()->GetColour();
    } else if( m_bRtIsSelected ) {
        col = g_pRouteMan->GetSelectedRoutePen()->GetColour();
    } else {
        if( m_Colour == wxEmptyString ) {
            col = g_pRouteMan->GetRoutePen()->GetColour();
        } else {
            for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) {
                if( m_Colour == ::GpxxColorNames[i] ) {
                    col = ::GpxxColors[i];
                    break;
                }
            }
        }
    }

    wxPenStyle style = wxPENSTYLE_SOLID;
    if( m_style != wxPENSTYLE_INVALID ) style = m_style;
    dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) );

    glColor3ub(col.Red(), col.Green(), col.Blue());
    glLineWidth( wxMax( g_GLMinSymbolLineWidth, width ) );

    dc.SetGLStipple();

    DrawGLLines(vp, NULL);

    glDisable (GL_LINE_STIPPLE);

    /* direction arrows.. could probably be further optimized for opengl */
    wxRoutePointListNode *node = pRoutePointList->GetFirst();
    wxPoint rpt1, rpt2;
    while(node) {
        RoutePoint *prp = node->GetData();
        cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 );
        if(node != pRoutePointList->GetFirst())
            RenderSegmentArrowsGL( rpt1.x, rpt1.y, rpt2.x, rpt2.y, vp );
        rpt1 = rpt2;
        node = node->GetNext();
    }
#endif
}
Example #3
0
void Route::DrawGL( ViewPort &VP )
{
#ifdef ocpnUSE_GL
    if( m_nPoints < 1 || !m_bVisible ) return;

    //  Hiliting first
    //  Being special case to draw something for a 1 point route....
    ocpnDC dc;
    if(m_hiliteWidth) {
        wxColour y = GetGlobalColor( _T ( "YELO1" ) );
        wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 );

        wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID );

        ocpnDC dc;
        dc.SetPen( HiPen );

        wxRoutePointListNode *node = pRoutePointList->GetFirst();
        RoutePoint *prp0 = node->GetData();
        wxPoint r0;

        bool r0valid = cc1->GetCanvasPointPix( prp0->m_lat, prp0->m_lon, &r0);

        int lines = 0;
        node = node->GetNext();
        while( node ) {

            RoutePoint *prp = node->GetData();
            wxPoint r1;
            bool r1valid = cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &r1);

            if(r0valid && r1valid) {
                dc.StrokeLine( r0.x, r0.y, r1.x, r1.y );
                lines++;
            }

            r0valid = r1valid;
            r0 = r1;
            node = node->GetNext();

        }

        if(lines == 0 &&
                cc1->GetCanvasPointPix( prp0->m_lat, prp0->m_lon, &r0)) {
            dc.StrokeLine( r0.x, r0.y, r0.x + 2, r0.y + 2 );
            return;
        }
    }

//    if( m_nPoints < 2  )
//        return;

    /* determine color and width */
    wxColour col;

    int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width;
    if( m_width != wxPENSTYLE_INVALID )
        width = m_width;
    if(m_bIsTrack)
        width = g_pRouteMan->GetTrackPen()->GetWidth();

    if( m_bRtIsActive )
    {
        col = g_pRouteMan->GetActiveRoutePen()->GetColour();
    } else if( m_bRtIsSelected ) {
        col = g_pRouteMan->GetSelectedRoutePen()->GetColour();
    } else {
        if( m_Colour == wxEmptyString ) {
            col = g_pRouteMan->GetRoutePen()->GetColour();

            //  For tracks, establish colour based on first icon name
            if(m_bIsTrack) {
                wxRoutePointListNode *node = pRoutePointList->GetFirst();
                RoutePoint *prp = node->GetData();

                if( prp->GetIconName().StartsWith( _T("xmred") ) )
                    col = GetGlobalColor( _T ( "URED" ) );
                else if( prp->GetIconName().StartsWith( _T("xmblue") ) )
                    col = GetGlobalColor( _T ( "BLUE3" ) );
                else if( prp->GetIconName().StartsWith( _T("xmgreen") ) )
                    col = GetGlobalColor( _T ( "UGREN" ) );
                else
                    col = GetGlobalColor( _T ( "CHMGD" ) );
            }
        } else {
            for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) {
                if( m_Colour == ::GpxxColorNames[i] ) {
                    col = ::GpxxColors[i];
                    break;
                }
            }
        }
    }

    int style = wxSOLID;
    if( m_style != wxPENSTYLE_INVALID ) style = m_style;
    dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) );

    glColor3ub(col.Red(), col.Green(), col.Blue());
    glLineWidth( wxMax( g_GLMinSymbolLineWidth, width ) );

    dc.SetGLStipple();
    glBegin(GL_LINE_STRIP);
    float lastlon = 0;
    float lastlat = 0;
    unsigned short int FromSegNo = 1;
    for(wxRoutePointListNode *node = pRoutePointList->GetFirst();
            node; node = node->GetNext()) {
        RoutePoint *prp = node->GetData();
        unsigned short int ToSegNo = prp->m_GPXTrkSegNo;

        /* crosses IDL? if so break up into two segments */
        int dir = 0;
        if(prp->m_lon > 150 && lastlon < -150)
            dir = -1;
        else if(prp->m_lon < -150 && lastlon > 150)
            dir = 1;

        wxPoint r;
        if (FromSegNo != ToSegNo)
        {
            glEnd();
            FromSegNo = ToSegNo;
            glBegin(GL_LINE_STRIP);
        }
        if(dir)
        {
            double crosslat = lat_rl_crosses_meridian(lastlat, lastlon, prp->m_lat, prp->m_lon, 180.0);
            if(cc1->GetCanvasPointPix( crosslat, dir*180, &r))
                glVertex2i(r.x, r.y);
            glEnd();
            glBegin(GL_LINE_STRIP);
            if(cc1->GetCanvasPointPix( crosslat, -dir*180, &r))
                glVertex2i(r.x, r.y);
        }
        lastlat=prp->m_lat;
        lastlon=prp->m_lon;

        if(cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &r))
            glVertex2i(r.x, r.y);
        else {
            glEnd();
            glBegin(GL_LINE_STRIP);
        }
    }
    glEnd();
    glDisable (GL_LINE_STIPPLE);

    /* direction arrows.. could probably be further optimized for opengl */
    if( !m_bIsTrack ) {
        wxRoutePointListNode *node = pRoutePointList->GetFirst();
        wxPoint rpt1, rpt2;
        while(node) {
            RoutePoint *prp = node->GetData();
            cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 );
            if(node != pRoutePointList->GetFirst())
                RenderSegmentArrowsGL( rpt1.x, rpt1.y, rpt2.x, rpt2.y, cc1->GetVP() );
            rpt1 = rpt2;
            node = node->GetNext();
        }
    }

    /*  Route points  */
    for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) {
        RoutePoint *prp = node->GetData();
        if ( !m_bVisible && prp->m_bKeepXRoute )
            prp->DrawGL( VP );
        else if (m_bVisible)
            prp->DrawGL( VP );

    }

#endif
}