KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_wire_bus_properties.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) 2017 Seth Hillbrand <[email protected]>
5 * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <sch_line.h>
26#include <sch_bus_entry.h>
27#include <sch_junction.h>
31#include <sch_edit_frame.h>
32#include <stroke_params.h>
34
35
37 std::deque<SCH_ITEM*>& aItems ) :
39 m_frame( aParent ),
40 m_items( aItems ),
41 m_wireWidth( aParent, m_staticTextWidth, m_lineWidth, m_staticWidthUnits ),
42 m_junctionSize( aParent, m_dotSizeLabel, m_dotSizeCtrl, m_dotSizeUnits )
43{
44 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
45
48
49 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
50 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
51
53
54 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
55 m_typeCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
56
57 m_typeCombo->Append( DEFAULT_STYLE );
58
59 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
60
61 // Now all widgets have the size fixed, call FinishDialogSettings
63}
64
65
67{
68 STROKE_PARAMS stroke;
70 int dotSize = -1; // set value to "not found"
71
72 for( SCH_ITEM* item : m_items )
73 {
74 if( item->HasLineStroke() )
75 {
76 stroke = item->GetStroke();
77 color = stroke.GetColor();
78 }
79 else
80 {
81 wxASSERT( item->Type() == SCH_JUNCTION_T );
82 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
83 color = junction->GetColor();
84 dotSize = junction->GetDiameter();
85 }
86 }
87
88 if( std::all_of( m_items.begin(), m_items.end(),
89 [&]( const SCH_ITEM* item )
90 {
91 return !item->HasLineStroke() || item->GetStroke().GetWidth() == stroke.GetWidth();
92 } ) )
93 {
94 m_wireWidth.SetValue( stroke.GetWidth() );
95 }
96 else
97 {
99 }
100
101 if( std::all_of( m_items.begin(), m_items.end(),
102 [&]( const SCH_ITEM* item )
103 {
104 if( item->HasLineStroke() )
105 return item->GetStroke().GetColor() == color;
106 else
107 return static_cast<const SCH_JUNCTION*>( item )->GetColor() == color;
108 } ) )
109 {
111 }
112 else
113 {
114 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
115 }
116
117 if( std::all_of( m_items.begin(), m_items.end(),
118 [&]( const SCH_ITEM* item )
119 {
120 return !item->HasLineStroke()
121 || item->GetStroke().GetPlotStyle() == stroke.GetPlotStyle();
122 } ) )
123 {
124 int style = static_cast<int>( stroke.GetPlotStyle() );
125
126 if( style == -1 )
127 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
128 else if( style < (int) lineTypeNames.size() )
129 m_typeCombo->SetSelection( style );
130 else
131 wxFAIL_MSG( "Line type not found in the type lookup map" );
132 }
133 else
134 {
136 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
137 }
138
139 if( std::all_of( m_items.begin(), m_items.end(),
140 [&]( const SCH_ITEM* item )
141 {
142 return item->Type() != SCH_JUNCTION_T
143 || static_cast<const SCH_JUNCTION*>( item )->GetDiameter() == dotSize;
144 } ) )
145 {
146 if( dotSize >=0 )
147 m_junctionSize.SetValue( dotSize );
148 else
149 {
150 // No junction found in selected items: disable m_junctionSize
151 m_junctionSize.Enable( false );
153 }
154 }
155 else
156 {
158 }
159
160 return true;
161}
162
163
164void DIALOG_WIRE_BUS_PROPERTIES::resetDefaults( wxCommandEvent& event )
165{
167 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
168 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
170
171 Refresh();
172}
173
174
176{
177 PICKED_ITEMS_LIST pickedItems;
178
179 for( SCH_ITEM* strokeItem : m_items )
180 pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), strokeItem, UNDO_REDO::CHANGED ) );
181
182 m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false, false );
183
184 for( SCH_ITEM* item : m_items )
185 {
186 if( item->HasLineStroke() )
187 {
189 {
190 int width = std::max( 0, m_wireWidth.GetIntValue() );
191
192 if( item->Type() == SCH_LINE_T )
193 static_cast<SCH_LINE*>( item )->SetLineWidth( width );
194 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
195 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetPenWidth( width );
196 }
197
198 PLOT_DASH_TYPE lineStyle = PLOT_DASH_TYPE::DEFAULT;
199
200 auto it = lineTypeNames.begin();
201 std::advance( it, m_typeCombo->GetSelection() );
202
203 if( it != lineTypeNames.end() )
204 lineStyle = it->first;
205
206 if( item->Type() == SCH_LINE_T )
207 static_cast<SCH_LINE*>( item )->SetLineStyle( lineStyle );
208 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
209 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetLineStyle( lineStyle );
210
212
213 if( item->Type() == SCH_LINE_T )
214 static_cast<SCH_LINE*>( item )->SetLineColor( color );
215 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
216 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetBusEntryColor( color );
217 }
218 else
219 {
220 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
221
222 junction->SetColor( m_colorSwatch->GetSwatchColor() );
223
225 junction->SetDiameter( m_junctionSize.GetValue() );
226 }
227
228 m_frame->UpdateItem( item, false, true );
229 }
230
232 m_frame->OnModify();
233
234 return true;
235}
int color
Definition: DXF_plotter.cpp:57
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:106
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.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
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...
Class DIALOG_WIRE_BUS_PROPERTIES_BASE.
std::deque< SCH_ITEM * > m_items
DIALOG_WIRE_BUS_PROPERTIES(SCH_EDIT_FRAME *aParent, std::deque< SCH_ITEM * > &aItems)
void resetDefaults(wxCommandEvent &event) override
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
wxColour ToColour() const
Definition: color4d.cpp:219
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
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.
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
void SetBusEntryColor(const COLOR4D &aColor)
void SetPenWidth(int aWidth)
void SetLineStyle(PLOT_DASH_TYPE aStyle)
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void SetDiameter(int aDiameter)
COLOR4D GetColor() const
Definition: sch_junction.h:114
int GetDiameter() const
Definition: sch_junction.h:109
void SetColor(const COLOR4D &aColor)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:244
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
int GetWidth() const
Definition: stroke_params.h:98
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
int GetIntValue()
Definition: unit_binder.h:127
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
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:380
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
#define INDETERMINATE_STYLE
Definition: stroke_params.h:81
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
@ SCH_LINE_T
Definition: typeinfo.h:136
@ SCH_JUNCTION_T
Definition: typeinfo.h:132
#define INDETERMINATE_ACTION
Definition: ui_common.h:43