KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_origin_transforms.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 (C) 2019-2020 Reece R. Pollack <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <origin_transforms.h>
24
25class PCB_BASE_FRAME;
26
28{
29public:
30 PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame );
31
33
35
36 virtual long long int ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override;
37 virtual double ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
38 virtual double ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override;
39
41
42 virtual long long int FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override;
43 virtual double FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
44 virtual EDA_ANGLE FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override;
45
53
61
72
83
84
85 // =============== Single-axis Relative Transforms ===============
86
87 template<typename T>
88 T ToDisplayRelX( T aInternalValue ) const
89 {
90 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertXAxis() );
91 }
92
93 template<typename T>
94 T ToDisplayRelY( T aInternalValue ) const
95 {
96 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertYAxis() );
97 }
98
99 template<typename T>
100 T FromDisplayRelX( T aDisplayValue ) const
101 {
102 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertXAxis() );
103 }
104
105 template<typename T>
106 T FromDisplayRelY( T aDisplayValue ) const
107 {
108 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertYAxis() );
109 }
110
111
112 // =============== Single-axis Absolute Transforms ===============
113
114 template<typename T>
115 T ToDisplayAbsX( T aInternalValue ) const
116 {
117 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserXOrigin(), invertXAxis() );
118 }
119
120 template<typename T>
121 T ToDisplayAbsY( T aInternalValue ) const
122 {
123 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserYOrigin(), invertYAxis() );
124 }
125
126 template<typename T>
127 T FromDisplayAbsX( T aDisplayValue ) const
128 {
130 }
131
132 template<typename T>
133 T FromDisplayAbsY( T aDisplayValue ) const
134 {
136 }
137
138
139 // =============== Two-axis Transforms ===============
140
141 template<typename T>
142 T ToDisplayAbs( T aInternalValue ) const
143 {
144 T displayValue;
145
146 displayValue.x = ToDisplayAbsX( aInternalValue.x );
147 displayValue.y = ToDisplayAbsY( aInternalValue.y );
148
149 return displayValue;
150 }
151
152 template<typename T>
153 T FromDisplayAbs( T aDisplayValue ) const
154 {
155 T internalValue;
156
157 internalValue.x = FromDisplayAbsX( aDisplayValue.x );
158 internalValue.y = FromDisplayAbsY( aDisplayValue.y );
159
160 return internalValue;
161 }
162
163 template<typename T>
164 T ToDisplayRel( T aInternalValue ) const
165 {
166 T displayValue;
167
168 displayValue.x = ToDisplayRelX( aInternalValue.x );
169 displayValue.y = ToDisplayRelY( aInternalValue.y );
170
171 return displayValue;
172 }
173
174 template<typename T>
175 T FromDisplayRel( T aDisplayValue ) const
176 {
177 T internalValue;
178
179 internalValue.x = FromDisplayRelX( aDisplayValue.x );
180 internalValue.y = FromDisplayRelY( aDisplayValue.y );
181
182 return internalValue;
183 }
184
185protected:
186 int getUserXOrigin() const;
187 int getUserYOrigin() const;
188
189 bool invertXAxis() const;
190 bool invertYAxis() const;
191
192protected:
194};
A class to perform either relative or absolute display origin transforms for a single axis of a point...
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const
T FromDisplayRel(const T &aValue) const
T ToDisplayRel(const T &aValue) const
T ToDisplayAbs(const T &aValue) const
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
COORD_TYPES_T
The supported Display Origin Transform types.
T FromDisplayAbs(const T &aValue) const
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
T ToDisplayRelY(T aInternalValue) const
T ToDisplayAbsX(T aInternalValue) const
~PCB_ORIGIN_TRANSFORMS()=default
PCB_ORIGIN_TRANSFORMS(PCB_BASE_FRAME &aPcbBaseFrame)
virtual long long int FromDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
T FromDisplayRel(T aDisplayValue) const
T ToDisplayAbs(T aInternalValue) const
const PCB_BASE_FRAME & m_pcbBaseFrame
T FromDisplayRelY(T aDisplayValue) const
T ToDisplayRel(T aInternalValue) const
T FromDisplayAbs(T aDisplayValue) const
T FromDisplayAbsY(T aDisplayValue) const
T FromDisplayAbsX(T aDisplayValue) const
T ToDisplayRelX(T aInternalValue) const
Transform a 2-D coordinate point referenced to the internal origin to the equivalent point referenced...
T ToDisplayAbsY(T aInternalValue) const
virtual long long int ToDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
T FromDisplayRelX(T aDisplayValue) const