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>
25 #include <pgm_base.h>
27 #include <sch_edit_frame.h>
28 
29 const int BUTT_COLOR_MINSIZE_X = 32;
30 const int BUTT_COLOR_MINSIZE_Y = 20;
31 
32 
34 {
35  COLOR4D indeterminateColor;
36 
37  indeterminateColor.r = indeterminateColor.b = indeterminateColor.g =
38  indeterminateColor.a = -1.0;
39 
40  return indeterminateColor;
41 }
42 
43 
45  std::deque<SCH_JUNCTION*>& aJunctions ) :
46  DIALOG_JUNCTION_PROPS_BASE( aParent ),
47  m_frame( aParent ),
48  m_junctions( aJunctions ),
49  m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
50  m_staticTextDiameterUnits, true )
51 {
52  m_sdbSizerApply->SetLabel( _( "Default" ) );
53 
55 
56  m_sdbSizerOK->SetDefault();
57 
58  // Now all widgets have the size fixed, call FinishDialogSettings
60 }
61 
62 
64 {
65  auto firstJunction = m_junctions.front();
66 
67  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
68  [&]( const SCH_JUNCTION* r )
69  {
70  return r->GetDiameter() == firstJunction->GetDiameter();
71  } ) )
72  {
73  m_diameter.SetValue( firstJunction->GetDiameter() );
74  }
75  else
76  {
78  }
79 
80  if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
81  [&]( const SCH_JUNCTION* r )
82  {
83  return r->GetColor() == firstJunction->GetColor();
84  } ) )
85  {
86  setColor( firstJunction->GetColor() );
87  }
88  else
89  {
91  }
92 
93  return true;
94 }
95 
96 
97 void DIALOG_JUNCTION_PROPS::onColorButtonClicked( wxCommandEvent& event )
98 {
99  COLOR4D newColor = COLOR4D::UNSPECIFIED;
100  DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false );
101 
102  if( dialog.ShowModal() == wxID_OK )
103  newColor = dialog.GetColor();
104 
105  if( m_selectedColor == newColor )
106  return;
107 
108  setColor( newColor );
109 }
110 
111 
113 {
114  wxMemoryDC iconDC;
115 
116  if( aColor == COLOR4D::UNSPECIFIED || aColor == GetIndeterminateColor() )
117  {
118  m_buttonColor->SetBitmap( KiBitmap( question_mark_xpm ) );
119  }
120  else
121  {
122  wxBitmap bitmap( std::max( m_buttonColor->GetSize().x, BUTT_COLOR_MINSIZE_X ),
123  std::max( m_buttonColor->GetSize().y, BUTT_COLOR_MINSIZE_Y ) );
124 
125  iconDC.SelectObject( bitmap );
126  iconDC.SetPen( *wxBLACK_PEN );
127 
128  wxBrush brush( aColor.ToColour() );
129  iconDC.SetBrush( brush );
130 
131  // Paint the full bitmap in aColor:
132  iconDC.SetBackground( brush );
133  iconDC.Clear();
134 
135  m_buttonColor->SetBitmap( bitmap );
136  }
137 
138  m_buttonColor->Refresh();
139 
140  Refresh( false );
141 }
142 
143 
144 void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
145 {
146  m_diameter.SetValue( 0 );
147  setColor( COLOR4D::UNSPECIFIED );
148 
149  Refresh();
150 }
151 
152 
154 {
155  m_selectedColor = aColor;
156 
157  if( aColor == COLOR4D::UNSPECIFIED )
158  {
159  COLOR4D defaultColor = Pgm().GetSettingsManager().GetColorSettings()->GetColor(
160  m_junctions.front()->GetLayer() );
161  updateColorButton( defaultColor );
162  }
163  else
164  {
166  }
167 }
168 
169 
171 {
172  PICKED_ITEMS_LIST pickedItems;
173 
174  for( SCH_JUNCTION* junction : m_junctions )
175  pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), junction, UR_CHANGED ) );
176 
177  m_frame->SaveCopyInUndoList( pickedItems, UR_CHANGED, false );
178 
179  for( auto& junction : m_junctions )
180  {
181  if( !m_diameter.IsIndeterminate() )
182  junction->SetDiameter( m_diameter.GetValue() );
183 
185  junction->SetColor( m_selectedColor );
186  }
187 
188  m_frame->GetCanvas()->Refresh();
189  m_frame->OnModify();
190 
191  return true;
192 }
std::deque< SCH_JUNCTION * > m_junctions
void updateColorButton(COLOR4D &aColor)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
double g
Green component.
Definition: color4d.h:367
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,...
const int BUTT_COLOR_MINSIZE_Y
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
double b
Blue component.
Definition: color4d.h:368
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
double a
Alpha component.
Definition: color4d.h:369
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)
const BITMAP_OPAQUE question_mark_xpm[1]
Class DIALOG_JUNCTION_PROPS_BASE.
PICKED_ITEMS_LIST is 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 onColorButtonClicked(wxCommandEvent &aEvent) override
static COLOR4D GetIndeterminateColor()
see class PGM_BASE
#define _(s)
Definition: 3d_actions.cpp:33
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
#define INDETERMINATE_ACTION
KIGFX::COLOR4D GetColor()
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...
double r
Red component.
Definition: color4d.h:366
void setColor(const COLOR4D &aColor)
const int BUTT_COLOR_MINSIZE_X
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99