Calculations to create filled areas in a zone modified and uses 2 pass. See changelog

This commit is contained in:
charras 2009-01-10 17:12:51 +00:00
parent a369275153
commit 30da5aff07
3 changed files with 247 additions and 170 deletions

View File

@ -5,6 +5,20 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2009-Jan-19 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++Pcbnew:
Calculations to create filled areas in a zone modified and uses 2 pass:
1 - filled areas are calculated with pads in zone.
2 - If thermal shapes are wanted, they are added (i.e. copper removed after ).
Seen comments in zones_convert_brd_items_to_polygons.cpp
The initial method was calculate filled areas in one pass.
With the 2 pass calculation, the calculation time is more expensive but:
- Kbool seems now works correctly in cases where the one pass way does not work
- Thermal reliefs can have a better shape (todo..) because when calculating them, the filled
areas are known (this was not the case in one pass way)
2009-Jan-08 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++Eeschema:

View File

@ -222,7 +222,7 @@ int Propagation( WinEDA_PcbFrame* frame )
/********************************************/
/** Function Propagation()
* An important function to calculate zones
* Used now only in autoplace calculations
* Uses the routing matrix to fill the cells within the zone
* Search and mark cells within the zone, and agree with DRC options.
* Requirements:

View File

@ -79,14 +79,29 @@ double s_Correction; /* mult coeff used to enlarge rounded and oval pads (an
* 3 - Creates a correction using BOOL_CORRECTION operation to shrink the resulting area
* with m_ZoneMinThickness/2 value.
* The result is areas with a margin of m_ZoneMinThickness/2
* When drawing outline with segments having a thickness of m_ZoneMinThickness, the outlines wilm
* When drawing outline with segments having a thickness of m_ZoneMinThickness, the outlines will
* match exactly the initial outlines
* 4 - recreates the same Bool_Engine, with no correction
* 3 - Add the main outline (zone outline) in group A
* 4 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + m_ZoneMinThickness/2
* 5 - calculates the polygon A - B
* 6 - put resulting list of polygons (filled areas) in m_FilledPolysList
* 7 - Remove insulated copper islands
* 5 - Add the main modified outline (zone outline) in group A
* 6 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + m_ZoneMinThickness/2
* 7 - calculates the polygon A - B
* 8 - put resulting list of polygons (filled areas) in m_FilledPolysList
* This zone contains pads with the same net.
* 9 - Remove insulated copper islands
* 10 - If Thermal shapes are wanted, remove copper around pads in zone, in order to create thes thermal shapes
* a - Creates a bool engine and add the last copper areas in group A
* b - Add thermal shapes (non copper ares in group B
* c - Calculates the polygon A - B
* 11 - Remove new insulated copper islands
*/
/* Important note:
* One can add thermal areas in the step 6, with others items to substract.
* It is faster.
* But :
* kbool fails sometimes in this case (see comments in AddThermalReliefPadPolygon )
* The separate step to make thermal shapes allows a more sophisticated algorith (todo)
* like remove thermal copper bridges in thermal shapes that are not connected to an area
*/
void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
{
@ -116,7 +131,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
/* First, Add the main polygon (i.e. the filled area using only one outline)
* in GroupA in Bool_Engine to do a BOOL_CORRECTION operation
* to reserve a m_ZoneMinThickness/2 margind around the outlines and holes
* the margind will be filled when redraw outilnes with segments having a whidth set to
* the margin will be filled when redraw outilnes with segments having a width set to
* m_ZoneMinThickness
* so m_ZoneMinThickness is the min thickness of the filled zones areas
*/
@ -124,7 +139,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
booleng->SetCorrectionFactor( (double) -m_ZoneMinThickness / 2 );
booleng->Do_Operation( BOOL_CORRECTION );
/* No copy the new outline in m_FilledPolysList */
/* Now copy the new outline in m_FilledPolysList */
m_FilledPolysList.clear();
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
delete booleng;
@ -155,7 +170,8 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
zone_boundingbox.Inflate( m_ZoneClearance, clearance );
/*
* First : Add pads
* First : Add pads. Note: pads having the same net as zone are left in zone.
* Thermal shapes will be created later if necessary
*/
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
{
@ -172,26 +188,11 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
continue;
}
switch( m_PadOption )
if ( (m_PadOption == PAD_NOT_IN_ZONE) || (GetNet() == 0) )
{
case PAD_NOT_IN_ZONE:
item_boundingbox = pad->GetBoundingBox();
if( item_boundingbox.Intersects( zone_boundingbox ) )
AddPadWithClearancePolygon( booleng, *pad, clearance );
break;
case THERMAL_PAD:
item_boundingbox = pad->GetBoundingBox();
item_boundingbox.Inflate( m_ThermalReliefGapValue, m_ThermalReliefGapValue );
if( item_boundingbox.Intersects( zone_boundingbox ) )
AddThermalReliefPadPolygon( booleng, *pad,
m_ThermalReliefGapValue,
m_ThermalReliefCopperBridgeValue,
m_ZoneMinThickness );
break;
case PAD_IN_ZONE:
break;
}
}
}
@ -204,7 +205,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
{
if( !track->IsOnLayer( GetLayer() ) )
continue;
if( track->GetNet() == GetNet() )
if( track->GetNet() == GetNet() && (GetNet() != 0) )
continue;
item_boundingbox = track->GetBoundingBox();
if( item_boundingbox.Intersects( zone_boundingbox ) )
@ -238,7 +239,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
}
}
/* compute copper areas */
/* calculates copper areas */
booleng->Do_Operation( BOOL_A_SUB_B );
/* put these areas in m_FilledPolysList */
@ -246,6 +247,54 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
delete booleng;
// Remove insulated islands:
if( GetNet() > 0 )
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
// Remove thermal symbols
if( m_PadOption == THERMAL_PAD )
{
booleng = new Bool_Engine();
ArmBoolEng( booleng, true );
bool have_poly_to_substract = false;
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
{
for( D_PAD* pad = module->m_Pads; pad != NULL; pad = pad->Next() )
{
if( !pad->IsOnLayer( GetLayer() ) )
continue;
if( pad->GetNet() != GetNet() )
continue;
item_boundingbox = pad->GetBoundingBox();
item_boundingbox.Inflate( m_ThermalReliefGapValue, m_ThermalReliefGapValue );
if( item_boundingbox.Intersects( zone_boundingbox ) )
{
have_poly_to_substract = true;
AddThermalReliefPadPolygon( booleng, *pad,
m_ThermalReliefGapValue,
m_ThermalReliefCopperBridgeValue,
m_ZoneMinThickness );
}
}
}
if ( have_poly_to_substract )
{
/* Add the main corrected polygon (i.e. the filled area using only one outline)
* in GroupA in Bool_Engine
*/
CopyPolygonsFromFilledPolysListToBoolengine( booleng, GROUP_A );
/* remove thermal areas (non copper areas) */
booleng->Do_Operation( BOOL_A_SUB_B );
/* put these areas in m_FilledPolysList */
m_FilledPolysList.clear();
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
}
delete booleng;
}
// Remove insulated islands:
if( GetNet() > 0 )
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
@ -361,6 +410,7 @@ void AddPadWithClearancePolygon( Bool_Engine* aBooleng,
corner_position += PadShapePos; // Shift origin to position
aBooleng->AddPoint( corner_position.x, corner_position.y );
}
for( int i = 0; i < s_CircleToSegmentsCount / 4 + 1; i++ )
{
corner_position = wxPoint( -rounding_radius, 0 );
@ -371,6 +421,7 @@ void AddPadWithClearancePolygon( Bool_Engine* aBooleng,
corner_position += PadShapePos;
aBooleng->AddPoint( corner_position.x, corner_position.y );
}
for( int i = 0; i < s_CircleToSegmentsCount / 4 + 1; i++ )
{
corner_position = wxPoint( 0, rounding_radius );
@ -381,6 +432,7 @@ void AddPadWithClearancePolygon( Bool_Engine* aBooleng,
corner_position += PadShapePos;
aBooleng->AddPoint( corner_position.x, corner_position.y );
}
for( int i = 0; i < s_CircleToSegmentsCount / 4 + 1; i++ )
{
corner_position = wxPoint( rounding_radius, 0 );
@ -415,15 +467,16 @@ void AddPadWithClearancePolygon( Bool_Engine* aBooleng,
/* WARNING:
* When Kbool calculates the filled areas :
* i.e when substarcting holes (thermal shapes) to the full zone area
* i.e when substracting holes (thermal shapes) to the full zone area
* under certains circumstances kboll drop some holes.
* These circumstances are:
* some identical holes (same thermal shape and size) are *exactly* on the same vertical line
* And
* nothing else between holes
* And
* angles less than 90 deg between 2 consecutive lines in hole outline
* And a hole above the identical holes
* angles less than 90 deg between 2 consecutive lines in hole outline (sometime occurs without this condition)
* And
* a hole above the identical holes
*
* In fact, it is easy to find these conditions in pad arrays.
* So to avoid this, the workaround is do not use holes outlines that include
@ -529,6 +582,7 @@ void AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
// this seems a bug in kbool polygon (exists in 1.9 kbool version)
// angle = 450 (45.0 degrees orientation) seems work fine.
// angle = 0 with thermal shapes without angle < 90 deg has problems in rare circumstances
// Note: with the 2 step build ( thermal shpaes after correr areas build), 0 seems work
angle = 450;
int angle_pad = aPad.m_Orient; // Pad orientation
for( unsigned ihole = 0; ihole < 4; ihole++ )
@ -778,6 +832,7 @@ void AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
angle -= 3600;
}
}
break;
}
}
@ -948,7 +1003,8 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB
/************************************************************************************************************/
/** Function CopyPolygonsFromFilledPolysListToBoolengine
* Copy (Add) polygons created by kbool (after Do_Operation) to m_FilledPolysList
* Copy (Add) polygons found in m_FilledPolysList to kbool BoolEngine
* m_FilledPolysList may have more than one polygon
* @param aBoolengine = kbool engine
* @param aGroup = group in kbool engine (GROUP_A or GROUP_B only)
* @return the corner count
@ -958,6 +1014,8 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB
int count = 0;
unsigned ic = 0;
while( ic < corners_count )
{
if( aBoolengine->StartPolygonAdd( aGroup ) )
{
for( ; ic < corners_count; ic++ )
@ -966,11 +1024,15 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB
aBoolengine->AddPoint( corner->x, corner->y );
count++;
if( corner->end_contour )
{
ic++;
break;
}
}
aBoolengine->EndPolygonAdd();
}
}
return count;
}
@ -996,6 +1058,7 @@ int ZONE_CONTAINER::CopyPolygonsFromBoolengineToFilledPolysList( Bool_Engine* aB
corner.x = (int) aBoolengine->GetPolygonXPoint();
corner.y = (int) aBoolengine->GetPolygonYPoint();
corner.end_contour = false;
// Flag this corner if starting a hole connection segment:
corner.utility = (aBoolengine->GetPolygonPointEdgeType() == KB_FALSE_EDGE) ? 1 : 0;
m_FilledPolysList.push_back( corner );