KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema/dialogs/dialog_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 The 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
25#include <stroke_params.h>
26#include <sch_edit_frame.h>
27#include <symbol_edit_frame.h>
28#include <sch_shape.h>
29#include <sch_rule_area.h>
33#include <sch_commit.h>
34#include <string_utils.h>
35
36
39 m_frame( aParent ),
40 m_shape( aShape ),
42{
43 SetTitle( wxString::Format( GetTitle(), aShape->GetFriendlyName() ) );
44
45 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
46 // different shapes (and even whether or not we're within the symbol editor) cause different
47 // dialog layouts.
48 m_hash_key = TO_UTF8( GetTitle() + aParent->GetName() );
49
50 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
51 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
52
53 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
54 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
55
56 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
57 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
58
59 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
60 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
61
62 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
63 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
64
65 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
66 m_borderColorSwatch->SetSwatchBackground( canvas.ToColour() );
67 m_fillColorSwatch->SetSwatchBackground( canvas.ToColour() );
68
69 if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
70 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
71
72 m_ruleAreaSizer->Show( dynamic_cast<SCH_RULE_AREA*>( aShape ) != nullptr );
73
75
76 // Required under wxGTK if we want to dismiss the dialog with the ESC key
77 SetFocus();
78
80
81 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
82 {
83 m_fillBook->SetSelection( 1 );
84
85 if( !symbolEditor->IsSymbolEditable() || symbolEditor->IsSymbolAlias() )
86 {
87 m_sdbSizerCancel->SetDefault();
88 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
89 m_sdbSizerOK->Enable( false );
90 }
91 }
92 else
93 {
94 m_fillBook->SetSelection( 0 );
95 m_symbolEditorSizer->Show( false );
96 }
97
98 m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onBorderSwatch, this );
99 m_customColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onCustomColorSwatch, this );
100
101 // Now all widgets have the size fixed, call FinishDialogSettings
103}
104
105
111
112
114{
115 if( !wxDialog::TransferDataToWindow() )
116 return false;
117
118 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
119 {
120 m_cbExcludeFromSim->SetValue( ruleArea->GetExcludedFromSim() );
121 m_cbExcludeFromBom->SetValue( ruleArea->GetExcludedFromBOM() );
122 m_cbExcludeFromBoard->SetValue( ruleArea->GetExcludedFromBoard() );
123 m_cbDNP->SetValue( ruleArea->GetDNP() );
124 }
125
126 if( m_shape->GetWidth() >= 0 )
127 {
128 m_borderCheckbox->SetValue( true );
129 m_borderWidth.SetValue( m_shape->GetWidth() );
130 }
131 else
132 {
133 m_borderCheckbox->SetValue( false );
134
135 m_borderWidth.Enable( false );
136 m_borderColorLabel->Enable( false );
137 m_borderColorSwatch->Enable( false );
138 m_borderStyleLabel->Enable( false );
139 m_borderStyleCombo->Enable( false );
140 }
141
142 m_borderColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false );
143
144 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
145
146 if( style == -1 )
147 m_borderStyleCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
148 else if( style < (int) lineTypeNames.size() )
149 m_borderStyleCombo->SetSelection( style );
150 else
151 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
152
153 if( dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
154 {
155 m_rbFillNone->Enable( true );
156 m_rbFillOutline->Enable( true );
157 m_rbFillBackground->Enable( true );
158 m_rbFillCustom->Enable( true );
159 m_customColorSwatch->Enable( true );
160
161 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
162 {
163 m_rbFillOutline->SetValue( true );
164
165 COLOR4D color = m_shape->GetStroke().GetColor();
166
168 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
169
170 m_customColorSwatch->SetSwatchColor( color, false );
171 }
172 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
173 {
174 m_rbFillBackground->SetValue( true );
175
176 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
177 m_customColorSwatch->SetSwatchColor( color, false );
178 }
179 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
180 {
181 m_rbFillCustom->SetValue( true );
182 m_customColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
183 }
184 else
185 {
186 m_rbFillNone->SetValue( true );
187 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
188 }
189
190 const SYMBOL* symbol = m_shape->GetParentSymbol();
191
192 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
193 m_checkApplyToAllUnits->SetValue( symbol->IsMultiUnit() && m_shape->GetUnit() == 0 );
194 m_checkApplyToAllUnits->Enable( symbol->IsMultiUnit() );
195 m_checkApplyToAllBodyStyles->SetValue( symbol->IsMultiBodyStyle() && m_shape->GetBodyStyle() == 0 );
197 }
198 else
199 {
200 m_fillCtrl->SetSelection( m_shape->GetFillModeProp() );
201 m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
202 }
203
204 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
205 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
206
207 return true;
208}
209
210
211void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
212{
213 bool border = m_borderCheckbox->GetValue();
214
215 if( border && m_borderWidth.GetValue() < 0 )
216 {
217 int defaultInMils;
218
219 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
220 defaultInMils = symbolEditor->libeditconfig()->m_Defaults.line_width;
221 else
222 defaultInMils = m_frame->eeconfig()->m_Drawing.default_line_thickness;
223
224 m_borderWidth.SetValue( schIUScale.MilsToIU( defaultInMils ) );
225 }
226
227 m_borderWidth.Enable( border );
228 m_borderColorLabel->Enable( border );
229 m_borderColorSwatch->Enable( border );
230 m_borderStyleLabel->Enable( border );
231 m_borderStyleCombo->Enable( border );
232}
233
234
235void DIALOG_SHAPE_PROPERTIES::onFillChoice( wxCommandEvent& event )
236{
237 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
238 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
239}
240
241
243{
244 if( event.GetId() == NO_FILL )
245 {
246 m_rbFillNone->SetValue( true );
247 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
248 }
249 else if( event.GetId() == FILLED_SHAPE )
250 {
251 m_rbFillOutline->SetValue( true );
252
253 COLOR4D color = m_borderColorSwatch->GetSwatchColor();
254
255 if( color == COLOR4D::UNSPECIFIED || !m_rbFillOutline->GetValue() )
256 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
257
258 m_customColorSwatch->SetSwatchColor( color, false );
259 }
260 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
261 {
262 m_rbFillBackground->SetValue( true );
263
264 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
265 m_customColorSwatch->SetSwatchColor( color, false );
266 }
267 else if( event.GetId() == FILLED_WITH_COLOR )
268 {
269 m_rbFillCustom->SetValue( true );
270 m_customColorSwatch->GetNewSwatchColor();
271 }
272}
273
274
275void DIALOG_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
276{
277 if( m_rbFillOutline->GetValue() )
278 m_fillColorSwatch->SetSwatchColor( m_borderColorSwatch->GetSwatchColor(), false );
279
280 if( m_rbFillOutline->IsEnabled() && m_rbFillOutline->GetValue() )
281 {
283
284 if( m_rbFillOutline->GetValue() )
285 color = m_fillColorSwatch->GetSwatchColor();
286
288 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
289
290 m_customColorSwatch->SetSwatchColor( color, false );
291 }
292}
293
294
296{
297 m_rbFillCustom->SetValue( true );
298}
299
300
302{
303 if( !wxDialog::TransferDataFromWindow() )
304 return false;
305
306 SCH_COMMIT commit( m_frame );
307
308 if( !m_shape->IsNew() )
309 commit.Modify( m_shape, m_frame->GetScreen() );
310
311 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
312 {
313 ruleArea->SetExcludedFromSim( m_cbExcludeFromSim->GetValue() );
314 ruleArea->SetExcludedFromBOM( m_cbExcludeFromBom->GetValue() );
315 ruleArea->SetExcludedFromBoard( m_cbExcludeFromBoard->GetValue() );
316 ruleArea->SetDNP( m_cbDNP->GetValue() );
317 }
318
319 STROKE_PARAMS stroke = m_shape->GetStroke();
320
321 if( m_borderCheckbox->GetValue() )
322 {
323 if( !m_borderWidth.IsIndeterminate() )
324 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
325 }
326 else
327 {
328 stroke.SetWidth( -1 );
329 }
330
331 auto it = lineTypeNames.begin();
332 std::advance( it, m_borderStyleCombo->GetSelection() );
333
334 if( it == lineTypeNames.end() )
336 else
337 stroke.SetLineStyle( it->first );
338
339 stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
340
341 m_shape->SetStroke( stroke );
342
343 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
344 {
345 if( m_rbFillOutline->GetValue() )
346 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
347 else if( m_rbFillBackground->GetValue() )
349 else if( m_rbFillCustom->GetValue() )
350 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
351 else
352 m_shape->SetFillMode( FILL_T::NO_FILL );
353
354 m_shape->SetFillColor( m_customColorSwatch->GetSwatchColor() );
355
356 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
357
358 if( m_checkApplyToAllBodyStyles->IsChecked() )
359 m_shape->SetBodyStyle( 0 );
360 else
361 m_shape->SetBodyStyle( symbolEditor->GetBodyStyle() );
362
363 if( m_checkApplyToAllUnits->IsChecked() )
364 m_shape->SetUnit( 0 );
365 else
366 m_shape->SetUnit( symbolEditor->GetUnit() );
367 }
368 else
369 {
370 m_shape->SetFillModeProp( (UI_FILL_MODE) m_fillCtrl->GetSelection() );
371 m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
372 }
373
374 if( !commit.Empty() )
375 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->GetFriendlyName() ) );
376
377 return true;
378}
379
380
int color
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
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
bool Empty() const
Definition commit.h:137
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
DIALOG_SHAPE_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("%s Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_SHAPE_PROPERTIES(SCH_BASE_FRAME *aParent, SCH_SHAPE *aShape)
void onBorderChecked(wxCommandEvent &aEvent) override
void onFillChoice(wxCommandEvent &event) override
void onFillRadioButton(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:82
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:401
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
wxColour ToColour() const
Definition color4d.cpp:220
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Simple container to manage line stroke parameters.
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
The symbol library editor main window.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:63
virtual bool IsMultiUnit() const =0
virtual bool IsMultiBodyStyle() const =0
#define _(s)
UI_FILL_MODE
Definition eda_shape.h:68
@ NONE
Definition eda_shape.h:69
@ FILLED_WITH_COLOR
Definition eda_shape.h:60
@ NO_FILL
Definition eda_shape.h:57
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_shape.h:59
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:58
@ LAYER_DEVICE
Definition layer_ids.h:466
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:484
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
Conversion map between LINE_STYLE values and style names displayed.
#define DEFAULT_LINE_STYLE_LABEL