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, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <json_common.h>
25
26
27#define PARSE_VALUE( name ) \
28 if( j.find( #name ) != j.end() ) \
29 j.at( #name ).get_to( d.name )
30
31#define PARSE_TO_DOUBLE( name, def ) \
32 if( j.find( #name ) == j.end() ) \
33 { \
34 d.name = def; \
35 } \
36 else if( j.at( #name ).is_string() ) \
37 { \
38 wxString str = j.at( #name ).get<wxString>(); \
39 \
40 double out = 0; \
41 str.ToCDouble( &out ); \
42 d.name = out; \
43 } \
44 else if( j.at( #name ).is_number() ) \
45 { \
46 d.name = j.at( #name ).get<double>(); \
47 }
48
49
50void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOC_TYPE& d )
51{
52 if( j.is_string() )
53 {
54 wxString str = j.get<wxString>();
55
56 int out = 0;
57 str.ToInt( &out );
58 d = static_cast<EASYEDA::DOC_TYPE>( out );
59 }
60 else if( j.is_number() )
61 {
62 d = static_cast<EASYEDA::DOC_TYPE>( j.get<int>() );
63 }
64}
65
66
67void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::HEAD& d )
68{
69 PARSE_VALUE( docType );
70
71 PARSE_VALUE( editorVersion );
72 PARSE_VALUE( title );
73 PARSE_VALUE( description );
74
75 if( j.find( "c_para" ) != j.end() && j.at( "c_para" ).is_object() )
76 d.c_para = j.at( "c_para" );
77
78 PARSE_TO_DOUBLE( x, 0 );
79 PARSE_TO_DOUBLE( y, 0 );
80}
81
82
83void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT& d )
84{
85 PARSE_VALUE( docType );
86 PARSE_VALUE( head );
87
88 PARSE_VALUE( canvas );
89 PARSE_VALUE( title );
90 PARSE_VALUE( shape );
91 PARSE_VALUE( dataStr );
92}
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
104
105void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SYM& d )
106{
107 PARSE_VALUE( c_para );
108}
109
110
111void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::DOCUMENT_SCHEMATICS& d )
112{
113 PARSE_VALUE( schematics );
114}
115
116
117void EASYEDA::from_json( const nlohmann::json& j, EASYEDA::C_PARA& d )
118{
119 PARSE_VALUE( package );
120 PARSE_VALUE( pre );
121 PARSE_VALUE( Contributor );
122 PARSE_VALUE( link );
123 PARSE_VALUE( Model_3D );
124}
#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