mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 22:23:43 +00:00
API: Add initial spec for ZONE serialization
This commit is contained in:
parent
d7137c4a05
commit
dd65a44dd6
api/proto/board
pcbnew
qa/tests/api
@ -483,10 +483,134 @@ message Pad
|
||||
kiapi.common.types.Distance copper_clearance_override = 8;
|
||||
}
|
||||
|
||||
// Copper zone, non-copper zone, or rule area
|
||||
enum ZoneType
|
||||
{
|
||||
ZT_UNKNOWN = 0;
|
||||
ZT_COPPER = 1;
|
||||
ZT_GRAPHICAL = 2;
|
||||
ZT_RULE_AREA = 3;
|
||||
ZT_TEARDROP = 4;
|
||||
}
|
||||
|
||||
enum IslandRemovalMode
|
||||
{
|
||||
IRM_UNKNOWN = 0;
|
||||
IRM_ALWAYS = 1;
|
||||
IRM_NEVER = 2;
|
||||
IRM_AREA = 3;
|
||||
}
|
||||
|
||||
enum ZoneFillMode
|
||||
{
|
||||
ZFM_UNKNOWN = 0;
|
||||
ZFM_SOLID = 1;
|
||||
ZFM_HATCHED = 2;
|
||||
}
|
||||
|
||||
enum ZoneHatchSmoothing
|
||||
{
|
||||
ZHS_UNKNOWN = 0;
|
||||
ZHS_NONE = 1;
|
||||
ZHS_FILLET = 2;
|
||||
ZHS_ARC_LOW_DEF = 3;
|
||||
ZHS_ARC_HIGH_DEF = 4;
|
||||
}
|
||||
|
||||
enum ZoneHatchFillBorderMode
|
||||
{
|
||||
ZHFBM_UNKNOWN = 0;
|
||||
ZHFBM_USE_MIN_ZONE_THICKNESS = 1;
|
||||
ZHFMB_USE_HATCH_THICKNESS = 2;
|
||||
}
|
||||
|
||||
message HatchFillSettings
|
||||
{
|
||||
kiapi.common.types.Distance thickness = 1;
|
||||
kiapi.common.types.Distance gap = 2;
|
||||
kiapi.common.types.Angle orientation = 3;
|
||||
double hatch_smoothing_ratio = 4;
|
||||
double hatch_hole_min_area_ratio = 5;
|
||||
ZoneHatchFillBorderMode border_mode = 6;
|
||||
}
|
||||
|
||||
message CopperZoneSettings
|
||||
{
|
||||
ZoneConnectionSettings connection = 1;
|
||||
|
||||
kiapi.common.types.Distance clearance = 2;
|
||||
|
||||
kiapi.common.types.Distance min_thickness = 3;
|
||||
|
||||
IslandRemovalMode island_mode = 4;
|
||||
|
||||
uint64 min_island_area = 5;
|
||||
|
||||
ThermalSpokeSettings thermal_spokes = 6;
|
||||
|
||||
ZoneFillMode fill_mode = 7;
|
||||
|
||||
HatchFillSettings hatch_settings = 8;
|
||||
|
||||
Net net = 9;
|
||||
}
|
||||
|
||||
enum PlacementRuleSourceType
|
||||
{
|
||||
PRST_UNKNOWN = 0;
|
||||
PRST_SHEET_NAME = 1;
|
||||
PRST_COMPONENT_CLASS = 2;
|
||||
}
|
||||
|
||||
message RuleAreaSettings
|
||||
{
|
||||
bool keepout_copper = 1;
|
||||
bool keepout_vias = 2;
|
||||
bool keepout_tracks = 3;
|
||||
bool keepout_pads = 4;
|
||||
bool keepout_footprints = 5;
|
||||
|
||||
bool placement_enabled = 6;
|
||||
PlacementRuleSourceType placement_source_type = 7;
|
||||
string placement_source = 8;
|
||||
}
|
||||
|
||||
enum ZoneBorderStyle
|
||||
{
|
||||
ZBS_UNKNOWN = 0;
|
||||
ZBS_SOLID = 1;
|
||||
ZBS_DIAGONAL_FULL = 2;
|
||||
ZBS_DIAGONAL_EDGE = 3;
|
||||
ZBS_INVISIBLE = 4;
|
||||
}
|
||||
|
||||
message ZoneBorderSettings
|
||||
{
|
||||
ZoneBorderStyle style = 1;
|
||||
kiapi.common.types.Distance pitch = 2;
|
||||
}
|
||||
|
||||
message Zone
|
||||
{
|
||||
// TODO
|
||||
kiapi.common.types.KIID id = 1;
|
||||
|
||||
ZoneType type = 2;
|
||||
|
||||
repeated BoardLayer layers = 3;
|
||||
|
||||
kiapi.common.types.PolygonWithHoles outline = 4;
|
||||
|
||||
string name = 5;
|
||||
|
||||
oneof settings {
|
||||
CopperZoneSettings copper_settings = 6;
|
||||
RuleAreaSettings rule_area_settings = 7;
|
||||
}
|
||||
|
||||
uint32 priority = 8;
|
||||
|
||||
bool filled = 9;
|
||||
|
||||
repeated kiapi.common.types.PolySet filled_shape = 10;
|
||||
}
|
||||
|
||||
message Dimension
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <padstack.h>
|
||||
#include <pcb_track.h>
|
||||
#include <zones.h>
|
||||
#include <zone_settings.h>
|
||||
|
||||
using namespace kiapi::board;
|
||||
|
||||
@ -271,3 +272,135 @@ PADSTACK::UNCONNECTED_LAYER_MODE FromProtoEnum( types::UnconnectedLayerRemoval a
|
||||
"Unhandled case in FromProtoEnum<types::UnconnectedLayerRemoval>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::IslandRemovalMode ToProtoEnum( ISLAND_REMOVAL_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case ISLAND_REMOVAL_MODE::ALWAYS: return types::IslandRemovalMode::IRM_ALWAYS;
|
||||
case ISLAND_REMOVAL_MODE::NEVER: return types::IslandRemovalMode::IRM_NEVER;
|
||||
case ISLAND_REMOVAL_MODE::AREA: return types::IslandRemovalMode::IRM_AREA;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::IslandRemovalMode::IRM_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<ISLAND_REMOVAL_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
ISLAND_REMOVAL_MODE FromProtoEnum( types::IslandRemovalMode aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::IslandRemovalMode::IRM_ALWAYS: return ISLAND_REMOVAL_MODE::ALWAYS;
|
||||
case types::IslandRemovalMode::IRM_NEVER: return ISLAND_REMOVAL_MODE::NEVER;
|
||||
case types::IslandRemovalMode::IRM_AREA: return ISLAND_REMOVAL_MODE::AREA;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, ISLAND_REMOVAL_MODE::ALWAYS,
|
||||
"Unhandled case in FromProtoEnum<types::IslandRemovalMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::ZoneFillMode ToProtoEnum( ZONE_FILL_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case ZONE_FILL_MODE::POLYGONS: return types::ZoneFillMode::ZFM_SOLID;
|
||||
case ZONE_FILL_MODE::HATCH_PATTERN: return types::ZoneFillMode::ZFM_HATCHED;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::ZoneFillMode::ZFM_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<ZONE_FILL_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
ZONE_FILL_MODE FromProtoEnum( types::ZoneFillMode aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::ZoneFillMode::ZFM_SOLID: return ZONE_FILL_MODE::POLYGONS;
|
||||
case types::ZoneFillMode::ZFM_HATCHED: return ZONE_FILL_MODE::HATCH_PATTERN;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, ZONE_FILL_MODE::POLYGONS,
|
||||
"Unhandled case in FromProtoEnum<types::ZoneFillMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::ZoneBorderStyle ToProtoEnum( ZONE_BORDER_DISPLAY_STYLE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: return types::ZoneBorderStyle::ZBS_SOLID;
|
||||
case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: return types::ZoneBorderStyle::ZBS_DIAGONAL_FULL;
|
||||
case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: return types::ZoneBorderStyle::ZBS_DIAGONAL_EDGE;
|
||||
case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: return types::ZoneBorderStyle::ZBS_INVISIBLE;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::ZoneBorderStyle::ZBS_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<ZONE_BORDER_DISPLAY_STYLE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
ZONE_BORDER_DISPLAY_STYLE FromProtoEnum( types::ZoneBorderStyle aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::ZoneBorderStyle::ZBS_SOLID: return ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
|
||||
case types::ZoneBorderStyle::ZBS_DIAGONAL_FULL: return ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
|
||||
case types::ZoneBorderStyle::ZBS_DIAGONAL_EDGE: return ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
|
||||
case types::ZoneBorderStyle::ZBS_INVISIBLE: return ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
||||
"Unhandled case in FromProtoEnum<types::ZoneHatchBorderMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::PlacementRuleSourceType ToProtoEnum( RULE_AREA_PLACEMENT_SOURCE_TYPE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
|
||||
return types::PlacementRuleSourceType::PRST_SHEET_NAME;
|
||||
|
||||
case RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS:
|
||||
return types::PlacementRuleSourceType::PRST_COMPONENT_CLASS;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::PlacementRuleSourceType::PRST_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<RULE_AREA_PLACEMENT_SOURCE_TYPE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
RULE_AREA_PLACEMENT_SOURCE_TYPE FromProtoEnum( types::PlacementRuleSourceType aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::PlacementRuleSourceType::PRST_SHEET_NAME:
|
||||
return RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
|
||||
|
||||
case types::PlacementRuleSourceType::PRST_COMPONENT_CLASS:
|
||||
return RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME,
|
||||
"Unhandled case in FromProtoEnum<types::PlacementRuleSourceType>" );
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,12 @@
|
||||
#include <i18n_utility.h>
|
||||
#include <mutex>
|
||||
|
||||
#include <google/protobuf/any.pb.h>
|
||||
#include <api/api_enums.h>
|
||||
#include <api/api_utils.h>
|
||||
#include <api/api_pcb_utils.h>
|
||||
#include <api/board/board_types.pb.h>
|
||||
|
||||
|
||||
ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent ) :
|
||||
BOARD_CONNECTED_ITEM( aParent, PCB_ZONE_T ),
|
||||
@ -204,6 +210,52 @@ EDA_ITEM* ZONE::Clone() const
|
||||
}
|
||||
|
||||
|
||||
void ZONE::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
kiapi::board::types::Zone zone;
|
||||
|
||||
zone.mutable_id()->set_value( m_Uuid.AsStdString() );
|
||||
zone.set_filled( IsFilled() );
|
||||
kiapi::board::PackLayerSet( *zone.mutable_layers(), GetLayerSet() );
|
||||
|
||||
if( m_isRuleArea )
|
||||
zone.set_type( kiapi::board::types::ZT_RULE_AREA );
|
||||
else if( m_teardropType != TEARDROP_TYPE::TD_NONE )
|
||||
zone.set_type( kiapi::board::types::ZT_TEARDROP );
|
||||
else if( IsOnCopperLayer() )
|
||||
zone.set_type( kiapi::board::types::ZT_COPPER );
|
||||
else
|
||||
zone.set_type( kiapi::board::types::ZT_GRAPHICAL );
|
||||
|
||||
// TODO(JE) need to pack m_teardropType to enable round-tripping
|
||||
|
||||
zone.set_name( m_zoneName.ToUTF8() );
|
||||
|
||||
aContainer.PackFrom( zone );
|
||||
}
|
||||
|
||||
|
||||
bool ZONE::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
kiapi::board::types::Zone zone;
|
||||
|
||||
if( !aContainer.UnpackTo( &zone ) )
|
||||
return false;
|
||||
|
||||
const_cast<KIID&>( m_Uuid ) = KIID( zone.id().value() );
|
||||
SetLayerSet( kiapi::board::UnpackLayerSet( zone.layers() ) );
|
||||
|
||||
if( zone.filled() )
|
||||
{
|
||||
// TODO(JE) check what else has to happen here
|
||||
SetIsFilled( true );
|
||||
SetNeedRefill( false );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ZONE::HigherPriority( const ZONE* aOther ) const
|
||||
{
|
||||
// Teardrops are always higher priority than regular zones, so if one zone is a teardrop
|
||||
|
@ -84,6 +84,9 @@ public:
|
||||
return aItem && aItem->Type() == PCB_ZONE_T;
|
||||
}
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
/**
|
||||
* Not all ZONEs are *really* BOARD_CONNECTED_ITEMs....
|
||||
*/
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <padstack.h>
|
||||
#include <pcb_track.h>
|
||||
#include <zones.h>
|
||||
#include <zone_settings.h>
|
||||
|
||||
using namespace kiapi::common;
|
||||
|
||||
@ -187,5 +188,24 @@ BOOST_AUTO_TEST_CASE( ViaType )
|
||||
testEnums<VIATYPE, kiapi::board::types::ViaType>( true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( IslandRemovalMode )
|
||||
{
|
||||
testEnums<ISLAND_REMOVAL_MODE, kiapi::board::types::IslandRemovalMode>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ZoneFillMode )
|
||||
{
|
||||
testEnums<ZONE_FILL_MODE, kiapi::board::types::ZoneFillMode>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ZoneBorderStyle )
|
||||
{
|
||||
testEnums<ZONE_BORDER_DISPLAY_STYLE, kiapi::board::types::ZoneBorderStyle>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( PlacementRuleSourceType )
|
||||
{
|
||||
testEnums<RULE_AREA_PLACEMENT_SOURCE_TYPE, kiapi::board::types::PlacementRuleSourceType>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user