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-2024 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 <gal/painter.h>
33#include <grid_tricks.h>
35#include <tool/tool_manager.h>
36#include <pcb_painter.h>
37#include <string_utils.h>
38#include <view/view.h>
42#include <widgets/wx_panel.h>
45#include <confirm.h>
46
47
48// columns of netclasses grid
49enum
50{
52
63
69
71};
72
73std::vector<BITMAPS> g_lineStyleIcons;
74wxArrayString g_lineStyleNames;
75
76
78 std::shared_ptr<NET_SETTINGS> aNetSettings,
79 const std::set<wxString>& aNetNames,
80 bool aIsEEschema ) :
81 PANEL_SETUP_NETCLASSES_BASE( aParentWindow ),
82 m_frame( aFrame ),
83 m_isEEschema( aIsEEschema ),
84 m_netSettings( std::move( aNetSettings ) ),
85 m_netNames( aNetNames ),
86 m_lastCheckedTicker( 0 ),
87 m_hoveredCol( -1 ),
88 m_lastNetclassGridWidth( -1 )
89{
90 // Clear and re-load each time. Language (or darkmode) might have changed.
91 g_lineStyleIcons.clear();
92 g_lineStyleNames.clear();
93
94 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
95 g_lineStyleNames.push_back( _( "Solid" ) );
96 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
97 g_lineStyleNames.push_back( _( "Dashed" ) );
98 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
99 g_lineStyleNames.push_back( _( "Dotted" ) );
100 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
101 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
102 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
103 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
104
105 m_netclassesDirty = true;
106
107 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
108 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
109
110 m_netclassesPane->SetBorders( true, false, false, false );
111 m_membershipPane->SetBorders( true, false, false, false );
112
113 // Prevent Size events from firing before we are ready
114 Freeze();
115 m_netclassGrid->BeginBatch();
116 m_netclassGrid->SetUseNativeColLabels();
117 m_assignmentGrid->BeginBatch();
118 m_assignmentGrid->SetUseNativeColLabels();
119
120 m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) );
121
122 wxASSERT( m_netclassGrid->GetNumberCols() == GRID_END );
123
124 // Calculate a min best size to handle longest usual numeric values:
125 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
126
127 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
128 {
129 // We calculate the column min size only from texts sizes, not using the initial col width
130 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
131 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
132
133 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
134 : min_best_width;
135
136 // We use a "best size" >= min_best_width
137 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
138 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
139
140 if( i >= GRID_FIRST_EESCHEMA )
142 else
144 }
145
147
148 if( m_isEEschema )
150 else
152
154
155 wxGridCellAttr* attr = new wxGridCellAttr;
156 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
157 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
158 m_netclassGrid ) );
159 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
160
161 attr = new wxGridCellAttr;
162 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
163 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
164 m_netclassGrid ) );
165 m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
166
167 attr = new wxGridCellAttr;
170 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
171
172 if( m_isEEschema )
173 {
174 m_importColorsButton->Hide();
175 }
176 else
177 {
178 m_colorDefaultHelpText->SetLabel(
179 _( "Set color to transparent to use layer default color." ) );
180 m_colorDefaultHelpText->GetParent()->Layout();
181 }
182
183 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
184
195
196
197 // Be sure the column labels are readable
199
200 // Membership combobox editors require a bit more room, so increase the row size of
201 // all our grids for consistency
202 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
203 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
204
205 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
206 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
207
208 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
209 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
210
211 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
212
213 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
214 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
215
216 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
217 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
218
219 // wxFormBuilder doesn't include this event...
220 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
222 nullptr, this );
223
224 // Handle tooltips for grid
225 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
227 this );
228
229 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
230
231 m_netclassGrid->EndBatch();
232 m_assignmentGrid->EndBatch();
233 Thaw();
234
235 Bind( wxEVT_IDLE,
236 [this]( wxIdleEvent& aEvent )
237 {
238 // Careful of consuming CPU in an idle event handler. Check the ticker first to
239 // see if there's even a possibility of the netclasses having changed.
241 {
242 wxWindow* dialog = wxGetTopLevelParent( this );
243 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
244
245 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->m_NetClasses )
246 checkReload();
247 }
248 } );
249
250 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
251}
252
253
255{
257 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
258
259 if( m_isEEschema )
261 else
263
264 // Delete the GRID_TRICKS.
265 m_netclassGrid->PopEventHandler( true );
266 m_assignmentGrid->PopEventHandler( true );
267
268 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
270 nullptr, this );
271
272 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
273}
274
275
277{
278 KIGFX::PCB_RENDER_SETTINGS* rs = nullptr;
279
280 if( !m_isEEschema )
281 {
282 rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
284 }
285
286 int row = 0;
287
288 auto netclassToGridRow =
289 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
290 {
291 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
292
293 m_netclassGrid->SetUnitValue( aRow, GRID_WIREWIDTH, nc->GetWireWidth() );
294 m_netclassGrid->SetUnitValue( aRow, GRID_BUSWIDTH, nc->GetBusWidth() );
295
296 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
297 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
298
299 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
300
301 if( lineStyleIdx >= (int) g_lineStyleNames.size() )
302 lineStyleIdx = 0;
303
304 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE, g_lineStyleNames[lineStyleIdx] );
305 m_netclassGrid->SetUnitValue( aRow, GRID_CLEARANCE, nc->GetClearance() );
306 m_netclassGrid->SetUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidth() );
307 m_netclassGrid->SetUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameter() );
308 m_netclassGrid->SetUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrill() );
309 m_netclassGrid->SetUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameter() );
310 m_netclassGrid->SetUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrill() );
311 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
312 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
313
314 colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString();
315
316 if( m_isEEschema )
317 colorAsString = nc->GetPcbColor().ToCSSString();
318
319 if( rs )
320 {
321 std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
322
323 if( netclassColors.find( nc->GetName() ) != netclassColors.end() )
324 colorAsString = netclassColors[nc->GetName()].ToCSSString();
325 }
326
327 if( isDefault )
328 {
329 colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString();
330 m_netclassGrid->SetReadOnly( aRow, GRID_PCB_COLOR );
331 }
332
333 m_netclassGrid->SetCellValue( aRow, GRID_PCB_COLOR, colorAsString );
334 };
335
337
338 // enter the Default NETCLASS.
339 m_netclassGrid->AppendRows( 1 );
340 netclassToGridRow( row++, m_netSettings->m_DefaultNetClass, true );
341
342 // make the Default NETCLASS name read-only
343 wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
344 cellAttr->SetReadOnly();
345 cellAttr->DecRef();
346
347 // enter other netclasses
348 m_netclassGrid->AppendRows( (int) m_netSettings->m_NetClasses.size() );
349
350 for( const auto& [ name, netclass ] : m_netSettings->m_NetClasses )
351 netclassToGridRow( row++, netclass, false );
352
354 m_assignmentGrid->AppendRows( m_netSettings->m_NetClassPatternAssignments.size() );
355 row = 0;
356
357 for( const auto& [ matcher, netclassName ] : m_netSettings->m_NetClassPatternAssignments )
358 {
359 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
360 m_assignmentGrid->SetCellValue( row, 1, netclassName );
361 row++;
362 }
363}
364
365
367{
368 // MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
369 // event until we crash the stack).
371
372 if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
373 "Do you wish to reload them?" ) ) )
374 {
375 m_lastLoaded = m_netSettings->m_NetClasses;
377 }
378}
379
380
381void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
382{
383 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
384 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
385
386 m_netSettings = tempNetSettings;
387
389
390 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
391 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
392
394
395 m_netSettings = saveNetSettings;
396
397 aEvent.Skip();
398}
399
400
402{
403 m_lastLoaded = m_netSettings->m_NetClasses;
405
407 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
408
409 return true;
410}
411
412
414{
416
417 wxArrayString netclassNames;
418
419 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
420 {
421 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
422
423 if( !netclassName.IsEmpty() )
424 netclassNames.push_back( netclassName );
425 }
426
427 wxGridCellAttr* attr = new wxGridCellAttr;
428 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
429 m_assignmentGrid->SetColAttr( 1, attr );
430}
431
432
434{
435 if( !Validate() )
436 return false;
437
438 int row = 0;
439
440 auto gridRowToNetclass =
441 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
442 {
443 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
444
445 nc->SetWireWidth( m_netclassGrid->GetUnitValue( aRow, GRID_WIREWIDTH ) );
446 nc->SetBusWidth( m_netclassGrid->GetUnitValue( aRow, GRID_BUSWIDTH ) );
447
448 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
449 nc->SetSchematicColor( wxColour( color ) );
450
451 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
452 nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
453 wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
454
455 nc->SetClearance( m_netclassGrid->GetUnitValue( aRow, GRID_CLEARANCE ) );
456 nc->SetTrackWidth( m_netclassGrid->GetUnitValue( aRow, GRID_TRACKSIZE ) );
457 nc->SetViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_VIASIZE ) );
458 nc->SetViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_VIADRILL ) );
459 nc->SetuViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_uVIASIZE ) );
460 nc->SetuViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_uVIADRILL ) );
461 nc->SetDiffPairWidth( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
462 nc->SetDiffPairGap( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
463
464 if( !isDefault )
465 {
466 color = m_netclassGrid->GetCellValue( aRow, GRID_PCB_COLOR );
467 KIGFX::COLOR4D newPcbColor( color );
468
469 if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
470 nc->SetPcbColor( newPcbColor );
471
472 if( !m_isEEschema )
473 {
476 std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
477
478 if( newPcbColor != COLOR4D::UNSPECIFIED )
479 netclassColors[nc->GetName()] = newPcbColor;
480 else
481 netclassColors.erase( nc->GetName() );
482 }
483 }
484 };
485
486 m_netSettings->m_NetClasses.clear();
487
488 // Copy the default NetClass:
489 gridRowToNetclass( row++, m_netSettings->m_DefaultNetClass, true );
490
491 // Copy other NetClasses:
492 for( row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
493 {
494 auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
495 gridRowToNetclass( row, nc, false );
496 m_netSettings->m_NetClasses[ nc->GetName() ] = nc;
497 }
498
499 m_netSettings->m_NetClassPatternAssignments.clear();
500
501 for( row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
502 {
503 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
504 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
505
506 m_netSettings->m_NetClassPatternAssignments.push_back(
507 { std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ), netclass } );
508 }
509
510 m_netSettings->m_NetClassPatternAssignmentCache.clear();
511
512 return true;
513}
514
515
516bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
517 bool focusFirst )
518{
519 wxString tmp = aName;
520
521 tmp.Trim( true );
522 tmp.Trim( false );
523
524 if( tmp.IsEmpty() )
525 {
526 wxString msg = _( "Netclass must have a name." );
527 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
528 return false;
529 }
530
531 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
532 {
533 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
534 {
535 wxString msg = _( "Netclass name already in use." );
537 focusFirst ? aRow : ii, GRID_NAME );
538 return false;
539 }
540 }
541
542 return true;
543}
544
545
547{
548 if( event.GetCol() == GRID_NAME )
549 {
550 if( validateNetclassName( event.GetRow(), event.GetString() ) )
551 {
552 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
553 wxString newName = event.GetString();
554
555 if( !oldName.IsEmpty() )
556 {
557 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
558 {
559 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
560 m_assignmentGrid->SetCellValue( row, 1, newName );
561 }
562 }
563
564 m_netclassesDirty = true;
565 }
566 else
567 {
568 event.Veto();
569 }
570 }
571}
572
573
575{
576 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
577
578 if( aEvent.Moving() || aEvent.Entering() )
579 {
580 aEvent.Skip();
581
582 if( col == wxNOT_FOUND )
583 {
584 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
585 return;
586 }
587
588 if( col == m_hoveredCol )
589 return;
590
591 m_hoveredCol = col;
592
593 wxString tip;
594
595 switch( col )
596 {
597 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
598 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
599 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
600 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
601 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
602 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
603 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
604 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
605 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
606 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
607 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
608 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
609 case GRID_PCB_COLOR: tip = _( "PCB netclass color" ); break;
610 }
611
612 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
613 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
614 }
615 else if( aEvent.Leaving() )
616 {
617 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
618 aEvent.Skip();
619 }
620
621 aEvent.Skip();
622}
623
624
626{
628 return;
629
630 int row = m_netclassGrid->GetNumberRows();
631 m_netclassGrid->AppendRows();
632
633 // Copy values of the default class:
634 for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
635 m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
636
637 m_netclassGrid->MakeCellVisible( row, 0 );
638 m_netclassGrid->SetGridCursor( row, 0 );
639
640 m_netclassGrid->EnableCellEditControl( true );
641 m_netclassGrid->ShowCellEditControl();
642
643 m_netclassesDirty = true;
644}
645
646
648{
650 return;
651
652 int curRow = m_netclassGrid->GetGridCursorRow();
653
654 if( curRow < 0 )
655 {
656 return;
657 }
658 else if( curRow == 0 )
659 {
660 wxWindow* topLevelParent = wxGetTopLevelParent( this );
661
662 DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) );
663 return;
664 }
665
666 // reset the net class to default for members of the removed class
667 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
668
669 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
670 {
671 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
672 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
673 }
674
675 m_netclassGrid->DeleteRows( curRow, 1 );
676
677 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
678 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
679
680 m_netclassesDirty = true;
681}
682
683
685{
686 if( aWidth != m_lastNetclassGridWidth )
687 {
689
690 // Account for scroll bars
691 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
692
693 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
694 {
695 if( m_netclassGrid->GetColSize( i ) > 0 )
696 {
697 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
698 aWidth -= m_originalColWidths[ i ];
699 }
700 }
701
702 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
703 }
704}
705
706
708{
709 AdjustNetclassGridColumns( event.GetSize().GetX() );
710
711 event.Skip();
712}
713
714
716{
718 return;
719
720 int row = m_assignmentGrid->GetNumberRows();
721 m_assignmentGrid->AppendRows();
722
723 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->m_DefaultNetClass->GetName() );
724
725 m_assignmentGrid->MakeCellVisible( row, 0 );
726 m_assignmentGrid->SetGridCursor( row, 0 );
727
728 m_assignmentGrid->EnableCellEditControl( true );
729 m_assignmentGrid->ShowCellEditControl();
730}
731
732
734{
736 return;
737
738 int curRow = m_assignmentGrid->GetGridCursorRow();
739
740 if( curRow < 0 )
741 return;
742
743 m_assignmentGrid->DeleteRows( curRow, 1 );
744
745 if( m_assignmentGrid->GetNumberRows() > 0 )
746 {
747 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
748 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
749 }
750}
751
752
754{
755 std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses = m_netSettings->m_NetClasses;
756
757 for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
758 {
759 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
760
761 if( netclasses.find( netclassName ) != netclasses.end() )
762 {
763 const KIGFX::COLOR4D ncColor = netclasses[netclassName]->GetSchematicColor();
764 m_netclassGrid->SetCellValue( row, GRID_PCB_COLOR, ncColor.ToCSSString() );
765 }
766 }
767}
768
769
771{
772 // Account for scroll bars
773 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
774
775 int classNameWidth = 160;
776 m_assignmentGrid->SetColSize( 1, classNameWidth );
777 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
778}
779
780
782{
783 AdjustAssignmentGridColumns( event.GetSize().GetX() );
784
785 event.Skip();
786}
787
788
789void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
790{
792 {
794 m_netclassesDirty = false;
795 }
796
798 {
799 AdjustNetclassGridColumns( GetSize().x - 1 );
801 }
802
803 if( m_assignmentGrid->GetNumberRows() == 0 )
804 return;
805
806 wxString pattern;
807 int row = m_assignmentGrid->GetGridCursorRow();
808 int col = m_assignmentGrid->GetGridCursorCol();
809
810 if( row >= 0 )
811 pattern = m_assignmentGrid->GetCellValue( row, 0 );
812
813 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
814 {
815 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
816
817 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
818 pattern = txt->GetValue();
819
820 cellEditor->DecRef();
821 }
822
823 if( pattern != m_lastPattern )
824 {
826
827 if( !pattern.IsEmpty() )
828 {
829 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
830
831 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
832 pattern ) );
833
834 for( const wxString& net : m_netNames )
835 {
836 if( matcher.StartsWith( net ) )
837 m_matchingNets->Report( net );
838 }
839 }
840
842 m_lastPattern = pattern;
843 }
844}
845
846
848{
850 return false;
851
852 wxString msg;
853
854 // Test net class parameters.
855 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
856 {
857 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
858 netclassName.Trim( true );
859 netclassName.Trim( false );
860
861 if( !validateNetclassName( row, netclassName, false ) )
862 return false;
863 }
864
865 return true;
866}
867
868
869void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
870{
871 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
872
873 m_netSettings = aNetSettings;
875
877
878 m_netclassGrid->ForceRefresh();
879 m_assignmentGrid->ForceRefresh();
880
881 m_netSettings = std::move( savedSettings );
882}
883
884
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
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.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxString ToCSSString() const
Definition: color4d.cpp:147
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition: pcb_painter.h:78
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:120
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
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:46
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 OnImportColorsClick(wxCommandEvent &event) override
std::map< int, int > m_originalColWidths
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
std::bitset< 64 > m_shownColumns
void OnSizeNetclassGrid(wxSizeEvent &event) override
void AdjustNetclassGridColumns(int aWidth)
std::shared_ptr< NET_SETTINGS > m_netSettings
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:678
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:691
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:444
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:673
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:652
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:731
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:414
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:433
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:122
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:643
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:165
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:594
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:250
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
@ CTX_NETCLASS
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
STL namespace.
@ 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
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE