From 6ef20e34fcf48fbac0985728ec28d6b4cff3bd30 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 18 Aug 2020 18:01:19 +0100 Subject: [PATCH] Better support for mixed styles in Junction Properties dialog. Also move to COLOR_SWATCH to reduce code duplication. --- eeschema/dialogs/dialog_edit_line_style.cpp | 2 + eeschema/dialogs/dialog_junction_props.cpp | 113 +++--------------- eeschema/dialogs/dialog_junction_props.h | 9 +- .../dialogs/dialog_junction_props_base.cpp | 28 +++-- .../dialogs/dialog_junction_props_base.fbp | 103 +++++++++++----- eeschema/dialogs/dialog_junction_props_base.h | 15 ++- eeschema/sch_junction.cpp | 7 +- 7 files changed, 130 insertions(+), 147 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp index 76ead57caf..7a5a880aa9 100644 --- a/eeschema/dialogs/dialog_edit_line_style.cpp +++ b/eeschema/dialogs/dialog_edit_line_style.cpp @@ -62,6 +62,8 @@ DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( SCH_EDIT_FRAME* aParent, { m_sdbSizerApply->SetLabel( _( "Default" ) ); + m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED ); + SetInitialFocus( m_lineWidth ); for( auto& typeEntry : lineTypeNames ) diff --git a/eeschema/dialogs/dialog_junction_props.cpp b/eeschema/dialogs/dialog_junction_props.cpp index 5c86175d95..d677e147ac 100644 --- a/eeschema/dialogs/dialog_junction_props.cpp +++ b/eeschema/dialogs/dialog_junction_props.cpp @@ -21,28 +21,14 @@ #include #include #include -#include #include #include #include - -const int BUTT_COLOR_MINSIZE_X = 32; -const int BUTT_COLOR_MINSIZE_Y = 20; - - -static COLOR4D GetIndeterminateColor() -{ - COLOR4D indeterminateColor; - - indeterminateColor.r = indeterminateColor.b = indeterminateColor.g = - indeterminateColor.a = -1.0; - - return indeterminateColor; -} +#include DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent, - std::deque& aJunctions ) : + std::deque& aJunctions ) : DIALOG_JUNCTION_PROPS_BASE( aParent ), m_frame( aParent ), m_junctions( aJunctions ), @@ -51,6 +37,8 @@ DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent, { m_sdbSizerApply->SetLabel( _( "Default" ) ); + m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED ); + SetInitialFocus( m_textCtrlDiameter ); m_sdbSizerOK->SetDefault(); @@ -65,10 +53,10 @@ bool DIALOG_JUNCTION_PROPS::TransferDataToWindow() auto firstJunction = m_junctions.front(); if( std::all_of( m_junctions.begin() + 1, m_junctions.end(), - [&]( const SCH_JUNCTION* r ) - { - return r->GetDiameter() == firstJunction->GetDiameter(); - } ) ) + [&]( const SCH_JUNCTION* r ) + { + return r->GetDiameter() == firstJunction->GetDiameter(); + } ) ) { m_diameter.SetValue( firstJunction->GetDiameter() ); } @@ -78,95 +66,31 @@ bool DIALOG_JUNCTION_PROPS::TransferDataToWindow() } if( std::all_of( m_junctions.begin() + 1, m_junctions.end(), - [&]( const SCH_JUNCTION* r ) - { - return r->GetColor() == firstJunction->GetColor(); - } ) ) + [&]( const SCH_JUNCTION* r ) + { + return r->GetColor() == firstJunction->GetColor(); + } ) ) { - setColor( firstJunction->GetColor() ); + m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false ); } else { - setColor( GetIndeterminateColor() ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); } return true; } -void DIALOG_JUNCTION_PROPS::onColorButtonClicked( wxCommandEvent& event ) -{ - COLOR4D newColor = COLOR4D::UNSPECIFIED; - DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false ); - - if( dialog.ShowModal() == wxID_OK ) - newColor = dialog.GetColor(); - - if( m_selectedColor == newColor ) - return; - - setColor( newColor ); -} - - -void DIALOG_JUNCTION_PROPS::updateColorButton( COLOR4D& aColor ) -{ - wxMemoryDC iconDC; - - if( aColor == COLOR4D::UNSPECIFIED || aColor == GetIndeterminateColor() ) - { - m_buttonColor->SetBitmap( KiBitmap( question_mark_xpm ) ); - } - else - { - wxBitmap bitmap( std::max( m_buttonColor->GetSize().x, BUTT_COLOR_MINSIZE_X ), - std::max( m_buttonColor->GetSize().y, BUTT_COLOR_MINSIZE_Y ) ); - - iconDC.SelectObject( bitmap ); - iconDC.SetPen( *wxBLACK_PEN ); - - wxBrush brush( aColor.ToColour() ); - iconDC.SetBrush( brush ); - - // Paint the full bitmap in aColor: - iconDC.SetBackground( brush ); - iconDC.Clear(); - - m_buttonColor->SetBitmap( bitmap ); - } - - m_buttonColor->Refresh(); - - Refresh( false ); -} - - void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event ) { m_diameter.SetValue( 0 ); - setColor( COLOR4D::UNSPECIFIED ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); Refresh(); } -void DIALOG_JUNCTION_PROPS::setColor( const COLOR4D& aColor ) -{ - m_selectedColor = aColor; - - if( aColor == COLOR4D::UNSPECIFIED ) - { - COLOR4D defaultColor = Pgm().GetSettingsManager().GetColorSettings()->GetColor( - m_junctions.front()->GetLayer() ); - updateColorButton( defaultColor ); - } - else - { - updateColorButton( m_selectedColor ); - } -} - - bool DIALOG_JUNCTION_PROPS::TransferDataFromWindow() { PICKED_ITEMS_LIST pickedItems; @@ -176,13 +100,14 @@ bool DIALOG_JUNCTION_PROPS::TransferDataFromWindow() m_frame->SaveCopyInUndoList( pickedItems, UR_CHANGED, false ); - for( auto& junction : m_junctions ) + for( SCH_JUNCTION* junction : m_junctions ) { if( !m_diameter.IsIndeterminate() ) junction->SetDiameter( m_diameter.GetValue() ); - if( m_selectedColor != GetIndeterminateColor() ) - junction->SetColor( m_selectedColor ); + junction->SetColor( m_colorSwatch->GetSwatchColor() ); + + m_frame->GetCanvas()->GetView()->Update( junction ); } m_frame->GetCanvas()->Refresh(); diff --git a/eeschema/dialogs/dialog_junction_props.h b/eeschema/dialogs/dialog_junction_props.h index 127e9ca4f0..7e660fc355 100644 --- a/eeschema/dialogs/dialog_junction_props.h +++ b/eeschema/dialogs/dialog_junction_props.h @@ -39,17 +39,12 @@ public: bool TransferDataFromWindow() override; private: - SCH_EDIT_FRAME* m_frame; + SCH_EDIT_FRAME* m_frame; std::deque m_junctions; - UNIT_BINDER m_diameter; - COLOR4D m_selectedColor; + UNIT_BINDER m_diameter; void resetDefaults( wxCommandEvent& event ) override; - void onColorButtonClicked( wxCommandEvent& aEvent ) override; - - void setColor( const COLOR4D& aColor ); - void updateColorButton( COLOR4D& aColor ); }; #endif // __dialog_junction_props__ diff --git a/eeschema/dialogs/dialog_junction_props_base.cpp b/eeschema/dialogs/dialog_junction_props_base.cpp index 90efb61fcb..ac6bb3d0b2 100644 --- a/eeschema/dialogs/dialog_junction_props_base.cpp +++ b/eeschema/dialogs/dialog_junction_props_base.cpp @@ -1,10 +1,12 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "widgets/color_swatch.h" + #include "dialog_junction_props_base.h" /////////////////////////////////////////////////////////////////////////// @@ -24,10 +26,10 @@ DIALOG_JUNCTION_PROPS_BASE::DIALOG_JUNCTION_PROPS_BASE( wxWindow* parent, wxWind m_staticTextDiameter = new wxStaticText( this, wxID_ANY, _("Diameter:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextDiameter->Wrap( -1 ); - fgSizer2->Add( m_staticTextDiameter, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer2->Add( m_staticTextDiameter, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); m_textCtrlDiameter = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer2->Add( m_textCtrlDiameter, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxLEFT, 5 ); + fgSizer2->Add( m_textCtrlDiameter, 0, wxEXPAND, 5 ); m_staticTextDiameterUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextDiameterUnits->Wrap( -1 ); @@ -35,16 +37,26 @@ DIALOG_JUNCTION_PROPS_BASE::DIALOG_JUNCTION_PROPS_BASE( wxWindow* parent, wxWind m_staticTextColor = new wxStaticText( this, wxID_ANY, _("Color:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextColor->Wrap( -1 ); - fgSizer2->Add( m_staticTextColor, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer2->Add( m_staticTextColor, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); - m_buttonColor = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); - fgSizer2->Add( m_buttonColor, 0, wxEXPAND|wxLEFT, 5 ); + m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE|wxTAB_TRAVERSAL ); + wxBoxSizer* bSizer21; + bSizer21 = new wxBoxSizer( wxVERTICAL ); + + m_colorSwatch = new COLOR_SWATCH( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSizer21->Add( m_colorSwatch, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 ); + + + m_panel1->SetSizer( bSizer21 ); + m_panel1->Layout(); + bSizer21->Fit( m_panel1 ); + fgSizer2->Add( m_panel1, 0, wxALIGN_CENTER_VERTICAL, 5 ); fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); - bSizer2->Add( fgSizer2, 1, wxALL|wxEXPAND, 5 ); + bSizer2->Add( fgSizer2, 1, wxALL|wxEXPAND, 10 ); m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); bSizer2->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 ); @@ -68,14 +80,12 @@ DIALOG_JUNCTION_PROPS_BASE::DIALOG_JUNCTION_PROPS_BASE( wxWindow* parent, wxWind this->Centre( wxBOTH ); // Connect Events - m_buttonColor->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::onColorButtonClicked ), NULL, this ); m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::resetDefaults ), NULL, this ); } DIALOG_JUNCTION_PROPS_BASE::~DIALOG_JUNCTION_PROPS_BASE() { // Disconnect Events - m_buttonColor->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::onColorButtonClicked ), NULL, this ); m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_JUNCTION_PROPS_BASE::resetDefaults ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_junction_props_base.fbp b/eeschema/dialogs/dialog_junction_props_base.fbp index b71e6c89fa..d08d5da947 100644 --- a/eeschema/dialogs/dialog_junction_props_base.fbp +++ b/eeschema/dialogs/dialog_junction_props_base.fbp @@ -14,7 +14,6 @@ dialog_junction_props_base 1000 none - 1 dialog_junction_props_base @@ -26,7 +25,6 @@ 1 1 UI - 0 1 0 @@ -61,7 +59,7 @@ wxVERTICAL none - 5 + 10 wxALL|wxEXPAND 1 @@ -78,7 +76,7 @@ 5 5 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 1 @@ -139,7 +137,7 @@ 5 - wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxLEFT + wxEXPAND 0 1 @@ -264,7 +262,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 1 @@ -325,9 +323,9 @@ 5 - wxEXPAND|wxLEFT + wxALIGN_CENTER_VERTICAL 0 - + 1 1 1 @@ -336,34 +334,25 @@ - 0 - 1 0 1 1 - - 0 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY - MyButton - - 0 0 @@ -371,30 +360,90 @@ 0 1 - m_buttonColor + m_panel1 1 protected 1 - - Resizable 1 - ; ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - - onColorButtonClicked + wxBORDER_SIMPLE|wxTAB_TRAVERSAL + + + bSizer21 + wxVERTICAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + COLOR_SWATCH + 1 + + + 1 + + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + + 0 + + + 0 + + 1 + m_colorSwatch + 1 + + + protected + 1 + + Resizable + + 1 + + COLOR_SWATCH; widgets/color_swatch.h; forward_declare + 0 + + + + + + + diff --git a/eeschema/dialogs/dialog_junction_props_base.h b/eeschema/dialogs/dialog_junction_props_base.h index 4f16907747..f82e16c4e4 100644 --- a/eeschema/dialogs/dialog_junction_props_base.h +++ b/eeschema/dialogs/dialog_junction_props_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -10,6 +10,8 @@ #include #include #include +class COLOR_SWATCH; + #include "dialog_shim.h" #include #include @@ -18,13 +20,10 @@ #include #include #include -#include -#include -#include -#include -#include #include +#include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -41,7 +40,8 @@ class DIALOG_JUNCTION_PROPS_BASE : public DIALOG_SHIM wxTextCtrl* m_textCtrlDiameter; wxStaticText* m_staticTextDiameterUnits; wxStaticText* m_staticTextColor; - wxBitmapButton* m_buttonColor; + wxPanel* m_panel1; + COLOR_SWATCH* m_colorSwatch; wxStaticLine* m_staticline2; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; @@ -49,7 +49,6 @@ class DIALOG_JUNCTION_PROPS_BASE : public DIALOG_SHIM wxButton* m_sdbSizerCancel; // Virtual event handlers, overide them in your derived class - virtual void onColorButtonClicked( wxCommandEvent& event ) { event.Skip(); } virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); } diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 35cf09bfd0..0f2730f00e 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -175,12 +175,15 @@ void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const COLOR4D SCH_JUNCTION::GetColor() const { + if( m_color != COLOR4D::UNSPECIFIED ) + return m_color; + NETCLASSPTR netclass = NetClass(); - if( netclass && netclass->GetSchematicColor() != COLOR4D::UNSPECIFIED ) + if( netclass ) return netclass->GetSchematicColor(); - return m_color; + return COLOR4D::UNSPECIFIED; }