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_hoveredCol( -1 ),
82 m_lastNetclassGridWidth( -1 )
83{
84 // Clear and re-load each time. Language (or darkmode) might have changed.
85 g_lineStyleIcons.clear();
86 g_lineStyleNames.clear();
87
88 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
89 g_lineStyleNames.push_back( _( "Solid" ) );
90 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
91 g_lineStyleNames.push_back( _( "Dashed" ) );
92 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
93 g_lineStyleNames.push_back( _( "Dotted" ) );
94 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
95 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
96 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
97 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
98
99 m_netclassesDirty = true;
100
101 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
102 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
103
104 m_netclassesPane->SetBorders( true, false, false, false );
105 m_membershipPane->SetBorders( true, false, false, false );
106
107 // Prevent Size events from firing before we are ready
108 Freeze();
109 m_netclassGrid->BeginBatch();
110 m_assignmentGrid->BeginBatch();
111
112 m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
113 // Calculate a min best size to handle longest usual numeric values:
114 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
115
116 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
117 {
118 // We calculate the column min size only from texts sizes, not using the initial col width
119 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
120 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
121
122 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
123 : min_best_width;
124
125 m_netclassGrid->SetColMinimalWidth( i, min_width );
126
127 // We use a "best size" >= min_best_width
128 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
129 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
130 }
131
132 for( int i = GRID_FIRST_PCBNEW; i < GRID_END; ++i )
133 {
134 if( i >= GRID_FIRST_EESCHEMA )
135 {
137
138 if( !m_isEEschema )
139 {
140 m_netclassGrid->HideCol( i );
141 m_originalColWidths[ i ] = 0;
142 }
143 }
144 else
145 {
147
148 if( m_isEEschema )
149 {
150 m_netclassGrid->HideCol( i );
151 m_originalColWidths[ i ] = 0;
152 }
153 }
154 }
155
156 wxGridCellAttr* attr = new wxGridCellAttr;
157 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
158 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) );
159 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
160
161 attr = new wxGridCellAttr;
164 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
165
166 if( m_isEEschema )
167 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
168 else
170
181
182
183 // Be sure the column labels are readable
185
186 // Membership combobox editors require a bit more room, so increase the row size of
187 // all our grids for consistency
188 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
189 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
190
191 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
192 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
193
194 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
195 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
196
197 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
198 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
199
200 m_addButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
201 m_removeButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
202
203 m_addAssignmentButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
204 m_removeAssignmentButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
205
206 // wxFormBuilder doesn't include this event...
207 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
209 nullptr, this );
210
211 // Handle tooltips for grid
212 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
214 this );
215
216 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
217
218 m_netclassGrid->EndBatch();
219 m_assignmentGrid->EndBatch();
220 Thaw();
221
222 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
223}
224
225
227{
228 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
229 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
230
231 delete [] m_originalColWidths;
232
233 // Delete the GRID_TRICKS.
234 m_netclassGrid->PopEventHandler( true );
235 m_assignmentGrid->PopEventHandler( true );
236
237 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
239 nullptr, this );
240
241 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
242}
243
244
245void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
246{
247 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
248 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
249
250 m_netSettings = tempNetSettings;
251
253
254 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
255 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
256
258
259 m_netSettings = saveNetSettings;
260
261 aEvent.Skip();
262}
263
264
266{
267 int row = 0;
268
269 auto netclassToGridRow =
270 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
271 {
272 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
273
274 m_netclassGrid->SetUnitValue( aRow, GRID_WIREWIDTH, nc->GetWireWidth() );
275 m_netclassGrid->SetUnitValue( aRow, GRID_BUSWIDTH, nc->GetBusWidth() );
276
277 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
278 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
279
280 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
281
282 if( lineStyleIdx >= (int) g_lineStyleNames.size() )
283 lineStyleIdx = 0;
284
285 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE,
286 g_lineStyleNames[ lineStyleIdx ] );
287 m_netclassGrid->SetUnitValue( aRow, GRID_CLEARANCE, nc->GetClearance() );
288 m_netclassGrid->SetUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidth() );
289 m_netclassGrid->SetUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameter() );
290 m_netclassGrid->SetUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrill() );
291 m_netclassGrid->SetUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameter() );
292 m_netclassGrid->SetUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrill() );
293 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
294 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
295 };
296
298
299 // enter the Default NETCLASS.
300 m_netclassGrid->AppendRows( 1 );
301 netclassToGridRow( row++, m_netSettings->m_DefaultNetClass );
302
303 // make the Default NETCLASS name read-only
304 wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
305 cellAttr->SetReadOnly();
306 cellAttr->DecRef();
307
308 // enter other netclasses
309 m_netclassGrid->AppendRows( (int) m_netSettings->m_NetClasses.size() );
310
311 for( const auto& [ name, netclass ] : m_netSettings->m_NetClasses )
312 netclassToGridRow( row++, netclass );
313
315 m_assignmentGrid->AppendRows( m_netSettings->m_NetClassPatternAssignments.size() );
316 row = 0;
317
318 for( const auto& [ matcher, netclassName ] : m_netSettings->m_NetClassPatternAssignments )
319 {
320 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
321 m_assignmentGrid->SetCellValue( row, 1, netclassName );
322 row++;
323 }
324
325 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
326
327 return true;
328}
329
330
332{
334
335 wxArrayString netclassNames;
336
337 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
338 {
339 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
340
341 if( !netclassName.IsEmpty() )
342 netclassNames.push_back( netclassName );
343 }
344
345 wxGridCellAttr* attr = new wxGridCellAttr;
346 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
347 m_assignmentGrid->SetColAttr( 1, attr );
348}
349
350
352{
353 if( !Validate() )
354 return false;
355
356 int row = 0;
357
358 auto gridRowToNetclass =
359 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
360 {
361 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
362
363 nc->SetWireWidth( m_netclassGrid->GetUnitValue( aRow, GRID_WIREWIDTH ) );
364 nc->SetBusWidth( m_netclassGrid->GetUnitValue( aRow, GRID_BUSWIDTH ) );
365
366 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
367 nc->SetSchematicColor( wxColour( color ) );
368
369 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
370 nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
371 wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
372
373 nc->SetClearance( m_netclassGrid->GetUnitValue( aRow, GRID_CLEARANCE ) );
374 nc->SetTrackWidth( m_netclassGrid->GetUnitValue( aRow, GRID_TRACKSIZE ) );
375 nc->SetViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_VIASIZE ) );
376 nc->SetViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_VIADRILL ) );
377 nc->SetuViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_uVIASIZE ) );
378 nc->SetuViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_uVIADRILL ) );
379 nc->SetDiffPairWidth( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
380 nc->SetDiffPairGap( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
381 };
382
383 m_netSettings->m_NetClasses.clear();
384
385 // Copy the default NetClass:
386 gridRowToNetclass( row++, m_netSettings->m_DefaultNetClass );
387
388 // Copy other NetClasses:
389 for( row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
390 {
391 auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
392 gridRowToNetclass( row, nc );
393 m_netSettings->m_NetClasses[ nc->GetName() ] = nc;
394 }
395
396 m_netSettings->m_NetClassPatternAssignments.clear();
397
398 for( row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
399 {
400 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
401 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
402
403 m_netSettings->m_NetClassPatternAssignments.push_back(
404 {
405 std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ),
406 netclass
407 } );
408
409 m_netSettings->m_NetClassPatternAssignmentCache.clear();
410 }
411
412 return true;
413}
414
415
416bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
417 bool focusFirst )
418{
419 wxString tmp = aName;
420
421 tmp.Trim( true );
422 tmp.Trim( false );
423
424 if( tmp.IsEmpty() )
425 {
426 wxString msg = _( "Netclass must have a name." );
427 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
428 return false;
429 }
430
431 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
432 {
433 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
434 {
435 wxString msg = _( "Netclass name already in use." );
437 focusFirst ? aRow : ii, GRID_NAME );
438 return false;
439 }
440 }
441
442 return true;
443}
444
445
447{
448 if( event.GetCol() == GRID_NAME )
449 {
450 if( validateNetclassName( event.GetRow(), event.GetString() ) )
451 {
452 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
453 wxString newName = event.GetString();
454
455 if( !oldName.IsEmpty() )
456 {
457 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
458 {
459 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
460 m_assignmentGrid->SetCellValue( row, 1, newName );
461 }
462 }
463
464 m_netclassesDirty = true;
465 }
466 else
467 {
468 event.Veto();
469 }
470 }
471}
472
473
475{
476 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
477
478 if( aEvent.Moving() || aEvent.Entering() )
479 {
480 aEvent.Skip();
481
482 if( col == wxNOT_FOUND )
483 {
484 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
485 return;
486 }
487
488 if( col == m_hoveredCol )
489 return;
490
491 m_hoveredCol = col;
492
493 wxString tip;
494
495 switch( col )
496 {
497 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
498 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
499 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
500 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
501 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
502 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
503 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
504 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
505 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
506 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
507 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
508 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
509 }
510
511 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
512 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
513 }
514 else if( aEvent.Leaving() )
515 {
516 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
517 aEvent.Skip();
518 }
519
520 aEvent.Skip();
521}
522
523
525{
527 return;
528
529 int row = m_netclassGrid->GetNumberRows();
530 m_netclassGrid->AppendRows();
531
532 // Copy values of the default class:
533 for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
534 m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
535
536 m_netclassGrid->MakeCellVisible( row, 0 );
537 m_netclassGrid->SetGridCursor( row, 0 );
538
539 m_netclassGrid->EnableCellEditControl( true );
540 m_netclassGrid->ShowCellEditControl();
541
542 m_netclassesDirty = true;
543}
544
545
547{
549 return;
550
551 int curRow = m_netclassGrid->GetGridCursorRow();
552
553 if( curRow < 0 )
554 {
555 return;
556 }
557 else if( curRow == 0 )
558 {
559 DisplayErrorMessage( this, _( "The default net class is required." ) );
560 return;
561 }
562
563 // reset the net class to default for members of the removed class
564 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
565
566 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
567 {
568 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
569 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
570 }
571
572 m_netclassGrid->DeleteRows( curRow, 1 );
573
574 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
575 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
576
577 m_netclassesDirty = true;
578}
579
580
582{
583 if( aWidth != m_lastNetclassGridWidth )
584 {
586
587 // Account for scroll bars
588 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
589
590 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
591 {
592 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
593 aWidth -= m_originalColWidths[ i ];
594 }
595
596 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
597 }
598}
599
600
602{
603 AdjustNetclassGridColumns( event.GetSize().GetX() );
604
605 event.Skip();
606}
607
608
610{
612 return;
613
614 int row = m_assignmentGrid->GetNumberRows();
615 m_assignmentGrid->AppendRows();
616
617 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->m_DefaultNetClass->GetName() );
618
619 m_assignmentGrid->MakeCellVisible( row, 0 );
620 m_assignmentGrid->SetGridCursor( row, 0 );
621
622 m_assignmentGrid->EnableCellEditControl( true );
623 m_assignmentGrid->ShowCellEditControl();
624}
625
626
628{
630 return;
631
632 int curRow = m_assignmentGrid->GetGridCursorRow();
633
634 if( curRow < 0 )
635 return;
636
637 m_assignmentGrid->DeleteRows( curRow, 1 );
638
639 if( m_assignmentGrid->GetNumberRows() > 0 )
640 {
641 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
642 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
643 }
644}
645
646
648{
649 // Account for scroll bars
650 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
651
652 int classNameWidth = 160;
653 m_assignmentGrid->SetColSize( 1, classNameWidth );
654 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
655}
656
657
659{
660 AdjustAssignmentGridColumns( event.GetSize().GetX() );
661
662 event.Skip();
663}
664
665
666void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
667{
669 {
671 m_netclassesDirty = false;
672 }
673
674 if( m_assignmentGrid->GetNumberRows() == 0 )
675 return;
676
677 wxString pattern;
678 int row = m_assignmentGrid->GetGridCursorRow();
679 int col = m_assignmentGrid->GetGridCursorCol();
680
681 if( row >= 0 )
682 pattern = m_assignmentGrid->GetCellValue( row, 0 );
683
684 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
685 {
686 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
687
688 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
689 pattern = txt->GetValue();
690
691 cellEditor->DecRef();
692 }
693
694 if( pattern != m_lastPattern )
695 {
697
698 if( !pattern.IsEmpty() )
699 {
700 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
701
702 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
703 pattern ) );
704
705 for( const wxString& net : m_netNames )
706 {
707 if( matcher.StartsWith( net ) )
708 m_matchingNets->Report( net );
709 }
710 }
711
713 m_lastPattern = pattern;
714 }
715}
716
717
719{
721 return false;
722
723 wxString msg;
724
725 // Test net class parameters.
726 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
727 {
728 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
729 netclassName.Trim( true );
730 netclassName.Trim( false );
731
732 if( !validateNetclassName( row, netclassName, false ) )
733 return false;
734 }
735
736 return true;
737}
738
739
740void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
741{
742 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
743
744 m_netSettings = aNetSettings;
746
748
749 m_netclassGrid->ForceRefresh();
750 m_assignmentGrid->ForceRefresh();
751
752 m_netSettings = savedSettings;
753}
754
755
int color
Definition: DXF_plotter.cpp:57
const char * name
Definition: DXF_plotter.cpp:56
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
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
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
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
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
void SetBitmap(const wxBitmap &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:571
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:553
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:532
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:611
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:523
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:474
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:38
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:308
This file is part of the common library.
#define _(s)
@ CTX_NETCLASS
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
@ 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:115