7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 17:03:44 +00:00

API: Implement Deserialize for ZONE

This commit is contained in:
Jon Evans 2024-11-23 12:06:54 -05:00
parent 4ab8c23851
commit af91519e06
5 changed files with 237 additions and 44 deletions

View File

@ -635,6 +635,8 @@ message Zone
repeated ZoneFilledPolygons filled_polygons = 10;
ZoneBorderSettings border = 11;
kiapi.common.types.LockedState locked = 12;
}
message Dimension

View File

@ -216,7 +216,6 @@ void ZONE::Serialize( google::protobuf::Any& aContainer ) const
types::Zone zone;
zone.mutable_id()->set_value( m_Uuid.AsStdString() );
zone.set_filled( IsFilled() );
PackLayerSet( *zone.mutable_layers(), GetLayerSet() );
if( m_isRuleArea )
@ -312,12 +311,76 @@ bool ZONE::Deserialize( const google::protobuf::Any& aContainer )
const_cast<KIID&>( m_Uuid ) = KIID( zone.id().value() );
SetLayerSet( UnpackLayerSet( zone.layers() ) );
SetAssignedPriority( zone.priority() );
SetZoneName( wxString::FromUTF8( zone.name() ) );
if( zone.type() == types::ZoneType::ZT_RULE_AREA )
m_isRuleArea = true;
if( !m_Poly )
SetOutline( new SHAPE_POLY_SET );
*m_Poly = kiapi::common::UnpackPolySet( zone.outline() );
if( m_isRuleArea )
{
const types::RuleAreaSettings& ra = zone.rule_area_settings();
m_doNotAllowCopperPour = ra.keepout_copper();
m_doNotAllowFootprints = ra.keepout_footprints();
m_doNotAllowPads = ra.keepout_pads();
m_doNotAllowTracks = ra.keepout_tracks();
m_doNotAllowVias = ra.keepout_vias();
m_ruleAreaPlacementEnabled = ra.placement_enabled();
m_ruleAreaPlacementSource = wxString::FromUTF8( ra.placement_source() );
m_ruleAreaPlacementSourceType =
FromProtoEnum<RULE_AREA_PLACEMENT_SOURCE_TYPE>( ra.placement_source_type() );
}
else
{
const types::CopperZoneSettings& cu = zone.copper_settings();
m_PadConnection = FromProtoEnum<ZONE_CONNECTION>( cu.connection().zone_connection() );
m_thermalReliefSpokeWidth = cu.connection().thermal_spokes().width();
m_thermalReliefGap = cu.connection().thermal_spokes().gap();
m_ZoneClearance = cu.clearance().value_nm();
m_ZoneMinThickness = cu.min_thickness().value_nm();
m_islandRemovalMode = FromProtoEnum<ISLAND_REMOVAL_MODE>( cu.island_mode() );
m_minIslandArea = cu.min_island_area();
m_fillMode = FromProtoEnum<ZONE_FILL_MODE>( cu.fill_mode() );
m_hatchThickness = cu.hatch_settings().thickness().value_nm();
m_hatchGap = cu.hatch_settings().gap().value_nm();
m_hatchOrientation =
EDA_ANGLE( cu.hatch_settings().orientation().value_degrees(), DEGREES_T );
m_hatchSmoothingValue = cu.hatch_settings().hatch_smoothing_ratio();
m_hatchHoleMinArea = cu.hatch_settings().hatch_hole_min_area_ratio();
switch( cu.hatch_settings().border_mode() )
{
default:
case types::ZHFBM_USE_MIN_ZONE_THICKNESS: m_hatchBorderAlgorithm = 0; break;
case types::ZHFBM_USE_HATCH_THICKNESS: m_hatchBorderAlgorithm = 1; break;
}
SetNetCode( cu.net().code().value() );
m_teardropType = FromProtoEnum<TEARDROP_TYPE>( cu.teardrop().type() );
}
m_borderStyle = FromProtoEnum<ZONE_BORDER_DISPLAY_STYLE>( zone.border().style() );
m_borderHatchPitch = zone.border().pitch().value_nm();
if( zone.filled() )
{
// TODO(JE) check what else has to happen here
SetIsFilled( true );
SetNeedRefill( false );
for( const types::ZoneFilledPolygons& fillLayer : zone.filled_polygons() )
{
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( fillLayer.layer() );
SHAPE_POLY_SET shape = kiapi::common::UnpackPolySet( fillLayer.shapes() );
m_FilledPolysList[layer] = std::make_shared<SHAPE_POLY_SET>( shape );
}
}
return true;

View File

LOADING design file

View File

@ -48,7 +48,7 @@
"silk_text_thickness": 0.1,
"silk_text_upright": false,
"zones": {
"min_clearance": 0.5
"min_clearance": 0.0
}
},
"diff_pair_dimensions": [],
@ -63,16 +63,20 @@
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "error",
"creepage": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_filters_mismatch": "ignore",
"footprint_symbol_mismatch": "warning",
"footprint_type_mismatch": "ignore",
"hole_clearance": "error",
"hole_near_hole": "error",
"hole_to_hole": "warning",
"holes_co_located": "warning",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
@ -99,7 +103,9 @@
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_angle": "error",
"track_dangling": "warning",
"track_segment_length": "error",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
@ -112,6 +118,7 @@
"min_clearance": 0.0,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.5,
"min_groove_width": 0.0,
"min_hole_clearance": 0.25,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.2,
@ -129,10 +136,11 @@
},
"teardrop_options": [
{
"td_onpadsmd": true,
"td_onpthpad": true,
"td_onroundshapesonly": false,
"td_onsmdpad": true,
"td_ontrackend": false,
"td_onviapad": true
"td_onvia": true
}
],
"teardrop_parameters": [
@ -207,6 +215,7 @@
"mfg": "",
"mpn": ""
},
"layer_pairs": [],
"layer_presets": [],
"viewports": []
},
@ -220,7 +229,7 @@
},
"meta": {
"filename": "api_kitchen_sink.kicad_pro",
"version": 1
"version": 2
},
"net_settings": {
"classes": [
@ -235,6 +244,7 @@
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"priority": 2147483647,
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.2,
"via_diameter": 0.6,
@ -243,7 +253,7 @@
}
],
"meta": {
"version": 3
"version": 4
},
"net_colors": null,
"netclass_assignments": null,

View File

@ -113,9 +113,14 @@ BOOST_FIXTURE_TEST_CASE( BoardTypes, PROTO_TEST_FIXTURE )
for( FOOTPRINT* footprint : m_board->Footprints() )
testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint );
// Not yet
// for( ZONE* zone : m_board->Zones() )
// testProtoFromKiCadObject<kiapi::board::types::Zone>( zone );
for( ZONE* zone : m_board->Zones() )
testProtoFromKiCadObject<kiapi::board::types::Zone>( zone );
// TODO(JE) Shapes
// TODO(JE) Text
// TODO(JE) Dimensions
}