dcode.h 7.82 KB
Newer Older
1
/*
2
 * This program source code file is part of KiCad, a free EDA CAD application.
3 4 5
 *
 * Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
 * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6
 * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

26 27 28 29
/**
 * @file dcode.h
 */

30 31 32 33 34
#ifndef _DCODE_H_
#define _DCODE_H_

#include <vector>

35
#include <base_struct.h>
36 37


38
class GERBER_DRAW_ITEM;
39

40

41 42 43 44 45
/**
 * Enum APERTURE_T
 * is the set of all gerber aperture types allowed, according to page 16 of
 * http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf
 */
46
enum APERTURE_T {
47 48 49 50 51 52
    APT_CIRCLE  = 'C',      // Flashed shape: Circle with or without hole
    APT_RECT    = 'R',      // Flashed shape: Rectangle with or without hole
    APT_OVAL    = '0',      // Flashed shape: Oval with or without hole
    APT_POLYGON = 'P',      // Flashed shape: Regular polygon (3 to 12 edges)
                            // with or without hole. Can be rotated
    APT_MACRO   = 'M'       // Complex shape given by a macro definition (see AM_PRIMITIVE_ID)
53 54
};

55
// In aperture definition, round, oval and rectangular flashed shapes
56
// can have a hole (round or rectangular)
57 58 59 60 61 62
// this option is stored in .m_DrillShape D_CODE member
enum APERTURE_DEF_HOLETYPE {
    APT_DEF_NO_HOLE = 0,
    APT_DEF_ROUND_HOLE,
    APT_DEF_RECT_HOLE
};
63

64
/* define min and max values for D Codes values.
65
 * note: values >= 0 and > FIRST_DCODE can be used for special purposes
66 67 68 69
 */
#define FIRST_DCODE     10
#define LAST_DCODE      999
#define TOOLS_MAX_COUNT (LAST_DCODE + 1)
70

71
struct APERTURE_MACRO;
72 73 74 75 76 77 78 79


/**
 * Class D_CODE
 * holds a gerber DCODE definition.
 */
class D_CODE
{
80
private:
81 82 83 84 85 86
    APERTURE_MACRO* m_Macro;    ///< no ownership, points to
                                //   GERBER.m_aperture_macros element
    /**
     * parameters used only when this D_CODE holds a reference to an aperture
     * macro, and these parameters would customize the macro.
     */
87
    std::vector<double>   m_am_params;
88

89
    std::vector <wxPoint> m_PolyCorners;    /* Polygon used to draw APT_POLYGON shape and some other
90
                                             * complex shapes which are converted to polygon
91
                                             * (shapes with hole )
92 93 94
                                             */

public:
95 96 97 98 99 100
    wxSize                m_Size;           /* Horizontal and vertical dimensions. */
    APERTURE_T            m_Shape;          /* shape ( Line, rectangle, circle , oval .. ) */
    int                   m_Num_Dcode;      /* D code ( >= 10 ) */
    wxSize                m_Drill;          /* dimension of the hole (if any) */
    APERTURE_DEF_HOLETYPE m_DrillShape;     /* shape of the hole (0 = no hole, round = 1, rect = 2) */
    double                m_Rotation;       /* shape rotation in degrees */
101
    int                   m_EdgesCount;     /* in aperture definition Polygon only: number of edges for the polygon */
102 103
    bool                  m_InUse;          /* false if not used */
    bool                  m_Defined;        /* false if not defined */
104
    wxString              m_SpecialDescr;
105 106 107 108 109 110

public:
    D_CODE( int num_dcode );
    ~D_CODE();
    void Clear_D_CODE_Data();

111 112 113 114 115
    /**
     * AppendParam()
     * Add a parameter to the D_CODE parameter list.
     * used to customize the corresponding aperture macro
     */
116 117
    void AppendParam( double aValue )
    {
118 119
        m_am_params.push_back( aValue );
    }
120

121 122 123 124 125 126 127 128
    /**
     * GetParamCount()
     * Returns the number of parameters stored in parameter list.
     */
    unsigned GetParamCount() const
    {
       return  m_am_params.size();
    }
129

130 131 132 133 134 135 136 137 138 139 140 141
    /**
     * GetParam()
     * Returns a parameter stored in parameter list.
     * @param aIdx = index of parameter
     */
    double GetParam( unsigned aIdx ) const
    {
        wxASSERT( aIdx <= m_am_params.size() );
        if( aIdx <= m_am_params.size() )
            return  m_am_params[aIdx - 1];
        else
            return 0;
142 143
    }

144

145 146 147 148
    void SetMacro( APERTURE_MACRO* aMacro )
    {
        m_Macro = aMacro;
    }
149 150


151
    APERTURE_MACRO* GetMacro() const { return m_Macro; }
152 153 154 155 156 157 158 159

    /**
     * Function ShowApertureType
     * returns a character string telling what type of aperture type \a aType is.
     * @param aType The aperture type to show.
     */
    static const wxChar* ShowApertureType( APERTURE_T aType );

160 161
    /**
     * Function DrawFlashedShape
162 163
     * Draw the dcode shape for flashed items.
     * When an item is flashed, the DCode shape is the shape of the item
164
     * @param aParent = the GERBER_DRAW_ITEM being drawn
165 166 167
     * @param aClipBox = DC clip box (NULL is no clip)
     * @param aDC = device context
     * @param aColor = the normal color to use
168 169
     * @param aAltColor = the color used to draw with "reverse" exposure mode (used in
     *                    aperture macros only)
170
     * @param aShapePos = the actual shape position
171
     * @param aFilledShape = true to draw in filled mode, false to draw in sketch mode
172
     */
173
    void DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox,
174
                           wxDC* aDC, EDA_COLOR_T aColor, EDA_COLOR_T aAltColor,
175
                           wxPoint aShapePos, bool aFilledShape );
176

177 178
    /**
     * Function DrawFlashedPolygon
179
     * a helper function used to draw the polygon stored ion m_PolyCorners
180 181 182
     * Draw some Apertures shapes when they are defined as filled polygons.
     * APT_POLYGON is always a polygon, but some complex shapes are also converted to
     * polygons (shapes with holes, some rotated shapes)
183
     * @param aParent = the GERBER_DRAW_ITEM being drawn
184 185 186
     * @param aClipBox = DC clip box (NULL is no clip)
     * @param aDC = device context
     * @param aColor = the normal color to use
187
     * @param aFilled = true to draw in filled mode, false to draw in sketch mode
188
     * @param aPosition = the actual shape position
189 190
     */
    void DrawFlashedPolygon( GERBER_DRAW_ITEM* aParent,
191
                             EDA_RECT* aClipBox, wxDC* aDC, EDA_COLOR_T aColor,
192
                             bool aFilled, const wxPoint& aPosition );
193

194 195
    /**
     * Function ConvertShapeToPolygon
196 197 198 199 200
     * convert a shape to an equivalent polygon.
     * Arcs and circles are approximated by segments
     * Useful when a shape is not a graphic primitive (shape with hole,
     * rotated shape ... ) and cannot be easily drawn.
     */
201
    void ConvertShapeToPolygon();
202

203 204 205
    /**
     * Function GetShapeDim
     * calculates a value that can be used to evaluate the size of text
206 207 208 209 210 211 212 213 214
     * when displaying the D-Code of an item
     * due to the complexity of some shapes,
     * one cannot calculate the "size" of a shape (only a bounding box)
     * but here, the "dimension" of the shape is the diameter of the primitive
     * or for lines the width of the line if the shape is a line
     * @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
     * @return a dimension, or -1 if no dim to calculate
     */
    int GetShapeDim( GERBER_DRAW_ITEM* aParent );
215 216 217 218
};


#endif  // ifndef _DCODE_H_