KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easyedapro_parser.cpp
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 (C) 2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include "easyedapro_parser.h"
26
27#include <memory>
28
29#include <json_common.h>
31#include <string_utils.h>
33
34
35void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_ATTR& d )
36{
37 d.id = j.at( 1 ).get<wxString>();
38 d.parentId = j.at( 2 ).get<wxString>();
39 d.key = j.at( 3 ).get<wxString>();
40
41 if( j.at( 4 ).is_string() )
42 d.value = j.at( 4 ).get<wxString>();
43
44 if( j.at( 5 ).is_number() )
45 d.keyVisible = j.at( 5 ).get<int>();
46 else if( j.at( 5 ).is_boolean() )
47 d.keyVisible = j.at( 5 ).get<bool>();
48
49 if( j.at( 6 ).is_number() )
50 d.valVisible = j.at( 6 ).get<int>();
51 else if( j.at( 6 ).is_boolean() )
52 d.valVisible = j.at( 6 ).get<bool>();
53
54 if( j.at( 7 ).is_number() && j.at( 8 ).is_number() )
55 d.position = VECTOR2D( j.at( 7 ), j.at( 8 ) );
56
57 if( j.at( 9 ).is_number() )
58 d.rotation = j.at( 9 );
59
60 if( j.at( 10 ).is_string() )
61 d.fontStyle = j.at( 10 ).get<wxString>();
62}
63
64void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PCB_ATTR& d )
65{
66 d.id = j.at( 1 ).get<wxString>();
67 d.parentId = j.at( 3 ).get<wxString>();
68 d.layer = j.at( 4 );
69
70 if( j.at( 5 ).is_number() && j.at( 6 ).is_number() )
71 d.position = VECTOR2D( j.at( 5 ), j.at( 6 ) );
72
73 d.key = j.at( 7 ).get<wxString>();
74
75 if( j.at( 8 ).is_string() )
76 d.value = j.at( 8 ).get<wxString>();
77 else if( j.at( 8 ).is_number_integer() )
78 d.value << ( j.at( 8 ).get<int>() );
79
80 if( j.at( 9 ).is_number() )
81 d.keyVisible = j.at( 9 ).get<int>();
82 else if( j.at( 9 ).is_boolean() )
83 d.keyVisible = j.at( 9 ).get<bool>();
84
85 if( j.at( 10 ).is_number() )
86 d.valVisible = j.at( 10 ).get<int>();
87 else if( j.at( 10 ).is_boolean() )
88 d.valVisible = j.at( 10 ).get<bool>();
89
90 if( j.at( 11 ).is_string() )
91 d.fontName = j.at( 11 ).get<wxString>();
92
93 if( j.at( 12 ).is_number() )
94 d.height = j.at( 12 );
95
96 if( j.at( 13 ).is_number() )
97 d.strokeWidth = j.at( 13 );
98
99 if( j.at( 16 ).is_number() )
100 d.textOrigin = j.at( 16 );
101
102 if( j.at( 17 ).is_number() )
103 d.rotation = j.at( 17 );
104
105 if( j.at( 18 ).is_number() )
106 d.inverted = j.at( 18 );
107}
108
109
110void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_COMPONENT& d )
111{
112 d.id = j.at( 1 ).get<wxString>();
113 d.name = j.at( 2 ).get<wxString>();
114
115 if( j.at( 3 ).is_number() && j.at( 4 ).is_number() )
116 d.position = VECTOR2D( j.at( 3 ), j.at( 4 ) );
117
118 if( j.at( 5 ).is_number() )
119 d.rotation = j.at( 5 );
120
121 if( j.at( 6 ).is_number() )
122 d.mirror = j.at( 6 ).get<int>();
123
124 if( j.at( 6 ).is_number() )
125 d.unk1 = j.at( 6 );
126
127 if( j.at( 7 ).is_object() )
128 d.customProps = j.at( 7 );
129
130 if( j.at( 8 ).is_number() )
131 d.unk2 = j.at( 8 );
132}
133
134
135void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_WIRE& d )
136{
137 d.id = j.at( 1 ).get<wxString>();
138 d.geometry = j.at( 2 );
139
140 if( j.at( 3 ).is_string() )
141 d.lineStyle = j.at( 3 ).get<wxString>();
142}
143
144
145void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SYM_PIN& d )
146{
147 d.id = j.at( 1 ).get<wxString>();
148
149 if( j.at( 4 ).is_number() && j.at( 5 ).is_number() )
150 d.position = VECTOR2D( j.at( 4 ), j.at( 5 ) );
151
152 if( j.at( 6 ).is_number() )
153 d.length = j.at( 6 );
154
155 if( j.at( 7 ).is_number() )
156 d.rotation = j.at( 7 );
157
158 if( j.at( 9 ).is_number() )
159 d.inverted = j.at( 9 ).get<int>() == 2;
160}
161
162void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SYM_HEAD& d )
163{
164 if( !j.at( 1 ).is_object() )
165 return;
166
167 nlohmann::json config = j.at( 1 );
168
169 d.origin.x = config.value( "originX", 0 );
170 d.origin.y = config.value( "originY", 0 );
171 d.maxId = config.value( "maxId", 0 );
172 d.version = config.value( "version", "" );
173 d.symbolType = config.value( "symbolType", SYMBOL_TYPE::NORMAL );
174
175}
176
177void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SHEET& d )
178{
179 d.name = j.value( "name", "" );
180 d.uuid = j.value( "uuid", "" );
181 d.id = j.value( "id", 0 );
182}
183
184void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SCHEMATIC& d )
185{
186 d.name = j.value( "name", "" );
187 d.sheets = j.value( "sheets", std::vector<PRJ_SHEET>{} );
188}
189
190void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_BOARD& d )
191{
192 d.schematic = j.value( "schematic", "" );
193 d.pcb = j.value( "pcb", "" );
194}
195
196void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SYMBOL& d )
197{
198 if( j.at( "source" ).is_string() )
199 d.source = j.at( "source" ).get<wxString>();
200
201 if( j.contains( "desc" ) )
202 d.desc = j.at( "desc" ).get<wxString>();
203 else if( j.contains( "description" ) )
204 d.desc = j.at( "description" ).get<wxString>();
205
206 if( j.contains( "display_title" ) )
207 d.title = j.at( "display_title" ).get<wxString>();
208 else if( j.contains( "title" ) )
209 d.title = j.at( "title" ).get<wxString>();
210
211 if( j.at( "version" ).is_string() )
212 d.version = j.at( "version" ).get<wxString>();
213
214 if( j.at( "type" ).is_number() )
215 d.type = j.at( "type" );
216
217 if( j.at( "tags" ).is_object() )
218 d.tags = j.at( "tags" );
219
220 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
221 d.custom_tags = j.at( "custom_tags" );
222}
223
224void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_FOOTPRINT& d )
225{
226 if( j.at( "source" ).is_string() )
227 d.source = j.at( "source" ).get<wxString>();
228
229 if( j.contains( "desc" ) )
230 d.desc = j.at( "desc" ).get<wxString>();
231 else if( j.contains( "description" ) )
232 d.desc = j.at( "description" ).get<wxString>();
233
234 if( j.contains( "display_title" ) )
235 d.title = j.at( "display_title" ).get<wxString>();
236 else if( j.contains( "title" ) )
237 d.title = j.at( "title" ).get<wxString>();
238
239 if( j.at( "version" ).is_string() )
240 d.version = j.at( "version" ).get<wxString>();
241
242 if( j.at( "type" ).is_number() )
243 d.type = j.at( "type" );
244
245 if( j.at( "tags" ).is_object() )
246 d.tags = j.at( "tags" );
247
248 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
249 d.custom_tags = j.at( "custom_tags" );
250}
251
252void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_DEVICE& d )
253{
254 if( j.at( "source" ).is_string() )
255 d.source = j.at( "source" ).get<wxString>();
256
257 if( j.contains( "desc" ) )
258 d.description = j.at( "desc" ).get<wxString>();
259 else if( j.contains( "description" ) )
260 d.description = j.at( "description" ).get<wxString>();
261
262 if( j.contains( "display_title" ) )
263 d.title = j.at( "display_title" ).get<wxString>();
264 else if( j.contains( "title" ) )
265 d.title = j.at( "title" ).get<wxString>();
266
267 if( j.at( "version" ).is_string() )
268 d.version = j.at( "version" ).get<wxString>();
269
270 if( j.at( "tags" ).is_object() )
271 d.tags = j.at( "tags" );
272
273 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
274 d.custom_tags = j.at( "custom_tags" );
275
276 if( j.at( "attributes" ).is_object() )
277 d.attributes = AnyMapToStringMap( j.at( "attributes" ) );
278}
279
280void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::BLOB& d )
281{
282 d.objectId = j.at( 1 ).get<wxString>();
283 d.url = j.at( 3 ).get<wxString>();
284}
285
286void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::POURED& d )
287{
288 d.pouredId = j.at( 1 ).get<wxString>();
289 d.parentId = j.at( 2 ).get<wxString>();
290 d.unki = j.at( 3 ).get<int>();
291 d.isPoly = j.at( 4 ).get<bool>();
292 d.polyData = j.at( 5 );
293}
std::map< wxString, wxString > AnyMapToStringMap(const std::map< wxString, nlohmann::json > &aInput)
void from_json(const nlohmann::json &j, EASYEDAPRO::SCH_ATTR &d)
nlohmann::json polyData
std::map< wxString, wxString > attributes
std::vector< PRJ_SHEET > sheets
std::optional< VECTOR2D > position
std::vector< std::vector< double > > geometry