2010-10-01 19:11:30 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-10-01 19:11:30 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
|
|
|
|
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2021-06-03 18:32:24 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see change_log.txt for contributors.
|
2010-10-01 19:11:30 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
/**
|
|
|
|
* @file dcode.h
|
|
|
|
*/
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
#ifndef _DCODE_H_
|
|
|
|
#define _DCODE_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
#include <gal/color4d.h>
|
2017-09-17 22:43:20 +00:00
|
|
|
#include <geometry/shape_poly_set.h>
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
using KIGFX::COLOR4D;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
class wxDC;
|
2010-10-01 19:11:30 +00:00
|
|
|
class GERBER_DRAW_ITEM;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* The set of all gerber aperture types allowed, according to page 16 of
|
2010-09-28 14:42:05 +00:00
|
|
|
* http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf
|
|
|
|
*/
|
2010-09-28 19:34:16 +00:00
|
|
|
enum APERTURE_T {
|
2010-09-29 19:00:35 +00:00
|
|
|
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)
|
2010-09-28 14:42:05 +00:00
|
|
|
};
|
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
// In aperture definition, round, oval and rectangular flashed shapes
|
2011-10-17 20:01:27 +00:00
|
|
|
// can have a hole (round or rectangular)
|
2010-09-28 19:34:16 +00:00
|
|
|
// 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
|
|
|
|
};
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
/* define min and max values for D Codes values.
|
2019-09-15 11:30:56 +00:00
|
|
|
* note: values >= 0 and < FIRST_DCODE can be used for special purposes
|
2010-09-28 19:34:16 +00:00
|
|
|
*/
|
|
|
|
#define FIRST_DCODE 10
|
2019-09-15 11:30:56 +00:00
|
|
|
#define LAST_DCODE 10000
|
2010-09-28 19:34:16 +00:00
|
|
|
#define TOOLS_MAX_COUNT (LAST_DCODE + 1)
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2011-02-16 19:16:38 +00:00
|
|
|
struct APERTURE_MACRO;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* A gerber DCODE (also called Aperture) definition.
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
|
|
|
class D_CODE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
D_CODE( int num_dcode );
|
|
|
|
~D_CODE();
|
|
|
|
void Clear_D_CODE_Data();
|
|
|
|
|
2010-11-30 20:41:35 +00:00
|
|
|
/**
|
|
|
|
* Add a parameter to the D_CODE parameter list.
|
2021-06-03 18:32:24 +00:00
|
|
|
*
|
|
|
|
* Used to customize the corresponding aperture macro.
|
2010-11-30 20:41:35 +00:00
|
|
|
*/
|
2010-09-28 14:42:05 +00:00
|
|
|
void AppendParam( double aValue )
|
|
|
|
{
|
2010-11-30 20:41:35 +00:00
|
|
|
m_am_params.push_back( aValue );
|
|
|
|
}
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-30 20:41:35 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Return the number of parameters stored in parameter list.
|
2010-11-30 20:41:35 +00:00
|
|
|
*/
|
|
|
|
unsigned GetParamCount() const
|
|
|
|
{
|
|
|
|
return m_am_params.size();
|
|
|
|
}
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-30 20:41:35 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Return a parameter stored in parameter list.
|
|
|
|
*
|
|
|
|
* @param aIdx is the index of parameter.
|
2010-11-30 20:41:35 +00:00
|
|
|
*/
|
|
|
|
double GetParam( unsigned aIdx ) const
|
|
|
|
{
|
|
|
|
wxASSERT( aIdx <= m_am_params.size() );
|
2021-06-03 18:32:24 +00:00
|
|
|
|
2010-11-30 20:41:35 +00:00
|
|
|
if( aIdx <= m_am_params.size() )
|
|
|
|
return m_am_params[aIdx - 1];
|
|
|
|
else
|
|
|
|
return 0;
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetMacro( APERTURE_MACRO* aMacro )
|
|
|
|
{
|
|
|
|
m_Macro = aMacro;
|
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2010-12-01 19:30:52 +00:00
|
|
|
APERTURE_MACRO* GetMacro() const { return m_Macro; }
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Return a character string telling what type of aperture type \a aType is.
|
|
|
|
*
|
|
|
|
* @param aType is the aperture type to show.
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
|
|
|
static const wxChar* ShowApertureType( APERTURE_T aType );
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2010-09-28 14:42:05 +00:00
|
|
|
* Draw the dcode shape for flashed items.
|
2021-06-03 18:32:24 +00:00
|
|
|
*
|
|
|
|
* When an item is flashed, the DCode shape is the shape of the item.
|
|
|
|
*
|
|
|
|
* @param aParent is the #GERBER_DRAW_ITEM being drawn.
|
|
|
|
* @param aDC is the device context.
|
|
|
|
* @param aColor is the normal color to use.
|
|
|
|
* @param aShapePos is the actual shape position
|
|
|
|
* @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
2022-09-07 16:54:04 +00:00
|
|
|
void DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
|
|
|
|
const COLOR4D& aColor,
|
2022-01-28 22:51:34 +00:00
|
|
|
const VECTOR2I& aShapePos, bool aFilledShape );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* A helper function used to draw the polygon stored in m_PolyCorners.
|
|
|
|
*
|
|
|
|
* 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).
|
|
|
|
*
|
|
|
|
* @param aParent is the #GERBER_DRAW_ITEM being drawn.
|
|
|
|
* @param aDC is the device context.
|
|
|
|
* @param aColor is the normal color to use.
|
|
|
|
* @param aFilled set to true to draw in filled mode, false to draw in sketch mode.
|
|
|
|
* @param aPosition is the actual shape position.
|
2011-10-17 20:01:27 +00:00
|
|
|
*/
|
2022-09-07 16:54:04 +00:00
|
|
|
void DrawFlashedPolygon( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
|
|
|
|
const COLOR4D& aColor,
|
2022-01-28 22:51:34 +00:00
|
|
|
bool aFilled, const VECTOR2I& aPosition );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* 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.
|
2022-09-07 16:54:04 +00:00
|
|
|
* @param aParent is the #GERBER_DRAW_ITEM using this DCode.
|
|
|
|
* Not used in all shapes, used for APT_MACRO
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
2022-09-07 16:54:04 +00:00
|
|
|
void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent );
|
2010-10-23 18:12:11 +00:00
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Calculate a value that can be used to evaluate the size of text 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 is the parent GERBER_DRAW_ITEM which is actually drawn.
|
|
|
|
* @return a dimension, or -1 if no dim to calculate.
|
2010-10-23 18:12:11 +00:00
|
|
|
*/
|
|
|
|
int GetShapeDim( GERBER_DRAW_ITEM* aParent );
|
2021-06-03 18:32:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
wxSize m_Size; ///< Horizontal and vertical dimensions.
|
|
|
|
APERTURE_T m_Shape; ///< shape ( Line, rectangle, circle , oval .. )
|
|
|
|
int m_Num_Dcode; ///< D code value ( >= 10 )
|
|
|
|
wxSize m_Drill; ///< dimension of the hole (if any) (drill file)
|
|
|
|
APERTURE_DEF_HOLETYPE m_DrillShape; ///< shape of the hole (0 = no hole, round = 1,
|
|
|
|
///< rect = 2).
|
2022-01-20 20:54:22 +00:00
|
|
|
EDA_ANGLE m_Rotation; ///< shape rotation
|
2021-06-03 18:32:24 +00:00
|
|
|
int m_EdgesCount; ///< in aperture definition Polygon only:
|
|
|
|
///< number of edges for the polygon
|
|
|
|
bool m_InUse; ///< false if the aperture (previously defined)
|
|
|
|
///< is not used to draw something
|
|
|
|
bool m_Defined; ///< false if the aperture is not defined in the header
|
|
|
|
wxString m_AperFunction; ///< the aperture attribute (created by a
|
|
|
|
///< %TA.AperFunction command).
|
|
|
|
///< attached to the D_CODE
|
|
|
|
SHAPE_POLY_SET m_Polygon; /* Polygon used to draw APT_POLYGON shape and some other
|
|
|
|
* complex shapes which are converted to polygon
|
|
|
|
* (shapes with hole )
|
|
|
|
*/
|
|
|
|
|
|
|
|
private:
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
std::vector<double> m_am_params;
|
2010-09-28 14:42:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ifndef _DCODE_H_
|