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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#pragma once
26
27#include <origin_transforms.h>
28
29class PCB_BASE_FRAME;
30
32{
33public:
34 PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame );
35
37
39
40 virtual long long int ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override;
41 virtual double ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
42 virtual double ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override;
43
45
46 virtual long long int FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override;
47 virtual double FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
48 virtual EDA_ANGLE FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override;
49
57
65
76
87
88
89 // =============== Single-axis Relative Transforms ===============
90
91 template<typename T>
92 T ToDisplayRelX( T aInternalValue ) const
93 {
94 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertXAxis() );
95 }
96
97 template<typename T>
98 T ToDisplayRelY( T aInternalValue ) const
99 {
100 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertYAxis() );
101 }
102
103 template<typename T>
104 T FromDisplayRelX( T aDisplayValue ) const
105 {
106 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertXAxis() );
107 }
108
109 template<typename T>
110 T FromDisplayRelY( T aDisplayValue ) const
111 {
112 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertYAxis() );
113 }
114
115
116 // =============== Single-axis Absolute Transforms ===============
117
118 template<typename T>
119 T ToDisplayAbsX( T aInternalValue ) const
120 {
121 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserXOrigin(), invertXAxis() );
122 }
123
124 template<typename T>
125 T ToDisplayAbsY( T aInternalValue ) const
126 {
127 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserYOrigin(), invertYAxis() );
128 }
129
130 template<typename T>
131 T FromDisplayAbsX( T aDisplayValue ) const
132 {
134 }
135
136 template<typename T>
137 T FromDisplayAbsY( T aDisplayValue ) const
138 {
140 }
141
142
143 // =============== Two-axis Transforms ===============
144
145 template<typename T>
146 T ToDisplayAbs( T aInternalValue ) const
147 {
148 T displayValue;
149
150 displayValue.x = ToDisplayAbsX( aInternalValue.x );
151 displayValue.y = ToDisplayAbsY( aInternalValue.y );
152
153 return displayValue;
154 }
155
156 template<typename T>
157 T FromDisplayAbs( T aDisplayValue ) const
158 {
159 T internalValue;
160
161 internalValue.x = FromDisplayAbsX( aDisplayValue.x );
162 internalValue.y = FromDisplayAbsY( aDisplayValue.y );
163
164 return internalValue;
165 }
166
167 template<typename T>
168 T ToDisplayRel( T aInternalValue ) const
169 {
170 T displayValue;
171
172 displayValue.x = ToDisplayRelX( aInternalValue.x );
173 displayValue.y = ToDisplayRelY( aInternalValue.y );
174
175 return displayValue;
176 }
177
178 template<typename T>
179 T FromDisplayRel( T aDisplayValue ) const
180 {
181 T internalValue;
182
183 internalValue.x = FromDisplayRelX( aDisplayValue.x );
184 internalValue.y = FromDisplayRelY( aDisplayValue.y );
185
186 return internalValue;
187 }
188
189protected:
190 int getUserXOrigin() const;
191 int getUserYOrigin() const;
192
193 bool invertXAxis() const;
194 bool invertYAxis() const;
195
196protected:
198};
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