KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_label_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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <template_fieldnames.h>
24#include <widgets/font_choice.h>
29#include <sch_edit_frame.h>
30#include <tool/tool_manager.h>
31#include <gr_text.h>
32#include <confirm.h>
33#include <schematic.h>
36#include <string_utils.h>
37#include <kiface_base.h>
38#include <sch_label.h>
39#include <sch_commit.h>
40
41
44 m_Parent( aParent ),
45 m_currentLabel( aLabel ),
46 m_activeTextEntry( nullptr ),
47 m_netNameValidator( true ),
48 m_fields( nullptr ),
50 m_helpWindow( nullptr ),
51 m_labelList( nullptr )
52{
53 COLOR_SETTINGS* colorSettings = m_Parent->GetColorSettings();
54 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
55
56 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
57 embeddedFilesStack.push_back( m_currentLabel->Schematic() );
58
59 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_currentLabel, embeddedFilesStack );
62
63 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
64 {
65 m_activeTextEntry = m_valueCombo;
66 SetInitialFocus( m_valueCombo->GetTextCtrl() );
67
68 m_labelSingleLine->Show( false );
69 m_valueSingleLine->Show( false );
70 }
71 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
72 {
73 m_activeTextEntry = m_valueSingleLine;
74 SetInitialFocus( m_valueSingleLine );
75
76 m_labelCombo->Show( false );
77 m_valueCombo->Show( false );
78 }
79 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
80 {
81 SetInitialFocus( m_grid );
82 m_delayedFocusRow = 0;
83
84 m_labelSingleLine->Show( false );
85 m_valueSingleLine->Show( false );
86 m_labelCombo->Show( false );
87 m_valueCombo->Show( false );
88 m_syntaxHelp->Show( false );
89 m_textEntrySizer->Show( false );
90 m_labelCombo->Show( false );
91 m_valueCombo->Show( false );
92 m_cbMultiLine->Show( false );
93
94 m_textSizeLabel->SetLabel( _( "Pin length:" ) );
95 }
96
97 if( !aNew )
98 m_cbMultiLine->Show( false );
99
100 // multiline set of labels can be used only to create new labels
101 m_multilineAllowed = aNew && m_cbMultiLine->IsShown();
102
103 switch( m_currentLabel->Type() )
104 {
105 case SCH_GLOBAL_LABEL_T: SetTitle( _( "Global Label Properties" ) ); break;
106 case SCH_HIER_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break;
107 case SCH_LABEL_T: SetTitle( _( "Label Properties" ) ); break;
108 case SCH_DIRECTIVE_LABEL_T: SetTitle( _( "Directive Label Properties" ) ); break;
109 case SCH_SHEET_PIN_T: SetTitle( _( "Hierarchical Sheet Pin Properties" ) ); break;
110 default: UNIMPLEMENTED_FOR( m_currentLabel->GetClass() ); break;
111 }
112
113 m_grid->SetTable( m_fields );
114 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, embeddedFilesStack,
115 [&]( wxCommandEvent& aEvent )
116 {
117 OnAddField( aEvent );
118 } ) );
119 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
120 m_grid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
121 m_shownColumns = m_grid->GetShownColumns();
122
123 // Configure button logos
128
129 m_separator1->SetIsSeparator();
130
131 m_bold->SetIsCheckButton();
133 m_italic->SetIsCheckButton();
135
136 m_separator2->SetIsSeparator();
137
138 m_spin0->SetIsRadioButton();
139 m_spin1->SetIsRadioButton();
140 m_spin2->SetIsRadioButton();
141 m_spin3->SetIsRadioButton();
142
143 m_separator3->SetIsSeparator();
144
145 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
146 m_textColorSwatch->SetSwatchBackground( schematicBackground );
147
148 // Show/hide relevant controls
150 {
151 m_dot->Hide();
152 m_circle->Hide();
153 m_diamond->Hide();
154 m_rectangle->Hide();
155
156 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::label_align_left ) );
157 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::label_align_right ) );
158 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::label_align_bottom ) );
159 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::label_align_top ) );
160 }
161 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
162 {
163 m_input->Hide();
164 m_output->Hide();
165 m_bidirectional->Hide();
166 m_triState->Hide();
167 m_passive->Hide();
168
169 m_fontLabel->SetLabel( _( "Orientation:" ) );
170 m_fontCtrl->Hide();
171 m_separator1->Hide();
172 m_bold->Hide();
173 m_italic->Hide();
174 m_separator2->Hide();
175 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_down ) );
176 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_up ) );
177 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_right ) );
178 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_left ) );
179 m_separator3->Hide();
180
181 m_formattingGB->Detach( m_fontCtrl );
182 m_formattingGB->Detach( m_iconBar );
183 m_formattingGB->Add( m_iconBar, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxEXPAND | wxRIGHT, 5 );
184 }
185 else
186 {
187 m_shapeSizer->Show( false );
188
189 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
190 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
191 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::text_align_bottom ) );
192 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::text_align_top ) );
193 }
194
195 if( !m_currentLabel->AutoRotateOnPlacementSupported() )
196 {
197 m_autoRotate->Hide();
198 wxSizer* parentSizer = m_autoRotate->GetContainingSizer();
199 parentSizer->Detach( m_autoRotate );
200 parentSizer->Layout();
201 }
202
204
205 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
206 // various versions have different controls so we want to store sizes for each version.
207 m_hash_key = TO_UTF8( GetTitle() );
208
209 m_spin0->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
210 m_spin1->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
211 m_spin2->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
212 m_spin3->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
213
214 // wxFormBuilder doesn't include this event...
215 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
216 wxGridEventHandler( DIALOG_LABEL_PROPERTIES::OnGridCellChanging ), nullptr,
217 this );
218
219 // Now all widgets have the size fixed, call FinishDialogSettings
221}
222
223
225{
226 // Prevents crash bug in wxGrid's d'tor
227 m_grid->DestroyTable( m_fields );
228
229 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
230 wxGridEventHandler( DIALOG_LABEL_PROPERTIES::OnGridCellChanging ), nullptr,
231 this );
232
233 // Delete the GRID_TRICKS.
234 m_grid->PopEventHandler( true );
235
236 if( m_helpWindow )
237 m_helpWindow->Destroy();
238}
239
240
242{
243 if( !wxDialog::TransferDataToWindow() )
244 return false;
245
246 // Respond to previously-saved state of multilable checkbox
247 wxCommandEvent dummy;
249
250 wxString text;
251
253 {
254 // show control characters in a human-readable format
255 text = UnescapeString( m_currentLabel->GetText() );
256
257 // show text variable cross-references in a human-readable format
258 text = m_currentLabel->Schematic()->ConvertKIIDsToRefs( text );
259 }
260
261 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
262 {
263 // Load the combobox with the existing labels of the same type
264 std::set<wxString> existingLabels;
265 SCH_SCREENS allScreens( m_Parent->Schematic().Root() );
266
267 for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
268 {
269 for( SCH_ITEM* item : screen->Items().OfType( m_currentLabel->Type() ) )
270 {
271 const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( item );
272 existingLabels.insert( UnescapeString( label->GetText() ) );
273 }
274
275 // Add global power labels from power symbols
276 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T )
277 {
278 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
279 {
280 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
281
282 // Ensure the symbol has the Power (i.e. equivalent to a global label
283 // before adding its value in list
284 if( power->IsSymbolLikePowerGlobalLabel() )
285 {
286 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
287 existingLabels.insert( UnescapeString( valueField->GetText() ) );
288 }
289 }
290 }
291
292 // Add local power labels from power symbols
293 if( m_currentLabel->Type() == SCH_LABEL_T )
294 {
295 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
296 {
297 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
298
299 // Ensure the symbol has the Power (i.e. equivalent to a local label
300 // before adding its value in list
301 if( power->IsSymbolLikePowerLocalLabel() )
302 {
303 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
304 existingLabels.insert( UnescapeString( valueField->GetText() ) );
305 }
306 }
307 }
308 }
309
310 // Add bus aliases to label list
311 for( const std::shared_ptr<BUS_ALIAS>& busAlias : m_Parent->Schematic().GetAllBusAliases() )
312 existingLabels.insert( wxT( "{" ) + busAlias->GetName() + wxT( "}" ) );
313
314 for( const wxString& label : existingLabels )
315 m_existingLabelArray.push_back( label );
316
317 m_valueCombo->SetStringList( m_existingLabelArray );
318 m_valueCombo->SetSelectedString( text );
319 }
320 else if( m_activeTextEntry )
321 {
322 m_activeTextEntry->SetValue( text );
323 }
324
325 // Push a copy of each field into m_updateFields
326 for( SCH_FIELD& field : m_currentLabel->GetFields() )
327 {
328 SCH_FIELD field_copy( field );
329
330 // change offset to be symbol-relative
331 field_copy.Offset( -m_currentLabel->GetPosition() );
332
333 m_fields->push_back( field_copy );
334 }
335
336 // notify the grid
337 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (int) m_fields->size() );
338 m_grid->ProcessTableMessage( msg );
339
340 if( m_shapeSizer->AreAnyItemsShown() )
341 {
342 switch( m_currentLabel->GetShape() )
343 {
344 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
345 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
346 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
347 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
348 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
349 case LABEL_FLAG_SHAPE::F_DOT: m_dot->SetValue( true ); break;
350 case LABEL_FLAG_SHAPE::F_ROUND: m_circle->SetValue( true ); break;
351 case LABEL_FLAG_SHAPE::F_DIAMOND: m_diamond->SetValue( true ); break;
352 case LABEL_FLAG_SHAPE::F_RECTANGLE: m_rectangle->SetValue( true ); break;
353 }
354 }
355
356 m_fontCtrl->SetFontSelection( m_currentLabel->GetFont() );
357
359 m_textSize.SetValue( static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->GetPinLength() );
360 else
361 m_textSize.SetValue( m_currentLabel->GetTextWidth() );
362
363 m_bold->Check( m_currentLabel->IsBold() );
364 m_italic->Check( m_currentLabel->IsItalic() );
365 m_textColorSwatch->SetSwatchColor( m_currentLabel->GetTextColor(), false );
366
367 switch( m_currentLabel->GetSpinStyle() )
368 {
369 case SPIN_STYLE::RIGHT: m_spin0->Check( true ); break;
370 case SPIN_STYLE::LEFT: m_spin1->Check( true ); break;
371 case SPIN_STYLE::UP: m_spin2->Check( true ); break;
372 case SPIN_STYLE::BOTTOM: m_spin3->Check( true ); break;
373 }
374
375 if( m_currentLabel->AutoRotateOnPlacementSupported() )
376 m_autoRotate->SetValue( m_currentLabel->AutoRotateOnPlacement() );
377
378 // Recalculate layout after grid population
379 m_grid->Layout();
380 Layout();
381 GetSizer()->SetSizeHints( this );
382
383 wxSize minSize = GetMinSize();
384 wxSize curSize = GetSize();
385
386 if( curSize.x < minSize.x || curSize.y < minSize.y )
387 SetSize( wxSize( std::max( curSize.x, minSize.x ), std::max( curSize.y, minSize.y ) ) );
388
389 SendSizeEvent( wxSEND_EVENT_POST );
390
391 return true;
392}
393
394
395void DIALOG_LABEL_PROPERTIES::OnEnterKey( wxCommandEvent& aEvent )
396{
397 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
398}
399
400
402{
403 // If the key is WXK_RETURN/WXK_NUMPAD_ENTER because m_valueCombo is the source event, we do not skip
404 // the key event because the default action is to show the m_valueCombo dropdown list,
405 // and we only want to accept the entered string.
406 if(( aEvent.GetKeyCode() == WXK_RETURN ) || (aEvent.GetKeyCode() == WXK_NUMPAD_ENTER))
407 {
408 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
409 }
410 else if( aEvent.GetKeyCode() == WXK_SPACE )
411 {
412 // our FILTER_COMBOBOX uses the space as special command, not wanted here,
413 // to open the dropdown list of labels.
414 // So just add the space char to the current text, at current insertion point,
415 // and do not skip this event
416 m_activeTextEntry->WriteText( wxT(" " ) );
417 }
418 else
419 {
420 aEvent.Skip();
421 }
422}
423
424
426{
427 if( aEvent.GetKeyCode() == WXK_TAB )
428 {
429 if( aEvent.ShiftDown() )
430 {
431 m_textSizeCtrl->SetFocusFromKbd();
432 }
433 else if( !m_fields->empty() )
434 {
435 m_grid->SetFocusFromKbd();
436 m_grid->MakeCellVisible( 0, 0 );
437 m_grid->SetGridCursor( 0, 0 );
438 }
439 else
440 {
441 m_textSizeCtrl->SetFocusFromKbd();
442 }
443 }
444 else
445 {
446 aEvent.Skip();
447 }
448}
449
450
451static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
452{
453 return a.GetPosition() != b.GetPosition()
454 || a.GetHorizJustify() != b.GetHorizJustify()
455 || a.GetVertJustify() != b.GetVertJustify()
456 || a.GetTextAngle() != b.GetTextAngle();
457}
458
459
460static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
461{
462 for( size_t i = 0; i < a->size() && i < b.size(); ++i )
463 {
464 if( positioningChanged( a->at( i ), b.at( i ) ) )
465 return true;
466 }
467
468 return false;
469}
470
471
473{
474 if( !m_grid->CommitPendingChanges() )
475 return false;
476
477 if( !wxDialog::TransferDataFromWindow() )
478 return false;
479
480 // Don't allow text to disappear; it can be difficult to correct if you can't select it
481 if( !m_textSize.Validate( 0.01, 1000.0, EDA_UNITS::MM ) )
482 return false;
483
484 wxString text;
485
487 {
488 // labels need escaping
490
491 // convert any text variable cross-references to their UUIDs
492 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
493
494#ifdef __WXMAC__
495 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
496 text.Replace( wxS( "\r" ), wxS( "\n" ) );
497#endif
498
499 wxString visibleText = text;
500 visibleText.Trim( false ).Trim( true );
501
502 if( visibleText.IsEmpty() )
503 {
504 DisplayError( this, _( "Label can not be empty." ) );
505 return false;
506 }
507 }
508
509 // Stage only after validation, because a staged commit that is never pushed leaves the
510 // connectivity revision ahead of the published rows
511 SCH_COMMIT commit( m_Parent );
512
513 /* save old text in undo list if not already in edit */
514 if( m_currentLabel->GetEditFlags() == 0 )
515 commit.Modify( m_currentLabel, m_Parent->GetScreen() );
516
517 m_Parent->GetCanvas()->Refresh();
518
520 m_currentLabel->SetText( text );
521
522 // change all field positions from relative to absolute
523 for( SCH_FIELD& field : *m_fields )
524 {
525 field.Offset( m_currentLabel->GetPosition() );
526
527 if( field.GetUntranslatedName() == wxT( "Netclass" ) )
528 {
529 field.SetLayer( LAYER_NETCLASS_REFS );
530 }
531 else if( field.GetId() == FIELD_T::INTERSHEET_REFS )
532 {
533 if( field.IsVisible() != m_Parent->Schematic().Settings().m_IntersheetRefsShow )
534 {
535 DisplayInfoMessage( this, _( "Intersheet reference visibility is controlled globally from "
536 "Schematic Setup > General > Formatting" ) );
537 }
538
539 field.SetLayer( LAYER_INTERSHEET_REFS );
540 }
541 else
542 {
543 field.SetLayer( LAYER_FIELDS );
544 }
545 }
546
547 if( positioningChanged( m_fields, m_currentLabel->GetFields() ) )
548 m_currentLabel->SetFieldsAutoplaced( AUTOPLACE_NONE );
549
550 for( int ii = m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
551 {
552 SCH_FIELD& field = m_fields->at( ii );
553 const wxString& fieldName = field.GetUntranslatedName();
554 const wxString& fieldText = field.GetText();
555
556 if( fieldName.IsEmpty() && fieldText.IsEmpty() )
557 {
558 // delete empty, unnamed fields
559 m_fields->erase( m_fields->begin() + ii );
560 }
561 else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() )
562 {
563 // delete empty Netclass fields if there are other Netclass fields present
564 int netclassFieldCount = 0;
565
566 for( int jj = 0; jj < m_fields->GetNumberRows(); ++jj )
567 {
568 if( m_fields->at( jj ).GetUntranslatedName() == wxT( "Netclass" ) )
569 netclassFieldCount++;
570 }
571
572 if( netclassFieldCount > 1 )
573 m_fields->erase( m_fields->begin() + ii );
574 }
575 else if( fieldName.IsEmpty() )
576 {
577 // give non-empty, unnamed fields a name
578 field.SetName( _( "untitled" ) );
579 }
580 }
581
582 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
583
584 for( SCH_FIELD& field : *m_fields )
585 {
586 if( !field.IsMandatory() )
587 field.SetOrdinal( ordinal++, FIELD_T::USER );
588 }
589
590 m_currentLabel->SetFields( *m_fields );
591
592 if( m_shapeSizer->AreAnyItemsShown() )
593 {
594 if( m_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
595 else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
596 else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
597 else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
598 else if( m_passive->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
599 else if( m_dot->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT );
600 else if( m_circle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
601 else if( m_diamond->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND );
602 else if( m_rectangle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE );
603 }
604
605 if( m_fontCtrl->HaveFontSelection() )
606 m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
607
609 static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() );
610 else if( m_currentLabel->GetTextWidth() != m_textSize.GetIntValue() )
611 m_currentLabel->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
612
613 // Must come after SetTextSize()
614 m_currentLabel->SetBold( m_bold->IsChecked() );
615 m_currentLabel->SetItalic( m_italic->IsChecked() );
616
617 m_currentLabel->SetTextColor( m_textColorSwatch->GetSwatchColor() );
618
619 SPIN_STYLE selectedSpinStyle= SPIN_STYLE::LEFT;
620
621 if( m_spin0->IsChecked() ) selectedSpinStyle = SPIN_STYLE::RIGHT;
622 else if( m_spin1->IsChecked() ) selectedSpinStyle = SPIN_STYLE::LEFT;
623 else if( m_spin2->IsChecked() ) selectedSpinStyle = SPIN_STYLE::UP;
624 else if( m_spin3->IsChecked() ) selectedSpinStyle = SPIN_STYLE::BOTTOM;
625
626 if( m_currentLabel->AutoRotateOnPlacementSupported() )
627 {
628 SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_parentFrame );
629 m_currentLabel->SetAutoRotateOnPlacement( m_autoRotate->IsChecked() );
630 frame->AutoRotateItem( frame->GetScreen(), m_currentLabel );
631 }
632 else
633 {
634 m_currentLabel->SetAutoRotateOnPlacement( false );
635 }
636
637 if( !m_currentLabel->AutoRotateOnPlacement() && m_currentLabel->GetSpinStyle() != selectedSpinStyle )
638 m_currentLabel->SetSpinStyle( selectedSpinStyle );
639
640 AUTOPLACE_ALGO fieldsAutoplaced = m_currentLabel->GetFieldsAutoplaced();
641
642 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
643 m_currentLabel->AutoplaceFields( m_Parent->GetScreen(), fieldsAutoplaced );
644
645 if( !commit.Empty() )
646 {
647 commit.Push( _( "Edit Label Properties" ) );
648 }
649 else if( m_activeTextEntry && m_labelList )
650 {
651 text = m_activeTextEntry->GetValue();
652 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
653 text.Replace( wxS( "\r" ), wxS( "\n" ) );
654 wxArrayString lines = wxSplit( text, '\n' );
655
656 for( const wxString& line : lines )
657 {
658 text = EscapeString( line, CTX_NETNAME );
659 text.Trim( false ).Trim( true );
660
661 if( text.empty() )
662 continue;
663
664 // convert any text variable cross-references to their UUIDs
665 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
666
667 switch ( m_currentLabel->Type() )
668 {
670 {
671 SCH_GLOBALLABEL* label = new SCH_GLOBALLABEL( *static_cast<SCH_GLOBALLABEL*>( m_currentLabel ) );
672 const_cast<KIID&>( label->m_Uuid ) = KIID(); // Gives a new UUID to the copy
673 label->SetText( text );
674 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
675 break;
676 }
677 case SCH_HIER_LABEL_T:
678 {
679 SCH_HIERLABEL* label = new SCH_HIERLABEL( *static_cast<SCH_HIERLABEL*>( m_currentLabel ) );
680 const_cast<KIID&>( label->m_Uuid ) = KIID();
681 label->SetText( text );
682 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
683 break;
684 }
685 case SCH_LABEL_T:
686 {
687 SCH_LABEL* label = new SCH_LABEL( *static_cast<SCH_LABEL*>( m_currentLabel ) );
688 const_cast<KIID&>( label->m_Uuid ) = KIID();
689 label->SetText( text );
690 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
691 break;
692 }
693 default:
694 break;
695 }
696 }
697 }
698 else if( m_labelList && m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
699 {
701 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
702 }
703
704 return true;
705}
706
707
708void DIALOG_LABEL_PROPERTIES::onSpinButton( wxCommandEvent& aEvent )
709{
710 for( BITMAP_BUTTON* btn : { m_spin0, m_spin1, m_spin2, m_spin3 } )
711 {
712 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
713 btn->Check( false );
714 }
715}
716
717
718void DIALOG_LABEL_PROPERTIES::OnFormattingHelp( wxHyperlinkEvent& aEvent )
719{
721}
722
723
725{
726 wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
727 wxControl* control = editor->GetControl();
728
729 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
730 {
731 event.Veto();
732 m_delayedFocusRow = event.GetRow();
733 m_delayedFocusColumn = event.GetCol();
734 }
735 else if( event.GetCol() == FDC_NAME )
736 {
737 wxString newName = event.GetString();
738 bool isGlobalLabel = m_currentLabel->Type() == SCH_GLOBAL_LABEL_T;
739
740 for( int i = 0; i < m_grid->GetNumberRows(); ++i )
741 {
742 if( i == event.GetRow() )
743 continue;
744
745 wxString existing = m_grid->GetCellValue( i, FDC_NAME );
746
747 // Only global labels have a mandatory field (Intersheet References). Hierarchical,
748 // regular, and directive labels carry only user fields, which compare case-sensitively.
749 bool duplicate = isGlobalLabel
751 : FieldNamesAreDuplicates( newName, existing, {} );
752
753 if( duplicate )
754 {
755 DisplayError( this, wxString::Format( _( "Field name '%s' already in use." ),
756 newName ) );
757 event.Veto();
758 m_delayedFocusRow = event.GetRow();
759 m_delayedFocusColumn = event.GetCol();
760 break;
761 }
762 }
763 }
764
765 editor->DecRef();
766}
767
768
769void DIALOG_LABEL_PROPERTIES::OnAddField( wxCommandEvent& event )
770{
771 m_grid->OnAddRow(
772 [&]() -> std::pair<int, int>
773 {
774 wxString fieldName = wxT( "Netclass" );
775
776 for( SCH_FIELD& field : *m_fields )
777 {
778 if( field.GetId() != FIELD_T::INTERSHEET_REFS && field.GetName() != wxT( "Netclass" ) )
779 {
780 fieldName = wxEmptyString;
781 break;
782 }
783 }
784
785 fieldName = SCH_LABEL_BASE::GetDefaultFieldName( fieldName, true );
786
787 SCH_FIELD newField( m_currentLabel, FIELD_T::USER, fieldName );
788
789 if( m_fields->size() > 0 )
790 {
791 // SetAttributes() also covers text angle, size, italic and bold
792 newField.SetAttributes( m_fields->at( m_fields->size() - 1 ) );
793 newField.SetVisible( m_fields->at( m_fields->size() - 1 ).IsVisible() );
794 }
795 else
796 {
797 newField.SetVisible( true );
798 newField.SetItalic( true );
799 }
800
801 m_fields->push_back( newField );
802
803 // notify the grid
804 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
805 m_grid->ProcessTableMessage( msg );
806 return { m_fields->GetNumberRows() - 1, FDC_NAME };
807 } );
808}
809
810
811void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
812{
813 m_grid->OnDeleteRows(
814 [&]( int row )
815 {
816 if( row < m_fields->GetMandatoryRowCount() )
817 {
818 DisplayError( this, _( "The first field is mandatory." ) );
819 return false;
820 }
821
822 return true;
823 },
824 [&]( int row )
825 {
826 if( !m_fields->EraseRow( row ) )
827 return;
828
829 // notify the grid
830 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
831 m_grid->ProcessTableMessage( msg );
832 } );
833}
834
835
836void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
837{
838 m_grid->OnMoveRowUp(
839 [&]( int row )
840 {
841 return row > m_fields->GetMandatoryRowCount();
842 },
843 [&]( int row )
844 {
845 m_fields->SwapRows( row, row - 1 );
846 m_grid->ForceRefresh();
847 } );
848}
849
850
851void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
852{
853 m_grid->OnMoveRowDown(
854 [&]( int row )
855 {
856 return row >= m_fields->GetMandatoryRowCount();
857 },
858 [&]( int row )
859 {
860 m_fields->SwapRows( row, row + 1 );
861 m_grid->ForceRefresh();
862 } );
863}
864
865
866void DIALOG_LABEL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
867{
868 std::bitset<64> shownColumns = m_grid->GetShownColumns();
869
870 if( shownColumns != m_shownColumns )
871 {
872 m_shownColumns = shownColumns;
873
874 if( !m_grid->IsCellEditControlShown() )
875 m_grid->SetGridWidthsDirty();
876 }
877
878 // Handle a delayed focus
879 if( m_delayedFocusRow >= 0 && m_delayedFocusRow < m_grid->GetNumberRows() )
880 {
881 m_grid->SetFocus();
882 m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
884 }
885
888}
889
890
892{
893 bool multiLine = m_multilineAllowed && m_cbMultiLine->IsChecked();
894
895 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
896 {
897 m_labelCombo->Show( !multiLine );
898 m_valueCombo->Show( !multiLine );
899 m_labelMultiLine->Show( multiLine );
900 m_valueMultiLine->Show( multiLine );
901
902 if( multiLine )
903 {
904 m_valueMultiLine->SetValue( m_valueCombo->GetValue() );
907 }
908 else
909 {
910 wxString multiText = m_valueMultiLine->GetValue();
911 m_valueCombo->SetValue( multiText.BeforeFirst( '\n' ) );
913 SetInitialFocus( m_valueCombo->GetTextCtrl() );
914 }
915 }
916 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
917 {
918 m_labelSingleLine->Show( !multiLine );
919 m_valueSingleLine->Show( !multiLine );
920 m_labelMultiLine->Show( multiLine );
921 m_valueMultiLine->Show( multiLine );
922
923 if( multiLine )
924 {
925 m_valueMultiLine->SetValue( m_valueSingleLine->GetValue() );
928 }
929 else
930 {
931 wxString multiText = m_valueMultiLine->GetValue();
932 m_valueSingleLine->SetValue( multiText.BeforeFirst( '\n' ) );
935 }
936 }
937
938 Layout();
939}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
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:145
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:102
DIALOG_LABEL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Label Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
std::list< std::unique_ptr< SCH_LABEL_BASE > > * m_labelList
void OnMoveUp(wxCommandEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
DIALOG_LABEL_PROPERTIES(SCH_EDIT_FRAME *parent, SCH_LABEL_BASE *aLabel, bool aNew)
void OnEnterKey(wxCommandEvent &aEvent) override
wxEVT_COMMAND_ENTER event handler for single-line control.
void OnAddField(wxCommandEvent &event) override
SCH_NETNAME_VALIDATOR m_netNameValidator
void OnFormattingHelp(wxHyperlinkEvent &aEvent) override
void OnCBValueCharHook(wxKeyEvent &aEvent) override
void OnUpdateUI(wxUpdateUIEvent &event) override
void onSpinButton(wxCommandEvent &aEvent)
void onMultiLabelCheck(wxCommandEvent &aEvent) override
void OnDeleteField(wxCommandEvent &event) override
void OnGridCellChanging(wxGridEvent &event)
void OnValueCharHook(wxKeyEvent &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:94
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...
EDA_BASE_FRAME * m_parentFrame
const KIID m_Uuid
Definition eda_item.h:599
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:394
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:575
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:347
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:236
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:290
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Definition kiid.h:46
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void AutoRotateItem(SCH_SCREEN *aScreen, SCH_ITEM *aItem)
Automatically set the rotation of an item (if the item supports it).
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
void SetName(const wxString &aName)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:818
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:73
bool IsSymbolLikePowerGlobalLabel() const
bool IsSymbolLikePowerLocalLabel() const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Spin style for labels of all kinds on schematics.
Definition sch_label.h:38
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:245
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
@ FDC_NAME
@ FDC_VALUE
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition idf_helpers.h:37
@ LAYER_FIELDS
Definition layer_ids.h:484
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:486
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:510
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:485
AUTOPLACE_ALGO
Definition sch_item.h:73
@ AUTOPLACE_MANUAL
Definition sch_item.h:76
@ AUTOPLACE_NONE
Definition sch_item.h:74
@ AUTOPLACE_AUTO
Definition sch_item.h:75
@ L_BIDI
Definition sch_label.h:100
@ L_TRISTATE
Definition sch_label.h:101
@ L_UNSPECIFIED
Definition sch_label.h:102
@ F_DOT
Definition sch_label.h:105
@ F_ROUND
Definition sch_label.h:106
@ L_OUTPUT
Definition sch_label.h:99
@ F_DIAMOND
Definition sch_label.h:107
@ L_INPUT
Definition sch_label.h:98
@ F_RECTANGLE
Definition sch_label.h:108
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
@ USER
The field ID hasn't been set yet; field is invalid.
@ INTERSHEET_REFS
Global label cross-reference page numbers.
@ VALUE
Field Value of part, i.e. "3.3K".
#define GLOBALLABEL_MANDATORY_FIELDS
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_SYMBOL_LOCATE_POWER_T
Definition typeinfo.h:192
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708