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

Gerbview: added support of mirroring, scaling an offseting RS274X commands

parent 55eefbbe
Loading
Loading
Loading
Loading
+29 −20
Original line number Diff line number Diff line
@@ -82,8 +82,8 @@ static void GRSFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle
                          int EndAngle, int r, int width, int Color, int BgColor );
static void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
                      int width, int aPenSize, int Color );
static void GRSFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
                          int width, int Color );
static void GRSLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
                          int lines, int width, int Color );
/**/

extern BASE_SCREEN* ActiveScreen;
@@ -990,6 +990,13 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
              GRMapY( y2 ), ZoomValue( width ), 0, Color );
}

void GRCSegm( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
              int aWidth, int aColor )
{
    GRSCSegm( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
              GRMapX( aEnd.x ), GRMapY( aEnd.y ),
              ZoomValue( aWidth ), 0, aColor );
}

/*
 * Draw segment (full) with rounded ends in object space (real coords.).
@@ -997,24 +1004,17 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
void GRFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
                  int width, int Color )
{
    GRSFillCSegm( ClipBox, DC, GRMapX( x1 ), GRMapY( y1 ), GRMapX( x2 ),
                  GRMapY( y2 ), ZoomValue( width ), Color );
    WinClipAndDrawLine( ClipBox, DC, GRMapX( x1 ), GRMapY( y1 ), GRMapX( x2 ),
                  GRMapY( y2 ), Color, ZoomValue( width ) );
}


/*
 * Draw segment with rounded ends in screen space.
 */
void GRSFillCSegm( EDA_Rect* ClipBox,
                   wxDC*     DC,
                   int       x1,
                   int       y1,
                   int       x2,
                   int       y2,
                   int       width,
                   int       Color )
void GRFilledSegment( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
                      int aWidth, int aColor )
{
    WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, Color, width );
    WinClipAndDrawLine( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
                  GRMapX( aEnd.x ), GRMapY( aEnd.y ),
                  aColor, ZoomValue( aWidth ) );
}


@@ -1498,6 +1498,15 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
             Color );
}

void GRArc1( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
             wxPoint aCenter, int aWidth, int aColor )
{
    GRSArc1( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
             GRMapX( aEnd.x ), GRMapY( aEnd.y ),
             GRMapX( aCenter.x ), GRMapY( aCenter.y ), ZoomValue( aWidth ),
             aColor );
}


/*
 * Draw an arc, width = width, in screen space.
+4 −3
Original line number Diff line number Diff line
@@ -123,12 +123,13 @@ void GERBER::ResetDefaultValues()
    m_LayerName     = wxT( "no layer name" );       // Layer name from the LN command
    m_LayerNegative = false;                        // true = Negative Layer
    m_ImageNegative = false;                        // true = Negative image
    m_GerbMetric    = false;                        // false = Inches, true = metric
    m_GerbMetric    = false;                        // false = Inches (default), true = metric
    m_Relative = false;                             // false = absolute Coord,
                                                    // true = relative Coord
    m_NoTrailingZeros = false;                      // true: trailing zeros deleted
    m_MirorA    = false;                            // true: miror / axe A (default = X)
    m_MirorB    = false;                            // true: miror / axe B (default = Y)
    m_MirrorA    = false;                           // true: miror / axe A (default = X)
    m_MirrorB    = false;                           // true: miror / axe B (default = Y)
    m_SwapAxis  = false;                            // false if A = X, B = Y; true if A =Y, B = Y
    m_Has_DCode = false;                            // true = DCodes in file
                                                    // false = no DCode->
                                                    // search for separate DCode file
+8 −6
Original line number Diff line number Diff line
@@ -38,11 +38,12 @@ public:
    bool               m_GerbMetric;                                    // false = Inches, true = metric
    bool               m_Relative;                                      // false = absolute Coord, true = relative Coord
    bool               m_NoTrailingZeros;                               // true: remove tailing zeros.
    bool               m_MirorA;                                        // true: miror / axe A (X)
    bool               m_MirorB;                                        // true: miror / axe B (Y)
    bool               m_Has_DCode;                                     // true = DCodes in file
                                                                        // (false = no DCode -> separate DCode file
    wxPoint            m_Offset;                                        // Coord Offset
    bool               m_SwapAxis;                                      // false (default) if A = X and B = Y
                                                                        // true if A = Y, B = X
    bool               m_MirrorA;                                       // true: miror / axe A (X)
    bool               m_MirrorB;                                       // true: miror / axe B (Y)
    wxPoint            m_ImageOffset;                                   // Coord Offset, from IO command
    wxPoint            m_Offset;                                        // Coord Offset, from OF command
    wxSize             m_FmtScale;                                      // Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4
    wxSize             m_FmtLen;                                        // Nb chars per coord. ex fmt 2.3, m_FmtLen = 5
    wxRealPoint        m_LayerScale;                                    // scale (X and Y) of layer.
@@ -62,7 +63,8 @@ public:
    int                m_FilesPtr;                                      // Stack pointer for files list

    int                m_Selected_Tool;                                 // For hightlight: current selected Dcode

    bool               m_Has_DCode;                                     // true = DCodes in file
                                                                        // (false = no DCode -> separate DCode file
    bool               m_360Arc_enbl;                                   // Enbl 360 deg circular interpolation
    bool               m_PolygonFillMode;                               // Enable polygon mode (read coord as a polygon descr)
    int                m_PolygonFillModeState;                          // In polygon mode: 0 = first segm, 1 = next segm
+98 −33
Original line number Diff line number Diff line
@@ -42,10 +42,11 @@


/**********************************************************/
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) :
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER* aGerberparams ) :
    BOARD_ITEM( aParent, TYPE_GERBER_DRAW_ITEM )
/**********************************************************/
{
    m_imageParams = aGerberparams;
    m_Layer         = 0;
    m_Shape         = GBR_SEGMENT;
    m_Flashed       = false;
@@ -53,6 +54,12 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) :
    m_UnitsMetric   = false;
    m_ImageNegative = false;
    m_LayerNegative = false;
    m_swapAxis      = false;
    m_mirrorA       = false;
    m_mirrorB       = false;
    m_drawScale.x   = m_drawScale.y = 1.0;
    if( m_imageParams )
        SetLayerParameters();
}


@@ -60,6 +67,7 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) :
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) :
    BOARD_ITEM( aSource )
{
    m_imageParams = aSource.m_imageParams;
    m_Shape = aSource.m_Shape;

    m_Flags     = aSource.m_Flags;
@@ -77,7 +85,12 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) :
    m_UnitsMetric   = aSource.m_UnitsMetric;
    m_ImageNegative = aSource.m_ImageNegative;
    m_LayerNegative = aSource.m_LayerNegative;

    m_swapAxis      = aSource.m_swapAxis;
    m_mirrorA       = aSource.m_mirrorA;
    m_mirrorB       = aSource.m_mirrorB;
    m_layerOffset   = aSource.m_layerOffset;
    m_drawScale.x   = aSource.m_drawScale.x;
    m_drawScale.y   = aSource.m_drawScale.y;
}


@@ -92,6 +105,55 @@ GERBER_DRAW_ITEM* GERBER_DRAW_ITEM::Copy() const
}


/**
 * Function GetABPosition
 * returns the image position of aPosition for this object.
 * Image position is the value of aPosition, modified by image parameters:
 * offsets, axis selection, scale, rotation
 * @param aXYPosition = position in Y,X gerber axis
 * @return const wxPoint& - The position in A,B axis.
 */
wxPoint GERBER_DRAW_ITEM::GetABPosition( wxPoint& aXYPosition )
{
    /* Note: RS274Xrevd_e is obscure about the order of transforms:
     * For instance: Rotation must be made after or before mirroring ?
     */
    wxPoint abPos = aXYPosition;

    if( m_swapAxis )
        EXCHG( abPos.x, abPos.y );
    abPos  += m_layerOffset + m_imageParams->m_ImageOffset;
    abPos.x = wxRound( abPos.x * m_drawScale.x );
    abPos.y = wxRound( abPos.y * m_drawScale.y );
    if( m_imageParams->m_Rotation )
        RotatePoint( &abPos, m_imageParams->m_Rotation );
    if( m_mirrorA )
        NEGATE( abPos.x );
    if( m_mirrorB )
        NEGATE( abPos.y );
    return abPos;
}


/** function SetLayerParameters
 * Initialize draw parameters from Image and Layer parameters
 * found in the gerber file:
 *   m_UnitsMetric,
 *   m_MirrorA, m_MirrorB,
 *   m_DrawScale, m_DrawOffset
 */
void GERBER_DRAW_ITEM::SetLayerParameters()
{
    m_UnitsMetric = m_imageParams->m_GerbMetric;
    m_swapAxis    = m_imageParams->m_SwapAxis;              // false if A = X, B = Y;
                                                            // true if A =Y, B = Y
    m_mirrorA     = m_imageParams->m_MirrorA;               // true: mirror / axe A
    m_mirrorB     = m_imageParams->m_MirrorB;               // true: mirror / axe B
    m_drawScale   = m_imageParams->m_LayerScale;            // A and B scaling factor
    m_layerOffset = m_imageParams->m_Offset;                // Offset from OF command
}


wxString GERBER_DRAW_ITEM::ShowGBRShape()
{
    switch( m_Shape )
@@ -244,27 +306,29 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
        if( !isFilled )
        {
            // draw the border of the pen's path using two circles, each as narrow as possible
            GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius - halfPenWidth, 0, color );
            GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius + halfPenWidth, 0, color );
            GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                      radius - halfPenWidth, 0, color );
            GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                      radius + halfPenWidth, 0, color );
        }
        else    // Filled mode
        {
            GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius, m_Size.x, color );
            GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                      radius, m_Size.x, color );
        }
        break;

    case GBR_ARC:
        if( !isFilled )
        {
            GRArc1( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y,
                    m_End.x, m_End.y,
                    m_ArcCentre.x, m_ArcCentre.y, 0, color );
            GRArc1( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                    GetABPosition( m_End ), GetABPosition( m_ArcCentre ),
                    0, color );
        }
        else
        {
            GRArc1( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y,
                    m_End.x, m_End.y,
                    m_ArcCentre.x, m_ArcCentre.y,
            GRArc1( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                    GetABPosition( m_End ), GetABPosition( m_ArcCentre ),
                    m_Size.x, color );
        }
        break;
@@ -281,11 +345,11 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,

    case GBR_SEGMENT:
        if( !isFilled )
            GRCSegm( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y,
                     m_End.x, m_End.y, m_Size.x, color );
            GRCSegm( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                     GetABPosition( m_End ), m_Size.x, color );
        else
            GRFillCSegm( &aPanel->m_ClipBox, aDC, m_Start.x,
                         m_Start.y, m_End.x, m_End.y, m_Size.x, color );
            GRFilledSegment( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
                             GetABPosition( m_End ), m_Size.x, color );
        break;

    default:
@@ -317,6 +381,7 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_Rect* aClipBox,
        for( unsigned ii = 0; ii < points.size(); ii++ )
        {
            points[ii] += aOffset;
            points[ii]  = GetABPosition( points[ii] );
        }
    }

+46 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include "base_struct.h"
#include "class_board_item.h"
class GERBER;

/* Shapes id for basic shapes ( .m_Shape member ) */
enum Gbr_Basic_Shapes {
@@ -67,18 +68,34 @@ public:
    wxPoint m_ArcCentre;                    // for arcs only: Centre of arc
    std::vector <wxPoint> m_PolyCorners;    // list of corners for polygons (G36 to G37 coordinates)
                                            // or for complex shapes which are converted to polygon
    wxSize  m_Size;                         // Flashed shapes size of the shape
    wxSize  m_Size;                         // Flashed shapes: size of the shape
                                            // Lines : m_Size.x = m_Size.y = line width
    bool    m_Flashed;                      // True for flashed items
    int     m_DCode;                        // DCode used to draw this item.
                                            // 0 for items that do not use DCodes (polygons)
                                            // or when unknown and normal values are 10 to 999
                                            // values 0 to 9 can be used for special purposes
    // These values are used to draw this item, according to gerber layers parameters
    // Because these values can change inside a gerber image, they are stored here
    // for each item
    bool        m_ImageNegative;            // true = item in negative image
    bool        m_LayerNegative;            // TRUE = item in negative Layer
private:
    GERBER* m_imageParams;                 /* main GERBER info for this item
                                             * Note: some params stored in this class are common
                                             * to the whole gerber file (i.e) the whole graphic layer
                                             * and some can change when reaging the file, so they
                                             * are stored inside this item
                                             * there is no redundancy for these parameters
                                             */
    bool        m_swapAxis;                 // false if A = X, B = Y; true if A =Y, B = Y
    bool        m_mirrorA;                  // true: mirror / axe A
    bool        m_mirrorB;                  // true: mirror / axe B
    wxRealPoint m_drawScale;                // A and B scaling factor
    wxPoint     m_layerOffset;               // Offset for A and B axis, from OF parameter

public:
    GERBER_DRAW_ITEM( BOARD_ITEM* aParent );
    GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER* aGerberparams );
    GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
    ~GERBER_DRAW_ITEM();

@@ -99,6 +116,15 @@ public:
    }


    /** function SetLayerParameters
     * Initialize parameters from Image and Layer parameters
     * found in the gerber file:
     *   m_UnitsMetric,
     *   m_MirrorA, m_MirrorB,
     *   m_DrawScale, m_DrawOffset
     */
    void SetLayerParameters( );

    /**
     * Function Move
     * move this object.
@@ -110,12 +136,22 @@ public:
     * Function GetPosition
     * returns the position of this object.
     * @return const wxPoint& - The position of this object.
     * This function exists mainly to satisfy the virtual GetPosition() in parent class
     */
    wxPoint& GetPosition()
    {
        return m_Start;  // it had to be start or end.
    }

    /**
     * Function GetABPosition
     * returns the image position of aPosition for this object.
     * Image position is the value of aPosition, modified by image parameters:
     * offsets, axis selection, scale, rotation
     * @param aXYPosition = position in Y,X gerber axis
     * @return const wxPoint - The given position in A,B axis.
     */
    wxPoint GetABPosition(wxPoint& aXYPosition );

    /**
     * Function GetDcodeDescr
@@ -185,6 +221,7 @@ public:
    bool         Save( FILE* aFile ) const;

#if defined(DEBUG)

    /**
     * Function Show
     * is used to output the object tree, currently for debugging only.
@@ -193,6 +230,7 @@ public:
     * @param os The ostream& to output to.
     */
    virtual void Show( int nestLevel, std::ostream& os );

#endif
};

Loading