26#include <nlohmann/json.hpp>
44 j = nlohmann::json::parse( aJsonContent );
46 catch(
const nlohmann::json::exception& e )
59 for(
const auto& [key, val] : j.items() )
61 const wxString keyStr = wxString::FromUTF8( key );
63 if( !val.is_string() )
77 catch(
const std::invalid_argument& )
105APPLY_AUTO_RESOLUTIONS_RESULT
107 const std::vector<std::size_t>& aConflictActionIndices,
108 const std::map<wxString, ITEM_RES>& aResolutions )
112 if( aConflictActionIndices.empty() )
121 std::vector<std::pair<std::size_t, ITEM_RES>> staged;
122 staged.reserve( aConflictActionIndices.size() );
126 for( std::size_t actionIdx : aConflictActionIndices )
128 if( actionIdx >= aPlan.
actions.size() )
138 auto it = aResolutions.find( action.
id.
AsString() );
140 if( it == aResolutions.end() )
151 staged.emplace_back( actionIdx, it->second );
154 for(
const auto& [actionIdx, kind] : staged )
155 aPlan.
actions[actionIdx].kind = kind;
166 std::vector<CONFLICT_LIST_ENTRY> out;
170 for( std::size_t i = 0; i < aPlan.
actions.size(); ++i )
182 if( label.Length() > 40 )
183 label = wxS(
"…" ) + label.Right( 39 );
185 out.push_back( { i, label, action.
id } );
192std::vector<KIID_PATH>
194 const std::vector<std::size_t>& aConflictActionIndices )
196 std::vector<KIID_PATH> out;
198 for( std::size_t actionIdx : aConflictActionIndices )
204 if( actionIdx >= aPlan.
actions.size() )
212 out.push_back( a.
id );
221 const std::function<std::set<wxString>(
const KIID_PATH& )>& aEditedNames )
230 if( aCanCombine( action.
id ) )
232 unresolved.erase( action.
id );
240 action.
props.clear();
243 for(
const wxString&
name : aEditedNames( action.
id ) )
247 action.
props.push_back( std::move( prop ) );
250 if( unresolved.insert( action.
id ).second )
257 return !unresolved.contains( aId );
264 std::set<wxString> names;
267 names.insert(
delta.name );
273 names.insert( wxString::Format(
_(
"Pin %s" ), *child.
refdes ) );
287 std::set<wxString> edited;
289 for(
const std::map<KIID_PATH, const ITEM_CHANGE*>* changes : { &ours, &theirs } )
291 if(
auto it = changes->find( aId ); it != changes->end() )
302 const std::map<KIID_PATH, BOX2I>& aPrimary,
303 const std::map<KIID_PATH, BOX2I>& aOurs,
304 const std::map<KIID_PATH, BOX2I>& aTheirs,
305 const std::map<KIID_PATH, BOX2I>& aAncestor )
307 auto find = [](
const std::map<KIID_PATH, BOX2I>& aMap,
308 const KIID_PATH& aLookup ) -> std::optional<BOX2I>
310 auto it = aMap.find( aLookup );
312 if( it == aMap.end() )
319 if( it->second.GetWidth() <= 0 && it->second.GetHeight() <= 0 )
325 if(
auto b =
find( aPrimary, aId ); b.has_value() )
return b;
326 if(
auto b =
find( aOurs, aId ); b.has_value() )
return b;
327 if(
auto b =
find( aTheirs, aId ); b.has_value() )
return b;
328 if(
auto b =
find( aAncestor, aId ); b.has_value() )
return b;
337 text <<
_(
"Current resolution: " );
339 switch( aResolution.
kind )
349 text << wxS(
"\n\n" );
350 text << wxString::Format( wxPLURAL(
"%zu property edit in this resolution.\n",
351 "%zu property edits in this resolution.\n", aResolution.
props.size() ),
352 aResolution.
props.size() );
359 if( !names.IsEmpty() )
360 names << wxS(
", " );
365 if( !names.IsEmpty() )
366 text << wxString::Format(
_(
"Changed on either side: %s\n" ), names );
wxString AsString() const
wxString BuildConflictDetailText(const ITEM_RESOLUTION &aResolution)
Build the human-readable detail text shown in the merge dialog's resolution panel for a given ITEM_RE...
void SettleLibraryMerges(MERGE_PLAN &aPlan, const std::function< bool(const KIID_PATH &)> &aCanCombine, const std::function< std::set< wxString >(const KIID_PATH &)> &aEditedNames)
Settle the MERGE_PROPS of a library merge, where an item is combined whole or not at all.
AUTO_RESOLUTION_PARSE_RESULT ParseAutoResolutionJson(const std::string &aJsonContent)
Parse a KICAD_MERGETOOL_AUTO-format JSON object mapping item IDs (KIID_PATH strings) to ITEM_RES spel...
@ BAD_VALUE
at least one entry's value wasn't a string
@ NOT_OBJECT
JSON parsed but the root was not an object.
@ INVALID_JSON
input could not be parsed as JSON
@ UNKNOWN_KIND
at least one entry's string wasn't a known ITEM_RES
@ OK
parsed cleanly; resolutions is populated
@ ENGINE_INTERNAL_KIND
at least one entry asked for an engine-internal kind (KEEP / DELETE / MERGE_PROPS); only the TAKE_* f...
ITEM_RES
Resolution kind for a whole item.
std::vector< CONFLICT_LIST_ENTRY > BuildConflictList(const MERGE_PLAN &aPlan)
std::optional< BOX2I > ResolveConflictBBox(const KIID_PATH &aId, const std::map< KIID_PATH, BOX2I > &aPrimary, const std::map< KIID_PATH, BOX2I > &aOurs, const std::map< KIID_PATH, BOX2I > &aTheirs, const std::map< KIID_PATH, BOX2I > &aAncestor)
Resolve the best bounding box for a conflicted item across the three sides of a 3-way merge.
APPLY_AUTO_RESOLUTIONS_RESULT ApplyAutoResolutions(MERGE_PLAN &aPlan, const std::vector< std::size_t > &aConflictActionIndices, const std::map< wxString, ITEM_RES > &aResolutions)
Apply a parsed auto-resolution map to a MERGE_PLAN's conflicts.
ITEM_RES ItemResFromString(const std::string &aStr)
std::map< KIID_PATH, const ITEM_CHANGE * > IndexChangesByKiid(const DOCUMENT_DIFF &aDiff)
Flatten a DOCUMENT_DIFF's ITEM_CHANGE tree into a KIID_PATH -> ITEM_CHANGE* map, recursing into child...
std::function< std::set< wxString >(const KIID_PATH &)> EditedNamesIn(const DOCUMENT_DIFF &aOurs, const DOCUMENT_DIFF &aTheirs)
What either side edits in an item, for SettleLibraryMerges. Both diffs must outlive the result.
std::set< wxString > EditedNames(const ITEM_CHANGE &aChange)
The properties and elements aChange edits, by the names a user would know them by.
std::vector< KIID_PATH > CollectUnresolvedConflicts(const MERGE_PLAN &aPlan, const std::vector< std::size_t > &aConflictActionIndices)
Return the conflict actions that still have no decision.
APPLY_AUTO_RESOLUTIONS_STATUS status
KIID_PATH firstMissingId
Set only when status == PARTIAL AND the partial result was caused by a missing entry in the auto-reso...
Result of ParseAutoResolutionJson.
AUTO_RESOLUTION_STATUS status
std::map< wxString, ITEM_RES > resolutions
The full set of changes between two parsed documents of one type.
One change record on a single item.
std::vector< PROPERTY_DELTA > properties
std::optional< wxString > refdes
std::vector< ITEM_CHANGE > children
std::vector< PROPERTY_RESOLUTION > props
Result of planning a 3-way merge.
std::vector< ITEM_RESOLUTION > actions
std::vector< KIID_PATH > unresolved
Single (name, before, after) triple for one mutated property on an item.