2007-12-29 19:27:58 +00:00
|
|
|
// PolyLine.h ... definition of CPolyLine class
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2007-12-29 19:27:58 +00:00
|
|
|
//
|
|
|
|
// A polyline contains one or more contours, where each contour
|
|
|
|
// is defined by a list of corners and side-styles
|
|
|
|
// There may be multiple contours in a polyline.
|
|
|
|
// The last contour may be open or closed, any others must be closed.
|
|
|
|
// All of the corners and side-styles are concatenated into 2 arrays,
|
2008-05-15 11:20:19 +00:00
|
|
|
// separated by setting the end_contour flag of the last corner of
|
2007-12-29 19:27:58 +00:00
|
|
|
// each contour.
|
|
|
|
//
|
2008-09-27 19:26:29 +00:00
|
|
|
// When used for copper (or technical layers) areas, the first contour is the outer edge
|
2007-12-29 19:27:58 +00:00
|
|
|
// of the area, subsequent ones are "holes" in the copper.
|
|
|
|
|
|
|
|
#ifndef POLYLINE_H
|
|
|
|
#define POLYLINE_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2008-11-14 19:38:58 +00:00
|
|
|
#include "kbool/include/kbool/booleng.h"
|
2008-05-30 18:06:21 +00:00
|
|
|
#include "pad_shapes.h"
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2008-09-27 19:26:29 +00:00
|
|
|
// inflection modes for DS_LINE and DS_LINE_VERTEX, used in math_for_graphics.cpp
|
|
|
|
enum
|
|
|
|
{
|
2010-11-12 15:17:10 +00:00
|
|
|
IM_NONE = 0,
|
|
|
|
IM_90_45,
|
|
|
|
IM_45_90,
|
|
|
|
IM_90
|
2008-09-27 19:26:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-29 19:27:58 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
|
|
|
* Function ArmBoolEng
|
2008-05-30 18:06:21 +00:00
|
|
|
* Initialise parameters used in kbool
|
|
|
|
* @param aBooleng = pointer to the Bool_Engine to initialise
|
|
|
|
* @param aConvertHoles = mode for holes when a boolean operation is made
|
|
|
|
* true: holes are linked into outer contours by double overlapping segments
|
|
|
|
* false: holes are not linked: in this mode contours are added clockwise
|
2008-09-26 19:51:36 +00:00
|
|
|
* and polygons added counter clockwise are holes (default)
|
2008-05-30 18:06:21 +00:00
|
|
|
*/
|
2008-06-02 10:23:50 +00:00
|
|
|
void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles = false );
|
2007-12-29 19:27:58 +00:00
|
|
|
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
#define PCBU_PER_MIL 10
|
|
|
|
#define NM_PER_MIL 10 // 25400
|
2007-12-29 19:27:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
#define to_int( x ) wxRound( (x) )
|
2008-10-25 10:21:46 +00:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN( x1, x2 ) ( (x1) > (x2) ? (x2) : (x1) )
|
2008-05-30 18:06:21 +00:00
|
|
|
#endif
|
2008-10-25 10:21:46 +00:00
|
|
|
#ifndef MAX
|
|
|
|
#define MAX( x1, x2 ) ( (x1) > (x2) ? (x1) : (x2) )
|
2008-05-30 18:06:21 +00:00
|
|
|
#endif
|
2007-12-29 19:27:58 +00:00
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CRect
|
|
|
|
{
|
2007-12-29 19:27:58 +00:00
|
|
|
public:
|
2008-05-30 18:06:21 +00:00
|
|
|
int left, right, top, bottom;
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CPoint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int x, y;
|
2008-05-15 11:20:19 +00:00
|
|
|
public:
|
2008-05-30 18:06:21 +00:00
|
|
|
CPoint( void ) { x = y = 0; };
|
|
|
|
CPoint( int i, int j ) { x = i; y = j; };
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CSegment
|
2007-12-29 19:27:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-05-30 18:06:21 +00:00
|
|
|
int xi, yi, xf, yf;
|
|
|
|
CSegment() { };
|
|
|
|
CSegment( int x0, int y0, int x1, int y1 )
|
|
|
|
{
|
|
|
|
xi = x0; yi = y0; xf = x1; yf = y1;
|
|
|
|
}
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
|
|
|
|
#include "math_for_graphics.h"
|
|
|
|
|
|
|
|
class CArc
|
2007-12-29 19:27:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-05-30 18:06:21 +00:00
|
|
|
enum { MAX_STEP = 50 * 25400 }; // max step is 20 mils
|
|
|
|
enum { MIN_STEPS = 18 }; // min step is 5 degrees
|
|
|
|
int style;
|
|
|
|
int xi, yi, xf, yf;
|
|
|
|
int n_steps; // number of straight-line segments in gpc_poly
|
|
|
|
bool bFound;
|
|
|
|
};
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CPolyPt
|
|
|
|
{
|
|
|
|
public:
|
2008-10-11 19:27:43 +00:00
|
|
|
CPolyPt( int qx = 0, int qy = 0, bool qf = false )
|
2008-05-30 18:06:21 +00:00
|
|
|
{ x = qx; y = qy; end_contour = qf; utility = 0; };
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
bool end_contour;
|
|
|
|
int utility;
|
2009-08-23 15:22:44 +00:00
|
|
|
|
|
|
|
bool operator == (const CPolyPt& cpt2 ) const
|
|
|
|
{ return (x == cpt2.x) && (y == cpt2.y) && (end_contour == cpt2.end_contour); }
|
|
|
|
|
|
|
|
bool operator != (CPolyPt& cpt2 ) const
|
|
|
|
{ return (x != cpt2.x) || (y != cpt2.y) || (end_contour != cpt2.end_contour); }
|
2008-05-30 18:06:21 +00:00
|
|
|
};
|
2007-12-29 19:27:58 +00:00
|
|
|
|
2008-10-11 19:27:43 +00:00
|
|
|
#include "polygon_test_point_inside.h"
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CPolyLine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { STRAIGHT, ARC_CW, ARC_CCW }; // side styles
|
|
|
|
enum { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles
|
|
|
|
|
|
|
|
// constructors/destructor
|
|
|
|
CPolyLine();
|
|
|
|
~CPolyLine();
|
|
|
|
|
|
|
|
// functions for modifying polyline
|
|
|
|
void Start( int layer, int x, int y, int hatch );
|
2008-10-11 19:27:43 +00:00
|
|
|
void AppendCorner( int x, int y, int style = STRAIGHT, bool bDraw = false );
|
2008-05-30 18:06:21 +00:00
|
|
|
void InsertCorner( int ic, int x, int y );
|
2008-10-11 19:27:43 +00:00
|
|
|
void DeleteCorner( int ic, bool bDraw = false );
|
2008-05-30 18:06:21 +00:00
|
|
|
void MoveCorner( int ic, int x, int y );
|
2008-10-11 19:27:43 +00:00
|
|
|
void Close( int style = STRAIGHT, bool bDraw = false );
|
2008-05-30 18:06:21 +00:00
|
|
|
void RemoveContour( int icont );
|
|
|
|
|
2011-02-21 19:43:59 +00:00
|
|
|
/**
|
|
|
|
* Function Chamfer
|
|
|
|
* returns a chamfered version of a polygon.
|
|
|
|
* @param aDistance is the chamfering distance.
|
|
|
|
* @return CPolyLine* - Pointer to new polygon.
|
|
|
|
*/
|
|
|
|
CPolyLine* Chamfer( unsigned int aDistance );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Fillet
|
|
|
|
* returns a filleted version of a polygon.
|
|
|
|
* @param aDistance is the fillet radius.
|
|
|
|
* @param aSegments is the number of segments / fillet.
|
|
|
|
* @return CPolyLine* - Pointer to new polygon.
|
|
|
|
*/
|
|
|
|
CPolyLine* Fillet( unsigned int aRadius, unsigned int aSegments );
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
void RemoveAllContours( void );
|
|
|
|
|
|
|
|
// drawing functions
|
|
|
|
void Undraw();
|
|
|
|
void Draw();
|
|
|
|
void Hatch();
|
|
|
|
void MoveOrigin( int x_off, int y_off );
|
|
|
|
|
|
|
|
// misc. functions
|
|
|
|
CRect GetBounds();
|
|
|
|
CRect GetCornerBounds();
|
|
|
|
CRect GetCornerBounds( int icont );
|
|
|
|
void Copy( CPolyLine* src );
|
|
|
|
bool TestPointInside( int x, int y );
|
|
|
|
bool IsCutoutContour( int icont );
|
|
|
|
void AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int num );
|
|
|
|
|
|
|
|
// access functions
|
2011-02-21 19:43:59 +00:00
|
|
|
int GetLayer() { return m_layer; }
|
2008-05-30 18:06:21 +00:00
|
|
|
int GetNumCorners();
|
|
|
|
int GetNumSides();
|
|
|
|
int GetClosed();
|
|
|
|
int GetNumContours();
|
|
|
|
int GetContour( int ic );
|
|
|
|
int GetContourStart( int icont );
|
|
|
|
int GetContourEnd( int icont );
|
|
|
|
int GetContourSize( int icont );
|
|
|
|
int GetX( int ic );
|
|
|
|
int GetY( int ic );
|
|
|
|
int GetEndContour( int ic );
|
|
|
|
|
2011-02-23 21:34:28 +00:00
|
|
|
int GetUtility( int ic ) { return corner[ic].utility; };
|
|
|
|
void SetUtility( int ic, int utility ) { corner[ic].utility = utility; };
|
2008-05-30 18:06:21 +00:00
|
|
|
int GetSideStyle( int is );
|
|
|
|
|
2011-02-23 21:34:28 +00:00
|
|
|
int GetHatchStyle() { return m_HatchStyle; }
|
|
|
|
void SetHatch( int hatch ) { Undraw(); m_HatchStyle = hatch; Draw(); };
|
2008-05-30 18:06:21 +00:00
|
|
|
void SetX( int ic, int x );
|
|
|
|
void SetY( int ic, int y );
|
|
|
|
void SetEndContour( int ic, bool end_contour );
|
|
|
|
void SetSideStyle( int is, int style );
|
|
|
|
|
|
|
|
int RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine*> * pa = NULL );
|
|
|
|
|
2008-06-02 10:23:50 +00:00
|
|
|
int NormalizeAreaOutlines( std::vector<CPolyLine*> * pa = NULL,
|
2008-10-11 19:27:43 +00:00
|
|
|
bool bRetainArcs = false );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
|
|
|
// KBOOL functions
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function AddPolygonsToBoolEng
|
2008-05-30 18:06:21 +00:00
|
|
|
* and edges contours to a kbool engine, preparing a boolean op between polygons
|
|
|
|
* @param aStart_contour: starting contour number (-1 = all, 0 is the outlines of zone, > 1 = holes in zone
|
|
|
|
* @param aEnd_contour: ending contour number (-1 = all after aStart_contour)
|
|
|
|
* @param arc_array: arc connverted to poly (NULL if not exists)
|
|
|
|
* @param aBooleng : pointer on a bool engine (handle a set of polygons)
|
|
|
|
* @param aGroup : group to fill (aGroup = GROUP_A or GROUP_B) operations are made between GROUP_A and GROUP_B
|
|
|
|
*/
|
|
|
|
int AddPolygonsToBoolEng( Bool_Engine* aBooleng,
|
|
|
|
GroupType aGroup,
|
|
|
|
int aStart_contour = -1,
|
|
|
|
int aEnd_contour = -1,
|
|
|
|
std::vector<CArc> * arc_array = NULL );
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function MakeKboolPoly
|
2008-05-30 18:06:21 +00:00
|
|
|
* fill a kbool engine with a closed polyline contour
|
|
|
|
* approximates arcs with multiple straight-line segments
|
|
|
|
* @param aStart_contour: starting contour number (-1 = all, 0 is the outlines of zone, > 1 = holes in zone
|
|
|
|
* @param aEnd_contour: ending contour number (-1 = all after aStart_contour)
|
|
|
|
* combining intersecting contours if possible
|
|
|
|
* @param arc_array : return data on arcs in arc_array
|
2008-09-26 19:51:36 +00:00
|
|
|
* @param aConvertHoles = mode for holes when a boolean operation is made
|
|
|
|
* true: holes are linked into outer contours by double overlapping segments
|
|
|
|
* false: holes are not linked: in this mode contours are added clockwise
|
|
|
|
* and polygons added counter clockwise are holes (default)
|
2008-05-30 18:06:21 +00:00
|
|
|
* @return error: 0 if Ok, 1 if error
|
|
|
|
*/
|
2008-06-02 10:23:50 +00:00
|
|
|
int MakeKboolPoly( int aStart_contour = -1,
|
|
|
|
int aEnd_contour = -1,
|
2008-09-26 19:51:36 +00:00
|
|
|
std::vector<CArc> * arc_array = NULL,
|
|
|
|
bool aConvertHoles = false);
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function NormalizeWithKbool
|
2008-05-30 18:06:21 +00:00
|
|
|
* Use the Kbool Library to clip contours: if outlines are crossing, the self-crossing polygon
|
2008-06-02 10:23:50 +00:00
|
|
|
* is converted to non self-crossing polygon by adding extra points at the crossing locations
|
|
|
|
* and reordering corners
|
|
|
|
* if more than one outside contour are found, extra CPolyLines will be created
|
|
|
|
* because copper areas have only one outside contour
|
|
|
|
* Therefore, if this results in new CPolyLines, return them as std::vector pa
|
2011-01-01 17:28:21 +00:00
|
|
|
* @param aExtraPolyList: pointer on a std::vector<CPolyLine*> to store extra CPolyLines
|
2008-10-11 19:27:43 +00:00
|
|
|
* @param bRetainArcs == false, try to retain arcs in polys
|
2008-05-30 18:06:21 +00:00
|
|
|
* @return number of external contours, or -1 if error
|
|
|
|
*/
|
2008-06-02 10:23:50 +00:00
|
|
|
int NormalizeWithKbool( std::vector<CPolyLine*> * aExtraPolyList, bool bRetainArcs );
|
2008-09-27 19:26:29 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetKboolEngine
|
2008-09-26 19:51:36 +00:00
|
|
|
* @return the current used Kbool Engine (after normalization using kbool)
|
|
|
|
*/
|
|
|
|
Bool_Engine* GetKboolEngine( ) { return m_Kbool_Poly_Engine; }
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function FreeKboolEngine
|
2008-09-26 19:51:36 +00:00
|
|
|
* delete the current used Kbool Engine (free memory after normalization using kbool)
|
|
|
|
*/
|
|
|
|
void FreeKboolEngine( ) { delete m_Kbool_Poly_Engine; m_Kbool_Poly_Engine = NULL; }
|
2008-09-27 19:26:29 +00:00
|
|
|
|
2007-12-29 19:27:58 +00:00
|
|
|
|
|
|
|
private:
|
2008-05-30 18:06:21 +00:00
|
|
|
int m_layer; // layer to draw on
|
|
|
|
int m_Width; // lines width when drawing. Provided but not really used
|
|
|
|
int utility;
|
2008-01-04 12:27:16 +00:00
|
|
|
public:
|
2008-06-02 10:23:50 +00:00
|
|
|
std::vector <CPolyPt> corner; // array of points for corners
|
|
|
|
std::vector <int> side_style; // array of styles for sides
|
|
|
|
int m_HatchStyle; // hatch style, see enum above
|
|
|
|
std::vector <CSegment> m_HatchLines; // hatch lines
|
2007-12-29 19:27:58 +00:00
|
|
|
private:
|
2008-06-02 10:23:50 +00:00
|
|
|
Bool_Engine* m_Kbool_Poly_Engine; // polygons set in kbool engine data
|
2008-05-30 18:06:21 +00:00
|
|
|
bool bDrawn;
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
// Bezier Support
|
|
|
|
public:
|
|
|
|
void AppendBezier(int x1, int y1, int x2, int y2, int x3, int y3);
|
|
|
|
void AppendBezier(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
#endif // #ifndef POLYLINE_H
|