68AUTO_MODE loadAutoResolutionFile( std::map<wxString, KICAD_DIFF::ITEM_RES>& aOut )
72 if( !wxGetEnv( wxT(
"KICAD_MERGETOOL_AUTO" ), &
path ) ||
path.IsEmpty() )
73 return AUTO_MODE::NOT_SET;
75 wxFFile file(
path, wxT(
"rb" ) );
78 if( !file.IsOpened() || !file.ReadAll( &contents, wxConvUTF8 ) )
81 wxT(
"KICAD_MERGETOOL_AUTO points at unreadable path '%s'" ),
path );
82 return AUTO_MODE::LOAD_FAILED;
87 std::string( contents.utf8_str().data(), contents.utf8_str().length() ) );
92 wxT(
"KICAD_MERGETOOL_AUTO parse failed (status=%d, context=%s)" ),
94 return AUTO_MODE::LOAD_FAILED;
98 return AUTO_MODE::LOADED;
107 std::map<KIID_PATH, wxString> names;
109 for(
const wxString&
name : aNames )
112 auto nameOf = [names = std::move( names )](
const KIID_PATH& aId ) -> wxString
114 auto it = names.find( aId );
115 return it != names.end() ? it->second : wxString();
122 const std::optional<KIID_PATH>& aId )
124 draw( aCanvas, aSide, aId ? nameOf( *aId ) : wxString() );
136 aReporter.
Report(
_(
"--interactive requires a GUI KiCad process; the console "
137 "kicad-cli cannot open dialogs.\n" ),
159 m_canvas->SetMinSize( wxSize( -1, 200 ) );
163 const size_t insertAt = std::min<size_t>( 1, resolutionSizer->GetItemCount() );
164 resolutionSizer->Insert( insertAt,
m_canvas,
165 wxSizerFlags( 1 ).Expand().Border( wxALL, 4 ) );
208 std::map<wxString, KICAD_DIFF::ITEM_RES> autoResolutions;
210 switch( loadAutoResolutionFile( autoResolutions ) )
212 case AUTO_MODE::NOT_SET:
215 case AUTO_MODE::LOAD_FAILED:
217 wxT(
"KICAD_MERGETOOL_AUTO load failed; closing dialog as cancelled" ) );
218 CallAfter( [
this]() { EndModal( wxID_CANCEL ); } );
221 case AUTO_MODE::LOADED:
231 wxT(
"KICAD_MERGETOOL_AUTO missing resolution for %s" ),
233 CallAfter( [
this]() { EndModal( wxID_CANCEL ); } );
238 CallAfter( [
this]() { EndModal( wxID_APPLY ); } );
240 wxT(
"KICAD_MERGETOOL_AUTO applied %zu auto-resolutions" ),
253 EndModal( wxID_CANCEL );
259 EndModal( wxID_CANCEL );
266 const std::vector<KIID_PATH> stillUnresolved =
269 if( !stillUnresolved.empty() )
271 wxMessageBox( wxString::Format( wxPLURAL(
"%zu conflict still needs a resolution. "
272 "Pick Ours, Theirs, or Ancestor for each one.",
273 "%zu conflicts still need a resolution. "
274 "Pick Ours, Theirs, or Ancestor for each one.",
275 stillUnresolved.size() ),
276 stillUnresolved.size() ),
277 _(
"Resolve Merge Conflicts" ),
278 wxOK | wxICON_INFORMATION,
this );
282 m_plan.unresolved.clear();
283 EndModal( wxID_APPLY );
336 const std::map<KIID_PATH, BOX2I>* primaryBBoxes =
nullptr;
350 primaryBBoxes = &
m_context.ancestorBBoxes;
354 static const std::map<KIID_PATH, BOX2I> emptyBBoxMap;
364 const std::optional<BOX2I> resolved =
367 primaryBBoxes ? *primaryBBoxes : emptyBBoxMap,
371 if( resolved.has_value() )
373 conflictBBox = *resolved;
376 shape.
bbox = conflictBBox;
377 shape.
color = highlightColor();
388 std::optional<KIID_PATH> highlight;
393 m_canvas->SetScene( std::move( scene ) );
400 m_canvas->HighlightChange( highlight );
406 BOX2I focus = conflictBBox;
417 wxString named =
m_context.describeItem( aId );
419 if( !named.IsEmpty() )
449 m_labelDetail->SetLabel(
_(
"Select a conflict on the left to see details." ) );
461 m_radioUnresolved->SetLabel( offersMerge ?
_(
"Merge both changes" ) :
_(
"Not decided yet" ) );
465 switch( action.
kind )
478 case SIDE::OURS: shown =
_(
"showing your version" );
break;
479 case SIDE::THEIRS: shown =
_(
"showing their version" );
break;
490 +
_(
"\n\nBoth sides changed this item, and their edits are combined.\n"
491 "Where both changed the same thing, your version is kept.\n"
492 "Pick a side to take that version whole instead." ) );
496 m_textDetail->SetValue(
_(
"Pick Ours, Theirs, or Ancestor to preview and keep that version." ) );
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
wxButton * m_sdbSizerApply
wxRadioButton * m_radioTheirs
wxRadioButton * m_radioAncestor
wxStaticText * m_labelIntro
wxRadioButton * m_radioUnresolved
wxRadioButton * m_radioOurs
wxStaticText * m_labelDetail
wxListBox * m_listConflicts
DIALOG_KICAD_MERGE_3WAY_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Resolve Merge Conflicts"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(950, 700), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxTextCtrl * m_textDetail
wxPanel * m_panelResolution
void OnConflictSelected(wxCommandEvent &aEvent) override
SIDE activeSide() const
The side the canvas previews.
DIALOG_KICAD_MERGE_3WAY(wxWindow *aParent, const KICAD_DIFF::MERGE_PLAN &aPlan, CONFLICT_CONTEXT aContext={})
static CONFLICT_CONTEXT LibraryContext(const std::set< wxString > &aNames, LIBRARY_ITEM_DRAWER aDraw)
Context for merging a library, whose items are known by the names in aNames.
static bool CanOpen(REPORTER &aReporter)
Report to aReporter and return false when this process cannot open a dialog.
void OnApply(wxCommandEvent &aEvent) override
wxString describe(const KIID_PATH &aId, const wxString &aFallback) const
The item's name from the editor, or aFallback when there is none.
void OnCancel(wxCommandEvent &aEvent) override
void rebuildCanvas()
Rebuild the canvas scene from the current side (per radio) and the active conflict's bbox.
void OnClose(wxCloseEvent &aEvent) override
WIDGET_DIFF_CANVAS * m_canvas
GAL-backed conflict viewer injected into the resolution panel.
KICAD_DIFF::MERGE_PLAN m_plan
int m_currentConflict
Currently-displayed conflict (index into m_conflictActionIndex), -1 if none.
std::function< void(WIDGET_DIFF_CANVAS &, SIDE, const wxString &aName)> LIBRARY_ITEM_DRAWER
CONFLICT_CONTEXT m_context
void showConflict(int aIndex)
Update the detail panel for the selected conflict.
void buildList()
Populate the conflict list from the plan's unresolved items.
SIDE
Which side's version the canvas should currently display.
std::vector< bool > m_hasMergedEdit
True where the engine combined both sides' edits, in the order of m_conflictActionIndex.
void OnResolutionChanged(wxCommandEvent &aEvent) override
std::vector< std::size_t > m_conflictActionIndex
Indices into m_plan.actions matching the order of m_listConflicts.
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
A color representation with 4 components: red, green, blue, alpha.
wxString AsString() const
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
static bool empty(const wxTextEntryBase *aCtrl)
const wxChar *const traceDiffMerge
Flag to enable diff/merge engine and renderer debugging output.
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...
@ OK
parsed cleanly; resolutions is populated
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.
KIID_PATH LibraryItemKiidPath(const wxString &aName)
Build a deterministic synthetic KIID_PATH from a library item name (symbol name or footprint name).
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.
void ExpandBBoxToGeometry(DIFF_SCENE &aScene)
Grow the scene's documentBBox to also include the extent of any background geometry.
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.
PGM_BASE & Pgm()
The global program "get" accessor.
Phase 8 context for the conflict canvas.
std::function< void(WIDGET_DIFF_CANVAS &, SIDE, const std::optional< KIID_PATH > &)> drawSide
Draw a side on the canvas with the editor's own painter.
std::function< wxString(const KIID_PATH &)> describeItem
Name an item the way the editor would, so a conflict can be told from its neighbours.
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
Build the list of conflict-action indices the dialog walks: the positions in plan....
Diff colors with defaults for light backgrounds.
DOCUMENT_GEOMETRY referenceGeometry
Background geometry from the two source documents.
std::vector< SCENE_SHAPE > conflictShapes
Result of planning a 3-way merge.
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
KIID_PATH changeId
Stable identifier of the ITEM_CHANGE that produced this shape.
wxLogTrace helper definitions.