2010-09-28 14:42:05 +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-09-28 14:42:05 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 <Jean-Pierre Charras>
|
2011-09-30 18:15:37 +00:00
|
|
|
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
|
2010-09-28 14:42:05 +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 class_gerber_draw_item.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CLASS_GERBER_DRAW_ITEM_H
|
|
|
|
#define CLASS_GERBER_DRAW_ITEM_H
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <base_struct.h>
|
2012-05-04 17:44:42 +00:00
|
|
|
#include <dlist.h>
|
2013-03-30 17:24:04 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2012-09-01 13:38:27 +00:00
|
|
|
#include <gr_basic.h>
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
class GERBER_IMAGE;
|
2012-05-04 17:44:42 +00:00
|
|
|
class GBR_LAYOUT;
|
|
|
|
class D_CODE;
|
2013-01-12 17:32:24 +00:00
|
|
|
class MSG_PANEL_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
|
|
|
/* Shapes id for basic shapes ( .m_Shape member ) */
|
|
|
|
enum Gbr_Basic_Shapes {
|
|
|
|
GBR_SEGMENT = 0, // usual segment : line with rounded ends
|
|
|
|
GBR_ARC, // Arcs (with rounded ends)
|
|
|
|
GBR_CIRCLE, // ring
|
|
|
|
GBR_POLYGON, // polygonal shape
|
|
|
|
GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
|
|
|
|
GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
|
|
|
|
GBR_SPOT_OVAL, // flashed shape: oval shape
|
2011-10-17 20:01:27 +00:00
|
|
|
GBR_SPOT_POLY, // flashed shape: regular polygon, 3 to 12 edges
|
2010-09-28 19:34:16 +00:00
|
|
|
GBR_SPOT_MACRO, // complex shape described by a macro
|
2010-09-28 14:42:05 +00:00
|
|
|
GBR_LAST // last value for this list
|
|
|
|
};
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
class GERBER_DRAW_ITEM : public EDA_ITEM
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
// make SetNext() and SetBack() private so that they may not be called from anywhere.
|
|
|
|
// list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
|
|
|
|
private:
|
2010-12-08 20:12:46 +00:00
|
|
|
void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
|
|
|
|
void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
2011-10-17 20:01:27 +00:00
|
|
|
bool m_UnitsMetric; /* store here the gerber units (inch/mm). Used
|
|
|
|
* only to calculate aperture macros shapes sizes */
|
2010-09-28 14:42:05 +00:00
|
|
|
int m_Shape; // Shape and type of this gerber item
|
|
|
|
wxPoint m_Start; // Line or arc start point or position of the shape
|
|
|
|
// for flashed items
|
|
|
|
wxPoint m_End; // Line or arc end point
|
|
|
|
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
|
2010-10-09 20:05:03 +00:00
|
|
|
wxSize m_Size; // Flashed shapes: size of the shape
|
2010-09-28 14:42:05 +00:00
|
|
|
// 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
|
2010-10-16 14:51:22 +00:00
|
|
|
GERBER_IMAGE* m_imageParams; /* main GERBER info for this item
|
2010-10-09 20:05:03 +00:00
|
|
|
* Note: some params stored in this class are common
|
2011-10-17 20:01:27 +00:00
|
|
|
* 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
|
2010-10-09 20:05:03 +00:00
|
|
|
*/
|
2010-10-16 14:51:22 +00:00
|
|
|
private:
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM m_Layer;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
// These values are used to draw this item, according to gerber layers parameters
|
2011-10-17 20:01:27 +00:00
|
|
|
// Because they can change inside a gerber image, they are stored here
|
2010-10-16 14:51:22 +00:00
|
|
|
// for each item
|
2011-10-17 20:01:27 +00:00
|
|
|
bool m_LayerNegative; // true = item in negative Layer
|
2010-10-09 20:05:03 +00:00
|
|
|
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
|
2010-10-16 14:51:22 +00:00
|
|
|
wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
|
2010-10-17 16:42:06 +00:00
|
|
|
double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
public:
|
2012-05-04 17:44:42 +00:00
|
|
|
GERBER_DRAW_ITEM( GBR_LAYOUT* aParent, GERBER_IMAGE* aGerberparams );
|
2010-09-28 14:42:05 +00:00
|
|
|
GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
|
|
|
|
~GERBER_DRAW_ITEM();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Copy
|
|
|
|
* will copy this object
|
|
|
|
* the corresponding type.
|
|
|
|
* @return - GERBER_DRAW_ITEM*
|
|
|
|
*/
|
|
|
|
GERBER_DRAW_ITEM* Copy() const;
|
|
|
|
|
|
|
|
GERBER_DRAW_ITEM* Next() const { return (GERBER_DRAW_ITEM*) Pnext; }
|
|
|
|
GERBER_DRAW_ITEM* Back() const { return (GERBER_DRAW_ITEM*) Pback; }
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
/**
|
|
|
|
* Function GetLayer
|
|
|
|
* returns the layer this item is on.
|
|
|
|
*/
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM GetLayer() const { return m_Layer; }
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLayer
|
|
|
|
* sets the layer this item is on.
|
|
|
|
* @param aLayer The layer number.
|
|
|
|
* is virtual because some items (in fact: class DIMENSION)
|
|
|
|
* have a slightly different initialization
|
|
|
|
*/
|
2013-03-31 13:27:46 +00:00
|
|
|
void SetLayer( LAYER_NUM aLayer ) { m_Layer = aLayer; }
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2013-03-30 17:24:04 +00:00
|
|
|
LAYER_MSK GetLayerMask()
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2013-03-30 17:24:04 +00:00
|
|
|
return ::GetLayerMask( m_Layer );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
bool GetLayerPolarity()
|
|
|
|
{
|
|
|
|
return m_LayerNegative;
|
|
|
|
}
|
2010-12-18 18:47:58 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
/**
|
|
|
|
* Function HasNegativeItems
|
|
|
|
* @return true if this item or at least one shape (when using aperture macros
|
|
|
|
* must be drawn in background color
|
|
|
|
* used to optimize screen refresh (when no items are in background color
|
|
|
|
* refresh can be faster)
|
|
|
|
*/
|
|
|
|
bool HasNegativeItems();
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function SetLayerParameters
|
2010-10-09 20:05:03 +00:00
|
|
|
* Initialize parameters from Image and Layer parameters
|
|
|
|
* found in the gerber file:
|
|
|
|
* m_UnitsMetric,
|
|
|
|
* m_MirrorA, m_MirrorB,
|
|
|
|
* m_DrawScale, m_DrawOffset
|
|
|
|
*/
|
2011-10-17 20:01:27 +00:00
|
|
|
void SetLayerParameters();
|
2010-10-09 20:05:03 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
void SetLayerPolarity( bool aNegative)
|
|
|
|
{
|
|
|
|
m_LayerNegative = aNegative;
|
|
|
|
}
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/**
|
2010-10-15 18:59:26 +00:00
|
|
|
* Function MoveAB
|
2010-09-28 14:42:05 +00:00
|
|
|
* move this object.
|
2010-12-18 18:47:58 +00:00
|
|
|
* @param aMoveVector - the move vector for this object.
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
2010-10-15 18:59:26 +00:00
|
|
|
void MoveAB( const wxPoint& aMoveVector );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function MoveXY
|
|
|
|
* move this object.
|
2010-12-18 18:47:58 +00:00
|
|
|
* @param aMoveVector - the move vector for this object, in XY gerber axis.
|
2010-10-15 18:59:26 +00:00
|
|
|
*/
|
|
|
|
void MoveXY( const wxPoint& aMoveVector );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetPosition
|
|
|
|
* returns the position of this object.
|
|
|
|
* @return const wxPoint& - The position of this object.
|
2010-10-09 20:05:03 +00:00
|
|
|
* This function exists mainly to satisfy the virtual GetPosition() in parent class
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
2012-02-20 04:33:54 +00:00
|
|
|
const wxPoint& GetPosition() const { return m_Start; }
|
|
|
|
void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
|
2011-11-29 17:25:30 +00:00
|
|
|
|
2010-10-09 20:05:03 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2010-10-10 17:57:54 +00:00
|
|
|
* @param aXYPosition = position in X,Y gerber axis
|
|
|
|
* @return const wxPoint - The given position in plotter A,B axis.
|
2010-10-09 20:05:03 +00:00
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
|
2010-10-10 17:57:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetXYPosition
|
|
|
|
* 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 aABPosition = position in A,B plotter axis
|
|
|
|
* @return const wxPoint - The given position in X,Y axis.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
wxPoint GetXYPosition( const wxPoint& aABPosition );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetDcodeDescr
|
|
|
|
* returns the GetDcodeDescr of this object, or NULL.
|
|
|
|
* @return D_CODE* - a pointer to the DCode description (for flashed items).
|
|
|
|
*/
|
2011-10-17 20:01:27 +00:00
|
|
|
D_CODE* GetDcodeDescr();
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT GetBoundingBox() const;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/* Display on screen: */
|
2011-10-17 20:01:27 +00:00
|
|
|
void Draw( EDA_DRAW_PANEL* aPanel,
|
|
|
|
wxDC* aDC,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE aDrawMode,
|
2012-05-04 17:44:42 +00:00
|
|
|
const wxPoint&aOffset );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function ConvertSegmentToPolygon
|
2010-10-25 07:43:50 +00:00
|
|
|
* convert a line to an equivalent polygon.
|
|
|
|
* Useful when a line is plotted using a rectangular pen.
|
|
|
|
* In this case, the usual segment plot function cannot be used
|
|
|
|
*/
|
2011-10-17 20:01:27 +00:00
|
|
|
void ConvertSegmentToPolygon();
|
2010-10-25 07:43:50 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function DrawGbrPoly
|
2010-12-14 15:56:30 +00:00
|
|
|
* a helper function used to draw the polygon stored in m_PolyCorners
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
void DrawGbrPoly( EDA_RECT* aClipBox,
|
2012-09-02 12:06:47 +00:00
|
|
|
wxDC* aDC, EDA_COLOR_T aColor,
|
2010-09-28 14:42:05 +00:00
|
|
|
const wxPoint& aOffset, bool aFilledShape );
|
|
|
|
|
|
|
|
/* divers */
|
|
|
|
int Shape() const { return m_Shape; }
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
wxString ShowGBRShape();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
2010-12-18 18:47:58 +00:00
|
|
|
* @param aRefPos a wxPoint to test
|
2010-09-28 14:42:05 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-10-17 20:01:27 +00:00
|
|
|
bool HitTest( const wxPoint& aRefPos );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-17 20:01:27 +00:00
|
|
|
* Function HitTest (overloaded)
|
2010-09-28 14:42:05 +00:00
|
|
|
* tests if the given wxRect intersect this object.
|
|
|
|
* For now, an ending point must be inside this rect.
|
2010-12-18 18:47:58 +00:00
|
|
|
* @param aRefArea a wxPoint to test
|
2010-09-28 14:42:05 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-10-17 20:01:27 +00:00
|
|
|
bool HitTest( EDA_RECT& aRefArea );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetClass
|
|
|
|
* returns the class name.
|
|
|
|
* @return wxString
|
|
|
|
*/
|
|
|
|
wxString GetClass() const
|
|
|
|
{
|
|
|
|
return wxT( "GERBER_DRAW_ITEM" );
|
|
|
|
}
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
/**
|
|
|
|
* Function Save.
|
|
|
|
* currently: no nothing, but must be defined to meet requirements
|
|
|
|
* of the basic class
|
|
|
|
*/
|
|
|
|
bool Save( FILE* aFile ) const;
|
2010-09-29 06:05:36 +00:00
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
/**
|
|
|
|
* Function UnLink
|
|
|
|
* detaches this object from its owner.
|
|
|
|
*/
|
|
|
|
void UnLink()
|
|
|
|
{
|
|
|
|
DLIST<GERBER_DRAW_ITEM>* list = (DLIST<GERBER_DRAW_ITEM>*) GetList();
|
|
|
|
wxASSERT( list );
|
|
|
|
|
|
|
|
if( list )
|
|
|
|
list->Remove( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteStructure
|
|
|
|
* deletes this object after UnLink()ing it from its owner.
|
|
|
|
*/
|
|
|
|
void DeleteStructure()
|
|
|
|
{
|
|
|
|
UnLink();
|
|
|
|
delete this;
|
|
|
|
}
|
2010-09-29 06:05:36 +00:00
|
|
|
#if defined(DEBUG)
|
2011-12-14 17:25:42 +00:00
|
|
|
void Show( int nestLevel, std::ostream& os ) const; // override
|
2010-09-29 06:05:36 +00:00
|
|
|
#endif
|
2011-12-14 17:25:42 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CLASS_GERBER_DRAW_ITEM_H */
|