Пример #1
0
//---------------------------------------------------------------
void IsoLine::drawIsoLine(GRIBOverlayFactory *pof, wxDC *dc, PlugIn_ViewPort *vp, bool bHiDef)
{
      int nsegs = trace.size();
      if(nsegs < 1)
            return;

      GetGlobalColor ( _T ( "UITX1" ), &isoLineColor );

#if wxUSE_GRAPHICS_CONTEXT
      wxGraphicsContext *pgc = NULL;
#endif

      if(dc) {
          wxPen ppISO ( isoLineColor, 2 );

#if wxUSE_GRAPHICS_CONTEXT
          wxMemoryDC *pmdc;
          pmdc= wxDynamicCast(dc, wxMemoryDC);
          pgc = wxGraphicsContext::Create(*pmdc);
          pgc->SetPen(ppISO);
#endif
          dc->SetPen(ppISO);
      } else { /* opengl */
#ifdef ocpnUSE_GL
          if(m_pixelMM > 0.2){        // pixel size large enough to render well
          //      Enable anti-aliased lines, at best quality
            glEnable( GL_LINE_SMOOTH );
            glEnable( GL_BLEND );
            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
            glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
            glLineWidth( 2 );
          }
          else{
            glLineWidth( 0.4/m_pixelMM);        //  set a target line width by MM
          }
          
          glColor4ub(isoLineColor.Red(), isoLineColor.Green(), isoLineColor.Blue(),
                     255/*isoLineColor.Alpha()*/);
          glBegin( GL_LINES );
#endif          
      }

      std::list<Segment *>::iterator it;

    //---------------------------------------------------------
    // Dessine les segments
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++)
    {
        Segment *seg = *it;

        if(vp->m_projection_type == PI_PROJECTION_MERCATOR ||
           vp->m_projection_type == PI_PROJECTION_EQUIRECTANGULAR) {
            /* skip segments that go the wrong way around the world */
            double sx1 = seg->px1, sx2 = seg->px2;
            if(sx2 - sx1 > 180)
                sx2 -= 360;
            else if(sx1 - sx2 > 180)
                sx1 -= 360;

            if((sx1+180 < vp->clon && sx2+180 > vp->clon) ||
               (sx1+180 > vp->clon && sx2+180 < vp->clon) ||
               (sx1-180 < vp->clon && sx2-180 > vp->clon) ||
               (sx1-180 > vp->clon && sx2-180 < vp->clon))
                continue;
        }

        wxPoint ab;
        GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
        wxPoint cd;
        GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);

        if(dc) {
#if wxUSE_GRAPHICS_CONTEXT
            if(bHiDef && pgc)
                pgc->StrokeLine(ab.x, ab.y, cd.x, cd.y);
            else
#endif
                dc->DrawLine(ab.x, ab.y, cd.x, cd.y);
        } else { /* opengl */
#ifdef ocpnUSE_GL
            glVertex2d(ab.x, ab.y);
            glVertex2d(cd.x, cd.y);
#endif                
        }
    }

#if 0
      int text_sx, text_sy;
      dc.GetTextExtent(_T("10000"), &text_sx, &text_sy);
//      double m = text_sy / 2;
      int label_size = text_sx;
      int label_space = 400;
//      double coef = .01;
      int len = label_space/4;

      //    Allocate an array big enough
      wxPoint *pPoints = new wxPoint[nsegs+1];

      MySegListList::Node *listnode;
      listnode = m_SegListList.GetFirst();
      while(listnode)
      {
            MySegList *listsort = listnode->GetData();

            //    Fill in the array
            MySegList::Node *node;
            Segment *seg;

            node = listsort->GetFirst();
            if(node)
            {
                  seg = node->GetData();
//                  wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
//                  wxPoint ab(0,0);
				  wxPoint ab;
				  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  pPoints[0] = ab;
            }
            int ip=1;

            while (node)
            {
                  seg = node->GetData();
//                  wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
//                  wxPoint cd(0,0);
				  wxPoint cd;
				  GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);
                  pPoints[ip++] = cd;

                  node=node->GetNext();
            }

            int np = listsort->GetCount() + 1;


            if(np > 1)
            {

      // Test code
      //          dc.DrawLines(np, pPoints);

                  GenerateSpline(np, pPoints);

      //    Test Code
      //            dc.DrawLines(&ocpn_wx_spline_point_list, 0, 0 );

                  bool bDrawing = true;
                  wxPoint lstart;

                  wxList::compatibility_iterator snode = ocpn_wx_spline_point_list.GetFirst();
                  wxPoint *point0 = (wxPoint *)snode->GetData();
                  snode=snode->GetNext();

                  while (snode)
                  {
                        wxPoint *point = (wxPoint *)snode->GetData();

                        ClipResult res = cohen_sutherland_line_clip_i ( &point0->x, &point0->y, &point->x, &point->y,
                                    0, vp->pix_width, 0, vp->pix_height );
                        if ( res != Invisible )
                        {
                              int dl = (int)sqrt(
                                            (double)((point0->x - point->x) * (point0->x - point->x))
                                          +(double)((point0->y - point->y) * (point0->y - point->y)));
                              if(bDrawing)
                              {
                                    len += dl;
                                    if(len > label_space)
                                    {
                                          bDrawing = false;
                                          len = 0;
                                          lstart = *point;
                                    }
                              }
                              else
                              {
                                    len += dl;
                                    if(len > label_size)
                                    {
                                          bDrawing = true;
                                          len = 0;
                                    }
                              }
                        }

                        *point0 = *point;
                        snode=snode->GetNext();
                  }

                  ClearSplineList();
            }

            listnode = listnode->GetNext();             // Next continuous chain

      }

      delete[] pPoints;

#endif

#if wxUSE_GRAPHICS_CONTEXT
      delete pgc;
#endif

      if(!dc) /* opengl */
          glEnd();
}
Пример #2
0
void Route::RenderSegment( ocpnDC& dc, int xa, int ya, int xb, int yb, ViewPort &VP,
        bool bdraw_arrow, int hilite_width )
{
    //    Get the dc boundary
    int sx, sy;
    dc.GetSize( &sx, &sy );

    //    Try to exit early if the segment is nowhere near the screen
    wxRect r( 0, 0, sx, sy );
    wxRect s( xa, ya, 1, 1 );
    wxRect t( xb, yb, 1, 1 );
    s.Union( t );
    if( !r.Intersects( s ) ) return;

    //    Clip the line segment to the dc boundary
    int x0 = xa;
    int y0 = ya;
    int x1 = xb;
    int y1 = yb;

    //    If hilite is desired, use a Native Graphics context to render alpha colours
    //    That is, if wxGraphicsContext is available.....

    if( hilite_width ) {
        if( Visible == cohen_sutherland_line_clip_i( &x0, &y0, &x1, &y1, 0, sx, 0, sy ) ) {
            wxPen psave = dc.GetPen();

            wxColour y = GetGlobalColor( _T ( "YELO1" ) );
            wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 );

            wxPen HiPen( hilt, hilite_width, wxSOLID );

            dc.SetPen( HiPen );
            dc.StrokeLine( x0, y0, x1, y1 );

            dc.SetPen( psave );
            dc.StrokeLine( x0, y0, x1, y1 );
        }
    } else {
        if( Visible == cohen_sutherland_line_clip_i( &x0, &y0, &x1, &y1, 0, sx, 0, sy ) )
            dc.StrokeLine( x0, y0, x1, y1 );
    }

    if( bdraw_arrow ) {
        //    Draw a direction arrow

        double theta = atan2( (double) ( yb - ya ), (double) ( xb - xa ) );
        theta -= PI / 2;

        wxPoint icon[10];
        double icon_scale_factor = 100 * VP.view_scale_ppm;
        icon_scale_factor = fmin ( icon_scale_factor, 1.5 );              // Sets the max size
        icon_scale_factor = fmax ( icon_scale_factor, .10 );

        //    Get the absolute line length
        //    and constrain the arrow to be no more than xx% of the line length
        double nom_arrow_size = 20.;
        double max_arrow_to_leg = .20;
        double lpp = sqrt( pow( (double) ( xa - xb ), 2 ) + pow( (double) ( ya - yb ), 2 ) );

        double icon_size = icon_scale_factor * nom_arrow_size;
        if( icon_size > ( lpp * max_arrow_to_leg ) ) icon_scale_factor = ( lpp * max_arrow_to_leg )
                / nom_arrow_size;

        for( int i = 0; i < 7; i++ ) {
            int j = i * 2;
            double pxa = (double) ( s_arrow_icon[j] );
            double pya = (double) ( s_arrow_icon[j + 1] );

            pya *= icon_scale_factor;
            pxa *= icon_scale_factor;

            double px = ( pxa * sin( theta ) ) + ( pya * cos( theta ) );
            double py = ( pya * sin( theta ) ) - ( pxa * cos( theta ) );

            icon[i].x = (int) ( px ) + xb;
            icon[i].y = (int) ( py ) + yb;
        }
        wxPen savePen = dc.GetPen();
        dc.SetPen( *wxTRANSPARENT_PEN );
        dc.StrokePolygon( 6, &icon[0], 0, 0 );
        dc.SetPen( savePen );
    }
}
Пример #3
0
//---------------------------------------------------------------
void IsoLine::drawIsoLine(GRIBOverlayFactory *pof, wxDC &dc, PlugIn_ViewPort *vp, bool bShowLabels, bool bHiDef)
{
      int nsegs = trace.size();
      if(nsegs < 1)
            return;

      GetGlobalColor ( _T ( "UITX1" ), &isoLineColor );
      wxPen ppISO ( isoLineColor, 2 );

#if wxUSE_GRAPHICS_CONTEXT
      wxMemoryDC *pmdc;
//      pmdc = dynamic_cast<wxMemoryDC*>(&dc);
      pmdc= wxDynamicCast(&dc, wxMemoryDC);
      wxGraphicsContext *pgc = wxGraphicsContext::Create(*pmdc);
      pgc->SetPen(ppISO);
#endif

      dc.SetPen(ppISO);



      std::list<Segment *>::iterator it;

    //---------------------------------------------------------
    // Dessine les segments
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++)
    {
        Segment *seg = *it;

        {
 //             wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
 //             wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
            wxPoint ab;
            GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
            wxPoint cd;
            GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);


///            ClipResult res = cohen_sutherland_line_clip_i ( &ab.x, &ab.y, &cd.x, &cd.y,
///                         0, vp->pix_width, 0, vp->pix_height );
///            if ( res != Invisible )
             {
#if wxUSE_GRAPHICS_CONTEXT
                  if(bHiDef && pgc)
                        pgc->StrokeLine(ab.x, ab.y, cd.x, cd.y);
                  else 
                        dc.DrawLine(ab.x, ab.y, cd.x, cd.y);
#else
                  dc.DrawLine(ab.x, ab.y, cd.x, cd.y);
#endif
             }

        }
    }
//#endif

      int text_sx, text_sy;
      dc.GetTextExtent(_T("10000"), &text_sx, &text_sy);
//      double m = text_sy / 2;
      int label_size = text_sx;
      int label_space = 400;
//      double coef = .01;
      int len = label_space/4;

      //    Allocate an array big enough
      wxPoint *pPoints = new wxPoint[nsegs+1];

      MySegListList::Node *listnode;
      listnode = m_SegListList.GetFirst();
      while(listnode)
      {
            MySegList *listsort = listnode->GetData();

            //    Fill in the array
            MySegList::Node *node;
            Segment *seg;

            node = listsort->GetFirst();
            if(node)
            {
                  seg = node->GetData();
//                  wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
//                  wxPoint ab(0,0);
				  wxPoint ab;
				  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  pPoints[0] = ab;
            }
            int ip=1;

            while (node)
            {
                  seg = node->GetData();
//                  wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
//                  wxPoint cd(0,0);
				  wxPoint cd;
				  GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);
                  pPoints[ip++] = cd;

                  node=node->GetNext();
            }

            int np = listsort->GetCount() + 1;


            if(np > 1)
            {

      // Test code
      //          dc.DrawLines(np, pPoints);

                  GenerateSpline(np, pPoints);

      //    Test Code
      //            dc.DrawLines(&ocpn_wx_spline_point_list, 0, 0 );

                  bool bDrawing = true;
                  wxPoint lstart;

                  wxList::compatibility_iterator snode = ocpn_wx_spline_point_list.GetFirst();
                  wxPoint *point0 = (wxPoint *)snode->GetData();
                  snode=snode->GetNext();

                  while (snode)
                  {
                        wxPoint *point = (wxPoint *)snode->GetData();

                        ClipResult res = cohen_sutherland_line_clip_i ( &point0->x, &point0->y, &point->x, &point->y,
                                    0, vp->pix_width, 0, vp->pix_height );
                        if ( res != Invisible )
                        {
                              int dl = (int)sqrt(
                                            (double)((point0->x - point->x) * (point0->x - point->x))
                                          +(double)((point0->y - point->y) * (point0->y - point->y)));
                              if(bDrawing)
                              {
                                    len += dl;
                                    if(len > label_space)
                                    {
                                          bDrawing = false;
                                          len = 0;
                                          lstart = *point;
                                    }
                              }
                              else
                              {
                                    len += dl;
                                    if(len > label_size)
                                    {
                                          bDrawing = true;
                                          len = 0;
#if 0
                                          if(bShowLabels)
                                          {
                                                double label_angle = atan2((double)(lstart.y - point->y),
                                                    (double)(point->x - lstart.x)) * 180. / PI;
                                                wxString label;
                                                label.Printf(_T("%d"), (int)(value*coef+0.5));

                                                double xs = lstart.x - (m * sin(label_angle * PI / 180.));
                                                double ys = lstart.y - (m * cos(label_angle * PI / 180.));
                                                dc.DrawRotatedText(label, (int)xs, (int)ys, label_angle);
                                          }
#endif
                                    }
                              }

#if 0
//                              if(bDrawing || !bShowLabels)
                              {
                                    if(bHiDef)
                                          dc.StrokeLine(point0->x, point0->y, point->x, point->y);
                                    else
                                          dc.DrawLine(point0->x, point0->y, point->x, point->y);
                              }
#endif
                        }

                        *point0 = *point;
                        snode=snode->GetNext();
                  }

                  ClearSplineList();
            }

            listnode = listnode->GetNext();             // Next continuous chain

      }

      delete[] pPoints;

#if wxUSE_GRAPHICS_CONTEXT
      delete pgc;
#endif

}