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