KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_jobset.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) 2024 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "panel_jobset.h"
22#include "dialog_destination.h"
24#include <wx/aui/auibook.h>
25#include <jobs/jobset.h>
26#include <jobs/job_registry.h>
27#include <eda_list_dialog.h>
28#include <wx/checkbox.h>
29#include <wx/menu.h>
30#include <bitmaps.h>
31#include <i18n_utility.h>
32#include <jobs_runner.h>
34#include <kicad_manager_frame.h>
35#include <vector>
36#include <wx/dcclient.h>
37
40#include <widgets/wx_grid.h>
42#include <kiplatform/ui.h>
43#include <confirm.h>
44
48
49
50extern KICOMMON_API
51std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos;
52
53
55{
56public:
57 DIALOG_JOBSET_RUN_LOG( wxWindow* aParent, JOBSET* aJobsFile, JOBSET_DESTINATION* aDestination ) :
59 m_jobsFile( aJobsFile ),
60 m_destination( aDestination ),
61 m_lastWidth( -1 ),
62 m_marginsWidth( -1 )
63 {
64 m_staticTextOutputName->SetLabel( wxString::Format( _( "Destination: %s" ),
65 aDestination->GetDescription() ) );
66
67 int jobBmpColId = m_jobList->AppendColumn( wxT( "" ) );
68 int jobNoColId = m_jobList->AppendColumn( _( "No." ) );
69 int jobDescColId = m_jobList->AppendColumn( _( "Job Description" ) );
70 int jobSourceColId = m_jobList->AppendColumn( _( "Source" ) );
71 m_jobList->SetColumnWidth( jobBmpColId, 26 );
72 m_jobList->SetColumnWidth( jobNoColId, GetTextExtent( wxT( "XXXX" ) ).GetWidth() );
73 m_jobList->SetColumnWidth( jobSourceColId, GetTextExtent( wxT( "XXXXXX" ) ).GetWidth() );
74
75 wxImageList* imageList = new wxImageList( 16, 16, true, 3 );
76 imageList->Add( KiBitmapBundle( BITMAPS::ercerr ).GetBitmap( wxSize( 16, 16 ) ) );
77 imageList->Add( KiBitmapBundle( BITMAPS::checked_ok ).GetBitmap( wxSize( 16, 16 ) ) );
78 m_jobList->SetImageList( imageList, wxIMAGE_LIST_SMALL );
79
80 int num = 1;
81
82 for( JOBSET_JOB& job : aJobsFile->GetJobsForDestination( aDestination ) )
83 {
84 int imageIdx = -1;
85
86 if( aDestination->m_lastRunSuccessMap.contains( job.m_id ) )
87 {
88 if( aDestination->m_lastRunSuccessMap[job.m_id].value() )
89 imageIdx = 1;
90 else
91 imageIdx = 0;
92 }
93
94 long itemIndex = m_jobList->InsertItem( m_jobList->GetItemCount(), imageIdx );
95
96 m_jobList->SetItem( itemIndex, jobNoColId, wxString::Format( "%d", num++ ) );
97 m_jobList->SetItem( itemIndex, jobDescColId, job.GetDescription() );
98
99 KIWAY::FACE_T iface = JOB_REGISTRY::GetKifaceType( job.m_type );
100 wxString source = wxEmptyString;
101
102 if( iface < KIWAY::KIWAY_FACE_COUNT )
103 {
104 if( iface == KIWAY::FACE_PCB )
105 source = wxT( "PCB" );
106 else if( iface == KIWAY::FACE_SCH )
107 source = wxT( "SCH" );
108 }
109
110 m_jobList->SetItem( itemIndex, jobSourceColId, source );
111 }
112
113 SetupStandardButtons( { { wxID_OK, _( "Close" ) } } );
115 }
116
117 virtual void OnUpdateUI( wxUpdateUIEvent& event ) override
118 {
119 if( GetSize().GetWidth() != m_lastWidth )
120 {
121 m_lastWidth = GetSize().GetWidth();
122
123 if( m_marginsWidth < 0 )
124 m_marginsWidth = m_lastWidth - ( m_jobList->GetSize().GetWidth() * 2 );
125
126 int width = ( m_lastWidth / 2 );
127 width -= m_marginsWidth;
128 width -= m_jobList->GetColumnWidth( 0 );
129 width -= m_jobList->GetColumnWidth( 1 );
130 width -= m_jobList->GetColumnWidth( 3 );
131
132 m_jobList->SetColumnWidth( 2, width );
133 }
134 }
135
136 void OnJobListItemSelected( wxListEvent& event ) override
137 {
138 int itemIndex = event.GetIndex();
139
140 // The index could be negative (it is default -1)
141 if( itemIndex < 0 )
142 return;
143
144 std::vector<JOBSET_JOB> jobs = m_jobsFile->GetJobsForDestination( m_destination );
145
146 if( static_cast<size_t>( itemIndex ) < jobs.size() )
147 {
148 wxString jobId = jobs[itemIndex].m_id;
149
150 if( m_destination->m_lastRunReporters.contains( jobId ) )
151 m_textCtrlOutput->SetValue( m_destination->m_lastRunReporters.at( jobId )->GetMessages() );
152 else
153 m_textCtrlOutput->SetValue( _( "No output messages" ) );
154 }
155 }
156
157private:
160
163};
164
165
167{
168public:
169 PANEL_DESTINATION( wxWindow* aParent, PANEL_JOBSET* aPanelParent, KICAD_MANAGER_FRAME* aFrame,
170 JOBSET* aFile, JOBSET_DESTINATION* aDestination ) :
171 PANEL_DESTINATION_BASE( aParent ),
172 m_jobsFile( aFile ),
173 m_destinationId( aDestination->m_id ),
174 m_frame( aFrame ),
175 m_panelParent( aPanelParent )
176 {
177 m_buttonProperties->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
178 m_buttonDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
179
180#if _WIN32
181 // BORDER_RAISED/SUNKEN look pretty on every platform but Windows
182 long style = GetWindowStyleFlag();
183 style &= ~wxBORDER_MASK;
184 style |= wxBORDER_SIMPLE;
185 SetWindowStyleFlag( style );
186#endif // _WIN32
187
188 Connect( wxEVT_MENU, wxCommandEventHandler( PANEL_DESTINATION::onMenu ), nullptr, this );
189
190 if( JobsetDestinationTypeInfos.contains( aDestination->m_type ) )
191 {
192 JOBSET_DESTINATION_T_INFO& jobTypeInfo = JobsetDestinationTypeInfos[aDestination->m_type];
193 m_textOutputType->SetLabel( aDestination->GetDescription() );
194 m_bitmapOutputType->SetBitmap( KiBitmapBundle( jobTypeInfo.bitmap ) );
195 }
196
197 m_pathInfo->SetFont( KIUI::GetSmallInfoFont( this ) );
198 UpdatePathInfo( aDestination->GetPathInfo() );
199 UpdateStatus();
200 }
201
203 {
204 Disconnect( wxEVT_MENU, wxCommandEventHandler( PANEL_DESTINATION::onMenu ), nullptr, this );
205 }
206
208 {
209 JOBSET_DESTINATION* destination = GetDestination();
210 wxCHECK( destination, /*void*/ );
211
212 destination->m_lastRunSuccess = std::nullopt;
213 m_statusBitmap->SetBitmap( wxNullBitmap );
214 }
215
217 {
218 JOBSET_DESTINATION* destination = GetDestination();
219 wxCHECK( destination, /*void*/ );
220
221 if( destination->m_lastRunSuccess.has_value() )
222 {
223 if( destination->m_lastRunSuccess.value() )
224 {
225 m_statusBitmap->SetBitmap( KiBitmapBundle( BITMAPS::checked_ok ) );
226 m_statusBitmap->Show();
227 m_statusBitmap->SetToolTip( _( "Last run successful" ) );
228 }
229 else
230 {
231 m_statusBitmap->SetBitmap( KiBitmapBundle( BITMAPS::ercerr ) );
232 m_statusBitmap->Show();
233 m_statusBitmap->SetToolTip( _( "Last run failed" ) );
234 }
235 }
236 else
237 {
238 m_statusBitmap->SetBitmap( wxNullBitmap );
239 }
240
241 m_buttonGenerate->Enable( !m_jobsFile->GetJobsForDestination( destination ).empty() );
242 }
243
244 void UpdatePathInfo( const wxString& aMsg )
245 {
246 wxClientDC dc( this );
247 int width = GetSize().GetWidth();
248
249 m_pathInfo->SetLabel( wxControl::Ellipsize( aMsg, dc, wxELLIPSIZE_MIDDLE, width ) );
250 }
251
252 virtual void OnGenerate( wxCommandEvent& event ) override
253 {
254 ClearStatus();
255 Refresh();
256
257 CallAfter(
258 [this]()
259 {
262
263 wxFileName fn = project.GetProjectFullName();
264 wxSetWorkingDirectory( fn.GetPath() );
265
266 {
267 JOBS_PROGRESS_REPORTER progressReporter( m_frame, _( "Running Jobs" ) );
268 JOBS_RUNNER jobRunner( &m_frame->Kiway(), m_jobsFile, &project,
269 NULL_REPORTER::GetInstance(), &progressReporter );
270
271 if( JOBSET_DESTINATION* destination = GetDestination() )
272 jobRunner.RunJobsForDestination( destination );
273
274 UpdateStatus();
275 }
276
277 // Bring the Kicad manager frame back to the front
278 m_frame->Raise();
279 } );
280 }
281
282 virtual void OnLastStatusClick( wxMouseEvent& aEvent ) override
283 {
284 JOBSET_DESTINATION* destination = GetDestination();
285 wxCHECK( destination, /*void*/ );
286
287 DIALOG_JOBSET_RUN_LOG dialog( m_frame, m_jobsFile, destination );
288 dialog.ShowModal();
289 }
290
291 void OnRightDown( wxMouseEvent& aEvent ) override
292 {
293 JOBSET_DESTINATION* destination = GetDestination();
294 wxCHECK( destination, /*void*/ );
295
296 wxMenu menu;
297 menu.Append( wxID_EDIT, _( "Edit Destination Options..." ) );
298 menu.Append( wxID_DELETE, _( "Delete Destination" ) );
299
300 menu.AppendSeparator();
301 menu.Append( wxID_VIEW_DETAILS, _( "View Last Run Log..." ) );
302
303 menu.Enable( wxID_VIEW_DETAILS, destination->m_lastRunSuccess.has_value() );
304
305 PopupMenu( &menu );
306 }
307
308 void OnProperties( wxCommandEvent& aEvent ) override
309 {
310 JOBSET_DESTINATION* destination = GetDestination();
311 wxCHECK( destination, /*void*/ );
312
313 DIALOG_DESTINATION dialog( m_frame, m_jobsFile, destination );
314
315 if( dialog.ShowModal() == wxID_OK )
316 {
317 m_textOutputType->SetLabel( destination->GetDescription() );
318 UpdatePathInfo( destination->GetPathInfo() );
321 }
322 }
323
324 virtual void OnDelete( wxCommandEvent& aEvent ) override
325 {
327 }
328
330 {
331 for( JOBSET_DESTINATION& destination : m_jobsFile->GetDestinations() )
332 {
333 if( destination.m_id == m_destinationId )
334 return &destination;
335 }
336
337 return nullptr;
338 }
339
340private:
341 void onMenu( wxCommandEvent& aEvent )
342 {
343 switch( aEvent.GetId() )
344 {
345 case wxID_EDIT:
346 {
347 wxCommandEvent dummy;
349 }
350 break;
351
352 case wxID_DELETE:
353 {
354 wxCommandEvent dummy;
355 OnDelete( dummy );
356 }
357 break;
358
359 case wxID_VIEW_DETAILS:
360 {
361 wxMouseEvent dummy;
363 }
364 break;
365
366 default:
367 wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
368 }
369 }
370
371private:
376};
377
378
380 GRID_TRICKS( aGrid ),
381 m_parent( aParent ),
382 m_doubleClickRow( -1 )
383{
386}
387
388
389void JOBS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
390{
391 wxArrayInt selectedRows = m_grid->GetSelectedRows();
392
393 menu.Append( JOB_DESCRIPTION, _( "Edit Job Description" ) );
394 menu.Append( JOB_PROPERTIES, _( "Edit Job Settings..." ) );
395 menu.AppendSeparator();
396 menu.Append( GRIDTRICKS_ID_COPY, _( "Copy" ) + "\tCtrl+C", _( "Copy selected cells to clipboard" ) );
397 menu.Append( GRIDTRICKS_ID_DELETE, _( "Delete" ) + "\tDel", _( "Delete selected jobs" ) );
398 menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All" ) + "\tCtrl+A", _( "Select all jobs" ) );
399
400 menu.Enable( JOB_DESCRIPTION, selectedRows.size() == 1 );
401 menu.Enable( JOB_PROPERTIES, selectedRows.size() == 1 );
402 menu.Enable( GRIDTRICKS_ID_DELETE, selectedRows.size() > 0 );
403
404 m_grid->PopupMenu( &menu );
405}
406
407
408void JOBS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
409{
410 wxArrayInt selectedRows = m_grid->GetSelectedRows();
411
412 if( event.GetId() == JOB_DESCRIPTION )
413 {
414 if( selectedRows.size() > 0 )
415 {
416 m_grid->SetGridCursor( selectedRows[0], 2 );
417 m_grid->EnableCellEditControl();
418 }
419 }
420 else if( event.GetId() == JOB_PROPERTIES )
421 {
422 if( selectedRows.size() > 0 )
423 m_parent->OpenJobOptionsForListItem( selectedRows[0] );
424 }
425 else if( event.GetId() == GRIDTRICKS_ID_DELETE )
426 {
427 wxCommandEvent dummy;
429 }
430 else
431 {
433 }
434}
435
436
437bool JOBS_GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent )
438{
440
441 int curr_col = aEvent.GetCol();
442 int curr_row = aEvent.GetRow();
443
444 if( ( curr_col == COL_NUMBER || curr_col == COL_SOURCE || curr_col == COL_DESCR )
445 && curr_row >= 0 && curr_row < (int) m_parent->GetJobsFile()->GetJobs().size() )
446 {
447 m_doubleClickRow = curr_row;
449
450 CallAfter(
451 [this]()
452 {
453 // Yes, again. CancelShowEditorOnMouseUp() doesn't appear to be 100%
454 // reliable.
456 int row = m_doubleClickRow;
457 m_doubleClickRow = -1;
458
459 if( row >= 0 && row < (int) m_parent->GetJobsFile()->GetJobs().size() )
461 } );
462
463 return true;
464 }
465
466 return false;
467}
468
469
470PANEL_JOBSET::PANEL_JOBSET( wxAuiNotebook* aParent, KICAD_MANAGER_FRAME* aFrame,
471 std::unique_ptr<JOBSET> aJobsFile ) :
472 PANEL_JOBSET_BASE( aParent ),
473 m_parentBook( aParent ),
474 m_frame( aFrame ),
475 m_jobsFile( std::move( aJobsFile ) )
476{
477 m_jobsGrid->PushEventHandler( new JOBS_GRID_TRICKS( this, m_jobsGrid ) );
478
479 m_jobsGrid->OverrideMinSize( 0.6, 0.3 );
480 m_jobsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
481
482 // 'm' for margins
483 m_jobsGrid->SetColSize( COL_NUMBER, GetTextExtent( wxT( "99m" ) ).x );
484 m_jobsGrid->SetColSize( COL_SOURCE, GetTextExtent( wxT( "PCBm" ) ).x );
485
486 m_buttonAddJob->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
487 m_buttonUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
488 m_buttonDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
489 m_buttonDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
490 m_buttonAddDestination->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
491
494}
495
496
498{
499 // Delete the GRID_TRICKS.
500 m_jobsGrid->PopEventHandler( true );
501}
502
503
505{
506 JOBSET_DESTINATION* output = aPanel->GetDestination();
507
508 m_destinationListSizer->Detach( aPanel );
509 aPanel->Destroy();
510
511 // ensure the window contents get shifted as needed
512 m_destinationList->Layout();
513 Layout();
514
515 m_jobsFile->RemoveDestination( output );
516}
517
518
520{
521 if( m_jobsGrid->GetNumberRows() )
522 m_jobsGrid->DeleteRows( 0, m_jobsGrid->GetNumberRows() );
523
524 m_jobsGrid->AppendRows( (int) m_jobsFile->GetJobs().size() );
525
526 int num = 1;
527
528 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
529 {
530 m_jobsGrid->SetCellValue( num - 1, COL_NUMBER, wxString::Format( "%d", num ) );
531 m_jobsGrid->SetReadOnly( num - 1, COL_NUMBER );
532
533 m_jobsGrid->SetCellValue( num - 1, COL_DESCR, job.GetDescription() );
534
535 m_jobsGrid->SetReadOnly( num - 1, COL_SOURCE );
536
537 KIWAY::FACE_T iface = JOB_REGISTRY::GetKifaceType( job.m_type );
538 wxString source = wxEmptyString;
539
540 if( iface < KIWAY::KIWAY_FACE_COUNT )
541 {
542 if( iface == KIWAY::FACE_PCB )
543 source = wxT( "PCB" );
544 else if( iface == KIWAY::FACE_SCH )
545 source = wxT( "SCH" );
546 }
547
548 m_jobsGrid->SetCellValue( num - 1, COL_SOURCE, source );
549
550 num++;
551 }
552
553 UpdateTitle();
554
555 // Ensure the outputs get their Run-ability status updated
557 panel->UpdateStatus();
558}
559
560
562{
563 wxString tabName = m_jobsFile->GetFullName();
564
565 if( m_jobsFile->GetDirty() )
566 tabName = wxS( "*" ) + tabName;
567
568 int pageIdx = m_parentBook->FindPage( this );
569
570 if( pageIdx >= 0 )
571 m_parentBook->SetPageText( pageIdx, tabName );
572}
573
574
576{
577 PANEL_DESTINATION* destinationPanel = new PANEL_DESTINATION( m_destinationList, this, m_frame,
578 m_jobsFile.get(), aOutput );
579
580#if __OSX__
581 m_outputListSizer->Add( destinationPanel, 0, wxEXPAND, 5 );
582#else
583 m_destinationListSizer->Add( destinationPanel, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
584#endif
585
586 m_destinationList->Layout();
587}
588
589
590std::vector<PANEL_DESTINATION*> PANEL_JOBSET::GetDestinationPanels()
591{
592 std::vector<PANEL_DESTINATION*> panels;
593
594 for( const wxSizerItem* item : m_destinationListSizer->GetChildren() )
595 {
596 if( PANEL_DESTINATION* panel = dynamic_cast<PANEL_DESTINATION*>( item->GetWindow() ) )
597 panels.push_back( panel );
598 }
599
600 return panels;
601}
602
603
605{
606 Freeze();
607
608 for( JOBSET_DESTINATION& job : m_jobsFile->GetDestinations() )
609 addDestinationPanel( &job );
610
611 // ensure the window contents get shifted as needed
612 Layout();
613 Thaw();
614}
615
616
618{
619 bool success = false;
620 JOBSET_JOB& job = m_jobsFile->GetJobs()[aItemIndex];
622
623 if( iface < KIWAY::KIWAY_FACE_COUNT )
624 {
626 success = m_frame->Kiway().ProcessJobConfigDialog( iface, job.m_job.get(), m_frame );
627 }
628 else
629 {
630 // special jobs
631 if( job.m_job->GetType() == "special_execute" )
632 {
633 JOB_SPECIAL_EXECUTE* specialJob = static_cast<JOB_SPECIAL_EXECUTE*>( job.m_job.get() );
634
635 DIALOG_EXECUTECOMMAND_JOB_SETTINGS dialog( m_frame, specialJob );
636
637 // QuasiModal for Scintilla autocomplete
638 if( dialog.ShowQuasiModal() == wxID_OK )
639 success = true;
640 }
641 else if( job.m_job->GetType() == "special_copyfiles" )
642 {
643 JOB_SPECIAL_COPYFILES* specialJob = static_cast<JOB_SPECIAL_COPYFILES*>( job.m_job.get() );
644 DIALOG_COPYFILES_JOB_SETTINGS dialog( m_frame, specialJob );
645
646 if( dialog.ShowModal() == wxID_OK )
647 success = true;
648 }
649 }
650
651 if( success )
652 {
653 m_jobsFile->SetDirty();
654 UpdateTitle();
655 }
656
657 // Bring the Kicad manager frame back to the front
658 m_frame->Raise();
659
660 return success;
661}
662
663
664void PANEL_JOBSET::OnGridCellChange( wxGridEvent& aEvent )
665{
666 int row = aEvent.GetRow();
667 int col = aEvent.GetCol();
668
669 if( col == COL_DESCR )
670 m_jobsFile->GetJobs()[row].SetDescription( m_jobsGrid->GetCellValue( row, col ) );
671}
672
673
674void PANEL_JOBSET::OnSaveButtonClick( wxCommandEvent& aEvent )
675{
677 return;
678
679 m_jobsFile->SaveToFile( wxEmptyString, true );
680 UpdateTitle();
681}
682
683
684void PANEL_JOBSET::OnAddJobClick( wxCommandEvent& aEvent )
685{
687 return;
688
689 wxArrayString headers;
690 std::vector<wxArrayString> items;
691
692 headers.Add( _( "Job Types" ) );
693
695
696 for( const std::pair<const wxString, JOB_REGISTRY_ENTRY>& entry : jobMap )
697 {
698 if( entry.second.deprecated )
699 continue;
700
701 wxArrayString item;
702 item.Add( wxGetTranslation( entry.second.title ) );
703 items.emplace_back( item );
704 }
705
706 EDA_LIST_DIALOG dlg( this, _( "Add New Job" ), headers, items );
707 dlg.SetListLabel( _( "Select job type:" ) );
708
709 if( dlg.ShowModal() == wxID_OK )
710 {
711 wxString selectedString = dlg.GetTextSelection();
712
713 wxString jobKey;
714
715 if( !selectedString.IsEmpty() )
716 {
717 for( const std::pair<const wxString, JOB_REGISTRY_ENTRY>& entry : jobMap )
718 {
719 if( entry.second.deprecated )
720 continue;
721
722 if( wxGetTranslation( entry.second.title ) == selectedString )
723 {
724 jobKey = entry.first;
725 break;
726 }
727 }
728 }
729
730 if( !jobKey.IsEmpty() )
731 {
732 int row = m_jobsFile->GetJobs().size();
733 bool wasDirty = m_jobsFile->GetDirty();
734 JOB* job = JOB_REGISTRY::CreateInstance<JOB>( jobKey );
735
736 m_jobsFile->AddNewJob( jobKey, job );
737
738 if( OpenJobOptionsForListItem( row ) )
739 {
741
742 m_jobsGrid->SetGridCursor( row, 2 );
743 m_jobsGrid->EnableCellEditControl();
744 }
745 else
746 {
747 m_jobsFile->RemoveJob( row );
748 m_jobsFile->SetDirty( wasDirty );
749 }
750 }
751 }
752}
753
754
755void PANEL_JOBSET::OnJobButtonDelete( wxCommandEvent& aEvent )
756{
758 [&]( int row )
759 {
760 m_jobsFile->RemoveJob( row );
761 m_jobsGrid->DeleteRows( row, 1 );
762 } );
763}
764
765
766void PANEL_JOBSET::OnAddDestinationClick( wxCommandEvent& aEvent )
767{
768 wxArrayString headers;
769 std::vector<wxArrayString> items;
770
771 headers.Add( _( "Destination Types" ) );
772
773 for( const auto& [destinationType, destinationTypeInfo] : JobsetDestinationTypeInfos )
774 {
775 wxArrayString item;
776 item.Add( wxGetTranslation( destinationTypeInfo.name ) );
777 items.emplace_back( item );
778 }
779
780 EDA_LIST_DIALOG dlg( this, _( "Add New Destination" ), headers, items );
781 dlg.SetListLabel( _( "Select destination type:" ) );
782 dlg.HideFilter();
783
784 if( dlg.ShowModal() == wxID_OK )
785 {
786 wxString selectedString = dlg.GetTextSelection();
787
788 for( const auto& [destinationType, destinationTypeInfo] : JobsetDestinationTypeInfos )
789 {
790 if( wxGetTranslation( destinationTypeInfo.name ) == selectedString )
791 {
792 JOBSET_DESTINATION* destination = m_jobsFile->AddNewDestination( destinationType );
793
794 DIALOG_DESTINATION dialog( m_frame, m_jobsFile.get(), destination );
795
796 if (dialog.ShowModal() == wxID_OK)
797 {
798 Freeze();
799 addDestinationPanel( destination );
800 Thaw();
801 }
802 else
803 {
804 // canceled
805 m_jobsFile->RemoveDestination( destination );
806 }
807 }
808 }
809 }
810}
811
812
814{
815 if( m_jobsFile->GetDirty() )
816 {
817 wxFileName fileName = m_jobsFile->GetFullFilename();
818 wxString msg = _( "Save changes to '%s' before closing?" );
819
820 if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
821 [&]() -> bool
822 {
823 return m_jobsFile->SaveToFile( wxEmptyString, true );
824 } ) )
825 {
826 return false;
827 }
828 }
829
830 return true;
831}
832
833
835{
837 KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_PCB_EDITOR, false );
838
839 if( !frame )
840 {
841 frame = m_frame->Kiway().Player( FRAME_PCB_EDITOR, true );
842
843 // frame can be null if Cvpcb cannot be run. No need to show a warning
844 // Kiway() generates the error messages
845 if( !frame )
846 return;
847
848 wxFileName boardfn = project.GetProjectFullName();
849 boardfn.SetExt( FILEEXT::PcbFileExtension );
850
851 // Prevent our window from being closed during the open process
852 wxEventBlocker blocker( this );
853
854 frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
855
856 if( !frame->IsVisible() )
857 frame->Show( true );
858 }
859
860 frame = m_frame->Kiway().Player( FRAME_SCH, false );
861
862 if( !frame )
863 {
864 frame = m_frame->Kiway().Player( FRAME_SCH, true );
865
866 // frame can be null if Cvpcb cannot be run. No need to show a warning
867 // Kiway() generates the error messages
868 if( !frame )
869 return;
870
871 wxFileName schFn = project.GetProjectFullName();
873
874 wxEventBlocker blocker( this );
875
876 frame->OpenProjectFiles( std::vector<wxString>( 1, schFn.GetFullPath() ) );
877
878 if( !frame->IsVisible() )
879 frame->Show( true );
880 }
881
882 SetFocus();
883}
884
885
887{
888 return m_jobsFile->GetFullFilename();
889}
890
891
892void PANEL_JOBSET::OnJobButtonUp( wxCommandEvent& aEvent )
893{
895 return;
896
897 int item = m_jobsGrid->GetGridCursorRow();
898
899 if( item > 0 )
900 {
901 m_jobsFile->MoveJobUp( item );
902
904
905 m_jobsGrid->SelectRow( item - 1 );
906 m_jobsGrid->SetGridCursor( item - 1, m_jobsGrid->GetGridCursorCol() );
907 }
908 else
909 {
910 wxBell();
911 }
912}
913
914
915void PANEL_JOBSET::OnJobButtonDown( wxCommandEvent& aEvent )
916{
918 return;
919
920 int item = m_jobsGrid->GetGridCursorRow();
921
922 if( item < m_jobsGrid->GetNumberRows() - 1 )
923 {
924 m_jobsFile->MoveJobDown( item );
925
927
928 m_jobsGrid->SelectRow( item + 1 );
929 m_jobsGrid->SetGridCursor( item + 1, m_jobsGrid->GetGridCursorCol() );
930 }
931 else
932 {
933 wxBell();
934 }
935}
936
937
939{
941 return;
942
943 // sanity
944 if( m_jobsFile->GetDestinations().empty() )
945 {
946 DisplayError( this, _( "No destinations defined" ) );
947 return;
948 }
949
951 panel->ClearStatus();
952
953 Refresh();
954
955 CallAfter(
956 [this]()
957 {
960
961 wxFileName fn = project.GetProjectFullName();
962 wxSetWorkingDirectory( fn.GetPath() );
963
964 {
965 JOBS_PROGRESS_REPORTER progressReporter( m_frame, _( "Running Jobs" ) );
966 JOBS_RUNNER jobRunner( &m_frame->Kiway(), m_jobsFile.get(), &project,
967 NULL_REPORTER::GetInstance(), &progressReporter );
968
969 jobRunner.RunJobsAllDestinations();
970
972 panel->UpdateStatus();
973 }
974
975 // Bring the Kicad manager frame back to the front
976 m_frame->Raise();
977 } );
978}
979
980
981void PANEL_JOBSET::OnSizeGrid( wxSizeEvent& aEvent )
982{
983 m_jobsGrid->SetColSize( COL_DESCR, m_jobsGrid->GetSize().x - m_jobsGrid->GetColSize( COL_SOURCE )
984 - m_jobsGrid->GetColSize( COL_NUMBER ) );
985
986 // Always propagate for a grid repaint (needed if the height changes, as well as width)
987 aEvent.Skip();
988}
989
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
Class DIALOG_JOBSET_RUN_LOG_BASE.
wxStaticText * m_staticTextOutputName
void OnJobListItemSelected(wxListEvent &event) override
DIALOG_JOBSET_RUN_LOG(wxWindow *aParent, JOBSET *aJobsFile, JOBSET_DESTINATION *aDestination)
JOBSET_DESTINATION * m_destination
virtual void OnUpdateUI(wxUpdateUIEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowQuasiModal()
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
A dialog which shows:
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
bool m_multiCellEditEnabled
Definition: grid_tricks.h:142
bool m_enableSingleClickEdit
Definition: grid_tricks.h:141
virtual void doPopupSelection(wxCommandEvent &event)
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:128
Definition: jobset.h:144
std::vector< JOBSET_DESTINATION > & GetDestinations()
Definition: jobset.h:157
void SetDirty(bool aFlag=true)
Definition: jobset.h:167
std::vector< JOBSET_JOB > GetJobsForDestination(JOBSET_DESTINATION *aDestination)
Definition: jobset.cpp:307
std::vector< JOBSET_JOB > & GetJobs()
Definition: jobset.h:150
PANEL_JOBSET * m_parent
Definition: panel_jobset.h:63
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
void doPopupSelection(wxCommandEvent &event) override
bool handleDoubleClick(wxGridEvent &aEvent) override
JOBS_GRID_TRICKS(PANEL_JOBSET *aParent, WX_GRID *aGrid)
bool RunJobsAllDestinations(bool aBail=false)
Definition: jobs_runner.cpp:48
bool RunJobsForDestination(JOBSET_DESTINATION *aDestination, bool aBail=false)
static const REGISTRY_MAP_T & GetRegistry()
Definition: job_registry.h:55
std::unordered_map< wxString, JOB_REGISTRY_ENTRY > REGISTRY_MAP_T
Definition: job_registry.h:38
static KIWAY::FACE_T GetKifaceType(const wxString &aName)
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:183
The main KiCad project manager frame.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:113
bool ProcessJobConfigDialog(KIWAY::FACE_T aFace, JOB *aJob, wxWindow *aWindow)
Definition: kiway.cpp:686
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:395
FACE_T
Known KIFACE implementations.
Definition: kiway.h:292
@ KIWAY_FACE_COUNT
Definition: kiway.h:302
@ FACE_SCH
eeschema DSO
Definition: kiway.h:293
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:294
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:192
static REPORTER & GetInstance()
Definition: reporter.cpp:108
Class PANEL_DESTINATION_BASE.
wxStaticBitmap * m_statusBitmap
STD_BITMAP_BUTTON * m_buttonProperties
STD_BITMAP_BUTTON * m_buttonDelete
wxStaticBitmap * m_bitmapOutputType
wxStaticText * m_textOutputType
void onMenu(wxCommandEvent &aEvent)
JOBSET_DESTINATION * GetDestination()
void UpdatePathInfo(const wxString &aMsg)
PANEL_DESTINATION(wxWindow *aParent, PANEL_JOBSET *aPanelParent, KICAD_MANAGER_FRAME *aFrame, JOBSET *aFile, JOBSET_DESTINATION *aDestination)
wxString m_destinationId
virtual void OnDelete(wxCommandEvent &aEvent) override
virtual void OnLastStatusClick(wxMouseEvent &aEvent) override
virtual void OnGenerate(wxCommandEvent &event) override
void OnRightDown(wxMouseEvent &aEvent) override
KICAD_MANAGER_FRAME * m_frame
void OnProperties(wxCommandEvent &aEvent) override
PANEL_JOBSET * m_panelParent
Class PANEL_JOBSET_BASE.
STD_BITMAP_BUTTON * m_buttonAddDestination
STD_BITMAP_BUTTON * m_buttonDown
wxScrolledWindow * m_destinationList
wxBoxSizer * m_destinationListSizer
STD_BITMAP_BUTTON * m_buttonAddJob
STD_BITMAP_BUTTON * m_buttonDelete
STD_BITMAP_BUTTON * m_buttonUp
wxString GetFilePath() const
JOBSET * GetJobsFile()
Definition: panel_jobset.h:83
virtual void OnSaveButtonClick(wxCommandEvent &aEvent) override
void OnJobButtonDelete(wxCommandEvent &aEvent) override
virtual void OnJobButtonDown(wxCommandEvent &aEvent) override
void EnsurePcbSchFramesOpen()
bool GetCanClose() override
void rebuildJobList()
wxAuiNotebook * m_parentBook
Definition: panel_jobset.h:108
void addDestinationPanel(JOBSET_DESTINATION *aDestination)
void UpdateTitle()
virtual void OnGenerateAllDestinationsClick(wxCommandEvent &event) override
bool OpenJobOptionsForListItem(size_t aItemIndex)
std::vector< PANEL_DESTINATION * > GetDestinationPanels()
void buildDestinationList()
KICAD_MANAGER_FRAME * m_frame
Definition: panel_jobset.h:109
PANEL_JOBSET(wxAuiNotebook *aParent, KICAD_MANAGER_FRAME *aFrame, std::unique_ptr< JOBSET > aJobsFile)
virtual void OnAddDestinationClick(wxCommandEvent &aEvent) override
virtual void OnAddJobClick(wxCommandEvent &aEvent) override
std::unique_ptr< JOBSET > m_jobsFile
Definition: panel_jobset.h:110
virtual void OnGridCellChange(wxGridEvent &aEvent) override
void RemoveDestination(PANEL_DESTINATION *aPanel)
virtual void OnJobButtonUp(wxCommandEvent &aEvent) override
virtual void OnSizeGrid(wxSizeEvent &aEvent) override
Container for project specific data.
Definition: project.h:65
void SetBitmap(const wxBitmapBundle &aBmp)
void OverrideMinSize(double aXPct, double aYPct)
Grids that have column sizes automatically set to fill the available width don't want to shrink after...
Definition: wx_grid.h:242
bool CancelPendingChanges()
Definition: wx_grid.cpp:604
void CancelShowEditorOnMouseUp()
Definition: wx_grid.h:213
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition: wx_grid.cpp:704
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:632
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:129
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:169
This file is part of the common library.
#define _(s)
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
@ FRAME_SCH
Definition: frame_type.h:34
@ GRIDTRICKS_ID_SELECT
Definition: grid_tricks.h:46
@ GRIDTRICKS_ID_COPY
Definition: grid_tricks.h:43
@ GRIDTRICKS_ID_DELETE
Definition: grid_tricks.h:44
static const std::string KiCadSchematicFileExtension
Some functions to handle hotkeys in KiCad.
KICOMMON_API std::map< JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition: jobset.cpp:40
PROJECT & Prj()
Definition: kicad.cpp:608
#define KICOMMON_API
Definition: kicommon.h:28
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:162
STL namespace.
KICOMMON_API std::map< JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition: jobset.cpp:40
@ COL_NUMBER
Definition: panel_jobset.h:36
@ COL_DESCR
Definition: panel_jobset.h:38
@ COL_SOURCE
Definition: panel_jobset.h:37
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< FAB_LAYER_COLOR > dummy
std::unordered_map< wxString, std::shared_ptr< JOBSET_OUTPUT_REPORTER > > m_lastRunReporters
Definition: jobset.h:139
JOBSET_DESTINATION_T m_type
Definition: jobset.h:131
wxString GetPathInfo() const
Definition: jobset.cpp:157
wxString GetDescription() const
Definition: jobset.cpp:151
std::optional< bool > m_lastRunSuccess
Definition: jobset.h:137
std::unordered_map< wxString, std::optional< bool > > m_lastRunSuccessMap
Definition: jobset.h:138
std::shared_ptr< JOB > m_job
Definition: jobset.h:87
wxString m_type
Definition: jobset.h:85
Definition of file extensions used in Kicad.