BOARD::GetBoardPolygonOutlines(): do not generate a separate SHAPE_POLY_SET for holes.

They are already managed by SHAPE_POLY_SET board outline.
This commit is contained in:
jean-pierre charras 2017-03-22 10:58:14 +01:00
parent d99fbddc22
commit 05220a86f1
6 changed files with 57 additions and 73 deletions

View File

@ -475,20 +475,15 @@ void CINFO3D_VISU::createBoardPolygon()
{ {
m_board_poly.RemoveAllContours(); m_board_poly.RemoveAllContours();
// Create board outlines and board holes
SHAPE_POLY_SET allLayerHoles;
wxString errmsg; wxString errmsg;
if( !m_board->GetBoardPolygonOutlines( m_board_poly, allLayerHoles, &errmsg ) ) if( !m_board->GetBoardPolygonOutlines( m_board_poly, /*allLayerHoles,*/ &errmsg ) )
{ {
errmsg.append( wxT( "\n\n" ) ); errmsg.append( wxT( "\n\n" ) );
errmsg.append( _( "Cannot determine the board outline." ) ); errmsg.append( _( "Cannot determine the board outline." ) );
wxLogMessage( errmsg ); wxLogMessage( errmsg );
} }
m_board_poly.BooleanSubtract( allLayerHoles, SHAPE_POLY_SET::PM_FAST );
Polygon_Calc_BBox_3DU( m_board_poly, m_board2dBBox3DU, m_biuTo3Dunits ); Polygon_Calc_BBox_3DU( m_board_poly, m_board2dBBox3DU, m_biuTo3Dunits );
} }

View File

@ -2876,12 +2876,10 @@ BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem,
*/ */
extern bool BuildBoardPolygonOutlines( BOARD* aBoard, extern bool BuildBoardPolygonOutlines( BOARD* aBoard,
SHAPE_POLY_SET& aOutlines, SHAPE_POLY_SET& aOutlines,
SHAPE_POLY_SET& aHoles,
wxString* aErrorText ); wxString* aErrorText );
bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
SHAPE_POLY_SET& aHoles,
wxString* aErrorText ) wxString* aErrorText )
{ {
return BuildBoardPolygonOutlines( this, aOutlines, aHoles, aErrorText ); return BuildBoardPolygonOutlines( this, aOutlines, aErrorText );
} }

View File

@ -575,14 +575,13 @@ public:
* from lines, arcs and circle items on edge cut layer * from lines, arcs and circle items on edge cut layer
* Any closed outline inside the main outline is a hole * 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 * 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 SHAPE_POLY_SET to fill in with outlines/holes.
* @param aErrorText = a wxString reference to display an error message * @param aErrorText = a wxString reference to display an error message
* with the coordinate of the point which creates the error * with the coordinate of the point which creates the error
* (default = NULL , no message returned on error) * (default = NULL , no message returned on error)
* @return true if success, false if a contour is not valid * @return true if success, false if a contour is not valid
*/ */
bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
SHAPE_POLY_SET& aHoles,
wxString* aErrorText = NULL ); wxString* aErrorText = NULL );
/** /**

View File

@ -190,7 +190,7 @@ bool ConvertOutlineToPolygon( std::vector< DRAWSEGMENT* >& aSegList,
std::vector< DRAWSEGMENT* > segList = aSegList; std::vector< DRAWSEGMENT* > segList = aSegList;
unsigned prox; // a proximity BIU metric, not an accurate distance unsigned prox; // a proximity BIU metric, not an accurate distance
const int STEPS = 16; // for a segmentation of an arc of 360 degrees const int STEPS = 36; // for a segmentation of an arc of 360 degrees
DRAWSEGMENT* graphic; DRAWSEGMENT* graphic;
wxPoint prevPt; wxPoint prevPt;
@ -584,7 +584,6 @@ bool ConvertOutlineToPolygon( std::vector< DRAWSEGMENT* >& aSegList,
*/ */
bool BuildBoardPolygonOutlines( BOARD* aBoard, bool BuildBoardPolygonOutlines( BOARD* aBoard,
SHAPE_POLY_SET& aOutlines, SHAPE_POLY_SET& aOutlines,
SHAPE_POLY_SET& aHoles,
wxString* aErrorText ) wxString* aErrorText )
{ {
PCB_TYPE_COLLECTOR items; PCB_TYPE_COLLECTOR items;
@ -609,7 +608,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard,
// only one main outline is expected // only one main outline is expected
if( success && aOutlines.OutlineCount() ) if( success && aOutlines.OutlineCount() )
{ {
int outlineId = 0; /* int outlineId = 0;
int holecount = aOutlines.HoleCount( outlineId ); int holecount = aOutlines.HoleCount( outlineId );
@ -623,7 +622,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard,
// Remove holes from aOutlines: // Remove holes from aOutlines:
SHAPE_POLY_SET::POLYGON& polygon = aOutlines.Polygon( outlineId ); SHAPE_POLY_SET::POLYGON& polygon = aOutlines.Polygon( outlineId );
polygon.erase( polygon.begin()+1, polygon.end() ); polygon.erase( polygon.begin()+1, polygon.end() );
} }*/
} }
else else
{ {

View File

@ -798,12 +798,10 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb )
// board edges and cutouts // board edges and cutouts
static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb )
{ {
SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines SHAPE_POLY_SET pcbOutlines; // stores the board main outlines
SHAPE_POLY_SET allLayerHoles; // Contains through holes, calculated only once
// Build a polygon from edge cut items
wxString msg; wxString msg;
if( !aPcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) ) if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) )
{ {
msg << "\n\n" << msg << "\n\n" <<
_( "Unable to calculate the board outlines; fall back to using the board boundary box." ); _( "Unable to calculate the board outlines; fall back to using the board boundary box." );
@ -812,9 +810,9 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb )
int seg; int seg;
for( int i = 0; i < bufferPcbOutlines.OutlineCount(); i++ ) for( int cnt = 0; cnt < pcbOutlines.OutlineCount(); cnt++ )
{ {
const SHAPE_LINE_CHAIN& outline = bufferPcbOutlines.COutline( i ); const SHAPE_LINE_CHAIN& outline = pcbOutlines.COutline( cnt );
seg = aModel.m_board.NewContour(); seg = aModel.m_board.NewContour();
@ -826,31 +824,32 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb )
} }
aModel.m_board.EnsureWinding( seg, false ); aModel.m_board.EnsureWinding( seg, false );
}
for( int i = 0; i < allLayerHoles.OutlineCount(); i++ ) // Generate holes:
{ for( int ii = 0; ii < pcbOutlines.HoleCount( cnt ); ii++ )
const SHAPE_LINE_CHAIN& outline = allLayerHoles.COutline( i );
seg = aModel.m_holes.NewContour();
if( seg < 0 )
{ {
msg << "\n\n" << const SHAPE_LINE_CHAIN& hole = pcbOutlines.Hole( cnt, ii );
_( "VRML Export Failed: Could not add holes to contours." );
wxMessageBox( msg );
return; seg = aModel.m_holes.NewContour();
if( seg < 0 )
{
msg << "\n\n" <<
_( "VRML Export Failed: Could not add holes to contours." );
wxMessageBox( msg );
return;
}
for( int j = 0; j < hole.PointCount(); j++ )
{
aModel.m_holes.AddVertex( seg, (double)hole.CPoint(j).x * BOARD_SCALE,
-((double)hole.CPoint(j).y * BOARD_SCALE ) );
}
aModel.m_holes.EnsureWinding( seg, true );
} }
for( int j = 0; j < outline.PointCount(); j++ )
{
aModel.m_holes.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
-((double)outline.CPoint(j).y * BOARD_SCALE ) );
}
aModel.m_holes.EnsureWinding( seg, true );
} }
} }

View File

@ -733,19 +733,16 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary )
{ {
wxString errMessage; wxString errMessage;
SHAPE_POLY_SET outlines; SHAPE_POLY_SET outlines;
SHAPE_POLY_SET holes;
aBoard->GetBoardPolygonOutlines( outlines, holes, &errMessage ); aBoard->GetBoardPolygonOutlines( outlines, &errMessage );
//const int STEPS = 36; // for a segmentation of an arc of 360 degrees for( int cnt = 0; cnt < outlines.OutlineCount(); cnt++ ) // Should be one outline
if( outlines.OutlineCount() ) // Should be always true
{ {
PATH* path = new PATH( boundary ); PATH* path = new PATH( boundary );
boundary->paths.push_back( path ); boundary->paths.push_back( path );
path->layer_id = "pcb"; path->layer_id = "pcb";
SHAPE_LINE_CHAIN& outline = outlines.Outline( 0 ); SHAPE_LINE_CHAIN& outline = outlines.Outline( cnt );
for( int ii = 0; ii < outline.PointCount(); ii++ ) for( int ii = 0; ii < outline.PointCount(); ii++ )
{ {
@ -754,35 +751,32 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary )
} }
// Close polygon: // Close polygon:
wxPoint pos( outline.Point( 0 ).x, outline.Point( 0 ).y ); wxPoint pos0( outline.Point( 0 ).x, outline.Point( 0 ).y );
path->AppendPoint( mapPt( pos ) ); path->AppendPoint( mapPt( pos0 ) );
}
// Output the interior Edge.Cuts graphics as keepouts, using same nearness // Generate holes as keepout:
// metric as the board edge as otherwise we have trouble completing complex for( int ii = 0; ii < outlines.HoleCount( cnt ); ii++ )
// polygons.
for( int ii = 0; ii < holes.OutlineCount(); ii++ )
{
// emit a signal layers keepout for every interior polygon left...
KEEPOUT* keepout = new KEEPOUT( NULL, T_keepout );
PATH* poly_ko = new PATH( NULL, T_polygon );
keepout->SetShape( poly_ko );
poly_ko->SetLayerId( "signal" );
pcb->structure->keepouts.push_back( keepout );
SHAPE_LINE_CHAIN& hole = holes.Outline( ii );
for( int jj = 0; jj < hole.PointCount(); jj++ )
{ {
wxPoint pos( hole.Point( jj ).x, hole.Point( jj ).y ); // emit a signal layers keepout for every interior polygon left...
KEEPOUT* keepout = new KEEPOUT( NULL, T_keepout );
PATH* poly_ko = new PATH( NULL, T_polygon );
keepout->SetShape( poly_ko );
poly_ko->SetLayerId( "signal" );
pcb->structure->keepouts.push_back( keepout );
SHAPE_LINE_CHAIN& hole = outlines.Hole( cnt, ii );
for( int jj = 0; jj < hole.PointCount(); jj++ )
{
wxPoint pos( hole.Point( jj ).x, hole.Point( jj ).y );
poly_ko->AppendPoint( mapPt( pos ) );
}
// Close polygon:
wxPoint pos( hole.Point( 0 ).x, hole.Point( 0 ).y );
poly_ko->AppendPoint( mapPt( pos ) ); poly_ko->AppendPoint( mapPt( pos ) );
} }
// Close polygon:
wxPoint pos( hole.Point( 0 ).x, hole.Point( 0 ).y );
poly_ko->AppendPoint( mapPt( pos ) );
} }
if( !errMessage.IsEmpty() ) if( !errMessage.IsEmpty() )