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 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
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
53
54void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOC_TYPE& d )
55{
56 if( j.is_string() )
57 {
58 wxString str = j.get<wxString>();
59
60 int out = 0;
61 str.ToInt( &out );
62 d = static_cast<EASYEDA::DOC_TYPE>( out );
63 }
64 else if( j.is_number() )
65 {
66 d = static_cast<EASYEDA::DOC_TYPE>( j.get<int>() );
67 }
68}
69
70
71void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::HEAD& d )
72{
73 PARSE_VALUE( docType );
74
75 PARSE_VALUE( editorVersion );
76 PARSE_VALUE( title );
77 PARSE_VALUE( description );
78
79 if( j.find( "c_para" ) != j.end() && j.at( "c_para" ).is_object() )
80 d.c_para = j.at( "c_para" );
81
82 PARSE_TO_DOUBLE( x, 0 );
83 PARSE_TO_DOUBLE( y, 0 );
84}
85
86
87void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT& d )
88{
89 PARSE_VALUE( docType );
90 PARSE_VALUE( head );
91
92 PARSE_VALUE( canvas );
93 PARSE_VALUE( title );
94 PARSE_VALUE( shape );
95 PARSE_VALUE( dataStr );
96}
97
98
99void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_PCB& d )
100{
101 PARSE_VALUE( c_para );
102 d.layers = j.at( "layers" );
103
104 if( j.find( "DRCRULE" ) != j.end() && j.at( "DRCRULE" ).is_object() )
105 d.DRCRULE = j.at( "DRCRULE" );
106}
107
108
109void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SYM& d )
110{
111 PARSE_VALUE( c_para );
112}
113
114
115void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SCHEMATICS& d )
116{
117 PARSE_VALUE( schematics );
118}
119
120
121void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::C_PARA& d )
122{
123 PARSE_VALUE( package );
124 PARSE_VALUE( pre );
125 PARSE_VALUE( Contributor );
126 PARSE_VALUE( link );
127 PARSE_VALUE( Model_3D );
128}
#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