diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 1974c73256..700511b636 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -201,6 +201,7 @@ set( COMMON_WIDGET_SRCS widgets/footprint_preview_widget.cpp widgets/footprint_select_widget.cpp widgets/gal_options_panel.cpp + widgets/grid_color_swatch_helpers.cpp widgets/grid_combobox.cpp widgets/grid_icon_text_helpers.cpp widgets/grid_text_button_helpers.cpp diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index a399ce6c2b..ea10b49f70 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -32,11 +32,15 @@ #include #include #include +#include +#include -// Columns of netclasses grid +// PCBNEW columns of netclasses grid enum { GRID_NAME = 0, - GRID_CLEARANCE, + + GRID_FIRST_PCBNEW, + GRID_CLEARANCE = GRID_FIRST_PCBNEW, GRID_TRACKSIZE, GRID_VIASIZE, GRID_VIADRILL, @@ -44,18 +48,44 @@ enum { GRID_uVIADRILL, GRID_DIFF_PAIR_WIDTH, GRID_DIFF_PAIR_GAP, - GRID_DIFF_PAIR_VIA_GAP + + GRID_FIRST_EESCHEMA, + GRID_WIREWIDTH = GRID_FIRST_EESCHEMA, + GRID_BUSWIDTH, + GRID_SCHEMATIC_COLOR, + GRID_LINESTYLE, + + GRID_END }; + +// These are conceptually constexpr +std::vector g_lineStyleIcons; +wxArrayString g_lineStyleNames; + + #define NO_NETCLASS_ASSIGNMENT _( "" ) PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, NETCLASSES* aNetclasses, - const std::vector& aCandidateNetNames ) : + const std::vector& aCandidateNetNames, + bool aIsEEschema ) : PANEL_SETUP_NETCLASSES_BASE( aParent->GetTreebook() ), m_Parent( aParent ), m_netclasses( aNetclasses ), m_candidateNetNames( aCandidateNetNames ) { + if( g_lineStyleIcons.empty() ) + { + g_lineStyleIcons.push_back( stroke_solid_xpm ); + g_lineStyleNames.push_back( _( "Solid" ) ); + g_lineStyleIcons.push_back( stroke_dash_xpm ); + g_lineStyleNames.push_back( _( "Dashed" ) ); + g_lineStyleIcons.push_back( stroke_dot_xpm ); + g_lineStyleNames.push_back( _( "Dotted" ) ); + g_lineStyleIcons.push_back( stroke_dashdot_xpm ); + g_lineStyleNames.push_back( _( "Dash-Dot" ) ); + } + m_netclassesDirty = true; // Figure out the smallest the netclass membership pane can ever be so that nothing is cutoff @@ -80,12 +110,44 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, NETCLASSE // We calculate the column min size only from texts sizes, not using the initial col width // as this initial width is sometimes strange depending on the language (wxGrid bug?) int min_width = m_netclassGrid->GetVisibleWidth( i, true, true, false ); + + if( i == GRID_LINESTYLE ) + min_best_width *= 1.5; + m_netclassGrid->SetColMinimalWidth( i, min_width ); + // We use a "best size" >= min_best_width m_originalColWidths[ i ] = std::max( min_width, min_best_width ); m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] ); } + if( aIsEEschema ) + { + for( int i = GRID_FIRST_PCBNEW; i < GRID_FIRST_EESCHEMA; ++i ) + { + m_netclassGrid->HideCol( i ); + m_originalColWidths[ i ] = 0; + } + + wxGridCellAttr* attr = new wxGridCellAttr; + attr->SetRenderer( new GRID_CELL_COLOR_RENDERER() ); + attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( aParent, m_netclassGrid ) ); + m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr ); + + attr = new wxGridCellAttr; + attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( g_lineStyleIcons, g_lineStyleNames ) ); + attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( g_lineStyleIcons, g_lineStyleNames ) ); + m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr ); + } + else + { + for( int i = GRID_FIRST_EESCHEMA; i < GRID_END; ++i ) + { + m_netclassGrid->HideCol( i ); + m_originalColWidths[ i ] = 0; + } + } + // Be sure the column labels are readable m_netclassGrid->EnsureColLabelsVisible(); @@ -144,7 +206,13 @@ static void netclassToGridRow( EDA_UNITS aUnits, wxGrid* aGrid, int aRow, const SET_MILS_CELL( GRID_uVIADRILL, nc->GetuViaDrill() ); SET_MILS_CELL( GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() ); SET_MILS_CELL( GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() ); - SET_MILS_CELL( GRID_DIFF_PAIR_VIA_GAP, nc->GetDiffPairViaGap() ); + + SET_MILS_CELL( GRID_WIREWIDTH, nc->GetWireWidth() ); + SET_MILS_CELL( GRID_BUSWIDTH, nc->GetBusWidth() ); + + wxString colorAsString = nc->GetSchematicColor().ToWxString( wxC2S_CSS_SYNTAX ); + aGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString ); + aGrid->SetCellValue( aRow, GRID_LINESTYLE, g_lineStyleNames[ nc->GetLineStyle() ] ); } @@ -268,7 +336,12 @@ static void gridRowToNetclass( EDA_UNITS aUnits, wxGrid* grid, int row, const NE nc->SetuViaDrill( MYCELL( GRID_uVIADRILL ) ); nc->SetDiffPairWidth( MYCELL( GRID_DIFF_PAIR_WIDTH ) ); nc->SetDiffPairGap( MYCELL( GRID_DIFF_PAIR_GAP ) ); - // 6.0 TODO: nc->SetDiffPairViaGap( MYCELL( GRID_DIFF_PAIR_VIA_GAP ) ); + + nc->SetWireWidth( MYCELL( GRID_WIREWIDTH ) ); + nc->SetBusWidth( MYCELL( GRID_BUSWIDTH ) ); + + nc->SetSchematicColor( wxColour( grid->GetCellValue( row, GRID_SCHEMATIC_COLOR ) ) ); + nc->SetLineStyle( g_lineStyleNames.Index( grid->GetCellValue( row, GRID_LINESTYLE ) ) ); } @@ -282,7 +355,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow() // Copy the default NetClass: gridRowToNetclass( m_Parent->GetUserUnits(), m_netclassGrid, 0, m_netclasses->GetDefault() ); - // Copy other NetClasses : + // Copy other NetClasses: for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row ) { NETCLASSPTR nc = std::make_shared( m_netclassGrid->GetCellValue( row, GRID_NAME ) ); diff --git a/common/dialogs/panel_setup_netclasses.h b/common/dialogs/panel_setup_netclasses.h index 534b027d19..1de908820c 100644 --- a/common/dialogs/panel_setup_netclasses.h +++ b/common/dialogs/panel_setup_netclasses.h @@ -70,7 +70,7 @@ private: public: PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, NETCLASSES* aNetclasses, - const std::vector& aCandidateNetNames ); + const std::vector& aCandidateNetNames, bool isEEschema ); ~PANEL_SETUP_NETCLASSES( ) override; bool TransferDataToWindow() override; diff --git a/common/dialogs/panel_setup_netclasses_base.cpp b/common/dialogs/panel_setup_netclasses_base.cpp index c4c76870a2..5094529191 100644 --- a/common/dialogs/panel_setup_netclasses_base.cpp +++ b/common/dialogs/panel_setup_netclasses_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jun 3 2020) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -23,27 +23,17 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi wxStaticBoxSizer* sbSizerUpper; sbSizerUpper = new wxStaticBoxSizer( new wxStaticBox( m_netclassesPane, wxID_ANY, _("Net Classes") ), wxVERTICAL ); - sbSizerUpper->SetMinSize( wxSize( -1,220 ) ); + sbSizerUpper->SetMinSize( wxSize( -1,200 ) ); m_netclassGrid = new WX_GRID( m_netclassesPane, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_DEFAULT|wxHSCROLL|wxTAB_TRAVERSAL|wxVSCROLL ); // Grid - m_netclassGrid->CreateGrid( 1, 10 ); + m_netclassGrid->CreateGrid( 1, 13 ); m_netclassGrid->EnableEditing( true ); m_netclassGrid->EnableGridLines( true ); m_netclassGrid->EnableDragGridSize( false ); m_netclassGrid->SetMargins( 0, 0 ); // Columns - m_netclassGrid->SetColSize( 0, 130 ); - m_netclassGrid->SetColSize( 1, 96 ); - m_netclassGrid->SetColSize( 2, 96 ); - m_netclassGrid->SetColSize( 3, 96 ); - m_netclassGrid->SetColSize( 4, 96 ); - m_netclassGrid->SetColSize( 5, 96 ); - m_netclassGrid->SetColSize( 6, 96 ); - m_netclassGrid->SetColSize( 7, 60 ); - m_netclassGrid->SetColSize( 8, 60 ); - m_netclassGrid->SetColSize( 9, 60 ); m_netclassGrid->EnableDragColMove( false ); m_netclassGrid->EnableDragColSize( true ); m_netclassGrid->SetColLabelSize( 24 ); @@ -56,7 +46,10 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi m_netclassGrid->SetColLabelValue( 6, _("uVia Drill") ); m_netclassGrid->SetColLabelValue( 7, _("DP Width") ); m_netclassGrid->SetColLabelValue( 8, _("DP Gap") ); - m_netclassGrid->SetColLabelValue( 9, _("DP Via Gap") ); + m_netclassGrid->SetColLabelValue( 9, _("Wire Thickness") ); + m_netclassGrid->SetColLabelValue( 10, _("Bus Thickness") ); + m_netclassGrid->SetColLabelValue( 11, _("Color") ); + m_netclassGrid->SetColLabelValue( 12, _("Line Style") ); m_netclassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); // Rows @@ -92,7 +85,7 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi m_netclassesPane->SetSizer( sbSizerUpper ); m_netclassesPane->Layout(); sbSizerUpper->Fit( m_netclassesPane ); - bMargins->Add( m_netclassesPane, 1, wxALL|wxEXPAND, 5 ); + bMargins->Add( m_netclassesPane, 4, wxALL|wxEXPAND, 5 ); m_membershipPane = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxStaticBoxSizer* sbMembership; @@ -233,7 +226,7 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi m_membershipPane->SetSizer( sbMembership ); m_membershipPane->Layout(); sbMembership->Fit( m_membershipPane ); - bMargins->Add( m_membershipPane, 1, wxALL|wxEXPAND, 5 ); + bMargins->Add( m_membershipPane, 5, wxALL|wxEXPAND, 5 ); bpanelNetClassesSizer->Add( bMargins, 1, wxEXPAND, 5 ); diff --git a/common/dialogs/panel_setup_netclasses_base.fbp b/common/dialogs/panel_setup_netclasses_base.fbp index 2e50f3370f..65b373603c 100644 --- a/common/dialogs/panel_setup_netclasses_base.fbp +++ b/common/dialogs/panel_setup_netclasses_base.fbp @@ -14,7 +14,6 @@ panel_setup_netclasses_base 1000 none - 1 panel_setup_netclasses_base @@ -26,7 +25,6 @@ 1 1 UI - 0 1 0 @@ -69,7 +67,7 @@ 5 wxALL|wxEXPAND - 1 + 4 1 1 @@ -124,7 +122,7 @@ wxID_ANY Net Classes - -1,220 + -1,200 sbSizerUpper wxVERTICAL 0 @@ -157,10 +155,10 @@ 1 wxALIGN_CENTER 24 - "Name" "Clearance" "Track Width" "Via Size" "Via Drill" "uVia Size" "uVia Drill" "DP Width" "DP Gap" "DP Via Gap" + "Name" "Clearance" "Track Width" "Via Size" "Via Drill" "uVia Size" "uVia Drill" "DP Width" "DP Gap" "Wire Thickness" "Bus Thickness" "Color" "Line Style" wxALIGN_CENTER - 10 - 130,96,96,96,96,96,96,60,60,60 + 13 + 1 0 @@ -240,7 +238,6 @@ - 0 @@ -324,7 +321,6 @@ - 0 @@ -393,7 +389,7 @@ 5 wxALL|wxEXPAND - 1 + 5 1 1 @@ -768,7 +764,6 @@ - 0 @@ -852,7 +847,6 @@ - 0 @@ -1087,7 +1081,6 @@ - 0 @@ -1171,7 +1164,6 @@ - 0 diff --git a/common/dialogs/panel_setup_netclasses_base.h b/common/dialogs/panel_setup_netclasses_base.h index 85c227108a..d0baea8bd7 100644 --- a/common/dialogs/panel_setup_netclasses_base.h +++ b/common/dialogs/panel_setup_netclasses_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jun 3 2020) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! diff --git a/common/netclass.cpp b/common/netclass.cpp index 1630049a9e..344a75acec 100644 --- a/common/netclass.cpp +++ b/common/netclass.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr - * Copyright (C) 2009 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2009-2020 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,29 +24,27 @@ */ #include -#include -#include - #include - -#ifndef PCBNEW -#define PCBNEW // needed to define the right value of Millimeter2iu(x) -#endif #include // This will get mapped to "kicad_default" in the specctra_export. const char NETCLASS::Default[] = "Default"; // Initial values for netclass initialization -const int DEFAULT_CLEARANCE = Millimeter2iu( 0.2 ); // track to track and track to pads clearance -const int DEFAULT_VIA_DIAMETER = Millimeter2iu( 0.8 ); -const int DEFAULT_VIA_DRILL = Millimeter2iu( 0.4 ); -const int DEFAULT_UVIA_DIAMETER = Millimeter2iu( 0.3 ); -const int DEFAULT_UVIA_DRILL = Millimeter2iu( 0.1 ); -const int DEFAULT_TRACK_WIDTH = Millimeter2iu( 0.25 ); -const int DEFAULT_DIFF_PAIR_WIDTH = Millimeter2iu( 0.2 ); -const int DEFAULT_DIFF_PAIR_GAP = Millimeter2iu( 0.25 ); -const int DEFAULT_DIFF_PAIR_VIAGAP = Millimeter2iu( 0.25 ); +const int DEFAULT_CLEARANCE = PcbMillimeter2iu( 0.2 ); // track to track and track to pads clearance +const int DEFAULT_VIA_DIAMETER = PcbMillimeter2iu( 0.8 ); +const int DEFAULT_VIA_DRILL = PcbMillimeter2iu( 0.4 ); +const int DEFAULT_UVIA_DIAMETER = PcbMillimeter2iu( 0.3 ); +const int DEFAULT_UVIA_DRILL = PcbMillimeter2iu( 0.1 ); +const int DEFAULT_TRACK_WIDTH = PcbMillimeter2iu( 0.25 ); +const int DEFAULT_DIFF_PAIR_WIDTH = PcbMillimeter2iu( 0.2 ); +const int DEFAULT_DIFF_PAIR_GAP = PcbMillimeter2iu( 0.25 ); +const int DEFAULT_DIFF_PAIR_VIAGAP = PcbMillimeter2iu( 0.25 ); + +const int DEFAULT_WIRE_WIDTH = SchMils2iu( 6 ); +const int DEFAULT_BUS_WIDTH = SchMils2iu( 12 ); + +const int DEFAULT_LINE_STYLE = 0; // solid NETCLASS::NETCLASS( const wxString& aName ) : @@ -65,21 +63,11 @@ NETCLASS::NETCLASS( const wxString& aName ) : SetDiffPairWidth( DEFAULT_DIFF_PAIR_WIDTH ); SetDiffPairGap( DEFAULT_DIFF_PAIR_GAP ); SetDiffPairViaGap( DEFAULT_DIFF_PAIR_VIAGAP ); -} - -void NETCLASS::SetParams( const NETCLASS& aDefaults ) -{ - SetClearance( aDefaults.GetClearance() ); - SetTrackWidth( aDefaults.GetTrackWidth() ); - SetViaDiameter( aDefaults.GetViaDiameter() ); - SetViaDrill( aDefaults.GetViaDrill() ); - SetuViaDiameter( aDefaults.GetuViaDiameter() ); - SetuViaDrill( aDefaults.GetuViaDrill() ); - SetDiffPairWidth( aDefaults.GetDiffPairWidth() ); - SetDiffPairGap( aDefaults.GetDiffPairGap() ); - SetDiffPairViaGap( aDefaults.GetDiffPairViaGap() ); - SetPcbColor( KIGFX::COLOR4D::UNSPECIFIED ); + SetWireWidth( DEFAULT_WIRE_WIDTH ); + SetBusWidth( DEFAULT_BUS_WIDTH ); + SetSchematicColor( COLOR4D::UNSPECIFIED ); + SetLineStyle( DEFAULT_LINE_STYLE ); } diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index e9effd861a..cd84f0e396 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -20,13 +20,9 @@ #include #include - -// Netclasses were originally only stored in board files. The IU context is PCBNEW. -#ifndef PCBNEW -#define PCBNEW -#endif -#include +#include #include +#include const int netSettingsSchemaVersion = 0; @@ -51,17 +47,19 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : ++nc; } + // Note: we're in common/, but we do happen to know which of these fields + // are used in which units system. nlohmann::json netJson = { - { "name", netclass->GetName().ToUTF8() }, - { "clearance", Iu2Millimeter( netclass->GetClearance() ) }, - { "track_width", Iu2Millimeter( netclass->GetTrackWidth() ) }, - { "via_diameter", Iu2Millimeter( netclass->GetViaDiameter() ) }, - { "via_drill", Iu2Millimeter( netclass->GetViaDrill() ) }, - { "microvia_diameter", Iu2Millimeter( netclass->GetuViaDiameter() ) }, - { "microvia_drill", Iu2Millimeter( netclass->GetuViaDrill() ) }, - { "diff_pair_width", Iu2Millimeter( netclass->GetDiffPairWidth() ) }, - { "diff_pair_gap", Iu2Millimeter( netclass->GetDiffPairGap() ) }, - { "diff_pair_via_gap", Iu2Millimeter( netclass->GetDiffPairViaGap() ) } + { "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() ) } }; if( netclass->GetPcbColor() != KIGFX::COLOR4D::UNSPECIFIED ) @@ -74,7 +72,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : for( const auto& ii : *netclass ) { if( !ii.empty() ) - membersJson.push_back( std::string( ii.ToUTF8() ) ); + membersJson.push_back( ii ); } netJson["nets"] = membersJson; @@ -98,7 +96,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : []( const nlohmann::json& aObj, const std::string& aKey, int aDefault ) { if( aObj.contains( aKey ) ) - return Millimeter2iu( aObj[aKey].get() ); + return PcbMillimeter2iu( aObj[aKey].get() ); else return aDefault; }; diff --git a/common/widgets/grid_color_swatch_helpers.cpp b/common/widgets/grid_color_swatch_helpers.cpp new file mode 100644 index 0000000000..b47d3551de --- /dev/null +++ b/common/widgets/grid_color_swatch_helpers.cpp @@ -0,0 +1,162 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +#include +#include +#include + + +//-------- Custom wxGridCellRenderers -------------------------------------------------- + + +GRID_CELL_COLOR_RENDERER::GRID_CELL_COLOR_RENDERER() +{ +} + + +GRID_CELL_COLOR_RENDERER::~GRID_CELL_COLOR_RENDERER() +{ +} + + +wxGridCellRenderer* GRID_CELL_COLOR_RENDERER::Clone() const +{ + return new GRID_CELL_COLOR_RENDERER; +} + + +wxSize GRID_CELL_COLOR_RENDERER::GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, + int row, int col ) +{ + wxSize bestSize; + + dc.SetFont(attr.GetFont()); + dc.GetTextExtent( "WWW", &bestSize.x, &bestSize.y ); + + return bestSize; +} + + +void GRID_CELL_COLOR_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, + const wxRect& aRect, int aRow, int aCol, bool isSelected ) +{ + wxRect rect = aRect; + + // erase background + wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected ); + + // draw the swatch + wxBitmap bitmap( aRect.GetWidth() + 1, aRect.GetHeight() + 1 ); + wxMemoryDC bmpDC; + wxBrush brush; + wxColour color; + + // Prepare Bitmap + bmpDC.SelectObject( bitmap ); + + color.Set( aGrid.GetTable()->GetValue( aRow, aCol ) ); + brush.SetStyle( wxBRUSHSTYLE_SOLID ); + brush.SetColour( color ); + bmpDC.SetBrush( brush ); + bmpDC.DrawRectangle( -1, -1, bitmap.GetWidth()+1, bitmap.GetHeight()+1 ); + + aDC.DrawBitmap( bitmap, rect.GetTopLeft(), true ); +} + + + +//-------- Custom wxGridCellEditors ---------------------------------------------------- +// +// Note: this implementation is an adaptation of wxGridCellBoolEditor + + +GRID_CELL_COLOR_SELECTOR::GRID_CELL_COLOR_SELECTOR( DIALOG_SHIM* aDialog, wxGrid* aGrid ) : + m_dialog( aDialog ), + m_grid( aGrid ), + m_value( COLOR4D::UNSPECIFIED ) +{ +} + + +wxGridCellEditor* GRID_CELL_COLOR_SELECTOR::Clone() const +{ + return new GRID_CELL_COLOR_SELECTOR( m_dialog, m_grid ); +} + + +void GRID_CELL_COLOR_SELECTOR::Create( wxWindow* aParent, wxWindowID aId, + wxEvtHandler* aEventHandler ) +{ + // wxWidgets needs a control to hold on to the event handler + m_control = new wxCheckBox( aParent, wxID_ANY, wxEmptyString ); + + wxGridCellEditor::Create( aParent, aId, aEventHandler ); +} + + +wxString GRID_CELL_COLOR_SELECTOR::GetValue() const +{ + return m_value.ToWxString( wxC2S_CSS_SYNTAX ); +} + + +void GRID_CELL_COLOR_SELECTOR::BeginEdit( int row, int col, wxGrid* grid ) +{ + m_value.SetFromWxString( grid->GetTable()->GetValue( row, col ) ); + + DIALOG_COLOR_PICKER dialog( m_dialog, m_value, false ); + + if( dialog.ShowModal() == wxID_OK ) + m_value = dialog.GetColor(); + + m_grid->GetTable()->SetValue( row, col, GetValue() ); + + // That's it; we're all done + m_grid->HideCellEditControl(); + m_grid->ForceRefresh(); +} + + +bool GRID_CELL_COLOR_SELECTOR::EndEdit( int row, int col, const wxGrid* grid, + const wxString& oldval, wxString *newval ) +{ + if ( newval ) + *newval = GetValue(); + + return true; +} + + +void GRID_CELL_COLOR_SELECTOR::ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) +{ + aGrid->GetTable()->SetValue( aRow, aCol, GetValue() ); +} + + +void GRID_CELL_COLOR_SELECTOR::Reset() +{ +} + + diff --git a/common/widgets/grid_color_swatch_helpers.h b/common/widgets/grid_color_swatch_helpers.h new file mode 100644 index 0000000000..81c8e0c90a --- /dev/null +++ b/common/widgets/grid_color_swatch_helpers.h @@ -0,0 +1,79 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef GRID_COLOR_SWATCH_HELPERS +#define GRID_COLOR_SWATCH_HELPERS + +#include +#include +#include + + +class wxGrid; +class DIALOG_SHIM; + + +//-------- Custom wxGridCellRenderers -------------------------------------------------- + +class GRID_CELL_COLOR_RENDERER : public wxGridCellRenderer +{ +public: + GRID_CELL_COLOR_RENDERER(); + ~GRID_CELL_COLOR_RENDERER() override; + + wxGridCellRenderer* Clone() const override; + wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override; + + void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow, + int aCol, bool isSelected ) override; +}; + + +//-------- Custom wxGridCellEditors ---------------------------------------------------- +// +// Note: this implementation is an adaptation of wxGridCellChoiceEditor + +class GRID_CELL_COLOR_SELECTOR : public wxGridCellEditor +{ +public: + GRID_CELL_COLOR_SELECTOR( DIALOG_SHIM* aDialog, wxGrid* aGrid ); + + wxGridCellEditor* Clone() const override; + void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override; + + wxString GetValue() const override; + + void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override; + bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override; + void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override; + void Reset() override; + +protected: + DIALOG_SHIM* m_dialog; + wxGrid* m_grid; + KIGFX::COLOR4D m_value; + + wxDECLARE_NO_COPY_CLASS( GRID_CELL_COLOR_SELECTOR ); +}; + +#endif // GRID_COLOR_SWATCH_HELPERS diff --git a/common/widgets/grid_icon_text_helpers.cpp b/common/widgets/grid_icon_text_helpers.cpp index 8a617d48ed..1c934d92a6 100644 --- a/common/widgets/grid_icon_text_helpers.cpp +++ b/common/widgets/grid_icon_text_helpers.cpp @@ -38,8 +38,7 @@ GRID_CELL_ICON_TEXT_RENDERER::GRID_CELL_ICON_TEXT_RENDERER( const std::vector #include #include +#include #include "sch_painter.h" @@ -122,8 +123,35 @@ const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const } +COLOR4D SCH_BUS_ENTRY_BASE::GetStrokeColor() const +{ + NETCLASSPTR netclass = NetClass(); + + if( netclass && netclass->GetSchematicColor() != COLOR4D::UNSPECIFIED ) + return netclass->GetSchematicColor(); + + return m_stroke.GetColor(); +} + + +PLOT_DASH_TYPE SCH_BUS_ENTRY_BASE::GetStrokeStyle() const +{ + NETCLASSPTR netclass = NetClass(); + + if( netclass ) + return (PLOT_DASH_TYPE) netclass->GetLineStyle(); + + return m_stroke.GetType(); +} + + int SCH_BUS_WIRE_ENTRY::GetPenWidth() const { + NETCLASSPTR netclass = NetClass(); + + if( netclass ) + return netclass->GetWireWidth(); + if( m_stroke.GetWidth() == 0 && Schematic() ) return std::max( Schematic()->Settings().m_DefaultWireThickness, 1 ); @@ -133,6 +161,11 @@ int SCH_BUS_WIRE_ENTRY::GetPenWidth() const int SCH_BUS_BUS_ENTRY::GetPenWidth() const { + NETCLASSPTR netclass = NetClass(); + + if( netclass ) + return netclass->GetBusWidth(); + if( m_stroke.GetWidth() == 0 && Schematic() ) return std::max( Schematic()->Settings().m_DefaultBusThickness, 1 ); diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index 00141dfbd8..9942677171 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -78,10 +78,10 @@ public: virtual STROKE_PARAMS GetStroke() const override { return m_stroke; } virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; } - PLOT_DASH_TYPE GetStrokeStyle() const { return m_stroke.GetType(); } + PLOT_DASH_TYPE GetStrokeStyle() const; void SetStrokeStyle( PLOT_DASH_TYPE aStyle ) { m_stroke.SetType( aStyle ); } - COLOR4D GetStrokeColor() const { return m_stroke.GetColor(); } + COLOR4D GetStrokeColor() const; void SetStrokeColor( const COLOR4D& aColor ) { m_stroke.SetColor( aColor ); } void SwapData( SCH_ITEM* aItem ) override; diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index 25e612cb4b..03e84dd38d 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include /* Constructor and destructor for SCH_ITEM */ @@ -154,6 +157,22 @@ SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH& aSheet ) const } +NETCLASSPTR SCH_ITEM::NetClass() const +{ + if( m_connection_map.size() ) + { + NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings(); + const wxString& netname = m_connection_map.begin()->second->Name( true ); + const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ]; + + if( !netclassName.IsEmpty() ) + return netSettings.m_NetClasses.Find( netclassName ); + } + + return nullptr; +} + + ITEM_SET& SCH_ITEM::ConnectedItems( const SCH_SHEET_PATH& aSheet ) { return m_connected_items[ aSheet ]; diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 7eb1a44eb0..6f3d16f1d8 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -37,6 +37,7 @@ #include #include #include +#include class CONNECTION_GRAPH; class SCH_CONNECTION; @@ -426,6 +427,8 @@ public: void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; } + NETCLASSPTR NetClass() const; + /** * Return whether the fields have been automatically placed. */ diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index bc9bafd87a..2ab1ba89f0 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -23,13 +23,8 @@ */ #include -//#include -//#include -//#include #include #include -//#include -//#include #include #include #include @@ -51,17 +46,9 @@ SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : switch( layer ) { - default: - m_Layer = LAYER_NOTES; - break; - - case LAYER_WIRE: - m_Layer = LAYER_WIRE; - break; - - case LAYER_BUS: - m_Layer = LAYER_BUS; - break; + default: m_Layer = LAYER_NOTES; break; + case LAYER_WIRE: m_Layer = LAYER_WIRE; break; + case LAYER_BUS: m_Layer = LAYER_BUS; break; } } @@ -221,6 +208,11 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con COLOR4D SCH_LINE::GetLineColor() const { + NETCLASSPTR netclass = NetClass(); + + if( netclass && netclass->GetSchematicColor() != COLOR4D::UNSPECIFIED ) + return netclass->GetSchematicColor(); + return m_stroke.GetColor(); } @@ -258,6 +250,17 @@ PLOT_DASH_TYPE SCH_LINE::GetLineStyle() const } +PLOT_DASH_TYPE SCH_LINE::GetEffectiveLineStyle() const +{ + NETCLASSPTR netclass = NetClass(); + + if( netclass ) + return (PLOT_DASH_TYPE) netclass->GetLineStyle(); + + return GetLineStyle(); +} + + void SCH_LINE::SetLineWidth( const int aSize ) { m_stroke.SetWidth( aSize ); @@ -266,6 +269,11 @@ void SCH_LINE::SetLineWidth( const int aSize ) int SCH_LINE::GetPenWidth() const { + NETCLASSPTR netclass = NetClass(); + + if( netclass ) + return ( m_Layer == LAYER_BUS ) ? netclass->GetBusWidth() : netclass->GetWireWidth(); + if( m_stroke.GetWidth() == 0 && Schematic() ) return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 ); @@ -285,7 +293,7 @@ void SCH_LINE::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset ) color = aSettings->GetLayerColor( m_Layer ); GRLine( nullptr, DC, start.x, start.y, end.x, end.y, penWidth, color, - GetwxPenStyle( GetLineStyle() ) ); + GetwxPenStyle( GetEffectiveLineStyle() ) ); } @@ -740,7 +748,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter ) penWidth = m_stroke.GetWidth(); aPlotter->SetCurrentLineWidth( penWidth ); - aPlotter->SetDash( GetLineStyle() ); + aPlotter->SetDash( GetEffectiveLineStyle() ); aPlotter->MoveTo( m_start ); aPlotter->FinishTo( m_end ); @@ -768,7 +776,12 @@ void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) } aList.push_back( MSG_PANEL_ITEM( _( "Line Type" ), msg, DARKCYAN ) ); - msg = GetLineStyleName( GetLineStyle() ); + + if( GetLineStyle() != GetEffectiveLineStyle() ) + msg = _( "from netclass" ); + else + msg = GetLineStyleName( GetLineStyle() ); + aList.push_back( MSG_PANEL_ITEM( _( "Line Style" ), msg, DARKCYAN ) ); SCH_EDIT_FRAME* frame = dynamic_cast( aFrame ); diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 4a561da7cc..0c27ba1b58 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -103,12 +103,16 @@ public: void SetLineStyle( const int aStyleId ); PLOT_DASH_TYPE GetLineStyle() const; + /// @return the style that the line should be drawn in + /// this might be set on the line or inherited from the line's netclass + PLOT_DASH_TYPE GetEffectiveLineStyle() const; + /// @return the style name from the style id - /// (mainly to write it in .sch file + /// (mainly to write it in .sch file) static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle ); /// @return the style id from the style name - /// (mainly to read style from .sch file + /// (mainly to read style from .sch file) static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName ); void SetLineColor( const COLOR4D& aColor ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index d725aef0c0..7fecd2d1b7 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -329,27 +329,7 @@ float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) { wxCHECK( aItem, static_cast( m_schSettings.m_DefaultWireThickness ) ); - float width; - const SCH_LINE* line = dynamic_cast( aItem ); - - if( line && aItem->GetLayer() == LAYER_WIRE ) - { - if( line->GetLineSize() != 0 ) - width = (float) line->GetLineSize(); - else - width = (float) m_schSettings.m_DefaultWireThickness; - } - else if( line && aItem->GetLayer() == LAYER_BUS ) - { - if( line->GetLineSize() != 0 ) - width = (float) line->GetLineSize(); - else - width = (float) m_schSettings.m_DefaultBusThickness; - } - else - { - width = (float) std::max( aItem->GetPenWidth(), m_schSettings.GetDefaultPenWidth() ); - } + float width = (float) std::max( aItem->GetPenWidth(), m_schSettings.GetDefaultPenWidth() ); if( aItem->IsSelected() && aDrawingShadows ) width += getShadowWidth(); @@ -1224,14 +1204,15 @@ void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer ) if( drawingShadows && !aLine->IsSelected() ) return; - COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows ); - float width = getLineWidth( aLine, drawingShadows ); + COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows ); + float width = getLineWidth( aLine, drawingShadows ); + PLOT_DASH_TYPE lineStyle = aLine->GetEffectiveLineStyle(); m_gal->SetIsStroke( true ); m_gal->SetStrokeColor( color ); m_gal->SetLineWidth( width ); - if( aLine->GetLineStyle() <= PLOT_DASH_TYPE::FIRST_TYPE || drawingShadows ) + if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE || drawingShadows ) { m_gal->DrawLine( aLine->GetStartPoint(), aLine->GetEndPoint() ); } @@ -1246,7 +1227,7 @@ void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer ) double theta = atan2( end.y - start.y, end.x - start.x ); double strokes[] = { 1.0, DASH_GAP_LEN( width ), 1.0, DASH_GAP_LEN( width ) }; - switch( aLine->GetLineStyle() ) + switch( lineStyle ) { default: case PLOT_DASH_TYPE::DASH: @@ -1733,20 +1714,20 @@ void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer ) if( aEntry->IsSelected() ) line.SetSelected(); + else if( aEntry->IsBrightened() ) + line.SetBrightened(); line.SetStartPoint( aEntry->GetPosition() ); line.SetEndPoint( aEntry->m_End() ); line.SetStroke( aEntry->GetStroke() ); - if( aEntry->GetStrokeColor() == COLOR4D::UNSPECIFIED ) - { - COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows ); + COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows ); - if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T ) - color = getRenderColor( aEntry, LAYER_BUS, drawingShadows ); + if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T ) + color = getRenderColor( aEntry, LAYER_BUS, drawingShadows ); - line.SetLineColor( color ); - } + line.SetLineColor( color ); + line.SetLineStyle( aEntry->GetStrokeStyle() ); draw( &line, aLayer ); diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 58337e3ae9..6cf1a2a932 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -326,12 +326,12 @@ void NGSPICE::init_dll() const vector dllPaths = { "", "/mingw64/bin", "/mingw32/bin" }; #elif defined(__WXMAC__) const vector dllPaths = { - GetOSXKicadUserDataDir() + "/PlugIns/ngspice", - GetOSXKicadMachineDataDir() + "/PlugIns/ngspice", + GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice", + GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice", // when running kicad.app - stdPaths.GetPluginsDir() + "/sim", + stdPaths.GetPluginsDir().ToStdString() + "/sim", // when running eeschema.app - wxFileName( stdPaths.GetExecutablePath() ).GetPath() + "/../../../../../Contents/PlugIns/sim" + wxFileName( stdPaths.GetExecutablePath() ).GetPath().ToStdString() + "/../../../../../Contents/PlugIns/sim" }; #else // Unix systems const vector dllPaths = { "/usr/local/lib" }; @@ -411,8 +411,8 @@ void NGSPICE::init_dll() { ".", #ifdef __WXMAC__ - stdPaths.GetPluginsDir() + "/sim/ngspice/scripts", - wxFileName( stdPaths.GetExecutablePath() ).GetPath() + "/../../../../../Contents/PlugIns/sim/ngspice/scripts" + stdPaths.GetPluginsDir().ToStdString() + "/sim/ngspice/scripts", + wxFileName( stdPaths.GetExecutablePath() ).GetPath().ToStdString() + "/../../../../../Contents/PlugIns/sim/ngspice/scripts" #endif /* __WXMAC__ */ "../share/kicad", "../share", @@ -476,8 +476,8 @@ string NGSPICE::findCmPath() const #ifdef __WXMAC__ "/Applications/ngspice/lib/ngspice", "Contents/Frameworks", - wxStandardPaths::Get().GetPluginsDir() + "/sim/ngspice", - wxFileName( wxStandardPaths::Get().GetExecutablePath() ).GetPath() + "/../../../../../Contents/PlugIns/sim/ngspice", + wxStandardPaths::Get().GetPluginsDir().ToStdString() + "/sim/ngspice", + wxFileName( wxStandardPaths::Get().GetExecutablePath() ).GetPath().ToStdString() + "/../../../../../Contents/PlugIns/sim/ngspice", "../Plugins/sim/ngspice", #endif /* __WXMAC__ */ "../lib/ngspice", diff --git a/include/board_design_settings.h b/include/board_design_settings.h index 510207c01f..6a75c7260c 100644 --- a/include/board_design_settings.h +++ b/include/board_design_settings.h @@ -338,10 +338,6 @@ private: /// The defualt settings that will be used for new zones ZONE_SETTINGS m_defaultZoneSettings; - SEVERITY severityFromString( const wxString& aSeverity ); - - wxString severityToString( const SEVERITY& aSeverity ); - void initFromOther( const BOARD_DESIGN_SETTINGS& aOther ); public: diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index 3627bc619d..1b72fbe67e 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -31,50 +31,34 @@ * depending on compile time option */ +constexpr double GERB_IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers. +constexpr double PCB_IU_PER_MM = 1e6; // Pcbnew IU is 1 nanometer. +constexpr double PL_IU_PER_MM = 1e3; // internal units in micron (should be enough) +constexpr double SCH_IU_PER_MM = 1e4; // Schematic internal units 1=100nm + /// Scaling factor to convert mils to internal units. -#if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW) - #if defined(GERBVIEW) - constexpr double IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers. - #else - constexpr double IU_PER_MM = 1e6; // Pcbnew IU is 1 nanometer. - #endif +#if defined(PCBNEW) || defined(CVPCB) +constexpr double IU_PER_MM = PCB_IU_PER_MM; +#elif defined(GERBVIEW) +constexpr double IU_PER_MM = GERB_IU_PER_MM; +#elif defined(PL_EDITOR) +constexpr double IU_PER_MM = PL_IU_PER_MM; +#elif defined(EESCHEMA) +constexpr double IU_PER_MM = SCH_IU_PER_MM; +#else +#define UNKNOWN_IU +#endif -constexpr double IU_PER_MILS = IU_PER_MM * 0.0254; - -/// Convert mils to PCBNEW internal units (iu). -inline int Mils2iu( int mils ) -{ - double x = mils * IU_PER_MILS; - return int( x < 0 ? x - 0.5 : x + 0.5 ); -} - -constexpr inline double Iu2Mils( int iu ) -{ - double mils = iu / IU_PER_MILS; - - return static_cast< int >( mils < 0 ? mils - 0.5 : mils + 0.5 ); -} -#elif defined (PL_EDITOR) -constexpr double IU_PER_MM = 1e3; // internal units in micron (should be enough) +#ifndef UNKNOWN_IU constexpr double IU_PER_MILS = (IU_PER_MM * 0.0254); -/// Convert mils to page layout editor internal units (iu). -inline int Mils2iu( int mils ) -{ - double x = mils * IU_PER_MILS; - return int( x < 0 ? x - 0.5 : x + 0.5 ); -} - -#elif defined (EESCHEMA) // Eeschema -constexpr double IU_PER_MM = 1e4; // Schematic internal units 1=100nm -constexpr double IU_PER_MILS = IU_PER_MM * 0.0254; - constexpr inline int Mils2iu( int mils ) { double x = mils * IU_PER_MILS; return int( x < 0 ? x - 0.5 : x + 0.5 ); } +#if defined(EESCHEMA) constexpr inline int Iu2Mils( int iu ) { double mils = iu / IU_PER_MILS; @@ -82,12 +66,14 @@ constexpr inline int Iu2Mils( int iu ) return static_cast< int >( mils < 0 ? mils - 0.5 : mils + 0.5 ); } #else -// Here, we do not know the value of internal units: do not define -// conversion functions (They do not have meaning) -#define UNKNOWN_IU +constexpr inline double Iu2Mils( int iu ) +{ + double mils = iu / IU_PER_MILS; + + return static_cast< int >( mils < 0 ? mils - 0.5 : mils + 0.5 ); +} #endif -#ifndef UNKNOWN_IU // Other definitions used in a few files constexpr double MM_PER_IU = ( 1 / IU_PER_MM ); @@ -117,6 +103,38 @@ constexpr inline double Iu2Millimeter( int iu ) constexpr int ARC_LOW_DEF = Millimeter2iu( 0.02 ); constexpr int ARC_HIGH_DEF = Millimeter2iu( 0.005 ); +#else +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 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 diff --git a/include/netclass.h b/include/netclass.h index 7b57b42251..e56364acfb 100644 --- a/include/netclass.h +++ b/include/netclass.h @@ -1,13 +1,9 @@ -/** - * @file class_netclass.h - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr - * Copyright (C) 2009 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2009-2020 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,21 +23,18 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - #ifndef CLASS_NETCLASS_H #define CLASS_NETCLASS_H #include -#include -#include -#include #include class LINE_READER; class BOARD; class BOARD_DESIGN_SETTINGS; +using KIGFX::COLOR4D; DECL_SET_FOR_SWIG( STRINGSET, wxString ) @@ -76,10 +69,14 @@ protected: int m_diffPairGap; int m_diffPairViaGap; - KIGFX::COLOR4D m_PcbColor; ///< Optional color override for this netclass (PCB context) + int m_wireWidth; + int m_busWidth; + COLOR4D m_schematicColor; + int m_lineStyle; + + COLOR4D m_PcbColor; ///< Optional color override for this netclass (PCB context) public: - static const char Default[]; ///< the name of the default NETCLASS /** @@ -96,11 +93,7 @@ public: return wxT( "NETCLASS" ); } - const wxString& GetName() const - { - return m_Name; - } - + const wxString& GetName() const { return m_Name; } void SetName( const wxString& aName ) { m_Name = aName; } /** @@ -196,17 +189,20 @@ public: int GetDiffPairViaGap() const { return m_diffPairViaGap; } void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; } - KIGFX::COLOR4D GetPcbColor() const { return m_PcbColor; } - void SetPcbColor( const KIGFX::COLOR4D& aColor ) { m_PcbColor = aColor; } + COLOR4D GetPcbColor() const { return m_PcbColor; } + void SetPcbColor( const COLOR4D& aColor ) { m_PcbColor = aColor; } - /** - * Function SetParams - * will set all the parameters by copying them from \a defaults. - * Parameters are the values like m_ViaSize, etc, but do not include m_Description. - * @param aDefaults is another NETCLASS object to copy from. - */ - void SetParams( const NETCLASS& aDefaults ); + int GetWireWidth() const { return m_wireWidth; } + void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; } + int GetBusWidth() const { return m_busWidth; } + void SetBusWidth( int aWidth ) { m_busWidth = aWidth; } + + COLOR4D GetSchematicColor() const { return m_schematicColor; } + void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; } + + int GetLineStyle() const { return m_lineStyle; } + void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; } #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const; @@ -220,18 +216,13 @@ DECL_MAP_FOR_SWIG( NETCLASS_MAP, wxString, NETCLASSPTR ) /** * NETCLASSES - * is a container for NETCLASS instances. It owns all its NETCLASSes - * (=> it will delete them at time of destruction). This container will always have - * a default NETCLASS with the name given by const NETCLASS::Default. + * is a container for NETCLASS instances. It owns all its NETCLASSes. This container will + * always have a default NETCLASS with the name given by const NETCLASS::Default. */ class NETCLASSES { private: - - /// all the NETCLASSes except the default one. - NETCLASS_MAP m_NetClasses; - - /// the default NETCLASS + NETCLASS_MAP m_NetClasses; // All the netclasses EXCEPT the default one NETCLASSPTR m_default; public: diff --git a/include/widgets/grid_icon_text_helpers.h b/include/widgets/grid_icon_text_helpers.h index 60ea612d32..c3e8fa171d 100644 --- a/include/widgets/grid_icon_text_helpers.h +++ b/include/widgets/grid_icon_text_helpers.h @@ -43,6 +43,7 @@ public: void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow, int aCol, bool isSelected ) override; + wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row, int col ) override; private: const std::vector& m_icons; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 3e40f38cfd..6a7e59d5d7 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -59,7 +59,7 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : bds.m_DRCSeverities ); m_netclasses = new PANEL_SETUP_NETCLASSES( this, &bds.GetNetClasses(), - board->GetNetClassAssignmentCandidates() ); + board->GetNetClassAssignmentCandidates(), false ); m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() ); diff --git a/pcbnew/pcbnew.h b/pcbnew/pcbnew.h index 1599a531fa..d336257460 100644 --- a/pcbnew/pcbnew.h +++ b/pcbnew/pcbnew.h @@ -22,17 +22,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcbnew.h - */ - #ifndef PCBNEW_H #define PCBNEW_H #include // wxWidgets include. -#include // IS_DRAGGED and IN_EDIT definitions. #include // to define Mils2iu() conversion function -#include // These are only here for algorithmic safety, not to tell the user what to do #define TEXTS_MIN_SIZE Mils2iu( 1 ) ///< Minimum text size in internal units (1 mil) @@ -40,13 +34,6 @@ #define TEXTS_MAX_WIDTH Mils2iu( 10000 ) ///< Maximum text width in internal units (10 inches) -// Flag to force the SKETCH mode to display items (.m_Flags member) -#define FORCE_SKETCH ( IS_DRAGGED | IN_EDIT ) - - -/// List of segments of the trace currently being drawn. -class TRACK; - /** * Helper function PythonPluginsReloadBase * Reload Python plugins if they are newer than