From 05220a86f166027d26107d4219d3c23ae38373c3 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 22 Mar 2017 10:58:14 +0100 Subject: [PATCH] BOARD::GetBoardPolygonOutlines(): do not generate a separate SHAPE_POLY_SET for holes. They are already managed by SHAPE_POLY_SET board outline. --- 3d-viewer/3d_canvas/cinfo3d_visu.cpp | 7 +-- pcbnew/class_board.cpp | 4 +- pcbnew/class_board.h | 3 +- .../convert_drawsegment_list_to_polygon.cpp | 7 +-- pcbnew/exporters/export_vrml.cpp | 53 +++++++++--------- pcbnew/specctra_export.cpp | 56 +++++++++---------- 6 files changed, 57 insertions(+), 73 deletions(-) diff --git a/3d-viewer/3d_canvas/cinfo3d_visu.cpp b/3d-viewer/3d_canvas/cinfo3d_visu.cpp index 088f580e06..f6c74466ea 100644 --- a/3d-viewer/3d_canvas/cinfo3d_visu.cpp +++ b/3d-viewer/3d_canvas/cinfo3d_visu.cpp @@ -475,20 +475,15 @@ void CINFO3D_VISU::createBoardPolygon() { m_board_poly.RemoveAllContours(); - // Create board outlines and board holes - SHAPE_POLY_SET allLayerHoles; - 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( _( "Cannot determine the board outline." ) ); wxLogMessage( errmsg ); } - m_board_poly.BooleanSubtract( allLayerHoles, SHAPE_POLY_SET::PM_FAST ); - Polygon_Calc_BBox_3DU( m_board_poly, m_board2dBBox3DU, m_biuTo3Dunits ); } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 18bc8ee885..636babadbe 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2876,12 +2876,10 @@ BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, */ extern bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, - SHAPE_POLY_SET& aHoles, wxString* aErrorText ); bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, - SHAPE_POLY_SET& aHoles, wxString* aErrorText ) { - return BuildBoardPolygonOutlines( this, aOutlines, aHoles, aErrorText ); + return BuildBoardPolygonOutlines( this, aOutlines, aErrorText ); } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index bff0513270..47381580d7 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -575,14 +575,13 @@ 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 SHAPE_POLY_SET to fill in with outlines/holes. * @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, wxString* aErrorText = NULL ); /** diff --git a/pcbnew/convert_drawsegment_list_to_polygon.cpp b/pcbnew/convert_drawsegment_list_to_polygon.cpp index 704832a0a2..bcdb882d90 100644 --- a/pcbnew/convert_drawsegment_list_to_polygon.cpp +++ b/pcbnew/convert_drawsegment_list_to_polygon.cpp @@ -190,7 +190,7 @@ bool ConvertOutlineToPolygon( std::vector< DRAWSEGMENT* >& aSegList, std::vector< DRAWSEGMENT* > segList = aSegList; 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; wxPoint prevPt; @@ -584,7 +584,6 @@ bool ConvertOutlineToPolygon( std::vector< DRAWSEGMENT* >& aSegList, */ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, - SHAPE_POLY_SET& aHoles, wxString* aErrorText ) { PCB_TYPE_COLLECTOR items; @@ -609,7 +608,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, // only one main outline is expected if( success && aOutlines.OutlineCount() ) { - int outlineId = 0; +/* int outlineId = 0; int holecount = aOutlines.HoleCount( outlineId ); @@ -623,7 +622,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, // Remove holes from aOutlines: SHAPE_POLY_SET::POLYGON& polygon = aOutlines.Polygon( outlineId ); polygon.erase( polygon.begin()+1, polygon.end() ); - } + }*/ } else { diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp index b09e1d62ca..c6e7c9b205 100644 --- a/pcbnew/exporters/export_vrml.cpp +++ b/pcbnew/exporters/export_vrml.cpp @@ -798,12 +798,10 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb ) // board edges and cutouts static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) { - SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines - SHAPE_POLY_SET allLayerHoles; // Contains through holes, calculated only once - // Build a polygon from edge cut items + SHAPE_POLY_SET pcbOutlines; // stores the board main outlines wxString msg; - if( !aPcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) ) + if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) ) { msg << "\n\n" << _( "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; - 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(); @@ -826,31 +824,32 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) } aModel.m_board.EnsureWinding( seg, false ); - } - for( int i = 0; i < allLayerHoles.OutlineCount(); i++ ) - { - const SHAPE_LINE_CHAIN& outline = allLayerHoles.COutline( i ); - - seg = aModel.m_holes.NewContour(); - - if( seg < 0 ) + // Generate holes: + for( int ii = 0; ii < pcbOutlines.HoleCount( cnt ); ii++ ) { - msg << "\n\n" << - _( "VRML Export Failed: Could not add holes to contours." ); - wxMessageBox( msg ); + const SHAPE_LINE_CHAIN& hole = pcbOutlines.Hole( cnt, ii ); - 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 ); } } diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 65a7cd3a5f..102bde7372 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -733,19 +733,16 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) { wxString errMessage; 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 - - if( outlines.OutlineCount() ) // Should be always true + for( int cnt = 0; cnt < outlines.OutlineCount(); cnt++ ) // Should be one outline { PATH* path = new PATH( boundary ); boundary->paths.push_back( path ); 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++ ) { @@ -754,35 +751,32 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) } // Close polygon: - wxPoint pos( outline.Point( 0 ).x, outline.Point( 0 ).y ); - path->AppendPoint( mapPt( pos ) ); - } + wxPoint pos0( outline.Point( 0 ).x, outline.Point( 0 ).y ); + path->AppendPoint( mapPt( pos0 ) ); - // Output the interior Edge.Cuts graphics as keepouts, using same nearness - // metric as the board edge as otherwise we have trouble completing complex - // 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++ ) + // Generate holes as keepout: + for( int ii = 0; ii < outlines.HoleCount( cnt ); ii++ ) { - 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 ) ); } - - // Close polygon: - wxPoint pos( hole.Point( 0 ).x, hole.Point( 0 ).y ); - poly_ko->AppendPoint( mapPt( pos ) ); } if( !errMessage.IsEmpty() )