Commit ef5f1b9e authored by jean-pierre charras's avatar jean-pierre charras

Start work on a better support of polygons in Kicad (code cleaning).

Some coding style policy fix.
parent 9259b21f
......@@ -305,7 +305,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List()
{
CPolyPt* endcorner = &polysList[ic];
if( begincorner->utility == 0 )
if( begincorner->m_utility == 0 )
{
// Draw only basic outlines, not extra segments
dummysegment.m_Start.x = begincorner->x;
......@@ -318,7 +318,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List()
if( (endcorner->end_contour) || (ic == imax) )
{
// the last corner of a filled area is found: draw it
if( endcorner->utility == 0 )
if( endcorner->m_utility == 0 )
{
// Draw only basic outlines, not extra segments
dummysegment.m_Start.x = endcorner->x;
......
......@@ -167,19 +167,19 @@ void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>
// Calculate the polygon with clearance and holes
// holes are linked to the main outline, so only one polygon should be created.
KPolygonSet polyset_zone_solid_areas;
std::vector<KPolyPoint> cornerslist;
KI_POLYGON_SET polyset_zone_solid_areas;
std::vector<KI_POLY_POINT> cornerslist;
unsigned ic = 0;
unsigned corners_count = zoneOutines.size();
while( ic < corners_count )
{
cornerslist.clear();
KPolygon poly;
KI_POLYGON poly;
{
for( ; ic < corners_count; ic++ )
{
CPolyPt* corner = &zoneOutines[ic];
cornerslist.push_back( KPolyPoint( corner->x, corner->y ) );
cornerslist.push_back( KI_POLY_POINT( corner->x, corner->y ) );
if( corner->end_contour )
{
ic++;
......@@ -197,12 +197,12 @@ void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>
// Put the resultng polygon in buffer
for( unsigned ii = 0; ii < polyset_zone_solid_areas.size(); ii++ )
{
KPolygon& poly = polyset_zone_solid_areas[ii];
KI_POLYGON& poly = polyset_zone_solid_areas[ii];
CPolyPt corner( 0, 0, false );
for( unsigned jj = 0; jj < poly.size(); jj++ )
{
KPolyPoint point = *(poly.begin() + jj);
KI_POLY_POINT point = *(poly.begin() + jj);
corner.x = point.x();
corner.y = point.y();
corner.end_contour = false;
......
......@@ -210,7 +210,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const
{
seg_start = GetCornerPosition( ic ) + offset;
if( m_Poly->corner[ic].end_contour == false && ic < GetNumCorners() - 1 )
if( m_Poly->m_CornersList[ic].end_contour == false && ic < GetNumCorners() - 1 )
{
seg_end = GetCornerPosition( ic + 1 ) + offset;
}
......@@ -306,7 +306,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
CornersBuffer.push_back( coord );
CornersTypeBuffer.push_back( (char) corner->utility );
CornersTypeBuffer.push_back( (char) corner->m_utility );
if( (corner->end_contour) || (ic == imax) ) // the last corner of a filled area is found: draw it
{
......@@ -432,13 +432,13 @@ void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, in
int yi = GetCornerPosition( ic ).y;
int xf, yf;
if( m_Poly->corner[ic].end_contour == false && ic < icmax )
if( m_Poly->m_CornersList[ic].end_contour == false && ic < icmax )
{
is_close_segment = false;
xf = GetCornerPosition( ic + 1 ).x;
yf = GetCornerPosition( ic + 1 ).y;
if( (m_Poly->corner[ic + 1].end_contour) || (ic == icmax - 1) )
if( (m_Poly->m_CornersList[ic + 1].end_contour) || (ic == icmax - 1) )
current_gr_mode = GR_XOR;
else
current_gr_mode = draw_mode;
......@@ -507,12 +507,12 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;
wxPoint delta;
unsigned lim = m_Poly->corner.size();
unsigned lim = m_Poly->m_CornersList.size();
for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
{
delta.x = refPos.x - m_Poly->corner[item_pos].x;
delta.y = refPos.y - m_Poly->corner[item_pos].y;
delta.x = refPos.x - m_Poly->m_CornersList[item_pos].x;
delta.y = refPos.y - m_Poly->m_CornersList[item_pos].y;
// Calculate a distance:
int dist = MAX( abs( delta.x ), abs( delta.y ) );
......@@ -530,7 +530,7 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
{
unsigned lim = m_Poly->corner.size();
unsigned lim = m_Poly->m_CornersList.size();
m_CornerSelection = -1; // Set to not found
......@@ -547,7 +547,7 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
* the last segment of the current outline starts at current corner, and ends
* at the first corner of the outline
*/
if( m_Poly->corner[item_pos].end_contour || end_segm >= lim )
if( m_Poly->m_CornersList[item_pos].end_contour || end_segm >= lim )
{
unsigned tmp = first_corner_pos;
first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline
......@@ -557,10 +557,10 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
/* test the dist between segment and ref point */
int dist = (int) GetPointToLineSegmentDistance( refPos.x,
refPos.y,
m_Poly->corner[item_pos].x,
m_Poly->corner[item_pos].y,
m_Poly->corner[end_segm].x,
m_Poly->corner[end_segm].y );
m_Poly->m_CornersList[item_pos].x,
m_Poly->m_CornersList[item_pos].y,
m_Poly->m_CornersList[end_segm].x,
m_Poly->m_CornersList[end_segm].y );
if( dist < min_dist )
{
......@@ -703,7 +703,7 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame )
msg = board->GetLayerName( m_Layer );
frame->AppendMsgPanel( _( "Layer" ), msg, BROWN );
msg.Printf( wxT( "%d" ), (int) m_Poly->corner.size() );
msg.Printf( wxT( "%d" ), (int) m_Poly->m_CornersList.size() );
frame->AppendMsgPanel( _( "Corners" ), msg, BLUE );
if( m_FillMode )
......@@ -730,7 +730,7 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame )
void ZONE_CONTAINER::Move( const wxPoint& offset )
{
/* move outlines */
for( unsigned ii = 0; ii < m_Poly->corner.size(); ii++ )
for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
{
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
}
......@@ -761,7 +761,7 @@ void ZONE_CONTAINER::MoveEdge( const wxPoint& offset )
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
// Move the end point of the selected edge:
if( m_Poly->corner[ii].end_contour || ii == GetNumCorners() - 1 )
if( m_Poly->m_CornersList[ii].end_contour || ii == GetNumCorners() - 1 )
{
int icont = m_Poly->GetContour( ii );
ii = m_Poly->GetContourStart( icont );
......@@ -781,13 +781,13 @@ void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
{
wxPoint pos;
for( unsigned ii = 0; ii < m_Poly->corner.size(); ii++ )
for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
{
pos.x = m_Poly->corner[ii].x;
pos.y = m_Poly->corner[ii].y;
pos.x = m_Poly->m_CornersList[ii].x;
pos.y = m_Poly->m_CornersList[ii].y;
RotatePoint( &pos, centre, angle );
m_Poly->corner[ii].x = pos.x;
m_Poly->corner[ii].y = pos.y;
m_Poly->m_CornersList[ii].x = pos.x;
m_Poly->m_CornersList[ii].y = pos.y;
}
m_Poly->Hatch();
......@@ -820,11 +820,11 @@ void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
{
for( unsigned ii = 0; ii < m_Poly->corner.size(); ii++ )
for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
{
m_Poly->corner[ii].y -= mirror_ref.y;
NEGATE( m_Poly->corner[ii].y );
m_Poly->corner[ii].y += mirror_ref.y;
m_Poly->m_CornersList[ii].y -= mirror_ref.y;
NEGATE( m_Poly->m_CornersList[ii].y );
m_Poly->m_CornersList[ii].y += mirror_ref.y;
}
m_Poly->Hatch();
......
......@@ -1059,7 +1059,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
m_out->Print( 0, ")\n" );
const std::vector< CPolyPt >& cv = aZone->m_Poly->corner;
const std::vector< CPolyPt >& cv = aZone->m_Poly->m_CornersList;
int newLine = 0;
if( cv.size() )
......
......@@ -3609,7 +3609,7 @@ void LEGACY_PLUGIN::saveZONE_CONTAINER( const ZONE_CONTAINER* me ) const
typedef std::vector< CPolyPt > CPOLY_PTS;
// Save the corner list
const CPOLY_PTS& cv = me->m_Poly->corner;
const CPOLY_PTS& cv = me->m_Poly->m_CornersList;
for( CPOLY_PTS::const_iterator it = cv.begin(); it != cv.end(); ++it )
{
fprintf( m_fp, "ZCorner %s %d\n",
......@@ -3628,7 +3628,7 @@ void LEGACY_PLUGIN::saveZONE_CONTAINER( const ZONE_CONTAINER* me ) const
fprintf( m_fp, "%s %d %d\n",
fmtBIUPair( it->x, it->y ).c_str(),
it->end_contour,
it->utility );
it->m_utility );
}
fprintf( m_fp, "$endPOLYSCORNERS\n" );
......
......@@ -12,10 +12,55 @@
namespace bpl = boost::polygon; // bpl = boost polygon library
using namespace bpl::operators; // +, -, =, ...
// Definitions needed by boost::polygon
typedef int coordinate_type;
typedef bpl::polygon_data<int> KPolygon;
typedef std::vector<KPolygon> KPolygonSet;
/**
* KI_POLYGON defines a single polygon ( boost::polygon_data type.
* When holes are created in a KPolygon, they are
* linked to main outline by overlapping segments,
* so there is always one polygon and one list of corners
* coordinates are int
*/
typedef bpl::polygon_data<int> KI_POLYGON;
/**
* KI_POLYGON_SET defines a set of single KI_POLYGON.
* A KI_POLYGON_SET is used to store a set of polygons
* when performing operations between 2 polygons
* or 2 sets of polygons
* The result of operations like and, xor... between 2 polygons
* is always stored in a KI_POLYGON_SET, because these operations
* can create many polygons
*/
typedef std::vector<KI_POLYGON> KI_POLYGON_SET;
/**
* KI_POLY_POINT defines a point for boost::polygon.
* KI_POLY_POINT store x and y coordinates (int)
*/
typedef bpl::point_data<int> KI_POLY_POINT;
/**
* KI_POLYGON_WITH_HOLES defines a single polygon with holes
* When holes are created in a KI_POLYGON_WITH_HOLES, they are
* stored as separate single polygons,
* KI_POLYGON_WITH_HOLES store always one polygon for the external outline
* and one list of polygons (holes) which can be empty
*/
typedef bpl::polygon_with_holes_data<int> KI_POLYGON_WITH_HOLES;
/**
* KI_POLYGON_WITH_HOLES_SET defines a set of KI_POLYGON_WITH_HOLES.
* A KI_POLYGON_WITH_HOLES_SET is used to store a set of polygons with holes
* when performing operations between 2 polygons
* or 2 sets of polygons with holes
* The result of operations like and, xor... between 2 polygons with holes
* is always stored in a KI_POLYGON_WITH_HOLES_SET, because these operations
* can create many separate polygons with holespolygons
*/
typedef std::vector<KI_POLYGON_WITH_HOLES> KI_POLYGON_WITH_HOLES_SET;
typedef bpl::point_data<int> KPolyPoint;
#endif // #ifndef _POLYGONS_DEFS_H_
......@@ -1178,16 +1178,16 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
mainPolygon->layer_id = layerIds[ kicadLayer2pcb[ item->GetLayer() ] ];
int count = item->m_Poly->corner.size();
int count = item->m_Poly->m_CornersList.size();
int ndx = 0; // used in 2 for() loops below
for( ; ndx<count; ++ndx )
{
wxPoint point( item->m_Poly->corner[ndx].x,
item->m_Poly->corner[ndx].y );
wxPoint point( item->m_Poly->m_CornersList[ndx].x,
item->m_Poly->m_CornersList[ndx].y );
mainPolygon->AppendPoint( mapPt(point) );
// this was the end of the main polygon
if( item->m_Poly->corner[ndx].end_contour )
if( item->m_Poly->m_CornersList[ndx].end_contour )
break;
}
......@@ -1197,7 +1197,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
// handle the cutouts
for( ++ndx; ndx<count; ++ndx )
{
if( item->m_Poly->corner[ndx-1].end_contour )
if( item->m_Poly->m_CornersList[ndx-1].end_contour )
{
window = new WINDOW( plane );
plane->AddWindow( window );
......@@ -1211,8 +1211,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
wxASSERT( window );
wxASSERT( cutout );
wxPoint point(item->m_Poly->corner[ndx].x,
item->m_Poly->corner[ndx].y );
wxPoint point(item->m_Poly->m_CornersList[ndx].x,
item->m_Poly->m_CornersList[ndx].y );
cutout->AppendPoint( mapPt(point) );
}
}
......@@ -1253,16 +1253,16 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
mainPolygon->layer_id = layerIds[ kicadLayer2pcb[ item->GetLayer() ] ];
int count = item->m_Poly->corner.size();
int count = item->m_Poly->m_CornersList.size();
int ndx = 0; // used in 2 for() loops below
for( ; ndx<count; ++ndx )
{
wxPoint point( item->m_Poly->corner[ndx].x,
item->m_Poly->corner[ndx].y );
wxPoint point( item->m_Poly->m_CornersList[ndx].x,
item->m_Poly->m_CornersList[ndx].y );
mainPolygon->AppendPoint( mapPt(point) );
// this was the end of the main polygon
if( item->m_Poly->corner[ndx].end_contour )
if( item->m_Poly->m_CornersList[ndx].end_contour )
break;
}
......@@ -1272,7 +1272,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
// handle the cutouts
for( ++ndx; ndx<count; ++ndx )
{
if( item->m_Poly->corner[ndx-1].end_contour )
if( item->m_Poly->m_CornersList[ndx-1].end_contour )
{
window = new WINDOW( keepout );
keepout->AddWindow( window );
......@@ -1286,8 +1286,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR )
wxASSERT( window );
wxASSERT( cutout );
wxPoint point(item->m_Poly->corner[ndx].x,
item->m_Poly->corner[ndx].y );
wxPoint point(item->m_Poly->m_CornersList[ndx].x,
item->m_Poly->m_CornersList[ndx].y );
cutout->AppendPoint( mapPt(point) );
}
}
......
......@@ -188,7 +188,7 @@ int ZONE_CONTAINER::Fill_Zone_Areas_With_Segments()
x_coordinates.clear();
for( ics = istart, ice = iend; ics <= iend; ice = ics, ics++ )
{
if ( m_FilledPolysList[ice].utility )
if ( m_FilledPolysList[ice].m_utility )
continue;
int seg_startX = m_FilledPolysList[ics].x;
int seg_startY = m_FilledPolysList[ics].y;
......
......@@ -81,14 +81,14 @@ extern void CreateThermalReliefPadPolygon( std::vector<CPolyPt>& aCornerBuffer,
int aThermalRot );
// Local Functions: helper function to calculate solid areas
static void AddPolygonCornersToKPolygonList( std::vector <CPolyPt>& aCornersBuffer,
KPolygonSet& aKPolyList );
static void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,
KI_POLYGON_SET& aKiPolyList );
static int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* aZone,
KPolygonSet& aKPolyList );
static int CopyPolygonsFromKiPolygonListToFilledPolysList( ZONE_CONTAINER* aZone,
KI_POLYGON_SET& aKiPolyList );
static int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* aZone,
KPolygonSet& aKPolyList );
static int CopyPolygonsFromFilledPolysListToKiPolygonList( ZONE_CONTAINER* aZone,
KI_POLYGON_SET& aKiPolyList );
// Local Variables:
......@@ -148,8 +148,8 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
*/
s_Correction = 1.0 / cos( 3.14159265 / s_CircleToSegmentsCount );
// This KPolygonSet is the area(s) to fill, with m_ZoneMinThickness/2
KPolygonSet polyset_zone_solid_areas;
// This KI_POLYGON_SET is the area(s) to fill, with m_ZoneMinThickness/2
KI_POLYGON_SET polyset_zone_solid_areas;
int margin = m_ZoneMinThickness / 2;
/* First, creates the main polygon (i.e. the filled area using only one outline)
......@@ -160,7 +160,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
* the main polygon is stored in polyset_zone_solid_areas
*/
CopyPolygonsFromFilledPolysListTotKPolygonList( this, polyset_zone_solid_areas );
CopyPolygonsFromFilledPolysListToKiPolygonList( this, polyset_zone_solid_areas );
polyset_zone_solid_areas -= margin;
if( polyset_zone_solid_areas.size() == 0 )
......@@ -431,15 +431,15 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
// Calculate now actual solid areas
if( cornerBufferPolysToSubstract.size() > 0 )
{
KPolygonSet polyset_holes;
AddPolygonCornersToKPolygonList( cornerBufferPolysToSubstract, polyset_holes );
KI_POLYGON_SET polyset_holes;
AddPolygonCornersToKiPolygonList( cornerBufferPolysToSubstract, polyset_holes );
// Remove holes from initial area.:
polyset_zone_solid_areas -= polyset_holes;
}
// put solid areas in m_FilledPolysList:
m_FilledPolysList.clear();
CopyPolygonsFromKPolygonListToFilledPolysList( this, polyset_zone_solid_areas );
CopyPolygonsFromKiPolygonListToFilledPolysList( this, polyset_zone_solid_areas );
// Remove insulated islands:
if( GetNet() > 0 )
......@@ -455,13 +455,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
// remove copper areas
if( cornerBufferPolysToSubstract.size() )
{
KPolygonSet polyset_holes;
AddPolygonCornersToKPolygonList( cornerBufferPolysToSubstract, polyset_holes );
KI_POLYGON_SET polyset_holes;
AddPolygonCornersToKiPolygonList( cornerBufferPolysToSubstract, polyset_holes );
polyset_zone_solid_areas -= polyset_holes;
// put these areas in m_FilledPolysList
m_FilledPolysList.clear();
CopyPolygonsFromKPolygonListToFilledPolysList( this, polyset_zone_solid_areas );
CopyPolygonsFromKiPolygonListToFilledPolysList( this, polyset_zone_solid_areas );
if( GetNet() > 0 )
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
......@@ -470,12 +470,12 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
cornerBufferPolysToSubstract.clear();
}
void AddPolygonCornersToKPolygonList( std::vector <CPolyPt>& aCornersBuffer,
KPolygonSet& aKPolyList )
void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,
KI_POLYGON_SET& aKiPolyList )
{
unsigned ii;
std::vector<KPolyPoint> cornerslist;
std::vector<KI_POLY_POINT> cornerslist;
int polycount = 0;
......@@ -485,42 +485,42 @@ void AddPolygonCornersToKPolygonList( std::vector <CPolyPt>& aCornersBuffer,
polycount++;
}
aKPolyList.reserve( polycount );
aKiPolyList.reserve( polycount );
for( unsigned icnt = 0; icnt < aCornersBuffer.size(); )
{
KPolygon poly;
KI_POLYGON poly;
cornerslist.clear();
for( ii = icnt; ii < aCornersBuffer.size(); ii++ )
{
cornerslist.push_back( KPolyPoint( aCornersBuffer[ii].x, aCornersBuffer[ii].y ) );
cornerslist.push_back( KI_POLY_POINT( aCornersBuffer[ii].x, aCornersBuffer[ii].y ) );
if( aCornersBuffer[ii].end_contour )
break;
}
bpl::set_points( poly, cornerslist.begin(), cornerslist.end() );
aKPolyList.push_back( poly );
aKiPolyList.push_back( poly );
icnt = ii + 1;
}
}
int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* aZone,
KPolygonSet& aKPolyList )
int CopyPolygonsFromKiPolygonListToFilledPolysList( ZONE_CONTAINER* aZone,
KI_POLYGON_SET& aKiPolyList )
{
int count = 0;
std::vector<CPolyPt> polysList;
for( unsigned ii = 0; ii < aKPolyList.size(); ii++ )
for( unsigned ii = 0; ii < aKiPolyList.size(); ii++ )
{
KPolygon& poly = aKPolyList[ii];
KI_POLYGON& poly = aKiPolyList[ii];
CPolyPt corner( 0, 0, false );
for( unsigned jj = 0; jj < poly.size(); jj++ )
{
KPolyPoint point = *(poly.begin() + jj);
KI_POLY_POINT point = *(poly.begin() + jj);
corner.x = point.x();
corner.y = point.y();
corner.end_contour = false;
......@@ -542,10 +542,10 @@ int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* aZone,
}
int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* aZone,
KPolygonSet& aKPolyList )
int CopyPolygonsFromFilledPolysListToKiPolygonList( ZONE_CONTAINER* aZone,
KI_POLYGON_SET& aKiPolyList )
{
std::vector<CPolyPt> polysList = aZone->GetFilledPolysList();
const std::vector<CPolyPt>& polysList = aZone->GetFilledPolysList();
unsigned corners_count = polysList.size();
int count = 0;
unsigned ic = 0;
......@@ -554,35 +554,32 @@ int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* aZone,
for( unsigned ii = 0; ii < corners_count; ii++ )
{
CPolyPt* corner = &polysList[ic];
const CPolyPt& corner = polysList[ii];
if( corner->end_contour )
if( corner.end_contour )
polycount++;
}
aKPolyList.reserve( polycount );
std::vector<KPolyPoint> cornerslist;
aKiPolyList.reserve( polycount );
std::vector<KI_POLY_POINT> cornerslist;
while( ic < corners_count )
{
cornerslist.clear();
KPolygon poly;
KI_POLYGON poly;
{
for( ; ic < corners_count; ic++ )
while( ic < corners_count )
{
CPolyPt* corner = &polysList[ic];
cornerslist.push_back( KPolyPoint( corner->x, corner->y ) );
const CPolyPt& corner = polysList[ic++];
cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) );
count++;
if( corner->end_contour )
{
ic++;
if( corner.end_contour )
break;
}
}
bpl::set_points( poly, cornerslist.begin(), cornerslist.end() );
aKPolyList.push_back( poly );
aKiPolyList.push_back( poly );
}
}
......
......@@ -115,7 +115,7 @@ bool ZONE_CONTAINER::IsSame( const ZONE_CONTAINER& aZoneToCompare )
wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
wxASSERT( aZoneToCompare.m_Poly );
if( m_Poly->corner != aZoneToCompare.m_Poly->corner ) // Compare vector
if( m_Poly->m_CornersList != aZoneToCompare.m_Poly->m_CornersList ) // Compare vector
return false;
return true;
......
......@@ -31,6 +31,7 @@
*/
#include <fctsys.h>
#include <polygons_defs.h>
#include <common.h>
#include <confirm.h>
#include <class_undoredo_container.h>
......@@ -142,7 +143,7 @@ int BOARD::TestAreaPolygon( ZONE_CONTAINER* CurrArea )
// first, check for sides intersecting other sides, especially arcs
bool bInt = false;
bool bArcInt = false;
int n_cont = p->GetNumContours();
int n_cont = p->GetContoursCount();
// make bounding rect for each contour
std::vector<CRect> cr;
......@@ -550,7 +551,7 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
continue;
// test for intersecting segments
for( int icont1 = 0; icont1<poly1->GetNumContours(); icont1++ )
for( int icont1 = 0; icont1<poly1->GetContoursCount(); icont1++ )
{
int is1 = poly1->GetContourStart( icont1 );
int ie1 = poly1->GetContourEnd( icont1 );
......@@ -574,7 +575,7 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
style1 = poly1->GetSideStyle( ic1 );
for( int icont2 = 0; icont2 < poly2->GetNumContours(); icont2++ )
for( int icont2 = 0; icont2 < poly2->GetContoursCount(); icont2++ )
{
int is2 = poly2->GetContourStart( icont2 );
int ie2 = poly2->GetContourEnd( icont2 );
......@@ -668,7 +669,7 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
bool bInt = false;
bool bArcInt = false;
for( int icont1 = 0; icont1<poly1->GetNumContours(); icont1++ )
for( int icont1 = 0; icont1<poly1->GetContoursCount(); icont1++ )
{
int is1 = poly1->GetContourStart( icont1 );
int ie1 = poly1->GetContourEnd( icont1 );
......@@ -692,7 +693,7 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
style1 = poly1->GetSideStyle( ic1 );
for( int icont2 = 0; icont2<poly2->GetNumContours(); icont2++ )
for( int icont2 = 0; icont2<poly2->GetContoursCount(); icont2++ )
{
int is2 = poly2->GetContourStart( icont2 );
int ie2 = poly2->GetContourEnd( icont2 );
......@@ -778,145 +779,139 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
return 1;
}
/**
* Function CopyPolysListToKiPolygonWithHole
* converts the outline contours aPolysList to a KI_POLYGON_WITH_HOLES
*
* @param aPolysList = the list of corners of contours
* @param aPolygoneWithHole = a KI_POLYGON_WITH_HOLES to populate
*/
void CopyPolysListToKiPolygonWithHole( const std::vector<CPolyPt>& aPolysList,
KI_POLYGON_WITH_HOLES& aPolygoneWithHole )
{
unsigned corners_count = aPolysList.size();
std::vector<KI_POLY_POINT> cornerslist;
KI_POLYGON poly;
// Enter main outline: this is the first contour
unsigned ic = 0;
while( ic < corners_count )
{
const CPolyPt& corner = aPolysList[ic++];
cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) );
if( corner.end_contour )
break;
}
aPolygoneWithHole.set( cornerslist.begin(), cornerslist.end() );
// Enter holes: they are next contours (when exist)
if( ic < corners_count )
{
KI_POLYGON_SET holePolyList;
while( ic < corners_count )
{
cornerslist.clear();
while( ic < corners_count )
{
const CPolyPt& corner = aPolysList[ic++];
cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) );
if( corner.end_contour )
break;
}
bpl::set_points( poly, cornerslist.begin(), cornerslist.end() );
holePolyList.push_back( poly );
}
aPolygoneWithHole.set_holes( holePolyList.begin(), holePolyList.end() );
}
}
/**
* Function CombineAreas
* If possible, combine 2 copper areas
* Merge 2 copper areas (which are expected intersecting)
* @param aDeletedList = a PICKED_ITEMS_LIST * where to store deleted areas (useful in undo
* commands can be NULL
* @param area_ref = tje main area (zone)
* @param area_ref = the main area (zone)
* @param area_to_combine = the zone that can be merged with area_ref
* area_ref must be BEFORE area_to_combine
* area_to_combine will be deleted, if areas are combined
* @return : 0 if no intersection
* 1 if intersection
* 2 if arcs intersect
* 2 if arcs intersect (Currently not supported)
*/
int BOARD::CombineAreas( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_ref,
ZONE_CONTAINER* area_to_combine )
{
if( area_ref == area_to_combine )
{
wxASSERT( 0 );
return 0;
}
// polygons intersect, combine them
std::vector<CArc> arc_array1;
std::vector<CArc> arc_array2;
bool keep_area_to_combine = false;
Bool_Engine* booleng = new Bool_Engine();
ArmBoolEng( booleng );
area_ref->m_Poly->AddPolygonsToBoolEng( booleng, GROUP_A, -1, -1 );
area_to_combine->m_Poly->AddPolygonsToBoolEng( booleng, GROUP_B, -1, -1 );
booleng->Do_Operation( BOOL_OR );
// create area with external contour: Recreate only area edges, NOT holes
if( booleng->StartPolygonGet() )
{
if( booleng->GetPolygonPointEdgeType() == KB_INSIDE_EDGE )
{
DisplayError( NULL, wxT( "BOARD::CombineAreas() error: unexpected hole descriptor" ) );
}
// std::vector<CArc> arc_array1;
// std::vector<CArc> arc_array2;
bool keep_area_to_combine = false; // TODO test if areas intersect
KI_POLYGON_WITH_HOLES areaRefPoly;
KI_POLYGON_WITH_HOLES areaToMergePoly;
CopyPolysListToKiPolygonWithHole( area_ref->m_Poly->m_CornersList, areaRefPoly );
CopyPolysListToKiPolygonWithHole( area_to_combine->m_Poly->m_CornersList, areaToMergePoly );
KI_POLYGON_WITH_HOLES_SET mergedOutlines;
mergedOutlines.push_back( areaRefPoly );
mergedOutlines += areaToMergePoly;
// We should have only one polygon with holes in mergedOutlines
// or the 2 initial outlines do not intersect
if( mergedOutlines.size() > 1 )
return 0;
areaRefPoly = mergedOutlines[0];
area_ref->m_Poly->RemoveAllContours();
// foreach point in the polygon
bool first = true;
while( booleng->PolygonHasMorePoints() )
{
int x = (int) booleng->GetPolygonXPoint();
int y = (int) booleng->GetPolygonYPoint();
if( first )
{
first = false;
area_ref->m_Poly->Start( area_ref->GetLayer(
), x, y, area_ref->m_Poly->GetHatchStyle() );
}
else
{
area_ref->m_Poly->AppendCorner( x, y );
}
}
booleng->EndPolygonGet();
area_ref->m_Poly->Close();
}
// Recreate the area_to_combine if a second polygon exists
// if not exists , the first poly contains the 2 initial polygons
#if 0 // TestAreaIntersection must be called before combine areas, so
// 2 intersecting areas are expected, and only one outline contour after combining areas
else
{
area_to_combine->m_Poly->RemoveAllContours();
keep_area_to_combine = true;
// create area with external contour: Recreate only area edges, NOT holes (todo..)
{
// foreach point in the polygon
bool first = true;
while( booleng->PolygonHasMorePoints() )
{
int x = booleng->GetPolygonXPoint();
int y = booleng->GetPolygonYPoint();
if( first )
{
first = false;
area_to_combine->m_Poly->Start( area_ref->GetLayer(), x, y,
KI_POLYGON_WITH_HOLES::iterator_type corner = areaRefPoly.begin();
// create area with external contour: Recreate only area edges, NOT holes
area_ref->m_Poly->Start( area_ref->GetLayer(), corner->x(), corner->y(),
area_ref->m_Poly->GetHatchStyle() );
}
else
while( ++corner != areaRefPoly.end() )
{
area_to_combine->m_Poly->AppendCorner( x, y );
}
area_ref->m_Poly->AppendCorner( corner->x(), corner->y() );
}
booleng->EndPolygonGet();
area_to_combine->m_Poly->Close();
}
}
#endif
// add holes
bool show_error = true;
area_ref->m_Poly->Close();
while( booleng->StartPolygonGet() )
// add holes (set of polygons)
KI_POLYGON_WITH_HOLES::iterator_holes_type hole = areaRefPoly.begin_holes();
while( hole != areaRefPoly.end_holes() )
{
// we expect all vertex are holes inside the main outline
if( booleng->GetPolygonPointEdgeType() != KB_INSIDE_EDGE )
{
if( show_error ) // show this error only once, if happens
DisplayError( NULL,
wxT( "BOARD::CombineAreas() error: unexpected outside contour descriptor" ) );
show_error = false;
continue;
}
while( booleng->PolygonHasMorePoints() )
KI_POLYGON::iterator_type hole_corner = hole->begin();
// create area with external contour: Recreate only area edges, NOT holes
while( hole_corner != hole->end() )
{
int x = (int) booleng->GetPolygonXPoint();
int y = (int) booleng->GetPolygonYPoint();
area_ref->m_Poly->AppendCorner( x, y );
area_ref->m_Poly->AppendCorner( hole_corner->x(), hole_corner->y() );
hole_corner++;
}
area_ref->m_Poly->Close();
booleng->EndPolygonGet();
hole++;
}
if( !keep_area_to_combine )
RemoveArea( aDeletedList, area_to_combine );
area_ref->utility = 1;
area_ref->m_Poly->RestoreArcs( &arc_array1 );
area_ref->m_Poly->RestoreArcs( &arc_array2 );
// area_ref->m_Poly->RestoreArcs( &arc_array1 );
// area_ref->m_Poly->RestoreArcs( &arc_array2 );
area_ref->m_Poly->Hatch();
delete booleng;
return 1;
}
......@@ -1024,7 +1019,7 @@ int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_E
}
// now test spacing between areas
for( int icont = 0; icont < refSmoothedPoly->GetNumContours(); icont++ )
for( int icont = 0; icont < refSmoothedPoly->GetContoursCount(); icont++ )
{
int ic_start = refSmoothedPoly->GetContourStart( icont );
int ic_end = refSmoothedPoly->GetContourEnd( icont );
......@@ -1048,7 +1043,7 @@ int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_E
int astyle = refSmoothedPoly->GetSideStyle( ic );
for( int icont2 = 0; icont2 < testSmoothedPoly->GetNumContours(); icont2++ )
for( int icont2 = 0; icont2 < testSmoothedPoly->GetContoursCount(); icont2++ )
{
int ic_start2 = testSmoothedPoly->GetContourStart( icont2 );
int ic_end2 = testSmoothedPoly->GetContourEnd( icont2 );
......@@ -1128,7 +1123,7 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex )
wxPoint end;
// Search the end point of the edge starting at aCornerIndex
if( aArea->m_Poly->corner[aCornerIndex].end_contour == false
if( aArea->m_Poly->m_CornersList[aCornerIndex].end_contour == false
&& aCornerIndex < (aArea->GetNumCorners() - 1) )
{
end = aArea->GetCornerPosition( aCornerIndex + 1 );
......@@ -1141,7 +1136,7 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex )
while( ii >= 0 )
{
if( aArea->m_Poly->corner[ii].end_contour )
if( aArea->m_Poly->m_CornersList[ii].end_contour )
break;
end = aArea->GetCornerPosition( ii );
......@@ -1189,7 +1184,7 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex )
int ax2 = end.x;
int ay2 = end.y;
for( int icont2 = 0; icont2 < area_to_test->m_Poly->GetNumContours(); icont2++ )
for( int icont2 = 0; icont2 < area_to_test->m_Poly->GetContoursCount(); icont2++ )
{
int ic_start2 = area_to_test->m_Poly->GetContourStart( icont2 );
int ic_end2 = area_to_test->m_Poly->GetContourEnd( icont2 );
......
......@@ -18,8 +18,8 @@ CPolyLine::CPolyLine()
{
m_hatchStyle = NO_HATCH;
m_hatchPitch = 0;
m_Width = 0;
utility = 0;
m_width = 0;
m_utility = 0;
m_Kbool_Poly_Engine = NULL;
}
......@@ -33,6 +33,16 @@ CPolyLine::~CPolyLine()
delete m_Kbool_Poly_Engine;
}
/**
* Function armBoolEng
* Initialise parameters used in kbool
* @param aBooleng = pointer to the Bool_Engine to initialise
* @param aConvertHoles = mode for holes when a boolean operation is made
* true: holes are linked into outer contours by double overlapping segments
* false: holes are not linked: in this mode contours are added clockwise
* and polygons added counter clockwise are holes (default)
*/
static void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles = false );
/**
* Function NormalizeWithKbool
......@@ -95,8 +105,8 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*> * aExtraPolyList, boo
else if( n_ext_cont == 0 )
{
// first external contour, replace this poly
corner.clear();
side_style.clear();
m_CornersList.clear();
m_SideStyle.clear();
bool first = true;
while( m_Kbool_Poly_Engine->PolygonHasMorePoints() )
{
......@@ -271,7 +281,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
m_Kbool_Poly_Engine = NULL;
}
int polycount = GetNumContours();
int polycount = GetContoursCount();
if( !GetClosed() && (aStart_contour == (polycount - 1) || aStart_contour == -1) )
return 1; // error
......@@ -297,7 +307,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
// Fill a kbool engine for this contour,
// and combine it with previous contours
Bool_Engine* booleng = new Bool_Engine();
ArmBoolEng( booleng, aConvertHoles );
armBoolEng( booleng, aConvertHoles );
if( m_Kbool_Poly_Engine ) // a previous contour exists. Put it in new engine
{
......@@ -329,7 +339,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
}
for( int ic = ic_st; ic<=ic_end; ic++ )
{
int style = side_style[ic];
int style = m_SideStyle[ic];
if( style == STRAIGHT )
n_vertices++;
else
......@@ -345,19 +355,19 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
int ivtx = 0;
for( int ic = ic_st; ic<=ic_end; ic++ )
{
int style = side_style[ic];
int x1 = corner[ic].x;
int y1 = corner[ic].y;
int style = m_SideStyle[ic];
int x1 = m_CornersList[ic].x;
int y1 = m_CornersList[ic].y;
int x2, y2;
if( ic < ic_end )
{
x2 = corner[ic + 1].x;
y2 = corner[ic + 1].y;
x2 = m_CornersList[ic + 1].x;
y2 = m_CornersList[ic + 1].y;
}
else
{
x2 = corner[ic_st].x;
y2 = corner[ic_st].y;
x2 = m_CornersList[ic_st].x;
y2 = m_CornersList[ic_st].y;
}
if( style == STRAIGHT )
{
......@@ -504,14 +514,14 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector<
/**
* Function ArmBoolEng
* Function armBoolEng
* Initialise parameters used in kbool
* @param aBooleng = pointer to the Bool_Engine to initialise
* @param aConvertHoles = mode for holes when a boolean operation is made
* true: in resulting polygon, holes are linked into outer contours by double overlapping segments
* false: in resulting polygons, holes are not linked: they are separate polygons
*/
void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
{
// set some global vals to arm the boolean engine
......@@ -614,7 +624,7 @@ int CPolyLine::RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine
n_polys += pa->size();
CPolyLine* poly;
// undraw polys and clear utility flag for all corners
// undraw polys and clear m_utility flag for all corners
for( int ip = 0; ip<n_polys; ip++ )
{
if( ip == 0 )
......@@ -625,7 +635,7 @@ int CPolyLine::RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine
for( int ic = 0; ic<poly->GetNumCorners(); ic++ )
poly->SetUtility( ic, 0 );
// clear utility flag
// clear m_utility flag
}
// find arcs and replace them
......@@ -649,7 +659,7 @@ int CPolyLine::RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine
poly = this;
else
poly = (*pa)[ip - 1];
int polycount = poly->GetNumContours();
int polycount = poly->GetContoursCount();
for( int icont = 0; icont < polycount; icont++ )
{
int ic_start = poly->GetContourStart( icont );
......@@ -697,7 +707,7 @@ int CPolyLine::RestoreArcs( std::vector<CArc> * arc_array, std::vector<CPolyLine
}
if( bFound )
{
poly->side_style[arc_start] = style;
poly->m_SideStyle[arc_start] = style;
// mark corners for deletion from arc_start+1 to arc_end-1
for( int i = arc_start + 1; i!=arc_end; )
......@@ -769,8 +779,8 @@ void CPolyLine::Start( int layer, int x, int y, int hatch )
CPolyPt poly_pt( x, y );
poly_pt.end_contour = false;
corner.push_back( poly_pt );
side_style.push_back( 0 );
m_CornersList.push_back( poly_pt );
m_SideStyle.push_back( 0 );
}
......@@ -783,10 +793,10 @@ void CPolyLine::AppendCorner( int x, int y, int style, bool bDraw )
poly_pt.end_contour = false;
// add entries for new corner and side
corner.push_back( poly_pt );
side_style.push_back( style );
if( corner.size() > 0 && !corner[corner.size() - 1].end_contour )
side_style[corner.size() - 1] = style;
m_CornersList.push_back( poly_pt );
m_SideStyle.push_back( style );
if( m_CornersList.size() > 0 && !m_CornersList[m_CornersList.size() - 1].end_contour )
m_SideStyle[m_CornersList.size() - 1] = style;
if( bDraw )
Hatch();
}
......@@ -801,8 +811,8 @@ void CPolyLine::Close( int style, bool bDraw )
wxASSERT( 0 );
}
UnHatch();
side_style[corner.size() - 1] = style;
corner[corner.size() - 1].end_contour = true;
m_SideStyle[m_CornersList.size() - 1] = style;
m_CornersList[m_CornersList.size() - 1].end_contour = true;
if( bDraw )
Hatch();
}
......@@ -813,8 +823,8 @@ void CPolyLine::Close( int style, bool bDraw )
void CPolyLine::MoveCorner( int ic, int x, int y )
{
UnHatch();
corner[ic].x = x;
corner[ic].y = y;
m_CornersList[ic].x = x;
m_CornersList[ic].y = y;
Hatch();
}
......@@ -827,23 +837,23 @@ void CPolyLine::DeleteCorner( int ic, bool bDraw )
int icont = GetContour( ic );
int istart = GetContourStart( icont );
int iend = GetContourEnd( icont );
bool bClosed = icont < GetNumContours() - 1 || GetClosed();
bool bClosed = icont < GetContoursCount() - 1 || GetClosed();
if( !bClosed )
{
// open contour, must be last contour
corner.erase( corner.begin() + ic );
m_CornersList.erase( m_CornersList.begin() + ic );
if( ic != istart )
side_style.erase( side_style.begin() + ic - 1 );
m_SideStyle.erase( m_SideStyle.begin() + ic - 1 );
}
else
{
// closed contour
corner.erase( corner.begin() + ic );
side_style.erase( side_style.begin() + ic );
m_CornersList.erase( m_CornersList.begin() + ic );
m_SideStyle.erase( m_SideStyle.begin() + ic );
if( ic == iend )
corner[ic - 1].end_contour = true;
m_CornersList[ic - 1].end_contour = true;
}
if( bClosed && GetContourSize( icont ) < 3 )
{
......@@ -869,7 +879,7 @@ void CPolyLine::RemoveContour( int icont )
int istart = GetContourStart( icont );
int iend = GetContourEnd( icont );
int polycount = GetNumContours();
int polycount = GetContoursCount();
if( icont == 0 && polycount == 1 )
{
// remove the only contour
......@@ -878,16 +888,16 @@ void CPolyLine::RemoveContour( int icont )
else if( icont == polycount - 1 )
{
// remove last contour
corner.erase( corner.begin() + istart, corner.end() );
side_style.erase( side_style.begin() + istart, side_style.end() );
m_CornersList.erase( m_CornersList.begin() + istart, m_CornersList.end() );
m_SideStyle.erase( m_SideStyle.begin() + istart, m_SideStyle.end() );
}
else
{
// remove closed contour
for( int ic = iend; ic>=istart; ic-- )
{
corner.erase( corner.begin() + ic );
side_style.erase( side_style.begin() + ic );
m_CornersList.erase( m_CornersList.begin() + ic );
m_SideStyle.erase( m_SideStyle.begin() + ic );
}
}
Hatch();
......@@ -904,7 +914,7 @@ CPolyLine* CPolyLine::Chamfer( unsigned int aDistance )
return newPoly;
}
int polycount = GetNumContours();
int polycount = GetContoursCount();
for( int contour = 0; contour < polycount; contour++ )
{
unsigned int startIndex = GetContourStart( contour );
......@@ -915,29 +925,29 @@ CPolyLine* CPolyLine::Chamfer( unsigned int aDistance )
int x1, y1, nx, ny;
long long xa, ya, xb, yb;
x1 = corner[index].x;
y1 = corner[index].y;
x1 = m_CornersList[index].x;
y1 = m_CornersList[index].y;
if( index == startIndex )
{
xa = corner[endIndex].x - x1;
ya = corner[endIndex].y - y1;
xa = m_CornersList[endIndex].x - x1;
ya = m_CornersList[endIndex].y - y1;
}
else
{
xa = corner[index-1].x - x1;
ya = corner[index-1].y - y1;
xa = m_CornersList[index-1].x - x1;
ya = m_CornersList[index-1].y - y1;
}
if( index == endIndex )
{
xb = corner[startIndex].x - x1;
yb = corner[startIndex].y - y1;
xb = m_CornersList[startIndex].x - x1;
yb = m_CornersList[startIndex].y - y1;
}
else
{
xb = corner[index+1].x - x1;
yb = corner[index+1].y - y1;
xb = m_CornersList[index+1].x - x1;
yb = m_CornersList[index+1].y - y1;
}
unsigned int lena = (unsigned int)sqrt( (double)(xa*xa + ya*ya) );
......@@ -980,7 +990,7 @@ CPolyLine* CPolyLine::Fillet( unsigned int aRadius, unsigned int aSegments )
return newPoly;
}
int polycount = GetNumContours();
int polycount = GetContoursCount();
for( int contour = 0; contour < polycount; contour++ )
{
unsigned int startIndex = GetContourStart( contour );
......@@ -994,29 +1004,29 @@ CPolyLine* CPolyLine::Fillet( unsigned int aRadius, unsigned int aSegments )
long long xb, yb; // Next vertex
double nx, ny;
x1 = corner[index].x;
y1 = corner[index].y;
x1 = m_CornersList[index].x;
y1 = m_CornersList[index].y;
if( index == startIndex )
{
xa = corner[endIndex].x - x1;
ya = corner[endIndex].y - y1;
xa = m_CornersList[endIndex].x - x1;
ya = m_CornersList[endIndex].y - y1;
}
else
{
xa = corner[index-1].x - x1;
ya = corner[index-1].y - y1;
xa = m_CornersList[index-1].x - x1;
ya = m_CornersList[index-1].y - y1;
}
if( index == endIndex )
{
xb = corner[startIndex].x - x1;
yb = corner[startIndex].y - y1;
xb = m_CornersList[startIndex].x - x1;
yb = m_CornersList[startIndex].y - y1;
}
else
{
xb = corner[index+1].x - x1;
yb = corner[index+1].y - y1;
xb = m_CornersList[index+1].x - x1;
yb = m_CornersList[index+1].y - y1;
}
double lena = sqrt( (double) (xa*xa + ya*ya) );
......@@ -1103,8 +1113,8 @@ void CPolyLine::RemoveAllContours( void )
* Others params are not chnaged
*/
{
corner.clear();
side_style.clear();
m_CornersList.clear();
m_SideStyle.clear();
}
......@@ -1117,23 +1127,23 @@ void CPolyLine::RemoveAllContours( void )
void CPolyLine::InsertCorner( int ic, int x, int y )
{
UnHatch();
if( (unsigned) (ic) >= corner.size() )
if( (unsigned) (ic) >= m_CornersList.size() )
{
corner.push_back( CPolyPt( x, y ) );
side_style.push_back( STRAIGHT );
m_CornersList.push_back( CPolyPt( x, y ) );
m_SideStyle.push_back( STRAIGHT );
}
else
{
corner.insert( corner.begin() + ic + 1, CPolyPt( x, y ) );
side_style.insert( side_style.begin() + ic + 1, STRAIGHT );
m_CornersList.insert( m_CornersList.begin() + ic + 1, CPolyPt( x, y ) );
m_SideStyle.insert( m_SideStyle.begin() + ic + 1, STRAIGHT );
}
if( (unsigned) (ic + 1) < corner.size() )
if( (unsigned) (ic + 1) < m_CornersList.size() )
{
if( corner[ic].end_contour )
if( m_CornersList[ic].end_contour )
{
corner[ic + 1].end_contour = true;
corner[ic].end_contour = false;
m_CornersList[ic + 1].end_contour = true;
m_CornersList[ic].end_contour = false;
}
}
Hatch();
......@@ -1150,7 +1160,7 @@ void CPolyLine::UnHatch()
int CPolyLine::GetEndContour( int ic )
{
return corner[ic].end_contour;
return m_CornersList[ic].end_contour;
}
......@@ -1158,10 +1168,10 @@ CRect CPolyLine::GetBounds()
{
CRect r = GetCornerBounds();
r.left -= m_Width / 2;
r.right += m_Width / 2;
r.bottom -= m_Width / 2;
r.top += m_Width / 2;
r.left -= m_width / 2;
r.right += m_width / 2;
r.bottom -= m_width / 2;
r.top += m_width / 2;
return r;
}
......@@ -1172,12 +1182,12 @@ CRect CPolyLine::GetCornerBounds()
r.left = r.bottom = INT_MAX;
r.right = r.top = INT_MIN;
for( unsigned i = 0; i<corner.size(); i++ )
for( unsigned i = 0; i<m_CornersList.size(); i++ )
{
r.left = min( r.left, corner[i].x );
r.right = max( r.right, corner[i].x );
r.bottom = min( r.bottom, corner[i].y );
r.top = max( r.top, corner[i].y );
r.left = min( r.left, m_CornersList[i].x );
r.right = max( r.right, m_CornersList[i].x );
r.bottom = min( r.bottom, m_CornersList[i].y );
r.top = max( r.top, m_CornersList[i].y );
}
return r;
......@@ -1194,10 +1204,10 @@ CRect CPolyLine::GetCornerBounds( int icont )
int iend = GetContourEnd( icont );
for( int i = istart; i<=iend; i++ )
{
r.left = min( r.left, corner[i].x );
r.right = max( r.right, corner[i].x );
r.bottom = min( r.bottom, corner[i].y );
r.top = max( r.top, corner[i].y );
r.left = min( r.left, m_CornersList[i].x );
r.right = max( r.right, m_CornersList[i].x );
r.bottom = min( r.bottom, m_CornersList[i].y );
r.top = max( r.top, m_CornersList[i].y );
}
return r;
......@@ -1206,31 +1216,31 @@ CRect CPolyLine::GetCornerBounds( int icont )
int CPolyLine::GetNumCorners()
{
return corner.size();
return m_CornersList.size();
}
int CPolyLine::GetNumSides()
{
if( GetClosed() )
return corner.size();
return m_CornersList.size();
else
return corner.size() - 1;
return m_CornersList.size() - 1;
}
int CPolyLine::GetNumContours()
int CPolyLine::GetContoursCount()
{
int ncont = 0;
if( !corner.size() )
if( !m_CornersList.size() )
return 0;
for( unsigned ic = 0; ic<corner.size(); ic++ )
if( corner[ic].end_contour )
for( unsigned ic = 0; ic < m_CornersList.size(); ic++ )
if( m_CornersList[ic].end_contour )
ncont++;
if( !corner[corner.size() - 1].end_contour )
if( !m_CornersList[m_CornersList.size() - 1].end_contour )
ncont++;
return ncont;
}
......@@ -1242,7 +1252,7 @@ int CPolyLine::GetContour( int ic )
for( int i = 0; i<ic; i++ )
{
if( corner[i].end_contour )
if( m_CornersList[i].end_contour )
ncont++;
}
......@@ -1256,9 +1266,9 @@ int CPolyLine::GetContourStart( int icont )
return 0;
int ncont = 0;
for( unsigned i = 0; i<corner.size(); i++ )
for( unsigned i = 0; i<m_CornersList.size(); i++ )
{
if( corner[i].end_contour )
if( m_CornersList[i].end_contour )
{
ncont++;
if( ncont == icont )
......@@ -1276,13 +1286,13 @@ int CPolyLine::GetContourEnd( int icont )
if( icont < 0 )
return 0;
if( icont == GetNumContours() - 1 )
return corner.size() - 1;
if( icont == GetContoursCount() - 1 )
return m_CornersList.size() - 1;
int ncont = 0;
for( unsigned i = 0; i<corner.size(); i++ )
for( unsigned i = 0; i<m_CornersList.size(); i++ )
{
if( corner[i].end_contour )
if( m_CornersList[i].end_contour )
{
if( ncont == icont )
return i;
......@@ -1305,40 +1315,40 @@ void CPolyLine::SetSideStyle( int is, int style )
{
UnHatch();
wxPoint p1, p2;
if( is == (int) (corner.size() - 1) )
if( is == (int) (m_CornersList.size() - 1) )
{
p1.x = corner[corner.size() - 1].x;
p1.y = corner[corner.size() - 1].y;
p2.x = corner[0].x;
p2.y = corner[0].y;
p1.x = m_CornersList[m_CornersList.size() - 1].x;
p1.y = m_CornersList[m_CornersList.size() - 1].y;
p2.x = m_CornersList[0].x;
p2.y = m_CornersList[0].y;
}
else
{
p1.x = corner[is].x;
p1.y = corner[is].y;
p2.x = corner[is + 1].x;
p2.y = corner[is + 1].y;
p1.x = m_CornersList[is].x;
p1.y = m_CornersList[is].y;
p2.x = m_CornersList[is + 1].x;
p2.y = m_CornersList[is + 1].y;
}
if( p1.x == p2.x || p1.y == p2.y )
side_style[is] = STRAIGHT;
m_SideStyle[is] = STRAIGHT;
else
side_style[is] = style;
m_SideStyle[is] = style;
Hatch();
}
int CPolyLine::GetSideStyle( int is )
{
return side_style[is];
return m_SideStyle[is];
}
int CPolyLine::GetClosed()
{
if( corner.size() == 0 )
if( m_CornersList.size() == 0 )
return 0;
else
return corner[corner.size() - 1].end_contour;
return m_CornersList[m_CornersList.size() - 1].end_contour;
}
......@@ -1360,20 +1370,20 @@ void CPolyLine::Hatch()
return;
// define range for hatch lines
int min_x = corner[0].x;
int max_x = corner[0].x;
int min_y = corner[0].y;
int max_y = corner[0].y;
for( unsigned ic = 1; ic < corner.size(); ic++ )
{
if( corner[ic].x < min_x )
min_x = corner[ic].x;
if( corner[ic].x > max_x )
max_x = corner[ic].x;
if( corner[ic].y < min_y )
min_y = corner[ic].y;
if( corner[ic].y > max_y )
max_y = corner[ic].y;
int min_x = m_CornersList[0].x;
int max_x = m_CornersList[0].x;
int min_y = m_CornersList[0].y;
int max_y = m_CornersList[0].y;
for( unsigned ic = 1; ic < m_CornersList.size(); ic++ )
{
if( m_CornersList[ic].x < min_x )
min_x = m_CornersList[ic].x;
if( m_CornersList[ic].x > max_x )
max_x = m_CornersList[ic].x;
if( m_CornersList[ic].y < min_y )
min_y = m_CornersList[ic].y;
if( m_CornersList[ic].y > max_y )
max_y = m_CornersList[ic].y;
}
// Calculate spacing betwwen 2 hatch lines
......@@ -1409,7 +1419,7 @@ void CPolyLine::Hatch()
min_a += offset;
// now calculate and draw hatch lines
int nc = corner.size();
int nc = m_CornersList.size();
// loop through hatch lines
#define MAXPTS 200 // Usually we store only few values per one hatch line
......@@ -1433,22 +1443,22 @@ void CPolyLine::Hatch()
{
double x, y, x2, y2;
int ok;
if( corner[ic].end_contour || ( ic == (int) (corner.size() - 1) ) )
if( m_CornersList[ic].end_contour || ( ic == (int) (m_CornersList.size() - 1) ) )
{
ok = FindLineSegmentIntersection( a, slope,
corner[ic].x, corner[ic].y,
corner[i_start_contour].x,
corner[i_start_contour].y,
side_style[ic],
m_CornersList[ic].x, m_CornersList[ic].y,
m_CornersList[i_start_contour].x,
m_CornersList[i_start_contour].y,
m_SideStyle[ic],
&x, &y, &x2, &y2 );
i_start_contour = ic + 1;
}
else
{
ok = FindLineSegmentIntersection( a, slope,
corner[ic].x, corner[ic].y,
corner[ic + 1].x, corner[ic + 1].y,
side_style[ic],
m_CornersList[ic].x, m_CornersList[ic].y,
m_CornersList[ic + 1].x, m_CornersList[ic + 1].y,
m_SideStyle[ic],
&x, &y, &x2, &y2 );
}
if( ok )
......@@ -1534,7 +1544,7 @@ bool CPolyLine::TestPointInside( int px, int py )
// if the tested point is inside only one contour, it is inside the whole polygon
// (in fact inside the main outline, and outside all holes).
// if inside 2 contours (the main outline + an hole), it is outside the poly.
int polycount = GetNumContours();
int polycount = GetContoursCount();
bool inside = false;
for( int icont = 0; icont < polycount; icont++ )
{
......@@ -1542,7 +1552,7 @@ bool CPolyLine::TestPointInside( int px, int py )
int iend = GetContourEnd( icont );
// Test this polygon:
if( TestPointInsidePolygon( corner, istart, iend, px, py) ) // test point inside the current polygon
if( TestPointInsidePolygon( m_CornersList, istart, iend, px, py) ) // test point inside the current polygon
inside = not inside;
}
......@@ -1557,9 +1567,9 @@ void CPolyLine::Copy( CPolyLine* src )
m_hatchStyle = src->m_hatchStyle;
m_hatchPitch = src->m_hatchPitch;
// copy corners, using vector copy
corner = src->corner;
m_CornersList = src->m_CornersList;
// copy side styles, using vector copy
side_style = src->side_style;
m_SideStyle = src->m_SideStyle;
}
......@@ -1598,19 +1608,19 @@ void CPolyLine::MoveOrigin( int x_off, int y_off )
//
void CPolyLine::SetX( int ic, int x )
{
corner[ic].x = x;
m_CornersList[ic].x = x;
}
void CPolyLine::SetY( int ic, int y )
{
corner[ic].y = y;
m_CornersList[ic].y = y;
}
void CPolyLine::SetEndContour( int ic, bool end_contour )
{
corner[ic].end_contour = end_contour;
m_CornersList[ic].end_contour = end_contour;
}
......@@ -1676,7 +1686,7 @@ int CPolyLine::Distance( wxPoint aStart, wxPoint aEnd, int aWidth )
return 0;
int distance = INT_MAX;
int polycount = GetNumContours();
int polycount = GetContoursCount();
for( int icont = 0; icont < polycount; icont++ )
{
......@@ -1732,7 +1742,7 @@ int CPolyLine::Distance( const wxPoint& aPoint )
return 0;
int distance = INT_MAX;
int polycount = GetNumContours();
int polycount = GetContoursCount();
for( int icont = 0; icont < polycount; icont++ )
{
......
......@@ -31,18 +31,6 @@ enum
};
/**
* Function ArmBoolEng
* Initialise parameters used in kbool
* @param aBooleng = pointer to the Bool_Engine to initialise
* @param aConvertHoles = mode for holes when a boolean operation is made
* true: holes are linked into outer contours by double overlapping segments
* false: holes are not linked: in this mode contours are added clockwise
* and polygons added counter clockwise are holes (default)
*/
void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles = false );
class CRect
{
public:
......@@ -86,22 +74,22 @@ class CPolyPt : public wxPoint
{
public:
CPolyPt( int aX = 0, int aY = 0, bool aEnd = false, int aUtility = 0 ) :
wxPoint( aX, aY ), end_contour( aEnd ), utility( aUtility )
wxPoint( aX, aY ), end_contour( aEnd ), m_utility( aUtility )
{}
/// Pure copy constructor is here to dis-ambiguate from the
/// specialized CPolyPt( const wxPoint& ) constructor version below.
CPolyPt( const CPolyPt& aPt ) :
wxPoint( aPt.x, aPt.y ), end_contour( aPt.end_contour ), utility( aPt.utility )
wxPoint( aPt.x, aPt.y ), end_contour( aPt.end_contour ), m_utility( aPt.m_utility )
{}
CPolyPt( const wxPoint& aPoint ) :
wxPoint( aPoint ), end_contour( false ), utility( 0 )
wxPoint( aPoint ), end_contour( false ), m_utility( 0 )
{}
bool end_contour;
int utility;
int m_utility;
bool operator == (const CPolyPt& cpt2 ) const
{ return (x == cpt2.x) && (y == cpt2.y) && (end_contour == cpt2.end_contour); }
......@@ -116,7 +104,7 @@ public:
class CPolyLine
{
public:
enum side_style { STRAIGHT, ARC_CW, ARC_CCW }; // side styles
enum m_SideStyle { STRAIGHT, ARC_CW, ARC_CCW }; // side styles
enum hatch_style { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles
// constructors/destructor
......@@ -173,21 +161,21 @@ public:
int GetNumCorners();
int GetNumSides();
int GetClosed();
int GetNumContours();
int GetContoursCount();
int GetContour( int ic );
int GetContourStart( int icont );
int GetContourEnd( int icont );
int GetContourSize( int icont );
int GetX( int ic ) const { return corner[ic].x; }
int GetY( int ic ) const { return corner[ic].y; }
int GetX( int ic ) const { return m_CornersList[ic].x; }
int GetY( int ic ) const { return m_CornersList[ic].y; }
const wxPoint& GetPos( int ic ) const { return corner[ic]; }
const wxPoint& GetPos( int ic ) const { return m_CornersList[ic]; }
int GetEndContour( int ic );
int GetUtility( int ic ) { return corner[ic].utility; };
void SetUtility( int ic, int utility ) { corner[ic].utility = utility; };
int GetUtility( int ic ) { return m_CornersList[ic].m_utility; };
void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; };
int GetSideStyle( int is );
int GetHatchPitch() { return m_hatchPitch; }
int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils
......@@ -301,18 +289,18 @@ public:
private:
int m_layer; // layer to draw on
int m_Width; // lines width when drawing. Provided but not really used
int m_width; // lines width when drawing. Provided but not really used
enum hatch_style m_hatchStyle; // hatch style, see enum above
int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines
// and the len of eacvh segment
// for DIAGONAL_FULL, the pitch is twice this value
int utility;
int m_utility; // a flag used in some calculations
Bool_Engine* m_Kbool_Poly_Engine; // polygons set in kbool engine data
public:
std::vector <CPolyPt> corner; // array of points for corners
std::vector <int> side_style; // array of styles for sides
std::vector <CSegment> m_HatchLines; // hatch lines
std::vector <CPolyPt> m_CornersList; // array of points for corners
std::vector <int> m_SideStyle; // array of styles for sides
std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area
};
#endif // #ifndef POLYLINE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment