Commit d54ade94 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Rework on DXF export.

parent 073a9e17
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
    BOARD* pcb = GetBoard();
    bool realistic_mode = g_Parm_3D_Visu.IsRealisticMode();

    // Number of segments to draw a circle using segments
    // Number of segments to convert a circle to polygon
    const int       segcountforcircle   = 16;
    double          correctionFactor    = 1.0 / cos( M_PI / (segcountforcircle * 2) );
    const int       segcountLowQuality  = 12;   // segments to draw a circle with low quality
+1 −1
Original line number Diff line number Diff line
@@ -848,7 +848,7 @@ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC,
        // Close the polygon
        if( aPoints[lastpt] != aPoints[0] )
        {
            GRLineTo( aClipBox, aDC, aPoints[lastpt].x, aPoints[lastpt].y, aWidth, aColor );
            GRLineTo( aClipBox, aDC, aPoints[0].x, aPoints[0].y, aWidth, aColor );
        }
    }
}
+82 −24
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <trigo.h>
#include <class_board.h>
#include <class_pad.h>
#include <class_track.h>
#include <class_drawsegment.h>
@@ -38,6 +39,80 @@ static void addTextSegmToPoly( int x0, int y0, int xf, int yf )
                                           s_textCircle2SegmentCount, s_textWidth );
}

/**
 * Function ConvertBrdLayerToPolygonalContours
 * Build a set of polygons which are the outlines of copper items
 * (pads, tracks, texts, zones)
 * the holes in vias or pads are ignored
 * Usefull to export the shape of copper layers to dxf polygons
 * or 3D viewer
 * the polygons are not merged.
 * @param aLayer = A layer, like LAYER_N_BACK, etc.
 * @param aOutlines The CPOLYGONS_LIST to fill in with main outlines.
 * @return true if success, false if a contour is not valid
 */
void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_NUM aLayer, CPOLYGONS_LIST& aOutlines )
{
    // Number of segments to convert a circle to a polygon
    const int       segcountforcircle   = 16;
    double          correctionFactor    = 1.0 / cos( M_PI / (segcountforcircle * 2) );

    // convert tracks and vias:
    for( TRACK* track = m_Track; track != NULL; track = track->Next() )
    {
        if( !track->IsOnLayer( aLayer ) )
            continue;

        track->TransformShapeWithClearanceToPolygon( aOutlines,
                0, segcountforcircle, correctionFactor );
    }

    // convert pads
    for( MODULE* module = m_Modules; module != NULL; module = module->Next() )
    {
        module->TransformPadsShapesWithClearanceToPolygon( aLayer,
                aOutlines, 0, segcountforcircle, correctionFactor );

        // Micro-wave modules may have items on copper layers
        module->TransformGraphicShapesWithClearanceToPolygonSet( aLayer,
                aOutlines, 0, segcountforcircle, correctionFactor );
    }

    // convert copper zones
    for( int ii = 0; ii < GetAreaCount(); ii++ )
    {
        ZONE_CONTAINER* zone = GetArea( ii );
        LAYER_NUM       zonelayer = zone->GetLayer();

        if( zonelayer == aLayer )
            zone->TransformSolidAreasShapesToPolygonSet(
                aOutlines, segcountforcircle, correctionFactor );
    }

    // convert graphic items on copper layers (texts)
    for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
    {
        if( !item->IsOnLayer( aLayer ) )
            continue;

        switch( item->Type() )
        {
        case PCB_LINE_T:    // should not exist on copper layers
            ( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon(
                aOutlines, 0, segcountforcircle, correctionFactor );
            break;

        case PCB_TEXT_T:
            ( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet(
                aOutlines, 0, segcountforcircle, correctionFactor );
            break;

        default:
            break;
        }
    }
}

/* generate pads shapes on layer aLayer as polygons,
 * and adds these polygons to aCornerBuffer
 * aCornerBuffer = the buffer to store polygons
@@ -614,43 +689,26 @@ bool D_PAD::BuildPadDrillShapePolygon( CPOLYGONS_LIST& aCornerBuffer,
                                       int aInflateValue, int aSegmentsPerCircle ) const
{
    wxSize drillsize = GetDrillSize();
    bool hasHole = drillsize.x && drillsize.y;

    if( ! hasHole )
    if( !drillsize.x || !drillsize.y )
        return false;

    drillsize.x += aInflateValue;
    drillsize.y += aInflateValue;

    if( drillsize.x == drillsize.y )    // usual round hole
    {
        TransformCircleToPolygon( aCornerBuffer, GetPosition(),
                                  drillsize.x /2, aSegmentsPerCircle );
                (drillsize.x / 2) + aInflateValue, aSegmentsPerCircle );
    }
    else    // Oblong hole
    {
        wxPoint ends_offset;
        wxPoint start, end;
        int width;

        if( drillsize.x > drillsize.y )    // Horizontal oval
        {
            ends_offset.x = ( drillsize.x - drillsize.y ) / 2;
            width = drillsize.y;
        }
        else    // Vertical oval
        {
            ends_offset.y = ( drillsize.y - drillsize.x ) / 2;
            width = drillsize.x;
        }

        RotatePoint( &ends_offset, GetOrientation() );
        GetOblongDrillGeometry( start, end, width );

        wxPoint start  = GetPosition() + ends_offset;
        wxPoint end  = GetPosition() - ends_offset;
        width += aInflateValue * 2;

        // Prepare the shape creation
        TransformRoundedEndsSegmentToPolygon( aCornerBuffer, start, end,
                                              aSegmentsPerCircle, width );
        TransformRoundedEndsSegmentToPolygon( aCornerBuffer,
                GetPosition() + start, GetPosition() + end, aSegmentsPerCircle, width );
    }

    return true;
+13 −0
Original line number Diff line number Diff line
@@ -685,6 +685,19 @@ public:
                                  CPOLYGONS_LIST& aHoles,
                                  wxString* aErrorText = NULL );

    /**
     * Function ConvertBrdLayerToPolygonalContours
     * Build a set of polygons which are the outlines of copper items
     * (pads, tracks, vias, texts, zones)
     * Holes in vias or pads are ignored
     * Usefull to export the shape of copper layers to dxf polygons
     * or 3D viewer
     * the polygons are not merged.
     * @param aLayer = A copper layer, like LAYER_N_BACK, etc.
     * @param aOutlines The CPOLYGONS_LIST to fill in with items outline.
     */
    void ConvertBrdLayerToPolygonalContours( LAYER_NUM aLayer, CPOLYGONS_LIST& aOutlines );

    /**
     * Function GetLayerName
     * returns the name of a layer given by aLayer.  Copper layers may
+33 −0
Original line number Diff line number Diff line
@@ -637,6 +637,39 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const
}


void D_PAD::GetOblongDrillGeometry( wxPoint& aStartPoint,
                                    wxPoint& aEndPoint, int& aWidth ) const
{
    // calculates the start point, end point and width
    // of an equivalent segment which have the same position and width as the hole
    int delta_cx, delta_cy;

    wxSize halfsize = GetDrillSize();;
    halfsize.x /= 2;
    halfsize.y /= 2;

    if( m_Drill.x > m_Drill.y )  // horizontal
    {
        delta_cx = halfsize.x - halfsize.y;
        delta_cy = 0;
        aWidth   = m_Drill.y;
    }
    else                         // vertical
    {
        delta_cx = 0;
        delta_cy = halfsize.y - halfsize.x;
        aWidth   = m_Drill.x;
    }

    RotatePoint( &delta_cx, &delta_cy, m_Orient );

    aStartPoint.x = delta_cx;
    aStartPoint.y = delta_cy;

    aEndPoint.x = - delta_cx;
    aEndPoint.y = - delta_cy;
}

bool D_PAD::HitTest( const wxPoint& aPosition ) const
{
    int     dx, dy;
Loading