From b74e125264f6a4cd4ee1bc30b9f9f356ce439134 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 27 Jul 2020 22:14:44 +0100 Subject: [PATCH] Read/write schematic netclass properties. Fixes https://gitlab.com/kicad/code/kicad/issues/4990 --- common/project/net_settings.cpp | 71 ++++++++++++++------- eeschema/dialogs/panel_setup_formatting.cpp | 2 - include/convert_to_biu.h | 19 ++---- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index 045b0ae6cc..8ac7f2c78c 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -49,7 +49,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : // Note: we're in common/, but we do happen to know which of these fields // are used in which units system. - nlohmann::json netJson = { + nlohmann::json netclassJson = { { "name", netclass->GetName().ToUTF8() }, { "clearance", PcbIu2Millimeter( netclass->GetClearance() ) }, { "track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) }, @@ -59,11 +59,17 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : { "microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) }, { "diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) }, { "diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) }, - { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } + { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) }, + { "wire_width", SchIu2Mils( netclass->GetWireWidth() ) }, + { "bus_width", SchIu2Mils( netclass->GetBusWidth() ) }, + { "line_style", netclass->GetLineStyle() } }; if( netclass->GetPcbColor() != KIGFX::COLOR4D::UNSPECIFIED ) - netJson["pcb_color"] = netclass->GetPcbColor(); + netclassJson["pcb_color"] = netclass->GetPcbColor(); + + if( netclass->GetSchematicColor() != KIGFX::COLOR4D::UNSPECIFIED ) + netclassJson["schematic_color"] = netclass->GetSchematicColor(); if( idx > 0 ) { @@ -75,10 +81,10 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : membersJson.push_back( ii ); } - netJson["nets"] = membersJson; + netclassJson["nets"] = membersJson; } - ret.push_back( netJson ); + ret.push_back( netclassJson ); } return ret; @@ -93,7 +99,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : NETCLASSPTR netclass; NETCLASSPTR defaultClass = m_NetClasses.GetDefault(); - auto get = + auto getInPcbUnits = []( const nlohmann::json& aObj, const std::string& aKey, int aDefault ) { if( aObj.contains( aKey ) ) @@ -102,6 +108,15 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : return aDefault; }; + auto getInSchematicUnits = + []( const nlohmann::json& aObj, const std::string& aKey, int aDefault ) + { + if( aObj.contains( aKey ) ) + return SchMils2iu( aObj[aKey].get() ); + else + return aDefault; + }; + for( const nlohmann::json& entry : aJson ) { if( !entry.is_object() || !entry.contains( "name" ) ) @@ -114,22 +129,31 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : else netclass = std::make_shared( name ); - netclass->SetClearance( get( entry, "clearance", netclass->GetClearance() ) ); - netclass->SetTrackWidth( - get( entry, "track_width", netclass->GetTrackWidth() ) ); - netclass->SetViaDiameter( - get( entry, "via_diameter", netclass->GetViaDiameter() ) ); - netclass->SetViaDrill( get( entry, "via_drill", netclass->GetViaDrill() ) ); - netclass->SetuViaDiameter( - get( entry, "microvia_diameter", netclass->GetuViaDiameter() ) ); - netclass->SetuViaDrill( - get( entry, "microvia_drill", netclass->GetuViaDrill() ) ); - netclass->SetDiffPairWidth( - get( entry, "diff_pair_width", netclass->GetDiffPairWidth() ) ); - netclass->SetDiffPairGap( - get( entry, "diff_pair_gap", netclass->GetDiffPairGap() ) ); - netclass->SetDiffPairViaGap( - get( entry, "diff_pair_via_gap", netclass->GetDiffPairViaGap() ) ); + 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() ) ); + netclass->SetWireWidth( getInSchematicUnits( entry, "wire_width", + netclass->GetWireWidth() ) ); + netclass->SetBusWidth( getInSchematicUnits( entry, "bus_width", + netclass->GetWireWidth() ) ); + + if( entry.contains( "line_style" ) && entry["line_style"].is_number() ) + netclass->SetLineStyle( entry["line_style"].get() ); if( entry.contains( "nets" ) && entry["nets"].is_array() ) { @@ -140,6 +164,9 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() ) netclass->SetPcbColor( entry["pcb_color"].get() ); + if( entry.contains( "schematic_color" ) && entry["schematic_color"].is_string() ) + netclass->SetSchematicColor( entry["schematic_color"].get() ); + if( netclass != defaultClass ) m_NetClasses.Add( netclass ); diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index e48391de9c..70119e96b0 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -116,8 +116,6 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue(); settings.m_JunctionSize = (int) m_junctionSize.GetValue(); - m_frame->SaveProjectSettings(); - double dtmp = 0.0; wxString msg = m_textOffsetRatioCtrl->GetValue(); msg.ToDouble( &dtmp ); diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index 1b72fbe67e..63c7941505 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -107,34 +107,25 @@ constexpr int ARC_HIGH_DEF = Millimeter2iu( 0.005 ); constexpr double PCB_IU_PER_MILS = (PCB_IU_PER_MM * 0.0254); constexpr double SCH_IU_PER_MILS = (SCH_IU_PER_MM * 0.0254); -constexpr inline int PcbMils2iu( int mils ) -{ - double x = mils * PCB_IU_PER_MILS; - return int( x < 0 ? x - 0.5 : x + 0.5 ); -} constexpr inline int SchMils2iu( int mils ) { double x = mils * SCH_IU_PER_MILS; return int( x < 0 ? x - 0.5 : x + 0.5 ); } +constexpr inline double SchIu2Mils( int iu ) +{ + return iu / SCH_IU_PER_MILS; +} constexpr inline int PcbMillimeter2iu( double mm ) { return (int) ( mm < 0 ? mm * PCB_IU_PER_MM - 0.5 : mm * PCB_IU_PER_MM + 0.5 ); } -constexpr inline int SchMillimeter2iu( double mm ) -{ - return (int) ( mm < 0 ? mm * SCH_IU_PER_MM - 0.5 : mm * SCH_IU_PER_MM + 0.5 ); -} - constexpr inline double PcbIu2Millimeter( int iu ) { return iu / PCB_IU_PER_MM; } -constexpr inline double SchIu2Millimeter( int iu ) -{ - return iu / SCH_IU_PER_MM; -} + #endif /* ZOOM LIMITS