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 <confirm.h>
33#include <gal/painter.h>
34#include <grid_tricks.h>
36#include <tool/tool_manager.h>
37#include <pcb_painter.h>
38#include <string_utils.h>
39#include <view/view.h>
43#include <widgets/wx_panel.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 // Calculate a min best size to handle longest usual numeric values:
123 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
124
125 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
126 {
127 // We calculate the column min size only from texts sizes, not using the initial col width
128 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
129 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
130
131 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
132 : min_best_width;
133
134 m_netclassGrid->SetColMinimalWidth( i, min_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
141 for( int i = GRID_FIRST_PCBNEW; i < GRID_END; ++i )
142 {
143 if( i >= GRID_FIRST_EESCHEMA )
144 {
146
147 if( !m_isEEschema )
148 {
149 m_netclassGrid->HideCol( i );
150 m_originalColWidths[ i ] = 0;
151 }
152 }
153 else
154 {
156
157 if( m_isEEschema )
158 {
159 m_netclassGrid->HideCol( i );
160 m_originalColWidths[ i ] = 0;
161 }
162 }
163 }
164
165 wxGridCellAttr* attr = new wxGridCellAttr;
166 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
167 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
168 m_netclassGrid ) );
169 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
170
171 attr = new wxGridCellAttr;
172 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
173 attr->SetEditor(
175 m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
176
177 attr = new wxGridCellAttr;
180 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
181
182 if( m_isEEschema )
183 {
184 m_importColorsButton->Hide();
185 }
186 else
187 {
188 m_colorDefaultHelpText->SetLabel(
189 _( "Set color to transparent to use layer default color." ) );
190 m_colorDefaultHelpText->GetParent()->Layout();
191 }
192
193 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
194
205
206
207 // Be sure the column labels are readable
209
210 // Membership combobox editors require a bit more room, so increase the row size of
211 // all our grids for consistency
212 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
213 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
214
215 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
216 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
217
218 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
219 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
220
222 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
223
224 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
225 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
226
227 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
228 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
229
230 // wxFormBuilder doesn't include this event...
231 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
233 nullptr, this );
234
235 // Handle tooltips for grid
236 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
238 this );
239
240 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
241
242 m_netclassGrid->EndBatch();
243 m_assignmentGrid->EndBatch();
244 Thaw();
245
246 Bind( wxEVT_IDLE,
247 [this]( wxIdleEvent& aEvent )
248 {
249 // Careful of consuming CPU in an idle event handler. Check the ticker first to
250 // see if there's even a possibility of the netclasses having changed.
252 {
253 wxWindow* dialog = wxGetTopLevelParent( this );
254 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
255
256 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->m_NetClasses )
257 checkReload();
258 }
259 } );
260
261 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
262}
263
264
266{
268 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
269
270 // Delete the GRID_TRICKS.
271 m_netclassGrid->PopEventHandler( true );
272 m_assignmentGrid->PopEventHandler( true );
273
274 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
276 nullptr, this );
277
278 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
279}
280
281
283{
284 KIGFX::PCB_RENDER_SETTINGS* rs = nullptr;
285 if( !m_isEEschema )
286 {
287 rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
289 }
290
291 int row = 0;
292
293 auto netclassToGridRow = [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
294 {
295 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
296
297 m_netclassGrid->SetUnitValue( aRow, GRID_WIREWIDTH, nc->GetWireWidth() );
298 m_netclassGrid->SetUnitValue( aRow, GRID_BUSWIDTH, nc->GetBusWidth() );
299
300 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
301 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
302
303 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
304
305 if( lineStyleIdx >= (int) g_lineStyleNames.size() )
306 lineStyleIdx = 0;
307
308 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE, g_lineStyleNames[lineStyleIdx] );
309 m_netclassGrid->SetUnitValue( aRow, GRID_CLEARANCE, nc->GetClearance() );
310 m_netclassGrid->SetUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidth() );
311 m_netclassGrid->SetUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameter() );
312 m_netclassGrid->SetUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrill() );
313 m_netclassGrid->SetUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameter() );
314 m_netclassGrid->SetUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrill() );
315 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
316 m_netclassGrid->SetUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
317
318 colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString();
319
320 if( m_isEEschema )
321 {
322 colorAsString = nc->GetPcbColor().ToCSSString();
323 }
324
325 if( rs )
326 {
327 std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
328 if( netclassColors.find( nc->GetName() ) != netclassColors.end() )
329 {
330 colorAsString = netclassColors[nc->GetName()].ToCSSString();
331 }
332 }
333
334 if( isDefault )
335 {
336 colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString();
337 m_netclassGrid->SetReadOnly( aRow, GRID_PCB_COLOR );
338 }
339
340 m_netclassGrid->SetCellValue( aRow, GRID_PCB_COLOR, colorAsString );
341 };
342
344
345 // enter the Default NETCLASS.
346 m_netclassGrid->AppendRows( 1 );
347 netclassToGridRow( row++, m_netSettings->m_DefaultNetClass, true );
348
349 // make the Default NETCLASS name read-only
350 wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
351 cellAttr->SetReadOnly();
352 cellAttr->DecRef();
353
354 // enter other netclasses
355 m_netclassGrid->AppendRows( (int) m_netSettings->m_NetClasses.size() );
356
357 for( const auto& [ name, netclass ] : m_netSettings->m_NetClasses )
358 netclassToGridRow( row++, netclass, false );
359
361 m_assignmentGrid->AppendRows( m_netSettings->m_NetClassPatternAssignments.size() );
362 row = 0;
363
364 for( const auto& [ matcher, netclassName ] : m_netSettings->m_NetClassPatternAssignments )
365 {
366 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
367 m_assignmentGrid->SetCellValue( row, 1, netclassName );
368 row++;
369 }
370}
371
372
374{
375 // MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
376 // event until we crash the stack).
378
379 if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
380 "Do you wish to reload them?" ) ) )
381 {
382 m_lastLoaded = m_netSettings->m_NetClasses;
384 }
385}
386
387
388void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
389{
390 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
391 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
392
393 m_netSettings = tempNetSettings;
394
396
397 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
398 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
399
401
402 m_netSettings = saveNetSettings;
403
404 aEvent.Skip();
405}
406
407
409{
410 m_lastLoaded = m_netSettings->m_NetClasses;
412
414 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
415
416 return true;
417}
418
419
421{
423
424 wxArrayString netclassNames;
425
426 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
427 {
428 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
429
430 if( !netclassName.IsEmpty() )
431 netclassNames.push_back( netclassName );
432 }
433
434 wxGridCellAttr* attr = new wxGridCellAttr;
435 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
436 m_assignmentGrid->SetColAttr( 1, attr );
437}
438
439
441{
442 if( !Validate() )
443 return false;
444
445 int row = 0;
446
447 auto gridRowToNetclass = [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
448 {
449 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
450
451 nc->SetWireWidth( m_netclassGrid->GetUnitValue( aRow, GRID_WIREWIDTH ) );
452 nc->SetBusWidth( m_netclassGrid->GetUnitValue( aRow, GRID_BUSWIDTH ) );
453
454 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
455 nc->SetSchematicColor( wxColour( color ) );
456
457 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
458 nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
459 wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
460
461 nc->SetClearance( m_netclassGrid->GetUnitValue( aRow, GRID_CLEARANCE ) );
462 nc->SetTrackWidth( m_netclassGrid->GetUnitValue( aRow, GRID_TRACKSIZE ) );
463 nc->SetViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_VIASIZE ) );
464 nc->SetViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_VIADRILL ) );
465 nc->SetuViaDiameter( m_netclassGrid->GetUnitValue( aRow, GRID_uVIASIZE ) );
466 nc->SetuViaDrill( m_netclassGrid->GetUnitValue( aRow, GRID_uVIADRILL ) );
467 nc->SetDiffPairWidth( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
468 nc->SetDiffPairGap( m_netclassGrid->GetUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
469
470 if( !isDefault )
471 {
472 color = m_netclassGrid->GetCellValue( aRow, GRID_PCB_COLOR );
473 KIGFX::COLOR4D newPcbColor( color );
474
475 if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
476 {
477 nc->SetPcbColor( newPcbColor );
478 }
479
480 if( !m_isEEschema )
481 {
484 std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
485
486 if( newPcbColor != COLOR4D::UNSPECIFIED )
487 {
488 netclassColors[nc->GetName()] = newPcbColor;
489 }
490 else
491 {
492 netclassColors.erase( nc->GetName() );
493 }
494 }
495 }
496 };
497
498 m_netSettings->m_NetClasses.clear();
499
500 // Copy the default NetClass:
501 gridRowToNetclass( row++, m_netSettings->m_DefaultNetClass, true );
502
503 // Copy other NetClasses:
504 for( row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
505 {
506 auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
507 gridRowToNetclass( row, nc, false );
508 m_netSettings->m_NetClasses[ nc->GetName() ] = nc;
509 }
510
511 m_netSettings->m_NetClassPatternAssignments.clear();
512
513 for( row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
514 {
515 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
516 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
517
518 m_netSettings->m_NetClassPatternAssignments.push_back(
519 {
520 std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ),
521 netclass
522 } );
523
524 m_netSettings->m_NetClassPatternAssignmentCache.clear();
525 }
526
527 return true;
528}
529
530
531bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
532 bool focusFirst )
533{
534 wxString tmp = aName;
535
536 tmp.Trim( true );
537 tmp.Trim( false );
538
539 if( tmp.IsEmpty() )
540 {
541 wxString msg = _( "Netclass must have a name." );
542 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
543 return false;
544 }
545
546 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
547 {
548 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
549 {
550 wxString msg = _( "Netclass name already in use." );
552 focusFirst ? aRow : ii, GRID_NAME );
553 return false;
554 }
555 }
556
557 return true;
558}
559
560
562{
563 if( event.GetCol() == GRID_NAME )
564 {
565 if( validateNetclassName( event.GetRow(), event.GetString() ) )
566 {
567 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
568 wxString newName = event.GetString();
569
570 if( !oldName.IsEmpty() )
571 {
572 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
573 {
574 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
575 m_assignmentGrid->SetCellValue( row, 1, newName );
576 }
577 }
578
579 m_netclassesDirty = true;
580 }
581 else
582 {
583 event.Veto();
584 }
585 }
586}
587
588
590{
591 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
592
593 if( aEvent.Moving() || aEvent.Entering() )
594 {
595 aEvent.Skip();
596
597 if( col == wxNOT_FOUND )
598 {
599 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
600 return;
601 }
602
603 if( col == m_hoveredCol )
604 return;
605
606 m_hoveredCol = col;
607
608 wxString tip;
609
610 switch( col )
611 {
612 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
613 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
614 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
615 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
616 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
617 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
618 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
619 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
620 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
621 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
622 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
623 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
624 case GRID_PCB_COLOR: tip = _( "PCB netclass color" ); break;
625 }
626
627 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
628 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
629 }
630 else if( aEvent.Leaving() )
631 {
632 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
633 aEvent.Skip();
634 }
635
636 aEvent.Skip();
637}
638
639
641{
643 return;
644
645 int row = m_netclassGrid->GetNumberRows();
646 m_netclassGrid->AppendRows();
647
648 // Copy values of the default class:
649 for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
650 m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
651
652 m_netclassGrid->MakeCellVisible( row, 0 );
653 m_netclassGrid->SetGridCursor( row, 0 );
654
655 m_netclassGrid->EnableCellEditControl( true );
656 m_netclassGrid->ShowCellEditControl();
657
658 m_netclassesDirty = true;
659}
660
661
663{
665 return;
666
667 int curRow = m_netclassGrid->GetGridCursorRow();
668
669 if( curRow < 0 )
670 {
671 return;
672 }
673 else if( curRow == 0 )
674 {
675 wxWindow* topLevelParent = wxGetTopLevelParent( this );
676
677 DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) );
678 return;
679 }
680
681 // reset the net class to default for members of the removed class
682 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
683
684 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
685 {
686 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
687 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
688 }
689
690 m_netclassGrid->DeleteRows( curRow, 1 );
691
692 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
693 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
694
695 m_netclassesDirty = true;
696}
697
698
700{
701 if( aWidth != m_lastNetclassGridWidth )
702 {
704
705 // Account for scroll bars
706 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
707
708 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
709 {
710 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
711 aWidth -= m_originalColWidths[ i ];
712 }
713
714 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
715 }
716}
717
718
720{
721 AdjustNetclassGridColumns( event.GetSize().GetX() );
722
723 event.Skip();
724}
725
726
728{
730 return;
731
732 int row = m_assignmentGrid->GetNumberRows();
733 m_assignmentGrid->AppendRows();
734
735 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->m_DefaultNetClass->GetName() );
736
737 m_assignmentGrid->MakeCellVisible( row, 0 );
738 m_assignmentGrid->SetGridCursor( row, 0 );
739
740 m_assignmentGrid->EnableCellEditControl( true );
741 m_assignmentGrid->ShowCellEditControl();
742}
743
744
746{
748 return;
749
750 int curRow = m_assignmentGrid->GetGridCursorRow();
751
752 if( curRow < 0 )
753 return;
754
755 m_assignmentGrid->DeleteRows( curRow, 1 );
756
757 if( m_assignmentGrid->GetNumberRows() > 0 )
758 {
759 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
760 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
761 }
762}
763
764
766{
767 std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses = m_netSettings->m_NetClasses;
768
769 for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
770 {
771 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
772
773 if( netclasses.find( netclassName ) != netclasses.end() )
774 {
775 const KIGFX::COLOR4D ncColor = netclasses[netclassName]->GetSchematicColor();
776 m_netclassGrid->SetCellValue( row, GRID_PCB_COLOR, ncColor.ToCSSString() );
777 }
778 }
779}
780
781
783{
784 // Account for scroll bars
785 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
786
787 int classNameWidth = 160;
788 m_assignmentGrid->SetColSize( 1, classNameWidth );
789 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
790}
791
792
794{
795 AdjustAssignmentGridColumns( event.GetSize().GetX() );
796
797 event.Skip();
798}
799
800
801void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
802{
804 {
806 m_netclassesDirty = false;
807 }
808
809 if( m_assignmentGrid->GetNumberRows() == 0 )
810 return;
811
812 wxString pattern;
813 int row = m_assignmentGrid->GetGridCursorRow();
814 int col = m_assignmentGrid->GetGridCursorCol();
815
816 if( row >= 0 )
817 pattern = m_assignmentGrid->GetCellValue( row, 0 );
818
819 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
820 {
821 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
822
823 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
824 pattern = txt->GetValue();
825
826 cellEditor->DecRef();
827 }
828
829 if( pattern != m_lastPattern )
830 {
832
833 if( !pattern.IsEmpty() )
834 {
835 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
836
837 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
838 pattern ) );
839
840 for( const wxString& net : m_netNames )
841 {
842 if( matcher.StartsWith( net ) )
843 m_matchingNets->Report( net );
844 }
845 }
846
848 m_lastPattern = pattern;
849 }
850}
851
852
854{
856 return false;
857
858 wxString msg;
859
860 // Test net class parameters.
861 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
862 {
863 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
864 netclassName.Trim( true );
865 netclassName.Trim( false );
866
867 if( !validateNetclassName( row, netclassName, false ) )
868 return false;
869 }
870
871 return true;
872}
873
874
875void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
876{
877 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
878
879 m_netSettings = aNetSettings;
881
883
884 m_netclassGrid->ForceRefresh();
885 m_assignmentGrid->ForceRefresh();
886
887 m_netSettings = std::move( savedSettings );
888}
889
890
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:77
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:119
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
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:655
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:637
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:616
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:695
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:114
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:607
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:157
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:558
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
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
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