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
48std::vector<IMPORT_PROJECT_DESC> ProjectToSelectorDialog( const nlohmann::json& aProject, bool aPcbOnly = false,
49 bool aSchOnly = false );
50
51nlohmann::json FindJsonFile( const wxString& aZipFileName, const std::set<wxString>& aFileNames );
52
53nlohmann::json ReadProjectOrDeviceFile( const wxString& aZipFileName );
54
55void IterateZipFiles( const wxString& aFileName,
56 std::function<bool( const wxString&, const wxString&, wxInputStream& )> aCallback );
57
58std::vector<nlohmann::json> ParseJsonLines( wxInputStream& aInput, const wxString& aSource );
59
64std::vector<std::vector<nlohmann::json>> ParseJsonLinesWithSeparation( wxInputStream& aInput, const wxString& aSource );
65
66std::map<wxString, wxString> AnyMapToStringMap( const std::map<wxString, nlohmann::json>& aInput );
67
75nlohmann::json BuildV3ProjectIndexFromRawDocs( const V3_DOC_PARSER& aParser, bool aIncludeLibraryMetadata = true );
76
77std::map<wxString, BLOB> BuildV3BlobMap( const V3_DOC_PARSER& aParser );
78
79wxString GetV3LibraryItemTitle( const nlohmann::json& aMetadata, const wxString& aUuid );
80
84wxString KeywordsFromV3Tags( const nlohmann::json& aTags );
85
89wxString ResolveDeviceFieldVariables( const wxString& aInput, const std::map<wxString, wxString>& aDeviceAttributes );
90
92wxString NormalizeEasyEDAText( wxString aText );
93
97wxString MakeUniqueLibName( std::set<wxString>& aUsedNames, const wxString& aName, const wxString& aFallback );
98
104std::map<wxString, wxString> BuildV3DeviceLibNames( nlohmann::json& aProject,
105 const std::map<wxString, PRJ_DEVICE>& aDevices,
106 std::set<wxString>* aUsedNames = nullptr );
107
108wxString LookupV3DeviceLibName( const nlohmann::json& aProject, const wxString& aDeviceUuid );
109
111{
112 bool found = false;
113 wxString description;
114 std::map<wxString, wxString> attributes;
115};
116
117V3_DEVICE_DATA GetV3DeviceData( const nlohmann::json& aProject, const wxString& aDeviceUuid );
118
122wxString ResolveV3DeviceValueText( const std::map<wxString, wxString>& aDeviceAttributes );
123
128void ForEachImportedDeviceField( const std::map<wxString, wxString>& aDeviceAttributes, bool aIncludeValue,
129 const std::function<void( const wxString& aKey, const wxString& aValue )>& aCallback );
130
139{
140 wxString symbolUuid;
142 bool hasDevice = false;
143};
144
145std::map<wxString, V3_SYMBOL_LIB_ITEM> BuildV3SymbolLibraryMap( const V3_DOC_PARSER& aParser );
146
147std::map<wxString, wxString> BuildV3LibraryItemMap( const V3_DOC_PARSER& aParser, const char* aIndexKey,
148 const wxString& aDocType );
149
150} // namespace EASYEDAPRO
151
152
153#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)
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.