7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-19 17:51:41 +00:00

Don't store DRC expressions in file format for placement rule areas

This commit is contained in:
JamesJCode 2024-10-09 01:06:11 +01:00
parent a6923b3de3
commit bc0c9634b8
12 changed files with 168 additions and 46 deletions

View File

@ -74,6 +74,7 @@ column_count
column_widths
comment
company
component_class
component_classes
connect
connect_pads
@ -115,7 +116,6 @@ end
epsilon_r
exclude_from_pos_files
exclude_from_bom
expr
extension_height
extension_offset
external

View File

@ -162,28 +162,30 @@ bool DIALOG_RULE_AREA_PROPERTIES::TransferDataToWindow()
m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
}
// Init keepout parameters:
m_cbTracksCtrl->SetValue( m_zonesettings.GetDoNotAllowTracks() );
m_cbViasCtrl->SetValue( m_zonesettings.GetDoNotAllowVias() );
m_cbPadsCtrl->SetValue( m_zonesettings.GetDoNotAllowPads() );
m_cbFootprintsCtrl->SetValue( m_zonesettings.GetDoNotAllowFootprints() );
m_cbCopperPourCtrl->SetValue( m_zonesettings.GetDoNotAllowCopperPour() );
// Init placement parameters:
m_ruleText->SetText( m_zonesettings.GetRuleAreaPlacementSource() );
if( m_zonesettings.GetRuleAreaType() == RULE_AREA_TYPE::KEEPOUT )
{
// Init keepout parameters:
m_cbTracksCtrl->SetValue( m_zonesettings.GetDoNotAllowTracks() );
m_cbViasCtrl->SetValue( m_zonesettings.GetDoNotAllowVias() );
m_cbPadsCtrl->SetValue( m_zonesettings.GetDoNotAllowPads() );
m_cbFootprintsCtrl->SetValue( m_zonesettings.GetDoNotAllowFootprints() );
m_cbCopperPourCtrl->SetValue( m_zonesettings.GetDoNotAllowCopperPour() );
m_rbRuleType->Select( 0 );
m_placementRuleSizer->Show( false );
m_keepoutRuleSizer->Show( true );
}
else
{
m_rbRuleType->Select( 1 );
m_placementRuleSizer->Show( true );
m_keepoutRuleSizer->Show( false );
m_rbRuleType->Select( 1 );
}
m_ruleText->SetText( m_zonesettings.GetRuleAreaExpression() );
m_cbLocked->SetValue( m_zonesettings.m_Locked );
m_tcName->SetValue( m_zonesettings.m_Name );
switch( m_zonesettings.m_ZoneBorderDisplayStyle )
@ -268,7 +270,8 @@ bool DIALOG_RULE_AREA_PROPERTIES::TransferDataFromWindow()
// Init keepout parameters:
m_zonesettings.SetRuleAreaType( m_rbRuleType->GetSelection() == 0 ? RULE_AREA_TYPE::KEEPOUT : RULE_AREA_TYPE::PLACEMENT );
m_zonesettings.SetRuleAreaExpression( m_ruleText->GetText() );
m_zonesettings.SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
m_zonesettings.SetRuleAreaPlacementSource( m_ruleText->GetText() );
m_zonesettings.SetIsRuleArea( true );
m_zonesettings.SetDoNotAllowTracks( m_cbTracksCtrl->GetValue() );
m_zonesettings.SetDoNotAllowVias( m_cbViasCtrl->GetValue() );

View File

@ -113,7 +113,7 @@ DIALOG_RULE_AREA_PROPERTIES_BASE::DIALOG_RULE_AREA_PROPERTIES_BASE( wxWindow* pa
m_placementRuleSizer->SetFlexibleDirection( wxBOTH );
m_placementRuleSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText31 = new wxStaticText( this, wxID_ANY, _("Condition:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText31 = new wxStaticText( this, wxID_ANY, _("Schematic Sheetname:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText31->Wrap( -1 );
m_staticText31->SetToolTip( _("A unique name for this rule area for use in DRC rules") );

View File

@ -887,7 +887,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Condition:</property>
<property name="label">Schematic Sheetname:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>

View File

@ -2694,24 +2694,45 @@ void PCB_IO_KICAD_SEXPR::format( const ZONE* aZone, int aNestLevel ) const
{
switch( aZone->GetRuleAreaType() )
{
case RULE_AREA_TYPE::KEEPOUT:
m_out->Print( aNestLevel + 1,
"(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) "
"(footprints %s))\n",
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
break;
case RULE_AREA_TYPE::KEEPOUT:
{
m_out->Print( aNestLevel + 1,
"(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) "
"(footprints %s))\n",
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
break;
}
case RULE_AREA_TYPE::PLACEMENT:
{
m_out->Print( aNestLevel + 1, "(placement" );
m_out->Print( aNestLevel + 2, "(enabled " );
case RULE_AREA_TYPE::PLACEMENT:
m_out->Print( aNestLevel + 1,
"(placement (expr %s))", m_out->Quotew( aZone->GetRuleAreaExpression() ).c_str() );
break;
if( aZone->GetRuleAreaPlacementEnabled() )
m_out->Print( aNestLevel + 2, "yes)" );
else
m_out->Print( aNestLevel + 2, "no)" );
default:
switch( aZone->GetRuleAreaPlacementSourceType() )
{
case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
m_out->Print( aNestLevel + 2, "(sheetname %s)",
m_out->Quotew( aZone->GetRuleAreaPlacementSource() ).c_str() );
break;
case RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS:
m_out->Print( aNestLevel + 2, "(component_class %s)",
m_out->Quotew( aZone->GetRuleAreaPlacementSource() ).c_str() );
break;
}
m_out->Print( aNestLevel + 1, ")" );
break;
}
default:
break;
}
}

View File

@ -166,7 +166,8 @@ class PCB_IO_KICAD_SEXPR; // forward decl
//#define SEXPR_BOARD_FILE_VERSION 20240928 // Component classes
//#define SEXPR_BOARD_FILE_VERSION 20240929 // Complex padstacks
//#define SEXPR_BOARD_FILE_VERSION 20241006 // Via stacks
#define SEXPR_BOARD_FILE_VERSION 20241007 // Tracks can have soldermask layer and margin
//#define SEXPR_BOARD_FILE_VERSION 20241007 // Tracks can have soldermask layer and margin
#define SEXPR_BOARD_FILE_VERSION 20241009 // Evolve placement rule areas file format
#define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag
#define LEGACY_ARC_FORMATTING 20210925 ///< These were the last to use old arc formatting

View File

@ -6854,10 +6854,42 @@ ZONE* PCB_IO_KICAD_SEXPR_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
if( token == T_LEFT )
token = NextTok();
if( token == T_expr )
switch( token )
{
case T_sheetname:
{
zone->SetRuleAreaPlacementSourceType(
RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
NeedSYMBOL();
zone->SetRuleAreaPlacementSource( FromUTF8() );
break;
}
case T_component_class:
{
zone->SetRuleAreaPlacementSourceType(
RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS );
NeedSYMBOL();
zone->SetRuleAreaPlacementSource( FromUTF8() );
break;
}
case T_enabled:
{
token = NextTok();
zone->SetRuleAreaExpression( FromUTF8() );
if( token == T_yes )
zone->SetRuleAreaPlacementEnabled( true );
else if( token == T_no )
zone->SetRuleAreaPlacementEnabled( false );
else
Expecting( "yes or no" );
break;
}
default:
{
Expecting( "enabled, sheetname or component_class" );
break;
}
}
NeedRIGHT();

View File

@ -87,7 +87,21 @@ bool MULTICHANNEL_TOOL::identifyComponentsInRuleArea( ZONE* aRul
wxLogTrace( traceMultichannelTool, wxT( "rule area '%s'"), aRuleArea->GetZoneName() );
auto ok = compiler.Compile( aRuleArea->GetRuleAreaExpression(), &ucode, &preflightCtx );
wxString ruleText;
switch( aRuleArea->GetRuleAreaPlacementSourceType() )
{
case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
{
ruleText =
wxT( "A.memberOfSheet('" ) + aRuleArea->GetRuleAreaPlacementSource() + wxT( "')" );
break;
}
default:
wxFAIL_MSG( "RULE_AREA_PLACEMENT_SOURCE_TYPE not yet implemented" );
}
auto ok = compiler.Compile( ruleText, &ucode, &preflightCtx );
if( !ok )
{
@ -749,8 +763,8 @@ int MULTICHANNEL_TOOL::AutogenerateRuleAreas( const TOOL_EVENT& aEvent )
newZone->SetIsRuleArea( true );
newZone->SetLayerSet( LSET::AllCuMask() );
newZone->SetRuleAreaType( RULE_AREA_TYPE::PLACEMENT );
newZone->SetRuleAreaExpression(
wxString::Format( wxT( "A.memberOfSheet('%s')" ), ra.m_sheetPath ) );
newZone->SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
newZone->SetRuleAreaPlacementSource( ra.m_sheetPath );
newZone->AddPolygon( raOutline );
newZone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );

View File

@ -50,6 +50,7 @@ ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent ) :
m_cornerRadius( 0 ),
m_priority( 0 ),
m_isRuleArea( false ),
m_ruleAreaPlacementEnabled( false ),
m_teardropType( TEARDROP_TYPE::TD_NONE ),
m_PadConnection( ZONE_CONNECTION::NONE ),
m_ZoneClearance( 0 ),
@ -131,8 +132,9 @@ void ZONE::InitDataFromSrcInCopyCtor( const ZONE& aZone )
m_zoneName = aZone.m_zoneName;
m_priority = aZone.m_priority;
m_isRuleArea = aZone.m_isRuleArea;
m_ruleAreaExpression = aZone.m_ruleAreaExpression;
m_ruleAreaType = aZone.m_ruleAreaType;
m_ruleAreaPlacementSourceType = aZone.m_ruleAreaPlacementSourceType;
m_ruleAreaPlacementSource = aZone.m_ruleAreaPlacementSource;
SetLayerSet( aZone.GetLayerSet() );
m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
@ -1463,7 +1465,10 @@ bool ZONE::operator==( const ZONE& aOther ) const
}
else if ( GetRuleAreaType() == RULE_AREA_TYPE::PLACEMENT )
{
if( GetRuleAreaExpression() != other.GetRuleAreaExpression() )
if( GetRuleAreaPlacementSourceType() != other.GetRuleAreaPlacementSourceType() )
return false;
if( GetRuleAreaPlacementSource() != other.GetRuleAreaPlacementSource() )
return false;
}
}

View File

@ -711,7 +711,12 @@ public:
*/
bool GetIsRuleArea() const { return m_isRuleArea; }
RULE_AREA_TYPE GetRuleAreaType() const { return m_ruleAreaType; }
const wxString& GetRuleAreaExpression( ) const { return m_ruleAreaExpression; }
bool GetRuleAreaPlacementEnabled() const { return m_ruleAreaPlacementEnabled ; }
RULE_AREA_PLACEMENT_SOURCE_TYPE GetRuleAreaPlacementSourceType() const
{
return m_ruleAreaPlacementSourceType;
}
wxString GetRuleAreaPlacementSource() const { return m_ruleAreaPlacementSource; }
bool GetDoNotAllowCopperPour() const { return m_doNotAllowCopperPour; }
bool GetDoNotAllowVias() const { return m_doNotAllowVias; }
bool GetDoNotAllowTracks() const { return m_doNotAllowTracks; }
@ -720,7 +725,15 @@ public:
void SetIsRuleArea( bool aEnable ) { m_isRuleArea = aEnable; }
void SetRuleAreaType( RULE_AREA_TYPE aType ) { m_ruleAreaType = aType; }
void SetRuleAreaExpression( const wxString& aExpr ) { m_ruleAreaExpression = aExpr; }
void SetRuleAreaPlacementEnabled( bool aEnabled ) { m_ruleAreaPlacementEnabled = aEnabled; }
void SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE aType )
{
m_ruleAreaPlacementSourceType = aType;
}
void SetRuleAreaPlacementSource( const wxString& aSource )
{
m_ruleAreaPlacementSource = aSource;
}
void SetDoNotAllowCopperPour( bool aEnable ) { m_doNotAllowCopperPour = aEnable; }
void SetDoNotAllowVias( bool aEnable ) { m_doNotAllowVias = aEnable; }
void SetDoNotAllowTracks( bool aEnable ) { m_doNotAllowTracks = aEnable; }
@ -828,9 +841,15 @@ protected:
/* A zone outline can be a keepout zone.
* It will be never filled, and DRC should test for pads, tracks and vias
*/
bool m_isRuleArea;
RULE_AREA_TYPE m_ruleAreaType;
wxString m_ruleAreaExpression;
bool m_isRuleArea;
RULE_AREA_TYPE m_ruleAreaType;
/**
* Placement rule area data
*/
bool m_ruleAreaPlacementEnabled;
RULE_AREA_PLACEMENT_SOURCE_TYPE m_ruleAreaPlacementSourceType;
wxString m_ruleAreaPlacementSource;
/* A zone outline can be a teardrop zone with different rules for priority
* (always bigger priority than copper zones) and never removed from a

View File

@ -110,6 +110,9 @@ bool ZONE_SETTINGS::operator==( const ZONE_SETTINGS& aOther ) const
if( m_cornerSmoothingType != aOther.m_cornerSmoothingType ) return false;
if( m_cornerRadius != aOther.m_cornerRadius ) return false;
if( m_isRuleArea != aOther.m_isRuleArea ) return false;
if( m_ruleAreaType != aOther.m_ruleAreaType ) return false;
if( m_ruleAreaPlacementSourceType != aOther.m_ruleAreaPlacementSourceType ) return false;
if( m_ruleAreaPlacementSource != aOther.m_ruleAreaPlacementSource ) return false;
if( m_keepoutDoNotAllowCopperPour != aOther.m_keepoutDoNotAllowCopperPour ) return false;
if( m_keepoutDoNotAllowVias != aOther.m_keepoutDoNotAllowVias ) return false;
if( m_keepoutDoNotAllowTracks != aOther.m_keepoutDoNotAllowTracks ) return false;
@ -153,8 +156,9 @@ ZONE_SETTINGS& ZONE_SETTINGS::operator << ( const ZONE& aSource )
m_cornerSmoothingType = aSource.GetCornerSmoothingType();
m_cornerRadius = aSource.GetCornerRadius();
m_isRuleArea = aSource.GetIsRuleArea();
m_ruleAreaExpression = aSource.GetRuleAreaExpression();
m_ruleAreaType = aSource.GetRuleAreaType();
m_ruleAreaPlacementSourceType = aSource.GetRuleAreaPlacementSourceType();
m_ruleAreaPlacementSource = aSource.GetRuleAreaPlacementSource();
m_keepoutDoNotAllowCopperPour = aSource.GetDoNotAllowCopperPour();
m_keepoutDoNotAllowVias = aSource.GetDoNotAllowVias();
m_keepoutDoNotAllowTracks = aSource.GetDoNotAllowTracks();
@ -194,7 +198,8 @@ void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const
aTarget.SetCornerRadius( m_cornerRadius );
aTarget.SetIsRuleArea( GetIsRuleArea() );
aTarget.SetRuleAreaType( GetRuleAreaType() );
aTarget.SetRuleAreaExpression( GetRuleAreaExpression() );
aTarget.SetRuleAreaPlacementSourceType( GetRuleAreaPlacementSourceType() );
aTarget.SetRuleAreaPlacementSource( GetRuleAreaPlacementSource() );
aTarget.SetDoNotAllowCopperPour( GetDoNotAllowCopperPour() );
aTarget.SetDoNotAllowVias( GetDoNotAllowVias() );
aTarget.SetDoNotAllowTracks( GetDoNotAllowTracks() );

View File

@ -68,6 +68,12 @@ enum class RULE_AREA_TYPE
PLACEMENT
};
enum class RULE_AREA_PLACEMENT_SOURCE_TYPE
{
SHEETNAME = 0,
COMPONENT_CLASS
};
/**
* ZONE_SETTINGS
* handles zones parameters.
@ -133,12 +139,17 @@ private:
RULE_AREA_TYPE m_ruleAreaType;
/**
* Placement rule area data
*/
RULE_AREA_PLACEMENT_SOURCE_TYPE m_ruleAreaPlacementSourceType;
wxString m_ruleAreaPlacementSource;
bool m_keepoutDoNotAllowCopperPour;
bool m_keepoutDoNotAllowVias;
bool m_keepoutDoNotAllowTracks;
bool m_keepoutDoNotAllowPads;
bool m_keepoutDoNotAllowFootprints;
wxString m_ruleAreaExpression;
ISLAND_REMOVAL_MODE m_removeIslands;
long long int m_minIslandArea;
@ -197,7 +208,11 @@ public:
*/
bool GetIsRuleArea() const { return m_isRuleArea; }
RULE_AREA_TYPE GetRuleAreaType() const { return m_ruleAreaType; }
const wxString& GetRuleAreaExpression( ) const { return m_ruleAreaExpression; }
RULE_AREA_PLACEMENT_SOURCE_TYPE GetRuleAreaPlacementSourceType() const
{
return m_ruleAreaPlacementSourceType;
}
wxString GetRuleAreaPlacementSource() const { return m_ruleAreaPlacementSource; }
bool GetDoNotAllowCopperPour() const { return m_keepoutDoNotAllowCopperPour; }
bool GetDoNotAllowVias() const { return m_keepoutDoNotAllowVias; }
bool GetDoNotAllowTracks() const { return m_keepoutDoNotAllowTracks; }
@ -206,7 +221,14 @@ public:
void SetIsRuleArea( bool aEnable ) { m_isRuleArea = aEnable; }
void SetRuleAreaType( RULE_AREA_TYPE aType ) { m_ruleAreaType = aType; }
void SetRuleAreaExpression( const wxString& aExpr ) { m_ruleAreaExpression = aExpr; }
void SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE aType )
{
m_ruleAreaPlacementSourceType = aType;
}
void SetRuleAreaPlacementSource( const wxString& aSource )
{
m_ruleAreaPlacementSource = aSource;
}
void SetDoNotAllowCopperPour( bool aEnable ) { m_keepoutDoNotAllowCopperPour = aEnable; }
void SetDoNotAllowVias( bool aEnable ) { m_keepoutDoNotAllowVias = aEnable; }
void SetDoNotAllowTracks( bool aEnable ) { m_keepoutDoNotAllowTracks = aEnable; }