KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easyeda_parser_structs.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
26
27#include <json_common.h>
29
30
31#define PARSE_VALUE( name ) \
32 if( j.find( #name ) != j.end() ) \
33 j.at( #name ).get_to( d.name )
34
35#define PARSE_TO_DOUBLE( name, def ) \
36 if( j.find( #name ) == j.end() ) \
37 { \
38 d.name = def; \
39 } \
40 else if( j.at( #name ).is_string() ) \
41 { \
42 wxString str = j.at( #name ).get<wxString>(); \
43 \
44 double out = 0; \
45 str.ToCDouble( &out ); \
46 d.name = out; \
47 } \
48 else if( j.at( #name ).is_number() ) \
49 { \
50 d.name = j.at( #name ).get<double>(); \
51 }
52
53void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOC_TYPE& d )
54{
55 if( j.is_string() )
56 {
57 wxString str = j.get<wxString>();
58
59 int out = 0;
60 str.ToInt( &out );
61 d = static_cast<EASYEDA::DOC_TYPE>( out );
62 }
63 else if( j.is_number() )
64 {
65 d = static_cast<EASYEDA::DOC_TYPE>( j.get<int>() );
66 }
67}
68
69void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::HEAD& d )
70{
71 PARSE_VALUE( docType );
72
73 PARSE_VALUE( editorVersion );
74 PARSE_VALUE( title );
75 PARSE_VALUE( description );
76
77 if( j.find( "c_para" ) != j.end() && j.at( "c_para" ).is_object() )
78 d.c_para = j.at( "c_para" );
79
80 PARSE_TO_DOUBLE( x, 0 );
81 PARSE_TO_DOUBLE( y, 0 );
82}
83
84void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT& d )
85{
86 PARSE_VALUE( docType );
87 PARSE_VALUE( head );
88
89 PARSE_VALUE( canvas );
90 PARSE_VALUE( title );
91 PARSE_VALUE( shape );
92 PARSE_VALUE( dataStr );
93}
94
95void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_PCB& d )
96{
97 PARSE_VALUE( c_para );
98 d.layers = j.at( "layers" );
99
100 if( j.find( "DRCRULE" ) != j.end() && j.at( "DRCRULE" ).is_object() )
101 d.DRCRULE = j.at( "DRCRULE" );
102}
103
104void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SYM& d )
105{
106 PARSE_VALUE( c_para );
107}
108
109void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SCHEMATICS& d )
110{
111 PARSE_VALUE( schematics );
112}
113
114void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::C_PARA& d )
115{
116 PARSE_VALUE( package );
117 PARSE_VALUE( pre );
118 PARSE_VALUE( Contributor );
119 PARSE_VALUE( link );
120 PARSE_VALUE( Model_3D );
121}
#define PARSE_TO_DOUBLE(name, def)
#define PARSE_VALUE(name)
void from_json(const nlohmann::json &j, EASYEDA::DOC_TYPE &d)
std::optional< std::map< wxString, nlohmann::json > > DRCRULE
std::vector< wxString > layers
std::optional< std::map< wxString, wxString > > c_para