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 throw std::runtime_error( "Failed in create directory tree process" );
70
71 try
72 {
73 entity->GenerateFiles( writer );
74 }
75 catch( const std::exception& e )
76 {
77 throw std::runtime_error( "Failed in generate files process.\n" + std::string( e.what() ) );
78 }
79
80 }
81 return true;
82}
83
84
85bool PCB_IO_ODBPP::ExportODB( const wxString& aFileName )
86{
87 try
88 {
89 std::shared_ptr<ODB_TREE_WRITER> writer =
90 std::make_shared<ODB_TREE_WRITER>( aFileName );
91 writer->SetRootPath( writer->GetCurrentPath() );
92
94 {
95 m_progressReporter->SetNumPhases( 3 );
96 m_progressReporter->BeginPhase( 0 );
97 m_progressReporter->Report( _( "Creating ODB++ Structure" ) );
98 }
99
100 CreateEntity();
101
103 {
104 m_progressReporter->SetCurrentProgress( 1.0 );
105 }
106
107 for( auto const& entity : m_entities )
108 {
109 entity->InitEntityData();
110 }
111
113 {
114 m_progressReporter->SetCurrentProgress( 1.0 );
115 m_progressReporter->AdvancePhase( _( "Exporting board to ODB++" ) );
116 }
117
118 if( !GenerateFiles( *writer ) )
119 return false;
120
121 return true;
122 }
123 catch( const std::exception& e )
124 {
125 wxLogError( "Exception in ODB++ ExportODB process: %s", e.what() );
126 std::cerr << e.what() << std::endl;
127 return false;
128 }
129}
130
131
133{
134 std::vector<FOOTPRINT*> retval;
135 retval.reserve( m_loaded_footprints.size() );
136
137 for( const auto& fp : m_loaded_footprints )
138 {
139 retval.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
140 }
141
142 return retval;
143}
144
145
146void PCB_IO_ODBPP::SaveBoard( const wxString& aFileName, BOARD* aBoard,
147 const std::map<std::string, UTF8>* aProperties )
148{
149 m_board = aBoard;
150
151 if( auto it = aProperties->find( "units" ); it != aProperties->end() )
152 {
153 if( it->second == "inch" )
154 {
155 m_unitsStr = "INCH";
156 m_scale = ( 1.0 / 25.4 ) / PCB_IU_PER_MM;
157 m_symbolScale = ( 1.0 / 25.4 ) / PL_IU_PER_MM;
158 }
159 else
160 {
161 m_unitsStr = "MM";
162 m_scale = 1.0 / PCB_IU_PER_MM;
164 }
165 }
166
167 if( auto it = aProperties->find( "sigfig" ); it != aProperties->end() )
168 m_sigfig = std::stoi( it->second );
169
170 ExportODB( aFileName );
171
172}
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition base_units.h:72
constexpr double PL_IU_PER_MM
Internal units in micron (should be enough).
Definition base_units.h:73
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
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)