KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_odbpp.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * Author: SYSUEric <[email protected]>.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "pcb_io_odbpp.h"
22#include "progress_reporter.h"
23#include "odb_util.h"
24#include "odb_attribute.h"
25
26#include "odb_defines.h"
27#include "odb_feature.h"
28#include "odb_entity.h"
29#include "wx/log.h"
30
31#include <footprint.h>
32
33
37std::string PCB_IO_ODBPP::m_unitsStr = "MM";
38
43
44
49
50
62
63
65{
66 for( const auto& entity : m_entities )
67 {
68 if( !entity->CreateDirectoryTree( writer ) )
69 {
70 throw std::runtime_error( "Failed in create directory tree process" );
71 return false;
72 }
73
74 try
75 {
76 entity->GenerateFiles( writer );
77 }
78 catch( const std::exception& e )
79 {
80 throw std::runtime_error( "Failed in generate files process.\n"
81 + std::string( e.what() ) );
82 return false;
83 }
84
85 }
86 return true;
87}
88
89
90bool PCB_IO_ODBPP::ExportODB( const wxString& aFileName )
91{
92 try
93 {
94 std::shared_ptr<ODB_TREE_WRITER> writer =
95 std::make_shared<ODB_TREE_WRITER>( aFileName );
96 writer->SetRootPath( writer->GetCurrentPath() );
97
99 {
100 m_progressReporter->SetNumPhases( 3 );
101 m_progressReporter->BeginPhase( 0 );
102 m_progressReporter->Report( _( "Creating ODB++ Structure" ) );
103 }
104
105 CreateEntity();
106
108 {
109 m_progressReporter->SetCurrentProgress( 1.0 );
110 }
111
112 for( auto const& entity : m_entities )
113 {
114 entity->InitEntityData();
115 }
116
118 {
119 m_progressReporter->SetCurrentProgress( 1.0 );
120 m_progressReporter->AdvancePhase( _( "Exporting board to ODB++" ) );
121 }
122
123 if( !GenerateFiles( *writer ) )
124 return false;
125
126 return true;
127 }
128 catch( const std::exception& e )
129 {
130 wxLogError( "Exception in ODB++ ExportODB process: %s", e.what() );
131 std::cerr << e.what() << std::endl;
132 return false;
133 }
134}
135
136
138{
139 std::vector<FOOTPRINT*> retval;
140 retval.reserve( m_loaded_footprints.size() );
141
142 for( const auto& fp : m_loaded_footprints )
143 {
144 retval.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
145 }
146
147 return retval;
148}
149
150
151void PCB_IO_ODBPP::SaveBoard( const wxString& aFileName, BOARD* aBoard,
152 const std::map<std::string, UTF8>* aProperties )
153{
154 m_board = aBoard;
155
156 if( auto it = aProperties->find( "units" ); it != aProperties->end() )
157 {
158 if( it->second == "inch" )
159 {
160 m_unitsStr = "INCH";
161 m_scale = ( 1.0 / 25.4 ) / PCB_IU_PER_MM;
162 m_symbolScale = ( 1.0 / 25.4 ) / PL_IU_PER_MM;
163 }
164 else
165 {
166 m_unitsStr = "MM";
167 m_scale = 1.0 / PCB_IU_PER_MM;
169 }
170 }
171
172 if( auto it = aProperties->find( "sigfig" ); it != aProperties->end() )
173 m_sigfig = std::stoi( it->second );
174
175 ExportODB( aFileName );
176
177}
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition base_units.h:70
constexpr double PL_IU_PER_MM
Internal units in micron (should be enough).
Definition base_units.h:71
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:240
static int m_sigfig
BOARD * m_board
~PCB_IO_ODBPP() override
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void ClearLoadedFootprints()
void Make(Args &&... args)
void CreateEntity()
bool ExportODB(const wxString &aFileName)
static double m_symbolScale
std::vector< std::shared_ptr< FOOTPRINT > > m_loaded_footprints
std::vector< std::shared_ptr< ODB_ENTITY_BASE > > m_entities
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
static std::string m_unitsStr
static double m_scale
bool GenerateFiles(ODB_TREE_WRITER &writer)
#define _(s)