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>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pad_shapes.h>
|
2012-07-25 18:46:25 +00:00
|
|
|
#include <wx/gdicmn.h> // for wxPoint definition
|
|
|
|
|
|
|
|
#include <polygons_defs.h>
|
2008-05-15 11:20:19 +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 CSegment
|
2007-12-29 19:27:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-07-13 18:55:29 +00:00
|
|
|
wxPoint m_Start;
|
|
|
|
wxPoint m_End;
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
CSegment() { };
|
2012-07-25 18:46:25 +00:00
|
|
|
CSegment( const wxPoint& aStart, const wxPoint& aEnd )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
|
|
|
m_Start = aStart;
|
2012-07-25 18:46:25 +00:00
|
|
|
m_End = aEnd;
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
2012-07-25 18:46:25 +00:00
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
CSegment( int x0, int y0, int x1, int y1 )
|
|
|
|
{
|
2012-07-25 18:46:25 +00:00
|
|
|
m_Start.x = x0; m_Start.y = y0;
|
|
|
|
m_End.x = x1; m_End.y = y1;
|
2008-05-30 18:06:21 +00:00
|
|
|
}
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2012-02-20 04:33:54 +00:00
|
|
|
class CPolyPt : public wxPoint
|
2008-05-30 18:06:21 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-06-10 09:48:42 +00:00
|
|
|
CPolyPt( int aX = 0, int aY = 0, bool aEnd = false, int aUtility = 0 ) :
|
2012-07-25 07:36:56 +00:00
|
|
|
wxPoint( aX, aY ), end_contour( aEnd ), m_utility( aUtility )
|
2012-06-10 09:48:42 +00:00
|
|
|
{}
|
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
// / Pure copy constructor is here to dis-ambiguate from the
|
|
|
|
// / specialized CPolyPt( const wxPoint& ) constructor version below.
|
2012-06-10 09:48:42 +00:00
|
|
|
CPolyPt( const CPolyPt& aPt ) :
|
2012-07-25 07:36:56 +00:00
|
|
|
wxPoint( aPt.x, aPt.y ), end_contour( aPt.end_contour ), m_utility( aPt.m_utility )
|
2012-06-10 09:48:42 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
CPolyPt( const wxPoint& aPoint ) :
|
2012-07-25 07:36:56 +00:00
|
|
|
wxPoint( aPoint ), end_contour( false ), m_utility( 0 )
|
2012-06-10 09:48:42 +00:00
|
|
|
{}
|
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
bool end_contour;
|
|
|
|
int m_utility;
|
2009-08-23 15:22:44 +00:00
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
bool operator ==( const CPolyPt& cpt2 ) const
|
2009-08-23 15:22:44 +00:00
|
|
|
{ return (x == cpt2.x) && (y == cpt2.y) && (end_contour == cpt2.end_contour); }
|
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
bool operator !=( CPolyPt& cpt2 ) const
|
2009-08-23 15:22:44 +00:00
|
|
|
{ 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
|
|
|
|
2012-02-20 04:33:54 +00:00
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
class CPolyLine
|
|
|
|
{
|
|
|
|
public:
|
2012-07-30 07:40:25 +00:00
|
|
|
enum HATCH_STYLE { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles
|
2008-05-30 18:06:21 +00:00
|
|
|
|
|
|
|
// constructors/destructor
|
|
|
|
CPolyLine();
|
|
|
|
~CPolyLine();
|
|
|
|
|
2012-08-02 17:32:42 +00:00
|
|
|
/**
|
|
|
|
* Function ImportSettings
|
|
|
|
* Copy settings (layer, hatch styles) from aPoly
|
|
|
|
* @param aPoly is the CPolyLine to import settings
|
|
|
|
*/
|
|
|
|
void ImportSettings( const CPolyLine * aPoly );
|
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
// functions for modifying the CPolyLine contours
|
|
|
|
|
|
|
|
/* initialize a contour
|
|
|
|
* set layer, hatch style, and starting point
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
void Start( int layer, int x, int y, int hatch );
|
2012-07-31 13:12:51 +00:00
|
|
|
|
|
|
|
void AppendCorner( int x, int y );
|
2012-07-25 18:46:25 +00:00
|
|
|
void InsertCorner( int ic, int x, int y );
|
2012-08-31 13:58:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteCorner
|
|
|
|
* remove the given corner. if it is the last point of a contour
|
|
|
|
* keep the controur closed by modifying the previous corner
|
|
|
|
* @param ic = the index of the corner to delete
|
|
|
|
*/
|
|
|
|
void DeleteCorner ( int ic );
|
2012-07-25 18:46:25 +00:00
|
|
|
void MoveCorner( int ic, int x, int y );
|
2012-07-30 07:40:25 +00:00
|
|
|
void CloseLastContour();
|
2012-07-25 18:46:25 +00:00
|
|
|
void RemoveContour( int icont );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
/**
|
|
|
|
* Function IsPolygonSelfIntersecting
|
|
|
|
* Test a CPolyLine for self-intersection of vertex (all contours).
|
|
|
|
*
|
|
|
|
* @return :
|
|
|
|
* false if no intersecting sides
|
|
|
|
* true if intersecting sides
|
|
|
|
* When a CPolyLine is self intersectic, it need to be normalized.
|
|
|
|
* (converted to non intersecting polygons)
|
|
|
|
*/
|
|
|
|
bool IsPolygonSelfIntersecting();
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
CPolyLine* Chamfer( unsigned int aDistance );
|
2011-02-21 19:43:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Fillet
|
|
|
|
* returns a filleted version of a polygon.
|
2011-06-07 15:29:01 +00:00
|
|
|
* @param aRadius is the fillet radius.
|
2011-02-21 19:43:59 +00:00
|
|
|
* @param aSegments is the number of segments / fillet.
|
|
|
|
* @return CPolyLine* - Pointer to new polygon.
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
CPolyLine* Fillet( unsigned int aRadius, unsigned int aSegments );
|
2011-02-21 19:43:59 +00:00
|
|
|
|
2012-08-31 13:58:23 +00:00
|
|
|
/**
|
|
|
|
* Function RemoveNullSegments
|
|
|
|
* Removes corners which create a null segment edge
|
|
|
|
* (i.e. when 2 successive corners are at the same location)
|
|
|
|
* @return the count of removed corners.
|
|
|
|
*/
|
|
|
|
int RemoveNullSegments();
|
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
void RemoveAllContours( void );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2012-01-13 18:35:46 +00:00
|
|
|
// Remove or create hatch
|
2012-07-25 18:46:25 +00:00
|
|
|
void UnHatch();
|
|
|
|
void Hatch();
|
2012-01-13 18:35:46 +00:00
|
|
|
|
|
|
|
// Transform functions
|
2012-07-25 18:46:25 +00:00
|
|
|
void MoveOrigin( int x_off, int y_off );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
|
|
|
// misc. functions
|
2012-07-25 18:46:25 +00:00
|
|
|
CRect GetBounds();
|
|
|
|
CRect GetCornerBounds();
|
|
|
|
CRect GetCornerBounds( int icont );
|
|
|
|
void Copy( CPolyLine* src );
|
|
|
|
bool TestPointInside( int x, int y );
|
|
|
|
bool IsCutoutContour( int icont );
|
2012-07-30 07:40:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function AppendArc.
|
|
|
|
* Adds segments to current contour to approximate the given arc
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
void AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int num );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
|
|
|
// access functions
|
2012-06-05 11:44:22 +00:00
|
|
|
void SetLayer( int aLayer ) { m_layer = aLayer; }
|
2012-08-02 17:32:42 +00:00
|
|
|
int GetLayer() const { return m_layer; }
|
|
|
|
int GetNumCorners();
|
|
|
|
int GetNumSides();
|
|
|
|
int GetClosed();
|
|
|
|
int GetContoursCount();
|
|
|
|
int GetContour( int ic );
|
|
|
|
int GetContourStart( int icont );
|
|
|
|
int GetContourEnd( int icont );
|
|
|
|
int GetContourSize( int icont );
|
2012-02-20 04:33:54 +00:00
|
|
|
|
2012-07-25 07:36:56 +00:00
|
|
|
int GetX( int ic ) const { return m_CornersList[ic].x; }
|
|
|
|
int GetY( int ic ) const { return m_CornersList[ic].y; }
|
2012-02-20 04:33:54 +00:00
|
|
|
|
2012-07-25 07:36:56 +00:00
|
|
|
const wxPoint& GetPos( int ic ) const { return m_CornersList[ic]; }
|
2012-02-20 04:33:54 +00:00
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
int GetEndContour( int ic );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2012-08-02 17:32:42 +00:00
|
|
|
int GetUtility( int ic ) const { return m_CornersList[ic].m_utility; };
|
2012-07-25 07:36:56 +00:00
|
|
|
void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; };
|
2012-07-25 18:46:25 +00:00
|
|
|
|
2012-08-02 17:32:42 +00:00
|
|
|
int GetHatchPitch() const { return m_hatchPitch; }
|
2012-07-30 07:40:25 +00:00
|
|
|
static int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils
|
2012-04-11 09:47:57 +00:00
|
|
|
|
2012-08-02 17:32:42 +00:00
|
|
|
enum HATCH_STYLE GetHatchStyle() const { return m_hatchStyle; }
|
2012-07-30 07:40:25 +00:00
|
|
|
void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
|
2012-07-25 18:46:25 +00:00
|
|
|
{
|
2012-07-30 07:40:25 +00:00
|
|
|
SetHatchPitch( aHatchPitch );
|
|
|
|
m_hatchStyle = (enum HATCH_STYLE) aHatchStyle;
|
|
|
|
if( aRebuildHatch )
|
|
|
|
Hatch();
|
2012-07-25 18:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetX( int ic, int x );
|
|
|
|
void SetY( int ic, int y );
|
|
|
|
void SetEndContour( int ic, bool end_contour );
|
|
|
|
|
2012-07-30 07:40:25 +00:00
|
|
|
void SetHatchStyle( enum HATCH_STYLE style )
|
2012-07-25 18:46:25 +00:00
|
|
|
{
|
|
|
|
m_hatchStyle = style;
|
|
|
|
}
|
|
|
|
|
2012-04-11 09:47:57 +00:00
|
|
|
void SetHatchPitch( int pitch ) { m_hatchPitch = pitch; }
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
/**
|
|
|
|
* Function NormalizeAreaOutlines
|
|
|
|
* Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s)
|
|
|
|
* @param aNewPolygonList = a std::vector<CPolyLine*> reference where to store new CPolyLine
|
|
|
|
* needed by the normalization
|
2012-08-04 09:43:27 +00:00
|
|
|
* @return the polygon count (always >= 1, because there is at least one polygon)
|
2012-07-31 13:12:51 +00:00
|
|
|
* There are new polygons only if the polygon count is > 1
|
|
|
|
*/
|
|
|
|
int NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2012-01-13 18:35:46 +00:00
|
|
|
// Bezier Support
|
2012-07-25 18:46:25 +00:00
|
|
|
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 );
|
2012-01-13 18:35:46 +00:00
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
/**
|
|
|
|
* Function Distance
|
|
|
|
* Calculates the distance between a point and the zone:
|
|
|
|
* @param aPoint the coordinate of the point.
|
|
|
|
* @return int = distance between the point and outline.
|
|
|
|
* 0 if the point is inside
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
int Distance( const wxPoint& aPoint );
|
2012-07-13 18:55:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Distance
|
|
|
|
* Calculates the distance between a segment and the zone:
|
|
|
|
* @param aStart the starting point of the segment.
|
|
|
|
* @param aEnd the ending point of the segment.
|
|
|
|
* @param aWidth the width of the segment.
|
|
|
|
* @return int = distance between the segment and outline.
|
|
|
|
* 0 if segment intersects or is inside
|
|
|
|
*/
|
2012-07-25 18:46:25 +00:00
|
|
|
int Distance( wxPoint aStart, wxPoint aEnd, int aWidth );
|
2007-12-29 19:27:58 +00:00
|
|
|
|
|
|
|
private:
|
2012-07-25 18:46:25 +00:00
|
|
|
int m_layer; // layer to draw on
|
2012-07-30 07:40:25 +00:00
|
|
|
enum HATCH_STYLE m_hatchStyle; // hatch style, see enum above
|
2012-07-25 18:46:25 +00:00
|
|
|
int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines
|
|
|
|
// and the len of eacvh segment
|
|
|
|
// for DIAGONAL_FULL, the pitch is twice this value
|
|
|
|
int m_utility; // a flag used in some calculations
|
2012-08-04 09:43:27 +00:00
|
|
|
|
2008-01-04 12:27:16 +00:00
|
|
|
public:
|
2012-07-25 18:46:25 +00:00
|
|
|
std::vector <CPolyPt> m_CornersList; // array of points for corners
|
|
|
|
std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area
|
2007-12-29 19:27:58 +00:00
|
|
|
};
|
|
|
|
|
2012-07-25 18:46:25 +00:00
|
|
|
/**
|
|
|
|
* Function CopyPolysListToKiPolygonWithHole
|
|
|
|
* converts the outline contours aPolysList to a KI_POLYGON_WITH_HOLES
|
|
|
|
*
|
|
|
|
* @param aPolysList = the list of corners of contours
|
|
|
|
* @param aPolygoneWithHole = a KI_POLYGON_WITH_HOLES to populate
|
|
|
|
*/
|
|
|
|
void CopyPolysListToKiPolygonWithHole( const std::vector<CPolyPt>& aPolysList,
|
|
|
|
KI_POLYGON_WITH_HOLES& aPolygoneWithHole );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ConvertPolysListWithHolesToOnePolygon
|
|
|
|
* converts the outline contours aPolysListWithHoles with holes to one polygon
|
|
|
|
* with no holes (only one contour)
|
|
|
|
* holes are linked to main outlines by overlap segments, to give only one polygon
|
|
|
|
*
|
|
|
|
* @param aPolysListWithHoles = the list of corners of contours (haing holes
|
|
|
|
* @param aOnePolyList = a polygon with no holes
|
|
|
|
*/
|
|
|
|
void ConvertPolysListWithHolesToOnePolygon( const std::vector<CPolyPt>& aPolysListWithHoles,
|
|
|
|
std::vector<CPolyPt>& aOnePolyList );
|
|
|
|
|
|
|
|
#endif // #ifndef POLYLINE_H
|