KiCad PCB EDA Suite
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 <stambaughw@gmail.com>
5  * Copyright (C) 2020 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>
22 #include <dialog_junction_props.h>
24 #include <sch_edit_frame.h>
25 #include <widgets/color_swatch.h>
26 
27 
29  std::deque<SCH_JUNCTION*>& aJunctions ) :
30  DIALOG_JUNCTION_PROPS_BASE( aParent ),
31  m_frame( aParent ),
32  m_junctions( aJunctions ),
33  m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
34  m_staticTextDiameterUnits, true )
35 {
36  m_sdbSizerApply->SetLabel( _( "Default" ) );
37 
38  m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
39 
40  m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
41  m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
42 
44 
45  m_sdbSizerOK->SetDefault();
46 
47  // Now all widgets have the size fixed, call FinishDialogSettings
49 }
50 
51 
53 {
54  auto firstJunction = m_junctions.front();
55 
56  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
57  [&]( const SCH_JUNCTION* r )
58  {
59  return r->GetDiameter() == firstJunction->GetDiameter();
60  } ) )
61  {
62  m_diameter.SetValue( firstJunction->GetDiameter() );
63  }
64  else
65  {
67  }
68 
69  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
70  [&]( const SCH_JUNCTION* r )
71  {
72  return r->GetColor() == firstJunction->GetColor();
73  } ) )
74  {
75  m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false );
76  }
77  else
78  {
79  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
80  }
81 
82  return true;
83 }
84 
85 
86 void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
87 {
88  m_diameter.SetValue( 0 );
89  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
90 
91  Refresh();
92 }
93 
94 
96 {
97  PICKED_ITEMS_LIST pickedItems;
98 
99  for( SCH_JUNCTION* junction : m_junctions )
100  pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), junction, UNDO_REDO::CHANGED ) );
101 
102  m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false );
103 
104  for( SCH_JUNCTION* junction : m_junctions )
105  {
106  if( !m_diameter.IsIndeterminate() )
107  junction->SetDiameter( m_diameter.GetValue() );
108 
109  junction->SetColor( m_colorSwatch->GetSwatchColor() );
110 
111  m_frame->GetCanvas()->GetView()->Update( junction );
112  }
113 
114  m_frame->GetCanvas()->Refresh();
115  m_frame->OnModify();
116 
117  return true;
118 }
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
std::deque< SCH_JUNCTION * > m_junctions
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
KIGFX::COLOR4D GetSwatchColor() const
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
Schematic editor (Eeschema) main window.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
void resetDefaults(wxCommandEvent &event) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool TransferDataFromWindow() override
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
#define _(s)
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
DIALOG_JUNCTION_PROPS(SCH_EDIT_FRAME *aParent, std::deque< SCH_JUNCTION * > &aJunctions)
Class DIALOG_JUNCTION_PROPS_BASE.
A holder to handle information on schematic or board items.
E_SERIE r
Definition: eserie.cpp:41
bool TransferDataToWindow() override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual long long int GetValue()
Return the current value in Internal Units.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
#define INDETERMINATE_ACTION
Definition: base_units.h:48
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:1512