diff --git a/common/design_block.h b/common/design_block.h index a08b172ad3..f3a1fd9c4f 100644 --- a/common/design_block.h +++ b/common/design_block.h @@ -48,12 +48,8 @@ public: const wxString& GetBoardFile() const { return m_boardFile; } void SetBoardFile( const wxString& aFile ) { m_boardFile = aFile; } - void SetFields( nlohmann::ordered_map& aFields ) - { - m_fields = std::move( aFields ); - } - const nlohmann::ordered_map& GetFields() const { return m_fields; } + nlohmann::ordered_map& GetFields() { return m_fields; } DESIGN_BLOCK() = default; diff --git a/common/design_block_io.cpp b/common/design_block_io.cpp index 2fd2ed875f..d38d9ee288 100644 --- a/common/design_block_io.cpp +++ b/common/design_block_io.cpp @@ -325,8 +325,6 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath, if( dbMetadata.contains( "keywords" ) ) newDB->SetKeywords( dbMetadata["keywords"] ); - nlohmann::ordered_map fields; - // Read the "fields" object from the JSON if( dbMetadata.contains( "fields" ) ) { @@ -335,10 +333,8 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath, wxString name = wxString::FromUTF8( item.key() ); wxString value = wxString::FromUTF8( item.value().get() ); - fields[name] = value; + newDB->GetFields()[name] = value; } - - newDB->SetFields( fields ); } } catch( ... ) diff --git a/common/dialogs/dialog_design_block_properties.cpp b/common/dialogs/dialog_design_block_properties.cpp index 6a3a0b9982..07b1a0648f 100644 --- a/common/dialogs/dialog_design_block_properties.cpp +++ b/common/dialogs/dialog_design_block_properties.cpp @@ -194,7 +194,7 @@ bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataFromGrid() if( !m_fieldsGrid->CommitPendingChanges() ) return false; - nlohmann::ordered_map newFields; + m_designBlock->GetFields().clear(); for( int row = 0; row < m_fieldsGrid->GetNumberRows(); row++ ) { @@ -202,17 +202,15 @@ bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataFromGrid() fieldName.Replace( wxT( "\n" ), wxT( "" ), true ); // strip all newlines fieldName.Replace( wxT( " " ), wxT( " " ), true ); // double space to single - if( newFields.count( fieldName ) ) + if( m_designBlock->GetFields().count( fieldName ) ) { wxMessageBox( _( "Duplicate fields are not allowed." ) ); return false; } - newFields[fieldName] = m_fieldsGrid->GetCellValue( row, 1 ); + m_designBlock->GetFields()[fieldName] = m_fieldsGrid->GetCellValue( row, 1 ); } - m_designBlock->SetFields( newFields ); - return true; } diff --git a/cvpcb/dialogs/dialog_config_equfiles.cpp b/cvpcb/dialogs/dialog_config_equfiles.cpp index 29d3063918..66627fc72a 100644 --- a/cvpcb/dialogs/dialog_config_equfiles.cpp +++ b/cvpcb/dialogs/dialog_config_equfiles.cpp @@ -194,10 +194,13 @@ void DIALOG_CONFIG_EQUFILES::OnRemoveFiles( wxCommandEvent& event ) wxArrayInt selections; m_filesListBox->GetSelections( selections ); - std::sort( selections.begin(), selections.end() ); + if( !selections.empty() ) + { + std::sort( selections.begin(), selections.end() ); - for( int ii = selections.GetCount()-1; ii >= 0; ii-- ) - m_filesListBox->Delete( selections[ii] ); + for( int ii = (int) selections.GetCount() - 1; ii >= 0; ii-- ) + m_filesListBox->Delete( selections[ii] ); + } } diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index f1f8383180..820fb88527 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -1041,59 +1041,62 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnPageChanging( wxBookCtrlEvent& aEvent ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnCreateJumperPinGroup( wxCommandEvent& aEvent ) { wxArrayInt selections; - int n = m_listAvailablePins->GetSelections( selections ); - wxCHECK( n > 0, /* void */ ); + m_listAvailablePins->GetSelections( selections ); - m_listJumperPinGroups->Freeze(); - m_listAvailablePins->Freeze(); - - wxString group; - int i = 0; - - for( int idx : selections ) + if( !selections.empty() ) { - group << m_listAvailablePins->GetString( idx ); + m_listJumperPinGroups->Freeze(); + m_listAvailablePins->Freeze(); - if( ++i < n ) - group << ", "; + wxString group; + int i = 0; + + for( int idx : selections ) + { + group << m_listAvailablePins->GetString( idx ); + + if( ++i < selections.Count() ) + group << ", "; + } + + for( int idx = (int) selections.size() - 1; idx >= 0; --idx ) + m_listAvailablePins->Delete( selections[idx] ); + + m_listJumperPinGroups->AppendString( group ); + + m_listJumperPinGroups->Thaw(); + m_listAvailablePins->Thaw(); } - - for( int idx = selections.size() - 1; idx >= 0; --idx ) - m_listAvailablePins->Delete( selections[idx] ); - - m_listJumperPinGroups->AppendString( group ); - - m_listJumperPinGroups->Thaw(); - m_listAvailablePins->Thaw(); } void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnRemoveJumperPinGroup( wxCommandEvent& aEvent ) { wxArrayInt selections; + m_listJumperPinGroups->GetSelections( selections ); - if( m_listJumperPinGroups->GetSelections( selections ) <= 0 ) - return; - - m_listJumperPinGroups->Freeze(); - m_listAvailablePins->Freeze(); - - for( int idx : selections ) + if( !selections.empty() ) { - wxStringTokenizer tokenizer( m_listJumperPinGroups->GetString( idx ), ", " ); + m_listJumperPinGroups->Freeze(); + m_listAvailablePins->Freeze(); - while( tokenizer.HasMoreTokens() ) + for( int idx : selections ) { - if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() ) - m_listAvailablePins->AppendString( token ); + wxStringTokenizer tokenizer( m_listJumperPinGroups->GetString( idx ), ", " ); + + while( tokenizer.HasMoreTokens() ) + { + if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() ) + m_listAvailablePins->AppendString( token ); + } } + + for( int idx = (int) selections.size() - 1; idx >= 0; --idx ) + m_listJumperPinGroups->Delete( selections[idx] ); + + m_listJumperPinGroups->Thaw(); + m_listAvailablePins->Thaw(); } - - for( int idx = selections.size() - 1; idx >= 0; --idx ) - m_listJumperPinGroups->Delete( selections[idx] ); - - m_listJumperPinGroups->Thaw(); - m_listAvailablePins->Thaw(); } diff --git a/eeschema/sch_design_block_utils.cpp b/eeschema/sch_design_block_utils.cpp index fdda03e868..79a7483ab2 100644 --- a/eeschema/sch_design_block_utils.cpp +++ b/eeschema/sch_design_block_utils.cpp @@ -98,19 +98,14 @@ bool SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName, SCH_S blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) ); // Copy all fields from the sheet to the design block - std::vector& shFields = aSheetPath.Last()->GetFields(); - nlohmann::ordered_map dbFields; - - for( SCH_FIELD& f : shFields ) + for( SCH_FIELD& field : aSheetPath.Last()->GetFields() ) { - if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME ) + if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME ) continue; - dbFields[f.GetCanonicalName()] = f.GetText(); + blk.GetFields()[field.GetCanonicalName()] = field.GetText(); } - blk.SetFields( dbFields ); - DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk ); if( dlg.ShowModal() != wxID_OK ) @@ -191,19 +186,14 @@ bool SCH_EDIT_FRAME::SaveSheetToDesignBlock( const LIB_ID& aLibId, SCH_SHEET_PAT // Copy all fields from the sheet to the design block. // Note: this will overwrite any existing fields in the design block, but // will leave extra fields not in this source sheet alone. - std::vector& shFields = aSheetPath.Last()->GetFields(); - nlohmann::ordered_map dbFields = blk->GetFields(); - - for( SCH_FIELD& f : shFields ) + for( SCH_FIELD& field : aSheetPath.Last()->GetFields() ) { - if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME ) + if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME ) continue; - dbFields[f.GetCanonicalName()] = f.GetText(); + blk->GetFields()[field.GetCanonicalName()] = field.GetText(); } - blk->SetFields( dbFields ); - DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, blk.get(), true ); if( dlg.ShowModal() != wxID_OK ) diff --git a/eeschema/sync_sheet_pin/sheet_synchronization_model.cpp b/eeschema/sync_sheet_pin/sheet_synchronization_model.cpp index a46f076b92..0ac2d7a30e 100644 --- a/eeschema/sync_sheet_pin/sheet_synchronization_model.cpp +++ b/eeschema/sync_sheet_pin/sheet_synchronization_model.cpp @@ -39,11 +39,11 @@ extern wxString getElectricalTypeLabel( LABEL_FLAG_SHAPE aType ); SHEET_SYNCHRONIZATION_MODEL::SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET* aSheet, - SCH_SHEET_PATH& aPath ) : + const SCH_SHEET_PATH& aPath ) : m_selectedIndex( std::optional() ), m_agent( aAgent ), m_sheet( aSheet ), - m_path( std::move( aPath ) ) + m_path( aPath ) { } diff --git a/eeschema/sync_sheet_pin/sheet_synchronization_model.h b/eeschema/sync_sheet_pin/sheet_synchronization_model.h index 07fc2672ac..a43d309b27 100644 --- a/eeschema/sync_sheet_pin/sheet_synchronization_model.h +++ b/eeschema/sync_sheet_pin/sheet_synchronization_model.h @@ -71,7 +71,7 @@ public: SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET* aSheet, - SCH_SHEET_PATH& aPath ); + const SCH_SHEET_PATH& aPath ); ~SHEET_SYNCHRONIZATION_MODEL() override; void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override; diff --git a/include/singleton.h b/include/singleton.h index c9c1ef3991..ff3713edd0 100644 --- a/include/singleton.h +++ b/include/singleton.h @@ -31,14 +31,18 @@ class thread_pool; class KICAD_SINGLETON { public: - KICAD_SINGLETON(){}; + KICAD_SINGLETON() : + m_ThreadPool( nullptr ), + m_GLContextManager( nullptr ) + {}; ~KICAD_SINGLETON(); void Init(); - BS::thread_pool* m_ThreadPool; +public: + BS::thread_pool* m_ThreadPool; GL_CONTEXT_MANAGER* m_GLContextManager; };