KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_unit_converter.h
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 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PADS_UNIT_CONVERTER_H
21#define PADS_UNIT_CONVERTER_H
22
23#include <cstdint>
24#include <optional>
25#include <string>
26#include <vector>
27
37
47{
48public:
50
56 void SetBaseUnits( PADS_UNIT_TYPE aUnitType );
57
64
74 void SetBasicUnitsMode( bool aEnabled );
75
81 bool IsBasicUnitsMode() const { return m_basicUnitsMode; }
82
91 void SetBasicUnitsScale( double aScale );
92
98 double GetBasicUnitsScale() const { return m_basicUnitsScale; }
99
109 bool ParseFileHeader( const std::string& aHeader );
110
125 static std::optional<PADS_UNIT_TYPE> ParseUnitCode( const std::string& aUnitCode );
126
138 bool PushUnitOverride( const std::string& aUnitCode );
139
146 void PopUnitOverride();
147
153 bool HasUnitOverride() const { return !m_unitOverrideStack.empty(); }
154
160 size_t GetOverrideDepth() const { return m_unitOverrideStack.size(); }
161
170 int64_t ToNanometers( double aValue ) const;
171
181 int64_t ToNanometersSize( double aValue ) const;
182
183 // Conversion constants
184 static constexpr double MILS_TO_NM = 25400.0; // 1 mil = 25.4 um = 25400 nm
185 static constexpr double MM_TO_NM = 1000000.0; // 1 mm = 1,000,000 nm
186 static constexpr double INCHES_TO_NM = 25400000.0; // 1 inch = 25.4 mm = 25,400,000 nm
187 static constexpr double BASIC_TO_NM = MILS_TO_NM / 38100.0; // 1 BASIC unit = 1/38100 mil
188
189private:
190 void updateScaleFactor();
191
196 std::vector<PADS_UNIT_TYPE> m_unitOverrideStack;
197};
198
199#endif // PADS_UNIT_CONVERTER_H
static constexpr double MILS_TO_NM
double GetBasicUnitsScale() const
Get the current BASIC units scale.
static constexpr double INCHES_TO_NM
std::vector< PADS_UNIT_TYPE > m_unitOverrideStack
bool IsBasicUnitsMode() const
Check if BASIC units mode is enabled.
size_t GetOverrideDepth() const
Get the current override depth.
void SetBaseUnits(PADS_UNIT_TYPE aUnitType)
Set the base units for conversion.
bool PushUnitOverride(const std::string &aUnitCode)
Push a unit override onto the stack.
static constexpr double BASIC_TO_NM
void SetBasicUnitsMode(bool aEnabled)
Enable or disable BASIC units mode.
int64_t ToNanometersSize(double aValue) const
Convert a size value to nanometers.
bool ParseFileHeader(const std::string &aHeader)
Parse a PADS file header string and configure units accordingly.
static std::optional< PADS_UNIT_TYPE > ParseUnitCode(const std::string &aUnitCode)
Parse a PADS unit code and return the corresponding unit type.
PADS_UNIT_TYPE GetUnitType() const
Get the current unit type.
static constexpr double MM_TO_NM
void SetBasicUnitsScale(double aScale)
Set a custom scale for BASIC units.
void PopUnitOverride()
Pop the most recent unit override from the stack.
int64_t ToNanometers(double aValue) const
Convert a coordinate value to nanometers.
bool HasUnitOverride() const
Check if any unit overrides are currently active.
PADS_UNIT_TYPE
Unit types supported by PADS file formats.
@ METRIC
Millimeters.