mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 12:51:41 +00:00
Reverted commits that remove boost::polygon dependency (need more testing).
This commit is contained in:
parent
9f18e5a98f
commit
d2ebf688f9
3d-viewer
3d_canvas.h3d_draw.cpp3d_draw_basic_functions.cpp3d_draw_basic_functions.h3d_draw_board_body.cpp3d_draw_helper_functions.cpp
common
gerbview
include
pcbnew
board_items_to_polygon_shape_transform.cppclass_board.cppclass_board.hclass_drawsegment.hclass_module.hclass_pad.hclass_pcb_text.hclass_track.hclass_zone.cppclass_zone.h
exporters
kicad_plugin.cpplegacy_plugin.cpponrightclick.cpppcb_painter.cpppcb_parser.cppplot_board_layers.cppplot_brditems_plotter.cppratsnest_data.cppratsnest_data.hspecctra.hspecctra_export.cppzone_filling_algorithm.cppzones_convert_brd_items_to_polygons_with_Boost.cppzones_convert_to_polygons_aux_functions.cppzones_polygons_insulated_copper_islands.cppzones_polygons_test_connections.cppzones_test_and_combine_areas.cpppolygon
@ -49,7 +49,7 @@
|
||||
|
||||
class BOARD_DESIGN_SETTINGS;
|
||||
class EDA_3D_FRAME;
|
||||
class SHAPE_POLY_SET;
|
||||
class CPOLYGONS_LIST;
|
||||
class REPORTER;
|
||||
|
||||
class VIA;
|
||||
@ -306,7 +306,7 @@ private:
|
||||
* Used only to draw pads outlines on silkscreen layers.
|
||||
*/
|
||||
void buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aWidth,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor );
|
||||
|
@ -637,7 +637,9 @@ void EDA_3D_CANVAS::buildBoard3DAuxLayers( REPORTER* aErrorMessages, REPORTER* a
|
||||
double correctionFactor = 1.0 / cos( M_PI / (segcountforcircle * 2) );
|
||||
BOARD* pcb = GetBoard();
|
||||
|
||||
SHAPE_POLY_SET bufferPolys;
|
||||
CPOLYGONS_LIST bufferPolys;
|
||||
|
||||
bufferPolys.reserve( 5000 ); // Reserve for items not on board
|
||||
|
||||
static const LAYER_ID sequence[] = {
|
||||
Dwgs_User,
|
||||
@ -699,10 +701,12 @@ void EDA_3D_CANVAS::buildBoard3DAuxLayers( REPORTER* aErrorMessages, REPORTER* a
|
||||
|
||||
// bufferPolys contains polygons to merge. Many overlaps .
|
||||
// Calculate merged polygons and remove pads and vias holes
|
||||
if( bufferPolys.IsEmpty() )
|
||||
if( bufferPolys.GetCornersCount() == 0 )
|
||||
continue;
|
||||
|
||||
bufferPolys.Fracture();
|
||||
KI_POLYGON_SET currLayerPolyset;
|
||||
KI_POLYGON_SET polyset;
|
||||
bufferPolys.ExportTo( polyset );
|
||||
currLayerPolyset += polyset;
|
||||
|
||||
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
|
||||
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
|
||||
@ -715,6 +719,9 @@ void EDA_3D_CANVAS::buildBoard3DAuxLayers( REPORTER* aErrorMessages, REPORTER* a
|
||||
else
|
||||
zpos -= thickness/2 ;
|
||||
|
||||
bufferPolys.RemoveAllContours();
|
||||
bufferPolys.ImportFrom( currLayerPolyset );
|
||||
|
||||
float zNormal = 1.0f; // When using thickness it will draw first the top and then botton (with z inverted)
|
||||
|
||||
// If we are not using thickness, then the znormal must face the layer direction
|
||||
|
@ -62,7 +62,7 @@ void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUni
|
||||
* from Z position = aZpos to aZpos + aHeight
|
||||
* Used to create the vertical sides of 3D horizontal shapes with thickness.
|
||||
*/
|
||||
static void Draw3D_VerticalPolygonalCylinder( const SHAPE_POLY_SET& aPolysList,
|
||||
static void Draw3D_VerticalPolygonalCylinder( const CPOLYGONS_LIST& aPolysList,
|
||||
int aHeight, int aZpos,
|
||||
bool aInside, double aBiuTo3DUnits )
|
||||
{
|
||||
@ -87,28 +87,29 @@ static void Draw3D_VerticalPolygonalCylinder( const SHAPE_POLY_SET& aPolysList,
|
||||
coords[3].z = coords[0].z;
|
||||
|
||||
// Draw the vertical polygonal side
|
||||
for( int ii = 0; ii < aPolysList.OutlineCount(); ii++ )
|
||||
int startContour = 0;
|
||||
for( unsigned ii = 0; ii < aPolysList.GetCornersCount(); ii++ )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& path = aPolysList.COutline( ii );
|
||||
unsigned jj = ii + 1;
|
||||
|
||||
for( int jj = 0; jj < path.PointCount(); jj++ )
|
||||
if( aPolysList.IsEndContour( ii ) || jj >= aPolysList.GetCornersCount() )
|
||||
{
|
||||
const VECTOR2I& a = path.CPoint( jj );
|
||||
const VECTOR2I& b = path.CPoint( jj + 1 );
|
||||
|
||||
// Build the 4 vertices of each GL_QUAD
|
||||
coords[0].x = a.x;
|
||||
coords[0].y = -a.y;
|
||||
coords[1].x = coords[0].x;
|
||||
coords[1].y = coords[0].y; // only z change
|
||||
coords[2].x = b.x;
|
||||
coords[2].y = -b.y;
|
||||
coords[3].x = coords[2].x;
|
||||
coords[3].y = coords[2].y; // only z change
|
||||
|
||||
// Creates the GL_QUAD
|
||||
TransfertToGLlist( coords, aBiuTo3DUnits );
|
||||
jj = startContour;
|
||||
startContour = ii + 1;
|
||||
}
|
||||
|
||||
// Build the 4 vertices of each GL_QUAD
|
||||
coords[0].x = aPolysList.GetX( ii );
|
||||
coords[0].y = -aPolysList.GetY( ii );
|
||||
coords[1].x = coords[0].x;
|
||||
coords[1].y = coords[0].y; // only z change
|
||||
coords[2].x = aPolysList.GetX( jj );
|
||||
coords[2].y = -aPolysList.GetY( jj );
|
||||
coords[3].x = coords[2].x;
|
||||
coords[3].y = coords[2].y; // only z change
|
||||
|
||||
// Creates the GL_QUAD
|
||||
TransfertToGLlist( coords, aBiuTo3DUnits );
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +147,7 @@ void SetGLTexture( GLuint text_id, float scale )
|
||||
* The top side is located at aZpos + aThickness / 2
|
||||
* The bottom side is located at aZpos - aThickness / 2
|
||||
*/
|
||||
void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
|
||||
int aZpos, int aThickness, double aBiuTo3DUnits,
|
||||
bool aUseTextures,
|
||||
float aNormal_Z_Orientation )
|
||||
@ -175,7 +176,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
glNormal3f( 0.0, 0.0, aNormal_Z_Orientation );
|
||||
|
||||
// Draw solid areas contained in this list
|
||||
SHAPE_POLY_SET polylist = aPolysList; // temporary copy for gluTessVertex
|
||||
CPOLYGONS_LIST polylist = aPolysList; // temporary copy for gluTessVertex
|
||||
|
||||
int startContour;
|
||||
|
||||
@ -183,7 +184,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
{
|
||||
startContour = 1;
|
||||
|
||||
for ( SHAPE_POLY_SET::ITERATOR ii = polylist.Iterate(); ii; ++ii )
|
||||
for( unsigned ii = 0; ii < polylist.GetCornersCount(); ii++ )
|
||||
{
|
||||
if( startContour == 1 )
|
||||
{
|
||||
@ -192,16 +193,16 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
startContour = 0;
|
||||
}
|
||||
|
||||
v_data[0] = ii->x * aBiuTo3DUnits;
|
||||
v_data[1] = -ii->y * aBiuTo3DUnits;
|
||||
v_data[0] = polylist.GetX( ii ) * aBiuTo3DUnits;
|
||||
v_data[1] = -polylist.GetY( ii ) * aBiuTo3DUnits;
|
||||
// gluTessVertex store pointers on data, not data, so do not store
|
||||
// different corners values in a temporary variable
|
||||
// but send pointer on each CPolyPt value in polylist
|
||||
// before calling gluDeleteTess
|
||||
gluTessVertex( tess, v_data, &ii.Get() );
|
||||
gluTessVertex( tess, v_data, &polylist[ii] );
|
||||
|
||||
|
||||
if( ii.IsEndContour() )
|
||||
if( polylist.IsEndContour( ii ) )
|
||||
{
|
||||
gluTessEndContour( tess );
|
||||
gluTessEndPolygon( tess );
|
||||
@ -241,15 +242,14 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
* The first polygon is the main polygon, others are holes
|
||||
* See Draw3D_SolidHorizontalPolyPolygons for more info
|
||||
*/
|
||||
void Draw3D_SolidHorizontalPolygonWithHoles( const SHAPE_POLY_SET& aPolysList,
|
||||
void Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
|
||||
int aZpos, int aThickness,
|
||||
double aBiuTo3DUnits, bool aUseTextures,
|
||||
float aNormal_Z_Orientation )
|
||||
{
|
||||
SHAPE_POLY_SET polygon( aPolysList );
|
||||
|
||||
polygon.Fracture();
|
||||
CPOLYGONS_LIST polygon;
|
||||
|
||||
ConvertPolysListWithHolesToOnePolygon( aPolysList, polygon );
|
||||
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, aThickness, aBiuTo3DUnits, aUseTextures,
|
||||
aNormal_Z_Orientation );
|
||||
}
|
||||
@ -265,7 +265,7 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,
|
||||
int aZpos, double aBiuTo3DUnits )
|
||||
{
|
||||
const int slice = SEGM_PER_CIRCLE;
|
||||
SHAPE_POLY_SET outer_cornerBuffer;
|
||||
CPOLYGONS_LIST outer_cornerBuffer;
|
||||
|
||||
TransformCircleToPolygon( outer_cornerBuffer, aCenterPos,
|
||||
aRadius + (aThickness / 2), slice );
|
||||
@ -273,7 +273,7 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,
|
||||
std::vector<S3D_VERTEX> coords;
|
||||
coords.resize( 4 );
|
||||
|
||||
SHAPE_POLY_SET inner_cornerBuffer;
|
||||
CPOLYGONS_LIST inner_cornerBuffer;
|
||||
if( aThickness ) // build the the vertical inner polygon (hole)
|
||||
TransformCircleToPolygon( inner_cornerBuffer, aCenterPos,
|
||||
aRadius - (aThickness / 2), slice );
|
||||
@ -294,11 +294,10 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,
|
||||
if( aThickness )
|
||||
{
|
||||
// draw top (front) and bottom (back) horizontal sides (rings)
|
||||
outer_cornerBuffer.AddHole( inner_cornerBuffer.COutline( 0 ) );
|
||||
SHAPE_POLY_SET polygon = outer_cornerBuffer;
|
||||
|
||||
polygon.Fracture();
|
||||
outer_cornerBuffer.Append( inner_cornerBuffer );
|
||||
CPOLYGONS_LIST polygon;
|
||||
|
||||
ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon );
|
||||
// draw top (front) horizontal ring
|
||||
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false,
|
||||
1.0f );
|
||||
@ -327,7 +326,7 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
|
||||
const int slice = SEGM_PER_CIRCLE;
|
||||
|
||||
// Build the points to approximate oblong cylinder by segments
|
||||
SHAPE_POLY_SET outer_cornerBuffer;
|
||||
CPOLYGONS_LIST outer_cornerBuffer;
|
||||
|
||||
int segm_width = (aRadius * 2) + aThickness;
|
||||
TransformRoundedEndsSegmentToPolygon( outer_cornerBuffer, aAxis1Pos,
|
||||
@ -340,7 +339,7 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
|
||||
|
||||
if( aThickness )
|
||||
{
|
||||
SHAPE_POLY_SET inner_cornerBuffer;
|
||||
CPOLYGONS_LIST inner_cornerBuffer;
|
||||
segm_width = aRadius * 2;
|
||||
TransformRoundedEndsSegmentToPolygon( inner_cornerBuffer, aAxis1Pos,
|
||||
aAxis2Pos, slice, segm_width );
|
||||
@ -352,10 +351,10 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
|
||||
|
||||
// Build the horizontal full polygon shape
|
||||
// (outer polygon shape - inner polygon shape)
|
||||
outer_cornerBuffer.AddHole( inner_cornerBuffer.COutline( 0 ) );
|
||||
outer_cornerBuffer.Append( inner_cornerBuffer );
|
||||
|
||||
SHAPE_POLY_SET polygon( outer_cornerBuffer );
|
||||
polygon.Fracture();
|
||||
CPOLYGONS_LIST polygon;
|
||||
ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon );
|
||||
|
||||
// draw top (front) horizontal side (ring)
|
||||
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false,
|
||||
@ -380,8 +379,8 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
|
||||
void Draw3D_SolidSegment( const wxPoint& aStart, const wxPoint& aEnd,
|
||||
int aWidth, int aThickness, int aZpos, double aBiuTo3DUnits )
|
||||
{
|
||||
SHAPE_POLY_SET cornerBuffer;
|
||||
const int slice = SEGM_PER_CIRCLE;
|
||||
CPOLYGONS_LIST cornerBuffer;
|
||||
const int slice = SEGM_PER_CIRCLE;
|
||||
|
||||
TransformRoundedEndsSegmentToPolygon( cornerBuffer, aStart, aEnd, slice, aWidth );
|
||||
|
||||
@ -395,7 +394,7 @@ void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint,
|
||||
{
|
||||
const int slice = SEGM_PER_CIRCLE;
|
||||
|
||||
SHAPE_POLY_SET cornerBuffer;
|
||||
CPOLYGONS_LIST cornerBuffer;
|
||||
TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
|
||||
slice, aWidth );
|
||||
|
||||
@ -422,7 +421,7 @@ void CALLBACK tessEndCB()
|
||||
void CALLBACK tessCPolyPt2Vertex( const GLvoid* data )
|
||||
{
|
||||
// cast back to double type
|
||||
const VECTOR2I* ptr = (const VECTOR2I*) data;
|
||||
const CPolyPt* ptr = (const CPolyPt*) data;
|
||||
|
||||
if( s_useTextures )
|
||||
{
|
||||
|
@ -43,7 +43,7 @@
|
||||
* The top side is located at aZpos + aThickness / 2
|
||||
* The bottom side is located at aZpos - aThickness / 2
|
||||
*/
|
||||
void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
|
||||
int aZpos, int aThickness, double aBiuTo3DUnits,
|
||||
bool aUseTextures,
|
||||
float aNormal_Z_Orientation );
|
||||
@ -61,7 +61,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList,
|
||||
* The top side is located at aZpos + aThickness / 2
|
||||
* The bottom side is located at aZpos - aThickness / 2
|
||||
*/
|
||||
void Draw3D_SolidHorizontalPolygonWithHoles( const SHAPE_POLY_SET& aPolysList,
|
||||
void Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
|
||||
int aZpos, int aThickness, double aBiuTo3DUnits,
|
||||
bool aUseTextures,
|
||||
float aNormal_Z_Orientation );
|
||||
|
@ -57,8 +57,6 @@
|
||||
#include <trackball.h>
|
||||
#include <3d_draw_basic_functions.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
#include <geometry/shape_file_io.h>
|
||||
|
||||
|
||||
#include <CImage.h>
|
||||
#include <reporter.h>
|
||||
@ -70,7 +68,6 @@
|
||||
*/
|
||||
GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer );
|
||||
|
||||
#if 0
|
||||
|
||||
// FIX ME: these 2 functions are fully duplicate of the same 2 functions in
|
||||
// pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp
|
||||
@ -91,7 +88,7 @@ static const SHAPE_POLY_SET convertPolyListToPolySet(const CPOLYGONS_LIST& aList
|
||||
|
||||
while( ic < corners_count )
|
||||
{
|
||||
rv.Append( aList.GetX(ic), aList.GetY(ic) );
|
||||
rv.AppendVertex( aList.GetX(ic), aList.GetY(ic) );
|
||||
if( aList.IsEndContour( ic ) )
|
||||
break;
|
||||
|
||||
@ -131,7 +128,6 @@ static const CPOLYGONS_LIST convertPolySetToPolyList(const SHAPE_POLY_SET& aPoly
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
REPORTER* aErrorMessages, REPORTER* aActivity )
|
||||
@ -160,11 +156,13 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
// a fine representation
|
||||
double correctionFactorLQ = 1.0 / cos( M_PI / (segcountLowQuality * 2.0) );
|
||||
|
||||
SHAPE_POLY_SET bufferPolys;
|
||||
SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines
|
||||
SHAPE_POLY_SET bufferZonesPolys;
|
||||
SHAPE_POLY_SET currLayerHoles, allLayerHoles; // Contains holes for the current layer
|
||||
// + zones when holes are removed from zones
|
||||
CPOLYGONS_LIST bufferPolys;
|
||||
bufferPolys.reserve( 500000 ); // Reserve for large board: tracks mainly
|
||||
// + zones when holes are removed from zones
|
||||
|
||||
CPOLYGONS_LIST bufferPcbOutlines; // stores the board main outlines
|
||||
CPOLYGONS_LIST allLayerHoles; // Contains through holes, calculated only once
|
||||
allLayerHoles.reserve( 20000 );
|
||||
|
||||
// Build a polygon from edge cut items
|
||||
wxString msg;
|
||||
@ -181,7 +179,12 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
}
|
||||
}
|
||||
|
||||
bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once
|
||||
CPOLYGONS_LIST bufferZonesPolys;
|
||||
bufferZonesPolys.reserve( 300000 ); // Reserve for large board ( copper zones mainly )
|
||||
// when holes are not removed from zones
|
||||
|
||||
CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer
|
||||
bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once
|
||||
|
||||
LSET cu_set = LSET::AllCuMask( GetPrm3DVisu().m_CopperLayersCount );
|
||||
|
||||
@ -348,18 +351,47 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
|
||||
// bufferPolys contains polygons to merge. Many overlaps .
|
||||
// Calculate merged polygons
|
||||
if( bufferPolys.IsEmpty() )
|
||||
if( bufferPolys.GetCornersCount() == 0 )
|
||||
continue;
|
||||
|
||||
#if 0
|
||||
// Set to 1 to use boost::polygon to subtract holes to copper areas
|
||||
// (due to bugs in boost::polygon, this is deprecated and Clipper is used instead
|
||||
KI_POLYGON_SET currLayerPolyset;
|
||||
KI_POLYGON_SET polysetHoles;
|
||||
|
||||
// Add polygons, without holes
|
||||
bufferPolys.ExportTo( currLayerPolyset );
|
||||
|
||||
// Add through holes (created only once) in current polygon holes list
|
||||
currLayerHoles.Append( allLayerHoles );
|
||||
|
||||
if( currLayerHoles.GetCornersCount() > 0 )
|
||||
currLayerHoles.ExportTo( polysetHoles );
|
||||
|
||||
// Merge polygons, and remove holes
|
||||
currLayerPolyset -= polysetHoles;
|
||||
|
||||
bufferPolys.RemoveAllContours();
|
||||
bufferPolys.ImportFrom( currLayerPolyset );
|
||||
#else
|
||||
// Use Clipper lib to subtract holes to copper areas
|
||||
SHAPE_POLY_SET solidAreas = convertPolyListToPolySet( bufferPolys );
|
||||
solidAreas.Simplify();
|
||||
|
||||
bufferPolys.Simplify();
|
||||
currLayerHoles.Simplify();
|
||||
allLayerHoles.Simplify();
|
||||
|
||||
bufferPolys.BooleanSubtract( allLayerHoles );
|
||||
bufferPolys.Fracture();
|
||||
|
||||
// Add through holes (created only once) in current polygon holes list
|
||||
currLayerHoles.Append( allLayerHoles );
|
||||
if( currLayerHoles.GetCornersCount() > 0 )
|
||||
{
|
||||
SHAPE_POLY_SET holes = convertPolyListToPolySet( currLayerHoles );
|
||||
holes.Simplify();
|
||||
solidAreas.Subtract ( holes );
|
||||
}
|
||||
SHAPE_POLY_SET fractured = solidAreas;
|
||||
fractured.Fracture();
|
||||
bufferPolys.RemoveAllContours();
|
||||
bufferPolys = convertPolySetToPolyList( fractured );
|
||||
#endif
|
||||
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
|
||||
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
|
||||
|
||||
@ -389,7 +421,7 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
|
||||
// If holes are not removed from copper zones (for calculation time reasons,
|
||||
// the zone polygons are stored in bufferZonesPolys and have to be drawn now:
|
||||
if( !bufferZonesPolys.IsEmpty() )
|
||||
if( bufferZonesPolys.GetCornersCount() )
|
||||
{
|
||||
Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos, thickness,
|
||||
GetPrm3DVisu().m_BiuTo3Dunits, useTextures,
|
||||
@ -458,10 +490,22 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
|
||||
zpos += (copper_thickness + epsilon) / 2.0f;
|
||||
board_thickness -= copper_thickness + epsilon;
|
||||
|
||||
bufferPcbOutlines.BooleanSubtract( allLayerHoles );
|
||||
bufferPcbOutlines.Fracture();
|
||||
KI_POLYGON_SET currLayerPolyset;
|
||||
KI_POLYGON_SET polysetHoles;
|
||||
|
||||
if( !bufferPcbOutlines.IsEmpty() )
|
||||
// Add polygons, without holes
|
||||
bufferPcbOutlines.ExportTo( currLayerPolyset );
|
||||
|
||||
// Build holes list
|
||||
allLayerHoles.ExportTo( polysetHoles );
|
||||
|
||||
// remove holes
|
||||
currLayerPolyset -= polysetHoles;
|
||||
|
||||
bufferPcbOutlines.RemoveAllContours();
|
||||
bufferPcbOutlines.ImportFrom( currLayerPolyset );
|
||||
|
||||
if( bufferPcbOutlines.GetCornersCount() )
|
||||
{
|
||||
Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness / 2.0,
|
||||
board_thickness, GetPrm3DVisu().m_BiuTo3Dunits, useTextures,
|
||||
@ -487,9 +531,12 @@ void EDA_3D_CANVAS::buildTechLayers3DView( REPORTER* aErrorMessages, REPORTER* a
|
||||
|
||||
double correctionFactorLQ = 1.0 / cos( M_PI / (segcountLowQuality * 2) );
|
||||
|
||||
SHAPE_POLY_SET bufferPolys;
|
||||
SHAPE_POLY_SET allLayerHoles; // Contains through holes, calculated only once
|
||||
SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines
|
||||
CPOLYGONS_LIST bufferPolys;
|
||||
bufferPolys.reserve( 100000 ); // Reserve for large board
|
||||
CPOLYGONS_LIST allLayerHoles; // Contains through holes, calculated only once
|
||||
allLayerHoles.reserve( 20000 );
|
||||
|
||||
CPOLYGONS_LIST bufferPcbOutlines; // stores the board main outlines
|
||||
|
||||
// Build a polygon from edge cut items
|
||||
wxString msg;
|
||||
@ -534,6 +581,9 @@ void EDA_3D_CANVAS::buildTechLayers3DView( REPORTER* aErrorMessages, REPORTER* a
|
||||
|
||||
// draw graphic items, on technical layers
|
||||
|
||||
KI_POLYGON_SET brdpolysetHoles;
|
||||
allLayerHoles.ExportTo( brdpolysetHoles );
|
||||
|
||||
static const LAYER_ID teckLayerList[] = {
|
||||
B_Adhes,
|
||||
F_Adhes,
|
||||
@ -625,33 +675,32 @@ void EDA_3D_CANVAS::buildTechLayers3DView( REPORTER* aErrorMessages, REPORTER* a
|
||||
|
||||
// bufferPolys contains polygons to merge. Many overlaps .
|
||||
// Calculate merged polygons and remove pads and vias holes
|
||||
if( bufferPolys.IsEmpty() )
|
||||
if( bufferPolys.GetCornersCount() == 0 )
|
||||
continue;
|
||||
|
||||
allLayerHoles.Simplify();
|
||||
KI_POLYGON_SET currLayerPolyset;
|
||||
KI_POLYGON_SET polyset;
|
||||
|
||||
// Solder mask layers are "negative" layers.
|
||||
// Shapes should be removed from the full board area.
|
||||
if( layer == B_Mask || layer == F_Mask )
|
||||
{
|
||||
SHAPE_POLY_SET cuts = bufferPolys;
|
||||
bufferPolys = bufferPcbOutlines;
|
||||
|
||||
cuts.Append(allLayerHoles);
|
||||
cuts.Simplify();
|
||||
|
||||
bufferPolys.BooleanSubtract( cuts );
|
||||
bufferPcbOutlines.ExportTo( currLayerPolyset );
|
||||
bufferPolys.Append( allLayerHoles );
|
||||
bufferPolys.ExportTo( polyset );
|
||||
currLayerPolyset -= polyset;
|
||||
}
|
||||
// Remove holes from Solder paste layers and siklscreen
|
||||
else if( layer == B_Paste || layer == F_Paste
|
||||
|| layer == B_SilkS || layer == F_SilkS )
|
||||
{
|
||||
|
||||
bufferPolys.BooleanSubtract( allLayerHoles );
|
||||
bufferPolys.ExportTo( currLayerPolyset );
|
||||
currLayerPolyset -= brdpolysetHoles;
|
||||
}
|
||||
else // usuall layers, merge polys built from each item shape:
|
||||
{
|
||||
bufferPolys.ExportTo( polyset );
|
||||
currLayerPolyset += polyset;
|
||||
}
|
||||
|
||||
bufferPolys.Fracture();
|
||||
|
||||
|
||||
int thickness = 0;
|
||||
|
||||
@ -679,6 +728,8 @@ void EDA_3D_CANVAS::buildTechLayers3DView( REPORTER* aErrorMessages, REPORTER* a
|
||||
zpos -= thickness/2 ;
|
||||
}
|
||||
|
||||
bufferPolys.RemoveAllContours();
|
||||
bufferPolys.ImportFrom( currLayerPolyset );
|
||||
|
||||
float zNormal = 1.0f; // When using thickness it will draw first the top and then botton (with z inverted)
|
||||
|
||||
|
@ -358,7 +358,7 @@ void EDA_3D_CANVAS::draw3DPadHole( const D_PAD* aPad )
|
||||
return;
|
||||
|
||||
// Store here the points to approximate hole by segments
|
||||
SHAPE_POLY_SET holecornersBuffer;
|
||||
CPOLYGONS_LIST holecornersBuffer;
|
||||
int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
|
||||
int height = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) -
|
||||
GetPrm3DVisu().GetLayerZcoordBIU( B_Cu );
|
||||
@ -436,7 +436,7 @@ void EDA_3D_CANVAS::draw3DViaHole( const VIA* aVia )
|
||||
* Used only to draw pads outlines on silkscreen layers.
|
||||
*/
|
||||
void EDA_3D_CANVAS::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aWidth,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor )
|
||||
@ -449,22 +449,17 @@ void EDA_3D_CANVAS::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
|
||||
}
|
||||
|
||||
// For other shapes, draw polygon outlines
|
||||
SHAPE_POLY_SET corners;
|
||||
CPOLYGONS_LIST corners;
|
||||
aPad->BuildPadShapePolygon( corners, wxSize( 0, 0 ),
|
||||
aCircleToSegmentsCount, aCorrectionFactor );
|
||||
|
||||
// Add outlines as thick segments in polygon buffer
|
||||
|
||||
const SHAPE_LINE_CHAIN& path = corners.COutline( 0 );
|
||||
|
||||
for( int ii = 0; ii < path.PointCount(); ii++ )
|
||||
for( unsigned ii = 0, jj = corners.GetCornersCount() - 1;
|
||||
ii < corners.GetCornersCount(); jj = ii, ii++ )
|
||||
{
|
||||
const VECTOR2I& a = path.CPoint( ii );
|
||||
const VECTOR2I& b = path.CPoint( ii + 1 );
|
||||
|
||||
TransformRoundedEndsSegmentToPolygon( aCornerBuffer,
|
||||
wxPoint( a.x, a.y ),
|
||||
wxPoint( b.x, b.y ),
|
||||
corners.GetPos( jj ),
|
||||
corners.GetPos( ii ),
|
||||
aCircleToSegmentsCount, aWidth );
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,8 @@ void DXF_PLOTTER::Circle( const wxPoint& centre, int diameter, FILL_T fill, int
|
||||
* It does not know thhick segments, therefore filled polygons with thick outline
|
||||
* are converted to inflated polygon by aWidth/2
|
||||
*/
|
||||
void DXF_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
|
||||
#include "clipper.hpp"
|
||||
void DXF_PLOTTER::PlotPoly( const std::vector< wxPoint >& aCornerList,
|
||||
FILL_T aFill, int aWidth)
|
||||
{
|
||||
if( aCornerList.size() <= 1 )
|
||||
@ -391,12 +392,10 @@ void DXF_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
|
||||
// The polygon outline has thickness, and is filled
|
||||
// Build and plot the polygon which contains the initial
|
||||
// polygon and its thick outline
|
||||
SHAPE_POLY_SET bufferOutline;
|
||||
SHAPE_POLY_SET bufferPolybase;
|
||||
CPOLYGONS_LIST bufferOutline;
|
||||
CPOLYGONS_LIST bufferPolybase;
|
||||
const int circleToSegmentsCount = 16;
|
||||
|
||||
bufferPolybase.NewOutline();
|
||||
|
||||
// enter outline as polygon:
|
||||
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
||||
{
|
||||
@ -407,40 +406,47 @@ void DXF_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
|
||||
// enter the initial polygon:
|
||||
for( unsigned ii = 0; ii < aCornerList.size(); ii++ )
|
||||
{
|
||||
bufferPolybase.Append( aCornerList[ii] );
|
||||
CPolyPt polypoint( aCornerList[ii].x, aCornerList[ii].y );
|
||||
bufferPolybase.Append( polypoint );
|
||||
}
|
||||
|
||||
bufferPolybase.CloseLastContour();
|
||||
|
||||
// Merge polygons to build the polygon which contains the initial
|
||||
// polygon and its thick outline
|
||||
KI_POLYGON_SET polysBase; // Store the main outline and the final outline
|
||||
KI_POLYGON_SET polysOutline; // Store the thick segments to draw the outline
|
||||
bufferPolybase.ExportTo( polysBase );
|
||||
bufferOutline.ExportTo( polysOutline );
|
||||
|
||||
bufferPolybase.BooleanAdd( bufferOutline ); // create the outline which contains thick outline
|
||||
bufferPolybase.Fracture();
|
||||
polysBase += polysOutline; // create the outline which contains thick outline
|
||||
|
||||
// We should have only one polygon in list, now.
|
||||
wxASSERT( polysBase.size() == 1 );
|
||||
|
||||
if( bufferPolybase.OutlineCount() < 1 ) // should not happen
|
||||
if( polysBase.size() < 1 ) // should not happen
|
||||
return;
|
||||
|
||||
const SHAPE_LINE_CHAIN& path = bufferPolybase.COutline( 0 );
|
||||
KI_POLYGON poly = polysBase[0]; // Expected only one polygon here
|
||||
|
||||
if( path.PointCount() < 2 ) // should not happen
|
||||
if( poly.size() < 2 ) // should not happen
|
||||
return;
|
||||
|
||||
// Now, output the final polygon to DXF file:
|
||||
last = path.PointCount() - 1;
|
||||
VECTOR2I point = path.CPoint( 0 );
|
||||
|
||||
wxPoint startPoint( point.x, point.y );
|
||||
last = poly.size() - 1;
|
||||
KI_POLY_POINT point = *(poly.begin());
|
||||
wxPoint startPoint( point.x(), point.y() );
|
||||
MoveTo( startPoint );
|
||||
|
||||
for( int ii = 1; ii < path.PointCount(); ii++ )
|
||||
for( unsigned ii = 1; ii < poly.size(); ii++ )
|
||||
{
|
||||
point = path.CPoint( ii );
|
||||
LineTo( wxPoint( point.x, point.y ) );
|
||||
point = *( poly.begin() + ii );
|
||||
LineTo( wxPoint( point.x(), point.y() ) );
|
||||
}
|
||||
|
||||
// Close polygon, if needed
|
||||
point = path.CPoint( last );
|
||||
wxPoint endPoint( point.x, point.y );
|
||||
point = *(poly.begin() + last);
|
||||
wxPoint endPoint( point.x(), point.y() );
|
||||
|
||||
if( endPoint != startPoint )
|
||||
LineTo( startPoint );
|
||||
|
@ -43,7 +43,7 @@
|
||||
* Note: the polygon is inside the circle, so if you want to have the polygon
|
||||
* outside the circle, you should give aRadius calculated with a corrrection factor
|
||||
*/
|
||||
void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformCircleToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCenter, int aRadius,
|
||||
int aCircleToSegmentsCount )
|
||||
{
|
||||
@ -51,8 +51,6 @@ void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree
|
||||
int halfstep = 1800 / aCircleToSegmentsCount; // the starting value for rot angles
|
||||
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( int ii = 0; ii < aCircleToSegmentsCount; ii++ )
|
||||
{
|
||||
corner_position.x = aRadius;
|
||||
@ -60,8 +58,11 @@ void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
int angle = (ii * delta) + halfstep;
|
||||
RotatePoint( &corner_position.x, &corner_position.y, angle );
|
||||
corner_position += aCenter;
|
||||
aCornerBuffer.Append( corner_position.x, corner_position.y );
|
||||
CPolyPt polypoint( corner_position.x, corner_position.y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +78,7 @@ void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* Note: the polygon is inside the arc ends, so if you want to have the polygon
|
||||
* outside the circle, you should give aStart and aEnd calculated with a correction factor
|
||||
*/
|
||||
void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformRoundedEndsSegmentToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aStart, wxPoint aEnd,
|
||||
int aCircleToSegmentsCount,
|
||||
int aWidth )
|
||||
@ -86,9 +87,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
wxPoint endp = aEnd - aStart; // end point coordinate for the same segment starting at (0,0)
|
||||
wxPoint startp = aStart;
|
||||
wxPoint corner;
|
||||
VECTOR2I polypoint;
|
||||
|
||||
aCornerBuffer.NewOutline();
|
||||
CPolyPt polypoint;
|
||||
|
||||
// normalize the position in order to have endp.x >= 0;
|
||||
if( endp.x < 0 )
|
||||
@ -113,7 +112,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
corner += startp;
|
||||
polypoint.x = corner.x;
|
||||
polypoint.y = corner.y;
|
||||
aCornerBuffer.Append( polypoint.x, polypoint.y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
}
|
||||
|
||||
// Finish arc:
|
||||
@ -122,7 +121,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
corner += startp;
|
||||
polypoint.x = corner.x;
|
||||
polypoint.y = corner.y;
|
||||
aCornerBuffer.Append( polypoint.x, polypoint.y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
|
||||
// add left rounded end:
|
||||
for( int ii = 0; ii < 1800; ii += delta )
|
||||
@ -133,7 +132,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
corner += startp;
|
||||
polypoint.x = corner.x;
|
||||
polypoint.y = corner.y;
|
||||
aCornerBuffer.Append( polypoint.x, polypoint.y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
}
|
||||
|
||||
// Finish arc:
|
||||
@ -142,7 +141,9 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
corner += startp;
|
||||
polypoint.x = corner.x;
|
||||
polypoint.y = corner.y;
|
||||
aCornerBuffer.Append( polypoint.x, polypoint.y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +158,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* @param aWidth = width (thickness) of the line
|
||||
*/
|
||||
void TransformArcToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformArcToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCentre, wxPoint aStart, double aArcAngle,
|
||||
int aCircleToSegmentsCount, int aWidth )
|
||||
{
|
||||
@ -207,7 +208,7 @@ void TransformArcToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* @param aWidth = width (thickness) of the ring
|
||||
*/
|
||||
void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformRingToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCentre, int aRadius,
|
||||
int aCircleToSegmentsCount, int aWidth )
|
||||
{
|
||||
@ -217,8 +218,7 @@ void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
wxPoint curr_point;
|
||||
int inner_radius = aRadius - ( aWidth / 2 );
|
||||
int outer_radius = inner_radius + aWidth;
|
||||
|
||||
aCornerBuffer.NewOutline();
|
||||
CPolyPt polycorner;
|
||||
|
||||
// Draw the inner circle of the ring
|
||||
for( int ii = 0; ii < 3600; ii += delta )
|
||||
@ -227,11 +227,15 @@ void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
curr_point.y = 0;
|
||||
RotatePoint( &curr_point, ii );
|
||||
curr_point += aCentre;
|
||||
aCornerBuffer.Append( curr_point.x, curr_point.y );
|
||||
polycorner.x = curr_point.x;
|
||||
polycorner.y = curr_point.y;
|
||||
aCornerBuffer.Append( polycorner );
|
||||
}
|
||||
|
||||
// Draw the last point of inner circle
|
||||
aCornerBuffer.Append( aCentre.x + inner_radius, aCentre.y );
|
||||
polycorner.x = aCentre.x + inner_radius;
|
||||
polycorner.y = aCentre.y;
|
||||
aCornerBuffer.Append( polycorner );
|
||||
|
||||
// Draw the outer circle of the ring
|
||||
for( int ii = 0; ii < 3600; ii += delta )
|
||||
@ -240,10 +244,18 @@ void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
curr_point.y = 0;
|
||||
RotatePoint( &curr_point, -ii );
|
||||
curr_point += aCentre;
|
||||
aCornerBuffer.Append( curr_point.x, curr_point.y );
|
||||
polycorner.x = curr_point.x;
|
||||
polycorner.y = curr_point.y;
|
||||
aCornerBuffer.Append( polycorner );
|
||||
}
|
||||
|
||||
// Draw the last point of outer circle
|
||||
aCornerBuffer.Append( aCentre.x + outer_radius, aCentre.y );
|
||||
aCornerBuffer.Append( aCentre.x + inner_radius, aCentre.y );
|
||||
polycorner.x = aCentre.x + outer_radius;
|
||||
polycorner.y = aCentre.y;
|
||||
aCornerBuffer.Append( polycorner );
|
||||
|
||||
// Close the polygon
|
||||
polycorner.x = aCentre.x + inner_radius;
|
||||
polycorner.end_contour = true;
|
||||
aCornerBuffer.Append( polycorner );
|
||||
}
|
||||
|
@ -4,9 +4,6 @@
|
||||
* Copyright (C) 2015 CERN
|
||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||
*
|
||||
* Point in polygon algorithm adapted from Clipper Library (C) Angus Johnson,
|
||||
* subject to Clipper library license.
|
||||
*
|
||||
* 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
|
||||
@ -28,34 +25,22 @@
|
||||
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <geometry/shape.h>
|
||||
#include <geometry/shape_line_chain.h>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <geometry/shape.h>
|
||||
#include <geometry/shape_line_chain.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
#include "geometry/shape_poly_set.h"
|
||||
|
||||
using namespace ClipperLib;
|
||||
|
||||
SHAPE_POLY_SET::SHAPE_POLY_SET() :
|
||||
SHAPE( SH_POLY_SET )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
SHAPE_POLY_SET::~SHAPE_POLY_SET()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int SHAPE_POLY_SET::NewOutline()
|
||||
{
|
||||
SHAPE_LINE_CHAIN empty_path;
|
||||
POLYGON poly;
|
||||
Path empty_path;
|
||||
Paths poly;
|
||||
poly.push_back( empty_path );
|
||||
m_polys.push_back( poly );
|
||||
return m_polys.size() - 1;
|
||||
@ -64,13 +49,12 @@ int SHAPE_POLY_SET::NewOutline()
|
||||
|
||||
int SHAPE_POLY_SET::NewHole( int aOutline )
|
||||
{
|
||||
m_polys.back().push_back( SHAPE_LINE_CHAIN() );
|
||||
|
||||
return m_polys.back().size() - 2;
|
||||
assert( false );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int SHAPE_POLY_SET::Append( int x, int y, int aOutline, int aHole )
|
||||
int SHAPE_POLY_SET::AppendVertex( int x, int y, int aOutline, int aHole )
|
||||
{
|
||||
if( aOutline < 0 )
|
||||
aOutline += m_polys.size();
|
||||
@ -85,13 +69,13 @@ int SHAPE_POLY_SET::Append( int x, int y, int aOutline, int aHole )
|
||||
assert( aOutline < (int)m_polys.size() );
|
||||
assert( idx < (int)m_polys[aOutline].size() );
|
||||
|
||||
m_polys[aOutline][idx].Append( x, y );
|
||||
m_polys[aOutline][idx].push_back( IntPoint( x, y ) );
|
||||
|
||||
return m_polys[aOutline][idx].PointCount();
|
||||
return m_polys[aOutline][idx].size();
|
||||
}
|
||||
|
||||
|
||||
int SHAPE_POLY_SET::VertexCount( int aOutline , int aHole ) const
|
||||
int SHAPE_POLY_SET::VertexCount( int aOutline, int aHole ) const
|
||||
{
|
||||
if( aOutline < 0 )
|
||||
aOutline += m_polys.size();
|
||||
@ -106,11 +90,11 @@ int SHAPE_POLY_SET::VertexCount( int aOutline , int aHole ) const
|
||||
assert ( aOutline < (int)m_polys.size() );
|
||||
assert ( idx < (int)m_polys[aOutline].size() );
|
||||
|
||||
return m_polys[aOutline][idx].PointCount();
|
||||
return m_polys[aOutline][idx].size();
|
||||
}
|
||||
|
||||
|
||||
const VECTOR2I& SHAPE_POLY_SET::CVertex( int index, int aOutline , int aHole ) const
|
||||
const VECTOR2I SHAPE_POLY_SET::GetVertex( int index, int aOutline, int aHole ) const
|
||||
{
|
||||
if( aOutline < 0 )
|
||||
aOutline += m_polys.size();
|
||||
@ -125,26 +109,8 @@ const VECTOR2I& SHAPE_POLY_SET::CVertex( int index, int aOutline , int aHole ) c
|
||||
assert( aOutline < (int)m_polys.size() );
|
||||
assert( idx < (int)m_polys[aOutline].size() );
|
||||
|
||||
return m_polys[aOutline][idx].CPoint( index );
|
||||
}
|
||||
|
||||
|
||||
VECTOR2I& SHAPE_POLY_SET::Vertex( int index, int aOutline , int aHole )
|
||||
{
|
||||
if( aOutline < 0 )
|
||||
aOutline += m_polys.size();
|
||||
|
||||
int idx;
|
||||
|
||||
if( aHole < 0 )
|
||||
idx = 0;
|
||||
else
|
||||
idx = aHole + 1;
|
||||
|
||||
assert( aOutline < (int)m_polys.size() );
|
||||
assert( idx < (int)m_polys[aOutline].size() );
|
||||
|
||||
return m_polys[aOutline][idx].Point( index );
|
||||
IntPoint p = m_polys[aOutline][idx][index];
|
||||
return VECTOR2I (p.X, p.Y);
|
||||
}
|
||||
|
||||
|
||||
@ -152,9 +118,13 @@ int SHAPE_POLY_SET::AddOutline( const SHAPE_LINE_CHAIN& aOutline )
|
||||
{
|
||||
assert( aOutline.IsClosed() );
|
||||
|
||||
POLYGON poly;
|
||||
Path p = convert( aOutline );
|
||||
Paths poly;
|
||||
|
||||
poly.push_back( aOutline );
|
||||
if( !Orientation( p ) )
|
||||
ReversePath( p ); // outlines are always CW
|
||||
|
||||
poly.push_back( p );
|
||||
|
||||
m_polys.push_back( poly );
|
||||
|
||||
@ -169,60 +139,49 @@ int SHAPE_POLY_SET::AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline )
|
||||
if( aOutline < 0 )
|
||||
aOutline += m_polys.size();
|
||||
|
||||
POLYGON& poly = m_polys[aOutline];
|
||||
Paths& poly = m_polys[aOutline];
|
||||
|
||||
assert( poly.size() );
|
||||
|
||||
poly.push_back( aHole );
|
||||
Path p = convert( aHole );
|
||||
|
||||
if( Orientation( p ) )
|
||||
ReversePath( p ); // holes are always CCW
|
||||
|
||||
poly.push_back( p );
|
||||
|
||||
return poly.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
const Path SHAPE_POLY_SET::convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation )
|
||||
const ClipperLib::Path SHAPE_POLY_SET::convert( const SHAPE_LINE_CHAIN& aPath )
|
||||
{
|
||||
Path c_path;
|
||||
|
||||
for( int i = 0; i < aPath.PointCount(); i++ )
|
||||
{
|
||||
const VECTOR2I& vertex = aPath.CPoint( i );
|
||||
c_path.push_back( IntPoint( vertex.x, vertex.y ) );
|
||||
c_path.push_back( ClipperLib::IntPoint( vertex.x, vertex.y ) );
|
||||
}
|
||||
|
||||
if( Orientation( c_path ) != aRequiredOrientation )
|
||||
ReversePath( c_path );
|
||||
|
||||
return c_path;
|
||||
}
|
||||
|
||||
|
||||
const SHAPE_LINE_CHAIN SHAPE_POLY_SET::convertFromClipper( const Path& aPath )
|
||||
{
|
||||
SHAPE_LINE_CHAIN lc;
|
||||
|
||||
for( unsigned int i = 0; i < aPath.size(); i++ )
|
||||
lc.Append( aPath[i].X, aPath[i].Y );
|
||||
|
||||
return lc;
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::booleanOp( ClipType type, const SHAPE_POLY_SET& b )
|
||||
void SHAPE_POLY_SET::booleanOp( ClipperLib::ClipType type, const SHAPE_POLY_SET& b )
|
||||
{
|
||||
Clipper c;
|
||||
|
||||
c.StrictlySimple( true );
|
||||
|
||||
BOOST_FOREACH( const POLYGON& poly, m_polys )
|
||||
BOOST_FOREACH( Paths& subject, m_polys )
|
||||
{
|
||||
for( unsigned int i = 0; i < poly.size(); i++ )
|
||||
c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
|
||||
c.AddPaths( subject, ptSubject, true );
|
||||
}
|
||||
|
||||
BOOST_FOREACH( const POLYGON& poly, b.m_polys )
|
||||
BOOST_FOREACH( const Paths& clip, b.m_polys )
|
||||
{
|
||||
for( unsigned int i = 0; i < poly.size(); i++ )
|
||||
c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
|
||||
c.AddPaths( clip, ptClip, true );
|
||||
}
|
||||
|
||||
PolyTree solution;
|
||||
@ -233,39 +192,41 @@ void SHAPE_POLY_SET::booleanOp( ClipType type, const SHAPE_POLY_SET& b )
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::BooleanAdd( const SHAPE_POLY_SET& b )
|
||||
void SHAPE_POLY_SET::Add( const SHAPE_POLY_SET& b )
|
||||
{
|
||||
booleanOp( ctUnion, b );
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::BooleanSubtract( const SHAPE_POLY_SET& b )
|
||||
void SHAPE_POLY_SET::Subtract( const SHAPE_POLY_SET& b )
|
||||
{
|
||||
booleanOp( ctDifference, b );
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::Inflate( int aFactor, int aCircleSegmentsCount )
|
||||
void SHAPE_POLY_SET::Erode( int aFactor )
|
||||
{
|
||||
ClipperOffset c;
|
||||
|
||||
BOOST_FOREACH( const POLYGON& poly, m_polys )
|
||||
{
|
||||
for( unsigned int i = 0; i < poly.size(); i++ )
|
||||
c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), jtRound, etClosedPolygon );
|
||||
}
|
||||
BOOST_FOREACH( Paths& p, m_polys )
|
||||
c.AddPaths(p, jtRound, etClosedPolygon );
|
||||
|
||||
PolyTree solution;
|
||||
|
||||
c.ArcTolerance = (double)fabs( aFactor ) / M_PI / aCircleSegmentsCount;
|
||||
|
||||
c.Execute( solution, aFactor );
|
||||
|
||||
importTree( &solution );
|
||||
m_polys.clear();
|
||||
|
||||
for( PolyNode* n = solution.GetFirst(); n; n = n->GetNext() )
|
||||
{
|
||||
Paths ps;
|
||||
ps.push_back( n->Contour );
|
||||
m_polys.push_back( ps );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::importTree( PolyTree* tree)
|
||||
void SHAPE_POLY_SET::importTree( ClipperLib::PolyTree* tree )
|
||||
{
|
||||
m_polys.clear();
|
||||
|
||||
@ -273,37 +234,37 @@ void SHAPE_POLY_SET::importTree( PolyTree* tree)
|
||||
{
|
||||
if( !n->IsHole() )
|
||||
{
|
||||
POLYGON paths;
|
||||
paths.push_back( convertFromClipper( n->Contour ) );
|
||||
Paths paths;
|
||||
paths.push_back( n->Contour );
|
||||
|
||||
for( unsigned int i = 0; i < n->Childs.size(); i++ )
|
||||
paths.push_back( convertFromClipper( n->Childs[i]->Contour ) );
|
||||
for( unsigned i = 0; i < n->Childs.size(); i++ )
|
||||
paths.push_back( n->Childs[i]->Contour );
|
||||
|
||||
m_polys.push_back(paths);
|
||||
m_polys.push_back( paths );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Polygon fracturing code. Work in progress.
|
||||
|
||||
// Polygon fracturing code. Work in progress.
|
||||
struct FractureEdge
|
||||
{
|
||||
FractureEdge( bool connected, SHAPE_LINE_CHAIN* owner, int index ) :
|
||||
FractureEdge( bool connected, Path* owner, int index ) :
|
||||
m_connected( connected ),
|
||||
m_next( NULL )
|
||||
{
|
||||
m_p1 = owner->CPoint( index );
|
||||
m_p2 = owner->CPoint( index + 1 );
|
||||
m_p1 = (*owner)[index];
|
||||
m_p2 = (*owner)[(index + 1) % owner->size()];
|
||||
}
|
||||
|
||||
FractureEdge( int y = 0 ) :
|
||||
FractureEdge( int64_t y = 0 ) :
|
||||
m_connected( false ),
|
||||
m_next( NULL )
|
||||
{
|
||||
m_p1.x = m_p2.y = y;
|
||||
m_p1.Y = m_p2.Y = y;
|
||||
}
|
||||
|
||||
FractureEdge( bool connected, const VECTOR2I& p1, const VECTOR2I& p2 ) :
|
||||
FractureEdge( bool connected, const IntPoint& p1, const IntPoint& p2 ) :
|
||||
m_connected( connected ),
|
||||
m_p1( p1 ),
|
||||
m_p2( p2 ),
|
||||
@ -313,14 +274,14 @@ struct FractureEdge
|
||||
|
||||
bool matches( int y ) const
|
||||
{
|
||||
int y_min = std::min( m_p1.y, m_p2.y );
|
||||
int y_max = std::max( m_p1.y, m_p2.y );
|
||||
int y_min = std::min( m_p1.Y, m_p2.Y );
|
||||
int y_max = std::max( m_p1.Y, m_p2.Y );
|
||||
|
||||
return ( y >= y_min ) && ( y <= y_max );
|
||||
}
|
||||
|
||||
bool m_connected;
|
||||
VECTOR2I m_p1, m_p2;
|
||||
IntPoint m_p1, m_p2;
|
||||
FractureEdge* m_next;
|
||||
};
|
||||
|
||||
@ -329,10 +290,10 @@ typedef std::vector<FractureEdge*> FractureEdgeSet;
|
||||
|
||||
static int processEdge( FractureEdgeSet& edges, FractureEdge* edge )
|
||||
{
|
||||
int x = edge->m_p1.x;
|
||||
int y = edge->m_p1.y;
|
||||
int min_dist = std::numeric_limits<int>::max();
|
||||
int x_nearest = 0;
|
||||
int64_t x = edge->m_p1.X;
|
||||
int64_t y = edge->m_p1.Y;
|
||||
int64_t min_dist = std::numeric_limits<int64_t>::max();
|
||||
int64_t x_nearest = 0;
|
||||
|
||||
FractureEdge* e_nearest = NULL;
|
||||
|
||||
@ -341,14 +302,15 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge )
|
||||
if( !(*i)->matches( y ) )
|
||||
continue;
|
||||
|
||||
int x_intersect;
|
||||
int64_t x_intersect;
|
||||
|
||||
if( (*i)->m_p1.y == (*i)->m_p2.y ) // horizontal edge
|
||||
x_intersect = std::max ( (*i)->m_p1.x, (*i)->m_p2.x );
|
||||
if( (*i)->m_p1.Y == (*i)->m_p2.Y ) // horizontal edge
|
||||
x_intersect = std::max( (*i)->m_p1.X, (*i)->m_p2.X );
|
||||
else
|
||||
x_intersect = (*i)->m_p1.x + rescale((*i)->m_p2.x - (*i)->m_p1.x, y - (*i)->m_p1.y, (*i)->m_p2.y - (*i)->m_p1.y );
|
||||
x_intersect = (*i)->m_p1.X + rescale((*i)->m_p2.X - (*i)->m_p1.X,
|
||||
y - (*i)->m_p1.Y, (*i)->m_p2.Y - (*i)->m_p1.Y );
|
||||
|
||||
int dist = ( x - x_intersect );
|
||||
int64_t dist = ( x - x_intersect );
|
||||
|
||||
if( dist > 0 && dist < min_dist )
|
||||
{
|
||||
@ -362,9 +324,9 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge )
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
FractureEdge* lead1 = new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) );
|
||||
FractureEdge* lead2 = new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) );
|
||||
FractureEdge* split_2 = new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 );
|
||||
FractureEdge* lead1 = new FractureEdge( true, IntPoint( x_nearest, y), IntPoint( x, y ) );
|
||||
FractureEdge* lead2 = new FractureEdge( true, IntPoint( x, y), IntPoint( x_nearest, y ) );
|
||||
FractureEdge* split_2 = new FractureEdge( true, IntPoint( x_nearest, y ), e_nearest->m_p2 );
|
||||
|
||||
edges.push_back( split_2 );
|
||||
edges.push_back( lead1 );
|
||||
@ -372,11 +334,11 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge )
|
||||
|
||||
FractureEdge* link = e_nearest->m_next;
|
||||
|
||||
e_nearest->m_p2 = VECTOR2I( x_nearest, y );
|
||||
e_nearest->m_p2 = IntPoint( x_nearest, y );
|
||||
e_nearest->m_next = lead1;
|
||||
lead1->m_next = edge;
|
||||
FractureEdge* last;
|
||||
|
||||
FractureEdge*last;
|
||||
for( last = edge; last->m_next != edge; last = last->m_next )
|
||||
{
|
||||
last->m_connected = true;
|
||||
@ -394,7 +356,8 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge )
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
|
||||
void SHAPE_POLY_SET::fractureSingle( ClipperLib::Paths& paths )
|
||||
{
|
||||
FractureEdgeSet edges;
|
||||
FractureEdgeSet border_edges;
|
||||
@ -407,23 +370,21 @@ void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
|
||||
int num_unconnected = 0;
|
||||
|
||||
BOOST_FOREACH( SHAPE_LINE_CHAIN& path, paths )
|
||||
BOOST_FOREACH( Path& path, paths )
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
FractureEdge *prev = NULL, *first_edge = NULL;
|
||||
|
||||
int x_min = std::numeric_limits<int>::max();
|
||||
int64_t x_min = std::numeric_limits<int64_t>::max();
|
||||
|
||||
for( int i = 0; i < path.PointCount(); i++ )
|
||||
for( unsigned i = 0; i < path.size(); i++ )
|
||||
{
|
||||
const VECTOR2I& p = path.CPoint( i );
|
||||
|
||||
if( p.x < x_min )
|
||||
x_min = p.x;
|
||||
if( path[i].X < x_min )
|
||||
x_min = path[i].X;
|
||||
}
|
||||
|
||||
for( int i = 0; i < path.PointCount(); i++ )
|
||||
for( unsigned i = 0; i < path.size(); i++ )
|
||||
{
|
||||
FractureEdge* fe = new FractureEdge( first, &path, index++ );
|
||||
|
||||
@ -436,7 +397,7 @@ void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
if( prev )
|
||||
prev->m_next = fe;
|
||||
|
||||
if( i == path.PointCount() - 1 )
|
||||
if( i == path.size() - 1 )
|
||||
fe->m_next = first_edge;
|
||||
|
||||
prev = fe;
|
||||
@ -444,27 +405,27 @@ void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
|
||||
if( !first )
|
||||
{
|
||||
if( fe->m_p1.x == x_min )
|
||||
if( fe->m_p1.X == x_min )
|
||||
border_edges.push_back( fe );
|
||||
}
|
||||
|
||||
if( !fe->m_connected )
|
||||
num_unconnected++;
|
||||
}
|
||||
|
||||
first = false; // first path is always the outline
|
||||
}
|
||||
|
||||
// keep connecting holes to the main outline, until there's no holes left...
|
||||
while( num_unconnected > 0 )
|
||||
{
|
||||
int x_min = std::numeric_limits<int>::max();
|
||||
|
||||
int64_t x_min = std::numeric_limits<int64_t>::max();
|
||||
FractureEdge* smallestX = NULL;
|
||||
|
||||
// find the left-most hole edge and merge with the outline
|
||||
for( FractureEdgeSet::iterator i = border_edges.begin(); i != border_edges.end(); ++i )
|
||||
{
|
||||
int xt = (*i)->m_p1.x;
|
||||
int64_t xt = (*i)->m_p1.X;
|
||||
|
||||
if( ( xt < x_min ) && ! (*i)->m_connected )
|
||||
{
|
||||
@ -477,16 +438,13 @@ void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
}
|
||||
|
||||
paths.clear();
|
||||
SHAPE_LINE_CHAIN newPath;
|
||||
|
||||
newPath.SetClosed( true );
|
||||
|
||||
Path newPath;
|
||||
FractureEdge* e;
|
||||
|
||||
for( e = root; e->m_next != root; e = e->m_next )
|
||||
newPath.Append( e->m_p1 );
|
||||
newPath.push_back( e->m_p1 );
|
||||
|
||||
newPath.Append( e->m_p1 );
|
||||
newPath.push_back( e->m_p1 );
|
||||
|
||||
for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
|
||||
delete *i;
|
||||
@ -497,9 +455,7 @@ void SHAPE_POLY_SET::fractureSingle( POLYGON& paths )
|
||||
|
||||
void SHAPE_POLY_SET::Fracture()
|
||||
{
|
||||
Simplify(); // remove overlallping holes/degeneracy
|
||||
|
||||
BOOST_FOREACH( POLYGON& paths, m_polys )
|
||||
BOOST_FOREACH( Paths& paths, m_polys )
|
||||
{
|
||||
fractureSingle( paths );
|
||||
}
|
||||
@ -508,9 +464,12 @@ void SHAPE_POLY_SET::Fracture()
|
||||
|
||||
void SHAPE_POLY_SET::Simplify()
|
||||
{
|
||||
SHAPE_POLY_SET empty;
|
||||
|
||||
booleanOp( ctUnion, empty );
|
||||
for( unsigned i = 0; i < m_polys.size(); i++ )
|
||||
{
|
||||
Paths out;
|
||||
SimplifyPolygons( m_polys[i], out, pftNonZero );
|
||||
m_polys[i] = out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -523,11 +482,13 @@ const std::string SHAPE_POLY_SET::Format() const
|
||||
for( unsigned i = 0; i < m_polys.size(); i++ )
|
||||
{
|
||||
ss << "poly " << m_polys[i].size() << "\n";
|
||||
|
||||
for( unsigned j = 0; j < m_polys[i].size(); j++)
|
||||
{
|
||||
ss << m_polys[i][j].PointCount() << "\n";
|
||||
for( int v = 0; v < m_polys[i][j].PointCount(); v++)
|
||||
ss << m_polys[i][j].CPoint( v ).x << " " << m_polys[i][j].CPoint( v ).y << "\n";
|
||||
ss << m_polys[i][j].size() << "\n";
|
||||
|
||||
for( unsigned v = 0; v < m_polys[i][j].size(); v++)
|
||||
ss << m_polys[i][j][v].X << " " << m_polys[i][j][v].Y << "\n";
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
@ -554,8 +515,7 @@ bool SHAPE_POLY_SET::Parse( std::stringstream& aStream )
|
||||
|
||||
for( int i = 0; i < n_polys; i++ )
|
||||
{
|
||||
POLYGON paths;
|
||||
|
||||
ClipperLib::Paths paths;
|
||||
aStream >> tmp;
|
||||
|
||||
if( tmp != "poly" )
|
||||
@ -569,26 +529,23 @@ bool SHAPE_POLY_SET::Parse( std::stringstream& aStream )
|
||||
|
||||
for( int j = 0; j < n_outlines; j++ )
|
||||
{
|
||||
SHAPE_LINE_CHAIN outline;
|
||||
|
||||
outline.SetClosed( true );
|
||||
ClipperLib::Path outline;
|
||||
|
||||
aStream >> tmp;
|
||||
int n_vertices = atoi( tmp.c_str() );
|
||||
for( int v = 0; v < n_vertices; v++ )
|
||||
{
|
||||
VECTOR2I p;
|
||||
ClipperLib::IntPoint p;
|
||||
|
||||
aStream >> tmp; p.x = atoi( tmp.c_str() );
|
||||
aStream >> tmp; p.y = atoi( tmp.c_str() );
|
||||
outline.Append( p );
|
||||
aStream >> tmp; p.X = atoi( tmp.c_str() );
|
||||
aStream >> tmp; p.Y = atoi( tmp.c_str() );
|
||||
outline.push_back( p );
|
||||
}
|
||||
|
||||
paths.push_back( outline );
|
||||
}
|
||||
|
||||
m_polys.push_back( paths );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -600,146 +557,22 @@ const BOX2I SHAPE_POLY_SET::BBox( int aClearance ) const
|
||||
|
||||
for( unsigned i = 0; i < m_polys.size(); i++ )
|
||||
{
|
||||
if( first )
|
||||
bb = m_polys[i][0].BBox();
|
||||
else
|
||||
bb.Merge( m_polys[i][0].BBox() );
|
||||
for( unsigned j = 0; j < m_polys[i].size(); j++)
|
||||
{
|
||||
for( unsigned v = 0; v < m_polys[i][j].size(); v++)
|
||||
{
|
||||
VECTOR2I p( m_polys[i][j][v].X, m_polys[i][j][v].Y );
|
||||
|
||||
if( first )
|
||||
bb = BOX2I( p, VECTOR2I( 0, 0 ) );
|
||||
else
|
||||
bb.Merge( p );
|
||||
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bb.Inflate( aClearance );
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::RemoveAllContours()
|
||||
{
|
||||
m_polys.clear();
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::DeletePolygon( int aIdx )
|
||||
{
|
||||
m_polys.erase( m_polys.begin() + aIdx );
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::Append( const SHAPE_POLY_SET& aSet )
|
||||
{
|
||||
m_polys.insert( m_polys.end(), aSet.m_polys.begin(), aSet.m_polys.end() );
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::Append( const VECTOR2I& aP, int aOutline, int aHole )
|
||||
{
|
||||
Append( aP.x, aP.y, aOutline, aHole );
|
||||
}
|
||||
|
||||
|
||||
bool SHAPE_POLY_SET::Contains( const VECTOR2I& aP, int aSubpolyIndex ) const
|
||||
{
|
||||
// fixme: support holes!
|
||||
|
||||
if( aSubpolyIndex >= 0 )
|
||||
return pointInPolygon( aP, m_polys[aSubpolyIndex][0] );
|
||||
|
||||
BOOST_FOREACH ( const POLYGON& polys, m_polys )
|
||||
{
|
||||
if( pointInPolygon( aP, polys[0] ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SHAPE_POLY_SET::pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const
|
||||
{
|
||||
int result = 0;
|
||||
int cnt = aPath.PointCount();
|
||||
|
||||
if ( !aPath.BBox().Contains( aP ) ) // test with bounding box first
|
||||
return false;
|
||||
|
||||
if( cnt < 3 )
|
||||
return false;
|
||||
|
||||
VECTOR2I ip = aPath.CPoint( 0 );
|
||||
|
||||
for( int i = 1; i <= cnt; ++i )
|
||||
{
|
||||
VECTOR2I ipNext = ( i == cnt ? aPath.CPoint( 0 ) : aPath.CPoint( i ) );
|
||||
|
||||
if( ipNext.y == aP.y )
|
||||
{
|
||||
if( ( ipNext.x == aP.x ) || ( ip.y == aP.y &&
|
||||
( ( ipNext.x > aP.x ) == ( ip.x < aP.x ) ) ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( ( ip.y < aP.y ) != ( ipNext.y < aP.y ) )
|
||||
{
|
||||
if( ip.x >= aP.x )
|
||||
{
|
||||
if( ipNext.x > aP.x )
|
||||
result = 1 - result;
|
||||
else
|
||||
{
|
||||
int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
|
||||
(int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
|
||||
|
||||
if( !d )
|
||||
return true;
|
||||
|
||||
if( ( d > 0 ) == ( ipNext.y > ip.y ) )
|
||||
result = 1 - result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ipNext.x > aP.x )
|
||||
{
|
||||
int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
|
||||
(int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
|
||||
|
||||
if( !d )
|
||||
return -1;
|
||||
|
||||
if( ( d > 0 ) == ( ipNext.y > ip.y ) )
|
||||
result = 1 - result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ip = ipNext;
|
||||
}
|
||||
|
||||
return result ? true : false;
|
||||
}
|
||||
|
||||
|
||||
void SHAPE_POLY_SET::Move( const VECTOR2I& aVector )
|
||||
{
|
||||
BOOST_FOREACH( POLYGON &poly, m_polys )
|
||||
{
|
||||
BOOST_FOREACH( SHAPE_LINE_CHAIN &path, poly )
|
||||
{
|
||||
path.Move( aVector );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int SHAPE_POLY_SET::TotalVertices() const
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
BOOST_FOREACH( const POLYGON& poly, m_polys )
|
||||
{
|
||||
BOOST_FOREACH ( const SHAPE_LINE_CHAIN& path, poly )
|
||||
{
|
||||
c += path.PointCount();
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <polygons_defs.h>
|
||||
#include <gr_basic.h>
|
||||
#include <common.h>
|
||||
#include <trigo.h>
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include <fctsys.h>
|
||||
#include <trigo.h>
|
||||
#include <macros.h>
|
||||
#include <PolyLine.h>
|
||||
|
||||
#include <geometry/shape_poly_set.h>
|
||||
/**
|
||||
* Function TransformCircleToPolygon
|
||||
* convert a circle to a polygon, using multiple straight lines
|
||||
@ -45,9 +45,9 @@
|
||||
* Note: the polygon is inside the circle, so if you want to have the polygon
|
||||
* outside the circle, you should give aRadius calculated with a correction factor
|
||||
*/
|
||||
void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
wxPoint aCenter, int aRadius,
|
||||
int aCircleToSegmentsCount );
|
||||
void TransformCircleToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCenter, int aRadius,
|
||||
int aCircleToSegmentsCount );
|
||||
|
||||
/**
|
||||
* Function TransformRoundedEndsSegmentToPolygon
|
||||
@ -61,7 +61,7 @@ void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* Note: the polygon is inside the arc ends, so if you want to have the polygon
|
||||
* outside the circle, you should give aStart and aEnd calculated with a correction factor
|
||||
*/
|
||||
void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformRoundedEndsSegmentToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aStart, wxPoint aEnd,
|
||||
int aCircleToSegmentsCount,
|
||||
int aWidth );
|
||||
@ -78,7 +78,7 @@ void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* @param aWidth = width (thickness) of the line
|
||||
*/
|
||||
void TransformArcToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformArcToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCentre, wxPoint aStart, double aArcAngle,
|
||||
int aCircleToSegmentsCount, int aWidth );
|
||||
|
||||
@ -92,7 +92,7 @@ void TransformArcToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* @param aWidth = width (thickness) of the ring
|
||||
*/
|
||||
void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformRingToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxPoint aCentre, int aRadius,
|
||||
int aCircleToSegmentsCount, int aWidth );
|
||||
|
||||
|
@ -255,9 +255,6 @@ public:
|
||||
if( aIndex < 0 )
|
||||
aIndex += PointCount();
|
||||
|
||||
if( aIndex >= PointCount() )
|
||||
aIndex -= PointCount();
|
||||
|
||||
return m_points[aIndex];
|
||||
}
|
||||
|
||||
@ -581,7 +578,6 @@ public:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
/// array of vertices
|
||||
std::vector<VECTOR2I> m_points;
|
||||
|
@ -32,103 +32,25 @@
|
||||
|
||||
#include "clipper.hpp"
|
||||
|
||||
|
||||
/**
|
||||
* Class SHAPE_POLY_SET
|
||||
*
|
||||
* Represents a set of closed polygons. Polygons may be nonconvex, self-intersecting
|
||||
* and have holes. Provides boolean operations (using Clipper library as the backend).
|
||||
*
|
||||
* TODO: add convex partitioning & spatial index
|
||||
* TODO: document, derive from class SHAPE, add convex partitioning & spatial index
|
||||
*/
|
||||
class SHAPE_POLY_SET : public SHAPE
|
||||
{
|
||||
public:
|
||||
///> represents a single polygon outline with holes. The first entry is the outline,
|
||||
///> the remaining (if any), are the holes
|
||||
typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
|
||||
|
||||
/**
|
||||
* Class ITERATOR_TEMPLATE
|
||||
*
|
||||
* Base class for iterating over all vertices in a given SHAPE_POLY_SET
|
||||
*/
|
||||
template <class T>
|
||||
class ITERATOR_TEMPLATE {
|
||||
public:
|
||||
|
||||
bool IsEndContour() const
|
||||
{
|
||||
return m_currentVertex + 1 == m_poly->CPolygon( m_currentOutline )[0].PointCount();
|
||||
}
|
||||
|
||||
bool IsLastContour() const
|
||||
{
|
||||
return m_currentOutline == m_lastOutline;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return m_currentOutline <= m_lastOutline;
|
||||
}
|
||||
|
||||
void Advance()
|
||||
{
|
||||
m_currentVertex ++;
|
||||
|
||||
if( m_currentVertex >= m_poly->CPolygon( m_currentOutline )[0].PointCount() )
|
||||
{
|
||||
m_currentVertex = 0;
|
||||
m_currentOutline++;
|
||||
}
|
||||
}
|
||||
|
||||
void operator++( int dummy )
|
||||
{
|
||||
Advance();
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
Advance();
|
||||
}
|
||||
|
||||
T& Get()
|
||||
{
|
||||
return m_poly->Polygon( m_currentOutline )[0].Point( m_currentVertex );
|
||||
}
|
||||
|
||||
T& operator*()
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
return &Get();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
friend class SHAPE_POLY_SET;
|
||||
|
||||
SHAPE_POLY_SET* m_poly;
|
||||
int m_currentOutline;
|
||||
int m_lastOutline;
|
||||
int m_currentVertex;
|
||||
};
|
||||
|
||||
typedef ITERATOR_TEMPLATE<VECTOR2I> ITERATOR;
|
||||
typedef ITERATOR_TEMPLATE<const VECTOR2I> CONST_ITERATOR;
|
||||
|
||||
SHAPE_POLY_SET();
|
||||
~SHAPE_POLY_SET();
|
||||
SHAPE_POLY_SET() : SHAPE( SH_POLY_SET ) {};
|
||||
~SHAPE_POLY_SET() {};
|
||||
|
||||
///> Creates a new empty polygon in the set and returns its index
|
||||
int NewOutline();
|
||||
|
||||
///> Creates a new hole in a given outline
|
||||
int NewHole( int aOutline = -1 );
|
||||
///> Cretes a new empty hole in the given outline (default: last one) and returns its index
|
||||
int NewHole( int aOutline = -1);
|
||||
|
||||
///> Adds a new outline to the set and returns its index
|
||||
int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
|
||||
@ -136,20 +58,11 @@ class SHAPE_POLY_SET : public SHAPE
|
||||
///> Adds a new hole to the given outline (default: last) and returns its index
|
||||
int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
|
||||
|
||||
///> Appends a vertex at the end of the given outline/hole (default: the last outline)
|
||||
int Append( int x, int y, int aOutline = -1, int aHole = -1 );
|
||||
|
||||
///> Merges polygons from two sets.
|
||||
void Append( const SHAPE_POLY_SET& aSet );
|
||||
|
||||
///> Appends a vertex at the end of the given outline/hole (default: the last outline)
|
||||
void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
|
||||
///> Appends a vertex at the end of the given outline/hole (default: last hole in the last outline)
|
||||
int AppendVertex( int x, int y, int aOutline = -1, int aHole = -1 );
|
||||
|
||||
///> Returns the index-th vertex in a given hole outline within a given outline
|
||||
VECTOR2I& Vertex( int index, int aOutline = -1, int aHole = -1 );
|
||||
|
||||
///> Returns the index-th vertex in a given hole outline within a given outline
|
||||
const VECTOR2I& CVertex( int index, int aOutline = -1, int aHole = -1 ) const;
|
||||
const VECTOR2I GetVertex( int index, int aOutline = -1, int aHole = -1) const;
|
||||
|
||||
///> Returns true if any of the outlines is self-intersecting
|
||||
bool IsSelfIntersecting();
|
||||
@ -160,109 +73,28 @@ class SHAPE_POLY_SET : public SHAPE
|
||||
///> Returns the number of vertices in a given outline/hole
|
||||
int VertexCount( int aOutline = -1, int aHole = -1 ) const;
|
||||
|
||||
///> Returns the number of holes in a given outline
|
||||
int HoleCount( int aOutline ) const;
|
||||
|
||||
///> Returns the reference to aIndex-th outline in the set
|
||||
SHAPE_LINE_CHAIN& Outline( int aIndex )
|
||||
{
|
||||
return m_polys[aIndex][0];
|
||||
}
|
||||
|
||||
///> Returns the reference to aHole-th hole in the aIndex-th outline
|
||||
SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
|
||||
{
|
||||
return m_polys[aOutline][aHole + 1];
|
||||
}
|
||||
|
||||
///> Returns the aIndex-th subpolygon in the set
|
||||
POLYGON& Polygon( int aIndex )
|
||||
///> Returns the internal representation (ClipperLib) of a given polygon (outline + holes)
|
||||
const ClipperLib::Paths& GetPoly( int aIndex ) const
|
||||
{
|
||||
return m_polys[aIndex];
|
||||
}
|
||||
|
||||
const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
|
||||
{
|
||||
return m_polys[aIndex][0];
|
||||
}
|
||||
|
||||
const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
|
||||
{
|
||||
return m_polys[aOutline][aHole + 1];
|
||||
}
|
||||
|
||||
const POLYGON& CPolygon( int aIndex ) const
|
||||
{
|
||||
return m_polys[aIndex];
|
||||
}
|
||||
|
||||
///> Returns an iterator object, for iterating between aFirst and aLast outline.
|
||||
ITERATOR Iterate( int aFirst, int aLast )
|
||||
{
|
||||
ITERATOR iter;
|
||||
|
||||
iter.m_poly = this;
|
||||
iter.m_currentOutline = aFirst;
|
||||
iter.m_lastOutline = aLast < 0 ? OutlineCount() - 1 : aLast;
|
||||
iter.m_currentVertex = 0;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
///> Returns an iterator object, for iterating aOutline-th outline
|
||||
ITERATOR Iterate( int aOutline )
|
||||
{
|
||||
return Iterate( aOutline, aOutline );
|
||||
}
|
||||
|
||||
///> Returns an iterator object, for all outlines in the set (no holes)
|
||||
ITERATOR Iterate()
|
||||
{
|
||||
return Iterate( 0, OutlineCount() - 1 );
|
||||
}
|
||||
|
||||
CONST_ITERATOR CIterate( int aFirst, int aLast ) const
|
||||
{
|
||||
CONST_ITERATOR iter;
|
||||
|
||||
iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
|
||||
iter.m_currentOutline = aFirst;
|
||||
iter.m_lastOutline = aLast < 0 ? OutlineCount() - 1 : aLast;
|
||||
iter.m_currentVertex = 0;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
CONST_ITERATOR CIterate( int aOutline ) const
|
||||
{
|
||||
return CIterate( aOutline, aOutline );
|
||||
}
|
||||
|
||||
CONST_ITERATOR CIterate() const
|
||||
{
|
||||
return CIterate( 0, OutlineCount() - 1 );
|
||||
}
|
||||
|
||||
|
||||
///> Performs boolean polyset union
|
||||
void BooleanAdd( const SHAPE_POLY_SET& b );
|
||||
|
||||
///> Performs boolean polyset difference
|
||||
void BooleanSubtract( const SHAPE_POLY_SET& b );
|
||||
void Subtract( const SHAPE_POLY_SET& b );
|
||||
|
||||
///> Performs outline inflation/deflation, using round corners.
|
||||
void Inflate( int aFactor, int aCircleSegmentsCount );
|
||||
///> Performs boolean polyset union
|
||||
void Add( const SHAPE_POLY_SET& b );
|
||||
|
||||
///> Performs smooth outline inflation (Minkowski sum of the outline and a circle of a given radius)
|
||||
void SmoothInflate( int aFactor );
|
||||
|
||||
///> Performs outline erosion/shrinking
|
||||
void Erode( int aFactor );
|
||||
|
||||
///> Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the outer ring
|
||||
///> to the inner holes
|
||||
void Fracture();
|
||||
|
||||
///> Converts a set of slitted polygons to a set of polygons with holes
|
||||
void Unfracture();
|
||||
|
||||
///> Returns true if the polygon set has any holes.
|
||||
bool HasHoles() const;
|
||||
|
||||
///> Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
|
||||
void Simplify();
|
||||
|
||||
@ -272,10 +104,8 @@ class SHAPE_POLY_SET : public SHAPE
|
||||
/// @copydoc SHAPE::Parse()
|
||||
bool Parse( std::stringstream& aStream );
|
||||
|
||||
/// @copydoc SHAPE::Move()
|
||||
void Move( const VECTOR2I& aVector );
|
||||
void Move( const VECTOR2I& aVector ) { assert(false ); };
|
||||
|
||||
/// @copydoc SHAPE::IsSolid()
|
||||
bool IsSolid() const
|
||||
{
|
||||
return true;
|
||||
@ -287,43 +117,15 @@ class SHAPE_POLY_SET : public SHAPE
|
||||
bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const { return false; }
|
||||
bool Collide( const SEG& aSeg, int aClearance = 0 ) const { return false; }
|
||||
|
||||
|
||||
///> Returns true is a given subpolygon contains the point aP. If aSubpolyIndex < 0 (default value),
|
||||
///> checks all polygons in the set
|
||||
bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1 ) const;
|
||||
|
||||
///> Returns true if the set is empty (no polygons at all)
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return m_polys.size() == 0;
|
||||
}
|
||||
|
||||
///> Removes all outlines & holes (clears) the polygon set.
|
||||
void RemoveAllContours();
|
||||
|
||||
///> Returns total number of vertices stored in the set.
|
||||
int TotalVertices() const;
|
||||
|
||||
///> Deletes aIdx-th polygon from the set
|
||||
void DeletePolygon( int aIdx );
|
||||
|
||||
private:
|
||||
|
||||
SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
|
||||
VECTOR2I& vertex( int aCornerId );
|
||||
const VECTOR2I& cvertex( int aCornerId ) const;
|
||||
|
||||
|
||||
void fractureSingle( POLYGON& paths );
|
||||
void importTree( ClipperLib::PolyTree* tree );
|
||||
void fractureSingle( ClipperLib::Paths& paths );
|
||||
void importTree( ClipperLib::PolyTree* tree);
|
||||
void booleanOp( ClipperLib::ClipType type, const SHAPE_POLY_SET& b );
|
||||
|
||||
bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
|
||||
const ClipperLib::Path convert( const SHAPE_LINE_CHAIN& aPath );
|
||||
|
||||
const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );
|
||||
const SHAPE_LINE_CHAIN convertFromClipper( const ClipperLib::Path& aPath );
|
||||
|
||||
typedef std::vector<POLYGON> Polyset;
|
||||
typedef std::vector<ClipperLib::Paths> Polyset;
|
||||
|
||||
Polyset m_polys;
|
||||
};
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <polygons_defs.h>
|
||||
#include <drawtxt.h>
|
||||
#include <pcbnew.h>
|
||||
#include <wxPcbStruct.h>
|
||||
@ -50,9 +51,9 @@
|
||||
// These variables are parameters used in addTextSegmToPoly.
|
||||
// But addTextSegmToPoly is a call-back function,
|
||||
// so we cannot send them as arguments.
|
||||
static int s_textWidth;
|
||||
static int s_textCircle2SegmentCount;
|
||||
static SHAPE_POLY_SET* s_cornerBuffer;
|
||||
int s_textWidth;
|
||||
int s_textCircle2SegmentCount;
|
||||
CPOLYGONS_LIST* s_cornerBuffer;
|
||||
|
||||
// This is a call back function, used by DrawGraphicText to draw the 3D text shape:
|
||||
static void addTextSegmToPoly( int x0, int y0, int xf, int yf )
|
||||
@ -63,7 +64,7 @@ static void addTextSegmToPoly( int x0, int y0, int xf, int yf )
|
||||
}
|
||||
|
||||
|
||||
void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines )
|
||||
void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, CPOLYGONS_LIST& aOutlines )
|
||||
{
|
||||
// Number of segments to convert a circle to a polygon
|
||||
const int segcountforcircle = 18;
|
||||
@ -127,7 +128,7 @@ void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET&
|
||||
|
||||
|
||||
void MODULE::TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor,
|
||||
@ -202,7 +203,7 @@ void MODULE::TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
|
||||
*/
|
||||
void MODULE::TransformGraphicShapesWithClearanceToPolygonSet(
|
||||
LAYER_ID aLayer,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor )
|
||||
@ -279,30 +280,43 @@ void MODULE::TransformGraphicShapesWithClearanceToPolygonSet(
|
||||
* keep arc radius when approximated by segments
|
||||
*/
|
||||
void ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor )
|
||||
{
|
||||
if( GetFilledPolysList().IsEmpty() )
|
||||
unsigned cornerscount = GetFilledPolysList().GetCornersCount();
|
||||
|
||||
if( cornerscount == 0 )
|
||||
return;
|
||||
|
||||
// add filled areas polygons
|
||||
aCornerBuffer.Append( m_FilledPolysList );
|
||||
|
||||
// add filled areas outlines, which are drawn with thick lines
|
||||
for( int i = 0; i < m_FilledPolysList.OutlineCount(); i++ )
|
||||
wxPoint seg_start, seg_end;
|
||||
int i_start_contour = 0;
|
||||
for( unsigned ic = 0; ic < cornerscount; ic++ )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( i );
|
||||
seg_start.x = m_FilledPolysList[ ic ].x;
|
||||
seg_start.y = m_FilledPolysList[ ic ].y;
|
||||
unsigned ic_next = ic+1;
|
||||
|
||||
for( int j = 0; j < path.PointCount(); j++ )
|
||||
if( !m_FilledPolysList[ic].end_contour &&
|
||||
ic_next < cornerscount )
|
||||
{
|
||||
const VECTOR2I& a = path.CPoint( j );
|
||||
const VECTOR2I& b = path.CPoint( j + 1 );
|
||||
|
||||
TransformRoundedEndsSegmentToPolygon( aCornerBuffer, wxPoint( a.x, a.y ), wxPoint( b.x, b.y ),
|
||||
aCircleToSegmentsCount,
|
||||
GetMinThickness() );
|
||||
seg_end.x = m_FilledPolysList[ ic_next ].x;
|
||||
seg_end.y = m_FilledPolysList[ ic_next ].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
seg_end.x = m_FilledPolysList[ i_start_contour ].x;
|
||||
seg_end.y = m_FilledPolysList[ i_start_contour ].y;
|
||||
i_start_contour = ic_next;
|
||||
}
|
||||
|
||||
TransformRoundedEndsSegmentToPolygon( aCornerBuffer, seg_start, seg_end,
|
||||
aCircleToSegmentsCount,
|
||||
GetMinThickness() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,13 +329,13 @@ void ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(
|
||||
* @param aClearanceValue = the clearance around the text bounding box
|
||||
*/
|
||||
void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
int aClearanceValue ) const
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue ) const
|
||||
{
|
||||
if( GetText().Length() == 0 )
|
||||
return;
|
||||
|
||||
wxPoint corners[4]; // Buffer of polygon corners
|
||||
CPolyPt corners[4]; // Buffer of polygon corners
|
||||
|
||||
EDA_RECT rect = GetTextBox( -1 );
|
||||
rect.Inflate( aClearanceValue );
|
||||
@ -334,14 +348,14 @@ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(
|
||||
corners[3].y = corners[2].y;
|
||||
corners[3].x = corners[0].x;
|
||||
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( int ii = 0; ii < 4; ii++ )
|
||||
{
|
||||
// Rotate polygon
|
||||
RotatePoint( &corners[ii].x, &corners[ii].y, m_Pos.x, m_Pos.y, m_Orient );
|
||||
aCornerBuffer.Append( corners[ii].x, corners[ii].y );
|
||||
aCornerBuffer.Append( corners[ii] );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
}
|
||||
|
||||
|
||||
@ -349,7 +363,7 @@ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(
|
||||
* Convert the text shape to a set of polygons (one by segment)
|
||||
* Used in filling zones calculations and 3D view
|
||||
* Circles and arcs are approximated by segments
|
||||
* aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
|
||||
* aCornerBuffer = CPOLYGONS_LIST to store the polygon corners
|
||||
* aClearanceValue = the clearance around the text
|
||||
* aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* aCorrectionFactor = the correction to apply to circles radius to keep
|
||||
@ -358,7 +372,7 @@ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(
|
||||
*/
|
||||
|
||||
void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const
|
||||
@ -414,7 +428,7 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(
|
||||
* clearance when the circle is approxiamted by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const
|
||||
@ -449,8 +463,6 @@ void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
|
||||
MODULE* module = GetParentModule(); // NULL for items not in footprints
|
||||
double orientation = module ? module->GetOrientation() : 0.0;
|
||||
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
// Build the polygon with the actual position and orientation:
|
||||
std::vector< wxPoint> poly;
|
||||
poly = GetPolyPoints();
|
||||
@ -486,8 +498,9 @@ void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
|
||||
for( unsigned ii = 0; ii < poly.size(); ii++ )
|
||||
{
|
||||
CPolyPt corner( poly[ii] );
|
||||
aCornerBuffer.Append( corner.x, corner.y );
|
||||
aCornerBuffer.Append( corner );
|
||||
}
|
||||
aCornerBuffer.CloseLastContour();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -512,7 +525,7 @@ void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TRACK:: TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const
|
||||
@ -541,14 +554,15 @@ void TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* Convert the pad shape to a closed polygon
|
||||
* Used in filling zones calculations and 3D view generation
|
||||
* Circles and arcs are approximated by segments
|
||||
* aCornerBuffer = a SHAPE_POLY_SET to store the polygon corners
|
||||
* aCornerBuffer = a CPOLYGONS_LIST to store the polygon corners
|
||||
* aClearanceValue = the clearance around the pad
|
||||
* aCircleToSegmentsCount = the number of segments to approximate a circle
|
||||
* aCorrectionFactor = the correction to apply to circles radius to keep
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void D_PAD:: TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
#include <clipper.hpp>
|
||||
void D_PAD:: TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const
|
||||
@ -601,21 +615,36 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer
|
||||
wxPoint corners[4];
|
||||
BuildPadPolygon( corners, wxSize( 0, 0 ), angle );
|
||||
|
||||
SHAPE_POLY_SET outline;
|
||||
|
||||
outline.NewOutline();
|
||||
// We are using ClipperLib to inflate the polygon shape, using
|
||||
// arcs to connect moved segments.
|
||||
ClipperLib::Path outline;
|
||||
ClipperLib::Paths shapeWithClearance;
|
||||
|
||||
for( int ii = 0; ii < 4; ii++ )
|
||||
{
|
||||
corners[ii] += PadShapePos;
|
||||
outline.Append( corners[ii].x, corners[ii].y );
|
||||
outline << ClipperLib::IntPoint( corners[ii].x, corners[ii].y );
|
||||
}
|
||||
|
||||
ClipperLib::ClipperOffset offset_engine;
|
||||
// Prepare an offset (inflate) transform, with edges connected by arcs
|
||||
offset_engine.AddPath( outline, ClipperLib::jtRound, ClipperLib::etClosedPolygon );
|
||||
|
||||
// Clipper approximates arcs by segments
|
||||
// It uses a value called ArcTolerance which is the max error between the arc
|
||||
// and segments created to approximate this arc
|
||||
// the number of segm per circle is:
|
||||
// n = PI / acos(1 - arc_tolerance / (arc radius))
|
||||
// the arc radius is aClearanceValue
|
||||
// because arc_tolerance is << aClearanceValue and aClearanceValue >= 0
|
||||
// n = PI / (arc_tolerance / aClearanceValue )
|
||||
offset_engine.ArcTolerance = (double)aClearanceValue / 3.14 / aCircleToSegmentsCount;
|
||||
|
||||
double rounding_radius = aClearanceValue * aCorrectionFactor;
|
||||
offset_engine.Execute( shapeWithClearance, rounding_radius );
|
||||
|
||||
outline.Inflate( (int) rounding_radius, aCircleToSegmentsCount );
|
||||
|
||||
aCornerBuffer.Append( outline );
|
||||
// get new outline (only one polygon is expected)
|
||||
aCornerBuffer.ImportFrom( shapeWithClearance );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -628,7 +657,7 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer
|
||||
* Note: for Round and oval pads this function is equivalent to
|
||||
* TransformShapeWithClearanceToPolygon, but not for other shapes
|
||||
*/
|
||||
void D_PAD::BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void D_PAD::BuildPadShapePolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxSize aInflateValue, int aSegmentsPerCircle,
|
||||
double aCorrectionFactor ) const
|
||||
{
|
||||
@ -645,15 +674,15 @@ void D_PAD::BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
case PAD_TRAPEZOID:
|
||||
case PAD_RECT:
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
BuildPadPolygon( corners, aInflateValue, m_Orient );
|
||||
for( int ii = 0; ii < 4; ii++ )
|
||||
{
|
||||
corners[ii] += PadShapePos; // Shift origin to position
|
||||
aCornerBuffer.Append( corners[ii].x, corners[ii].y );
|
||||
CPolyPt polypoint( corners[ii].x, corners[ii].y );
|
||||
aCornerBuffer.Append( polypoint );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -664,7 +693,7 @@ void D_PAD::BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* depending on shape pad hole and orientation
|
||||
* return false if the pad has no hole, true otherwise
|
||||
*/
|
||||
bool D_PAD::BuildPadDrillShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
bool D_PAD::BuildPadDrillShapePolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue, int aSegmentsPerCircle ) const
|
||||
{
|
||||
wxSize drillsize = GetDrillSize();
|
||||
@ -721,7 +750,7 @@ bool D_PAD::BuildPadDrillShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
* and are used in microwave applications and they *DO NOT* have a thermal relief that
|
||||
* change the shape by creating stubs and destroy their properties.
|
||||
*/
|
||||
void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
D_PAD& aPad,
|
||||
int aThermalGap,
|
||||
int aCopperThickness,
|
||||
@ -827,16 +856,15 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
for( unsigned ihole = 0; ihole < 4; ihole++ )
|
||||
{
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( unsigned ii = 0; ii < corners_buffer.size(); ii++ )
|
||||
{
|
||||
corner = corners_buffer[ii];
|
||||
RotatePoint( &corner, th_angle + angle_pad ); // Rotate by segment angle and pad orientation
|
||||
corner += PadShapePos;
|
||||
aCornerBuffer.Append( corner.x, corner.y );
|
||||
aCornerBuffer.Append( CPolyPt( corner.x, corner.y ) );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
th_angle += 900; // Note: th_angle in in 0.1 deg.
|
||||
}
|
||||
}
|
||||
@ -932,15 +960,15 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
for( int irect = 0; irect < 2; irect++ )
|
||||
{
|
||||
aCornerBuffer.NewOutline();
|
||||
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
||||
{
|
||||
wxPoint cpos = corners_buffer[ic];
|
||||
RotatePoint( &cpos, angle );
|
||||
cpos += PadShapePos;
|
||||
aCornerBuffer.Append( cpos.x, cpos.y );
|
||||
aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
angle = AddAngles( angle, 1800 ); // this is calculate hole 3
|
||||
}
|
||||
|
||||
@ -957,16 +985,15 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
for( int irect = 0; irect < 2; irect++ )
|
||||
{
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
||||
{
|
||||
wxPoint cpos = corners_buffer[ic];
|
||||
RotatePoint( &cpos, angle );
|
||||
cpos += PadShapePos;
|
||||
aCornerBuffer.Append( cpos.x, cpos.y );
|
||||
aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
angle = AddAngles( angle, 1800 );
|
||||
}
|
||||
}
|
||||
@ -1030,16 +1057,15 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
for( int irect = 0; irect < 2; irect++ )
|
||||
{
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
||||
{
|
||||
wxPoint cpos = corners_buffer[ic];
|
||||
RotatePoint( &cpos, angle ); // Rotate according to module orientation
|
||||
cpos += PadShapePos; // Shift origin to position
|
||||
aCornerBuffer.Append( cpos.x, cpos.y );
|
||||
aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
angle = AddAngles( angle, 1800 ); // this is calculate hole 3
|
||||
}
|
||||
|
||||
@ -1054,16 +1080,15 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
// Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg
|
||||
for( int irect = 0; irect < 2; irect++ )
|
||||
{
|
||||
aCornerBuffer.NewOutline();
|
||||
|
||||
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
||||
{
|
||||
wxPoint cpos = corners_buffer[ic];
|
||||
RotatePoint( &cpos, angle );
|
||||
cpos += PadShapePos;
|
||||
aCornerBuffer.Append( cpos.x, cpos.y );
|
||||
aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) );
|
||||
}
|
||||
|
||||
aCornerBuffer.CloseLastContour();
|
||||
angle = AddAngles( angle, 1800 );
|
||||
}
|
||||
}
|
||||
@ -1071,25 +1096,30 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
|
||||
case PAD_TRAPEZOID:
|
||||
{
|
||||
SHAPE_POLY_SET antipad; // The full antipad area
|
||||
|
||||
CPOLYGONS_LIST cbuffer;
|
||||
// We need a length to build the stubs of the thermal reliefs
|
||||
// the value is not very important. The pad bounding box gives a reasonable value
|
||||
EDA_RECT bbox = aPad.GetBoundingBox();
|
||||
int stub_len = std::max( bbox.GetWidth(), bbox.GetHeight() );
|
||||
|
||||
aPad.TransformShapeWithClearanceToPolygon( antipad, aThermalGap,
|
||||
aPad.TransformShapeWithClearanceToPolygon( cbuffer, aThermalGap,
|
||||
aCircleToSegmentsCount, aCorrectionFactor );
|
||||
|
||||
SHAPE_POLY_SET stub; // A basic stub ( a rectangle)
|
||||
SHAPE_POLY_SET stubs; // the full stubs shape
|
||||
SHAPE_POLY_SET thermalShape; // the holes in copper zone
|
||||
// We are using ClipperLib to substract stubs to clearance area (antipad area).
|
||||
ClipperLib::Path antipad; // The full antipad area
|
||||
ClipperLib::Path stub; // A basic stub ( a rectangle)
|
||||
ClipperLib::Paths stubs; // the full stubs shape
|
||||
ClipperLib::Paths thermalShape; // the holes in copper zone
|
||||
|
||||
// cbuffer is expected to contain only one polygon, which is
|
||||
// area of the pad + the thermal gap (the antipad)
|
||||
for( unsigned ii = 0; ii < cbuffer.GetCornersCount(); ii++ )
|
||||
antipad << ClipperLib::IntPoint( cbuffer.GetPos(ii).x, cbuffer.GetPos(ii).y );
|
||||
|
||||
// We now substract the stubs (connections to the copper zone)
|
||||
//ClipperLib::Clipper clip_engine;
|
||||
ClipperLib::Clipper clip_engine;
|
||||
// Prepare a clipping transform
|
||||
//clip_engine.AddPath( antipad, ClipperLib::ptSubject, true );
|
||||
clip_engine.AddPath( antipad, ClipperLib::ptSubject, true );
|
||||
|
||||
// Create stubs and add them to clipper engine
|
||||
wxPoint stubBuffer[4];
|
||||
@ -1102,17 +1132,16 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
stubBuffer[3] = stubBuffer[2];
|
||||
stubBuffer[3].y = copper_thickness.y/2;
|
||||
|
||||
stub.NewOutline();
|
||||
|
||||
for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
|
||||
{
|
||||
wxPoint cpos = stubBuffer[ii];
|
||||
RotatePoint( &cpos, aPad.GetOrientation() );
|
||||
cpos += PadShapePos;
|
||||
stub.Append( cpos.x, cpos.y );
|
||||
stub << ClipperLib::IntPoint( cpos.x, cpos.y );
|
||||
}
|
||||
|
||||
stubs.Append( stub );
|
||||
ClipperLib::Clipper stubs_engine;
|
||||
stubs_engine.AddPath( stub, ClipperLib::ptSubject, true );
|
||||
|
||||
stubBuffer[0].y = stub_len;
|
||||
stubBuffer[0].x = copper_thickness.x/2;
|
||||
@ -1122,24 +1151,27 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
stubBuffer[2].y = -stub_len;
|
||||
stubBuffer[3] = stubBuffer[2];
|
||||
stubBuffer[3].x = copper_thickness.x/2;
|
||||
|
||||
stub.RemoveAllContours();
|
||||
stub.NewOutline();
|
||||
stub.clear();
|
||||
|
||||
for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
|
||||
{
|
||||
wxPoint cpos = stubBuffer[ii];
|
||||
RotatePoint( &cpos, aPad.GetOrientation() );
|
||||
cpos += PadShapePos;
|
||||
stub.Append( cpos.x, cpos.y );
|
||||
stub << ClipperLib::IntPoint( cpos.x, cpos.y );
|
||||
}
|
||||
|
||||
stubs.Append( stub );
|
||||
stubs.Simplify();
|
||||
stubs_engine.AddPath( stub, ClipperLib::ptClip, true );
|
||||
|
||||
antipad.BooleanSubtract( stubs );
|
||||
aCornerBuffer.Append( antipad );
|
||||
// Build the full stubs shape:
|
||||
stubs_engine.Execute( ClipperLib::ctUnion, stubs );
|
||||
|
||||
// remove stubs to antipad area (i.e. add copper stubs)
|
||||
clip_engine.AddPath( stubs[0], ClipperLib::ptClip, true );
|
||||
clip_engine.Execute( ClipperLib::ctDifference, thermalShape );
|
||||
|
||||
// put thermal shapes (holes) to list:
|
||||
aCornerBuffer.ImportFrom( thermalShape );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2741,8 +2741,8 @@ wxString BOARD::GetNextModuleReferenceWithPrefix( const wxString& aPrefix,
|
||||
* return true if success, false if a contour is not valid
|
||||
*/
|
||||
#include <specctra.h>
|
||||
bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
|
||||
SHAPE_POLY_SET& aHoles,
|
||||
bool BOARD::GetBoardPolygonOutlines( CPOLYGONS_LIST& aOutlines,
|
||||
CPOLYGONS_LIST& aHoles,
|
||||
wxString* aErrorText )
|
||||
{
|
||||
// the SPECCTRA_DB function to extract board outlines:
|
||||
|
@ -57,7 +57,7 @@ class MSG_PANEL_ITEM;
|
||||
class NETLIST;
|
||||
class REPORTER;
|
||||
class RN_DATA;
|
||||
class SHAPE_POLY_SET;
|
||||
|
||||
|
||||
// non-owning container of item candidates when searching for items on the same track.
|
||||
typedef std::vector< TRACK* > TRACK_PTRS;
|
||||
@ -600,14 +600,15 @@ public:
|
||||
* from lines, arcs and circle items on edge cut layer
|
||||
* Any closed outline inside the main outline is a hole
|
||||
* All contours should be closed, i.e. have valid vertices to build a closed polygon
|
||||
* @param aPoly The SHAPE_POLY_SET to fill in with outlines/holes.
|
||||
* @param aOutlines The CPOLYGONS_LIST to fill in with main outlines.
|
||||
* @param aHoles The empty CPOLYGONS_LIST to fill in with holes, if any.
|
||||
* @param aErrorText = a wxString reference to display an error message
|
||||
* with the coordinate of the point which creates the error
|
||||
* (default = NULL , no message returned on error)
|
||||
* @return true if success, false if a contour is not valid
|
||||
*/
|
||||
bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
|
||||
SHAPE_POLY_SET& aHoles,
|
||||
bool GetBoardPolygonOutlines( CPOLYGONS_LIST& aOutlines,
|
||||
CPOLYGONS_LIST& aHoles,
|
||||
wxString* aErrorText = NULL );
|
||||
|
||||
/**
|
||||
@ -619,9 +620,9 @@ public:
|
||||
* or 3D viewer
|
||||
* the polygons are not merged.
|
||||
* @param aLayer = A copper layer, like B_Cu, etc.
|
||||
* @param aOutlines The SHAPE_POLY_SET to fill in with items outline.
|
||||
* @param aOutlines The CPOLYGONS_LIST to fill in with items outline.
|
||||
*/
|
||||
void ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines );
|
||||
void ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, CPOLYGONS_LIST& aOutlines );
|
||||
|
||||
/**
|
||||
* Function GetLayerID
|
||||
|
@ -231,7 +231,7 @@ public:
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const;
|
||||
|
@ -336,7 +336,7 @@ public:
|
||||
* default = false
|
||||
*/
|
||||
void TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor,
|
||||
@ -361,7 +361,7 @@ public:
|
||||
*/
|
||||
void TransformGraphicShapesWithClearanceToPolygonSet(
|
||||
LAYER_ID aLayer,
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor );
|
||||
|
@ -227,7 +227,7 @@ public:
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const;
|
||||
@ -324,7 +324,7 @@ public:
|
||||
* @param aCorrectionFactor = the correction to apply to circles radius to keep
|
||||
* the pad size when the circle is approximated by segments
|
||||
*/
|
||||
void BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void BuildPadShapePolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
wxSize aInflateValue, int aSegmentsPerCircle,
|
||||
double aCorrectionFactor ) const;
|
||||
|
||||
@ -339,7 +339,7 @@ public:
|
||||
* (used for round and oblong shapes only(16 to 32 is a good value)
|
||||
* @return false if the pad has no hole, true otherwise
|
||||
*/
|
||||
bool BuildPadDrillShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
bool BuildPadDrillShapePolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aInflateValue, int aSegmentsPerCircle ) const;
|
||||
|
||||
/**
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TransformBoundingBoxWithClearanceToPolygon(
|
||||
SHAPE_POLY_SET& aCornerBuffer,
|
||||
CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue ) const;
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ public:
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TransformShapeWithClearanceToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformShapeWithClearanceToPolygonSet( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const;
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
* clearance when the circle is approximated by segment bigger or equal
|
||||
* to the real clearance value (usually near from 1.0)
|
||||
*/
|
||||
void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aClearanceValue,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor ) const;
|
||||
|
@ -120,7 +120,7 @@ EDA_ITEM* ZONE_CONTAINER::Clone() const
|
||||
|
||||
bool ZONE_CONTAINER::UnFill()
|
||||
{
|
||||
bool change = ( !m_FilledPolysList.IsEmpty() ) ||
|
||||
bool change = ( m_FilledPolysList.GetCornersCount() > 0 ) ||
|
||||
( m_FillSegmList.size() > 0 );
|
||||
|
||||
m_FilledPolysList.RemoveAllContours();
|
||||
@ -228,7 +228,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
|
||||
if( displ_opts->m_DisplayZonesMode == 1 ) // Do not show filled areas
|
||||
return;
|
||||
|
||||
if( m_FilledPolysList.IsEmpty() ) // Nothing to draw
|
||||
if( m_FilledPolysList.GetCornersCount() == 0 ) // Nothing to draw
|
||||
return;
|
||||
|
||||
BOARD* brd = GetBoard();
|
||||
@ -253,57 +253,69 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
|
||||
|
||||
SetAlpha( &color, 150 );
|
||||
|
||||
CornersTypeBuffer.clear();
|
||||
CornersBuffer.clear();
|
||||
|
||||
for ( int ic = 0; ic < m_FilledPolysList.OutlineCount(); ic++ )
|
||||
// Draw all filled areas
|
||||
int imax = m_FilledPolysList.GetCornersCount() - 1;
|
||||
|
||||
for( int ic = 0; ic <= imax; ic++ )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( ic );
|
||||
const CPolyPt& corner = m_FilledPolysList.GetCorner( ic );
|
||||
wxPoint coord( corner.x + offset.x, corner.y + offset.y );
|
||||
CornersBuffer.push_back( coord );
|
||||
CornersTypeBuffer.push_back( (char) corner.m_flags );
|
||||
|
||||
CornersBuffer.clear();
|
||||
|
||||
wxPoint p0;
|
||||
|
||||
for( int j = 0; j < path.PointCount(); j++ )
|
||||
// the last corner of a filled area is found: draw it
|
||||
if( (corner.end_contour) || (ic == imax) )
|
||||
{
|
||||
const VECTOR2I& corner = path.CPoint( j );
|
||||
|
||||
wxPoint coord( corner.x + offset.x, corner.y + offset.y );
|
||||
|
||||
if( j == 0 )
|
||||
p0 = coord;
|
||||
|
||||
CornersBuffer.push_back( coord );
|
||||
}
|
||||
|
||||
CornersBuffer.push_back( p0 );
|
||||
|
||||
// Draw outlines:
|
||||
if( ( m_ZoneMinThickness > 1 ) || outline_mode )
|
||||
{
|
||||
int ilim = CornersBuffer.size() - 1;
|
||||
|
||||
for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
|
||||
/* Draw the current filled area: draw segments outline first
|
||||
* Curiously, draw segments outline first and after draw filled polygons
|
||||
* with outlines thickness = 0 is a faster than
|
||||
* just draw filled polygons but with outlines thickness = m_ZoneMinThickness
|
||||
* So DO NOT use draw filled polygons with outlines having a thickness > 0
|
||||
* Note: Extra segments ( added to joint holes with external outline) flagged by
|
||||
* m_flags != 0 are not drawn
|
||||
* Note not all polygon libraries provide a flag for these extra-segments, therefore
|
||||
* the m_flags member can be always 0
|
||||
*/
|
||||
{
|
||||
int x0 = CornersBuffer[is].x;
|
||||
int y0 = CornersBuffer[is].y;
|
||||
int x1 = CornersBuffer[ie].x;
|
||||
int y1 = CornersBuffer[ie].y;
|
||||
// Draw outlines:
|
||||
if( (m_ZoneMinThickness > 1) || outline_mode )
|
||||
{
|
||||
int ilim = CornersBuffer.size() - 1;
|
||||
|
||||
// Draw only basic outlines, not extra segments.
|
||||
if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
|
||||
GRCSegm( panel->GetClipBox(), DC,
|
||||
x0, y0, x1, y1,
|
||||
m_ZoneMinThickness, color );
|
||||
else
|
||||
GRFillCSegm( panel->GetClipBox(), DC,
|
||||
x0, y0, x1, y1,
|
||||
m_ZoneMinThickness, color );
|
||||
for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
|
||||
{
|
||||
int x0 = CornersBuffer[is].x;
|
||||
int y0 = CornersBuffer[is].y;
|
||||
int x1 = CornersBuffer[ie].x;
|
||||
int y1 = CornersBuffer[ie].y;
|
||||
|
||||
// Draw only basic outlines, not extra segments.
|
||||
if( CornersTypeBuffer[ie] == 0 )
|
||||
{
|
||||
if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
|
||||
GRCSegm( panel->GetClipBox(), DC,
|
||||
x0, y0, x1, y1,
|
||||
m_ZoneMinThickness, color );
|
||||
else
|
||||
GRFillCSegm( panel->GetClipBox(), DC,
|
||||
x0, y0, x1, y1,
|
||||
m_ZoneMinThickness, color );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw areas:
|
||||
if( m_FillMode == 0 && !outline_mode )
|
||||
GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
|
||||
true, 0, color, color );
|
||||
}
|
||||
}
|
||||
|
||||
// Draw areas:
|
||||
if( m_FillMode == 0 && !outline_mode )
|
||||
GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
|
||||
true, 0, color, color );
|
||||
CornersTypeBuffer.clear();
|
||||
CornersBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if( m_FillMode == 1 && !outline_mode ) // filled with segments
|
||||
@ -564,7 +576,26 @@ int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
|
||||
|
||||
bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
|
||||
{
|
||||
return m_FilledPolysList.Contains( VECTOR2I( aRefPos.x, aRefPos.y ) );
|
||||
unsigned indexstart = 0, indexend;
|
||||
bool inside = false;
|
||||
|
||||
for( indexend = 0; indexend < m_FilledPolysList.GetCornersCount(); indexend++ )
|
||||
{
|
||||
if( m_FilledPolysList.IsEndContour( indexend ) ) // end of a filled sub-area found
|
||||
{
|
||||
if( TestPointInsidePolygon( m_FilledPolysList, indexstart, indexend,
|
||||
aRefPos.x, aRefPos.y ) )
|
||||
{
|
||||
inside = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Prepare test of next area which starts after the current index end (if exists)
|
||||
indexstart = indexend + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
|
||||
@ -643,9 +674,9 @@ void ZONE_CONTAINER::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
||||
msg.Printf( wxT( "%d" ), (int) m_Poly->m_HatchLines.size() );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Hatch Lines" ), msg, BLUE ) );
|
||||
|
||||
if( !m_FilledPolysList.IsEmpty() )
|
||||
if( m_FilledPolysList.GetCornersCount() )
|
||||
{
|
||||
msg.Printf( wxT( "%d" ), (int) m_FilledPolysList.TotalVertices() );
|
||||
msg.Printf( wxT( "%d" ), (int) m_FilledPolysList.GetCornersCount() );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) );
|
||||
}
|
||||
}
|
||||
@ -663,7 +694,12 @@ void ZONE_CONTAINER::Move( const wxPoint& offset )
|
||||
|
||||
m_Poly->Hatch();
|
||||
|
||||
m_FilledPolysList.Move( VECTOR2I( offset.x, offset.y ) );
|
||||
/* move filled areas: */
|
||||
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
|
||||
{
|
||||
m_FilledPolysList.SetX( ic, m_FilledPolysList.GetX( ic ) + offset.x );
|
||||
m_FilledPolysList.SetY( ic, m_FilledPolysList.GetY( ic ) + offset.y );
|
||||
}
|
||||
|
||||
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
||||
{
|
||||
@ -710,8 +746,13 @@ void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
|
||||
m_Poly->Hatch();
|
||||
|
||||
/* rotate filled areas: */
|
||||
for( SHAPE_POLY_SET::ITERATOR ic = m_FilledPolysList.Iterate(); ic; ++ic )
|
||||
RotatePoint( &ic->x, &ic->y, centre.x, centre.y, angle );
|
||||
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
|
||||
{
|
||||
pos = m_FilledPolysList.GetPos( ic );
|
||||
RotatePoint( &pos, centre, angle );
|
||||
m_FilledPolysList.SetX( ic, pos.x );
|
||||
m_FilledPolysList.SetY( ic, pos.y );
|
||||
}
|
||||
|
||||
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
||||
{
|
||||
@ -738,10 +779,11 @@ void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
|
||||
|
||||
m_Poly->Hatch();
|
||||
|
||||
for( SHAPE_POLY_SET::ITERATOR ic = m_FilledPolysList.Iterate(); ic; ++ic )
|
||||
/* mirror filled areas: */
|
||||
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
|
||||
{
|
||||
int py = mirror_ref.y - ic->y;
|
||||
ic->y = py + mirror_ref.y;
|
||||
int py = mirror_ref.y - m_FilledPolysList.GetY( ic );
|
||||
m_FilledPolysList.SetY( ic, py + mirror_ref.y );
|
||||
}
|
||||
|
||||
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
||||
@ -854,4 +896,15 @@ wxString ZONE_CONTAINER::GetSelectMenuText() const
|
||||
GetChars( GetLayerName() ) );
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Copy polygons stored in aKiPolyList to m_FilledPolysList
|
||||
* The previous m_FilledPolysList contents is replaced.
|
||||
*/
|
||||
void ZONE_CONTAINER::CopyPolygonsFromClipperPathsToFilledPolysList(
|
||||
ClipperLib::Paths& aClipperPolyList )
|
||||
{
|
||||
m_FilledPolysList.RemoveAllContours();
|
||||
m_FilledPolysList.ImportFrom( aClipperPolyList );
|
||||
}
|
||||
|
@ -165,6 +165,18 @@ public:
|
||||
*/
|
||||
void TestForCopperIslandAndRemoveInsulatedIslands( BOARD* aPcb );
|
||||
|
||||
/**
|
||||
* Function CalculateSubAreaBoundaryBox
|
||||
* Calculates the bounding box of a a filled area ( list of CPolyPt )
|
||||
* use m_FilledPolysList as list of CPolyPt (that are the corners of one or more
|
||||
* polygons or filled areas )
|
||||
* @return an EDA_RECT as bounding box
|
||||
* @param aIndexStart = index of the first corner of a polygon (filled area)
|
||||
* in m_FilledPolysList
|
||||
* @param aIndexEnd = index of the last corner of a polygon in m_FilledPolysList
|
||||
*/
|
||||
EDA_RECT CalculateSubAreaBoundaryBox( int aIndexStart, int aIndexEnd );
|
||||
|
||||
/**
|
||||
* Function IsOnCopperLayer
|
||||
* @return true if this zone is on a copper layer, false if on a technical layer
|
||||
@ -259,7 +271,7 @@ public:
|
||||
* @param aCorrectionFactor = the correction to apply to arcs radius to roughly
|
||||
* keep arc radius when approximated by segments
|
||||
*/
|
||||
void TransformSolidAreasShapesToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformSolidAreasShapesToPolygonSet( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aCircleToSegmentsCount,
|
||||
double aCorrectionFactor );
|
||||
/**
|
||||
@ -283,7 +295,32 @@ public:
|
||||
* AddClearanceAreasPolygonsToPolysList() to add holes for pads and tracks
|
||||
* and other items not in net.
|
||||
*/
|
||||
bool BuildFilledSolidAreasPolygons( BOARD* aPcb, SHAPE_POLY_SET* aOutlineBuffer = NULL );
|
||||
bool BuildFilledSolidAreasPolygons( BOARD* aPcb, CPOLYGONS_LIST* aOutlineBuffer = NULL );
|
||||
|
||||
/**
|
||||
* Function CopyPolygonsFromKiPolygonListToFilledPolysList
|
||||
* Copy polygons stored in aKiPolyList to m_FilledPolysList
|
||||
* The previous m_FilledPolysList contents is replaced.
|
||||
* @param aKiPolyList = a KI_POLYGON_SET containing polygons.
|
||||
*/
|
||||
void CopyPolygonsFromKiPolygonListToFilledPolysList( KI_POLYGON_SET& aKiPolyList );
|
||||
|
||||
/**
|
||||
* Function CopyPolygonsFromClipperPathsToFilledPolysList
|
||||
* Copy polygons stored in aKiPolyList to m_FilledPolysList
|
||||
* The previous m_FilledPolysList contents is replaced.
|
||||
* @param aClipperPolyList = a ClipperLib::Paths containing polygons.
|
||||
*/
|
||||
void CopyPolygonsFromClipperPathsToFilledPolysList( ClipperLib::Paths& aClipperPolyList );
|
||||
|
||||
#if 0 //does not exist in rev 5741.
|
||||
/**
|
||||
* Function CopyPolygonsFromFilledPolysListToKiPolygonList
|
||||
* Copy polygons from m_FilledPolysList to aKiPolyList
|
||||
* @param aKiPolyList = a KI_POLYGON_SET to fill by polygons.
|
||||
*/
|
||||
void CopyPolygonsFromFilledPolysListToKiPolygonList( KI_POLYGON_SET& aKiPolyList );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Function AddClearanceAreasPolygonsToPolysList
|
||||
@ -315,7 +352,7 @@ public:
|
||||
* false to use aMinClearanceValue only
|
||||
* if both aMinClearanceValue = 0 and aUseNetClearance = false: create the zone outline polygon.
|
||||
*/
|
||||
void TransformOutlinesShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
||||
void TransformOutlinesShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
|
||||
int aMinClearanceValue,
|
||||
bool aUseNetClearance );
|
||||
/**
|
||||
@ -473,7 +510,7 @@ public:
|
||||
* returns a reference to the list of filled polygons.
|
||||
* @return Reference to the list of filled polygons.
|
||||
*/
|
||||
const SHAPE_POLY_SET& GetFilledPolysList() const
|
||||
const CPOLYGONS_LIST& GetFilledPolysList() const
|
||||
{
|
||||
return m_FilledPolysList;
|
||||
}
|
||||
@ -482,7 +519,7 @@ public:
|
||||
* Function AddFilledPolysList
|
||||
* sets the list of filled polygons.
|
||||
*/
|
||||
void AddFilledPolysList( SHAPE_POLY_SET& aPolysList )
|
||||
void AddFilledPolysList( CPOLYGONS_LIST& aPolysList )
|
||||
{
|
||||
m_FilledPolysList = aPolysList;
|
||||
}
|
||||
@ -511,7 +548,7 @@ public:
|
||||
|
||||
void AddPolygon( std::vector< wxPoint >& aPolygon );
|
||||
|
||||
void AddFilledPolygon( SHAPE_POLY_SET& aPolygon )
|
||||
void AddFilledPolygon( CPOLYGONS_LIST& aPolygon )
|
||||
{
|
||||
m_FilledPolysList.Append( aPolygon );
|
||||
}
|
||||
@ -547,7 +584,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
void buildFeatureHoleList( BOARD* aPcb, SHAPE_POLY_SET& aFeatures );
|
||||
void buildFeatureHoleList( BOARD* aPcb, CPOLYGONS_LIST& aFeatures );
|
||||
|
||||
CPolyLine* m_Poly; ///< Outline of the zone.
|
||||
CPolyLine* m_smoothedPoly; // Corner-smoothed version of m_Poly
|
||||
@ -615,7 +652,7 @@ private:
|
||||
* connecting "holes" with external main outline. In complex cases an outline
|
||||
* described by m_Poly can have many filled areas
|
||||
*/
|
||||
SHAPE_POLY_SET m_FilledPolysList;
|
||||
CPOLYGONS_LIST m_FilledPolysList;
|
||||
};
|
||||
|
||||
|
||||
|
@ -698,8 +698,11 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb )
|
||||
// board edges and cutouts
|
||||
static void export_vrml_board( MODEL_VRML& aModel, BOARD* pcb )
|
||||
{
|
||||
SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines
|
||||
SHAPE_POLY_SET allLayerHoles; // Contains through holes, calculated only once
|
||||
CPOLYGONS_LIST bufferPcbOutlines; // stores the board main outlines
|
||||
CPOLYGONS_LIST allLayerHoles; // Contains through holes, calculated only once
|
||||
|
||||
allLayerHoles.reserve( 20000 );
|
||||
|
||||
// Build a polygon from edge cut items
|
||||
wxString msg;
|
||||
|
||||
@ -712,28 +715,47 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* pcb )
|
||||
}
|
||||
|
||||
double scale = aModel.scale;
|
||||
|
||||
int i = 0;
|
||||
int seg;
|
||||
|
||||
for( int i = 0; i < bufferPcbOutlines.OutlineCount(); i++ )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& outline = bufferPcbOutlines.COutline( i );
|
||||
// deal with the solid outlines
|
||||
int nvert = bufferPcbOutlines.GetCornersCount();
|
||||
|
||||
while( i < nvert )
|
||||
{
|
||||
seg = aModel.board.NewContour();
|
||||
|
||||
for( int j = 0; j < outline.PointCount(); j++ )
|
||||
if( seg < 0 )
|
||||
{
|
||||
aModel.board.AddVertex( seg, (double)outline.CPoint(j).x * scale,
|
||||
-((double)outline.CPoint(j).y * scale ) );
|
||||
msg << wxT( "\n\n" ) <<
|
||||
_( "VRML Export Failed:\nCould not add outline to contours." );
|
||||
wxMessageBox( msg );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while( i < nvert )
|
||||
{
|
||||
if( bufferPcbOutlines[i].end_contour )
|
||||
break;
|
||||
|
||||
aModel.board.AddVertex( seg, bufferPcbOutlines[i].x * scale,
|
||||
-(bufferPcbOutlines[i].y * scale ) );
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
aModel.board.EnsureWinding( seg, false );
|
||||
++i;
|
||||
}
|
||||
|
||||
for( int i = 0; i < allLayerHoles.OutlineCount(); i++ )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& outline = allLayerHoles.COutline( i );
|
||||
// deal with the holes
|
||||
nvert = allLayerHoles.GetCornersCount();
|
||||
|
||||
i = 0;
|
||||
while( i < nvert )
|
||||
{
|
||||
seg = aModel.holes.NewContour();
|
||||
|
||||
if( seg < 0 )
|
||||
@ -745,14 +767,19 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* pcb )
|
||||
return;
|
||||
}
|
||||
|
||||
for( int j = 0; j < outline.PointCount(); j++ )
|
||||
while( i < nvert )
|
||||
{
|
||||
aModel.holes.AddVertex( seg, (double)outline.CPoint(j).x * scale,
|
||||
-((double)outline.CPoint(j).y * scale ) );
|
||||
if( allLayerHoles[i].end_contour )
|
||||
break;
|
||||
|
||||
aModel.holes.AddVertex( seg, allLayerHoles[i].x * scale,
|
||||
-( allLayerHoles[i].y * scale ) );
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
aModel.holes.EnsureWinding( seg, true );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -844,7 +871,9 @@ static void export_vrml_tracks( MODEL_VRML& aModel, BOARD* pcb )
|
||||
|
||||
static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb )
|
||||
{
|
||||
|
||||
double scale = aModel.scale;
|
||||
double x, y;
|
||||
|
||||
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
|
||||
{
|
||||
@ -861,23 +890,33 @@ static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb )
|
||||
zone->BuildFilledSolidAreasPolygons( aPcb );
|
||||
}
|
||||
|
||||
const SHAPE_POLY_SET& poly = zone->GetFilledPolysList();
|
||||
const CPOLYGONS_LIST& poly = zone->GetFilledPolysList();
|
||||
int nvert = poly.GetCornersCount();
|
||||
int i = 0;
|
||||
|
||||
for( int i = 0; i < poly.OutlineCount(); i++ )
|
||||
while( i < nvert )
|
||||
{
|
||||
const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
|
||||
|
||||
int seg = vl->NewContour();
|
||||
|
||||
for( int j = 0; j < outline.PointCount(); j++ )
|
||||
if( seg < 0 )
|
||||
break;
|
||||
|
||||
while( i < nvert )
|
||||
{
|
||||
if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * scale,
|
||||
-((double)outline.CPoint( j ).y * scale ) ) )
|
||||
x = poly.GetX(i) * scale;
|
||||
y = -(poly.GetY(i) * scale);
|
||||
|
||||
if( poly.IsEndContour(i) )
|
||||
break;
|
||||
|
||||
if( !vl->AddVertex( seg, x, y ) )
|
||||
throw( std::runtime_error( vl->GetError() ) );
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
vl->EnsureWinding( seg, false );
|
||||
vl->EnsureWinding( seg, false );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1617,22 +1617,22 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
|
||||
}
|
||||
|
||||
// Save the PolysList
|
||||
const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
|
||||
const CPOLYGONS_LIST& fv = aZone->GetFilledPolysList();
|
||||
newLine = 0;
|
||||
|
||||
if( !fv.IsEmpty() )
|
||||
if( fv.GetCornersCount() )
|
||||
{
|
||||
m_out->Print( aNestLevel+1, "(filled_polygon\n" );
|
||||
m_out->Print( aNestLevel+2, "(pts\n" );
|
||||
|
||||
for( SHAPE_POLY_SET::CONST_ITERATOR it = fv.CIterate(); it; ++it )
|
||||
for( unsigned it = 0; it < fv.GetCornersCount(); ++it )
|
||||
{
|
||||
if( newLine == 0 )
|
||||
m_out->Print( aNestLevel+3, "(xy %s %s)",
|
||||
FMT_IU( it->x ).c_str(), FMT_IU( it->y ).c_str() );
|
||||
FMT_IU( fv.GetX( it ) ).c_str(), FMT_IU( fv.GetY( it ) ).c_str() );
|
||||
else
|
||||
m_out->Print( 0, " (xy %s %s)",
|
||||
FMT_IU( it->x ) .c_str(), FMT_IU( it->y ).c_str() );
|
||||
FMT_IU( fv.GetX( it ) ).c_str(), FMT_IU( fv.GetY( it ) ).c_str() );
|
||||
|
||||
if( newLine < 4 )
|
||||
{
|
||||
@ -1644,14 +1644,14 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
|
||||
m_out->Print( 0, "\n" );
|
||||
}
|
||||
|
||||
if( it.IsEndContour() )
|
||||
if( fv.IsEndContour( it ) )
|
||||
{
|
||||
if( newLine != 0 )
|
||||
m_out->Print( 0, "\n" );
|
||||
|
||||
m_out->Print( aNestLevel+2, ")\n" );
|
||||
|
||||
if( !it.IsLastContour() )
|
||||
if( it+1 != fv.GetCornersCount() )
|
||||
{
|
||||
newLine = 0;
|
||||
m_out->Print( aNestLevel+1, ")\n" );
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user