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 <bitmaps.h>
22 #include <sch_junction.h>
23 #include <dialog_junction_props.h>
24 #include <pgm_base.h>
26 #include <sch_edit_frame.h>
27 #include <widgets/color_swatch.h>
28 
29 
31  std::deque<SCH_JUNCTION*>& aJunctions ) :
32  DIALOG_JUNCTION_PROPS_BASE( aParent ),
33  m_frame( aParent ),
34  m_junctions( aJunctions ),
35  m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
36  m_staticTextDiameterUnits, true )
37 {
38  m_sdbSizerApply->SetLabel( _( "Default" ) );
39 
40  m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
41 
43 
44  m_sdbSizerOK->SetDefault();
45 
46  // Now all widgets have the size fixed, call FinishDialogSettings
48 }
49 
50 
52 {
53  auto firstJunction = m_junctions.front();
54 
55  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
56  [&]( const SCH_JUNCTION* r )
57  {
58  return r->GetDiameter() == firstJunction->GetDiameter();
59  } ) )
60  {
61  m_diameter.SetValue( firstJunction->GetDiameter() );
62  }
63  else
64  {
66  }
67 
68  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
69  [&]( const SCH_JUNCTION* r )
70  {
71  return r->GetColor() == firstJunction->GetColor();
72  } ) )
73  {
74  m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false );
75  }
76  else
77  {
78  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
79  }
80 
81  return true;
82 }
83 
84 
85 void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
86 {
87  m_diameter.SetValue( 0 );
88  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
89 
90  Refresh();
91 }
92 
93 
95 {
96  PICKED_ITEMS_LIST pickedItems;
97 
98  for( SCH_JUNCTION* junction : m_junctions )
99  pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), junction, UNDO_REDO::CHANGED ) );
100 
101  m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false );
102 
103  for( SCH_JUNCTION* junction : m_junctions )
104  {
105  if( !m_diameter.IsIndeterminate() )
106  junction->SetDiameter( m_diameter.GetValue() );
107 
108  junction->SetColor( m_colorSwatch->GetSwatchColor() );
109 
110  m_frame->GetCanvas()->GetView()->Update( junction );
111  }
112 
113  m_frame->GetCanvas()->Refresh();
114  m_frame->OnModify();
115 
116  return true;
117 }
std::deque< SCH_JUNCTION * > m_junctions
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
KIGFX::COLOR4D GetSwatchColor() const
void SetSwatchColor(KIGFX::COLOR4D aColor, bool sendEvent)
Set the current swatch color directly.
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
Schematic editor (Eeschema) main window.
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance,...
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:114
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.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
DIALOG_JUNCTION_PROPS(SCH_EDIT_FRAME *aParent, std::deque< SCH_JUNCTION * > &aJunctions)
Class DIALOG_JUNCTION_PROPS_BASE.
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
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
see class PGM_BASE
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
virtual long long int GetValue()
Function GetValue Returns 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