KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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(
123 symbol && symbol->GetUnitCount() > 1 && m_shape->GetUnit() == 0 );
124 m_checkApplyToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
126
127 bool enblConvOptStyle = symbol && symbol->HasConversion();
128
129 // If a symbol contains no conversion-specific pins or graphic items, symbol->HasConversion()
130 // will return false.
131 // But when creating a new symbol, with DeMorgan option set, the ApplyToAllConversions
132 // must be enabled in order to be able to create graphic items shared by all body styles.
133 if( m_frame->GetShowDeMorgan() )
134 enblConvOptStyle = true;
135
136 m_checkApplyToAllConversions->Enable( enblConvOptStyle );
137
138 m_rbFillNone->Enable( true );
139 m_rbFillOutline->Enable( true );
140 m_rbFillBackground->Enable( true );
141 m_rbFillCustom->Enable( true );
142 m_fillColorSwatch->Enable( true );
143
144 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
145 {
146 m_rbFillOutline->SetValue( true );
147
149
150 if( color == COLOR4D::UNSPECIFIED )
152
154 }
155 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
156 {
157 m_rbFillBackground->SetValue( true );
158
161 }
162 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
163 {
164 m_rbFillCustom->SetValue( true );
166 }
167 else
168 {
169 m_rbFillNone->SetValue( true );
170 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
171 }
172
173 return true;
174}
175
176
177void DIALOG_LIB_SHAPE_PROPERTIES::onFill( wxCommandEvent& event )
178{
179 if( event.GetId() == NO_FILL )
180 {
181 m_rbFillNone->SetValue( true );
182 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
183 }
184 else if( event.GetId() == FILLED_SHAPE )
185 {
186 m_rbFillOutline->SetValue( true );
187
189
190 if( color == COLOR4D::UNSPECIFIED )
192
194 }
195 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
196 {
197 m_rbFillBackground->SetValue( true );
198
201 }
202 else if( event.GetId() == FILLED_WITH_COLOR )
203 {
204 m_rbFillCustom->SetValue( true );
206 }
207}
208
209
211{
212 bool border = m_checkBorder->GetValue();
213
214 if( border && m_borderWidth.GetValue() < 0 )
216
217 m_borderWidth.Enable( border );
218 m_borderColorLabel->Enable( border );
219 m_borderColorSwatch->Enable( border );
220 m_borderStyleLabel->Enable( border );
221 m_borderStyleCombo->Enable( border );
222}
223
224
226{
227 if( m_rbFillOutline->GetValue() )
229}
230
231
232void DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch( wxCommandEvent& aEvent )
233{
234 m_rbFillCustom->SetValue( true );
235}
236
237
239{
240 if( !wxDialog::TransferDataFromWindow() )
241 return false;
242
243 STROKE_PARAMS stroke = m_shape->GetStroke();
244
245 if( m_checkBorder->GetValue() )
246 {
248 stroke.SetWidth( m_borderWidth.GetValue() );
249 }
250 else
251 {
252 stroke.SetWidth( -1 );
253 }
254
255 auto it = lineTypeNames.begin();
256 std::advance( it, m_borderStyleCombo->GetSelection() );
257
258 if( it == lineTypeNames.end() )
259 stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
260 else
261 stroke.SetPlotStyle( it->first );
262
264
265 m_shape->SetStroke( stroke );
266
267 if( m_rbFillOutline->GetValue() )
268 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
269 else if( m_rbFillBackground->GetValue() )
270 m_shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
271 else if( m_rbFillCustom->GetValue() )
272 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
273 else
274 m_shape->SetFillMode( FILL_T::NO_FILL );
275
277
278 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
279
281 m_shape->SetConvert( 0 );
282 else
284
285 if( GetApplyToAllUnits() )
286 m_shape->SetUnit( 0 );
287 else
289
290 return true;
291}
292
293
295{
296 return m_checkApplyToAllConversions->IsChecked();
297}
298
299
301{
302 return m_checkApplyToAllUnits->IsChecked();
303}
304
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:106
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:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
int GetWidth() const
Definition: eda_shape.h:109
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool IsPrivate() const
Definition: lib_item.h:299
int GetUnit() const
Definition: lib_item.h:293
void SetPrivate(bool aPrivate)
Definition: lib_item.h:298
int GetConvert() const
Definition: lib_item.h:296
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:188
void SetConvert(int aConvert)
Definition: lib_item.h:295
void SetUnit(int aUnit)
Definition: lib_item.h:292
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_shape.h:52
Define a library symbol object.
Definition: lib_symbol.h:99
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)
@ LAYER_DEVICE
Definition: layer_ids.h:361
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:376
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:380
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
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