32#include <wx/stdstream.h>
33#include <wx/wfstream.h>
35#include <unordered_map>
48std::optional<std::string> docPropToPointer(
const wxString& aDocProp,
DOC_KIND aKind )
50 static const std::unordered_map<wxString, std::string>
table = {
66 return "/schematic/page_layout_descr_file";
68 return "/pcbnew/page_layout_descr_file";
71 auto it =
table.find( aDocProp );
73 if( it ==
table.end() )
84 return docPropToPointer( aDocProp, aKind );
95 const nlohmann::json& aSource,
96 const wxString& aDocProp,
106 nlohmann::json::json_pointer ptr( *pointer );
108 if( !aSource.contains( ptr ) )
115 aTarget[ptr] = aSource[ptr];
117 catch(
const std::exception& )
127 const nlohmann::json& aSource,
128 const wxString& aDocProp )
135 const nlohmann::json& aSource,
136 const std::set<wxString>& aDocProps,
139 if( aDocProps.empty() )
142 nlohmann::json target;
144 if( wxFileExists( aOutputProPath ) )
146 wxFFileInputStream fileStream( aOutputProPath );
148 if( !fileStream.IsOk() )
151 if( fileStream.GetLength() == 0 )
153 target = nlohmann::json::object();
163 wxStdInputStream stdStream( fileStream );
164 target = nlohmann::json::parse( stdStream,
nullptr,
true,
true );
166 catch(
const std::exception& )
184 for(
const wxString& docProp : aDocProps )
193 std::string payload = target.dump( 2 );
200 const nlohmann::json& aSource,
201 const std::set<wxString>& aDocProps )
const wxString DOC_PROP_ERC_SEVERITIES
const wxString DOC_PROP_NET_CLASSES
bool ApplyProjectFilePatch(nlohmann::json &aTarget, const nlohmann::json &aSource, const wxString &aDocProp, DOC_KIND aKind)
Copy the JSON sub-tree located at the pointer for aDocProp from aSource into aTarget.
const wxString DOC_PROP_DRAWING_SHEET
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
const wxString DOC_PROP_DRC_SEVERITIES
std::optional< std::string > DocPropJsonPointer(const wxString &aDocProp, DOC_KIND aKind)
Return the JSON pointer (RFC 6901, slash-separated) under which aDocProp is persisted in a ....
bool ApplyProjectFilePatches(const wxString &aOutputProPath, const nlohmann::json &aSource, const std::set< wxString > &aDocProps, DOC_KIND aKind)
Higher-level orchestrator: load the existing aOutputProPath as JSON (or start from aSource if the fil...
std::vector< std::vector< std::string > > table