KiCad PCB EDA Suite
Loading...
Searching...
No Matches
odb_component.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 "odb_component.h"
22#include "odb_util.h"
23#include "hash_eda.h"
24#include "pcb_io_odbpp.h"
25
26
28 const EDA_DATA::PACKAGE& aPkg )
29{
30 auto& comp = m_compList.emplace_back( m_compList.size(), aPkg.m_index );
31
32 comp.m_center = ODB::AddXY( aFp->GetPosition() );
33
34 if( aFp->GetOrientation() != ANGLE_0 )
35 {
36 // odb Rotation is expressed in degrees and is always clockwise.
37 // while kicad EDA_ANGLE is anticlockwise.
38
39 comp.m_rot =
40 ODB::Double2String( ( ANGLE_360 - aFp->GetOrientation() ).Normalize().AsDegrees() );
41 }
42
43 if( aFp->GetLayer() != F_Cu )
44 {
45 comp.m_mirror = wxT( "M" );
46 }
47
48 comp.m_comp_name = aFp->GetReference().ToAscii();
49 comp.m_part_name =
50 wxString::Format( "%s_%s_%s", aFp->GetFPID().GetFullLibraryName(),
51 aFp->GetFPID().GetLibItemName().wx_str(), aFp->GetValue() );
52
53 return comp;
54}
55
56
57void COMPONENTS_MANAGER::Write( std::ostream& ost ) const
58{
59 ost << "UNITS=" << PCB_IO_ODBPP::m_unitsStr << std::endl;
60
61 WriteAttributes( ost );
62
63 for( const auto& comp : m_compList )
64 {
65 comp.Write( ost );
66 }
67}
68
69
70void ODB_COMPONENT::Write( std::ostream& ost ) const
71{
72 ost << "# CMP " << m_index << std::endl;
73 ost << "CMP " << m_pkg_ref << " " << m_center.first << " " << m_center.second << " " << m_rot
74 << " " << m_mirror << " " << m_comp_name << " " << m_part_name;
75
76 WriteAttributes( ost );
77
78 ost << std::endl;
79
80 for( const auto& toep : m_toeprints )
81 {
82 toep.Write( ost );
83 }
84
85 ost << "#" << std::endl;
86}
87
88
89void ODB_COMPONENT::TOEPRINT::Write( std::ostream& ost ) const
90{
91 ost << "TOP " << m_pin_num << " " << m_center.first << " " << m_center.second << " " << m_rot
92 << " " << m_mirror << " " << m_net_num << " " << m_subnet_num << " " << m_toeprint_name
93 << std::endl;
94}
void WriteAttributes(std::ostream &ost, const std::string &prefix="") const
void WriteAttributes(std::ostream &ost) const
std::list< ODB_COMPONENT > m_compList
Definition: odb_component.h:44
ODB_COMPONENT & AddComponent(const FOOTPRINT *aFp, const EDA_DATA::PACKAGE &aPkg)
void Write(std::ostream &ost) const
const size_t m_index
Definition: odb_eda_data.h:232
EDA_ANGLE GetOrientation() const
Definition: footprint.h:227
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:236
const LIB_ID & GetFPID() const
Definition: footprint.h:248
const wxString & GetValue() const
Definition: footprint.h:624
const wxString & GetReference() const
Definition: footprint.h:602
VECTOR2I GetPosition() const override
Definition: footprint.h:224
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const wxString GetFullLibraryName() const
Definition: lib_id.cpp:277
wxString m_mirror
Definition: odb_component.h:57
const size_t m_index
! CMP index number on board to be used in SNT(TOP), 0~n-1
Definition: odb_component.h:53
wxString m_rot
Definition: odb_component.h:56
std::list< TOEPRINT > m_toeprints
Definition: odb_component.h:93
std::pair< wxString, wxString > m_center
Definition: odb_component.h:55
size_t m_pkg_ref
! package ref number from PKG in eda/data file, 0~n-1
Definition: odb_component.h:54
wxString m_part_name
! Part identification is a single string of ASCII characters without spaces
Definition: odb_component.h:62
void Write(std::ostream &ost) const
wxString m_comp_name
! Unique reference designator (component name)
Definition: odb_component.h:59
static std::string m_unitsStr
Definition: pcb_io_odbpp.h:144
wxString wx_str() const
Definition: utf8.cpp:45
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:407
@ F_Cu
Definition: layer_ids.h:64
std::pair< wxString, wxString > AddXY(const VECTOR2I &aVec)
Definition: odb_util.cpp:158
wxString Double2String(double aVal)
Definition: odb_util.cpp:118
size_t m_subnet_num
! Number of subnet (SNT record TOP) in the referenced net
Definition: odb_component.h:85
std::pair< wxString, wxString > m_center
! Board location of the pin.
Definition: odb_component.h:76
void Write(std::ostream &ost) const
size_t m_net_num
! Number of NET record in the eda/data file.
Definition: odb_component.h:83
wxString m_mirror
! equal to CMP m_mirror.
Definition: odb_component.h:81
const size_t m_pin_num
! index of PIN record in the eda/data file, 0~n-1.
Definition: odb_component.h:74
wxString m_toeprint_name
! Name of the pad in PIN record
Definition: odb_component.h:87
wxString m_rot
! Rotation, clockwise, it equals to the actual PAD rotation, ! not CMP m_rot.
Definition: odb_component.h:78