2008-11-09 15:01:35 +00:00
|
|
|
/*******************************************/
|
|
|
|
/* zones_convert_brd_items_to_polygons.cpp */
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
/* Functions to convert some board items to polygons
|
2009-01-10 17:12:51 +00:00
|
|
|
* (pads, tracks ..)
|
|
|
|
* This is used to calculate filled areas in copper zones.
|
|
|
|
* Filled areas are areas remainder of the full zone area after removed all polygons
|
|
|
|
* calculated from these items shapes and the clearance area
|
|
|
|
*
|
|
|
|
* Important note:
|
|
|
|
* Because filled areas must have a minimum thickness to match with Design rule, they are draw in 2 step:
|
|
|
|
* 1 - filled polygons are drawn
|
|
|
|
* 2 - polygon outlines are drawn with a "minimum thickness width" ( or with a minimum thickness pen )
|
|
|
|
* So outlines of filled polygons are calculated with the constraint they match with clearance,
|
|
|
|
* taking in account outlines have thickness
|
|
|
|
* This ensures:
|
|
|
|
* - areas meet the minimum thickness requirement.
|
|
|
|
* - shapes are smoothed.
|
2008-11-24 20:46:41 +00:00
|
|
|
*/
|
2008-11-09 15:01:35 +00:00
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
2009-09-10 13:04:04 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2008-10-02 13:24:31 +00:00
|
|
|
#include "trigo.h"
|
|
|
|
|
|
|
|
#include "zones.h"
|
|
|
|
|
|
|
|
#include "PolyLine.h"
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
// Kbool 1.9 and before had sometimes problemes when calculating thermal shapes as polygons (this is the best solution)
|
|
|
|
// Kbool 2.0 has solved some problems, but not all
|
2009-09-17 17:48:40 +00:00
|
|
|
// Kbool 2.1 has solved some others problems, but not all
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
// Used to create data files to debug Kbool
|
|
|
|
#include "debug_kbool_key_file_fct.h"
|
|
|
|
|
|
|
|
// Also we can create test files for Kbool bebug purposes
|
|
|
|
// when CREATE_KBOOL_KEY_FILES is defined
|
|
|
|
// See debug_kbool_key_file_fct.h
|
2009-05-21 17:42:42 +00:00
|
|
|
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb,
|
|
|
|
ZONE_CONTAINER* aZone_container );
|
2009-11-16 08:13:40 +00:00
|
|
|
extern void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer,
|
2009-11-14 19:47:52 +00:00
|
|
|
wxPoint aStart, wxPoint aEnd,
|
|
|
|
int aCircleToSegmentsCount,
|
|
|
|
int aWidth );
|
2008-10-11 19:27:43 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
void CreateThermalReliefPadPolygon( std::vector<CPolyPt>& aCornerBuffer,
|
|
|
|
D_PAD& aPad,
|
|
|
|
int aThermalGap,
|
|
|
|
int aCopperThickness,
|
|
|
|
int aMinThicknessValue,
|
|
|
|
int aCircleToSegmentsCount,
|
|
|
|
double aCorrectionFactor,
|
|
|
|
int aThermalRot );
|
|
|
|
|
2008-10-11 19:27:43 +00:00
|
|
|
|
2008-10-07 09:32:56 +00:00
|
|
|
// Local Functions:
|
2009-11-16 08:13:40 +00:00
|
|
|
void AddTrackWithClearancePolygon( Bool_Engine* aBooleng,
|
|
|
|
TRACK& aTrack, int aClearanceValue );
|
|
|
|
void AddPadWithClearancePolygon( Bool_Engine* aBooleng, D_PAD& aPad, int aClearanceValue );
|
|
|
|
int AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
|
|
|
|
D_PAD& aPad,
|
|
|
|
int aThermalGap,
|
|
|
|
int aCopperThickness, int aMinThicknessValue );
|
|
|
|
void AddRoundedEndsSegmentPolygon( Bool_Engine* aBooleng,
|
|
|
|
wxPoint aStart, wxPoint aEnd,
|
|
|
|
int aWidth );
|
2008-10-07 09:32:56 +00:00
|
|
|
|
|
|
|
// Local Variables:
|
2008-10-02 13:24:31 +00:00
|
|
|
/* how many segments are used to create a polygon from a circle: */
|
2010-01-12 13:15:13 +00:00
|
|
|
static int s_CircleToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF; /* default value. the real value will be changed to
|
|
|
|
* ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF
|
|
|
|
* if m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF
|
|
|
|
*/
|
2008-11-09 15:01:35 +00:00
|
|
|
double s_Correction; /* mult coeff used to enlarge rounded and oval pads (and vias)
|
|
|
|
* because the segment approximation for arcs and circles
|
|
|
|
* create a smaller gap than a true circle
|
|
|
|
*/
|
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
/** function AddClearanceAreasPolygonsToPolysList
|
2008-11-22 20:50:30 +00:00
|
|
|
* Supports a min thickness area constraint.
|
2008-10-02 13:24:31 +00:00
|
|
|
* Add non copper areas polygons (pads and tracks with clearence)
|
2008-11-22 20:50:30 +00:00
|
|
|
* to the filled copper area found
|
|
|
|
* in BuildFilledPolysListData after calculating filled areas in a zone
|
|
|
|
* Non filled copper areas are pads and track and their clearance areas
|
2008-10-02 13:24:31 +00:00
|
|
|
* The filled copper area must be computed just before.
|
|
|
|
* BuildFilledPolysListData() call this function just after creating the
|
|
|
|
* filled copper area polygon (without clearence areas
|
|
|
|
* to do that this function:
|
2008-11-09 20:36:40 +00:00
|
|
|
* 1 - creates a Bool_Engine,with option: holes are linked to outer contours by double overlapping segments
|
|
|
|
* this means the created polygons have no holes (hole are linked to outer outline by double overlapped segments
|
|
|
|
* and are therefore compatible with draw functions (DC draw polygons and Gerber or PS outputs)
|
2008-10-02 13:24:31 +00:00
|
|
|
* 2 - Add the main outline (zone outline) in group A
|
2008-11-23 17:43:53 +00:00
|
|
|
* 3 - Creates a correction using BOOL_CORRECTION operation to shrink the resulting area
|
2008-11-22 20:50:30 +00:00
|
|
|
* with m_ZoneMinThickness/2 value.
|
|
|
|
* The result is areas with a margin of m_ZoneMinThickness/2
|
2009-01-10 17:12:51 +00:00
|
|
|
* When drawing outline with segments having a thickness of m_ZoneMinThickness, the outlines will
|
2008-11-22 20:50:30 +00:00
|
|
|
* match exactly the initial outlines
|
|
|
|
* 4 - recreates the same Bool_Engine, with no correction
|
2009-01-10 17:12:51 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-01-18 13:14:50 +00:00
|
|
|
/* 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
|
2008-10-02 13:24:31 +00:00
|
|
|
*/
|
|
|
|
void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
|
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
bool have_poly_to_substract = false;
|
|
|
|
|
2008-10-10 11:31:46 +00:00
|
|
|
// Set the number of segments in arc approximations
|
2010-01-12 13:15:13 +00:00
|
|
|
if( m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF )
|
|
|
|
s_CircleToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF;
|
2008-10-10 11:31:46 +00:00
|
|
|
else
|
2010-01-12 13:15:13 +00:00
|
|
|
s_CircleToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF;
|
2008-10-10 11:31:46 +00:00
|
|
|
|
2008-10-31 17:02:24 +00:00
|
|
|
/* calculates the coeff to compensate radius reduction of holes clearance
|
2008-11-09 15:01:35 +00:00
|
|
|
* due to the segment approx.
|
|
|
|
* For a circle the min radius is radius * cos( 2PI / s_CircleToSegmentsCount / 2)
|
|
|
|
* s_Correction is 1 /cos( PI/s_CircleToSegmentsCount )
|
|
|
|
*/
|
|
|
|
s_Correction = 1.0 / cos( 3.14159265 / s_CircleToSegmentsCount );
|
2008-10-31 17:02:24 +00:00
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
/* Uses a kbool engine to add holes in the m_FilledPolysList polygon.
|
|
|
|
* Because this function is called just after creating the m_FilledPolysList,
|
|
|
|
* only one polygon is in list.
|
2008-11-22 20:50:30 +00:00
|
|
|
* (initial holes in zones are linked into outer contours by double overlapping segments).
|
|
|
|
* because after adding holes, many polygons could be exist in this list.
|
2008-10-02 13:24:31 +00:00
|
|
|
*/
|
|
|
|
|
2008-10-13 18:39:38 +00:00
|
|
|
Bool_Engine* booleng = new Bool_Engine();
|
2008-10-02 13:24:31 +00:00
|
|
|
ArmBoolEng( booleng, true );
|
|
|
|
|
2008-11-22 20:50:30 +00:00
|
|
|
/* 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
|
2009-01-10 17:12:51 +00:00
|
|
|
* the margin will be filled when redraw outilnes with segments having a width set to
|
2008-11-22 20:50:30 +00:00
|
|
|
* m_ZoneMinThickness
|
|
|
|
* so m_ZoneMinThickness is the min thickness of the filled zones areas
|
2008-10-02 13:24:31 +00:00
|
|
|
*/
|
2008-11-23 17:43:53 +00:00
|
|
|
CopyPolygonsFromFilledPolysListToBoolengine( booleng, GROUP_A );
|
2008-11-24 20:46:41 +00:00
|
|
|
booleng->SetCorrectionFactor( (double) -m_ZoneMinThickness / 2 );
|
2008-11-22 20:50:30 +00:00
|
|
|
booleng->Do_Operation( BOOL_CORRECTION );
|
|
|
|
|
2009-01-10 17:12:51 +00:00
|
|
|
/* Now copy the new outline in m_FilledPolysList */
|
2008-11-22 20:50:30 +00:00
|
|
|
m_FilledPolysList.clear();
|
2008-11-23 17:43:53 +00:00
|
|
|
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
|
2008-11-22 20:50:30 +00:00
|
|
|
delete booleng;
|
|
|
|
|
2009-03-19 18:11:37 +00:00
|
|
|
if( m_FilledPolysList.size() == 0 )
|
2009-03-16 19:51:23 +00:00
|
|
|
return;
|
|
|
|
|
2008-11-22 20:50:30 +00:00
|
|
|
/* Second, Add the main (corrected) polygon (i.e. the filled area using only one outline)
|
|
|
|
* in GroupA in Bool_Engine to do a BOOL_A_SUB_B operation
|
|
|
|
* All areas to remove will be put in GroupB in Bool_Engine
|
|
|
|
*/
|
|
|
|
booleng = new Bool_Engine();
|
|
|
|
ArmBoolEng( booleng, true );
|
|
|
|
|
2009-10-21 19:16:25 +00:00
|
|
|
/* Calculates the clearance value that meet DRC requirements
|
|
|
|
* from m_ZoneClearance and clearance from the corresponding netclass
|
|
|
|
* We have a "local" clearance in zones because most of time
|
|
|
|
* clearance between a zone and others items is bigger than the netclass clearance
|
|
|
|
* this is more true for small clearance values
|
|
|
|
* Note also the "local" clearance is used for clearance between non copper items
|
|
|
|
* or items like texts on copper layers
|
|
|
|
*/
|
|
|
|
int zone_clearance = max( m_ZoneClearance, GetClearance() );
|
|
|
|
zone_clearance += m_ZoneMinThickness / 2;
|
2008-11-22 20:50:30 +00:00
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
/* Add holes (i.e. tracks and pads areas as polygons outlines)
|
|
|
|
* in GroupB in Bool_Engine
|
2008-10-19 18:18:45 +00:00
|
|
|
*/
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-10-21 19:16:25 +00:00
|
|
|
/* items ouside the zone bounding box are skipped
|
2009-11-14 19:47:52 +00:00
|
|
|
* the bounding box is the zone bounding box + the biggest clearance found in Netclass list
|
|
|
|
*/
|
2008-10-19 18:18:45 +00:00
|
|
|
EDA_Rect item_boundingbox;
|
2009-11-14 19:47:52 +00:00
|
|
|
EDA_Rect zone_boundingbox = GetBoundingBox();
|
|
|
|
int biggest_clearance = aPcb->GetBiggestClearanceValue();
|
2009-10-21 19:16:25 +00:00
|
|
|
biggest_clearance = MAX( biggest_clearance, zone_clearance );
|
|
|
|
zone_boundingbox.Inflate( biggest_clearance, biggest_clearance );
|
2008-11-09 15:01:35 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS
|
|
|
|
CreateKeyFile();
|
|
|
|
OpenKeyFileEntity( "Layer_fp" );
|
|
|
|
CopyPolygonsFromFilledPolysListToKeyFile( this, 0 );
|
|
|
|
#endif
|
|
|
|
|
2008-10-19 18:18:45 +00:00
|
|
|
/*
|
2009-01-10 17:12:51 +00:00
|
|
|
* First : Add pads. Note: pads having the same net as zone are left in zone.
|
|
|
|
* Thermal shapes will be created later if necessary
|
2008-10-02 13:24:31 +00:00
|
|
|
*/
|
2009-10-21 19:16:25 +00:00
|
|
|
int item_clearance;
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = false;
|
2010-01-03 16:47:46 +00:00
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
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;
|
2008-10-07 09:32:56 +00:00
|
|
|
|
|
|
|
if( pad->GetNet() != GetNet() )
|
|
|
|
{
|
2009-11-14 19:47:52 +00:00
|
|
|
item_clearance = pad->GetClearance() + (m_ZoneMinThickness / 2);
|
2008-10-19 18:18:45 +00:00
|
|
|
item_boundingbox = pad->GetBoundingBox();
|
2008-11-09 15:01:35 +00:00
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
2009-03-16 19:51:23 +00:00
|
|
|
{
|
2009-11-14 19:47:52 +00:00
|
|
|
AddPadWithClearancePolygon( booleng, *pad, MAX( zone_clearance, item_clearance ) );
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = true;
|
|
|
|
}
|
2008-10-02 13:41:03 +00:00
|
|
|
continue;
|
2008-10-07 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 19:16:25 +00:00
|
|
|
int gap = zone_clearance;
|
2009-03-19 18:11:37 +00:00
|
|
|
if( (m_PadOption == PAD_NOT_IN_ZONE)
|
|
|
|
|| (GetNet() == 0) || pad->m_PadShape == PAD_TRAPEZOID )
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
// PAD_TRAPEZOID shapes are not in zones because they are used in microwave apps
|
2009-11-14 19:47:52 +00:00
|
|
|
// and i think it is good that shapes are not changed by thermal pads or others
|
2008-10-07 09:32:56 +00:00
|
|
|
{
|
2008-10-19 18:18:45 +00:00
|
|
|
item_boundingbox = pad->GetBoundingBox();
|
2008-11-09 15:01:35 +00:00
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
2009-03-16 19:51:23 +00:00
|
|
|
{
|
2009-09-10 13:04:04 +00:00
|
|
|
AddPadWithClearancePolygon( booleng, *pad, gap );
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = true;
|
|
|
|
}
|
2008-10-07 09:32:56 +00:00
|
|
|
}
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add holes (i.e. tracks and pads areas as polygons outlines)
|
|
|
|
* in GroupB in Bool_Engine
|
|
|
|
* Next : Add tracks and vias
|
|
|
|
*/
|
|
|
|
for( TRACK* track = aPcb->m_Track; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( !track->IsOnLayer( GetLayer() ) )
|
|
|
|
continue;
|
2009-01-10 17:12:51 +00:00
|
|
|
if( track->GetNet() == GetNet() && (GetNet() != 0) )
|
2008-10-02 13:41:03 +00:00
|
|
|
continue;
|
2009-10-21 19:16:25 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
item_clearance = track->GetClearance() + (m_ZoneMinThickness / 2);
|
2008-10-19 18:18:45 +00:00
|
|
|
item_boundingbox = track->GetBoundingBox();
|
2008-11-09 15:01:35 +00:00
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
2009-03-16 19:51:23 +00:00
|
|
|
{
|
2009-11-14 19:47:52 +00:00
|
|
|
AddTrackWithClearancePolygon( booleng, *track, MAX( zone_clearance, item_clearance ) );
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = true;
|
|
|
|
}
|
2009-03-19 18:11:37 +00:00
|
|
|
}
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
static std::vector <CPolyPt> cornerBuffer;
|
|
|
|
cornerBuffer.clear();
|
|
|
|
/* Add module edge items that are on copper layers
|
|
|
|
* Pcbnew allows these items to be on copper layers in microwvae applictions
|
|
|
|
* This is a bad thing, but must be handle here, until a better way is found
|
|
|
|
*/
|
|
|
|
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item = module->m_Drawings; item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( GetLayer() ) )
|
|
|
|
continue;
|
|
|
|
if( item->Type( ) != TYPE_EDGE_MODULE)
|
|
|
|
continue;
|
|
|
|
item_boundingbox = item->GetBoundingBox();
|
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
|
|
|
{
|
|
|
|
(( EDGE_MODULE* )item)->TransformShapeWithClearanceToPolygon(
|
|
|
|
cornerBuffer, m_ZoneClearance,
|
|
|
|
s_CircleToSegmentsCount, s_Correction );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
// Add graphic items (copper texts) and board edges
|
2008-10-02 13:24:31 +00:00
|
|
|
for( BOARD_ITEM* item = aPcb->m_Drawings; item; item = item->Next() )
|
|
|
|
{
|
2008-10-07 09:32:56 +00:00
|
|
|
if( item->GetLayer() != GetLayer() && item->GetLayer() != EDGE_N )
|
|
|
|
continue;
|
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_DRAWSEGMENT:
|
2009-11-16 08:13:40 +00:00
|
|
|
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon(
|
|
|
|
cornerBuffer,
|
|
|
|
m_ZoneClearance,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
s_Correction );
|
2008-10-02 13:24:31 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE:
|
2009-11-16 08:13:40 +00:00
|
|
|
( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygon(
|
|
|
|
cornerBuffer,
|
|
|
|
m_ZoneClearance,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
s_Correction );
|
2008-10-02 13:24:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
// cornerBuffer contains more than one polygon,
|
|
|
|
// so read cornerBuffer and verify if there is a end of polygon corner:
|
|
|
|
for( unsigned icnt = 0; icnt < cornerBuffer.size(); )
|
|
|
|
{
|
|
|
|
booleng->StartPolygonAdd( GROUP_B );
|
2009-11-16 08:13:40 +00:00
|
|
|
{
|
2009-11-20 19:51:39 +00:00
|
|
|
have_poly_to_substract = true;
|
|
|
|
unsigned ii;
|
|
|
|
for( ii = icnt; ii < cornerBuffer.size(); ii++ )
|
2009-11-16 08:13:40 +00:00
|
|
|
{
|
2009-11-20 19:51:39 +00:00
|
|
|
booleng->AddPoint( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
|
|
|
if( cornerBuffer[ii].end_contour )
|
|
|
|
break;
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
booleng->EndPolygonAdd();
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS
|
|
|
|
StartKeyFilePolygon( 1 );
|
|
|
|
for( ii = icnt; ii < cornerBuffer.size(); ii++ )
|
|
|
|
{
|
|
|
|
AddKeyFilePointXY( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
|
|
|
if( cornerBuffer[ii].end_contour )
|
|
|
|
break;
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
EndKeyFilePolygon();
|
|
|
|
#endif
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
icnt = ii + 1;
|
2009-11-16 08:13:40 +00:00
|
|
|
}
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS
|
|
|
|
CloseKeyFileEntity();
|
|
|
|
CloseKeyFile();
|
|
|
|
#endif
|
2009-02-23 16:04:11 +00:00
|
|
|
/* calculates copper areas */
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-03-19 18:11:37 +00:00
|
|
|
if( have_poly_to_substract )
|
2009-03-16 19:51:23 +00:00
|
|
|
{
|
2010-01-03 16:47:46 +00:00
|
|
|
/* Add the main corrected polygon (i.e. the filled area using only one outline)
|
|
|
|
* in GroupA in Bool_Engine
|
|
|
|
*/
|
|
|
|
CopyPolygonsFromFilledPolysListToBoolengine( booleng, GROUP_A );
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
booleng->Do_Operation( BOOL_A_SUB_B );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
/* put these areas in m_FilledPolysList */
|
|
|
|
m_FilledPolysList.clear();
|
|
|
|
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
|
|
|
|
}
|
2008-10-02 13:24:31 +00:00
|
|
|
delete booleng;
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-02-23 16:04:11 +00:00
|
|
|
// Remove insulated islands:
|
2009-01-10 17:12:51 +00:00
|
|
|
if( GetNet() > 0 )
|
|
|
|
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
// remove thermal gaps if required:
|
|
|
|
if( m_PadOption != THERMAL_PAD || aPcb->m_Modules == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-02-23 16:04:11 +00:00
|
|
|
// Remove thermal symbols
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = false;
|
|
|
|
|
2009-01-10 17:12:51 +00:00
|
|
|
if( m_PadOption == THERMAL_PAD )
|
|
|
|
{
|
|
|
|
booleng = new Bool_Engine();
|
|
|
|
ArmBoolEng( booleng, true );
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = false;
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES
|
2009-11-14 19:47:52 +00:00
|
|
|
CreateKeyFile();
|
|
|
|
OpenKeyFileEntity( "Layer" );
|
|
|
|
CopyPolygonsFromFilledPolysListToKeyFile( this, 0 );
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-10 17:12:51 +00:00
|
|
|
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 ) )
|
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
if( AddThermalReliefPadPolygon( booleng, *pad,
|
2009-01-10 17:12:51 +00:00
|
|
|
m_ThermalReliefGapValue,
|
|
|
|
m_ThermalReliefCopperBridgeValue,
|
2009-11-16 08:13:40 +00:00
|
|
|
m_ZoneMinThickness ) )
|
|
|
|
have_poly_to_substract = true;
|
2009-01-10 17:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES
|
2009-11-14 19:47:52 +00:00
|
|
|
CloseKeyFileEntity();
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2009-01-18 13:14:50 +00:00
|
|
|
if( have_poly_to_substract )
|
2009-01-10 17:12:51 +00:00
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
// Remove insulated islands:
|
|
|
|
if( GetNet() > 0 )
|
|
|
|
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
|
2009-09-10 13:04:04 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES
|
2009-11-14 19:47:52 +00:00
|
|
|
CloseKeyFile();
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif
|
2009-03-16 19:51:23 +00:00
|
|
|
}
|
2009-01-18 13:14:50 +00:00
|
|
|
|
2009-01-15 14:32:29 +00:00
|
|
|
// Now we remove all unused thermal stubs.
|
2009-08-23 15:22:44 +00:00
|
|
|
#define REMOVE_UNUSED_THERMAL_STUBS // Can be commented to skip unused thermal stubs calculations
|
|
|
|
#ifdef REMOVE_UNUSED_THERMAL_STUBS
|
2009-01-18 13:14:50 +00:00
|
|
|
|
2009-02-23 16:04:11 +00:00
|
|
|
/* Add the main (corrected) polygon (i.e. the filled area using only one outline)
|
|
|
|
* in GroupA in Bool_Engine to do a BOOL_A_SUB_B operation
|
|
|
|
* All areas to remove will be put in GroupB in Bool_Engine
|
|
|
|
*/
|
2009-01-15 14:32:29 +00:00
|
|
|
booleng = new Bool_Engine();
|
|
|
|
ArmBoolEng( booleng, true );
|
|
|
|
|
|
|
|
|
2009-02-23 16:04:11 +00:00
|
|
|
/*
|
|
|
|
* Test and add polygons to remove thermal stubs.
|
|
|
|
*/
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = false;
|
2009-01-15 14:32:29 +00:00
|
|
|
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad = module->m_Pads; pad != NULL; pad = pad->Next() )
|
|
|
|
{
|
|
|
|
// check
|
2009-01-18 13:14:50 +00:00
|
|
|
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 ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// test point
|
|
|
|
int dx =
|
|
|
|
( pad->m_Size.x / 2 ) + m_ThermalReliefGapValue;
|
|
|
|
int dy =
|
|
|
|
( pad->m_Size.y / 2 ) + m_ThermalReliefGapValue;
|
|
|
|
|
|
|
|
// This is CIRCLE pad tweak (for circle pads the thermal stubs are at 45 deg)
|
2009-03-19 18:11:37 +00:00
|
|
|
int fAngle = pad->m_Orient;
|
2009-01-18 13:14:50 +00:00
|
|
|
if( pad->m_PadShape == PAD_CIRCLE )
|
2009-01-15 14:32:29 +00:00
|
|
|
{
|
2009-11-14 19:47:52 +00:00
|
|
|
dx = (int) ( dx * s_Correction );
|
|
|
|
dy = dx;
|
2009-09-17 17:48:40 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_WITH_0_DEG
|
2009-09-10 13:04:04 +00:00
|
|
|
fAngle = 0;
|
|
|
|
#else
|
2009-01-18 13:14:50 +00:00
|
|
|
fAngle = 450;
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif
|
2009-01-18 13:14:50 +00:00
|
|
|
}
|
2009-01-15 14:32:29 +00:00
|
|
|
|
2009-01-18 13:14:50 +00:00
|
|
|
// compute north, south, west and east points for zone connection.
|
2009-01-22 18:45:33 +00:00
|
|
|
// Add a small value to ensure point is inside (or outside) zone, not on an edge
|
2009-01-18 13:14:50 +00:00
|
|
|
wxPoint ptTest[4];
|
|
|
|
ptTest[0] = wxPoint( 0, 3 + dy + m_ZoneMinThickness / 2 );
|
|
|
|
ptTest[1] = wxPoint( 0, -(3 + dy + m_ZoneMinThickness / 2) );
|
|
|
|
ptTest[2] = wxPoint( 3 + dx + m_ZoneMinThickness / 2, 0 );
|
|
|
|
ptTest[3] = wxPoint( -(3 + dx + m_ZoneMinThickness / 2), 0 );
|
2009-01-15 14:32:29 +00:00
|
|
|
|
|
|
|
|
2009-01-18 13:14:50 +00:00
|
|
|
// Test all sides
|
|
|
|
for( int i = 0; i<4; i++ )
|
|
|
|
{
|
|
|
|
// rotate point
|
|
|
|
RotatePoint( &ptTest[i], fAngle );
|
|
|
|
|
|
|
|
// translate point
|
|
|
|
ptTest[i] += pad->ReturnShapePos();
|
2009-01-24 19:30:39 +00:00
|
|
|
bool inside = HitTestFilledArea( ptTest[i] );
|
2009-01-15 14:32:29 +00:00
|
|
|
|
2009-01-18 13:14:50 +00:00
|
|
|
if( inside == false )
|
|
|
|
{
|
|
|
|
// polygon buffer
|
|
|
|
std::vector<wxPoint> corners_buffer;
|
|
|
|
|
|
|
|
// polygons are rectangles with width of copper bridge value
|
2009-03-05 17:40:23 +00:00
|
|
|
// contour line width has to be taken into calculation to avoid "thermal stub bleed"
|
2009-03-19 18:11:37 +00:00
|
|
|
const int iDTRC =
|
|
|
|
( m_ThermalReliefCopperBridgeValue - m_ZoneMinThickness ) / 2;
|
2009-01-18 13:14:50 +00:00
|
|
|
|
|
|
|
switch( i )
|
2009-01-15 14:32:29 +00:00
|
|
|
{
|
2009-01-18 13:14:50 +00:00
|
|
|
case 0:
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, dy ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, dy ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, -dy ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, -dy ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
corners_buffer.push_back( wxPoint( dx, -iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( dx, iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
corners_buffer.push_back( wxPoint( -dx, -iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -dx, iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
|
|
|
|
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add computed polygon to group_B
|
|
|
|
if( booleng->StartPolygonAdd( GROUP_B ) )
|
|
|
|
{
|
|
|
|
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
|
2009-01-15 14:32:29 +00:00
|
|
|
{
|
2009-01-18 13:14:50 +00:00
|
|
|
wxPoint cpos = corners_buffer[ic];
|
|
|
|
RotatePoint( &cpos, fAngle ); // Rotate according to module orientation
|
|
|
|
cpos += pad->ReturnShapePos(); // Shift origin to position
|
|
|
|
booleng->AddPoint( cpos.x, cpos.y );
|
2009-03-16 19:51:23 +00:00
|
|
|
have_poly_to_substract = true;
|
2009-01-15 14:32:29 +00:00
|
|
|
}
|
2009-01-18 13:14:50 +00:00
|
|
|
|
|
|
|
booleng->EndPolygonAdd();
|
2009-01-15 14:32:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-23 16:04:11 +00:00
|
|
|
/* compute copper areas */
|
2009-03-19 18:11:37 +00:00
|
|
|
if( have_poly_to_substract )
|
2009-03-16 19:51:23 +00:00
|
|
|
{
|
2010-01-03 16:47:46 +00:00
|
|
|
/* Add the main corrected polygon (i.e. the filled area using only one outline)
|
|
|
|
* in GroupA in Bool_Engine
|
|
|
|
*/
|
|
|
|
CopyPolygonsFromFilledPolysListToBoolengine( booleng, GROUP_A );
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
booleng->Do_Operation( BOOL_A_SUB_B );
|
|
|
|
|
2009-03-19 18:11:37 +00:00
|
|
|
/* put these areas in m_FilledPolysList */
|
2009-03-16 19:51:23 +00:00
|
|
|
m_FilledPolysList.clear();
|
|
|
|
CopyPolygonsFromBoolengineToFilledPolysList( booleng );
|
2009-03-19 18:11:37 +00:00
|
|
|
|
|
|
|
// Remove insulated islands, if any:
|
2009-03-16 19:51:23 +00:00
|
|
|
if( GetNet() > 0 )
|
|
|
|
Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb );
|
|
|
|
}
|
2009-01-15 14:32:29 +00:00
|
|
|
|
|
|
|
delete booleng;
|
2009-03-19 18:11:37 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif // REMOVE_UNUSED_THERMAL_STUBS
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function AddPadPolygonWithPadClearance
|
|
|
|
* Add a polygon cutout for a pad in a zone area
|
|
|
|
* Convert arcs and circles to multiple straight lines
|
|
|
|
*/
|
|
|
|
void AddPadWithClearancePolygon( Bool_Engine* aBooleng,
|
2008-10-07 09:32:56 +00:00
|
|
|
D_PAD& aPad, int aClearanceValue )
|
2008-10-02 13:24:31 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
static std::vector <CPolyPt> cornerBuffer;
|
2008-10-07 09:32:56 +00:00
|
|
|
if( aBooleng->StartPolygonAdd( GROUP_B ) == 0 )
|
|
|
|
return;
|
2009-11-14 19:47:52 +00:00
|
|
|
cornerBuffer.clear();
|
2009-11-16 08:13:40 +00:00
|
|
|
aPad.TransformShapeWithClearanceToPolygon( cornerBuffer,
|
|
|
|
aClearanceValue,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
s_Correction );
|
2008-10-07 09:32:56 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
aBooleng->AddPoint( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
2008-10-13 18:39:38 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
aBooleng->EndPolygonAdd();
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS
|
2009-11-16 08:13:40 +00:00
|
|
|
StartKeyFilePolygon( 1 );
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
AddKeyFilePointXY( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
2008-10-07 09:32:56 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
EndKeyFilePolygon();
|
2009-11-14 19:47:52 +00:00
|
|
|
#endif
|
2008-10-07 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
|
2008-10-07 09:32:56 +00:00
|
|
|
/** function AddThermalReliefPadPolygon
|
|
|
|
* Add holes around a pad to create a thermal relief
|
2008-12-21 08:35:21 +00:00
|
|
|
* copper thickness is min (dx/2, aCopperWitdh) or min (dy/2, aCopperWitdh)
|
2008-11-23 08:07:10 +00:00
|
|
|
* @param aBooleng = current Bool_Engine
|
|
|
|
* @param aPad = the current pad used to create the thermal shape
|
|
|
|
* @param aThermalGap = gap in thermal shape
|
|
|
|
* @param aMinThicknessValue = min copper thickness allowed
|
2008-10-07 09:32:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* thermal reliefs are created as 4 polygons.
|
|
|
|
* each corner of a polygon if calculated for a pad at position 0, 0, orient 0,
|
|
|
|
* and then moved and rotated acroding to the pad position and orientation
|
|
|
|
*/
|
2008-11-09 15:01:35 +00:00
|
|
|
|
|
|
|
/* WARNING:
|
|
|
|
* When Kbool calculates the filled areas :
|
2009-01-10 17:12:51 +00:00
|
|
|
* i.e when substracting holes (thermal shapes) to the full zone area
|
2008-11-09 15:01:35 +00:00
|
|
|
* under certains circumstances kboll drop some holes.
|
2009-11-16 08:13:40 +00:00
|
|
|
* see CreateThermalReliefPadPolygon().
|
2008-11-09 15:01:35 +00:00
|
|
|
*/
|
2009-11-16 08:13:40 +00:00
|
|
|
int AddThermalReliefPadPolygon( Bool_Engine* aBooleng,
|
|
|
|
D_PAD& aPad,
|
|
|
|
int aThermalGap,
|
|
|
|
int aCopperThickness, int aMinThicknessValue )
|
2008-10-07 09:32:56 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
static std::vector <CPolyPt> cornerBuffer;
|
|
|
|
cornerBuffer.clear();
|
2008-10-11 19:27:43 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
int polycount = 0;
|
|
|
|
int thermalRot = 450;
|
2009-09-17 17:48:40 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_WITH_0_DEG
|
2009-11-16 08:13:40 +00:00
|
|
|
thermalRot = 0;
|
2009-09-10 13:04:04 +00:00
|
|
|
#endif
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
CreateThermalReliefPadPolygon( cornerBuffer,
|
|
|
|
aPad, aThermalGap, aCopperThickness,
|
|
|
|
aMinThicknessValue,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
s_Correction, thermalRot );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
// cornerBuffer can contain more than one polygon,
|
|
|
|
// so read cornerBuffer and verify if there is a end of polygon corner:
|
|
|
|
for( unsigned icnt = 0; icnt < cornerBuffer.size(); )
|
2008-10-19 10:13:04 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
aBooleng->StartPolygonAdd( GROUP_B );
|
|
|
|
polycount++;
|
|
|
|
unsigned ii;
|
|
|
|
for( ii = icnt; ii < cornerBuffer.size(); ii++ )
|
2008-10-19 10:13:04 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
aBooleng->AddPoint( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
|
|
|
if( cornerBuffer[ii].end_contour )
|
|
|
|
break;
|
2008-10-19 10:13:04 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
aBooleng->EndPolygonAdd();
|
2008-10-19 10:13:04 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES
|
|
|
|
StartKeyFilePolygon( 1 );
|
|
|
|
for( ii = icnt; ii < cornerBuffer.size(); ii++ )
|
2008-10-19 10:13:04 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
AddKeyFilePointXY( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
|
|
|
if( cornerBuffer[ii].end_contour )
|
|
|
|
break;
|
2008-10-19 10:13:04 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
EndKeyFilePolygon();
|
|
|
|
#endif
|
2008-10-19 10:13:04 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
icnt = ii + 1;
|
2008-10-19 10:13:04 +00:00
|
|
|
}
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
return polycount;
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2008-10-02 13:24:31 +00:00
|
|
|
|
|
|
|
/** Function AddTrackWithClearancePolygon
|
|
|
|
* Add a polygon cutout for a track in a zone area
|
|
|
|
* Convert arcs and circles to multiple straight lines
|
|
|
|
*/
|
|
|
|
void AddTrackWithClearancePolygon( Bool_Engine* aBooleng,
|
|
|
|
TRACK& aTrack, int aClearanceValue )
|
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
static std::vector <CPolyPt> cornerBuffer;
|
2009-11-14 19:47:52 +00:00
|
|
|
cornerBuffer.clear();
|
2009-11-16 08:13:40 +00:00
|
|
|
aTrack.TransformShapeWithClearanceToPolygon( cornerBuffer,
|
2009-11-14 19:47:52 +00:00
|
|
|
aClearanceValue,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
s_Correction );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
if( !aBooleng->StartPolygonAdd( GROUP_B ) )
|
|
|
|
return;
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
aBooleng->AddPoint( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
aBooleng->EndPolygonAdd();
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS
|
2009-11-16 08:13:40 +00:00
|
|
|
StartKeyFilePolygon( 1 );
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
AddKeyFilePointXY( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
EndKeyFilePolygon();
|
2009-11-14 19:47:52 +00:00
|
|
|
#endif
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function AddRoundedEndsSegmentPolygon
|
|
|
|
* Add a polygon cutout for a segment (with rounded ends) in a zone area
|
|
|
|
* Convert arcs to multiple straight lines
|
|
|
|
*/
|
|
|
|
void AddRoundedEndsSegmentPolygon( Bool_Engine* aBooleng,
|
|
|
|
wxPoint aStart, wxPoint aEnd,
|
|
|
|
int aWidth )
|
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
static std::vector <CPolyPt> cornerBuffer;
|
2009-11-14 19:47:52 +00:00
|
|
|
cornerBuffer.clear();
|
|
|
|
TransformRoundedEndsSegmentToPolygon( cornerBuffer,
|
2009-11-16 08:13:40 +00:00
|
|
|
aStart, aEnd,
|
|
|
|
s_CircleToSegmentsCount,
|
|
|
|
aWidth );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
|
|
|
if( !aBooleng->StartPolygonAdd( GROUP_B ) )
|
2009-11-14 19:47:52 +00:00
|
|
|
return;
|
2009-09-17 17:48:40 +00:00
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
aBooleng->AddPoint( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
2009-09-17 17:48:40 +00:00
|
|
|
|
|
|
|
aBooleng->EndPolygonAdd();
|
|
|
|
|
|
|
|
#ifdef CREATE_KBOOL_KEY_FILES
|
2009-11-16 08:13:40 +00:00
|
|
|
StartKeyFilePolygon( 1 );
|
2009-11-14 19:47:52 +00:00
|
|
|
for( unsigned ii = 0; ii < cornerBuffer.size(); ii++ )
|
|
|
|
AddKeyFilePointXY( cornerBuffer[ii].x, cornerBuffer[ii].y );
|
2008-10-02 13:24:31 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
EndKeyFilePolygon();
|
2009-09-17 17:48:40 +00:00
|
|
|
#endif
|
2008-10-02 13:24:31 +00:00
|
|
|
}
|
2008-10-07 09:32:56 +00:00
|
|
|
|
|
|
|
|
2008-11-23 17:43:53 +00:00
|
|
|
/***********************************************************************************************************/
|
2008-11-24 20:46:41 +00:00
|
|
|
int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aBoolengine,
|
|
|
|
GroupType aGroup )
|
2008-11-23 17:43:53 +00:00
|
|
|
/************************************************************************************************************/
|
2008-11-24 20:46:41 +00:00
|
|
|
|
2008-11-23 17:43:53 +00:00
|
|
|
/** Function CopyPolygonsFromFilledPolysListToBoolengine
|
2009-01-10 17:12:51 +00:00
|
|
|
* Copy (Add) polygons found in m_FilledPolysList to kbool BoolEngine
|
|
|
|
* m_FilledPolysList may have more than one polygon
|
2008-11-23 17:43:53 +00:00
|
|
|
* @param aBoolengine = kbool engine
|
|
|
|
* @param aGroup = group in kbool engine (GROUP_A or GROUP_B only)
|
|
|
|
* @return the corner count
|
2008-11-24 20:46:41 +00:00
|
|
|
*/
|
2008-11-23 17:43:53 +00:00
|
|
|
{
|
|
|
|
unsigned corners_count = m_FilledPolysList.size();
|
2008-11-24 20:46:41 +00:00
|
|
|
int count = 0;
|
|
|
|
unsigned ic = 0;
|
|
|
|
|
2009-01-10 17:12:51 +00:00
|
|
|
while( ic < corners_count )
|
2008-11-23 17:43:53 +00:00
|
|
|
{
|
2009-01-10 17:12:51 +00:00
|
|
|
if( aBoolengine->StartPolygonAdd( aGroup ) )
|
2008-11-23 17:43:53 +00:00
|
|
|
{
|
2009-01-10 17:12:51 +00:00
|
|
|
for( ; ic < corners_count; ic++ )
|
|
|
|
{
|
|
|
|
CPolyPt* corner = &m_FilledPolysList[ic];
|
|
|
|
aBoolengine->AddPoint( corner->x, corner->y );
|
|
|
|
count++;
|
|
|
|
if( corner->end_contour )
|
|
|
|
{
|
|
|
|
ic++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-23 17:43:53 +00:00
|
|
|
|
2009-01-10 17:12:51 +00:00
|
|
|
aBoolengine->EndPolygonAdd();
|
|
|
|
}
|
2008-11-23 17:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2008-11-24 20:46:41 +00:00
|
|
|
|
|
|
|
|
2008-11-23 17:43:53 +00:00
|
|
|
/*****************************************************************************************/
|
|
|
|
int ZONE_CONTAINER::CopyPolygonsFromBoolengineToFilledPolysList( Bool_Engine* aBoolengine )
|
|
|
|
/*****************************************************************************************/
|
2008-11-24 20:46:41 +00:00
|
|
|
|
2008-11-23 17:43:53 +00:00
|
|
|
/** Function CopyPolygonsFromBoolengineToFilledPolysList
|
|
|
|
* Copy (Add) polygons created by kbool (after Do_Operation) to m_FilledPolysList
|
|
|
|
* @param aBoolengine = kbool engine
|
|
|
|
* @return the corner count
|
2008-11-24 20:46:41 +00:00
|
|
|
*/
|
2008-11-23 17:43:53 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
2008-11-24 20:46:41 +00:00
|
|
|
|
2008-11-23 17:43:53 +00:00
|
|
|
while( aBoolengine->StartPolygonGet() )
|
|
|
|
{
|
|
|
|
CPolyPt corner( 0, 0, false );
|
|
|
|
while( aBoolengine->PolygonHasMorePoints() )
|
|
|
|
{
|
|
|
|
corner.x = (int) aBoolengine->GetPolygonXPoint();
|
|
|
|
corner.y = (int) aBoolengine->GetPolygonYPoint();
|
|
|
|
corner.end_contour = false;
|
2009-01-10 17:12:51 +00:00
|
|
|
|
2008-12-03 10:32:53 +00:00
|
|
|
// Flag this corner if starting a hole connection segment:
|
2009-09-17 17:48:40 +00:00
|
|
|
// This is used by draw functions to draw only useful segments (and not extra segments)
|
2008-12-03 10:32:53 +00:00
|
|
|
corner.utility = (aBoolengine->GetPolygonPointEdgeType() == KB_FALSE_EDGE) ? 1 : 0;
|
2008-11-23 17:43:53 +00:00
|
|
|
m_FilledPolysList.push_back( corner );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
corner.end_contour = true;
|
|
|
|
m_FilledPolysList.pop_back();
|
|
|
|
m_FilledPolysList.push_back( corner );
|
|
|
|
aBoolengine->EndPolygonGet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|