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() );
124 for( std::size_t actionIdx : aConflictActionIndices )
126 if( actionIdx >= aPlan.
actions.size() )
136 auto it = aResolutions.find( action.
id.
AsString() );
138 if( it == aResolutions.end() )
148 staged.emplace_back( actionIdx, it->second );
151 for(
const auto& [actionIdx, kind] : staged )
152 aPlan.
actions[actionIdx].kind = kind;
163 std::vector<CONFLICT_LIST_ENTRY> out;
167 for( std::size_t i = 0; i < aPlan.
actions.size(); ++i )
179 if( label.Length() > 40 )
180 label = wxS(
"…" ) + label.Right( 39 );
182 out.push_back( { i, label, action.
id } );
189std::vector<KIID_PATH>
191 const std::vector<std::size_t>& aConflictActionIndices )
193 std::vector<KIID_PATH> out;
195 for( std::size_t actionIdx : aConflictActionIndices )
201 if( actionIdx >= aPlan.
actions.size() )
209 out.push_back( a.
id );
219 const std::map<KIID_PATH, BOX2I>& aPrimary,
220 const std::map<KIID_PATH, BOX2I>& aOurs,
221 const std::map<KIID_PATH, BOX2I>& aTheirs,
222 const std::map<KIID_PATH, BOX2I>& aAncestor )
224 auto find = [](
const std::map<KIID_PATH, BOX2I>& aMap,
225 const KIID_PATH& aLookup ) -> std::optional<BOX2I>
227 auto it = aMap.find( aLookup );
229 if( it == aMap.end() )
236 if( it->second.GetWidth() <= 0 && it->second.GetHeight() <= 0 )
242 if(
auto b =
find( aPrimary, aId ); b.has_value() )
return b;
243 if(
auto b =
find( aOurs, aId ); b.has_value() )
return b;
244 if(
auto b =
find( aTheirs, aId ); b.has_value() )
return b;
245 if(
auto b =
find( aAncestor, aId ); b.has_value() )
return b;
255 text <<
_(
"Current resolution: " );
257 switch( aResolution.
kind )
267 text << wxS(
"\n\n" );
268 text << wxString::Format( wxPLURAL(
"%zu property edit in this resolution.\n",
269 "%zu property edits in this resolution.\n", aResolution.
props.size() ),
270 aResolution.
props.size() );
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...
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::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
std::vector< PROPERTY_RESOLUTION > props
Result of planning a 3-way merge.
std::vector< ITEM_RESOLUTION > actions
std::vector< KIID_PATH > unresolved