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