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( wxString::Format( GetTitle(), aShape->EDA_SHAPE::GetFriendlyName() ) );
44
45 m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
46
47 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
48 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
49
50 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
51 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
52
53 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
54 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
55
57
58 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
59 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
60
61 m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
62
64 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
65
67
68 // Required under wxGTK if we want to dismiss the dialog with the ESC key
69 SetFocus();
70
72
73 if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
74 {
75 m_sdbSizerCancel->SetDefault();
76 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
77 m_sdbSizerOK->Enable( false );
78 }
79
80 m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
81 m_fillColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
82
83 // Now all widgets have the size fixed, call FinishDialogSettings
85}
86
87
89{
90 m_borderColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
91 m_fillColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
92}
93
94
96{
97 if( !wxDialog::TransferDataToWindow() )
98 return false;
99
100 LIB_SYMBOL* symbol = m_shape->GetParent();
101
102 m_checkBorder->SetValue( m_shape->GetWidth() >= 0 );
103
104 if( m_shape->GetWidth() >= 0 )
106
108 m_helpLabel->Enable( m_shape->GetWidth() >= 0 );
109 m_borderColorLabel->Enable( m_shape->GetWidth() >= 0 );
110 m_borderColorSwatch->Enable( m_shape->GetWidth() >= 0 );
111 m_borderStyleLabel->Enable( m_shape->GetWidth() >= 0 );
112 m_borderStyleCombo->Enable( m_shape->GetWidth() >= 0 );
113
115
116 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
117
118 if( style == -1 )
119 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
120 else if( style < (int) lineTypeNames.size() )
121 m_borderStyleCombo->SetSelection( style );
122 else
123 wxFAIL_MSG( "Line type not found in the type lookup map" );
124
125 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
126 m_checkApplyToAllUnits->SetValue(
127 symbol && symbol->GetUnitCount() > 1 && m_shape->GetUnit() == 0 );
128 m_checkApplyToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
130
131 bool enableAlternateBodyStyle = symbol && symbol->HasAlternateBodyStyle();
132
133 // If a symbol contains no body-style-specific pins or graphic items,
134 // symbol->HasAlternateBodyStyle() will return false.
135 // But when creating a new symbol, with DeMorgan option set, the m_checkApplyToAllBodyStyles
136 // must be enabled in order to be able to create graphic items shared by all body styles.
137 if( m_frame->GetShowDeMorgan() )
138 enableAlternateBodyStyle = true;
139
140 m_checkApplyToAllBodyStyles->Enable( enableAlternateBodyStyle );
141
142 m_rbFillNone->Enable( true );
143 m_rbFillOutline->Enable( true );
144 m_rbFillBackground->Enable( true );
145 m_rbFillCustom->Enable( true );
146 m_fillColorSwatch->Enable( true );
147
148 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
149 {
150 m_rbFillOutline->SetValue( true );
151
153
154 if( color == COLOR4D::UNSPECIFIED )
156
158 }
159 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
160 {
161 m_rbFillBackground->SetValue( true );
162
165 }
166 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
167 {
168 m_rbFillCustom->SetValue( true );
170 }
171 else
172 {
173 m_rbFillNone->SetValue( true );
174 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
175 }
176
177 return true;
178}
179
180
181void DIALOG_LIB_SHAPE_PROPERTIES::onFill( wxCommandEvent& event )
182{
183 if( event.GetId() == NO_FILL )
184 {
185 m_rbFillNone->SetValue( true );
186 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
187 }
188 else if( event.GetId() == FILLED_SHAPE )
189 {
190 m_rbFillOutline->SetValue( true );
191
193
194 if( color == COLOR4D::UNSPECIFIED )
196
198 }
199 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
200 {
201 m_rbFillBackground->SetValue( true );
202
205 }
206 else if( event.GetId() == FILLED_WITH_COLOR )
207 {
208 m_rbFillCustom->SetValue( true );
210 }
211}
212
213
215{
216 bool border = m_checkBorder->GetValue();
217
218 if( border && m_borderWidth.GetValue() < 0 )
220
221 m_borderWidth.Enable( border );
222 m_borderColorLabel->Enable( border );
223 m_borderColorSwatch->Enable( border );
224 m_borderStyleLabel->Enable( border );
225 m_borderStyleCombo->Enable( border );
226}
227
228
230{
231 if( m_rbFillOutline->GetValue() )
233}
234
235
236void DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch( wxCommandEvent& aEvent )
237{
238 m_rbFillCustom->SetValue( true );
239}
240
241
243{
244 if( !wxDialog::TransferDataFromWindow() )
245 return false;
246
247 STROKE_PARAMS stroke = m_shape->GetStroke();
248
249 if( m_checkBorder->GetValue() )
250 {
252 stroke.SetWidth( m_borderWidth.GetValue() );
253 }
254 else
255 {
256 stroke.SetWidth( -1 );
257 }
258
259 auto it = lineTypeNames.begin();
260 std::advance( it, m_borderStyleCombo->GetSelection() );
261
262 if( it == lineTypeNames.end() )
263 stroke.SetLineStyle( LINE_STYLE::DEFAULT );
264 else
265 stroke.SetLineStyle( it->first );
266
268
269 m_shape->SetStroke( stroke );
270
271 if( m_rbFillOutline->GetValue() )
272 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
273 else if( m_rbFillBackground->GetValue() )
274 m_shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
275 else if( m_rbFillCustom->GetValue() )
276 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
277 else
278 m_shape->SetFillMode( FILL_T::NO_FILL );
279
281
282 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
283
285 m_shape->SetBodyStyle( 0 );
286 else
288
289 if( GetApplyToAllUnits() )
290 m_shape->SetUnit( 0 );
291 else
293
294 return true;
295}
296
297
299{
300 return m_checkApplyToAllBodyStyles->IsChecked();
301}
302
303
305{
306 return m_checkApplyToAllUnits->IsChecked();
307}
308
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
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
virtual 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:104
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool IsPrivate() const
Definition: lib_item.h:349
int GetBodyStyle() const
Definition: lib_item.h:346
int GetUnit() const
Definition: lib_item.h:343
void SetPrivate(bool aPrivate)
Definition: lib_item.h:348
void SetBodyStyle(int aBodyStyle)
Definition: lib_item.h:345
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:209
void SetUnit(int aUnit)
Definition: lib_item.h:342
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
Define a library symbol object.
Definition: lib_symbol.h:99
bool HasAlternateBodyStyle() const
Test if symbol has more than one body conversion type (DeMorgan).
int GetUnitCount() const override
For items with units, return the number of units.
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
The symbol library editor main window.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
int GetBodyStyle() const
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.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
This file is part of the common library.
#define _(s)
@ LAYER_DEVICE
Definition: layer_ids.h:368
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:384
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:388
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94