KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easyedapro_import_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Alex Shvartzkop <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef EASYEDAPRO_IMPORT_UTILS_H_
22#define EASYEDAPRO_IMPORT_UTILS_H_
23
24#include <functional>
25#include <map>
26#include <set>
27#include <vector>
28#include <wx/stream.h>
29#include <wx/string.h>
31#include <lib_id.h>
32#include <nlohmann/json_fwd.hpp>
33
35
36#define EASY_IT_CONTINUE return false
37#define EASY_IT_BREAK return true
38
39namespace EASYEDAPRO
40{
41
42class V3_DOC_PARSER;
43
44wxString ShortenLibName( wxString aProjectName );
45
46LIB_ID ToKiCadLibID( const wxString& aLibName, const wxString& aLibReference );
47
52std::vector<IMPORT_PROJECT_DESC> ProjectToSelectorDialog( const nlohmann::json& aProject, bool aPcbOnly = false,
53 bool aSchOnly = false );
54
55nlohmann::json FindJsonFile( const wxString& aZipFileName, const std::set<wxString>& aFileNames );
56
57nlohmann::json ReadProjectOrDeviceFile( const wxString& aZipFileName );
58
59void IterateZipFiles( const wxString& aFileName,
60 std::function<bool( const wxString&, const wxString&, wxInputStream& )> aCallback );
61
62std::vector<nlohmann::json> ParseJsonLines( wxInputStream& aInput, const wxString& aSource );
63
68std::vector<std::vector<nlohmann::json>> ParseJsonLinesWithSeparation( wxInputStream& aInput, const wxString& aSource );
69
70std::map<wxString, wxString> AnyMapToStringMap( const std::map<wxString, nlohmann::json>& aInput );
71
79nlohmann::json BuildV3ProjectIndexFromRawDocs( const V3_DOC_PARSER& aParser, bool aIncludeLibraryMetadata = true );
80
81std::map<wxString, BLOB> BuildV3BlobMap( const V3_DOC_PARSER& aParser );
82
83wxString GetV3LibraryItemTitle( const nlohmann::json& aMetadata, const wxString& aUuid );
84
88wxString KeywordsFromV3Tags( const nlohmann::json& aTags );
89
93wxString ResolveDeviceFieldVariables( const wxString& aInput, const std::map<wxString, wxString>& aDeviceAttributes );
94
96wxString NormalizeEasyEDAText( wxString aText );
97
101wxString MakeUniqueLibName( std::set<wxString>& aUsedNames, const wxString& aName, const wxString& aFallback );
102
108std::map<wxString, wxString> BuildV3DeviceLibNames( nlohmann::json& aProject,
109 const std::map<wxString, PRJ_DEVICE>& aDevices,
110 std::set<wxString>* aUsedNames = nullptr );
111
112wxString LookupV3DeviceLibName( const nlohmann::json& aProject, const wxString& aDeviceUuid );
113
115{
116 bool found = false;
117 wxString description;
118 std::map<wxString, wxString> attributes;
119};
120
121V3_DEVICE_DATA GetV3DeviceData( const nlohmann::json& aProject, const wxString& aDeviceUuid );
122
126wxString ResolveV3DeviceValueText( const std::map<wxString, wxString>& aDeviceAttributes );
127
132void ForEachImportedDeviceField( const std::map<wxString, wxString>& aDeviceAttributes, bool aIncludeValue,
133 const std::function<void( const wxString& aKey, const wxString& aValue )>& aCallback );
134
143{
144 wxString symbolUuid;
146 bool hasDevice = false;
147};
148
149std::map<wxString, V3_SYMBOL_LIB_ITEM> BuildV3SymbolLibraryMap( const V3_DOC_PARSER& aParser );
150
151std::map<wxString, wxString> BuildV3LibraryItemMap( const V3_DOC_PARSER& aParser, const char* aIndexKey,
152 const wxString& aDocType );
153
154} // namespace EASYEDAPRO
155
156
157#endif // EASYEDAPRO_IMPORT_UTILS_H_
Parses EasyEDA Pro v3 .epro2 archives.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
nlohmann::json BuildV3ProjectIndexFromRawDocs(const V3_DOC_PARSER &aParser, bool aIncludeLibraryMetadata=true)
Build a minimal legacy-style project index from parsed v3 raw documents.
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
wxString MakeUniqueLibName(std::set< wxString > &aUsedNames, const wxString &aName, const wxString &aFallback)
Allocate a unique library item name, recording it in aUsedNames.
wxString KeywordsFromV3Tags(const nlohmann::json &aTags)
Build KiCad keywords from a v3 tags object (parent_tag / child_tag name fields).
wxString GetV3LibraryItemTitle(const nlohmann::json &aMetadata, const wxString &aUuid)
void ForEachImportedDeviceField(const std::map< wxString, wxString > &aDeviceAttributes, bool aIncludeValue, const std::function< void(const wxString &aKey, const wxString &aValue)> &aCallback)
Invoke aCallback for each non-empty whitelisted Device field (resolved + normalized).
wxString ResolveDeviceFieldVariables(const wxString &aInput, const std::map< wxString, wxString > &aDeviceAttributes)
Resolve EasyEDA ={Var} / ={A}text{B} field expressions against device attributes.
void IterateZipFiles(const wxString &aFileName, std::function< bool(const wxString &, const wxString &, wxInputStream &)> aCallback)
std::vector< nlohmann::json > ParseJsonLines(wxInputStream &aInput, const wxString &aSource)
wxString NormalizeEasyEDAText(wxString aText)
Replace EasyEDA temperature glyph (℃) with °C.
V3_DEVICE_DATA GetV3DeviceData(const nlohmann::json &aProject, const wxString &aDeviceUuid)
std::vector< std::vector< nlohmann::json > > ParseJsonLinesWithSeparation(wxInputStream &aInput, const wxString &aSource)
Multiple document types (e.g.
wxString LookupV3DeviceLibName(const nlohmann::json &aProject, const wxString &aDeviceUuid)
nlohmann::json FindJsonFile(const wxString &aZipFileName, const std::set< wxString > &aFileNames)
std::vector< IMPORT_PROJECT_DESC > ProjectToSelectorDialog(const nlohmann::json &aProject, bool aPcbOnly=false, bool aSchOnly=false)
List the project's board entries, then the PCBs and schematics no entry names.
nlohmann::json ReadProjectOrDeviceFile(const wxString &aZipFileName)
wxString ShortenLibName(wxString aProjectName)
std::map< wxString, wxString > AnyMapToStringMap(const std::map< wxString, nlohmann::json > &aInput)
wxString ResolveV3DeviceValueText(const std::map< wxString, wxString > &aDeviceAttributes)
Preferred Value text: Value attribute, else Name, with variables resolved.
std::map< wxString, V3_SYMBOL_LIB_ITEM > BuildV3SymbolLibraryMap(const V3_DOC_PARSER &aParser)
std::map< wxString, wxString > BuildV3LibraryItemMap(const V3_DOC_PARSER &aParser, const char *aIndexKey, const wxString &aDocType)
std::map< wxString, BLOB > BuildV3BlobMap(const V3_DOC_PARSER &aParser)
std::map< wxString, wxString > BuildV3DeviceLibNames(nlohmann::json &aProject, const std::map< wxString, PRJ_DEVICE > &aDevices, std::set< wxString > *aUsedNames=nullptr)
Stable project-lib item names keyed by Device UUID (one entry per Device).
std::map< wxString, wxString > attributes
Build the schematic-library name map for a v3 .elibz2.
Describes how non-KiCad boards and schematics should be imported as KiCad projects.