1 /*
2 	VeroRoute - Qt based Veroboard/Perfboard/PCB layout & routing application.
3 
4 	Copyright (C) 2017  Alex Lawrow    ( dralx@users.sourceforge.net )
5 
6 	This program is free software: you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation, either version 3 of the License, or
9 	(at your option) any later version.
10 
11 	This program is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "Common.h"
23 
24 class QPoint;
25 class QPolygon;
26 
27 // Bits used to construct the GPEN enum
28 static const int	BIT_GKO(1),	 BIT_PAD(2), BIT_VIA(4), BIT_TRK(8),
29 					BIT_SLK(16), BIT_GAP(32), BIT_MSK(64), BIT_HLE(128);
30 
31 // The GPEN enum defines "pen" types for writing to Gerber/Excellon files
32 enum class GPEN
33 {
34 	NONE	= 0,
35 	GKO		= BIT_GKO,				// Used for board outline
36 	PAD		= BIT_PAD,				// Used for pad
37 	VIA		= BIT_VIA,				// Used for via
38 	TRK		= BIT_TRK,				// Used for track
39 	SLK		= BIT_SLK,				// Used for silkscreen
40 	PAD_GAP	= BIT_PAD | BIT_GAP,	// Used for gap around a pad
41 	VIA_GAP	= BIT_VIA | BIT_GAP,	// Used for gap around a via
42 	TRK_GAP	= BIT_TRK | BIT_GAP,	// Used for gap around a track
43 	PAD_MSK	= BIT_PAD | BIT_MSK,	// Used for solder mask at a pad
44 	VIA_MSK	= BIT_VIA | BIT_MSK,	// Used for solder mask at a via
45 	PAD_HLE	= BIT_PAD | BIT_HLE,	// Used for drill hole at a pad
46 	VIA_HLE	= BIT_VIA | BIT_HLE		// Used for drill hole at a via
47 };
48 
49 // A class describing a curve as a set of points, with functionality for combining curves.
50 // Used for processing data before writing to Gerber file.
51 
52 class Curve : public std::list<QPoint>	// A curve drawn in a fixed size pen
53 {
54 public:
Curve()55 	Curve() {}
56 	Curve(const QPoint& p, const GPEN& ePen, const int& width = 0);
57 	Curve(const QPolygon& polygon, const GPEN& ePen, const int& width = 0);
~Curve()58 	~Curve() { clear(); }
59 	void Compress();		// Removes redundant points
60 	bool Splice(Curve* pB);	// Tries to splice curve B to this
61 	struct HasLargerPen		// Predicate for sorting
62 	{
operatorHasLargerPen63 		bool operator() (const Curve* p1, const Curve* p2) const
64 		{
65 			assert( static_cast<int>(GPEN::PAD) < static_cast<int>(GPEN::VIA) );
66 			if ( p1->m_width != p2->m_width ) return p1->m_width > p2->m_width;
67 			return static_cast<int>(p1->m_ePen) < static_cast<int>(p2->m_ePen);	// Pads before Vias if equal size
68 		}
69 	};
70 	GPEN	m_ePen	= GPEN::NONE;
71 	int		m_width	= 0;
72 };
73 
74 class CurveList : public std::list<Curve*>
75 {
76 public:
CurveList()77 	CurveList()		{}
~CurveList()78 	~CurveList()	{ Clear(); }
Clear()79 	void Clear()	{ for (auto& p : *this) p->clear(); clear(); }
80 	void Sort();
81 	void SpliceAll();
82 };
83