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 (C) 2024 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
35std::string PCB_IO_ODBPP::m_unitsStr = "MM";
36
38{
40}
41
42
44{
45 m_loaded_footprints.clear();
46}
47
48
50{
51 Make<ODB_FONTS_ENTITY>();
52 Make<ODB_INPUT_ENTITY>();
53 Make<ODB_MATRIX_ENTITY>( m_board, this );
54 Make<ODB_STEP_ENTITY>( m_board, this );
55 Make<ODB_MISC_ENTITY>();
56 Make<ODB_SYMBOLS_ENTITY>();
57 Make<ODB_USER_ENTITY>();
58 Make<ODB_WHEELS_ENTITY>();
59}
60
61
63{
64 for( const auto entity : m_entities )
65 {
66 if( !entity->CreateDirectoryTree( writer ) )
67 {
68 throw std::runtime_error( "Failed in create directory tree process" );
69 return false;
70 }
71
72 try
73 {
74 entity->GenerateFiles( writer );
75 }
76 catch( const std::exception& e )
77 {
78 throw std::runtime_error( "Failed in generate files process.\n"
79 + std::string( e.what() ) );
80 return false;
81 }
82
83 }
84 return true;
85}
86
87
88bool PCB_IO_ODBPP::ExportODB( const wxString& aFileName )
89{
90 try
91 {
92 std::shared_ptr<ODB_TREE_WRITER> writer =
93 std::make_shared<ODB_TREE_WRITER>( aFileName, "odb" );
94 writer->SetRootPath( writer->GetCurrentPath() );
95
97 {
100 m_progressReporter->Report( _( "Creating ODB++ Structure" ) );
101 }
102
103 CreateEntity();
104
106 {
108 }
109
110 for( auto const& entity : m_entities )
111 {
112 entity->InitEntityData();
113 }
114
116 {
118 m_progressReporter->AdvancePhase( _( "Exporting board to ODB++" ) );
119 }
120
121 if( !GenerateFiles( *writer ) )
122 return false;
123
124 return true;
125 }
126 catch( const std::exception& e )
127 {
128 wxLogError( "Exception in ODB++ ExportODB process: %s", e.what() );
129 std::cerr << e.what() << std::endl;
130 return false;
131 }
132}
133
134
136{
137 std::vector<FOOTPRINT*> retval;
138 retval.reserve( m_loaded_footprints.size() );
139
140 for( const auto& fp : m_loaded_footprints )
141 {
142 retval.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
143 }
144
145 return retval;
146}
147
148
149void PCB_IO_ODBPP::SaveBoard( const wxString& aFileName, BOARD* aBoard,
150 const std::map<std::string, UTF8>* aProperties )
151{
152 m_board = aBoard;
153
154 if( auto it = aProperties->find( "units" ); it != aProperties->end() )
155 {
156 if( it->second == "inch" )
157 {
158 m_unitsStr = "INCH";
159 m_scale = ( 1.0 / 25.4 ) / PCB_IU_PER_MM;
160 m_symbolScale = ( 1.0 / 25.4 ) / PL_IU_PER_MM;
161 }
162 else
163 {
164 m_unitsStr = "MM";
165 m_scale = 1.0 / PCB_IU_PER_MM;
167 }
168 }
169
170 if( auto it = aProperties->find( "sigfig" ); it != aProperties->end() )
171 m_sigfig = std::stoi( it->second );
172
173 ExportODB( aFileName );
174
175}
constexpr double PCB_IU_PER_MM
Definition: base_units.h:70
constexpr double PL_IU_PER_MM
Definition: base_units.h:71
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:221
static int m_sigfig
Definition: pcb_io_odbpp.h:143
BOARD * m_board
Definition: pcb_io_odbpp.h:157
~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 CreateEntity()
bool ExportODB(const wxString &aFileName)
static double m_symbolScale
Definition: pcb_io_odbpp.h:142
std::vector< std::shared_ptr< FOOTPRINT > > m_loaded_footprints
Definition: pcb_io_odbpp.h:159
std::vector< std::shared_ptr< ODB_ENTITY_BASE > > m_entities
Definition: pcb_io_odbpp.h:179
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
Definition: pcb_io_odbpp.h:144
static double m_scale
Definition: pcb_io_odbpp.h:141
bool GenerateFiles(ODB_TREE_WRITER &writer)
virtual void SetNumPhases(int aNumPhases)=0
Set the number of phases.
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void BeginPhase(int aPhase)=0
Initialize the aPhase virtual zone of the dialog progress bar.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
#define _(s)