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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "easyedapro_parser.h"
22
23#include <memory>
24
25#include <json_common.h>
27#include <string_utils.h>
29
30
31void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_ATTR& d )
32{
33 d.id = j.at( 1 ).get<wxString>();
34 d.parentId = j.at( 2 ).get<wxString>();
35 d.key = j.at( 3 ).get<wxString>();
36
37 if( j.at( 4 ).is_string() )
38 d.value = j.at( 4 ).get<wxString>();
39
40 if( j.at( 5 ).is_number() )
41 d.keyVisible = j.at( 5 ).get<int>();
42 else if( j.at( 5 ).is_boolean() )
43 d.keyVisible = j.at( 5 ).get<bool>();
44
45 if( j.at( 6 ).is_number() )
46 d.valVisible = j.at( 6 ).get<int>();
47 else if( j.at( 6 ).is_boolean() )
48 d.valVisible = j.at( 6 ).get<bool>();
49
50 if( j.at( 7 ).is_number() && j.at( 8 ).is_number() )
51 d.position = VECTOR2D( j.at( 7 ), j.at( 8 ) );
52
53 if( j.at( 9 ).is_number() )
54 d.rotation = j.at( 9 );
55
56 if( j.at( 10 ).is_string() )
57 d.fontStyle = j.at( 10 ).get<wxString>();
58}
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
159
160void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SYM_HEAD& d )
161{
162 if( !j.at( 1 ).is_object() )
163 return;
164
165 nlohmann::json config = j.at( 1 );
166
167 d.origin.x = config.value( "originX", 0 );
168 d.origin.y = config.value( "originY", 0 );
169 d.maxId = config.value( "maxId", 0 );
170 d.version = config.value( "version", "" );
171 d.symbolType = config.value( "symbolType", SYMBOL_TYPE::NORMAL );
172
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
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
190
191void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_BOARD& d )
192{
193 d.schematic = j.value( "schematic", "" );
194 d.pcb = j.value( "pcb", "" );
195}
196
197
198void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_SYMBOL& d )
199{
200 if( j.at( "source" ).is_string() )
201 d.source = j.at( "source" ).get<wxString>();
202
203 if( j.contains( "desc" ) )
204 d.desc = j.at( "desc" ).get<wxString>();
205 else if( j.contains( "description" ) )
206 d.desc = j.at( "description" ).get<wxString>();
207
208 if( j.contains( "display_title" ) )
209 d.title = j.at( "display_title" ).get<wxString>();
210 else if( j.contains( "title" ) )
211 d.title = j.at( "title" ).get<wxString>();
212
213 if( j.at( "version" ).is_string() )
214 d.version = j.at( "version" ).get<wxString>();
215
216 if( j.at( "type" ).is_number() )
217 d.type = j.at( "type" );
218
219 if( j.find( "tags" ) != j.end() && j.at( "tags" ).is_object() )
220 d.tags = j.at( "tags" );
221
222 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
223 d.custom_tags = j.at( "custom_tags" );
224}
225
226
227void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_FOOTPRINT& d )
228{
229 if( j.at( "source" ).is_string() )
230 d.source = j.at( "source" ).get<wxString>();
231
232 if( j.contains( "desc" ) )
233 d.desc = j.at( "desc" ).get<wxString>();
234 else if( j.contains( "description" ) )
235 d.desc = j.at( "description" ).get<wxString>();
236
237 if( j.contains( "display_title" ) )
238 d.title = j.at( "display_title" ).get<wxString>();
239 else if( j.contains( "title" ) )
240 d.title = j.at( "title" ).get<wxString>();
241
242 if( j.at( "version" ).is_string() )
243 d.version = j.at( "version" ).get<wxString>();
244
245 if( j.at( "type" ).is_number() )
246 d.type = j.at( "type" );
247
248 if( j.find( "tags" ) != j.end() && j.at( "tags" ).is_object() )
249 d.tags = j.at( "tags" );
250
251 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
252 d.custom_tags = j.at( "custom_tags" );
253}
254
255
256void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_DEVICE& d )
257{
258 if( j.at( "source" ).is_string() )
259 d.source = j.at( "source" ).get<wxString>();
260
261 if( j.contains( "desc" ) )
262 d.description = j.at( "desc" ).get<wxString>();
263 else if( j.contains( "description" ) )
264 d.description = j.at( "description" ).get<wxString>();
265
266 if( j.contains( "display_title" ) )
267 d.title = j.at( "display_title" ).get<wxString>();
268 else if( j.contains( "title" ) )
269 d.title = j.at( "title" ).get<wxString>();
270
271 if( j.at( "version" ).is_string() )
272 d.version = j.at( "version" ).get<wxString>();
273
274 if( j.find( "tags" ) != j.end() && j.at( "tags" ).is_object() )
275 d.tags = j.at( "tags" );
276
277 if( j.find( "custom_tags" ) != j.end() && j.at( "custom_tags" ).is_object() )
278 d.custom_tags = j.at( "custom_tags" );
279
280 if( j.at( "attributes" ).is_object() )
281 d.attributes = AnyMapToStringMap( j.at( "attributes" ) );
282}
283
284
285void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::BLOB& d )
286{
287 d.objectId = j.at( 1 ).get<wxString>();
288 d.url = j.at( 3 ).get<wxString>();
289}
290
291
292void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::POURED& d )
293{
294 d.pouredId = j.at( 1 ).get<wxString>();
295 d.parentId = j.at( 2 ).get<wxString>();
296 d.unki = j.at( 3 ).get<int>();
297 d.isPoly = j.at( 4 ).get<bool>();
298 d.polyData = j.at( 5 );
299}
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
VECTOR2< double > VECTOR2D
Definition vector2d.h:682