Better support for mixed styles in Junction Properties dialog.

Also move to COLOR_SWATCH to reduce code duplication.
This commit is contained in:
Jeff Young 2020-08-18 18:01:19 +01:00
parent b0a09b782d
commit 6ef20e34fc
7 changed files with 130 additions and 147 deletions

View File

@ -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 )

View File

@ -21,28 +21,14 @@
#include <bitmaps.h>
#include <sch_junction.h>
#include <dialog_junction_props.h>
#include <dialogs/dialog_color_picker.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <sch_edit_frame.h>
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 <widgets/color_swatch.h>
DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent,
std::deque<SCH_JUNCTION*>& aJunctions ) :
std::deque<SCH_JUNCTION*>& 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();

View File

@ -39,17 +39,12 @@ public:
bool TransferDataFromWindow() override;
private:
SCH_EDIT_FRAME* m_frame;
SCH_EDIT_FRAME* m_frame;
std::deque<SCH_JUNCTION*> 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__

View File

@ -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 );
}

View File

@ -14,7 +14,6 @@
<property name="file">dialog_junction_props_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">dialog_junction_props_base</property>
@ -26,7 +25,6 @@
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">1</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
@ -61,7 +59,7 @@
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="border">10</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="1">
@ -78,7 +76,7 @@
<property name="vgap">5</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
@ -139,7 +137,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxEXPAND|wxLEFT</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
@ -264,7 +262,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
@ -325,9 +323,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="1">
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -336,34 +334,25 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">MyButton</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -371,30 +360,90 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonColor</property>
<property name="name">m_panel1</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onColorButtonClicked</event>
<property name="window_style">wxBORDER_SIMPLE|wxTAB_TRAVERSAL</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer21</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="proportion">0</property>
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">COLOR_SWATCH</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include"></property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_colorSwatch</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">COLOR_SWATCH; widgets/color_swatch.h; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -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 <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class COLOR_SWATCH;
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/stattext.h>
@ -18,13 +20,10 @@
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/statline.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
@ -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(); }

View File

@ -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;
}