KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_netclasses.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) 2004-2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009 Dick Hollenbeck, [email protected]
6 * Copyright (C) 2009-2023 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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <algorithm>
27
28#include <pgm_base.h>
29#include <eda_draw_frame.h>
30#include <bitmaps.h>
31#include <netclass.h>
32#include <confirm.h>
33#include <grid_tricks.h>
35#include <tool/tool_manager.h>
36#include <string_utils.h>
40#include <widgets/wx_panel.h>
43
44
45// columns of netclasses grid
46enum {
48
58
64
66};
67
68std::vector<BITMAPS> g_lineStyleIcons;
69wxArrayString g_lineStyleNames;
70
71
73 std::shared_ptr<NET_SETTINGS> aNetSettings,
74 const std::set<wxString>& aNetNames,
75 bool aIsEEschema ) :
76 PANEL_SETUP_NETCLASSES_BASE( aParentWindow ),
77 m_frame( aFrame ),
78 m_isEEschema( aIsEEschema ),
79 m_netSettings( aNetSettings ),
80 m_netNames( aNetNames ),
81 m_lastCheckedTicker( 0 ),
82 m_hoveredCol( -1 ),
83 m_lastNetclassGridWidth( -1 )
84{
85 // Clear and re-load each time. Language (or darkmode) might have changed.
86 g_lineStyleIcons.clear();
87 g_lineStyleNames.clear();
88
89 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
90 g_lineStyleNames.push_back( _( "Solid" ) );
91 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
92 g_lineStyleNames.push_back( _( "Dashed" ) );
93 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
94 g_lineStyleNames.push_back( _( "Dotted" ) );
95 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
96 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
97 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
98 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
99
100 m_netclassesDirty = true;
101
102 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
103 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
104
105 m_netclassesPane->SetBorders( true, false, false, false );
106 m_membershipPane->SetBorders( true, false, false, false );
107
108 // Prevent Size events from firing before we are ready
109 Freeze();
110 m_netclassGrid->BeginBatch();
111 m_assignmentGrid->BeginBatch();
112
113 m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
114 // Calculate a min best size to handle longest usual numeric values:
115 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
116
117 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
118 {
119 // We calculate the column min size only from texts sizes, not using the initial col width
120 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
121 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
122
123 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
124 : min_best_width;
125
126 m_netclassGrid->SetColMinimalWidth( i, min_width );
127
128 // We use a "best size" >= min_best_width
129 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
130 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
131 }
132
133 for( int i = GRID_FIRST_PCBNEW; i < GRID_END; ++i )
134 {
135 if( i >= GRID_FIRST_EESCHEMA )
136 {
138
139 if( !m_isEEschema )
140 {
141 m_netclassGrid->HideCol( i );
142 m_originalColWidths[ i ] = 0;
143 }
144 }
145 else
146 {
148
149 if( m_isEEschema )
150 {
151 m_netclassGrid->HideCol( i );
152 m_originalColWidths[ i ] = 0;
153 }
154 }
155 }
156
157 wxGridCellAttr* attr = new wxGridCellAttr;
158 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
159 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) );
160 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
161
162 attr = new wxGridCellAttr;
165 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
166
167 if( m_isEEschema )
168 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
169 else
171
182
183
184 // Be sure the column labels are readable
186
187 // Membership combobox editors require a bit more room, so increase the row size of
188 // all our grids for consistency
189 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
190 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
191
192 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
193 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
194
195 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
196 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
197
198 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
199 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
200
201 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
202 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
203
204 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
205 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
206
207 // wxFormBuilder doesn't include this event...
208 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
210 nullptr, this );
211
212 // Handle tooltips for grid
213 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
215 this );
216
217 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
218
219 m_netclassGrid->EndBatch();
220 m_assignmentGrid->EndBatch();
221 Thaw();
222
223 Bind( wxEVT_IDLE,
224 [this]( wxIdleEvent& aEvent )
225 {
226 // Careful of consuming CPU in an idle event handler. Check the ticker first to
227 // see if there's even a possibility of the netclasses having changed.
229 {
230 wxWindow* dialog = wxGetTopLevelParent( this );
231 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
232
233 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->m_NetClasses )
234 checkReload();
235 }
236 } );
237
238 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
239}
240
241
243{
244 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
245 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
246
247 delete [] m_originalColWidths;
248
249 // Delete the GRID_TRICKS.
250 m_netclassGrid->PopEventHandler( true );
251 m_assignmentGrid->PopEventHandler( true );
252
253 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
255 nullptr, this );
256
257 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
258}
259
260
262{
263 int row = 0;
264
265 auto netclassToGridRow =
266 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
267 {
268 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
269
270 m_netclassGrid->SetUnitValue( aRow, GRID_WIREWIDTH, nc->GetWireWidth() );
271 m_netclassGrid->SetUnitValue( aRow, GRID_BUSWIDTH, nc->GetBusWidth() );
272
273 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
274 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
275
276 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
277
278 if( lineStyleIdx >= (int) g_lineStyleNames.size() )
279 lineStyleIdx = 0;
280
281 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE,
282 g_lineStyleNames[ lineStyleIdx ] );
283 m_netclassGrid->SetUnitValue( aRow, GRID_CLEARANCE, nc->GetClearance() );
284 m_netclassGrid->SetUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidth() );
285 m_netclassGrid->SetUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameter() );
286 m_netclassGrid->SetUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrill() );
287 m_netclassGrid->SetUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameter() );
288 m_netclassGrid->SetUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrill() );
289 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
290 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
291 };
292
294
295 // enter the Default NETCLASS.
296 m_netclassGrid->AppendRows( 1 );
297 netclassToGridRow( row++, m_netSettings->m_DefaultNetClass );
298
299 // make the Default NETCLASS name read-only
300 wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
301 cellAttr->SetReadOnly();
302 cellAttr->DecRef();
303
304 // enter other netclasses
305 m_netclassGrid->AppendRows( (int) m_netSettings->m_NetClasses.size() );
306
307 for( const auto& [ name, netclass ] : m_netSettings->m_NetClasses )
308 netclassToGridRow( row++, netclass );
309
311 m_assignmentGrid->AppendRows( m_netSettings->m_NetClassPatternAssignments.size() );
312 row = 0;
313
314 for( const auto& [ matcher, netclassName ] : m_netSettings->m_NetClassPatternAssignments )
315 {
316 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
317 m_assignmentGrid->SetCellValue( row, 1, netclassName );
318 row++;
319 }
320}
321
322
324{
325 // MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
326 // event until we crash the stack).
328
329 if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
330 "Do you wish to reload them?" ) ) )
331 {
332 m_lastLoaded = m_netSettings->m_NetClasses;
334 }
335}
336
337
338void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
339{
340 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
341 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
342
343 m_netSettings = tempNetSettings;
344
346
347 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
348 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
349
351
352 m_netSettings = saveNetSettings;
353
354 aEvent.Skip();
355}
356
357
359{
360 m_lastLoaded = m_netSettings->m_NetClasses;
362
364 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
365
366 return true;
367}
368
369
371{
373
374 wxArrayString netclassNames;
375
376 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
377 {
378 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
379
380 if( !netclassName.IsEmpty() )
381 netclassNames.push_back( netclassName );
382 }
383
384 wxGridCellAttr* attr = new wxGridCellAttr;
385 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
386 m_assignmentGrid->SetColAttr( 1, attr );
387}
388
389
391{
392 if( !Validate() )
393 return false;
394
395 int row = 0;
396
397 auto gridRowToNetclass =
398 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
399 {
400 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
401
402 nc->SetWireWidth( m_netclassGrid->GetUnitValue( aRow, GRID_WIREWIDTH ) );
403 nc->SetBusWidth( m_netclassGrid->GetUnitValue( aRow, GRID_BUSWIDTH ) );
404
405 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
406 nc->SetSchematicColor( wxColour( color ) );
407
408 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
409 nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
410 wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
411
412 nc->SetClearance( m_netclassGrid->GetUnitValue( aRow, GRID_CLEARANCE ) );
413 nc->SetTrackWidth( m_netclassGrid->GetUnitValue( aRow, GRID_TRACKSIZE ) );
414 nc->SetViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_VIASIZE ) );
415 nc->SetViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_VIADRILL ) );
416 nc->SetuViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_uVIASIZE ) );
417 nc->SetuViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_uVIADRILL ) );
418 nc->SetDiffPairWidth( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
419 nc->SetDiffPairGap( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
420 };
421
422 m_netSettings->m_NetClasses.clear();
423
424 // Copy the default NetClass:
425 gridRowToNetclass( row++, m_netSettings->m_DefaultNetClass );
426
427 // Copy other NetClasses:
428 for( row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
429 {
430 auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
431 gridRowToNetclass( row, nc );
432 m_netSettings->m_NetClasses[ nc->GetName() ] = nc;
433 }
434
435 m_netSettings->m_NetClassPatternAssignments.clear();
436
437 for( row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
438 {
439 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
440 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
441
442 m_netSettings->m_NetClassPatternAssignments.push_back(
443 {
444 std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ),
445 netclass
446 } );
447
448 m_netSettings->m_NetClassPatternAssignmentCache.clear();
449 }
450
451 return true;
452}
453
454
455bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
456 bool focusFirst )
457{
458 wxString tmp = aName;
459
460 tmp.Trim( true );
461 tmp.Trim( false );
462
463 if( tmp.IsEmpty() )
464 {
465 wxString msg = _( "Netclass must have a name." );
466 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
467 return false;
468 }
469
470 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
471 {
472 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
473 {
474 wxString msg = _( "Netclass name already in use." );
476 focusFirst ? aRow : ii, GRID_NAME );
477 return false;
478 }
479 }
480
481 return true;
482}
483
484
486{
487 if( event.GetCol() == GRID_NAME )
488 {
489 if( validateNetclassName( event.GetRow(), event.GetString() ) )
490 {
491 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
492 wxString newName = event.GetString();
493
494 if( !oldName.IsEmpty() )
495 {
496 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
497 {
498 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
499 m_assignmentGrid->SetCellValue( row, 1, newName );
500 }
501 }
502
503 m_netclassesDirty = true;
504 }
505 else
506 {
507 event.Veto();
508 }
509 }
510}
511
512
514{
515 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
516
517 if( aEvent.Moving() || aEvent.Entering() )
518 {
519 aEvent.Skip();
520
521 if( col == wxNOT_FOUND )
522 {
523 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
524 return;
525 }
526
527 if( col == m_hoveredCol )
528 return;
529
530 m_hoveredCol = col;
531
532 wxString tip;
533
534 switch( col )
535 {
536 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
537 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
538 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
539 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
540 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
541 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
542 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
543 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
544 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
545 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
546 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
547 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
548 }
549
550 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
551 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
552 }
553 else if( aEvent.Leaving() )
554 {
555 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
556 aEvent.Skip();
557 }
558
559 aEvent.Skip();
560}
561
562
564{
566 return;
567
568 int row = m_netclassGrid->GetNumberRows();
569 m_netclassGrid->AppendRows();
570
571 // Copy values of the default class:
572 for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
573 m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
574
575 m_netclassGrid->MakeCellVisible( row, 0 );
576 m_netclassGrid->SetGridCursor( row, 0 );
577
578 m_netclassGrid->EnableCellEditControl( true );
579 m_netclassGrid->ShowCellEditControl();
580
581 m_netclassesDirty = true;
582}
583
584
586{
588 return;
589
590 int curRow = m_netclassGrid->GetGridCursorRow();
591
592 if( curRow < 0 )
593 {
594 return;
595 }
596 else if( curRow == 0 )
597 {
598 DisplayErrorMessage( this, _( "The default net class is required." ) );
599 return;
600 }
601
602 // reset the net class to default for members of the removed class
603 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
604
605 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
606 {
607 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
608 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
609 }
610
611 m_netclassGrid->DeleteRows( curRow, 1 );
612
613 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
614 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
615
616 m_netclassesDirty = true;
617}
618
619
621{
622 if( aWidth != m_lastNetclassGridWidth )
623 {
625
626 // Account for scroll bars
627 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
628
629 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
630 {
631 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
632 aWidth -= m_originalColWidths[ i ];
633 }
634
635 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
636 }
637}
638
639
641{
642 AdjustNetclassGridColumns( event.GetSize().GetX() );
643
644 event.Skip();
645}
646
647
649{
651 return;
652
653 int row = m_assignmentGrid->GetNumberRows();
654 m_assignmentGrid->AppendRows();
655
656 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->m_DefaultNetClass->GetName() );
657
658 m_assignmentGrid->MakeCellVisible( row, 0 );
659 m_assignmentGrid->SetGridCursor( row, 0 );
660
661 m_assignmentGrid->EnableCellEditControl( true );
662 m_assignmentGrid->ShowCellEditControl();
663}
664
665
667{
669 return;
670
671 int curRow = m_assignmentGrid->GetGridCursorRow();
672
673 if( curRow < 0 )
674 return;
675
676 m_assignmentGrid->DeleteRows( curRow, 1 );
677
678 if( m_assignmentGrid->GetNumberRows() > 0 )
679 {
680 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
681 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
682 }
683}
684
685
687{
688 // Account for scroll bars
689 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
690
691 int classNameWidth = 160;
692 m_assignmentGrid->SetColSize( 1, classNameWidth );
693 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
694}
695
696
698{
699 AdjustAssignmentGridColumns( event.GetSize().GetX() );
700
701 event.Skip();
702}
703
704
705void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
706{
708 {
710 m_netclassesDirty = false;
711 }
712
713 if( m_assignmentGrid->GetNumberRows() == 0 )
714 return;
715
716 wxString pattern;
717 int row = m_assignmentGrid->GetGridCursorRow();
718 int col = m_assignmentGrid->GetGridCursorCol();
719
720 if( row >= 0 )
721 pattern = m_assignmentGrid->GetCellValue( row, 0 );
722
723 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
724 {
725 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
726
727 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
728 pattern = txt->GetValue();
729
730 cellEditor->DecRef();
731 }
732
733 if( pattern != m_lastPattern )
734 {
736
737 if( !pattern.IsEmpty() )
738 {
739 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
740
741 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
742 pattern ) );
743
744 for( const wxString& net : m_netNames )
745 {
746 if( matcher.StartsWith( net ) )
747 m_matchingNets->Report( net );
748 }
749 }
750
752 m_lastPattern = pattern;
753 }
754}
755
756
758{
760 return false;
761
762 wxString msg;
763
764 // Test net class parameters.
765 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
766 {
767 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
768 netclassName.Trim( true );
769 netclassName.Trim( false );
770
771 if( !validateNetclassName( row, netclassName, false ) )
772 return false;
773 }
774
775 return true;
776}
777
778
779void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
780{
781 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
782
783 m_netSettings = aNetSettings;
785
787
788 m_netclassGrid->ForceRefresh();
789 m_assignmentGrid->ForceRefresh();
790
791 m_netSettings = savedSettings;
792}
793
794
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
NETCLASS_PANEL m_NetclassPanel
bool StartsWith(const wxString &aTerm)
The base class for create windows for drawing purpose.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:49
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
Class PANEL_SETUP_NETCLASSES_BASE.
void OnUpdateUI(wxUpdateUIEvent &event) override
void OnSizeAssignmentGrid(wxSizeEvent &event) override
PANEL_SETUP_NETCLASSES(wxWindow *aParentWindow, EDA_DRAW_FRAME *aFrame, std::shared_ptr< NET_SETTINGS > aSettings, const std::set< wxString > &aNetNames, bool isEEschema)
void OnRemoveNetclassClick(wxCommandEvent &event) override
void OnRemoveAssignmentClick(wxCommandEvent &event) override
std::map< wxString, std::shared_ptr< NETCLASS > > m_lastLoaded
void ImportSettingsFrom(const std::shared_ptr< NET_SETTINGS > &aNetSettings)
void onUnitsChanged(wxCommandEvent &aEvent)
void OnNetclassGridCellChanging(wxGridEvent &event)
bool validateNetclassName(int aRow, const wxString &aName, bool focusFirst=true)
std::unique_ptr< UNITS_PROVIDER > m_pcbUnitsProvider
void OnNetclassGridMouseEvent(wxMouseEvent &event)
void OnAddAssignmentClick(wxCommandEvent &event) override
void AdjustAssignmentGridColumns(int aWidth)
std::set< wxString > m_netNames
void OnAddNetclassClick(wxCommandEvent &event) override
std::unique_ptr< UNITS_PROVIDER > m_schUnitsProvider
void OnSizeNetclassGrid(wxSizeEvent &event) override
void AdjustNetclassGridColumns(int aWidth)
std::shared_ptr< NET_SETTINGS > m_netSettings
int GetNetclassesTicker() const
Definition: project.h:97
int GetTextVarsTicker() const
Definition: project.h:94
void SetBitmap(const wxBitmapBundle &aBmp)
EDA_UNITS GetUserUnits() const
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:545
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:527
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:506
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:585
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:104
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:497
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:147
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:448
void Clear()
Delete the stored messages.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:39
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
This file is part of the common library.
#define _(s)
@ CTX_NETCLASS
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
@ GRID_FIRST_PCBNEW
@ GRID_DIFF_PAIR_GAP
@ GRID_SCHEMATIC_COLOR
@ GRID_DIFF_PAIR_WIDTH
@ GRID_FIRST_EESCHEMA
std::vector< BITMAPS > g_lineStyleIcons
wxArrayString g_lineStyleNames
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119