2011-09-23 20:00:30 +00:00
|
|
|
/**
|
|
|
|
* @file zones_convert_to_polygons_aux_functions.cpp
|
|
|
|
*/
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-05-01 19:01:14 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-08 09:56:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <PolyLine.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <trigo.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_zone.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <zones.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
/* Function TransformOutlinesShapeWithClearanceToPolygon
|
|
|
|
* Convert the zone filled areas polygons to polygons
|
|
|
|
* inflated (optional) by max( aClearanceValue, the zone clearance)
|
|
|
|
* and copy them in aCornerBuffer
|
|
|
|
* param aClearanceValue = the clearance around polygons
|
|
|
|
* param aAddClearance = true to add a clearance area to the polygon
|
|
|
|
* false to create the outline polygon.
|
|
|
|
*/
|
|
|
|
void ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET& aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2015-07-27 19:47:49 +00:00
|
|
|
// Creates the zone outline polygon (with holes if any)
|
|
|
|
SHAPE_POLY_SET polybuffer;
|
|
|
|
BuildFilledSolidAreasPolygons( NULL, &polybuffer );
|
2013-05-01 19:01:14 +00:00
|
|
|
|
|
|
|
// add clearance to outline
|
2014-12-19 19:09:53 +00:00
|
|
|
int clearance = aMinClearanceValue;
|
2014-11-30 17:07:02 +00:00
|
|
|
|
2015-08-01 10:20:23 +00:00
|
|
|
if( aUseNetClearance && IsOnCopperLayer() )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
|
|
|
clearance = GetClearance();
|
2014-12-19 19:09:53 +00:00
|
|
|
if( aMinClearanceValue > clearance )
|
|
|
|
clearance = aMinClearanceValue;
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
2014-12-19 19:09:53 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
// Calculate the polygon with clearance
|
2014-11-30 17:07:02 +00:00
|
|
|
// holes are linked to the main outline, so only one polygon is created.
|
|
|
|
if( clearance )
|
2015-07-27 19:47:49 +00:00
|
|
|
polybuffer.Inflate( clearance, 16 );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2015-07-27 19:47:49 +00:00
|
|
|
aCornerBuffer.Append( polybuffer );
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function BuildUnconnectedThermalStubsPolygonList
|
|
|
|
* Creates a set of polygons corresponding to stubs created by thermal shapes on pads
|
|
|
|
* which are not connected to a zone (dangling bridges)
|
2015-07-27 19:45:57 +00:00
|
|
|
* @param aCornerBuffer = a SHAPE_POLY_SET where to store polygons
|
2011-09-23 20:00:30 +00:00
|
|
|
* @param aPcb = the board.
|
|
|
|
* @param aZone = a pointer to the ZONE_CONTAINER to examine.
|
|
|
|
* @param aArcCorrection = a pointer to the ZONE_CONTAINER to examine.
|
|
|
|
* @param aRoundPadThermalRotation = the rotation in 1.0 degree for thermal stubs in round pads
|
|
|
|
*/
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
void BuildUnconnectedThermalStubsPolygonList( SHAPE_POLY_SET& aCornerBuffer,
|
2011-09-23 20:00:30 +00:00
|
|
|
BOARD* aPcb,
|
|
|
|
ZONE_CONTAINER* aZone,
|
|
|
|
double aArcCorrection,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aRoundPadThermalRotation )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
|
|
|
std::vector<wxPoint> corners_buffer; // a local polygon buffer to store one stub
|
|
|
|
corners_buffer.reserve( 4 );
|
|
|
|
wxPoint ptTest[4];
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
int zone_clearance = aZone->GetZoneClearance();
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
EDA_RECT item_boundingbox;
|
|
|
|
EDA_RECT zone_boundingbox = aZone->GetBoundingBox();
|
2014-05-13 09:22:51 +00:00
|
|
|
int biggest_clearance = aPcb->GetDesignSettings().GetBiggestClearanceValue();
|
2012-08-03 15:43:15 +00:00
|
|
|
biggest_clearance = std::max( biggest_clearance, zone_clearance );
|
2011-09-23 20:00:30 +00:00
|
|
|
zone_boundingbox.Inflate( biggest_clearance );
|
|
|
|
|
|
|
|
// half size of the pen used to draw/plot zones outlines
|
2013-03-18 19:36:07 +00:00
|
|
|
int pen_radius = aZone->GetMinThickness() / 2;
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
2017-04-25 09:06:24 +00:00
|
|
|
for( D_PAD* pad = module->PadsList(); pad != NULL; pad = pad->Next() )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2012-07-09 07:10:07 +00:00
|
|
|
// Rejects non-standard pads with tht-only thermal reliefs
|
2015-08-18 14:19:17 +00:00
|
|
|
if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_THT_THERMAL
|
2015-08-23 19:40:33 +00:00
|
|
|
&& pad->GetAttribute() != PAD_ATTRIB_STANDARD )
|
2012-07-09 07:10:07 +00:00
|
|
|
continue;
|
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
if( aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THERMAL
|
|
|
|
&& aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THT_THERMAL )
|
2012-02-24 23:23:46 +00:00
|
|
|
continue;
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
// check
|
|
|
|
if( !pad->IsOnLayer( aZone->GetLayer() ) )
|
|
|
|
continue;
|
2012-02-24 23:23:46 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode() )
|
2011-09-23 20:00:30 +00:00
|
|
|
continue;
|
|
|
|
|
2013-02-09 20:03:20 +00:00
|
|
|
// Calculate thermal bridge half width
|
|
|
|
int thermalBridgeWidth = aZone->GetThermalReliefCopperBridge( pad )
|
2013-03-18 19:36:07 +00:00
|
|
|
- aZone->GetMinThickness();
|
2013-02-09 20:03:20 +00:00
|
|
|
if( thermalBridgeWidth <= 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// we need the thermal bridge half width
|
|
|
|
// with a small extra size to be sure we create a stub
|
|
|
|
// slightly larger than the actual stub
|
|
|
|
thermalBridgeWidth = ( thermalBridgeWidth + 4 ) / 2;
|
|
|
|
|
|
|
|
int thermalReliefGap = aZone->GetThermalReliefGap( pad );
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
item_boundingbox = pad->GetBoundingBox();
|
2012-08-22 20:16:21 +00:00
|
|
|
item_boundingbox.Inflate( thermalReliefGap );
|
2011-09-23 20:00:30 +00:00
|
|
|
if( !( item_boundingbox.Intersects( zone_boundingbox ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Thermal bridges are like a segment from a starting point inside the pad
|
|
|
|
// to an ending point outside the pad
|
2013-02-09 20:03:20 +00:00
|
|
|
|
|
|
|
// calculate the ending point of the thermal pad, outside the pad
|
|
|
|
wxPoint endpoint;
|
2012-08-22 20:16:21 +00:00
|
|
|
endpoint.x = ( pad->GetSize().x / 2 ) + thermalReliefGap;
|
|
|
|
endpoint.y = ( pad->GetSize().y / 2 ) + thermalReliefGap;
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2013-02-09 20:03:20 +00:00
|
|
|
// Calculate the starting point of the thermal stub
|
|
|
|
// inside the pad
|
|
|
|
wxPoint startpoint;
|
|
|
|
int copperThickness = aZone->GetThermalReliefCopperBridge( pad )
|
2013-03-18 19:36:07 +00:00
|
|
|
- aZone->GetMinThickness();
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
if( copperThickness < 0 )
|
|
|
|
copperThickness = 0;
|
|
|
|
|
2013-02-09 20:03:20 +00:00
|
|
|
// Leave a small extra size to the copper area inside to pad
|
2013-05-04 11:57:09 +00:00
|
|
|
copperThickness += KiROUND( IU_PER_MM * 0.04 );
|
2013-02-09 20:03:20 +00:00
|
|
|
|
2012-08-03 15:43:15 +00:00
|
|
|
startpoint.x = std::min( pad->GetSize().x, copperThickness );
|
|
|
|
startpoint.y = std::min( pad->GetSize().y, copperThickness );
|
2013-02-09 20:03:20 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
startpoint.x /= 2;
|
|
|
|
startpoint.y /= 2;
|
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
// This is a CIRCLE pad tweak
|
|
|
|
// for circle pads, the thermal stubs orientation is 45 deg
|
2013-05-05 07:17:48 +00:00
|
|
|
double fAngle = pad->GetOrientation();
|
2015-08-23 19:40:33 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE_CIRCLE )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2013-05-04 11:57:09 +00:00
|
|
|
endpoint.x = KiROUND( endpoint.x * aArcCorrection );
|
2011-09-23 20:00:30 +00:00
|
|
|
endpoint.y = endpoint.x;
|
|
|
|
fAngle = aRoundPadThermalRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// contour line width has to be taken into calculation to avoid "thermal stub bleed"
|
|
|
|
endpoint.x += pen_radius;
|
|
|
|
endpoint.y += pen_radius;
|
|
|
|
// compute north, south, west and east points for zone connection.
|
|
|
|
ptTest[0] = wxPoint( 0, endpoint.y ); // lower point
|
|
|
|
ptTest[1] = wxPoint( 0, -endpoint.y ); // upper point
|
|
|
|
ptTest[2] = wxPoint( endpoint.x, 0 ); // right point
|
|
|
|
ptTest[3] = wxPoint( -endpoint.x, 0 ); // left point
|
|
|
|
|
|
|
|
// Test all sides
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
// rotate point
|
|
|
|
RotatePoint( &ptTest[i], fAngle );
|
|
|
|
|
|
|
|
// translate point
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
ptTest[i] += pad->ShapePos();
|
2013-02-09 20:03:20 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
if( aZone->HitTestFilledArea( ptTest[i] ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
corners_buffer.clear();
|
|
|
|
|
|
|
|
// polygons are rectangles with width of copper bridge value
|
|
|
|
switch( i )
|
|
|
|
{
|
|
|
|
case 0: // lower stub
|
2012-08-22 20:16:21 +00:00
|
|
|
corners_buffer.push_back( wxPoint( -thermalBridgeWidth, endpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +thermalBridgeWidth, endpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +thermalBridgeWidth, startpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -thermalBridgeWidth, startpoint.y ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // upper stub
|
2012-08-22 20:16:21 +00:00
|
|
|
corners_buffer.push_back( wxPoint( -thermalBridgeWidth, -endpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +thermalBridgeWidth, -endpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +thermalBridgeWidth, -startpoint.y ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -thermalBridgeWidth, -startpoint.y ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // right stub
|
2012-08-22 20:16:21 +00:00
|
|
|
corners_buffer.push_back( wxPoint( endpoint.x, -thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( endpoint.x, thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +startpoint.x, thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +startpoint.x, -thermalBridgeWidth ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // left stub
|
2012-08-22 20:16:21 +00:00
|
|
|
corners_buffer.push_back( wxPoint( -endpoint.x, -thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -endpoint.x, thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -startpoint.x, thermalBridgeWidth ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -startpoint.x, -thermalBridgeWidth ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
aCornerBuffer.NewOutline();
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
// add computed polygon to list
|
|
|
|
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
|
|
|
{
|
|
|
|
wxPoint cpos = corners_buffer[ic];
|
|
|
|
RotatePoint( &cpos, fAngle ); // Rotate according to module orientation
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
cpos += pad->ShapePos(); // Shift origin to position
|
2015-07-27 19:45:57 +00:00
|
|
|
aCornerBuffer.Append( cpos.x, cpos.y );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|