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>
23 #include <pgm_base.h>
25 #include <sch_edit_frame.h>
26 #include <widgets/color_swatch.h>
27 
28 
30  std::deque<SCH_JUNCTION*>& aJunctions ) :
31  DIALOG_JUNCTION_PROPS_BASE( aParent ),
32  m_frame( aParent ),
33  m_junctions( aJunctions ),
34  m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
35  m_staticTextDiameterUnits, true )
36 {
37  m_sdbSizerApply->SetLabel( _( "Default" ) );
38 
39  m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
40 
42 
43  m_sdbSizerOK->SetDefault();
44 
45  // Now all widgets have the size fixed, call FinishDialogSettings
47 }
48 
49 
51 {
52  auto firstJunction = m_junctions.front();
53 
54  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
55  [&]( const SCH_JUNCTION* r )
56  {
57  return r->GetDiameter() == firstJunction->GetDiameter();
58  } ) )
59  {
60  m_diameter.SetValue( firstJunction->GetDiameter() );
61  }
62  else
63  {
65  }
66 
67  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
68  [&]( const SCH_JUNCTION* r )
69  {
70  return r->GetColor() == firstJunction->GetColor();
71  } ) )
72  {
73  m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false );
74  }
75  else
76  {
77  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
78  }
79 
80  return true;
81 }
82 
83 
84 void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
85 {
86  m_diameter.SetValue( 0 );
87  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
88 
89  Refresh();
90 }
91 
92 
94 {
95  PICKED_ITEMS_LIST pickedItems;
96 
97  for( SCH_JUNCTION* junction : m_junctions )
98  pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), junction, UNDO_REDO::CHANGED ) );
99 
100  m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false );
101 
102  for( SCH_JUNCTION* junction : m_junctions )
103  {
104  if( !m_diameter.IsIndeterminate() )
105  junction->SetDiameter( m_diameter.GetValue() );
106 
107  junction->SetColor( m_colorSwatch->GetSwatchColor() );
108 
109  m_frame->GetCanvas()->GetView()->Update( junction );
110  }
111 
112  m_frame->GetCanvas()->Refresh();
113  m_frame->OnModify();
114 
115  return true;
116 }
std::deque< SCH_JUNCTION * > m_junctions
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void SetSwatchColor(KIGFX::COLOR4D aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
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:98
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.
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool TransferDataToWindow() override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
see class PGM_BASE
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.
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
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:49
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:1503