487 result.docType = wxS(
"kicad_pcb" );
496 std::vector<ITEM_DESCRIPTOR> beforeDesc;
497 std::vector<ITEM_DESCRIPTOR> afterDesc;
498 std::map<KIID, const BOARD_ITEM*> beforeMap;
499 std::map<KIID, const BOARD_ITEM*> afterMap;
501 beforeDesc.reserve( beforeSet.size() );
502 afterDesc.reserve( afterSet.size() );
510 beforeMap[item->m_Uuid] = item;
519 afterMap[item->m_Uuid] = item;
539 result.changes.push_back( std::move( c ) );
544 if( std::find_if(
result.changes.begin(),
result.changes.end(),
547 return aC.id == dup && aC.kind == CHANGE_KIND::DUPLICATE_UUID;
559 result.changes.push_back( std::move( c ) );
563 for(
const auto& [idA, idB] : recon.
aToB )
565 const KIID& uuidA = idA.back();
566 const KIID& uuidB = idB.back();
567 auto itA = beforeMap.find( uuidA );
568 auto itB = afterMap.find( uuidB );
569 const BOARD_ITEM* a = itA == beforeMap.end() ? nullptr : itA->second;
570 const BOARD_ITEM* b = itB == afterMap.end() ? nullptr : itB->second;
575 std::vector<PROPERTY_DELTA> propDeltas;
583 std::vector<ITEM_CHANGE> childChanges;
585 if(
auto fpA =
dynamic_cast<const FOOTPRINT*
>( a ) )
587 if(
auto fpB =
dynamic_cast<const FOOTPRINT*
>( b ) )
591 if( propDeltas.empty() && childChanges.empty() )
602 c.
children = std::move( childChanges );
603 result.changes.push_back( std::move( c ) );
611 auto isAutoGenerated = [](
const BOARD_ITEM* aItem )
619 if(
auto zone =
dynamic_cast<const ZONE*
>( aItem ) )
620 return zone->IsTeardropArea();
628 auto it = beforeMap.find( idA.back() );
630 if( it == beforeMap.end() || !it->second )
635 if( isAutoGenerated( a ) )
649 if(
auto fp =
dynamic_cast<const FOOTPRINT*
>( a ) )
651 std::vector<ITEM_CHANGE> dummyAfter;
658 result.changes.push_back( std::move( c ) );
664 auto it = afterMap.find( idB.back() );
666 if( it == afterMap.end() || !it->second )
671 if( isAutoGenerated( b ) )
683 if(
auto fp =
dynamic_cast<const FOOTPRINT*
>( b ) )
689 result.changes.push_back( std::move( c ) );
699 std::vector<PROPERTY_DELTA> docDeltas;
710 if( beforeThickness != afterThickness )
716 docDeltas.push_back( std::move( d ) );
719 auto summarizePlotOptions = [](
const PCB_PLOT_PARAMS& aParams ) -> std::string
722 aParams.Format( &formatter );
723 return wxString::Format( wxS(
"hash %zx" ), std::hash<std::string>{}( formatter.
GetString() ) )
727 const std::string beforePlot = summarizePlotOptions(
m_before->GetPlotOptions() );
728 const std::string afterPlot = summarizePlotOptions(
m_after->GetPlotOptions() );
730 if( beforePlot != afterPlot )
736 docDeltas.push_back( std::move( d ) );
745 docDeltas.push_back( std::move( d ) );
749 auto appendKeyedDeltas =
750 [&](
const wxString& aPrefix,
const std::map<wxString, wxString>& aBefore,
751 const std::map<wxString, wxString>& aAfter )
753 std::set<wxString> names;
755 for(
const auto& [
name, value] : aBefore )
756 names.insert(
name );
758 for(
const auto& [
name, value] : aAfter )
759 names.insert(
name );
761 auto render = [](
const std::map<wxString, wxString>& aMap,
const wxString& aName )
763 auto it = aMap.find( aName );
765 if( it == aMap.end() )
766 return wxString( wxS(
"(none)" ) );
768 return wxS(
"\"" ) + it->second + wxS(
"\"" );
771 for(
const wxString&
name : names )
773 const wxString before =
render( aBefore,
name );
774 const wxString after =
render( aAfter,
name );
776 if( before != after )
782 docDeltas.push_back( std::move( d ) );
787 auto boardVariants = [](
const BOARD* aBoard )
789 std::map<wxString, wxString>
result;
791 for(
const wxString&
name : aBoard->GetVariantNames() )
809 auto summarizeStackup = [](
const BOARD_STACKUP& aStackup ) -> std::string
828 std::size_t h = std::hash<std::string>{}( aStackup.m_FinishType.ToStdString() );
829 h =
KiHashCombine( h, std::hash<bool>{}( aStackup.m_HasDielectricConstrains ) );
830 h =
KiHashCombine( h, std::hash<bool>{}( aStackup.m_HasThicknessConstrains ) );
831 h =
KiHashCombine( h, std::hash<bool>{}( aStackup.m_EdgePlating ) );
832 h =
KiHashCombine( h, std::hash<int>{}(
static_cast<int>( aStackup.m_EdgeConnectorConstraints ) ) );
839 h =
KiHashCombine( h, std::hash<int>{}(
static_cast<int>( item->GetType() ) ) );
840 h =
KiHashCombine( h, std::hash<int>{}(
static_cast<int>( item->GetBrdLayerId() ) ) );
842 h =
KiHashCombine( h, std::hash<bool>{}( item->IsEnabled() ) );
844 for(
int sub = 0; sub < item->GetSublayersCount(); ++sub )
846 h =
KiHashCombine( h, std::hash<int>{}( item->GetThickness( sub ) ) );
850 if( item->HasEpsilonRValue() )
851 h =
KiHashCombine( h, std::hash<double>{}( item->GetEpsilonR( sub ) ) );
853 if( item->HasLossTangentValue() )
854 h =
KiHashCombine( h, std::hash<double>{}( item->GetLossTangent( sub ) ) );
858 return wxString::Format( wxS(
"%d copper / %d dielectric layers (hash %zx)" ), copper, dielectric, h )
862 if( beforeStackup != afterStackup )
868 docDeltas.push_back( std::move( d ) );
877 if( beforeDRC != afterDRC )
883 docDeltas.push_back( std::move( d ) );
894 auto summarizeNetSettings = [](
const NET_SETTINGS& aSettings ) -> std::string
902 auto hashNetclass = [&](
const NETCLASS* nc )
908 hashCombine(
static_cast<std::size_t
>( nc->GetPriority() ) );
909 hashCombine(
static_cast<std::size_t
>( nc->GetClearanceOpt().value_or( -1 ) ) );
910 hashCombine(
static_cast<std::size_t
>( nc->GetTrackWidthOpt().value_or( -1 ) ) );
911 hashCombine(
static_cast<std::size_t
>( nc->GetViaDiameterOpt().value_or( -1 ) ) );
912 hashCombine(
static_cast<std::size_t
>( nc->GetViaDrillOpt().value_or( -1 ) ) );
913 hashCombine(
static_cast<std::size_t
>( nc->GetuViaDiameterOpt().value_or( -1 ) ) );
914 hashCombine(
static_cast<std::size_t
>( nc->GetuViaDrillOpt().value_or( -1 ) ) );
915 hashCombine(
static_cast<std::size_t
>( nc->GetDiffPairWidthOpt().value_or( -1 ) ) );
916 hashCombine(
static_cast<std::size_t
>( nc->GetDiffPairGapOpt().value_or( -1 ) ) );
917 hashCombine(
static_cast<std::size_t
>( nc->GetDiffPairViaGapOpt().value_or( -1 ) ) );
918 hashCombine(
static_cast<std::size_t
>( nc->GetWireWidthOpt().value_or( -1 ) ) );
919 hashCombine(
static_cast<std::size_t
>( nc->GetBusWidthOpt().value_or( -1 ) ) );
920 hashCombine(
static_cast<std::size_t
>( nc->GetLineStyleOpt().value_or( -1 ) ) );
929 hashNetclass( aSettings.GetDefaultNetclass().get() );
931 for(
const auto& [
name, nc] : aSettings.GetNetclasses() )
932 hashNetclass( nc.get() );
934 for(
const auto& [netname, classes] : aSettings.GetNetclassLabelAssignments() )
936 hashCombine( std::hash<std::string>{}( netname.ToStdString() ) );
938 for(
const wxString& c : classes )
939 hashCombine( std::hash<std::string>{}( c.ToStdString() ) );
942 for(
const auto& [
chain, className] : aSettings.GetNetChainClasses() )
945 hashCombine( std::hash<std::string>{}( className.ToStdString() ) );
948 for(
const auto& [
chain, netclass] : aSettings.GetNetChainNetClasses() )
951 hashCombine( std::hash<std::string>{}( netclass.ToStdString() ) );
954 for(
const auto& [netname, color] : aSettings.GetNetColorAssignments() )
956 hashCombine( std::hash<std::string>{}( netname.ToStdString() ) );
960 const std::size_t classCount = aSettings.GetNetclasses().size() + ( aSettings.GetDefaultNetclass() ? 1u : 0u );
962 return wxString::Format( wxS(
"%zu netclass(es) (hash %zx)" ), classCount, h ).ToStdString();
965 const std::shared_ptr<NET_SETTINGS>& beforeNet = beforeDS.
m_NetSettings;
966 const std::shared_ptr<NET_SETTINGS>& afterNet = afterDS.
m_NetSettings;
972 if( beforeNet && afterNet && *beforeNet != *afterNet )
978 docDeltas.push_back( std::move( d ) );
985 auto readSiblingDruContent = [](
const BOARD* aBoard ) -> wxString
988 return wxEmptyString;
990 wxString boardPath = aBoard->GetFileName();
992 if( boardPath.IsEmpty() )
993 return wxEmptyString;
995 wxFileName fn( boardPath );
998 if( !fn.FileExists() )
999 return wxEmptyString;
1001 wxFile file( fn.GetFullPath() );
1003 if( !file.IsOpened() )
1004 return wxEmptyString;
1007 file.ReadAll( &contents );
1011 auto summarizeRules = [](
const wxString& aContents ) -> std::string
1013 if( aContents.IsEmpty() )
1014 return "(no custom rules)";
1016 std::size_t h = std::hash<std::string>{}( aContents.ToStdString() );
1017 return wxString::Format( wxS(
"%zu byte(s) (hash %zx)" ), aContents.size(), h ).ToStdString();
1020 const wxString beforeRules = readSiblingDruContent(
m_before );
1021 const wxString afterRules = readSiblingDruContent(
m_after );
1023 if( beforeRules != afterRules )
1029 docDeltas.push_back( std::move( d ) );
1035 auto readProjectFileNamed = [](
const BOARD* aBoard,
const std::string& aFileName ) -> wxString
1038 return wxEmptyString;
1042 if( boardPath.IsEmpty() )
1043 return wxEmptyString;
1045 wxFileName fn( boardPath );
1046 fn.SetFullName( wxString::FromUTF8( aFileName ) );
1048 if( !fn.FileExists() )
1049 return wxEmptyString;
1051 wxFile file( fn.GetFullPath() );
1053 if( !file.IsOpened() )
1054 return wxEmptyString;
1057 file.ReadAll( &contents );
1061 auto summarizeTable = [](
const wxString& aContents,
const wxString& aLabel ) -> std::string
1063 if( aContents.IsEmpty() )
1064 return wxString::Format( wxS(
"(no %s)" ), aLabel ).ToStdString();
1066 std::size_t h = std::hash<std::string>{}( aContents.ToStdString() );
1067 return wxString::Format( wxS(
"%zu byte(s) (hash %zx)" ), aContents.size(), h ).ToStdString();
1073 if( beforeFp != afterFp )
1079 docDeltas.push_back( std::move( d ) );
1085 if( beforeSym != afterSym )
1091 docDeltas.push_back( std::move( d ) );
1097 auto boardDrawingSheet = [](
const BOARD* aBoard ) -> wxString
1100 return wxEmptyString;
1105 const wxString beforeSheet = boardDrawingSheet(
m_before );
1106 const wxString afterSheet = boardDrawingSheet(
m_after );
1108 if( beforeSheet != afterSheet )
1114 docDeltas.push_back( std::move( d ) );
1120 std::set<wxString> fileNames;
1123 fileNames.insert(
name );
1126 fileNames.insert(
name );
1130 return aFile ? wxString::FromUTF8( aFile->data_hash ) : wxString( wxS(
"(none)" ) );
1133 for(
const wxString&
name : fileNames )
1138 if( beforeHash != afterHash )
1144 docDeltas.push_back( std::move( d ) );
1154 docDeltas.push_back( std::move( d ) );
1157 if( !docDeltas.empty() )
1166 result.changes.push_back( std::move( c ) );