Пример #1
0
/**
 * Function OuputOnePolygon
 * write one polygon to output file.
 * Polygon coordinates are expected scaled by the polygon extraction function
 */
void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon, const char * aBrdLayerName )
{
    unsigned ii, jj;
    KPolyPoint currpoint;

    int   offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
    int   offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY );

    KPolyPoint startpoint = *aPolygon.begin();

    switch( m_Format )
    {
    case POSTSCRIPT_FMT:
        offsetY = (int)( m_PixmapHeight * m_ScaleY );
        fprintf( m_Outfile, "newpath\n%d %d moveto\n",
                 startpoint.x(), offsetY - startpoint.y() );
        jj = 0;
        for( ii = 1; ii < aPolygon.size(); ii++ )
        {
            currpoint = *(aPolygon.begin() + ii);
            fprintf( m_Outfile, " %d %d lineto",
                     currpoint.x(), offsetY - currpoint.y() );

            if( jj++ > 6 )
            {
                jj = 0;
                fprintf( m_Outfile, ("\n") );
            }
        }

        fprintf( m_Outfile, "\nclosepath fill\n" );
        break;

    case PCBNEW_KICAD_MOD:
    {
        double width = 0.1;
        fprintf( m_Outfile, "  (fp_poly (pts" );

        jj = 0;
        for( ii = 0; ii < aPolygon.size(); ii++ )
        {
            currpoint = *( aPolygon.begin() + ii );
            fprintf( m_Outfile, " (xy %f %f)",
                    (currpoint.x() - offsetX) / 1e6,
                    (currpoint.y() - offsetY) / 1e6 );

            if( jj++ > 6 )
            {
                jj = 0;
                fprintf( m_Outfile, ("\n    ") );
            }
        }
        // Close polygon
        fprintf( m_Outfile, " (xy %f %f) )",
                (startpoint.x() - offsetX) / 1e6, (startpoint.y() - offsetY) / 1e6 );

        fprintf( m_Outfile, "(layer %s) (width  %f)\n  )\n", aBrdLayerName, width );

    }
    break;

    case KICAD_LOGO:
        fprintf( m_Outfile, "  (pts" );
        // Internal units = micron, file unit = mm
        jj = 0;
        for( ii = 0; ii < aPolygon.size(); ii++ )
        {
            currpoint = *( aPolygon.begin() + ii );
            fprintf( m_Outfile, " (xy %.3f %.3f)",
                    (currpoint.x() - offsetX) / 1e3,
                    (currpoint.y() - offsetY) / 1e3 );

            if( jj++ > 4 )
            {
                jj = 0;
                fprintf( m_Outfile, ("\n    ") );
            }
        }
        // Close polygon
        fprintf( m_Outfile, " (xy %.3f %.3f) )\n",
                (startpoint.x() - offsetX) / 1e3, (startpoint.y() - offsetY) / 1e3 );
        break;

    case EESCHEMA_FMT:
        fprintf( m_Outfile, "P %d 0 0 1", (int) aPolygon.size() + 1 );
        for( ii = 0; ii < aPolygon.size(); ii++ )
        {
            currpoint = *(aPolygon.begin() + ii);
            fprintf( m_Outfile, " %d %d",
                     currpoint.x() - offsetX, currpoint.y() - offsetY );
        }

        // Close polygon
        fprintf( m_Outfile, " %d %d",
                 startpoint.x() - offsetX, startpoint.y() - offsetY );

        fprintf( m_Outfile, " F\n" );
        break;
    }
}
Пример #2
0
/**
 * Function OuputOnePolygon
 * write one polygon to output file.
 * Polygon coordinates are expected scaled by the polugon extraction function
 */
void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon )
{
    unsigned ii;
    KPolyPoint currpoint;

    int   offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
    int   offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY );

    KPolyPoint startpoint = *aPolygon.begin();

    switch( m_Format )
    {
    case POSTSCRIPT_FMT:
        fprintf( m_Outfile, "%d %d moveto\n",
                 startpoint.x(), startpoint.y() );
        for( ii = 1; ii < aPolygon.size(); ii++ )
        {
            currpoint = *(aPolygon.begin() + ii);
            fprintf( m_Outfile, "%d %d lineto\n",
                     currpoint.x(), currpoint.y() );
        }

        fprintf( m_Outfile, "0 setgray fill\n" );
        break;

    case PCBNEW_FMT:
    {
        #define SILKSCREEN_N_FRONT 21
        int layer = SILKSCREEN_N_FRONT;
        int width = 1;
        fprintf( m_Outfile, "DP %d %d %d %d %d %d %d\n",
                 0, 0, 0, 0,
                 (int) aPolygon.size() + 1, width, layer );

        for( ii = 0; ii < aPolygon.size(); ii++ )
        {
            currpoint = *( aPolygon.begin() + ii );
            fprintf( m_Outfile, "Dl %d %d\n",
                    currpoint.x() - offsetX, currpoint.y() - offsetY );
        }

        // Close polygon
        fprintf( m_Outfile, "Dl %d %d\n",
                 startpoint.x() - offsetX, startpoint.y() - offsetY );
    }
    break;

    case EESCHEMA_FMT:
        fprintf( m_Outfile, "P %d 0 0 1", (int) aPolygon.size() + 1 );
        for( ii = 0; ii < aPolygon.size(); ii++ )
        {
            currpoint = *(aPolygon.begin() + ii);
            fprintf( m_Outfile, " %d %d",
                     currpoint.x() - offsetX, currpoint.y() - offsetY );
        }

        // Close polygon
        fprintf( m_Outfile, " %d %d",
                 startpoint.x() - offsetX, startpoint.y() - offsetY );

        fprintf( m_Outfile, " F\n" );
        break;
    }
}