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 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, 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
64
65void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PCB_ATTR& d )
66{
67 d.id = j.at( 1 ).get<wxString>();
68 d.parentId = j.at( 3 ).get<wxString>();
69 d.layer = j.at( 4 );
70
71 if( j.at( 5 ).is_number() && j.at( 6 ).is_number() )
72 d.position = VECTOR2D( j.at( 5 ), j.at( 6 ) );
73
74 d.key = j.at( 7 ).get<wxString>();
75
76 if( j.at( 8 ).is_string() )
77 d.value = j.at( 8 ).get<wxString>();
78 else if( j.at( 8 ).is_number_integer() )
79 d.value << ( j.at( 8 ).get<int>() );
80
81 if( j.at( 9 ).is_number() )
82 d.keyVisible = j.at( 9 ).get<int>();
83 else if( j.at( 9 ).is_boolean() )
84 d.keyVisible = j.at( 9 ).get<bool>();
85
86 if( j.at( 10 ).is_number() )
87 d.valVisible = j.at( 10 ).get<int>();
88 else if( j.at( 10 ).is_boolean() )
89 d.valVisible = j.at( 10 ).get<bool>();
90
91 if( j.at( 11 ).is_string() )
92 d.fontName = j.at( 11 ).get<wxString>();
93
94 if( j.at( 12 ).is_number() )
95 d.height = j.at( 12 );
96
97 if( j.at( 13 ).is_number() )
98 d.strokeWidth = j.at( 13 );
99
100 if( j.at( 16 ).is_number() )
101 d.textOrigin = j.at( 16 );
102
103 if( j.at( 17 ).is_number() )
104 d.rotation = j.at( 17 );
105
106 if( j.at( 18 ).is_number() )
107 d.inverted = j.at( 18 );
108}
109
110
111void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_COMPONENT& d )
112{
113 d.id = j.at( 1 ).get<wxString>();
114 d.name = j.at( 2 ).get<wxString>();
115
116 if( j.at( 3 ).is_number() && j.at( 4 ).is_number() )
117 d.position = VECTOR2D( j.at( 3 ), j.at( 4 ) );
118
119 if( j.at( 5 ).is_number() )
120 d.rotation = j.at( 5 );
121
122 if( j.at( 6 ).is_number() )
123 d.mirror = j.at( 6 ).get<int>();
124
125 if( j.at( 6 ).is_number() )
126 d.unk1 = j.at( 6 );
127
128 if( j.at( 7 ).is_object() )
129 d.customProps = j.at( 7 );
130
131 if( j.at( 8 ).is_number() )
132 d.unk2 = j.at( 8 );
133}
134
135
136void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_WIRE& d )
137{
138 d.id = j.at( 1 ).get<wxString>();
139 d.geometry = j.at( 2 );
140
141 if( j.at( 3 ).is_string() )
142 d.lineStyle = j.at( 3 ).get<wxString>();
143}
144
145
146void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SYM_PIN& d )
147{
148 d.id = j.at( 1 ).get<wxString>();
149
150 if( j.at( 4 ).is_number() && j.at( 5 ).is_number() )
151 d.position = VECTOR2D( j.at( 4 ), j.at( 5 ) );
152
153 if( j.at( 6 ).is_number() )
154 d.length = j.at( 6 );
155
156 if( j.at( 7 ).is_number() )
157 d.rotation = j.at( 7 );
158
159 if( j.at( 9 ).is_number() )
160 d.inverted = j.at( 9 ).get<int>() == 2;
161}
162
163
164void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SYM_HEAD& d )
165{
166 if( !j.at( 1 ).is_object() )
167 return;
168
169 nlohmann::json config = j.at( 1 );
170
171 d.origin.x = config.value( "originX", 0 );
172 d.origin.y = config.value( "originY", 0 );
173 d.maxId = config.value( "maxId", 0 );
174 d.version = config.value( "version", "" );
175 d.symbolType = config.value( "symbolType", SYMBOL_TYPE::NORMAL );
176
177}
178
179
180void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SHEET& d )
181{
182 d.name = j.value( "name", "" );
183 d.uuid = j.value( "uuid", "" );
184 d.id = j.value( "id", 0 );
185}
186
187
188void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SCHEMATIC& d )
189{
190 d.name = j.value( "name", "" );
191 d.sheets = j.value( "sheets", std::vector<PRJ_SHEET>{} );
192}
193
194
195void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_BOARD& d )
196{
197 d.schematic = j.value( "schematic", "" );
198 d.pcb = j.value( "pcb", "" );
199}
200
201
202void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SYMBOL& d )
203{
204 if( j.at( "source" ).is_string() )
205 d.source = j.at( "source" ).get<wxString>();
206
207 if( j.contains( "desc" ) )
208 d.desc = j.at( "desc" ).get<wxString>();
209 else if( j.contains( "description" ) )
210 d.desc = j.at( "description" ).get<wxString>();
211
212 if( j.contains( "display_title" ) )
213 d.title = j.at( "display_title" ).get<wxString>();
214 else if( j.contains( "title" ) )
215 d.title = j.at( "title" ).get<wxString>();
216
217 if( j.at( "version" ).is_string() )
218 d.version = j.at( "version" ).get<wxString>();
219
220 if( j.at( "type" ).is_number() )
221 d.type = j.at( "type" );
222
223 if( j.at( "tags" ).is_object() )
224 d.tags = j.at( "tags" );
225
226 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
227 d.custom_tags = j.at( "custom_tags" );
228}
229
230
231void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_FOOTPRINT& d )
232{
233 if( j.at( "source" ).is_string() )
234 d.source = j.at( "source" ).get<wxString>();
235
236 if( j.contains( "desc" ) )
237 d.desc = j.at( "desc" ).get<wxString>();
238 else if( j.contains( "description" ) )
239 d.desc = j.at( "description" ).get<wxString>();
240
241 if( j.contains( "display_title" ) )
242 d.title = j.at( "display_title" ).get<wxString>();
243 else if( j.contains( "title" ) )
244 d.title = j.at( "title" ).get<wxString>();
245
246 if( j.at( "version" ).is_string() )
247 d.version = j.at( "version" ).get<wxString>();
248
249 if( j.at( "type" ).is_number() )
250 d.type = j.at( "type" );
251
252 if( j.at( "tags" ).is_object() )
253 d.tags = j.at( "tags" );
254
255 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
256 d.custom_tags = j.at( "custom_tags" );
257}
258
259
260void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_DEVICE& d )
261{
262 if( j.at( "source" ).is_string() )
263 d.source = j.at( "source" ).get<wxString>();
264
265 if( j.contains( "desc" ) )
266 d.description = j.at( "desc" ).get<wxString>();
267 else if( j.contains( "description" ) )
268 d.description = j.at( "description" ).get<wxString>();
269
270 if( j.contains( "display_title" ) )
271 d.title = j.at( "display_title" ).get<wxString>();
272 else if( j.contains( "title" ) )
273 d.title = j.at( "title" ).get<wxString>();
274
275 if( j.at( "version" ).is_string() )
276 d.version = j.at( "version" ).get<wxString>();
277
278 if( j.at( "tags" ).is_object() )
279 d.tags = j.at( "tags" );
280
281 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
282 d.custom_tags = j.at( "custom_tags" );
283
284 if( j.at( "attributes" ).is_object() )
285 d.attributes = AnyMapToStringMap( j.at( "attributes" ) );
286}
287
288
289void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::BLOB& d )
290{
291 d.objectId = j.at( 1 ).get<wxString>();
292 d.url = j.at( 3 ).get<wxString>();
293}
294
295
296void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::POURED& d )
297{
298 d.pouredId = j.at( 1 ).get<wxString>();
299 d.parentId = j.at( 2 ).get<wxString>();
300 d.unki = j.at( 3 ).get<int>();
301 d.isPoly = j.at( 4 ).get<bool>();
302 d.polyData = j.at( 5 );
303}
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