KiCad PCB EDA Suite
dialog_lib_shape_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) 2006-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <lib_item.h>
26#include <symbol_edit_frame.h>
28#include <confirm.h>
29#include <lib_shape.h>
32#include <sch_painter.h>
33
35 LIB_SHAPE* aShape ) :
37 m_frame( aParent ),
38 m_shape( aShape ),
39 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
40{
41 wxASSERT( aShape );
42
43 SetTitle( m_shape->GetTypeName() + wxT( " " ) + GetTitle() );
44 m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
45
46 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
47 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
48
49 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
50 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
51
52 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
53 m_borderStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
54
56
57 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
58 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
59
60 m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
61
63
64 // Required under wxGTK if we want to dismiss the dialog with the ESC key
65 SetFocus();
66
68
69 if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
70 {
71 m_sdbSizerCancel->SetDefault();
72 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
73 m_sdbSizerOK->Enable( false );
74 }
75
76 m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
77 m_fillColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
78
79 // Now all widgets have the size fixed, call FinishDialogSettings
81}
82
83
85{
86 m_borderColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
87 m_fillColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
88}
89
90
92{
93 if( !wxDialog::TransferDataToWindow() )
94 return false;
95
96 LIB_SYMBOL* symbol = m_shape->GetParent();
97
98 m_checkBorder->SetValue( m_shape->GetWidth() >= 0 );
99
100 if( m_shape->GetWidth() >= 0 )
102
104 m_helpLabel->Enable( m_shape->GetWidth() >= 0 );
105 m_borderColorLabel->Enable( m_shape->GetWidth() >= 0 );
106 m_borderColorSwatch->Enable( m_shape->GetWidth() >= 0 );
107 m_borderStyleLabel->Enable( m_shape->GetWidth() >= 0 );
108 m_borderStyleCombo->Enable( m_shape->GetWidth() >= 0 );
109
111
112 int style = static_cast<int>( m_shape->GetStroke().GetPlotStyle() );
113
114 if( style == -1 )
115 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
116 else if( style < (int) lineTypeNames.size() )
117 m_borderStyleCombo->SetSelection( style );
118 else
119 wxFAIL_MSG( "Line type not found in the type lookup map" );
120
121 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
122 m_checkApplyToAllUnits->SetValue( m_shape->GetUnit() == 0 );
123 m_checkApplyToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
125
126 bool enblConvOptStyle = symbol && symbol->HasConversion();
127
128 // If a symbol contains no conversion-specific pins or graphic items, symbol->HasConversion()
129 // will return false.
130 // But when creating a new symbol, with DeMorgan option set, the ApplyToAllConversions
131 // must be enabled in order to be able to create graphic items shared by all body styles.
132 if( m_frame->GetShowDeMorgan() )
133 enblConvOptStyle = true;
134
135 m_checkApplyToAllConversions->Enable( enblConvOptStyle );
136
137 m_rbFillNone->Enable( true );
138 m_rbFillOutline->Enable( true );
139 m_rbFillBackground->Enable( true );
140 m_rbFillCustom->Enable( true );
141 m_fillColorSwatch->Enable( true );
142
144 {
145 m_rbFillOutline->SetValue( true );
146
148
149 if( color == COLOR4D::UNSPECIFIED )
151
153 }
155 {
156 m_rbFillBackground->SetValue( true );
157
160 }
162 {
163 m_rbFillCustom->SetValue( true );
165 }
166 else
167 {
168 m_rbFillNone->SetValue( true );
169 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
170 }
171
172 return true;
173}
174
175
176void DIALOG_LIB_SHAPE_PROPERTIES::onFill( wxCommandEvent& event )
177{
178 if( event.GetId() == NO_FILL )
179 {
180 m_rbFillNone->SetValue( true );
181 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
182 }
183 else if( event.GetId() == FILLED_SHAPE )
184 {
185 m_rbFillOutline->SetValue( true );
186
188
189 if( color == COLOR4D::UNSPECIFIED )
191
193 }
194 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
195 {
196 m_rbFillBackground->SetValue( true );
197
200 }
201 else if( event.GetId() == FILLED_WITH_COLOR )
202 {
203 m_rbFillCustom->SetValue( true );
205 }
206}
207
208
210{
211 bool border = m_checkBorder->GetValue();
212
213 if( border && m_borderWidth.GetValue() < 0 )
215
216 m_borderWidth.Enable( border );
217 m_borderColorLabel->Enable( border );
218 m_borderColorSwatch->Enable( border );
219 m_borderStyleLabel->Enable( border );
220 m_borderStyleCombo->Enable( border );
221}
222
223
225{
226 if( m_rbFillOutline->GetValue() )
228}
229
230
231void DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch( wxCommandEvent& aEvent )
232{
233 m_rbFillCustom->SetValue( true );
234}
235
236
238{
239 if( !wxDialog::TransferDataFromWindow() )
240 return false;
241
242 STROKE_PARAMS stroke = m_shape->GetStroke();
243
244 if( m_checkBorder->GetValue() )
245 {
247 stroke.SetWidth( m_borderWidth.GetValue() );
248 }
249 else
250 {
251 stroke.SetWidth( -1 );
252 }
253
254 auto it = lineTypeNames.begin();
255 std::advance( it, m_borderStyleCombo->GetSelection() );
256
257 if( it == lineTypeNames.end() )
259 else
260 stroke.SetPlotStyle( it->first );
261
263
264 m_shape->SetStroke( stroke );
265
266 if( m_rbFillOutline->GetValue() )
268 else if( m_rbFillBackground->GetValue() )
270 else if( m_rbFillCustom->GetValue() )
272 else
274
276
277 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
278
280 m_shape->SetConvert( 0 );
281 else
283
284 if( GetApplyToAllUnits() )
285 m_shape->SetUnit( 0 );
286 else
288
289 return true;
290}
291
292
294{
295 return m_checkApplyToAllConversions->IsChecked();
296}
297
298
300{
301 return m_checkApplyToAllUnits->IsChecked();
302}
303
int color
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
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:105
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
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.
Class DIALOG_LIB_SHAPE_PROPERTIES_BASE.
DIALOG_LIB_SHAPE_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SHAPE *aShape)
Constructor.
void onFillSwatch(wxCommandEvent &aEvent)
void onBorderSwatch(wxCommandEvent &aEvent)
void onBorderChecked(wxCommandEvent &aEvent) override
void onFill(wxCommandEvent &aEvent) 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
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...
FILL_T GetFillMode() const
Definition: eda_shape.h:101
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:104
COLOR4D GetFillColor() const
Definition: eda_shape.h:103
int GetWidth() const
Definition: eda_shape.h:107
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool IsPrivate() const
Definition: lib_item.h:279
int GetUnit() const
Definition: lib_item.h:273
void SetPrivate(bool aPrivate)
Definition: lib_item.h:278
int GetConvert() const
Definition: lib_item.h:276
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:168
void SetConvert(int aConvert)
Definition: lib_item.h:275
void SetUnit(int aUnit)
Definition: lib_item.h:272
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:52
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:53
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_shape.h:47
Define a library symbol object.
Definition: lib_symbol.h:98
int GetUnitCount() const override
For items with units, return the number of units.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
void SetWidth(int aWidth)
Definition: stroke_params.h:99
void SetColor(const KIGFX::COLOR4D &aColor)
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
The symbol library editor main window.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
bool GetShowDeMorgan() const
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
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.
This file is part of the common library.
#define _(s)
@ FILLED_WITH_COLOR
@ FILLED_WITH_BG_BODYCOLOR
@ FILLED_SHAPE
@ LAYER_DEVICE
Definition: layer_ids.h:357
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:372
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94