43#include <magic_enum.hpp>
45#include <google/protobuf/any.pb.h>
49#include <api/board/board_types.pb.h>
117 *
this = *
static_cast<const ZONE*
>( aOther );
223 return new ZONE( *
this );
241 ZONE* newZone =
static_cast<ZONE*
>( dupe );
247 [&](
const wxString& aName )
249 for(
const ZONE* zone : board->Zones() )
251 if( zone != newZone && zone->
GetZoneName() == aName )
259 for(
const auto& [item, change_type] : aCommit->
StagedItems() )
263 ZONE* zone =
static_cast<ZONE*
>( item );
265 if( zone != newZone && zone->
GetZoneName() == aName )
288 zone.mutable_id()->set_value(
m_Uuid.AsStdString() );
292 zone.set_type( types::ZT_RULE_AREA );
294 zone.set_type( types::ZT_TEARDROP );
296 zone.set_type( types::ZT_COPPER );
298 zone.set_type( types::ZT_GRAPHICAL );
307 zone.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
309 zone.mutable_parent()->set_value(
board->m_Uuid.AsStdString() );
313 types::RuleAreaSettings* ra = zone.mutable_rule_area_settings();
327 types::CopperZoneSettings* cu = zone.mutable_copper_settings();
328 cu->mutable_connection()->set_zone_connection(
331 types::ThermalSpokeSettings* thermals = cu->mutable_connection()->mutable_thermal_spokes();
343 cu->set_corner_smoothing(
349 types::HatchFillSettings* hatch = cu->mutable_hatch_settings();
351 hatch->mutable_gap()->set_value_nm(
m_hatchGap );
352 hatch->mutable_orientation()->set_value_degrees(
m_hatchOrientation.GetAngle().AsDegrees() );
359 case 0: hatch->set_border_mode( types::ZHFBM_USE_MIN_ZONE_THICKNESS );
break;
360 case 1: hatch->set_border_mode( types::ZHFBM_USE_HATCH_THICKNESS );
break;
364 cu->mutable_teardrop()->set_type(
367 types::ThievingFillSettings* thieving = cu->mutable_thieving_settings();
368 thieving->set_pattern(
374 thieving->mutable_orientation()->set_value_degrees(
m_thievingSettings.orientation.GetAngle().AsDegrees() );
379 types::ZoneFilledPolygons* filledLayer = zone.add_filled_polygons();
386 types::ZoneLayerProperties* layerProperties = zone.add_layer_properties();
389 if( properties.hatching_offset.has_value() )
391 PackVector2( *layerProperties->mutable_hatching_offset(),
392 properties.hatching_offset.value() );
396 zone.mutable_border()->set_style(
401 aContainer.PackFrom( zone );
411 if( !aContainer.UnpackTo( &zone ) )
420 if( zone.type() == types::ZoneType::ZT_RULE_AREA )
428 if(
m_Poly->OutlineCount() == 0 )
433 const types::RuleAreaSettings& ra = zone.rule_area_settings();
446 const types::CopperZoneSettings& cu = zone.copper_settings();
461 if( cu.has_corner_radius() )
467 m_hatchGap = cu.hatch_settings().gap().value_nm();
472 switch( cu.hatch_settings().border_mode() )
482 if( cu.has_thieving_settings() )
484 const types::ThievingFillSettings& thieving = cu.thieving_settings();
488 auto assignIfPositive = [](
int aProtoValue,
int& aTarget )
490 if( aProtoValue > 0 )
491 aTarget = aProtoValue;
494 assignIfPositive( thieving.element_size().value_nm(),
m_thievingSettings.element_size );
503 for(
const auto& properties : zone.layer_properties() )
509 if( properties.has_hatching_offset() )
510 layerProperties.
hatching_offset = UnpackVector2( properties.hatching_offset() );
524 for(
const types::ZoneFilledPolygons& fillLayer : zone.filled_polygons() )
577 change |= !pair.second->IsEmpty();
583 pair.second = std::make_shared<SHAPE_POLY_SET>();
601 if(
m_Poly->OutlineCount() == 0 ||
m_Poly->TotalVertices() == 0 )
620 if( uiLayers.size() )
641 if( uiLayers.size() )
702 if( aLayerSet.count() == 0 )
732 [&](
const auto& item )
734 return !effectiveSet.
Contains( item.first );
752 std::vector<int> layers;
758 layers.push_back( layer );
782 if( !onFront && !onBack )
784 onFront = parentFP->GetLayer() ==
F_Cu;
785 onBack = parentFP->GetLayer() ==
B_Cu;
791 if( onFront && !onBack && frHidden )
794 if( onBack && !onFront && bkHidden )
797 if( onFront && onBack && frHidden && bkHidden )
831 std::unordered_map<const ZONE*, BOX2I>& cache =
board->m_ZoneBBoxCache;
834 std::shared_lock<std::shared_mutex> readLock(
board->m_CachesMutex );
836 auto cacheIter = cache.find(
this );
838 if( cacheIter != cache.end() )
839 return cacheIter->second;
845 std::unique_lock<std::shared_mutex> writeLock(
board->m_CachesMutex );
846 cache[ this ] = bbox;
860 std::unique_lock<std::shared_mutex> writeLock(
board->m_CachesMutex );
861 board->m_ZoneBBoxCache.erase(
this );
886 std::unique_lock<std::shared_mutex> writeLock(
board->m_CachesMutex );
887 board->m_ZoneBBoxCache[
this] = bbox;
903 *aSource =
_(
"zone" );
958 poly =
m_Poly->CloneDropTriangulation();
968 poly =
m_Poly->CloneDropTriangulation();
990 libPos = fp->GetTransform().InverseApply( refPos );
992 return m_Poly->CollideVertex( libPos, aCornerHit, aAccuracy );
1001 libPos = fp->GetTransform().InverseApply( refPos );
1003 return m_Poly->CollideEdge( libPos, aCornerHit, aAccuracy );
1013 BOX2I arect = aRect;
1030 for(
int ii = 0; ii < count; ii++ )
1033 const VECTOR2I& vertexNext = boardOutline.
CVertex( ( ii + 1 ) % count );
1055 auto outlineIntersectingSelection =
1069 auto vertexInsideSelection =
1075 return vertexInsideSelection() && !outlineIntersectingSelection();
1112 libPos = fp->GetTransform().InverseApply( aRefPos );
1114 return m_Poly->Contains( libPos, -1, aAccuracy );
1117 std::shared_ptr<SHAPE_POLY_SET> fillPolys;
1128 return fillPolys->Contains( aRefPos, -1, aAccuracy );
1137 libPos = fp->GetTransform().InverseApply( aRefPos );
1141 for(
int i = 0; i <
m_Poly->OutlineCount(); i++ )
1143 for(
int j = 0; j <
m_Poly->HoleCount( i ); j++ )
1145 if(
m_Poly->Hole( i, j ).PointInside( libPos ) )
1166 aList.emplace_back(
_(
"Type" ), msg );
1187 if( !msg.IsEmpty() )
1188 aList.emplace_back(
_(
"Restrictions" ), msg );
1194 aList.emplace_back(
_(
"Layout link" ),
_(
"Linked" ) );
1202 aList.emplace_back(
_(
"Resolved Netclass" ),
1213 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
1219 if( layers.size() == 1 )
1223 else if( layers.size() == 2 )
1227 else if( layers.size() == 3 )
1232 else if( layers.size() > 3 )
1235 static_cast<int>( layers.size() - 2 ) );
1238 aList.emplace_back(
_(
"Layer" ), layerDesc );
1249 default: msg =
_(
"Unknown" );
break;
1252 aList.emplace_back(
_(
"Fill Mode" ), msg );
1254 aList.emplace_back(
_(
"Filled Area" ),
1263 wxString::Format(
_(
"(from %s)" ),
source ) );
1272 aList.emplace_back(
_(
"Outline Area" ),
1282 count += ii.second->TotalVertices();
1285 aList.emplace_back(
_(
"Corner Count" ), wxString::Format( wxT(
"%d" ), count ) );
1299 m_Poly->Move( outlineOffset );
1306 seg.A += outlineOffset;
1307 seg.B += outlineOffset;
1312 pair.second->Move( offset );
1324 if( it !=
GetBoard()->m_ZoneBBoxCache.end() )
1325 it->second.Move( offset );
1337 return _(
"Rule Area" );
1339 return _(
"Teardrop Area" );
1341 return _(
"Copper Zone" );
1343 return _(
"Non-copper Zone" );
1351 if(
m_Poly->GetNeighbourIndexes( aEdge,
nullptr, &next_corner ) )
1361 m_Poly->SetVertex( aEdge,
m_Poly->CVertex( aEdge ) + libOffset );
1362 m_Poly->SetVertex( next_corner,
m_Poly->CVertex( next_corner ) + libOffset );
1375 outlineCentre = fp->GetTransform().InverseApply( aCentre );
1377 m_Poly->Rotate( aAngle, outlineCentre );
1383 pair.second->Rotate( aAngle, aCentre );
1390 if( aRatioX == 1.0 && aRatioY == 1.0 )
1403 Mirror( aCentre, aFlipDirection );
1405 std::map<PCB_LAYER_ID, SHAPE_POLY_SET> fillsCopy;
1408 fillsCopy[oldLayer] = *shapePtr;
1410 std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES> layerPropertiesCopy =
m_layerProperties;
1419 for(
auto& [oldLayer, properties] : layerPropertiesCopy )
1425 for(
auto& [oldLayer, shape] : fillsCopy )
1438 outlineRef = fp->GetTransform().InverseApply( aMirrorRef );
1440 m_Poly->Mirror( outlineRef, aFlipDirection );
1446 pair.second->Mirror( aMirrorRef, aFlipDirection );
1453 if(
m_Poly->OutlineCount() < aOutlineIdx ||
m_Poly->HoleCount( aOutlineIdx ) < aHoleIdx )
1459 m_Poly->BooleanAdd( cutPoly );
1470 if(
m_Poly->OutlineCount() == 0 )
1471 m_Poly->AddOutline( aPolygon );
1473 m_Poly->AddHole( aPolygon );
1481 if( aPolygon.empty() )
1487 for(
const VECTOR2I& pt : aPolygon )
1499 if(
m_Poly->OutlineCount() == 0 )
1505 if( aHoleIdx >=
m_Poly->HoleCount( 0 ) )
1508 m_Poly->Append( aPosition.
x, aPosition.
y, -1, aHoleIdx, aAllowDuplication );
1525 return board->GetLayerName( aLayer );
1530 if( layers.size() == 1 )
1532 layerDesc.Printf(
_(
"on %s" ), layerName( layers[0] ) );
1534 else if (layers.size() == 2 )
1536 layerDesc.Printf(
_(
"on %s and %s" ),
1537 layerName( layers[0] ),
1538 layerName( layers[1] ) );
1540 else if (layers.size() == 3 )
1542 layerDesc.Printf(
_(
"on %s, %s and %s" ),
1543 layerName( layers[0] ),
1544 layerName( layers[1] ),
1545 layerName( layers[2] ) );
1547 else if( layers.size() > 3 )
1549 layerDesc.Printf(
_(
"on %s, %s and %zu more" ),
1550 layerName( layers[0] ),
1551 layerName( layers[1] ),
1552 layers.size() - 2 );
1559 return wxString::Format(
_(
"Rule Area %s" ), layerDesc );
1563 return wxString::Format(
_(
"Rule area '%s' %s" ),
1570 return wxString::Format(
_(
"Teardrop %s %s" ),
1578 return wxString::Format(
_(
"Zone %s %s, priority %d" ),
1585 return wxString::Format(
_(
"Zone '%s' %s %s, priority %d" ),
1596 bool aRebuildBorderHatch )
1603 if( aRebuildBorderHatch )
1636 hatch_line_len = -1;
1641 std::vector<double> slopes;
1644 slopes = { 0.7, -0.7 };
1645 else if( layer & 1 )
1688 std::swap( *
static_cast<ZONE*
>(
this ), *
static_cast<ZONE*
>( aImage) );
1696 std::vector<PCB_LAYER_ID> layers;
1701 layers.push_back( layer );
1709 m_Poly->CacheTriangulation();
1720 poly->CacheTriangulation(
false, aSubmitter );
1722 m_Poly->CacheTriangulation();
1729 std::shared_ptr<SHAPE_POLY_SET> poly;
1741 poly->CacheTriangulation(
false, aSubmitter );
1759 std::vector<ZONE*>* aOtherNetIntersectingZones )
const
1771 if( candidate ==
this )
1774 if( !candidate->GetLayerSet().test( aLayer ) )
1777 if( candidate->GetIsRuleArea() || candidate->IsTeardropArea() )
1780 if( !candidate->GetBoundingBox().Intersects( bbox ) )
1783 if( candidate->GetNetCode() ==
GetNetCode() )
1788 const SHAPE_POLY_SET* candidateOutline = &candidateOutlineStorage;
1796 if( candidate->GetParentFootprint() )
1797 candidateOutlineStorage = candidate->GetBoardOutline();
1799 candidateOutline = candidate->
Outline();
1801 if( selfOutline->
Collide( candidateOutline ) )
1802 aSameNetCollidingZones->push_back( candidate );
1806 aOtherNetIntersectingZones->push_back( candidate );
1826 aSmoothedPoly = std::move( flattened );
1831 bool keepExternalFillets =
false;
1839 smooth_requested =
false;
1843 keepExternalFillets =
board->GetDesignSettings().m_ZoneKeepExternalFillets;
1848 if( !smooth_requested )
1869 aSmoothedPoly = flattened;
1874 if( keepExternalFillets && smooth_requested )
1876 withFillets = flattened;
1877 smooth( withFillets );
1879 maxExtents = &withFillets;
1887 std::vector<ZONE*> sameNetCollidingZones;
1888 std::vector<ZONE*> diffNetIntersectingZones;
1891 for(
ZONE* sameNetZone : sameNetCollidingZones )
1893 BOX2I sameNetBoundingBox = sameNetZone->GetBoundingBox();
1907 for(
ZONE* diffNetZone : diffNetIntersectingZones )
1909 if( diffNetZone->HigherPriority( sameNetZone )
1910 && diffNetZone->GetBoundingBox().Intersects( sameNetBoundingBox ) )
1922 bool isolated =
false;
1947 smooth( aSmoothedPoly );
1949 if( aSmoothedPolyWithApron )
1959 if( !keepExternalFillets )
1962 *aSmoothedPolyWithApron = aSmoothedPoly;
2009 aBuffer.
Append( polybuffer );
2023 return std::make_shared<SHAPE_POLY_SET>( *
Outline() );
2029 return std::make_shared<SHAPE_NULL>();
2041 bool filled =
false;
2042 double largest = 0.0;
2051 if( fill->OutlineCount() == 0 )
2055 largest = std::max( largest, fill->Area() );
2074 int aError,
ERROR_LOC aErrorLoc,
bool aIgnoreLineWidth )
const
2076 wxASSERT_MSG( !aIgnoreLineWidth, wxT(
"IgnoreLineWidth has no meaning for zones." ) );
2078 std::shared_ptr<SHAPE_POLY_SET> fillPolys;
2091 aBuffer.
Append( *fillPolys );
2101 aClearance += aError;
2106 aBuffer.
Append( temp_buf );
2121 if( aLayerSet.count() == 0 )
2150 const ZONE& other =
static_cast<const ZONE&
>( aOther );
2151 return *
this == other;
2161 const ZONE& other =
static_cast<const ZONE&
>( aOther );
2228 const ZONE& other =
static_cast<const ZONE&
>( aOther );
2233 double similarity = 1.0;
2272 std::vector<VECTOR2I> corners;
2273 std::vector<VECTOR2I> otherCorners;
2303 if( layerEnum.
Choices().GetCount() == 0 )
2313 if( zcMap.
Choices().GetCount() == 0 )
2325 if( zfmMap.
Choices().GetCount() == 0 )
2335 if( tpMap.
Choices().GetCount() == 0 )
2345 if( irmMap.
Choices().GetCount() == 0 )
2355 if( rapstMap.
Choices().GetCount() == 0 )
2383 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2384 return !zone->GetIsRuleArea() &&
IsCopperLayer( zone->GetFirstLayer() );
2391 auto isNonThievingCopperZone =
2394 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2396 return !zone->GetIsRuleArea() &&
IsCopperLayer( zone->GetFirstLayer() )
2397 && !zone->IsCopperThieving();
2406 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2407 return zone->GetIsRuleArea();
2412 auto isHatchedFill =
2415 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2421 auto isThievingFill =
2424 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2425 return zone->IsCopperThieving();
2430 auto isThievingHatch =
2433 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2439 auto isThievingNonHatch =
2442 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2448 auto isAreaBasedIslandRemoval =
2451 if(
ZONE* zone =
dynamic_cast<ZONE*
>( aItem ) )
2464 isNonThievingCopperZone );
2466 isNonThievingCopperZone );
2475 const wxString groupKeepout =
_HKI(
"Keepout" );
2503 const wxString groupPlacement =
_HKI(
"Placement" );
2521 const wxString groupFill =
_HKI(
"Fill Style" );
2534 auto atLeastMinWidthValidator =
2537 int val = aValue.As<
int>();
2538 ZONE* zone =
dynamic_cast<ZONE*
>( aZone );
2539 wxCHECK( zone, std::nullopt );
2541 if( val < zone->GetMinThickness() )
2542 return std::make_unique<VALIDATION_ERROR_MSG>(
_(
"Cannot be less than zone minimum width" ) );
2544 return std::nullopt;
2632 const wxString groupElectrical =
_HKI(
"Electrical" );
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
BITMAPS
A list of all bitmap identifiers.
BASE_SET & set(size_t pos)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
wxString GetNetnameMsg() const
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
wxString GetNetname() const
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
void PackNet(kiapi::board::types::Net *aProto) const
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
void UnpackNet(const kiapi::board::types::Net &aProto)
Assigns a net to this item from an API message.
TEARDROP_PARAMETERS & GetTeardropParams()
ZONE_SETTINGS & GetDefaultZoneSettings()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
static double polygonArea(SHAPE_POLY_SET &aPolySet)
Area of aPolySet with every contour closed first, holes subtracted.
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
BOARD_ITEM_CONTAINER * GetParent() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
std::unordered_map< const ZONE *, BOX2I > m_ZoneBBoxCache
static wxString MakeUniqueZoneName(const wxString &aBaseName, const std::function< bool(const wxString &)> &aInUse)
Return a name based on aBaseName for which aInUse returns false, adding or incrementing a _<number> s...
BOARD_DESIGN_SETTINGS & GetDesignSettings()
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr bool Contains(const Vec &aPoint) const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
std::vector< std::pair< EDA_ITEM *, int > > StagedItems() const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
ENUM_MAP & Undefined(T aValue)
Class that other classes need to inherit from, in order to be inspectable.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisibleCached(int aLayer) const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET is a set of PCB_LAYER_IDs.
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
static const LSET & AllLayersMask()
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Handle the data for a net.
int GetLocalThermalGapOverride(wxString *aSource) const
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
static VALIDATOR_RESULT PositiveRatioValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT PositiveIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT RangeIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
bool Intersects(const SEG &aSeg) const
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
ITERATOR IterateWithHoles(int aOutline)
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
void SetVertex(const VERTEX_INDEX &aIndex, const VECTOR2I &aPos)
Accessor function to set the position of a specific point.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int TotalVertices() const
Return total number of vertices stored in the set.
int FullPointCount() const
Return the number of points in the shape poly set.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
SEGMENT_ITERATOR IterateSegments(int aFirst, int aLast, bool aIterateHoles=false)
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
void InflateWithLinkedHoles(int aFactor, CORNER_STRATEGY aCornerStrategy, int aMaxError)
Perform outline inflation/deflation, using round corners.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
std::function< void(std::function< void()>)> TASK_SUBMITTER
Callback that submits a unit of work for asynchronous execution.
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Copy settings to a given zone.
Handle a list of polygons defining a copper zone.
void SetHatchThickness(int aThickness)
void CacheTriangulation(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, const SHAPE_POLY_SET::TASK_SUBMITTER &aSubmitter={})
void SetNeedRefill(bool aNeedRefill)
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if a point is near an outline edge or a corner of this zone.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
wxString m_placementAreaSource
bool m_isRuleArea
A zone outline can be a rule area.
void SetDoNotAllowPads(bool aEnable)
void SetLayerProperties(const std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > &aOther)
ZONE & operator=(const ZONE &aOther)
REPEAT_LAYOUT_OPTIONS m_repeatOptions
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
PLACEMENT_SOURCE_T m_placementAreaSourceType
std::optional< int > GetLocalClearance() const override
void SetLocalClearance(std::optional< int > aClearance)
bool UnFill()
Removes the zone filling.
bool GetDoNotAllowVias() const
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
void TransformSolidAreasShapesToPolygon(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer) const
Convert solid areas full shapes to polygon set (the full shape is the polygon area with a thick outli...
void SetCornerRadius(unsigned int aRadius)
ZONE_FILL_MODE m_fillMode
THIEVING_SETTINGS m_thievingSettings
bool m_doNotAllowFootprints
bool unFillLocked()
Internal implementation of UnFill() that assumes the caller already holds m_filledPolysListMutex.
void TransformSmoothedOutlineToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, SHAPE_POLY_SET *aBoardOutline) const
Convert the outlines shape to a polygon with no holes inflated (optional) by max( aClearanceValue,...
BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const override
Create a copy of this BOARD_ITEM.
int GetThievingLineWidth() const
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
double m_hatchSmoothingValue
void SetLocalFlags(int aFlags)
int m_thermalReliefSpokeWidth
wxString GetPlacementAreaSource() const
bool HitTestCutout(const VECTOR2I &aRefPos, int *aOutlineIdx=nullptr, int *aHoleIdx=nullptr) const
Test if the given point is contained within a cutout of the zone.
void Mirror(const VECTOR2I &aMirrorRef, FLIP_DIRECTION aFlipDirection) override
Mirror the outlines relative to a given horizontal axis the layer is not changed.
std::map< PCB_LAYER_ID, std::set< int > > m_insulatedIslands
For each layer, a set of insulated islands that were not removed.
wxString m_zoneName
An optional unique name for this zone, used for identifying it in DRC checking.
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
std::map< PCB_LAYER_ID, std::shared_ptr< SHAPE_POLY_SET > > m_FilledPolysList
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
bool GetDoNotAllowPads() const
const BOX2I GetBoundingBox() const override
void SetMinThickness(int aMinThickness)
void SetPlacementAreaSource(const wxString &aSource)
BOX2I computeBoundingBox() const
Compute the bbox from scratch. Shared so the cached value can't diverge from the live one.
void SetThievingOrientation(const EDA_ANGLE &aOrientation)
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
std::mutex m_filledPolysListMutex
void SetThievingPattern(THIEVING_PATTERN aPattern)
wxString GetFriendlyName() const override
bool GetDoNotAllowTracks() const
int GetLocalFlags() const
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetHatchOrientation(const EDA_ANGLE &aStep)
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuildBorderHatch)
Set all hatch parameters for the zone.
void SetThievingElementSize(int aSize)
void SetHatchSmoothingValue(double aValue)
void CacheOutlineTriangulation()
Triangulate the zone outline only.
std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > m_layerProperties
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
bool HitTestForCorner(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a corner.
void SetHatchSmoothingLevel(int aLevel)
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
void SetPlacementAreaSourceType(PLACEMENT_SOURCE_T aType)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
SHAPE_POLY_SET * Outline()
ZONE(BOARD_ITEM_CONTAINER *parent)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
void Move(const VECTOR2I &offset) override
Move the outlines.
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
std::atomic< int > m_bboxCacheTimeStamp
bool IsCopperThieving() const
BOX2I m_bboxCache
Lock-free bbox cache, valid while m_bboxCacheTimeStamp matches the board timestamp.
SHAPE_POLY_SET * m_Poly
Outline of the zone.
TEARDROP_TYPE m_teardropType
A zone outline can be a teardrop zone with different rules for priority (always bigger priority than ...
std::map< PCB_LAYER_ID, HASH_128 > m_filledPolysHash
A hash value used in zone filling calculations to see if the filled areas are up to date.
long long int GetMinIslandArea() const
int m_hatchSmoothingLevel
void SetThievingStagger(bool aStagger)
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void SetIsRuleArea(bool aEnable)
void CopyFrom(const BOARD_ITEM *aOther) override
void SetThievingGap(int aGap)
void SetDoNotAllowTracks(bool aEnable)
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
bool m_placementAreaEnabled
Placement rule area data.
const wxString & GetZoneName() const
void CacheBoundingBox()
Used to preload the zone bounding box cache so we don't have to worry about mutex-locking it each tim...
int GetMinThickness() const
virtual void swapData(BOARD_ITEM *aImage) override
bool HitTestForEdge(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a segment defined by 2 corners.
SHAPE_POLY_SET GetBoardOutline() const
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
void Rotate(const VECTOR2I &aCentre, const EDA_ANGLE &aAngle) override
Rotate the outlines.
ZONE_SETTINGS::CORNER_SMOOTHING GetCornerSmoothingType() const
bool HigherPriority(const ZONE *aOther) const
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const VECTOR2I &aRefPos, int aAccuracy=0) const
Test if the given VECTOR2I is within the bounds of a filled area of this zone.
void SetIsFilled(bool isFilled)
std::mutex m_layerSetMutex
void SetFillMode(ZONE_FILL_MODE aFillMode)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
ZONE_CONNECTION GetPadConnection() const
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
int GetHatchThickness() const
double GetHatchHoleMinArea() const
void invalidateBoundingBoxCache() const
void SetLayerSet(const LSET &aLayerSet) override
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
int m_hatchBorderAlgorithm
bool GetPlacementAreaEnabled() const
void SetDoNotAllowVias(bool aEnable)
bool IsTeardropArea() const
std::vector< SEG > m_borderHatchLines
VECTOR2I GetPosition() const override
int GetThermalReliefSpokeWidth() const
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void BuildHashValue(PCB_LAYER_ID aLayer)
Build the hash value of m_FilledPolysList, and store it internally in m_filledPolysHash.
void SetThermalReliefGap(int aThermalReliefGap)
EDA_ANGLE GetHatchOrientation() const
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
EDA_ORIENTATION m_hatchOrientation
bool GetDoNotAllowFootprints() const
ZONE_FILL_MODE GetFillMode() const
double m_hatchHoleMinArea
std::vector< PCB_LAYER_ID > GetFilledLayers() const
Create a list of triangles that "fill" the solid areas used for instance to draw these solid areas on...
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool GetThievingStagger() const
void SetDoNotAllowFootprints(bool aEnable)
void SetBorderHatchPitch(int aPitch)
void SetThievingLineWidth(int aWidth)
void GetInteractingZones(PCB_LAYER_ID aLayer, std::vector< ZONE * > *aSameNetCollidingZones, std::vector< ZONE * > *aOtherNetIntersectingZones) const
Some intersecting zones, despite being on the same layer with the same net, cannot be merged due to o...
void SetLayerSetAndRemoveUnusedFills(const LSET &aLayerSet)
Set the zone to be on the aLayerSet layers and only remove the fill polygons from the unused layers,...
double CalculateOutlineArea()
Compute the area of the zone outline (not the filled area).
int GetThievingGap() const
void SetHatchHoleMinArea(double aPct)
unsigned m_priority
Priority: when a zone outline is inside and other zone, if its priority is higher the other zone prio...
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
bool IsConflicting() const
For rule areas which exclude footprints (and therefore participate in courtyard conflicts during move...
bool m_doNotAllowZoneFills
For keepout zones only: what is not allowed inside the keepout ( pads, tracks and vias )
ISLAND_REMOVAL_MODE m_islandRemovalMode
std::vector< SEG > GetHatchLines() const
bool m_isFilled
True when a zone was filled, false after deleting the filled areas.
double GetHatchSmoothingValue() const
std::atomic< bool > m_needRefill
False when a zone was refilled, true after changes in zone params.
THIEVING_PATTERN GetThievingPattern() const
bool GetDoNotAllowZoneFills() const
void MoveEdge(const VECTOR2I &offset, int aEdge)
Move the outline Edge.
int GetHatchSmoothingLevel() const
unsigned int GetCornerRadius() const
int GetThievingElementSize() const
SHAPE_POLY_SET GetLibraryOutline() const
bool IsOnCopperLayer() const override
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
void SetDoNotAllowZoneFills(bool aEnable)
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
ZONE_SETTINGS::CORNER_SMOOTHING m_cornerSmoothingType
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the zone shape to a closed polygon Used in filling zones calculations Circles and arcs are ap...
void SetAssignedPriority(unsigned aPriority)
unsigned int m_cornerRadius
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetZoneName(const wxString &aName)
bool operator==(const ZONE &aOther) const
void UnHatchBorder()
Clear the zone's hatch.
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
EDA_ANGLE GetThievingOrientation() const
double GetCoverageArea(int aTextMargin) const override
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
void SetOutline(SHAPE_POLY_SET *aOutline)
PCB_LAYER_ID GetFirstLayer() const
void SetMinIslandArea(long long int aArea)
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
HASH_128 GetHashValue(PCB_LAYER_ID aLayer)
ZONE_CONNECTION m_PadConnection
void InitDataFromSrcInCopyCtor(const ZONE &aZone, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Copy aZone data to me.
int GetThermalReliefGap() const
void SetHatchGap(int aStep)
static int GetDefaultHatchPitch()
void SetPlacementAreaEnabled(bool aEnabled)
unsigned GetAssignedPriority() const
int GetNumCorners(void) const
Access to m_Poly parameters.
bool SameNet(const ZONE *aOther) const
ZONE_BORDER_DISPLAY_STYLE m_borderStyle
long long int m_minIslandArea
When island removal mode is set to AREA, islands below this area will be removed.
A type-safe container of any type.
@ ROUND_ALL_CORNERS
All angles are rounded.
static constexpr EDA_ANGLE ANGLE_0
#define PCB_EDIT_FRAME_NAME
#define COURTYARD_CONFLICT
temporary set when moving footprints having courtyard overlapping
a few functions useful in geometry calculations.
Some functions to handle hotkeys in KiCad.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
PCB_LAYER_ID
A quick note on layer IDs:
size_t longest_common_subset(const _Container &__c1, const _Container &__c2)
Returns the length of the longest common subset of values between two containers.
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
KICOMMON_API void PackPolySet(types::PolySet &aOutput, const SHAPE_POLY_SET &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
KICOMMON_API SHAPE_POLY_SET UnpackPolySet(const types::PolySet &aInput, const EDA_IU_SCALE &aScale)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
#define IMPLEMENT_ENUM_TO_WXANY(type)
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
@ PT_DEGREE
Angle expressed in degrees.
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
@ PT_SIZE
Size expressed in distance units (mm/inch)
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
wxString UnescapeString(const wxString &aSource)
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
A storage class for 128-bit hash value.
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
std::optional< VECTOR2I > hatching_offset
TEARDROP_TYPE
define the type of a teardrop: on a via or pad, or a track end
wxString result
Test unit parsing edge cases and error handling.
@ PCB_ZONE_T
class ZONE, a copper pour area
VECTOR2< int32_t > VECTOR2I
static SHAPE_POLY_SET g_nullPoly
static struct ZONE_DESC _ZONE_DESC
THIEVING_PATTERN
Shape stamped onto the grid for a copper-thieving fill.
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
#define ZONE_CLEARANCE_MAX_VALUE_MM
ZONE_CONNECTION
How pads are covered by copper in zone.
@ THERMAL
Use thermal relief for pads.
@ THT_THERMAL
Thermal relief only for THT pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper
#define ZONE_BORDER_HATCH_DIST_MM
#define ZONE_BORDER_HATCH_MINDIST_MM
#define ZONE_THICKNESS_MIN_VALUE_MM
#define ZONE_BORDER_HATCH_MAXDIST_MM