diff --git a/common/marker_base.cpp b/common/marker_base.cpp index 165a0e04a5..008f8d1473 100644 --- a/common/marker_base.cpp +++ b/common/marker_base.cpp @@ -59,7 +59,7 @@ static const VECTOR2I MarkerShapeCorners[] = const unsigned CORNERS_COUNT = arrayDim( MarkerShapeCorners ); -MARKER_BASE::MARKER_BASE( int aScalingFactor, RC_ITEM* aItem, TYPEMARKER aType ) : +MARKER_BASE::MARKER_BASE( int aScalingFactor, std::shared_ptr aItem, TYPEMARKER aType ) : m_markerType( aType ), m_excluded( false ), m_rcItem( aItem ), @@ -85,8 +85,6 @@ MARKER_BASE::MARKER_BASE( int aScalingFactor, RC_ITEM* aItem, TYPEMARKER aType ) MARKER_BASE::~MARKER_BASE() { - printf("del rcitem %p\n", m_rcItem ); - delete m_rcItem; } diff --git a/common/rc_item.cpp b/common/rc_item.cpp index 7248186009..3d7eabce76 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -94,7 +94,7 @@ KIID RC_TREE_MODEL::ToUUID( wxDataViewItem aItem ) if( node ) { - const RC_ITEM* rc_item = node->m_RcItem; + const std::shared_ptr rc_item = node->m_RcItem; switch( node->m_Type ) { @@ -142,7 +142,7 @@ void RC_TREE_MODEL::rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities { wxWindowUpdateLocker updateLock( m_view ); - RC_ITEM* selectedRcItem = nullptr; + std::shared_ptr selectedRcItem = nullptr; if( m_view ) { @@ -170,7 +170,7 @@ void RC_TREE_MODEL::rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities for( int i = 0; m_rcItemsProvider && i < m_rcItemsProvider->GetCount(); ++i ) { - RC_ITEM* rcItem = m_rcItemsProvider->GetItem( i ); + std::shared_ptr rcItem = m_rcItemsProvider->GetItem( i ); m_tree.push_back( new RC_TREE_NODE( nullptr, rcItem, RC_TREE_NODE::MARKER ) ); RC_TREE_NODE* n = m_tree.back(); @@ -279,7 +279,7 @@ void RC_TREE_MODEL::GetValue( wxVariant& aVariant, unsigned int aCol ) const { const RC_TREE_NODE* node = ToNode( aItem ); - const RC_ITEM* rcItem = node->m_RcItem; + const std::shared_ptr rcItem = node->m_RcItem; switch( node->m_Type ) { @@ -394,7 +394,7 @@ void RC_TREE_MODEL::DeleteCurrentItem( bool aDeep ) void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep ) { RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() ); - const RC_ITEM* current_item = current_node ? current_node->m_RcItem : nullptr; + const std::shared_ptr current_item = current_node ? current_node->m_RcItem : nullptr; if( aCurrentOnly && !current_item ) { @@ -404,7 +404,7 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i ) { - RC_ITEM* rcItem = m_rcItemsProvider->GetItem( i ); + std::shared_ptr rcItem = m_rcItemsProvider->GetItem( i ); MARKER_BASE* marker = rcItem->GetParent(); bool excluded = marker ? marker->IsExcluded() : false; diff --git a/common/rc_item.h b/common/rc_item.h index dcd1f6bd6b..a49e7647a6 100644 --- a/common/rc_item.h +++ b/common/rc_item.h @@ -50,7 +50,7 @@ public: * Function GetItem * retrieves a RC_ITEM by index. */ - virtual RC_ITEM* GetItem( int aIndex ) = 0; + virtual std::shared_ptr GetItem( int aIndex ) = 0; /** * Function DeleteItem @@ -95,7 +95,7 @@ public: { } - RC_ITEM( RC_ITEM* aItem ) + RC_ITEM( std::shared_ptr aItem ) { m_errorCode = aItem->m_errorCode; m_errorMessage = aItem->m_errorMessage; @@ -185,7 +185,7 @@ class RC_TREE_NODE public: enum NODE_TYPE { MARKER, MAIN_ITEM, AUX_ITEM, AUX_ITEM2, AUX_ITEM3 }; - RC_TREE_NODE( RC_TREE_NODE* aParent, RC_ITEM* aRcItem, NODE_TYPE aType ) : + RC_TREE_NODE( RC_TREE_NODE* aParent, std::shared_ptr aRcItem, NODE_TYPE aType ) : m_Type( aType ), m_RcItem( aRcItem ), m_Parent( aParent ) @@ -198,7 +198,7 @@ public: } NODE_TYPE m_Type; - RC_ITEM* m_RcItem; + std::shared_ptr m_RcItem; RC_TREE_NODE* m_Parent; std::vector m_Children; diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index aee6eebf85..2f16e0ce3d 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -172,7 +172,7 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCreateMarkers ) static_cast( candidates[0] )->GetTransformedPosition() : candidates[0]->GetPosition(); - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_DRIVER_CONFLICT ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_DRIVER_CONFLICT ); ercItem->SetItems( candidates[0], second_item ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pos ); @@ -2118,7 +2118,7 @@ bool CONNECTION_GRAPH::ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSu if( net_item && bus_item ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_BUS_TO_NET_CONFLICT ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_BUS_TO_NET_CONFLICT ); ercItem->SetItems( net_item, bus_item ); SCH_MARKER* marker = new SCH_MARKER( ercItem, net_item->GetPosition() ); @@ -2186,7 +2186,7 @@ bool CONNECTION_GRAPH::ercCheckBusToBusConflicts( const CONNECTION_SUBGRAPH* aSu if( !match ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_BUS_TO_BUS_CONFLICT ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_BUS_TO_BUS_CONFLICT ); ercItem->SetItems( label, port ); SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() ); @@ -2266,7 +2266,7 @@ bool CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts( const CONNECTION_SUBGRAPH if( conflict ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_CONFLICT ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_CONFLICT ); ercItem->SetItems( bus_entry, bus_wire ); SCH_MARKER* marker = new SCH_MARKER( ercItem, bus_entry->GetPosition() ); @@ -2319,7 +2319,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph if( pin && has_invalid_items ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED ); ercItem->SetItems( pin ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetTransformedPosition() ); @@ -2330,7 +2330,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph if( !has_other_items ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_NOT_CONNECTED ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_NOT_CONNECTED ); ercItem->SetItems( aSubgraph->m_no_connect ); SCH_MARKER* marker = new SCH_MARKER( ercItem, aSubgraph->m_no_connect->GetPosition() ); @@ -2385,7 +2385,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph if( pin && !has_other_connections && pin->GetType() != ELECTRICAL_PINTYPE::PT_NC ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_CONNECTED ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_CONNECTED ); ercItem->SetItems( pin ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetTransformedPosition() ); @@ -2479,7 +2479,7 @@ bool CONNECTION_GRAPH::ercCheckLabels( const CONNECTION_SUBGRAPH* aSubgraph ) if( !has_other_connections ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( is_global ? ERCE_GLOBLABEL : ERCE_LABEL_NOT_CONNECTED ); + std::shared_ptr ercItem = ERC_ITEM::Create( is_global ? ERCE_GLOBLABEL : ERCE_LABEL_NOT_CONNECTED ); ercItem->SetItems( text ); SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() ); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index e373859b0f..1dd660c4ca 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -315,7 +315,7 @@ void DIALOG_ERC::TestErc( REPORTER& aReporter ) pin_to_net_map[pin_name], item->GetNetName() ); - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET ); ercItem->SetErrorMessage( msg ); ercItem->SetItems( item->m_Comp ); @@ -419,7 +419,7 @@ void DIALOG_ERC::OnERCItemRClick( wxDataViewEvent& aEvent ) ERC_SETTINGS& settings = m_parent->Schematic().ErcSettings(); - RC_ITEM* rcItem = node->m_RcItem; + std::shared_ptr rcItem = node->m_RcItem; wxString listName; wxMenu menu; wxString msg; diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 06acf79abe..2d82d07946 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -51,7 +51,7 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : m_pinToPinError = ERC_ITEM::Create( ERCE_PIN_TO_PIN_WARNING ); m_severities = new PANEL_SETUP_SEVERITIES( this, ERC_ITEM::GetItemsWithSeverities(), schematic.ErcSettings().m_Severities, - m_pinToPinError ); + m_pinToPinError.get() ); m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() ); @@ -87,8 +87,6 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP() { - delete m_pinToPinError; - m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_schematic_setup.h b/eeschema/dialogs/dialog_schematic_setup.h index 1e258e304d..c1d2e621ef 100644 --- a/eeschema/dialogs/dialog_schematic_setup.h +++ b/eeschema/dialogs/dialog_schematic_setup.h @@ -50,7 +50,7 @@ protected: PANEL_SETUP_SEVERITIES* m_severities; PANEL_SETUP_NETCLASSES* m_netclasses; PANEL_TEXT_VARIABLES* m_textVars; - ERC_ITEM* m_pinToPinError; + std::shared_ptr m_pinToPinError; std::vector m_macHack; diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index e8b7fe689a..632f7b5cd7 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -127,7 +127,7 @@ int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker ) { if( aCreateMarker ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_SHEET_NAME ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_SHEET_NAME ); ercItem->SetItems( sheet, test_item ); SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() ); @@ -178,7 +178,7 @@ void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) pos = component->GetTransform().TransformCoordinate( pos ); pos += component->GetPosition(); - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( &field ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pos ); @@ -194,7 +194,7 @@ void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { if( unresolved( field.GetShownText() ) ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( &field ); SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() ); @@ -206,7 +206,7 @@ void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { if( pin->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( pin ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() ); @@ -218,7 +218,7 @@ void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( text ); SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() ); @@ -233,7 +233,7 @@ void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() ); @@ -268,7 +268,7 @@ int ERC_TESTER::TestConflictingBusAliases() alias->GetParent()->GetFileName(), test->GetParent()->GetFileName() ); - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT ); ercItem->SetErrorMessage( msg ); SCH_MARKER* marker = new SCH_MARKER( ercItem, wxPoint() ); @@ -336,7 +336,7 @@ int ERC_TESTER::TestMultiunitFootprints() msg.Printf( _( "Different footprints assigned to %s and %s" ), unitName, secondName ); - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP ); ercItem->SetErrorMessage( msg ); ercItem->SetItems( unit, secondUnit ); @@ -368,7 +368,7 @@ void ERC_TESTER::diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItem { if( settings.GetSeverity( ERCE_PIN_NOT_DRIVEN ) != RPT_SEVERITY_IGNORE ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_DRIVEN ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_DRIVEN ); ercItem->SetItems( pin ); SCH_MARKER* marker = new SCH_MARKER( ercItem, aNetItemRef->m_Start ); @@ -382,7 +382,7 @@ void ERC_TESTER::diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItem { if( settings.GetSeverity( ERCE_PIN_TO_PIN_WARNING ) != RPT_SEVERITY_IGNORE ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( + std::shared_ptr ercItem = ERC_ITEM::Create( aDiag == PIN_ERROR::PP_ERROR ? ERCE_PIN_TO_PIN_ERROR : ERCE_PIN_TO_PIN_WARNING ); ercItem->SetItems( pin, static_cast( aNetItemTst->m_Comp ) ); @@ -557,7 +557,7 @@ int ERC_TESTER::TestNoConnectPins() { err_count++; - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED ); ercItem->SetItems( pair.second[0], pair.second[1], pair.second.size() > 2 ? pair.second[2] : nullptr, @@ -763,7 +763,7 @@ static int countIndenticalLabels( std::vector& aList, NETLIST_O // Helper function: creates a marker for similar labels ERC warning static void SimilarLabelsDiagnose( NETLIST_OBJECT* aItemA, NETLIST_OBJECT* aItemB ) { - ERC_ITEM* ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS ); + std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS ); ercItem->SetItems( aItemA->m_Comp, aItemB->m_Comp ); SCH_MARKER* marker = new SCH_MARKER( ercItem, aItemA->m_Start ); diff --git a/eeschema/erc_item.cpp b/eeschema/erc_item.cpp index 4063f89e09..f8ff959c26 100644 --- a/eeschema/erc_item.cpp +++ b/eeschema/erc_item.cpp @@ -141,73 +141,76 @@ std::vector> ERC_ITEM::allItemTypes( { -ERC_ITEM* ERC_ITEM::Create( int aErrorCode ) +std::shared_ptr ERC_ITEM::Create( int aErrorCode ) { + ERC_ITEM *item; switch( aErrorCode ) { case ERCE_DUPLICATE_SHEET_NAME: - return new ERC_ITEM( duplicateSheetName ); + item = new ERC_ITEM( duplicateSheetName ); break; case ERCE_PIN_NOT_CONNECTED: - return new ERC_ITEM( pinNotConnected ); + item = new ERC_ITEM( pinNotConnected ); break; case ERCE_PIN_NOT_DRIVEN: - return new ERC_ITEM( pinNotDriven ); + item = new ERC_ITEM( pinNotDriven ); break; case ERCE_PIN_TO_PIN_WARNING: - return new ERC_ITEM( pinTableWarning ); + item = new ERC_ITEM( pinTableWarning ); break; case ERCE_PIN_TO_PIN_ERROR: - return new ERC_ITEM( pinTableError ); + item = new ERC_ITEM( pinTableError ); break; case ERCE_HIERACHICAL_LABEL: - return new ERC_ITEM( hierLabelMismatch ); + item = new ERC_ITEM( hierLabelMismatch ); break; case ERCE_NOCONNECT_CONNECTED: - return new ERC_ITEM( noConnectConnected ); + item = new ERC_ITEM( noConnectConnected ); break; case ERCE_NOCONNECT_NOT_CONNECTED: - return new ERC_ITEM( noConnectDangling ); + item = new ERC_ITEM( noConnectDangling ); break; case ERCE_LABEL_NOT_CONNECTED: - return new ERC_ITEM( labelDangling ); + item = new ERC_ITEM( labelDangling ); break; case ERCE_SIMILAR_LABELS: - return new ERC_ITEM( similarLabels ); + item = new ERC_ITEM( similarLabels ); break; case ERCE_DIFFERENT_UNIT_FP: - return new ERC_ITEM( differentUnitFootprint ); + item = new ERC_ITEM( differentUnitFootprint ); break; case ERCE_DIFFERENT_UNIT_NET: - return new ERC_ITEM( differentUnitNet ); + item = new ERC_ITEM( differentUnitNet ); break; case ERCE_BUS_ALIAS_CONFLICT: - return new ERC_ITEM( busDefinitionConflict ); + item = new ERC_ITEM( busDefinitionConflict ); break; case ERCE_DRIVER_CONFLICT: - return new ERC_ITEM( multipleNetNames ); + item = new ERC_ITEM( multipleNetNames ); break; case ERCE_BUS_ENTRY_CONFLICT: - return new ERC_ITEM( netNotBusMember ); + item = new ERC_ITEM( netNotBusMember ); break; case ERCE_BUS_LABEL_ERROR: - return new ERC_ITEM( busLabelSyntax ); + item = new ERC_ITEM( busLabelSyntax ); break; case ERCE_BUS_TO_BUS_CONFLICT: - return new ERC_ITEM( busToBusConflict ); + item = new ERC_ITEM( busToBusConflict ); break; case ERCE_BUS_TO_NET_CONFLICT: - return new ERC_ITEM( busToNetConflict ); + item = new ERC_ITEM( busToNetConflict ); break; case ERCE_GLOBLABEL: - return new ERC_ITEM( globalLabelDangling ); + item = new ERC_ITEM( globalLabelDangling ); break; case ERCE_UNRESOLVED_VARIABLE: - return new ERC_ITEM( unresolvedVariable ); + item = new ERC_ITEM( unresolvedVariable ); break; case ERCE_UNSPECIFIED: default: wxFAIL_MSG( "Unknown ERC error code" ); return nullptr; } + + return std::shared_ptr( item ); } diff --git a/eeschema/erc_item.h b/eeschema/erc_item.h index 04eef82305..bbf0d11464 100644 --- a/eeschema/erc_item.h +++ b/eeschema/erc_item.h @@ -34,7 +34,7 @@ public: * Constructs an ERC_ITEM for the given error code * @see ERCE_T */ - static ERC_ITEM* Create( int aErrorCode ); + static std::shared_ptr Create( int aErrorCode ); static std::vector> GetItemsWithSeverities() { diff --git a/eeschema/erc_settings.cpp b/eeschema/erc_settings.cpp index fa2c47e0cf..ab949b7d71 100644 --- a/eeschema/erc_settings.cpp +++ b/eeschema/erc_settings.cpp @@ -296,11 +296,17 @@ int SHEETLIST_ERC_ITEMS_PROVIDER::GetCount( int aSeverity ) } -ERC_ITEM* SHEETLIST_ERC_ITEMS_PROVIDER::GetItem( int aIndex ) +std::shared_ptr SHEETLIST_ERC_ITEMS_PROVIDER::GetERCItem( int aIndex ) { SCH_MARKER* marker = m_filteredMarkers[ aIndex ]; - return marker ? static_cast( marker->GetRCItem() ) : nullptr; + return marker ? std::static_pointer_cast( marker->GetRCItem() ) : nullptr; +} + + +std::shared_ptr SHEETLIST_ERC_ITEMS_PROVIDER::GetItem( int aIndex ) +{ + return GetERCItem( aIndex ); } diff --git a/eeschema/erc_settings.h b/eeschema/erc_settings.h index 95c58fee22..c37e7d951d 100644 --- a/eeschema/erc_settings.h +++ b/eeschema/erc_settings.h @@ -187,7 +187,9 @@ public: int GetCount( int aSeverity = -1 ) override; - ERC_ITEM* GetItem( int aIndex ) override; + std::shared_ptr GetItem( int aIndex ) override; + + std::shared_ptr GetERCItem( int aIndex ); void DeleteItem( int aIndex, bool aDeep ) override; diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 2b126d3ed6..4a93b56b51 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -2047,7 +2047,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart ); @@ -2085,7 +2085,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart ); @@ -2127,7 +2127,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend ); @@ -2164,7 +2164,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend ); @@ -2206,7 +2206,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart ); @@ -2238,7 +2238,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart ); @@ -2277,7 +2277,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend ); @@ -2309,7 +2309,7 @@ void SCH_EAGLE_PLUGIN::addBusEntries() } else { - ERC_ITEM* ercItem = ERC_ITEM::Create( 0 ); + std::shared_ptr ercItem = ERC_ITEM::Create( 0 ); ercItem->SetErrorMessage( _( "Bus Entry needed" ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend ); diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index 910eeca5da..2094960258 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -41,7 +41,7 @@ #define SCALING_FACTOR Millimeter2iu( 0.15 ) -SCH_MARKER::SCH_MARKER( ERC_ITEM* aItem, const wxPoint& aPos ) : +SCH_MARKER::SCH_MARKER( std::shared_ptr aItem, const wxPoint& aPos ) : SCH_ITEM( nullptr, SCH_MARKER_T ), MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC ) { diff --git a/eeschema/sch_marker.h b/eeschema/sch_marker.h index f39f2efb19..95c99c5c2d 100644 --- a/eeschema/sch_marker.h +++ b/eeschema/sch_marker.h @@ -33,7 +33,7 @@ class SCH_MARKER : public SCH_ITEM, public MARKER_BASE { public: - SCH_MARKER( ERC_ITEM* aItem, const wxPoint& aPos ); + SCH_MARKER( std::shared_ptr aItem, const wxPoint& aPos ); // Do not create a copy constructor. The one generated by the compiler is adequate. diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index f373e06f79..93c75d90c5 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -1346,7 +1346,7 @@ void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int a for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) ) { SCH_MARKER* marker = static_cast( item ); - RC_ITEM* rcItem = marker->GetRCItem(); + std::shared_ptrrcItem = marker->GetRCItem(); if( marker->GetMarkerType() == aMarkerType && ( aErrorCode == ERCE_UNSPECIFIED || rcItem->GetErrorCode() == aErrorCode ) diff --git a/include/marker_base.h b/include/marker_base.h index 34361a3c4e..dfd5963c45 100644 --- a/include/marker_base.h +++ b/include/marker_base.h @@ -26,6 +26,8 @@ #ifndef MARKER_BASE_H #define MARKER_BASE_H +#include + #include #include #include @@ -61,7 +63,7 @@ public: protected: TYPEMARKER m_markerType; // The type of marker (useful to filter markers) bool m_excluded; // User has excluded this specific error - RC_ITEM* m_rcItem; + std::shared_ptr m_rcItem; int m_scalingFactor; // Scaling factor to convert corners coordinates // to internat units coordinates @@ -71,8 +73,7 @@ protected: public: - MARKER_BASE( int aScalingFactor, RC_ITEM* aItem, TYPEMARKER aType = MARKER_UNSPEC ); - + MARKER_BASE( int aScalingFactor, std::shared_ptr aItem, TYPEMARKER aType = MARKER_UNSPEC ); virtual ~MARKER_BASE(); /** The scaling factor to convert polygonal shape coordinates to internal units @@ -114,8 +115,9 @@ public: * interface may be used. * @return const& DRC_ITEM */ - RC_ITEM* GetRCItem() { return m_rcItem; } - const RC_ITEM* GetRCItem() const { return m_rcItem; } + + // fixme: use shared_ptr + std::shared_ptr GetRCItem() const { return m_rcItem; } /** * Tests if the given wxPoint is within the bounds of this object. diff --git a/pcbnew/board_design_settings.cpp b/pcbnew/board_design_settings.cpp index ff30df4c96..c137c6ab7c 100644 --- a/pcbnew/board_design_settings.cpp +++ b/pcbnew/board_design_settings.cpp @@ -677,9 +677,8 @@ bool BOARD_DESIGN_SETTINGS::LoadFromFile( const wxString& aDirectory ) auto drcName = []( int aCode ) -> std::string { - DRC_ITEM* item = DRC_ITEM::Create( aCode ); + std::shared_ptr item = DRC_ITEM::Create( aCode ); wxString name = item->GetSettingsKey(); - delete item; return std::string( name.ToUTF8() ); }; diff --git a/pcbnew/class_marker_pcb.cpp b/pcbnew/class_marker_pcb.cpp index cb444e70de..a4407f84a6 100644 --- a/pcbnew/class_marker_pcb.cpp +++ b/pcbnew/class_marker_pcb.cpp @@ -42,9 +42,10 @@ #define SCALING_FACTOR Millimeter2iu( 0.1 ) -MARKER_PCB::MARKER_PCB( DRC_ITEM* aItem, const wxPoint& aPosition ) : - BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add() - MARKER_BASE( SCALING_FACTOR, aItem ) + +MARKER_PCB::MARKER_PCB( std::shared_ptr aItem, const wxPoint& aPosition ) : + BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add() + MARKER_BASE( SCALING_FACTOR, aItem ) { if( m_rcItem ) m_rcItem->SetParent( this ); @@ -76,8 +77,8 @@ MARKER_PCB* MARKER_PCB::Deserialize( const wxString& data ) wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ), (int) strtol( props[2].c_str(), nullptr, 10 ) ); - DRC_ITEM* drcItem = DRC_ITEM::Create( props[0] ); - + std::shared_ptr drcItem = DRC_ITEM::Create( props[0] ); + if( !drcItem ) return nullptr; diff --git a/pcbnew/class_marker_pcb.h b/pcbnew/class_marker_pcb.h index 59b93081ae..c596675de7 100644 --- a/pcbnew/class_marker_pcb.h +++ b/pcbnew/class_marker_pcb.h @@ -46,8 +46,7 @@ class MSG_PANEL_ITEM; class MARKER_PCB : public BOARD_ITEM, public MARKER_BASE { public: - MARKER_PCB( DRC_ITEM* aItem, const wxPoint& aPosition ); - + MARKER_PCB( std::shared_ptr aItem, const wxPoint& aPosition ); ~MARKER_PCB(); static inline bool ClassOf( const EDA_ITEM* aItem ) diff --git a/pcbnew/cleanup_item.h b/pcbnew/cleanup_item.h index 8befcaa0d1..b9f691471c 100644 --- a/pcbnew/cleanup_item.h +++ b/pcbnew/cleanup_item.h @@ -73,11 +73,11 @@ public: */ class VECTOR_CLEANUP_ITEMS_PROVIDER : public RC_ITEMS_PROVIDER { - std::vector* m_sourceVector; // owns its CLEANUP_ITEMs + std::vector >* m_sourceVector; // owns its CLEANUP_ITEMs public: - VECTOR_CLEANUP_ITEMS_PROVIDER( std::vector* aList ) : + VECTOR_CLEANUP_ITEMS_PROVIDER( std::vector >* aList ) : m_sourceVector( aList ) { } @@ -91,18 +91,22 @@ public: return m_sourceVector->size(); } - CLEANUP_ITEM* GetItem( int aIndex ) override + std::shared_ptr GetItem( int aIndex ) override { return m_sourceVector->at( aIndex ); } + std::shared_ptr GetCleanupItem( int aIndex ) + { + return m_sourceVector->at( aIndex ); + } + + void DeleteItem( int aIndex, bool aDeep ) override { if( aDeep ) { - CLEANUP_ITEM* item = m_sourceVector->at( aIndex ); - delete item; - + auto item = m_sourceVector->at( aIndex ); m_sourceVector->erase( m_sourceVector->begin() + aIndex ); } } @@ -111,9 +115,6 @@ public: { if( aDeep ) { - for( CLEANUP_ITEM* item : *m_sourceVector ) - delete item; - m_sourceVector->clear(); } } diff --git a/pcbnew/dialogs/dialog_cleanup_graphics.cpp b/pcbnew/dialogs/dialog_cleanup_graphics.cpp index 1b701c4e75..8d58745c79 100644 --- a/pcbnew/dialogs/dialog_cleanup_graphics.cpp +++ b/pcbnew/dialogs/dialog_cleanup_graphics.cpp @@ -50,9 +50,6 @@ DIALOG_CLEANUP_GRAPHICS::DIALOG_CLEANUP_GRAPHICS( PCB_BASE_FRAME* aParent, bool DIALOG_CLEANUP_GRAPHICS::~DIALOG_CLEANUP_GRAPHICS() { - for( CLEANUP_ITEM* item : m_items ) - delete item; - m_changesTreeModel->DecRef(); } @@ -97,9 +94,6 @@ void DIALOG_CLEANUP_GRAPHICS::doCleanup( bool aDryRun ) m_changesTreeModel->SetProvider( nullptr ); } - for( CLEANUP_ITEM* item : m_items ) - delete item; - m_items.clear(); // Old model has to be refreshed, GAL normally does not keep updating it diff --git a/pcbnew/dialogs/dialog_cleanup_graphics.h b/pcbnew/dialogs/dialog_cleanup_graphics.h index 11ee676f52..e7176b9928 100644 --- a/pcbnew/dialogs/dialog_cleanup_graphics.h +++ b/pcbnew/dialogs/dialog_cleanup_graphics.h @@ -36,7 +36,7 @@ class DIALOG_CLEANUP_GRAPHICS: public DIALOG_CLEANUP_GRAPHICS_BASE { PCB_BASE_FRAME* m_parentFrame; bool m_isModEdit; - std::vector m_items; + std::vector > m_items; RC_TREE_MODEL* m_changesTreeModel; void doCleanup( bool aDryRun ); diff --git a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp index 4e743156c6..508b1e4d82 100644 --- a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp +++ b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp @@ -71,9 +71,6 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::~DIALOG_CLEANUP_TRACKS_AND_VIAS() cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue(); cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue(); - for( CLEANUP_ITEM* item : m_items ) - delete item; - m_changesTreeModel->DecRef(); } @@ -115,9 +112,6 @@ void DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup( bool aDryRun ) m_changesTreeModel->SetProvider( nullptr ); } - for( CLEANUP_ITEM* item : m_items ) - delete item; - m_items.clear(); // Old model has to be refreshed, GAL normally does not keep updating it diff --git a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.h b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.h index 2863eac19d..6b1f209ce5 100644 --- a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.h +++ b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.h @@ -35,7 +35,7 @@ class PCB_EDIT_FRAME; class DIALOG_CLEANUP_TRACKS_AND_VIAS: public DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE { PCB_EDIT_FRAME* m_parentFrame; - std::vector m_items; + std::vector > m_items; RC_TREE_MODEL* m_changesTreeModel; void doCleanup( bool aDryRun ); diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index ca61f42030..675eb2b255 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -306,7 +306,7 @@ void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent ) if( !node ) return; - RC_ITEM* rcItem = node->m_RcItem; + std::shared_ptr rcItem = node->m_RcItem; wxString listName; wxMenu menu; wxString msg; diff --git a/pcbnew/dialogs/dialog_netlist.cpp b/pcbnew/dialogs/dialog_netlist.cpp index 39a534e1ce..c59857ac7f 100644 --- a/pcbnew/dialogs/dialog_netlist.cpp +++ b/pcbnew/dialogs/dialog_netlist.cpp @@ -190,11 +190,11 @@ void DIALOG_NETLIST::OnTestFootprintsClick( wxCommandEvent& event ) return; HTML_MESSAGE_BOX dlg( this, _( "Check footprints" ) ); - std::vector drcItems; + std::vector > drcItems; TestFootprints( netlist, m_parent->GetBoard(), drcItems ); - for( DRC_ITEM* item : drcItems ) + for( auto item : drcItems ) dlg.AddHTML_Text( item->ShowHtml( m_parent ) ); dlg.ShowModal(); diff --git a/pcbnew/drc/drc.cpp b/pcbnew/drc/drc.cpp index e28a80e21c..4ce931b178 100644 --- a/pcbnew/drc/drc.cpp +++ b/pcbnew/drc/drc.cpp @@ -47,6 +47,7 @@ #include #include // for KiROUND #include +#include #include #include #include @@ -86,11 +87,6 @@ DRC::DRC() : DRC::~DRC() { - for( DRC_ITEM* unconnectedItem : m_unconnected ) - delete unconnectedItem; - - for( DRC_ITEM* footprintItem : m_footprints ) - delete footprintItem; } @@ -377,9 +373,6 @@ void DRC::RunTests( wxTextCtrl* aMessages ) tester.RunDRC( userUnits(), *m_pcb ); } - for( DRC_ITEM* footprintItem : m_footprints ) - delete footprintItem; - m_footprints.clear(); m_footprintsTested = false; @@ -513,7 +506,7 @@ void DRC::testPadClearances( BOARD_COMMIT& aCommit ) if( pad->Collide( &edge, minClearance, &actual ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_COPPER_EDGE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_COPPER_EDGE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -555,7 +548,7 @@ void DRC::testTracks( BOARD_COMMIT& aCommit, wxWindow *aActiveWindow, bool aShow // on OSX progressDialog = new APP_PROGRESS_DIALOG( _( "Track clearances" ), wxEmptyString, deltamax, aActiveWindow, false, - wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME ); + wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME ); progressDialog->Update( 0, wxEmptyString ); } @@ -609,7 +602,7 @@ void DRC::testTracks( BOARD_COMMIT& aCommit, wxWindow *aActiveWindow, bool aShow if( !settings.Ignore( code ) && connectivity->TestTrackEndpointDangling( *seg_it, &pos ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( code ); + std::shared_ptr drcItem = DRC_ITEM::Create( code ); drcItem->SetItems( *seg_it ); MARKER_PCB* marker = new MARKER_PCB( drcItem, pos ); @@ -624,9 +617,6 @@ void DRC::testTracks( BOARD_COMMIT& aCommit, wxWindow *aActiveWindow, bool aShow void DRC::testUnconnected() { - for( DRC_ITEM* unconnectedItem : m_unconnected ) - delete unconnectedItem; - m_unconnected.clear(); auto connectivity = m_pcb->GetConnectivity(); @@ -640,7 +630,7 @@ void DRC::testUnconnected() for( const CN_EDGE& edge : edges ) { - DRC_ITEM* item = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS ); + std::shared_ptr item = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS ); item->SetItems( edge.GetSourceNode()->Parent(), edge.GetTargetNode()->Parent() ); m_unconnected.push_back( item ); } @@ -677,7 +667,7 @@ void DRC::testZones( BOARD_COMMIT& aCommit ) if( ( netcode < 0 ) || pads_in_net == 0 ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ZONE_HAS_EMPTY_NET ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_ZONE_HAS_EMPTY_NET ); drcItem->SetItems( zone ); MARKER_PCB* marker = new MARKER_PCB( drcItem, zone->GetPosition() ); @@ -743,7 +733,7 @@ void DRC::testZones( BOARD_COMMIT& aCommit ) if( smoothed_polys[ia2].Contains( currentVertex ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT ); drcItem->SetItems( zoneRef, zoneToTest ); MARKER_PCB* marker = new MARKER_PCB( drcItem, pt ); @@ -759,7 +749,7 @@ void DRC::testZones( BOARD_COMMIT& aCommit ) if( smoothed_polys[ia].Contains( currentVertex ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT ); drcItem->SetItems( zoneToTest, zoneRef ); MARKER_PCB* marker = new MARKER_PCB( drcItem, pt ); @@ -814,7 +804,7 @@ void DRC::testZones( BOARD_COMMIT& aCommit ) for( const std::pair& conflict : conflictPoints ) { int actual = conflict.second; - DRC_ITEM* drcItem; + std::shared_ptr drcItem; if( actual <= 0 ) { @@ -943,7 +933,7 @@ void DRC::testCopperDrawItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem ) if( actual < INT_MAX ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -988,7 +978,7 @@ void DRC::testCopperDrawItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem ) if( actual < INT_MAX ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -1021,7 +1011,7 @@ void DRC::testOutline( BOARD_COMMIT& aCommit ) } else { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE ); m_msg.Printf( drcItem->GetErrorText() + _( " (not a closed shape)" ) ); @@ -1045,7 +1035,7 @@ void DRC::testDisabledLayers( BOARD_COMMIT& aCommit ) { if( disabledLayers.test( track->GetLayer() ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); m_msg.Printf( drcItem->GetErrorText() + _( "layer %s" ), track->GetLayerName() ); @@ -1065,7 +1055,7 @@ void DRC::testDisabledLayers( BOARD_COMMIT& aCommit ) { if( disabledLayers.test( child->GetLayer() ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); m_msg.Printf( drcItem->GetErrorText() + _( "layer %s" ), child->GetLayerName() ); @@ -1083,7 +1073,7 @@ void DRC::testDisabledLayers( BOARD_COMMIT& aCommit ) { if( disabledLayers.test( zone->GetLayer() ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM ); m_msg.Printf( drcItem->GetErrorText() + _( "layer %s" ), zone->GetLayerName() ); @@ -1147,7 +1137,7 @@ bool DRC::doPadToPadsDrc( BOARD_COMMIT& aCommit, D_PAD* aRefPad, D_PAD** aStart, if( aRefPad->Collide( pad->GetEffectiveHoleShape(), minClearance, &actual ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -1165,13 +1155,12 @@ bool DRC::doPadToPadsDrc( BOARD_COMMIT& aCommit, D_PAD* aRefPad, D_PAD** aStart, if( aRefPad->GetDrillSize().x ) { - int minClearance = pad->GetClearance( pad->GetLayer(), nullptr, - &m_clearanceSource ); + int minClearance = pad->GetClearance( nullptr, &m_clearanceSource ); int actual; if( pad->Collide( aRefPad->GetEffectiveHoleShape(), minClearance, &actual ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -1202,7 +1191,7 @@ bool DRC::doPadToPadsDrc( BOARD_COMMIT& aCommit, D_PAD* aRefPad, D_PAD** aStart, if( pad->GetNetCode() && aRefPad->GetNetCode() && pad->GetNetCode() != aRefPad->GetNetCode() ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_SHORTING_ITEMS ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_SHORTING_ITEMS ); m_msg.Printf( drcItem->GetErrorText() + _( " (nets %s and %s)" ), pad->GetNetname(), aRefPad->GetNetname() ); @@ -1214,7 +1203,7 @@ bool DRC::doPadToPadsDrc( BOARD_COMMIT& aCommit, D_PAD* aRefPad, D_PAD** aStart, addMarkerToPcb( aCommit, marker ); } - continue; + continue; } // if either pad has no drill and is only on technical layers, not a clearance violation @@ -1227,24 +1216,24 @@ bool DRC::doPadToPadsDrc( BOARD_COMMIT& aCommit, D_PAD* aRefPad, D_PAD** aStart, for( PCB_LAYER_ID layer : aRefPad->GetLayerSet().Seq() ) { int minClearance = aRefPad->GetClearance( layer, pad, &m_clearanceSource ); - int clearanceAllowed = minClearance - m_pcb->GetDesignSettings().GetDRCEpsilon(); - int actual; + int clearanceAllowed = minClearance - m_pcb->GetDesignSettings().GetDRCEpsilon(); + int actual; - if( aRefPad->Collide( pad, clearanceAllowed, &actual ) ) - { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + if( aRefPad->Collide( pad, clearanceAllowed, &actual ) ) + { + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); - m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), - m_clearanceSource, - MessageTextFromValue( userUnits(), minClearance, true ), - MessageTextFromValue( userUnits(), actual, true ) ); + m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), + m_clearanceSource, + MessageTextFromValue( userUnits(), minClearance, true ), + MessageTextFromValue( userUnits(), actual, true ) ); - drcItem->SetErrorMessage( m_msg ); - drcItem->SetItems( aRefPad, pad ); + drcItem->SetErrorMessage( m_msg ); + drcItem->SetItems( aRefPad, pad ); - MARKER_PCB* marker = new MARKER_PCB( drcItem, aRefPad->GetPosition() ); - addMarkerToPcb( aCommit, marker ); - return false; + MARKER_PCB* marker = new MARKER_PCB( drcItem, aRefPad->GetPosition() ); + addMarkerToPcb( aCommit, marker ); + return false; } } } diff --git a/pcbnew/drc/drc.h b/pcbnew/drc/drc.h index 9b54b0be28..e82afc1232 100644 --- a/pcbnew/drc/drc.h +++ b/pcbnew/drc/drc.h @@ -128,8 +128,8 @@ private: bool m_board_outline_valid; DIALOG_DRC* m_drcDialog; - std::vector m_unconnected; // list of unconnected pads - std::vector m_footprints; // list of footprint warnings + std::vector > m_unconnected; // list of unconnected pads + std::vector > m_footprints; // list of footprint warnings bool m_drcRun; // indicates DRC has been run at least once bool m_footprintsTested; // indicates footprints were tested in last run diff --git a/pcbnew/drc/drc_clearance_test_functions.cpp b/pcbnew/drc/drc_clearance_test_functions.cpp index e55c71fce3..9a0b6dbb4a 100644 --- a/pcbnew/drc/drc_clearance_test_functions.cpp +++ b/pcbnew/drc/drc_clearance_test_functions.cpp @@ -44,7 +44,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) { if( aRefVia->GetWidth() < bds.m_MicroViasMinSize ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_MICROVIA ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_VIA_ANNULUS ); m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ), MessageTextFromValue( userUnits(), bds.m_MicroViasMinSize, true ), @@ -61,7 +61,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) { if( aRefVia->GetWidth() < bds.m_ViasMinSize ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_VIA ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_VIA_ANNULUS ); m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ), MessageTextFromValue( userUnits(), bds.m_ViasMinSize, true ), @@ -80,7 +80,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) // and a default via hole can be bigger than some vias sizes if( aRefVia->GetDrillValue() > aRefVia->GetWidth() ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_VIA_HOLE_BIGGER ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_VIA_HOLE_BIGGER ); m_msg.Printf( drcItem->GetErrorText() + _( " (diameter %s; drill %s)" ), MessageTextFromValue( userUnits(), aRefVia->GetWidth(), true ), @@ -96,7 +96,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) // test if the type of via is allowed due to design rules if( aRefVia->GetViaType() == VIATYPE::MICROVIA && !bds.m_MicroViasAllowed ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS ); m_msg.Printf( _( "Microvia not allowed (board design rule constraints)" ) ); drcItem->SetErrorMessage( m_msg ); @@ -109,7 +109,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) // test if the type of via is allowed due to design rules if( aRefVia->GetViaType() == VIATYPE::BLIND_BURIED && !bds.m_BlindBuriedViaAllowed ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS ); m_msg.Printf( _( "Blind/buried via not allowed (board design rule constraints)" ) ); drcItem->SetErrorMessage( m_msg ); @@ -141,7 +141,7 @@ void DRC::doSingleViaDRC( BOARD_COMMIT& aCommit, VIA* aRefVia ) if( err ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_PADSTACK ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_PADSTACK ); m_msg.Printf( _( "Microvia through too many layers (%s and %s not adjacent)" ), m_pcb->GetLayerName( layer1 ), @@ -184,7 +184,7 @@ void DRC::doSingleTrackDRC( BOARD_COMMIT& aCommit, TRACK* aRefSeg ) { wxPoint refsegMiddle = ( aRefSeg->GetStart() + aRefSeg->GetEnd() ) / 2; - DRC_ITEM* drcItem = DRC_ITEM::Create( errorCode ); + std::shared_ptr drcItem = DRC_ITEM::Create( errorCode ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ), m_clearanceSource, @@ -322,7 +322,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS if( slot->Collide( &refSeg, minClearance + bds.GetDRCEpsilon(), &actual ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -350,7 +350,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS if( pad->Collide( &refSeg, minClearance - bds.GetDRCEpsilon(), &actual ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -409,7 +409,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS // Check two tracks crossing first as it reports a DRCE without distances if( OPT_VECTOR2I intersection = refSeg.GetSeg().Intersect( trackSeg.GetSeg() ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TRACKS_CROSSING ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_TRACKS_CROSSING ); drcItem->SetErrorMessage( m_msg ); drcItem->SetItems( aRefSeg, track ); @@ -422,7 +422,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS else if( refSeg.Collide( &trackSeg, minClearance, &actual ) ) { wxPoint pos = GetLocation( aRefSeg, trackSeg.GetSeg() ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -471,7 +471,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS if( zone->GetFilledPolysList( aLayer ).Collide( testSeg, allowedDist, &actual ) ) { actual = std::max( 0, actual - halfWidth ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, @@ -535,7 +535,7 @@ void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aS BOARD::IterateForward( m_pcb->Drawings(), inspector, nullptr, types ); int actual = std::max( 0.0, sqrt( center2center_squared ) - halfWidth ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_COPPER_EDGE_CLEARANCE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_COPPER_EDGE_CLEARANCE ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ), m_clearanceSource, diff --git a/pcbnew/drc/drc_courtyard_tester.cpp b/pcbnew/drc/drc_courtyard_tester.cpp index 1386a45e0f..3bf8e6a90a 100644 --- a/pcbnew/drc/drc_courtyard_tester.cpp +++ b/pcbnew/drc/drc_courtyard_tester.cpp @@ -56,7 +56,7 @@ bool DRC_COURTYARD_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) && footprint->GetPolyCourtyardFront().OutlineCount() == 0 && footprint->GetPolyCourtyardBack().OutlineCount() == 0 ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_MISSING_COURTYARD ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_MISSING_COURTYARD ); drcItem->SetItems( footprint ); HandleMarker( new MARKER_PCB( drcItem, footprint->GetPosition() ) ); success = false; @@ -71,7 +71,7 @@ bool DRC_COURTYARD_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) { if( !aBoard.GetDesignSettings().Ignore( DRCE_MALFORMED_COURTYARD ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD ); msg.Printf( drcItem->GetErrorText() + _( " (not a closed shape)" ) ); @@ -137,7 +137,7 @@ bool DRC_COURTYARD_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) if( overlap ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_OVERLAPPING_FOOTPRINTS ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_OVERLAPPING_FOOTPRINTS ); drcItem->SetItems( footprint, test ); HandleMarker( new MARKER_PCB( drcItem, pos ) ); success = false; @@ -175,7 +175,7 @@ bool DRC_COURTYARD_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) int code = pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ? DRCE_NPTH_IN_COURTYARD : DRCE_PTH_IN_COURTYARD; - DRC_ITEM* drcItem = DRC_ITEM::Create( code ); + std::shared_ptr drcItem = DRC_ITEM::Create( code ); drcItem->SetItems( footprint, pad ); HandleMarker( new MARKER_PCB( drcItem, pos ) ); success = false; diff --git a/pcbnew/drc/drc_drilled_hole_tester.cpp b/pcbnew/drc/drc_drilled_hole_tester.cpp index 93c8e4f71c..eb5536155c 100644 --- a/pcbnew/drc/drc_drilled_hole_tester.cpp +++ b/pcbnew/drc/drc_drilled_hole_tester.cpp @@ -110,7 +110,7 @@ bool DRC_DRILLED_HOLE_TESTER::checkPad( D_PAD* aPad ) if( holeSize < minHole ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ), m_source, @@ -161,7 +161,7 @@ bool DRC_DRILLED_HOLE_TESTER::checkVia( VIA* via ) if( via->GetDrillValue() < minHole ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ), m_source, @@ -211,9 +211,9 @@ bool DRC_DRILLED_HOLE_TESTER::checkMicroVia( VIA* via ) m_source = _( "board minimum" ); } - if( via->GetDrillValue() < minHole ) + if( via->GetDrillValue() < minHole ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_MICROVIA_DRILL ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_MICROVIA_DRILL ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ), m_source, @@ -288,7 +288,7 @@ bool DRC_DRILLED_HOLE_TESTER::checkHoles() if( actual < bds.m_HoleToHoleMin ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_DRILLED_HOLES_TOO_CLOSE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_DRILLED_HOLES_TOO_CLOSE ); m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ), MessageTextFromValue( m_units, bds.m_HoleToHoleMin, true ), diff --git a/pcbnew/drc/drc_item.cpp b/pcbnew/drc/drc_item.cpp index 90125b9ddf..2a6f05505c 100644 --- a/pcbnew/drc/drc_item.cpp +++ b/pcbnew/drc/drc_item.cpp @@ -199,55 +199,59 @@ std::vector> DRC_ITEM::allItemTypes( { } ); -DRC_ITEM* DRC_ITEM::Create( int aErrorCode ) +std::shared_ptr DRC_ITEM::Create( int aErrorCode ) { + DRC_ITEM *item = nullptr; + switch( aErrorCode ) { - case DRCE_UNCONNECTED_ITEMS: return new DRC_ITEM( unconnectedItems ); - case DRCE_SHORTING_ITEMS: return new DRC_ITEM( shortingItems ); - case DRCE_ALLOWED_ITEMS: return new DRC_ITEM( itemsNotAllowed ); - case DRCE_CLEARANCE: return new DRC_ITEM( clearance ); - case DRCE_TRACKS_CROSSING: return new DRC_ITEM( tracksCrossing ); - case DRCE_COPPER_EDGE_CLEARANCE: return new DRC_ITEM( copperEdgeClearance ); - case DRCE_ZONES_INTERSECT: return new DRC_ITEM( zonesIntersect ); - case DRCE_ZONE_HAS_EMPTY_NET: return new DRC_ITEM( zoneHasEmptyNet ); - case DRCE_DANGLING_VIA: return new DRC_ITEM( viaDangling ); - case DRCE_DANGLING_TRACK: return new DRC_ITEM( trackDangling ); - case DRCE_DRILLED_HOLES_TOO_CLOSE: return new DRC_ITEM( holeNearHole ); - case DRCE_TRACK_WIDTH: return new DRC_ITEM( trackWidth ); - case DRCE_TOO_SMALL_VIA: return new DRC_ITEM( viaTooSmall ); - case DRCE_VIA_ANNULUS: return new DRC_ITEM( viaAnnulus ); - case DRCE_TOO_SMALL_DRILL: return new DRC_ITEM( drillTooSmall ); - case DRCE_VIA_HOLE_BIGGER: return new DRC_ITEM( viaHoleLargerThanPad ); - case DRCE_PADSTACK: return new DRC_ITEM( padstack ); - case DRCE_TOO_SMALL_MICROVIA: return new DRC_ITEM( microviaTooSmall ); - case DRCE_TOO_SMALL_MICROVIA_DRILL: return new DRC_ITEM( microviaDrillTooSmall ); - case DRCE_KEEPOUT: return new DRC_ITEM( keepout ); - case DRCE_OVERLAPPING_FOOTPRINTS: return new DRC_ITEM( courtyardsOverlap ); - case DRCE_MISSING_COURTYARD: return new DRC_ITEM( missingCourtyard ); - case DRCE_MALFORMED_COURTYARD: return new DRC_ITEM( malformedCourtyard ); - case DRCE_PTH_IN_COURTYARD: return new DRC_ITEM( pthInsideCourtyard ); - case DRCE_NPTH_IN_COURTYARD: return new DRC_ITEM( npthInsideCourtyard ); - case DRCE_DISABLED_LAYER_ITEM: return new DRC_ITEM( itemOnDisabledLayer ); - case DRCE_INVALID_OUTLINE: return new DRC_ITEM( invalidOutline ); - case DRCE_MISSING_FOOTPRINT: return new DRC_ITEM( duplicateFootprints ); - case DRCE_DUPLICATE_FOOTPRINT: return new DRC_ITEM( missingFootprint ); - case DRCE_EXTRA_FOOTPRINT: return new DRC_ITEM( extraFootprint ); - case DRCE_UNRESOLVED_VARIABLE: return new DRC_ITEM( unresolvedVariable ); + case DRCE_UNCONNECTED_ITEMS: item = new DRC_ITEM( unconnectedItems ); break; + case DRCE_SHORTING_ITEMS: item = new DRC_ITEM( shortingItems ); break; + case DRCE_ALLOWED_ITEMS: item = new DRC_ITEM( itemsNotAllowed ); break; + case DRCE_CLEARANCE: item = new DRC_ITEM( clearance ); break; + case DRCE_TRACKS_CROSSING: item = new DRC_ITEM( tracksCrossing ); break; + case DRCE_COPPER_EDGE_CLEARANCE: item = new DRC_ITEM( copperEdgeClearance ); break; + case DRCE_ZONES_INTERSECT: item = new DRC_ITEM( zonesIntersect ); break; + case DRCE_ZONE_HAS_EMPTY_NET: item = new DRC_ITEM( zoneHasEmptyNet ); break; + case DRCE_DANGLING_VIA: item = new DRC_ITEM( viaDangling ); break; + case DRCE_DANGLING_TRACK: item = new DRC_ITEM( trackDangling ); break; + case DRCE_DRILLED_HOLES_TOO_CLOSE: item = new DRC_ITEM( holeNearHole ); break; + case DRCE_TRACK_WIDTH: item = new DRC_ITEM( trackWidth ); break; + case DRCE_TOO_SMALL_VIA: item = new DRC_ITEM( viaTooSmall ); break; + case DRCE_VIA_ANNULUS: item = new DRC_ITEM( viaAnnulus ); break; + case DRCE_TOO_SMALL_DRILL: item = new DRC_ITEM( drillTooSmall ); break; + case DRCE_VIA_HOLE_BIGGER: item = new DRC_ITEM( viaHoleLargerThanPad ); break; + case DRCE_PADSTACK: item = new DRC_ITEM( padstack ); break; + case DRCE_TOO_SMALL_MICROVIA: item = new DRC_ITEM( microviaTooSmall ); break; + case DRCE_TOO_SMALL_MICROVIA_DRILL: item = new DRC_ITEM( microviaDrillTooSmall ); break; + case DRCE_KEEPOUT: item = new DRC_ITEM( keepout ); break; + case DRCE_OVERLAPPING_FOOTPRINTS: item = new DRC_ITEM( courtyardsOverlap ); break; + case DRCE_MISSING_COURTYARD: item = new DRC_ITEM( missingCourtyard ); break; + case DRCE_MALFORMED_COURTYARD: item = new DRC_ITEM( malformedCourtyard ); break; + case DRCE_PTH_IN_COURTYARD: item = new DRC_ITEM( pthInsideCourtyard ); break; + case DRCE_NPTH_IN_COURTYARD: item = new DRC_ITEM( npthInsideCourtyard ); break; + case DRCE_DISABLED_LAYER_ITEM: item = new DRC_ITEM( itemOnDisabledLayer ); break; + case DRCE_INVALID_OUTLINE: item = new DRC_ITEM( invalidOutline ); break; + case DRCE_MISSING_FOOTPRINT: item = new DRC_ITEM( duplicateFootprints ); break; + case DRCE_DUPLICATE_FOOTPRINT: item = new DRC_ITEM( missingFootprint ); break; + case DRCE_EXTRA_FOOTPRINT: item = new DRC_ITEM( extraFootprint ); break; + case DRCE_UNRESOLVED_VARIABLE: item = new DRC_ITEM( unresolvedVariable ); break; default: wxFAIL_MSG( "Unknown DRC error code" ); return nullptr; } + + return std::shared_ptr( item ); } -DRC_ITEM* DRC_ITEM::Create( const wxString& aErrorKey ) +std::shared_ptr DRC_ITEM::Create( const wxString& aErrorKey ) { for( const RC_ITEM& item : allItemTypes ) { if( aErrorKey == item.GetSettingsKey() ) - return new DRC_ITEM( static_cast( item ) ); + return std::shared_ptr( new DRC_ITEM( static_cast( item ) ) ); } // This can happen if a project has old-format exclusions. Just drop these items. diff --git a/pcbnew/drc/drc_item.h b/pcbnew/drc/drc_item.h index e61bab8b41..1ace251a3e 100644 --- a/pcbnew/drc/drc_item.h +++ b/pcbnew/drc/drc_item.h @@ -36,7 +36,7 @@ public: * Constructs a DRC_ITEM for the given error code * @see DRCE_T */ - static DRC_ITEM* Create( int aErrorCode ); + static std::shared_ptr Create( int aErrorCode ); /** * Constructs a DRC item from a given error settings key @@ -44,7 +44,7 @@ public: * to represent a given error code in settings files and for storing ignored DRC items) * @return the created item */ - static DRC_ITEM* Create( const wxString& aErrorKey ); + static std::shared_ptr Create( const wxString& aErrorKey ); static std::vector> GetItemsWithSeverities() { diff --git a/pcbnew/drc/drc_keepout_tester.cpp b/pcbnew/drc/drc_keepout_tester.cpp index 76909f7555..1d5190aa98 100644 --- a/pcbnew/drc/drc_keepout_tester.cpp +++ b/pcbnew/drc/drc_keepout_tester.cpp @@ -95,7 +95,7 @@ bool DRC_KEEPOUT_TESTER::checkTracksAndVias() if( m_zone->Outline()->Collide( trackSeg, segm->GetWidth() / 2 ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( DISALLOW_TRACKS ) ); @@ -138,7 +138,7 @@ bool DRC_KEEPOUT_TESTER::checkTracksAndVias() if( m_zone->Outline()->Collide( seg, clearance ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( test ) ); drcItem->SetErrorMessage( m_msg ); drcItem->SetItems( segm, m_zone ); @@ -187,7 +187,7 @@ bool DRC_KEEPOUT_TESTER::checkFootprints() if( poly.OutlineCount() ) { const VECTOR2I& pt = poly.CVertex( 0, 0, -1 ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( DISALLOW_FOOTPRINTS ) ); @@ -237,7 +237,7 @@ bool DRC_KEEPOUT_TESTER::checkPads( MODULE* aModule ) if( outline.OutlineCount() ) { const VECTOR2I& pt = outline.CVertex( 0, 0, -1 ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( DISALLOW_PADS ) ); @@ -255,7 +255,7 @@ bool DRC_KEEPOUT_TESTER::checkPads( MODULE* aModule ) if( m_zone->Outline()->Collide( slot->GetSeg(), slot->GetWidth() / 2 ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( DISALLOW_HOLES ) ); @@ -307,7 +307,7 @@ bool DRC_KEEPOUT_TESTER::checkDrawings() if( poly.OutlineCount() ) { const VECTOR2I& pt = poly.CVertex( 0, 0, -1 ); - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_KEEPOUT ); m_msg.Printf( drcItem->GetErrorText() + _( " (%s)" ), m_sources.at( sourceId ) ); drcItem->SetErrorMessage( m_msg ); drcItem->SetItems( drawing, m_zone ); diff --git a/pcbnew/drc/drc_provider.h b/pcbnew/drc/drc_provider.h index 8721363595..73fdb160b5 100644 --- a/pcbnew/drc/drc_provider.h +++ b/pcbnew/drc/drc_provider.h @@ -144,11 +144,11 @@ public: return count; } - DRC_ITEM* GetItem( int aIndex ) override + std::shared_ptr GetItem( int aIndex ) override { MARKER_PCB* marker = m_filteredMarkers[ aIndex ]; - return marker ? static_cast( marker->GetRCItem() ) : nullptr; + return marker ? marker->GetRCItem() : nullptr; } void DeleteItem( int aIndex, bool aDeep ) override @@ -179,14 +179,14 @@ public: class VECTOR_DRC_ITEMS_PROVIDER : public RC_ITEMS_PROVIDER { PCB_BASE_FRAME* m_frame; - std::vector* m_sourceVector; // owns its DRC_ITEMs + std::vector >* m_sourceVector; // owns its DRC_ITEMs int m_severities; - std::vector m_filteredVector; // does not own its DRC_ITEMs + std::vector > m_filteredVector; // does not own its DRC_ITEMs public: - VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector* aList ) : + VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector >* aList ) : m_frame( aFrame ), m_sourceVector( aList ), m_severities( 0 ) @@ -203,7 +203,7 @@ public: if( m_sourceVector ) { - for( DRC_ITEM* item : *m_sourceVector ) + for( auto item : *m_sourceVector ) { if( bds.GetSeverity( item->GetErrorCode() ) & aSeverities ) m_filteredVector.push_back( item ); @@ -221,7 +221,7 @@ public: if( m_sourceVector ) { - for( DRC_ITEM* item : *m_sourceVector ) + for( auto item : *m_sourceVector ) { if( bds.GetSeverity( item->GetErrorCode() ) == aSeverity ) count++; @@ -231,14 +231,14 @@ public: return count; } - DRC_ITEM* GetItem( int aIndex ) override + std::shared_ptr GetItem( int aIndex ) override { return (m_filteredVector)[aIndex]; } void DeleteItem( int aIndex, bool aDeep ) override { - DRC_ITEM* item = m_filteredVector[aIndex]; + auto item = m_filteredVector[aIndex]; m_filteredVector.erase( m_filteredVector.begin() + aIndex ); if( aDeep ) @@ -247,7 +247,6 @@ public: { if( m_sourceVector->at( i ) == item ) { - delete item; m_sourceVector->erase( m_sourceVector->begin() + i ); break; } @@ -259,9 +258,6 @@ public: { if( aDeep ) { - for( DRC_ITEM* item : *m_sourceVector ) - delete item; - m_sourceVector->clear(); } @@ -279,7 +275,7 @@ class RATSNEST_DRC_ITEMS_PROVIDER : public VECTOR_DRC_ITEMS_PROVIDER // data-structure so that deleting/excluding things can do a deep delete/exclusion // which will be reflected in the ratsnest.... public: - RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector* aList ) : + RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector >* aList ) : VECTOR_DRC_ITEMS_PROVIDER( aFrame, aList ) { } }; diff --git a/pcbnew/drc/drc_rule.cpp b/pcbnew/drc/drc_rule.cpp index b60898124e..a3865a9d41 100644 --- a/pcbnew/drc/drc_rule.cpp +++ b/pcbnew/drc/drc_rule.cpp @@ -119,7 +119,7 @@ bool DRC_RULE_CONDITION::EvaluateFor( const BOARD_ITEM* aItemA, const BOARD_ITEM bool DRC_RULE_CONDITION::Compile( REPORTER* aReporter, int aSourceLine, int aSourceOffset ) { - PCB_EXPR_COMPILER compiler( aReporter, aSourceLine, aSourceOffset ); + PCB_EXPR_COMPILER compiler; if (!m_ucode) m_ucode = new PCB_EXPR_UCODE; diff --git a/pcbnew/drc/drc_rule_parser.cpp b/pcbnew/drc/drc_rule_parser.cpp index b27d9a4adf..4c4675d50f 100644 --- a/pcbnew/drc/drc_rule_parser.cpp +++ b/pcbnew/drc/drc_rule_parser.cpp @@ -376,7 +376,9 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule ) void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult ) { - PCB_EXPR_EVALUATOR evaluator( m_reporter, CurLineNumber(), CurOffset() ); + PCB_EXPR_EVALUATOR evaluator; + + // m_reporter, CurLineNumber(), CurOffset() ); evaluator.Evaluate( aExpr ); aResult = evaluator.Result(); diff --git a/pcbnew/drc/drc_textvar_tester.cpp b/pcbnew/drc/drc_textvar_tester.cpp index 8412bdaab3..117278f6c8 100644 --- a/pcbnew/drc/drc_textvar_tester.cpp +++ b/pcbnew/drc/drc_textvar_tester.cpp @@ -57,7 +57,7 @@ bool DRC_TEXTVAR_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); drcItem->SetItems( text ); HandleMarker( new MARKER_PCB( drcItem, text->GetPosition() ) ); @@ -75,7 +75,7 @@ bool DRC_TEXTVAR_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); drcItem->SetItems( text ); HandleMarker( new MARKER_PCB( drcItem, text->GetPosition() ) ); @@ -98,7 +98,7 @@ bool DRC_TEXTVAR_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) { if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { - DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); drcItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) ); HandleMarker( new MARKER_PCB( drcItem, text->GetPosition() ) ); diff --git a/pcbnew/drc/footprint_tester.cpp b/pcbnew/drc/footprint_tester.cpp index f64e63fbed..c293a5a1f8 100644 --- a/pcbnew/drc/footprint_tester.cpp +++ b/pcbnew/drc/footprint_tester.cpp @@ -26,7 +26,7 @@ #include #include -void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector& aDRCList ) +void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector >& aDRCList ) { wxString msg; @@ -45,7 +45,7 @@ void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector& a if( !ins.second ) { - DRC_ITEM* item = DRC_ITEM::Create( DRCE_DUPLICATE_FOOTPRINT ); + std::shared_ptr item = DRC_ITEM::Create( DRCE_DUPLICATE_FOOTPRINT ); item->SetItems( mod, *ins.first ); aDRCList.push_back( item ); } @@ -66,7 +66,7 @@ void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector& a component->GetReference(), component->GetValue() ); - DRC_ITEM* item = DRC_ITEM::Create( DRCE_MISSING_FOOTPRINT ); + std::shared_ptr item = DRC_ITEM::Create( DRCE_MISSING_FOOTPRINT ); item->SetErrorMessage( msg ); aDRCList.push_back( item ); } @@ -82,7 +82,7 @@ void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector& a if( component == NULL ) { - DRC_ITEM* item = DRC_ITEM::Create( DRCE_EXTRA_FOOTPRINT ); + std::shared_ptr item = DRC_ITEM::Create( DRCE_EXTRA_FOOTPRINT ); item->SetItems( module ); aDRCList.push_back( item ); } diff --git a/pcbnew/drc/footprint_tester.h b/pcbnew/drc/footprint_tester.h index bff20988a2..a492b25712 100644 --- a/pcbnew/drc/footprint_tester.h +++ b/pcbnew/drc/footprint_tester.h @@ -29,6 +29,6 @@ class BOARD; -void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector& aDRCList ); +void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vector >& aDRCList ); #endif // FOOTPRINT_TESTER_H diff --git a/pcbnew/graphics_cleaner.cpp b/pcbnew/graphics_cleaner.cpp index 8306268a27..fc07327394 100644 --- a/pcbnew/graphics_cleaner.cpp +++ b/pcbnew/graphics_cleaner.cpp @@ -43,7 +43,7 @@ GRAPHICS_CLEANER::GRAPHICS_CLEANER( DRAWINGS& aDrawings, MODULE* aParentModule, } -void GRAPHICS_CLEANER::CleanupBoard( bool aDryRun, std::vector* aItemsList, +void GRAPHICS_CLEANER::CleanupBoard( bool aDryRun, std::vector >* aItemsList, bool aMergeRects, bool aDeleteRedundant ) { m_dryRun = aDryRun; @@ -146,7 +146,7 @@ void GRAPHICS_CLEANER::cleanupSegments() if( isNullSegment( segment ) ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_NULL_GRAPHIC ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_NULL_GRAPHIC ) ); item->SetItems( segment ); m_itemsList->push_back( item ); @@ -165,7 +165,7 @@ void GRAPHICS_CLEANER::cleanupSegments() if( areEquivalent( segment, segment2 ) ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_DUPLICATE_GRAPHIC ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_DUPLICATE_GRAPHIC ) ); item->SetItems( segment2 ); m_itemsList->push_back( item ); @@ -293,7 +293,7 @@ void GRAPHICS_CLEANER::mergeRects() right->seg->SetFlags( IS_DELETED ); bottom->seg->SetFlags( IS_DELETED ); - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_LINES_TO_RECT ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_LINES_TO_RECT ) ); item->SetItems( left->seg, top->seg, right->seg, bottom->seg ); m_itemsList->push_back( item ); diff --git a/pcbnew/graphics_cleaner.h b/pcbnew/graphics_cleaner.h index fc8416e38b..3607669907 100644 --- a/pcbnew/graphics_cleaner.h +++ b/pcbnew/graphics_cleaner.h @@ -42,7 +42,7 @@ public: * @param aMergeRects = merge for segments forming a rectangle into a rect * @param aDeleteRedundant = true to delete null graphics and duplicated graphics */ - void CleanupBoard( bool aDryRun, std::vector* aItemsList, bool aMergeRects, + void CleanupBoard( bool aDryRun, std::vector >* aItemsList, bool aMergeRects, bool aDeleteRedundant ); private: @@ -57,7 +57,7 @@ private: MODULE* m_parentModule; // nullptr if not in ModEdit BOARD_COMMIT& m_commit; bool m_dryRun; - std::vector* m_itemsList; + std::vector >* m_itemsList; }; diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index fa53e70eb7..fd053a93d1 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -199,7 +199,7 @@ static void insideArea( LIBEVAL::CONTEXT* aCtx, void* self ) PCB_EXPR_BUILTIN_FUNCTIONS::PCB_EXPR_BUILTIN_FUNCTIONS() { - auto registerFunc = [&]( const wxString& funcSignature, FPTR funcPtr ) + auto registerFunc = [&]( const wxString& funcSignature, LIBEVAL::FUNC_CALL_REF funcPtr ) { wxString funcName = funcSignature.BeforeFirst( '(' ); m_funcs[ std::string( funcName.Lower() ) ] = std::move( funcPtr ); @@ -262,7 +262,7 @@ LIBEVAL::VALUE PCB_EXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx ) } -LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::CreateFuncCall( const char* aName ) +LIBEVAL::FUNC_CALL_REF PCB_EXPR_UCODE::CreateFuncCall( const wxString& aName ) { PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance(); @@ -270,28 +270,30 @@ LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::CreateFuncCall( const char* aName ) } -LIBEVAL::VAR_REF* PCB_EXPR_UCODE::CreateVarRef( const char* aVar, const char* aField ) +std::unique_ptr PCB_EXPR_UCODE::CreateVarRef( const wxString& aVar, const wxString& aField ) { PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); - PCB_EXPR_VAR_REF* vref = nullptr; + std::unique_ptr vref;; - if( *aVar == 'A' ) + if( aVar == "A" ) { - vref = new PCB_EXPR_VAR_REF( 0 ); + vref.reset( new PCB_EXPR_VAR_REF( 0 ) ); } - else if( *aVar == 'B' ) + else if( aVar == "B" ) { - vref = new PCB_EXPR_VAR_REF( 1 ); + vref.reset( new PCB_EXPR_VAR_REF( 1 ) ); } else { - return vref; + return nullptr; } - if( strlen( aField ) == 0 ) // return reference to base object - return vref; + if( aField.length() == 0 ) // return reference to base object + { + return std::move( vref ); + } - wxString field = wxString::FromUTF8( aField ); + wxString field( aField ); field.Replace( "_", " " ); for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() ) @@ -329,7 +331,7 @@ LIBEVAL::VAR_REF* PCB_EXPR_UCODE::CreateVarRef( const char* aVar, const char* aF if( vref->GetType() == LIBEVAL::VT_UNDEFINED ) vref->SetType( LIBEVAL::VT_PARSE_ERROR ); - return vref; + return std::move( vref ); } @@ -340,16 +342,16 @@ public: { } - virtual const std::vector& GetSupportedUnits() const override + virtual const std::vector& GetSupportedUnits() const override { - static const std::vector pcbUnits = { "mil", "mm", "in" }; + static const std::vector pcbUnits = { "mil", "mm", "in" }; return pcbUnits; } - virtual double Convert( const std::string& aString, int unitId ) const override + virtual double Convert( const wxString& aString, int unitId ) const override { - double v = atof( aString.c_str() ); + double v = wxAtof( aString ); switch( unitId ) { @@ -362,15 +364,13 @@ public: }; -PCB_EXPR_COMPILER::PCB_EXPR_COMPILER( REPORTER* aReporter, int aSourceLine, int aSourcePos ) : - COMPILER( aReporter, aSourceLine, aSourcePos ) +PCB_EXPR_COMPILER::PCB_EXPR_COMPILER() { m_unitResolver = std::make_unique(); } -PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR( REPORTER* aReporter, int aSourceLine, int aSourceOffset ) : - m_compiler( aReporter, aSourceLine, aSourceOffset ) +PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR() { m_result = 0; } diff --git a/pcbnew/pcb_expr_evaluator.h b/pcbnew/pcb_expr_evaluator.h index 7f760ca724..90b8dbfe8f 100644 --- a/pcbnew/pcb_expr_evaluator.h +++ b/pcbnew/pcb_expr_evaluator.h @@ -43,9 +43,8 @@ public: PCB_EXPR_UCODE() {}; virtual ~PCB_EXPR_UCODE() {}; - virtual LIBEVAL::VAR_REF* CreateVarRef( const char* aVar, const char* aField ) override; - - virtual FUNC_PTR CreateFuncCall( const char* aName ) override; + virtual std::unique_ptr CreateVarRef( const wxString& aVar, const wxString& aField ) override; + virtual LIBEVAL::FUNC_CALL_REF CreateFuncCall( const wxString& aName ) override; }; @@ -76,7 +75,7 @@ public: } private: - BOARD_ITEM* m_items[2]; + BOARD_ITEM* m_items[2]; PCB_LAYER_ID m_layer; }; @@ -92,6 +91,8 @@ public: //printf("*** CreateVarRef %p %d\n", this, aItemIndex ); } + ~PCB_EXPR_VAR_REF() {}; + void SetIsEnum( bool s ) { m_isEnum = s; } bool IsEnum() const { return m_isEnum; } @@ -128,7 +129,7 @@ public: return self; } - LIBEVAL::UCODE::FUNC_PTR Get( const wxString &name ) + LIBEVAL::FUNC_CALL_REF Get( const std::string &name ) { return m_funcs[ name ]; } @@ -139,7 +140,7 @@ public: } private: - std::map m_funcs; + std::map m_funcs; wxArrayString m_funcSigs; }; @@ -155,17 +156,20 @@ public: class PCB_EXPR_EVALUATOR { public: - PCB_EXPR_EVALUATOR( REPORTER* aReporter, int aSourceLine, int aSourceOffset ); + PCB_EXPR_EVALUATOR( ); ~PCB_EXPR_EVALUATOR(); bool Evaluate( const wxString& aExpr ); int Result() const { return m_result; } + bool IsErrorPending() const { return m_errorStatus.pendingError; } + const LIBEVAL::ERROR_STATUS& GetError() const { return m_errorStatus; } private: int m_result; PCB_EXPR_COMPILER m_compiler; PCB_EXPR_UCODE m_ucode; + LIBEVAL::ERROR_STATUS m_errorStatus; }; #endif diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index d3f9f68509..1db01ed3d1 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -50,7 +50,7 @@ TRACKS_CLEANER::TRACKS_CLEANER( BOARD* aPcb, BOARD_COMMIT& aCommit ) : * - vias on pad * - null length segments */ -void TRACKS_CLEANER::CleanupBoard( bool aDryRun, std::vector* aItemsList, +void TRACKS_CLEANER::CleanupBoard( bool aDryRun, std::vector >* aItemsList, bool aRemoveMisConnected, bool aCleanVias, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias ) { @@ -109,7 +109,7 @@ void TRACKS_CLEANER::removeBadTrackSegments() { if( segment->GetNetCode() != testedPad->GetNetCode() ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_SHORT ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_SHORT ) ); item->SetItems( segment ); m_itemsList->push_back( item ); @@ -121,7 +121,7 @@ void TRACKS_CLEANER::removeBadTrackSegments() { if( segment->GetNetCode() != testedTrack->GetNetCode() ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_SHORT ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_SHORT ) ); item->SetItems( segment ); m_itemsList->push_back( item ); @@ -168,7 +168,7 @@ void TRACKS_CLEANER::cleanupVias() if( ( pad->GetLayerSet() & all_cu ) == all_cu ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_REDUNDANT_VIA ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_REDUNDANT_VIA ) ); item->SetItems( via1, pad ); m_itemsList->push_back( item ); @@ -187,7 +187,7 @@ void TRACKS_CLEANER::cleanupVias() if( via1->GetViaType() == via2->GetViaType() ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_REDUNDANT_VIA ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_REDUNDANT_VIA ) ); item->SetItems( via1, via2 ); m_itemsList->push_back( item ); @@ -267,7 +267,7 @@ bool TRACKS_CLEANER::deleteDanglingTracks( bool aVia ) int errorCode = ( track->Type() != PCB_VIA_T ) ? CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA; - CLEANUP_ITEM* item = new CLEANUP_ITEM( errorCode ); + std::shared_ptr item( new CLEANUP_ITEM( errorCode ) ); item->SetItems( track ); m_itemsList->push_back( item ); @@ -300,7 +300,7 @@ void TRACKS_CLEANER::deleteNullSegments( TRACKS& aTracks ) { if( segment->IsNull() && segment->Type() == PCB_TRACE_T && !segment->IsLocked() ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_ZERO_LENGTH_TRACK ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_ZERO_LENGTH_TRACK ) ); item->SetItems( segment ); m_itemsList->push_back( item ); @@ -336,12 +336,12 @@ void TRACKS_CLEANER::deleteTracksInPads() poly.BooleanSubtract( *pad->GetEffectivePolygon(), SHAPE_POLY_SET::PM_FAST ); if( poly.IsEmpty() ) - { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_TRACK_IN_PAD ); - item->SetItems( track ); - m_itemsList->push_back( item ); + { + CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_TRACK_IN_PAD ); + item->SetItems( track ); + m_itemsList->push_back( item ); - toRemove.insert( track ); + toRemove.insert( track ); } } } @@ -380,7 +380,7 @@ void TRACKS_CLEANER::cleanupSegments() && track1->GetWidth() == track2->GetWidth() && track1->GetLayer() == track2->GetLayer() ) { - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_DUPLICATE_TRACK ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_DUPLICATE_TRACK ) ); item->SetItems( track2 ); m_itemsList->push_back( item ); @@ -489,7 +489,7 @@ bool TRACKS_CLEANER::mergeCollinearSegments( TRACK* aSeg1, TRACK* aSeg2 ) return false; } - CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_MERGE_TRACKS ); + std::shared_ptr item( new CLEANUP_ITEM( CLEANUP_MERGE_TRACKS ) ); item->SetItems( aSeg1, aSeg2 ); m_itemsList->push_back( item ); diff --git a/pcbnew/tracks_cleaner.h b/pcbnew/tracks_cleaner.h index b42531a4d3..dd022f3994 100644 --- a/pcbnew/tracks_cleaner.h +++ b/pcbnew/tracks_cleaner.h @@ -47,7 +47,7 @@ public: * @param aDeleteTracksinPad = true to remove tracks fully inside pads * @param aDeleteDanglingVias = true to remove a via that is only connected to a single layer */ - void CleanupBoard( bool aDryRun, std::vector* aItemsList, bool aCleanVias, + void CleanupBoard( bool aDryRun, std::vector >* aItemsList, bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias ); @@ -102,7 +102,7 @@ private: BOARD* m_brd; BOARD_COMMIT& m_commit; bool m_dryRun; - std::vector* m_itemsList; + std::vector >* m_itemsList; }; diff --git a/qa/pcbnew/drc/test_drc_courtyard_invalid.cpp b/qa/pcbnew/drc/test_drc_courtyard_invalid.cpp index 64038d6d55..9dd8ce54e2 100644 --- a/qa/pcbnew/drc/test_drc_courtyard_invalid.cpp +++ b/qa/pcbnew/drc/test_drc_courtyard_invalid.cpp @@ -234,7 +234,7 @@ std::unique_ptr MakeBoard( const std::vector( aMarker.GetRCItem() ); + auto reporter = std::static_pointer_cast( aMarker.GetRCItem() ); const MODULE* item_a = dynamic_cast( aBoard.GetItem( reporter->GetMainItemID() ) ); // This one is more than just a mis-match! diff --git a/qa/pcbnew/drc/test_drc_courtyard_overlap.cpp b/qa/pcbnew/drc/test_drc_courtyard_overlap.cpp index 8f3e829e60..39bae76a7c 100644 --- a/qa/pcbnew/drc/test_drc_courtyard_overlap.cpp +++ b/qa/pcbnew/drc/test_drc_courtyard_overlap.cpp @@ -396,7 +396,7 @@ static std::vector courtyard_cases = { static bool CollisionMatchesExpected( BOARD& aBoard, const MARKER_PCB& aMarker, const COURTYARD_COLLISION& aCollision ) { - const DRC_ITEM* reporter = static_cast( aMarker.GetRCItem() ); + auto reporter = std::static_pointer_cast( aMarker.GetRCItem() ); const MODULE* item_a = dynamic_cast( aBoard.GetItem( reporter->GetMainItemID() ) ); const MODULE* item_b = dynamic_cast( aBoard.GetItem( reporter->GetAuxItemID() ) );