void Route::DrawSegment( ocpnDC& dc, wxPoint *rp1, wxPoint *rp2, ViewPort &vp, bool bdraw_arrow ) { if( m_bRtIsSelected ) dc.SetPen( *g_pRouteMan->GetSelectedRoutePen() ); else if( m_bRtIsActive ) dc.SetPen( *g_pRouteMan->GetActiveRoutePen() ); else dc.SetPen( *g_pRouteMan->GetRoutePen() ); RenderSegment( dc, rp1->x, rp1->y, rp2->x, rp2->y, vp, bdraw_arrow ); }
void Route::Draw( ocpnDC& dc, ViewPort &VP ) { if( m_nPoints == 0 ) return; if( m_bVisible && m_bRtIsSelected ) { dc.SetPen( *g_pRouteMan->GetSelectedRoutePen() ); dc.SetBrush( *g_pRouteMan->GetSelectedRouteBrush() ); } else if ( m_bVisible ) { int style = wxSOLID; int width = g_route_line_width; wxColour col; if( m_style != STYLE_UNDEFINED ) style = m_style; if( m_width != STYLE_UNDEFINED ) width = m_width; 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; } } } dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) ); dc.SetBrush( *wxTheBrushList->FindOrCreateBrush( col, wxSOLID ) ); } if( m_bVisible && m_bRtIsActive ) { dc.SetPen( *g_pRouteMan->GetActiveRoutePen() ); dc.SetBrush( *g_pRouteMan->GetActiveRouteBrush() ); } wxPoint rpt1, rpt2; if ( m_bVisible ) DrawPointWhich( dc, 1, &rpt1 ); wxRoutePointListNode *node = pRoutePointList->GetFirst(); RoutePoint *prp1 = node->GetData(); node = node->GetNext(); if ( !m_bVisible && prp1->m_bKeepXRoute ) prp1->Draw( dc ); while( node ) { RoutePoint *prp2 = node->GetData(); if ( !m_bVisible && prp2->m_bKeepXRoute ) prp2->Draw( dc ); else if (m_bVisible) prp2->Draw( dc, &rpt2 ); if ( m_bVisible ) { // Handle offscreen points bool b_2_on = VP.GetBBox().PointInBox( prp2->m_lon, prp2->m_lat, 0 ); bool b_1_on = VP.GetBBox().PointInBox( prp1->m_lon, prp1->m_lat, 0 ); //TODO This logic could be simpliifed //Simple case if( b_1_on && b_2_on ) RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x, rpt2.y, VP, true ); // with arrows // In the cases where one point is on, and one off // we must decide which way to go in longitude // Arbitrarily, we will go the shortest way double pix_full_circle = WGS84_semimajor_axis_meters * mercator_k0 * 2 * PI * VP.view_scale_ppm; double dp = pow( (double) ( rpt1.x - rpt2.x ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); double dtest; int adder; if( b_1_on && !b_2_on ) { if( rpt2.x < rpt1.x ) adder = (int) pix_full_circle; else adder = -(int) pix_full_circle; dtest = pow( (double) ( rpt1.x - ( rpt2.x + adder ) ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); if( dp < dtest ) adder = 0; RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x + adder, rpt2.y, VP, true ); } else if( !b_1_on && b_2_on ) { if( rpt1.x < rpt2.x ) adder = (int) pix_full_circle; else adder = -(int) pix_full_circle; dtest = pow( (double) ( rpt2.x - ( rpt1.x + adder ) ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); if( dp < dtest ) adder = 0; RenderSegment( dc, rpt1.x + adder, rpt1.y, rpt2.x, rpt2.y, VP, true ); } //Both off, need to check shortest distance else if( !b_1_on && !b_2_on ) { if( rpt1.x < rpt2.x ) adder = (int) pix_full_circle; else adder = -(int) pix_full_circle; dtest = pow( (double) ( rpt2.x - ( rpt1.x + adder ) ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); if( dp < dtest ) adder = 0; RenderSegment( dc, rpt1.x + adder, rpt1.y, rpt2.x, rpt2.y, VP, true ); } } rpt1 = rpt2; prp1 = prp2; node = node->GetNext(); } }
void Route::Draw( ocpnDC& dc, ViewPort &vp, const LLBBox &box ) { if( pRoutePointList->empty() ) return; LLBBox test_box = GetBBox(); if( box.IntersectOut( test_box ) ) // Route is wholly outside window return; int width = g_route_line_width; if( m_width != WIDTH_UNDEFINED ) width = m_width; if( m_bVisible && m_bRtIsSelected ) { wxPen spen = *g_pRouteMan->GetSelectedRoutePen(); spen.SetWidth( width ); dc.SetPen( spen ); dc.SetBrush( *g_pRouteMan->GetSelectedRouteBrush() ); } else if ( m_bVisible ) { wxPenStyle style = wxPENSTYLE_SOLID; wxColour col; if( m_style != wxPENSTYLE_INVALID ) style = m_style; 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; } } } dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) ); dc.SetBrush( *wxTheBrushList->FindOrCreateBrush( col, wxBRUSHSTYLE_SOLID ) ); } if( m_bVisible && m_bRtIsActive ) { wxPen spen = *g_pRouteMan->GetActiveRoutePen(); spen.SetWidth( width ); dc.SetPen( spen ); dc.SetBrush( *g_pRouteMan->GetActiveRouteBrush() ); } wxPoint rpt1, rpt2; if ( m_bVisible ) DrawPointWhich( dc, 1, &rpt1 ); wxRoutePointListNode *node = pRoutePointList->GetFirst(); RoutePoint *prp1 = node->GetData(); node = node->GetNext(); if ( !m_bVisible && prp1->m_bKeepXRoute ) prp1->Draw( dc ); while( node ) { RoutePoint *prp2 = node->GetData(); if ( !m_bVisible && prp2->m_bKeepXRoute ) prp2->Draw( dc ); else if (m_bVisible) prp2->Draw( dc, &rpt2 ); if ( m_bVisible ) { // Handle offscreen points bool b_2_on = vp.GetBBox().Contains( prp2->m_lat, prp2->m_lon ); bool b_1_on = vp.GetBBox().Contains( prp1->m_lat, prp1->m_lon ); //Simple case if( b_1_on && b_2_on ) RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x, rpt2.y, vp, true, m_hiliteWidth ); // with arrows // In the cases where one point is on, and one off // we must decide which way to go in longitude // Arbitrarily, we will go the shortest way double pix_full_circle = WGS84_semimajor_axis_meters * mercator_k0 * 2 * PI * vp.view_scale_ppm; double dp = pow( (double) ( rpt1.x - rpt2.x ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); double dtest; int adder; if( b_1_on && !b_2_on ) { if( rpt2.x < rpt1.x ) adder = (int) pix_full_circle; else adder = -(int) pix_full_circle; dtest = pow( (double) ( rpt1.x - ( rpt2.x + adder ) ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 ); if( dp < dtest ) adder = 0; RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x + adder, rpt2.y, vp, true, m_hiliteWidth ); } else if( !b_1_on ) { if( rpt1.x < rpt2.x ) adder = (int) pix_full_circle; else adder = -(int) pix_full_circle; float rxd = rpt2.x - ( rpt1.x + adder ); float ryd = rpt1.y - rpt2.y; dtest = rxd*rxd + ryd*ryd; if( dp < dtest ) adder = 0; RenderSegment( dc, rpt1.x + adder, rpt1.y, rpt2.x, rpt2.y, vp, true, m_hiliteWidth ); } } rpt1 = rpt2; prp1 = prp2; node = node->GetNext(); } }