diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index 041c1e9d84..30e1105ae1 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -26,6 +26,13 @@ const int netSettingsSchemaVersion = 0; +static OPT getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey, OPT aDefault = OPT() ) +{ + if( aObj.contains( aKey ) ) + return PcbMillimeter2iu( aObj[aKey].get() ); + else + return aDefault; +}; NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ), @@ -51,15 +58,6 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : // are used in which units system. nlohmann::json netclassJson = { { "name", netclass->GetName().ToUTF8() }, - { "clearance", PcbIu2Millimeter( netclass->GetClearance() ) }, - { "track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) }, - { "via_diameter", PcbIu2Millimeter( netclass->GetViaDiameter() ) }, - { "via_drill", PcbIu2Millimeter( netclass->GetViaDrill() ) }, - { "microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) }, - { "microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) }, - { "diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) }, - { "diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) }, - { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) }, { "wire_width", SchIu2Mils( netclass->GetWireWidth() ) }, { "bus_width", SchIu2Mils( netclass->GetBusWidth() ) }, { "line_style", netclass->GetLineStyle() }, @@ -67,6 +65,34 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : { "pcb_color", netclass->GetPcbColor() } }; + + if( netclass->HasClearance() ) + netclassJson.push_back( { "clearance", PcbIu2Millimeter( netclass->GetClearance() ) } ); + + if( netclass->HasTrackWidth() ) + netclassJson.push_back( { "track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) } ); + + if( netclass->HasViaDiameter() ) + netclassJson.push_back( { "via_diameter", PcbIu2Millimeter( netclass->GetViaDiameter() ) } ); + + if( netclass->HasViaDrill() ) + netclassJson.push_back( { "via_drill", PcbIu2Millimeter( netclass->GetViaDrill() ) } ); + + if( netclass->HasuViaDiameter() ) + netclassJson.push_back( { "microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) } ); + + if( netclass->HasuViaDrill() ) + netclassJson.push_back( { "microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) } ); + + if( netclass->HasDiffPairWidth() ) + netclassJson.push_back( { "diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } ); + + if( netclass->HasDiffPairGap() ) + netclassJson.push_back( { "diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) } ); + + if( netclass->HasDiffPairViaGap() ) + netclassJson.push_back( { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } ); + if( idx > 0 ) // No need to store members of Default netclass { nlohmann::json membersJson = nlohmann::json::array(); @@ -95,15 +121,6 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : NETCLASSPTR netclass; NETCLASSPTR defaultClass = m_NetClasses.GetDefault(); - auto getInPcbUnits = - []( const nlohmann::json& aObj, const std::string& aKey, int aDefault ) - { - if( aObj.contains( aKey ) ) - return PcbMillimeter2iu( aObj[aKey].get() ); - else - return aDefault; - }; - auto getInSchematicUnits = []( const nlohmann::json& aObj, const std::string& aKey, int aDefault ) { @@ -125,24 +142,30 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : else netclass = std::make_shared( name ); - netclass->SetClearance( getInPcbUnits( entry, "clearance", - netclass->GetClearance() ) ); - netclass->SetTrackWidth( getInPcbUnits( entry, "track_width", - netclass->GetTrackWidth() ) ); - netclass->SetViaDiameter( getInPcbUnits( entry, "via_diameter", - netclass->GetViaDiameter() ) ); - netclass->SetViaDrill( getInPcbUnits( entry, "via_drill", - netclass->GetViaDrill() ) ); - netclass->SetuViaDiameter( getInPcbUnits( entry, "microvia_diameter", - netclass->GetuViaDiameter() ) ); - netclass->SetuViaDrill( getInPcbUnits( entry, "microvia_drill", - netclass->GetuViaDrill() ) ); - netclass->SetDiffPairWidth( getInPcbUnits( entry, "diff_pair_width", - netclass->GetDiffPairWidth() ) ); - netclass->SetDiffPairGap( getInPcbUnits( entry, "diff_pair_gap", - netclass->GetDiffPairGap() ) ); - netclass->SetDiffPairViaGap( getInPcbUnits( entry, "diff_pair_via_gap", - netclass->GetDiffPairViaGap() ) ); + if( auto value = getInPcbUnits( entry, "clearance" ) ) + netclass->SetClearance( *value ); + + if( auto value = getInPcbUnits( entry, "track_width" ) ) + netclass->SetTrackWidth( *value ); + + if( auto value = getInPcbUnits( entry, "via_diameter" ) ) + netclass->SetViaDiameter( *value ); + + if( auto value = getInPcbUnits( entry, "microvia_diameter" ) ) + netclass->SetuViaDiameter( *value ); + + if( auto value = getInPcbUnits( entry, "microvia_drill" ) ) + netclass->SetuViaDrill( *value ); + + if( auto value = getInPcbUnits( entry, "diff_pair_width" ) ) + netclass->SetDiffPairWidth( *value ); + + if( auto value = getInPcbUnits( entry, "diff_pair_gap" ) ) + netclass->SetDiffPairGap( *value ); + + if( auto value = getInPcbUnits( entry, "diff_pair_via_gap" ) ) + netclass->SetDiffPairViaGap( *value ); + netclass->SetWireWidth( getInSchematicUnits( entry, "wire_width", netclass->GetWireWidth() ) ); netclass->SetBusWidth( getInSchematicUnits( entry, "bus_width", diff --git a/include/netclass.h b/include/netclass.h index 9208950671..304ef940bd 100644 --- a/include/netclass.h +++ b/include/netclass.h @@ -29,7 +29,7 @@ #include #include - +#include class LINE_READER; class BOARD; @@ -56,18 +56,18 @@ protected: /// The units on these parameters is Internal Units (1 nm) - int m_Clearance; ///< clearance when routing + OPT m_Clearance; ///< clearance when routing - int m_TrackWidth; ///< track width used to route NETs in this NETCLASS - int m_ViaDia; ///< via diameter - int m_ViaDrill; ///< via drill hole diameter + OPT m_TrackWidth; ///< track width used to route NETs in this NETCLASS + OPT m_ViaDia; ///< via diameter + OPT m_ViaDrill; ///< via drill hole diameter - int m_uViaDia; ///< microvia diameter - int m_uViaDrill; ///< microvia drill hole diameter + OPT m_uViaDia; ///< microvia diameter + OPT m_uViaDrill; ///< microvia drill hole diameter - int m_diffPairWidth; - int m_diffPairGap; - int m_diffPairViaGap; + OPT m_diffPairWidth; + OPT m_diffPairGap; + OPT m_diffPairViaGap; int m_wireWidth; int m_busWidth; @@ -155,38 +155,40 @@ public: const wxString& GetDescription() const { return m_Description; } void SetDescription( const wxString& aDesc ) { m_Description = aDesc; } - int GetClearance( wxString* aSource = nullptr ) const - { - if( aSource ) - *aSource = wxString::Format( _( "'%s' netclass" ), m_Name ); - - return m_Clearance; - } - + bool HasClearance() const { return (bool) m_Clearance; } + int GetClearance() const { return m_Clearance.value_or(-1); } void SetClearance( int aClearance ) { m_Clearance = aClearance; } - int GetTrackWidth() const { return m_TrackWidth; } + bool HasTrackWidth() const { return (bool) m_TrackWidth; } + int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); } void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; } - int GetViaDiameter() const { return m_ViaDia; } + bool HasViaDiameter() const { return (bool) m_ViaDia; } + int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); } void SetViaDiameter( int aDia ) { m_ViaDia = aDia; } - int GetViaDrill() const { return m_ViaDrill; } + int HasViaDrill() const { return (bool) m_ViaDrill; } + int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); } void SetViaDrill( int aSize ) { m_ViaDrill = aSize; } - int GetuViaDiameter() const { return m_uViaDia; } + bool HasuViaDiameter() const { return (bool) m_uViaDia; } + int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); } void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; } - int GetuViaDrill() const { return m_uViaDrill; } + bool HasuViaDrill() const { return (bool) m_uViaDrill; } + int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); } void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; } - int GetDiffPairWidth() const { return m_diffPairWidth; } + bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; } + int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); } void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; } - int GetDiffPairGap() const { return m_diffPairGap; } + bool HasDiffPairGap() const { return (bool) m_diffPairGap; } + int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); } void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; } - int GetDiffPairViaGap() const { return m_diffPairViaGap; } + bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; } + int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); } void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; } COLOR4D GetPcbColor() const { return m_PcbColor; }