Loading pcbnew/board_items_to_polygon_shape_transform.cpp +86 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include <vector> #include <fctsys.h> #include <polygons_defs.h> #include <pcbnew.h> #include <wxPcbStruct.h> #include <trigo.h> Loading @@ -17,6 +18,7 @@ #include <class_track.h> #include <class_drawsegment.h> #include <class_pcb_text.h> #include <class_zone.h> /* Exported functions */ Loading Loading @@ -130,6 +132,90 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCo aCornerBuffer.back().end_contour = true; } /* Function TransformShapeWithClearanceToPolygon * Convert the track shape to a closed polygon * Used in filling zones calculations * Circles (vias) and arcs (ends of tracks) are approximated by segments * param aCornerBuffer = a buffer to store the polygon * param aClearanceValue = the clearance around the pad * param aCircleToSegmentsCount = the number of segments to approximate a circle * param aCorrectionFactor = the correction to apply to circles radius to keep * param aAddClearance = true to add a clearance area to the polygon * false to create the outline polygon. * clearance when the circle is approximated by segment bigger or equal * to the real clearance value (usually near from 1.0) */ void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool aAddClearance ) { /* Creates the main polygon (i.e. the filled area using only one outline) * and reserve a clearance margin around the outlines and holes */ std::vector <CPolyPt> zoneOutines; BuildFilledPolysListData( NULL, &zoneOutines ); int clearance = 0; if( aAddClearance ) { GetClearance(); if( aClearanceValue > clearance ) clearance = aClearanceValue; } // 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; unsigned ic = 0; unsigned corners_count = zoneOutines.size(); while( ic < corners_count ) { cornerslist.clear(); KPolygon poly; { for( ; ic < corners_count; ic++ ) { CPolyPt* corner = &zoneOutines[ic]; cornerslist.push_back( KPolyPoint( corner->x, corner->y ) ); if( corner->end_contour ) { ic++; break; } } bpl::set_points( poly, cornerslist.begin(), cornerslist.end() ); polyset_zone_solid_areas.push_back( poly ); } } polyset_zone_solid_areas += clearance; // Put the resultng polygon in buffer for( unsigned ii = 0; ii < polyset_zone_solid_areas.size(); ii++ ) { KPolygon& poly = polyset_zone_solid_areas[ii]; CPolyPt corner( 0, 0, false ); for( unsigned jj = 0; jj < poly.size(); jj++ ) { KPolyPoint point = *(poly.begin() + jj); corner.x = point.x(); corner.y = point.y(); corner.end_contour = false; aCornerBuffer.push_back( corner ); } corner.end_contour = true; aCornerBuffer.pop_back(); aCornerBuffer.push_back( corner ); } } /** * Function TransformShapeWithClearanceToPolygon Loading pcbnew/class_zone.cpp +11 −4 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) : m_CornerSelection = -1; m_IsFilled = false; // fill status : true when the zone is filled m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments m_priority = 0; smoothedPoly = NULL; cornerSmoothingType = ZONE_SETTING::SMOOTHING_NONE; cornerRadius = 0; Loading @@ -77,6 +78,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) : m_ZoneClearance = aZone.m_ZoneClearance; // clearance value m_ZoneMinThickness = aZone.m_ZoneMinThickness; m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons) m_priority = aZone.m_priority; m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount; m_PadOption = aZone.m_PadOption; m_ThermalReliefGap = aZone.m_ThermalReliefGap; Loading Loading @@ -677,16 +679,21 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame ) } frame->AppendMsgPanel( _( "NetName" ), msg, RED ); #if 1 // Display net code : (useful in test or debug) msg.Printf( wxT( "%d" ), GetNet() ); frame->AppendMsgPanel( _( "NetCode" ), msg, RED ); #endif // Display priority level msg.Printf( wxT( "%d" ), GetPriority() ); frame->AppendMsgPanel( _( "Priority" ), msg, BLUE ); } else { frame->AppendMsgPanel( _( "Non Copper Zone" ), wxEmptyString, RED ); } /* Display net code : (useful in test or debug) */ msg.Printf( wxT( "%d" ), GetNet() ); frame->AppendMsgPanel( _( "NetCode" ), msg, RED ); msg = board->GetLayerName( m_Layer ); frame->AppendMsgPanel( _( "Layer" ), msg, BROWN ); Loading pcbnew/class_zone.h +39 −2 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ private: CPolyLine* smoothedPoly; // Corner-smoothed version of m_Poly int cornerSmoothingType; unsigned int cornerRadius; // Priority: when a zone outline is inside and other zone, if its priority is highter // the other zone priority, it will be created inside. // if priorities are equal, a DRC erroc is set unsigned m_priority; public: ZONE_CONTAINER( BOARD* parent ); Loading @@ -149,6 +153,18 @@ public: const wxPoint GetPosition() const; // overload void SetPosition( const wxPoint& aPos ); // overload /** * Function SetPriority * @param aPriority = the priority level */ void SetPriority( unsigned aPriority ) { m_priority = aPriority; } /** * Function GetPriority * @return the priority level of this zone */ unsigned GetPriority() const { return m_priority; } /** * Function copy * copy useful data from the source. Loading Loading @@ -305,11 +321,13 @@ public: * in order to have drawable (and plottable) filled polygons * drawable filled polygons are polygons without hole * @param aPcb: the current board (can be NULL for non copper zones) * @param aCornerBuffer: A reference to a buffer to put polygon corners, or NULL * if NULL (default), uses m_FilledPolysList and fill current zone. * @return number of polygons * This function does not add holes for pads and tracks but calls * AddClearanceAreasPolygonsToPolysList() to do that for copper layers */ int BuildFilledPolysListData( BOARD* aPcb ); int BuildFilledPolysListData( BOARD* aPcb, std::vector <CPolyPt>* aCornerBuffer = NULL ); /** * Function AddClearanceAreasPolygonsToPolysList Loading Loading @@ -484,6 +502,25 @@ public: return m_Poly->GetHatchStyle(); } /** * Function TransformShapeWithClearanceToPolygon * Convert the track shape to a closed polygon * Used in filling zones calculations * Circles (vias) and arcs (ends of tracks) are approximated by segments * @param aCornerBuffer = a buffer to store the polygon * @param aClearanceValue = the clearance around the pad * @param aCircleToSegmentsCount = the number of segments to approximate a circle * @param aCorrectionFactor = the correction to apply to circles radius to keep * @param aAddClearance = true to add a clearance area to the polygon * false to create the outline polygon. * clearance when the circle is approximated by segment bigger or equal * to the real clearance value (usually near from 1.0) */ void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool aAddClearance ); /** * Function IsSame * tests if 2 zones are equivalent: Loading pcbnew/class_zone_setting.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ ZONE_SETTING::ZONE_SETTING( void ) { m_ZonePriority = 0; m_FillMode = 0; // Mode for filling zone : 1 use segments, 0 use polygons m_ZoneClearance = 200; // Clearance value m_ZoneMinThickness = 100; // Min thickness value in filled areas Loading @@ -50,6 +51,7 @@ ZONE_SETTING::ZONE_SETTING( void ) */ void ZONE_SETTING::ImportSetting( const ZONE_CONTAINER& aSource ) { m_ZonePriority = aSource.GetPriority(); m_FillMode = aSource.m_FillMode; m_ZoneClearance = aSource.m_ZoneClearance; m_ZoneMinThickness = aSource.m_ZoneMinThickness; Loading Loading @@ -88,6 +90,7 @@ void ZONE_SETTING::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) aTarget.SetCornerRadius( cornerRadius ); if( aFullExport ) { aTarget.SetPriority( m_ZonePriority ); aTarget.SetNet( m_NetcodeSelection ); aTarget.SetLayer( m_CurrentZone_Layer ); } Loading pcbnew/class_zone_setting.h +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ public: // Mode for filling zone : 1 use segments, 0 use polygons int m_FillMode; int m_ZonePriority; // Priority (0 ... N) of the zone int m_ZoneClearance; // Clearance value int m_ZoneMinThickness; // Min thickness value in filled areas int m_NetcodeSelection; // Net code selection for the current zone Loading Loading
pcbnew/board_items_to_polygon_shape_transform.cpp +86 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include <vector> #include <fctsys.h> #include <polygons_defs.h> #include <pcbnew.h> #include <wxPcbStruct.h> #include <trigo.h> Loading @@ -17,6 +18,7 @@ #include <class_track.h> #include <class_drawsegment.h> #include <class_pcb_text.h> #include <class_zone.h> /* Exported functions */ Loading Loading @@ -130,6 +132,90 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCo aCornerBuffer.back().end_contour = true; } /* Function TransformShapeWithClearanceToPolygon * Convert the track shape to a closed polygon * Used in filling zones calculations * Circles (vias) and arcs (ends of tracks) are approximated by segments * param aCornerBuffer = a buffer to store the polygon * param aClearanceValue = the clearance around the pad * param aCircleToSegmentsCount = the number of segments to approximate a circle * param aCorrectionFactor = the correction to apply to circles radius to keep * param aAddClearance = true to add a clearance area to the polygon * false to create the outline polygon. * clearance when the circle is approximated by segment bigger or equal * to the real clearance value (usually near from 1.0) */ void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool aAddClearance ) { /* Creates the main polygon (i.e. the filled area using only one outline) * and reserve a clearance margin around the outlines and holes */ std::vector <CPolyPt> zoneOutines; BuildFilledPolysListData( NULL, &zoneOutines ); int clearance = 0; if( aAddClearance ) { GetClearance(); if( aClearanceValue > clearance ) clearance = aClearanceValue; } // 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; unsigned ic = 0; unsigned corners_count = zoneOutines.size(); while( ic < corners_count ) { cornerslist.clear(); KPolygon poly; { for( ; ic < corners_count; ic++ ) { CPolyPt* corner = &zoneOutines[ic]; cornerslist.push_back( KPolyPoint( corner->x, corner->y ) ); if( corner->end_contour ) { ic++; break; } } bpl::set_points( poly, cornerslist.begin(), cornerslist.end() ); polyset_zone_solid_areas.push_back( poly ); } } polyset_zone_solid_areas += clearance; // Put the resultng polygon in buffer for( unsigned ii = 0; ii < polyset_zone_solid_areas.size(); ii++ ) { KPolygon& poly = polyset_zone_solid_areas[ii]; CPolyPt corner( 0, 0, false ); for( unsigned jj = 0; jj < poly.size(); jj++ ) { KPolyPoint point = *(poly.begin() + jj); corner.x = point.x(); corner.y = point.y(); corner.end_contour = false; aCornerBuffer.push_back( corner ); } corner.end_contour = true; aCornerBuffer.pop_back(); aCornerBuffer.push_back( corner ); } } /** * Function TransformShapeWithClearanceToPolygon Loading
pcbnew/class_zone.cpp +11 −4 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) : m_CornerSelection = -1; m_IsFilled = false; // fill status : true when the zone is filled m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments m_priority = 0; smoothedPoly = NULL; cornerSmoothingType = ZONE_SETTING::SMOOTHING_NONE; cornerRadius = 0; Loading @@ -77,6 +78,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) : m_ZoneClearance = aZone.m_ZoneClearance; // clearance value m_ZoneMinThickness = aZone.m_ZoneMinThickness; m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons) m_priority = aZone.m_priority; m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount; m_PadOption = aZone.m_PadOption; m_ThermalReliefGap = aZone.m_ThermalReliefGap; Loading Loading @@ -677,16 +679,21 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame ) } frame->AppendMsgPanel( _( "NetName" ), msg, RED ); #if 1 // Display net code : (useful in test or debug) msg.Printf( wxT( "%d" ), GetNet() ); frame->AppendMsgPanel( _( "NetCode" ), msg, RED ); #endif // Display priority level msg.Printf( wxT( "%d" ), GetPriority() ); frame->AppendMsgPanel( _( "Priority" ), msg, BLUE ); } else { frame->AppendMsgPanel( _( "Non Copper Zone" ), wxEmptyString, RED ); } /* Display net code : (useful in test or debug) */ msg.Printf( wxT( "%d" ), GetNet() ); frame->AppendMsgPanel( _( "NetCode" ), msg, RED ); msg = board->GetLayerName( m_Layer ); frame->AppendMsgPanel( _( "Layer" ), msg, BROWN ); Loading
pcbnew/class_zone.h +39 −2 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ private: CPolyLine* smoothedPoly; // Corner-smoothed version of m_Poly int cornerSmoothingType; unsigned int cornerRadius; // Priority: when a zone outline is inside and other zone, if its priority is highter // the other zone priority, it will be created inside. // if priorities are equal, a DRC erroc is set unsigned m_priority; public: ZONE_CONTAINER( BOARD* parent ); Loading @@ -149,6 +153,18 @@ public: const wxPoint GetPosition() const; // overload void SetPosition( const wxPoint& aPos ); // overload /** * Function SetPriority * @param aPriority = the priority level */ void SetPriority( unsigned aPriority ) { m_priority = aPriority; } /** * Function GetPriority * @return the priority level of this zone */ unsigned GetPriority() const { return m_priority; } /** * Function copy * copy useful data from the source. Loading Loading @@ -305,11 +321,13 @@ public: * in order to have drawable (and plottable) filled polygons * drawable filled polygons are polygons without hole * @param aPcb: the current board (can be NULL for non copper zones) * @param aCornerBuffer: A reference to a buffer to put polygon corners, or NULL * if NULL (default), uses m_FilledPolysList and fill current zone. * @return number of polygons * This function does not add holes for pads and tracks but calls * AddClearanceAreasPolygonsToPolysList() to do that for copper layers */ int BuildFilledPolysListData( BOARD* aPcb ); int BuildFilledPolysListData( BOARD* aPcb, std::vector <CPolyPt>* aCornerBuffer = NULL ); /** * Function AddClearanceAreasPolygonsToPolysList Loading Loading @@ -484,6 +502,25 @@ public: return m_Poly->GetHatchStyle(); } /** * Function TransformShapeWithClearanceToPolygon * Convert the track shape to a closed polygon * Used in filling zones calculations * Circles (vias) and arcs (ends of tracks) are approximated by segments * @param aCornerBuffer = a buffer to store the polygon * @param aClearanceValue = the clearance around the pad * @param aCircleToSegmentsCount = the number of segments to approximate a circle * @param aCorrectionFactor = the correction to apply to circles radius to keep * @param aAddClearance = true to add a clearance area to the polygon * false to create the outline polygon. * clearance when the circle is approximated by segment bigger or equal * to the real clearance value (usually near from 1.0) */ void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool aAddClearance ); /** * Function IsSame * tests if 2 zones are equivalent: Loading
pcbnew/class_zone_setting.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ ZONE_SETTING::ZONE_SETTING( void ) { m_ZonePriority = 0; m_FillMode = 0; // Mode for filling zone : 1 use segments, 0 use polygons m_ZoneClearance = 200; // Clearance value m_ZoneMinThickness = 100; // Min thickness value in filled areas Loading @@ -50,6 +51,7 @@ ZONE_SETTING::ZONE_SETTING( void ) */ void ZONE_SETTING::ImportSetting( const ZONE_CONTAINER& aSource ) { m_ZonePriority = aSource.GetPriority(); m_FillMode = aSource.m_FillMode; m_ZoneClearance = aSource.m_ZoneClearance; m_ZoneMinThickness = aSource.m_ZoneMinThickness; Loading Loading @@ -88,6 +90,7 @@ void ZONE_SETTING::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) aTarget.SetCornerRadius( cornerRadius ); if( aFullExport ) { aTarget.SetPriority( m_ZonePriority ); aTarget.SetNet( m_NetcodeSelection ); aTarget.SetLayer( m_CurrentZone_Layer ); } Loading
pcbnew/class_zone_setting.h +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ public: // Mode for filling zone : 1 use segments, 0 use polygons int m_FillMode; int m_ZonePriority; // Priority (0 ... N) of the zone int m_ZoneClearance; // Clearance value int m_ZoneMinThickness; // Min thickness value in filled areas int m_NetcodeSelection; // Net code selection for the current zone Loading