← Back to team overview

kicad-developers team mailing list archive

Re: Problem with GenericPolygonClipperLibrary.cpp

 

Hi all,

I have been thinking about this issue, and it really bugs me. As far as I see 
it, the use of the GPC lib essentially makes KiCad non-free, possibly to the 
extent that it can only legally be used for non-commercial designs.

I don't think any of us wants this. So I have taken a look to see to what 
extent we currently depend on GPC. Fortunately, it is not that much.

It is only used by Jean-Pierre has used GPC for combining zones. So I have 
tried removing all GPC dependencies, see attached diff.

Jean-Pierre, can I convince you to drop GPC in favor of a free alternative? I 
already suggested http://clippoly.sourceforge.net/, another (maybe better) 
alternative is http://www.cgal.org/ . I am willing to help replace GPC with 
whatever we chose.

Best regards
Jonas.
 --Boundary-00=_zvDHI4RniK+ujjG Content-Type: text/x-diff;
charset="utf-8";
name="remove_gpc.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="remove_gpc.diff"

Index: pcbnew/zones_test_and_combine_areas.cpp
===================================================================
--- pcbnew/zones_test_and_combine_areas.cpp	(Revision 1027)
+++ pcbnew/zones_test_and_combine_areas.cpp	(Arbeitskopie)
@@ -277,6 +277,7 @@

//** TODO test for cutouts outside of area
//**	if( test == 1 )
+#if 0
{
std::vector<CPolyLine*> * pa = new std::vector<CPolyLine*>;
curr_polygon->Undraw();
@@ -301,6 +302,7 @@
curr_polygon->Draw();
delete pa;
}
+#endif
return test;
}

@@ -382,9 +384,9 @@
false )
{
int ret = TestAreaIntersection( curr_area, area2 );
+// if( ret == 1 )
+// ret = CombineAreas( curr_area, area2 );
if( ret == 1 )
- ret = CombineAreas( curr_area, area2 );
- if( ret == 1 )
{
if( bMessageBox && bDontShowIntersectionWarning == false )
{
@@ -680,6 +682,7 @@
* 1 if intersection
* 2 if arcs intersect
*/
+#if 0
int BOARD::CombineAreas( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_combine )
{
if( area_ref == area_to_combine )
@@ -778,8 +781,8 @@
delete union_gpc;
return 1;
}
+#endif

-
#if 0 // Currently not used: work in progress

/**
Index: polygon/PolyLine.h
===================================================================
--- polygon/PolyLine.h	(Revision 1027)
+++ polygon/PolyLine.h	(Arbeitskopie)
@@ -18,7 +18,8 @@

#include "defs-macros.h"

-#include "GenericPolygonClipperLibrary.h"
+//#include "GenericPolygonClipperLibrary.h"
+
#include "php_polygon.h"
#include "php_polygon_vertex.h"

@@ -118,17 +119,20 @@
void SetSideStyle( int is, int style );

// GPC functions
+ /*
int MakeGpcPoly( int icontour=0, std::vector<CArc> * arc_array=NULL );
int FreeGpcPoly();
gpc_polygon * GetGpcPoly(){ return m_gpc_poly; };
int NormalizeWithGpc( std::vector<CPolyLine*> * pa=NULL, bool bRetainArcs=FALSE );
int RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine*> * pa=NULL );
-	CPolyLine * MakePolylineForPad( int type, int x, int y, int w, int l, int r, int angle );
-	void AddContourForPadClearance( int type, int x, int y, int w, 
-	int l, int r, int angle, int fill_clearance,
-	int hole_w, int hole_clearance, bool bThermal=FALSE, int spoke_w=0 );
+	
+
void ClipGpcPolygon( gpc_op op, CPolyLine * poly );
-
+ */
+ CPolyLine * MakePolylineForPad( int type, int x, int y, int w, int l, int r, int angle );
+ void AddContourForPadClearance( int type, int x, int y, int w, 
+ int l, int r, int angle, int fill_clearance,
+ int hole_w, int hole_clearance, bool bThermal=FALSE, int spoke_w=0 );
// PHP functions
int MakePhpPoly();
void FreePhpPoly();
@@ -144,7 +148,7 @@
int m_HatchStyle;	// hatch style, see enum above
std::vector <CSegment> m_HatchLines;	// hatch lines
private:
-	gpc_polygon * m_gpc_poly;	// polygon in gpc format
+	//gpc_polygon * m_gpc_poly;	// polygon in gpc format
polygon * m_php_poly;
bool bDrawn;
};
Index: polygon/PolyLine.cpp
===================================================================
--- polygon/PolyLine.cpp	(Revision 1027)
+++ polygon/PolyLine.cpp	(Arbeitskopie)
@@ -24,9 +24,9 @@
m_HatchStyle = 0;
m_Width = 0;
utility = 0;
-	m_gpc_poly = new gpc_polygon;
-	m_gpc_poly->num_contours = 0;
-	m_php_poly = new polygon;
+// m_gpc_poly = new gpc_polygon;
+// m_gpc_poly->num_contours = 0;
+// m_php_poly = new polygon;
}

// destructor, removes display elements
@@ -34,9 +34,9 @@
CPolyLine::~CPolyLine()
{
Undraw();
-	FreeGpcPoly();
-	delete m_gpc_poly;
-	delete m_php_poly;
+// FreeGpcPoly();
+// delete m_gpc_poly;
+// delete m_php_poly;
}

// Use the General Polygon Clipping Library to clip contours
@@ -44,6 +44,7 @@
// If bRetainArcs == TRUE, try to retain arcs in polys
// Returns number of external contours, or -1 if error
//
+/*
int CPolyLine::NormalizeWithGpc( std::vector<CPolyLine*> * pa, bool bRetainArcs )
{
std::vector<CArc> arc_array;
@@ -151,7 +152,7 @@

return n_ext_cont;
}
-
+*/
// make a php_polygon from first contour
int CPolyLine::MakePhpPoly()
{
@@ -223,6 +224,7 @@
// combining intersecting contours if possible
// returns data on arcs in arc_array
//
+/*
int CPolyLine::MakeGpcPoly( int icontour, std::vector<CArc> * arc_array )
{
if( m_gpc_poly->num_contours )
@@ -452,7 +454,6 @@
return 0;
}

-
// Restore arcs to a polygon where they were replaced with steps
// If pa != NULL, also use polygons in pa array
//
@@ -585,6 +586,7 @@
}
return 0;
}
+*/

// initialize new polyline
// set layer, width, selection box size, starting point, id and pointer
@@ -1318,7 +1320,7 @@
for( unsigned ii=0; ii < src->side_style.size(); ii++ )
side_style.push_back(src->side_style[ii]);
// don't copy the Gpc_poly, just clear the old one
-	FreeGpcPoly();
+// FreeGpcPoly();
}

@@ -1529,7 +1531,7 @@
Close( STRAIGHT );
}

-
+/*
void CPolyLine::ClipGpcPolygon( gpc_op op, CPolyLine * clip_poly )
{
gpc_polygon * result = new gpc_polygon;
@@ -1538,4 +1540,4 @@
delete m_gpc_poly;
m_gpc_poly = result;
}
-
+*/
 --Boundary-00=_zvDHI4RniK+ujjG-- 




Follow ups

References