KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_junction_props.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Wayne Stambaugh <[email protected]>
5 * Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <sch_junction.h>
24#include <sch_edit_frame.h>
26#include <sch_commit.h>
27
28
30 std::deque<SCH_JUNCTION*>& aJunctions ) :
32 m_frame( aParent ),
33 m_junctions( aJunctions ),
34 m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
35 m_staticTextDiameterUnits, true )
36{
37 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
38
41
42 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
43 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
44
46
47 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
48
49 // Now all widgets have the size fixed, call FinishDialogSettings
51}
52
53
55{
56 auto firstJunction = m_junctions.front();
57
58 if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
59 [&]( const SCH_JUNCTION* r )
60 {
61 return r->GetDiameter() == firstJunction->GetDiameter();
62 } ) )
63 {
64 m_diameter.SetValue( firstJunction->GetDiameter() );
65 }
66 else
67 {
69 }
70
71 if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
72 [&]( const SCH_JUNCTION* r )
73 {
74 return r->GetColor() == firstJunction->GetColor();
75 } ) )
76 {
77 m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false );
78 }
79 else
80 {
81 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
82 }
83
84 return true;
85}
86
87
88void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
89{
91 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
92
93 Refresh();
94}
95
96
98{
99 SCH_COMMIT commit( m_frame );
100
101 for( SCH_JUNCTION* junction : m_junctions )
102 {
103 commit.Modify( junction, m_frame->GetScreen() );
104
106 junction->SetDiameter( m_diameter.GetValue() );
107
108 junction->SetColor( m_colorSwatch->GetSwatchColor() );
109
110 m_frame->GetCanvas()->GetView()->Update( junction );
111 }
112
113 commit.Push( m_junctions.size() == 1 ? _( "Edit Junction" ) : _( "Edit Junctions" ) );
114
115 return true;
116}
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
Class DIALOG_JUNCTION_PROPS_BASE.
void resetDefaults(wxCommandEvent &event) override
std::deque< SCH_JUNCTION * > m_junctions
DIALOG_JUNCTION_PROPS(SCH_EDIT_FRAME *aParent, std::deque< SCH_JUNCTION * > &aJunctions)
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxColour ToColour() const
Definition: color4d.cpp:220
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1687
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:432
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual long long int GetValue()
Return the current value in Internal Units.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:391
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
#define INDETERMINATE_ACTION
Definition: ui_common.h:47