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
17 * along with this program. If not, see <https://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
34
40{
41public:
43
44 void SetBaseUnits( PADS_UNIT_TYPE aUnitType );
45
47
53 void SetBasicUnitsMode( bool aEnabled );
54
55 bool IsBasicUnitsMode() const { return m_basicUnitsMode; }
56
61 void SetBasicUnitsScale( double aScale );
62
63 double GetBasicUnitsScale() const { return m_basicUnitsScale; }
64
69 bool ParseFileHeader( const std::string& aHeader );
70
75 static std::optional<PADS_UNIT_TYPE> ParseUnitCode( const std::string& aUnitCode );
76
82 bool PushUnitOverride( const std::string& aUnitCode );
83
87 void PopUnitOverride();
88
89 bool HasUnitOverride() const { return !m_unitOverrideStack.empty(); }
90
91 size_t GetOverrideDepth() const { return m_unitOverrideStack.size(); }
92
96 int64_t ToNanometers( double aValue ) const;
97
102 int64_t ToNanometersSize( double aValue ) const;
103
104 static constexpr double MILS_TO_NM = 25400.0; // 1 mil = 25.4 um = 25400 nm
105 static constexpr double MM_TO_NM = 1000000.0; // 1 mm = 1,000,000 nm
106 static constexpr double INCHES_TO_NM = 25400000.0; // 1 inch = 25.4 mm = 25,400,000 nm
107 static constexpr double BASIC_TO_NM = MILS_TO_NM / 38100.0; // 1 BASIC unit = 1/38100 mil
108
109private:
110 void updateScaleFactor();
111
116 std::vector<PADS_UNIT_TYPE> m_unitOverrideStack;
117};
118
119#endif // PADS_UNIT_CONVERTER_H
static constexpr double MILS_TO_NM
double GetBasicUnitsScale() const
static constexpr double INCHES_TO_NM
std::vector< PADS_UNIT_TYPE > m_unitOverrideStack
size_t GetOverrideDepth() const
void SetBaseUnits(PADS_UNIT_TYPE aUnitType)
bool PushUnitOverride(const std::string &aUnitCode)
Push a unit override onto the stack, temporarily overriding the base units for subsequent conversions...
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 (width, height, radius) in PADS file units 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 override code ("M"/"D" mils, "MM" metric, "I" inches), returning an empty optional ...
PADS_UNIT_TYPE GetUnitType() const
static constexpr double MM_TO_NM
void SetBasicUnitsScale(double aScale)
Set a custom scale for BASIC units, in nanometers per BASIC unit.
void PopUnitOverride()
Pop the most recent unit override, reverting to the previous setting.
int64_t ToNanometers(double aValue) const
Convert a coordinate value in PADS file units to nanometers.
@ METRIC
Millimeters.