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
46 // =============== Single-axis Relative Transforms ===============
47
55 template<typename T>
56 T ToDisplayRelX( T aInternalValue ) const
57 {
58 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertXAxis() );
59 }
60
68 template<typename T>
69 T ToDisplayRelY( T aInternalValue ) const
70 {
71 return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertYAxis() );
72 }
73
84 template<typename T>
85 T FromDisplayRelX( T aDisplayValue ) const
86 {
87 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertXAxis() );
88 }
89
100 template<typename T>
101 T FromDisplayRelY( T aDisplayValue ) const
102 {
103 return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertYAxis() );
104 }
105
106
107 // =============== Single-axis Absolute Transforms ===============
108
109 template<typename T>
110 T ToDisplayAbsX( T aInternalValue ) const
111 {
112 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserXOrigin(), invertXAxis() );
113 }
114
115 template<typename T>
116 T ToDisplayAbsY( T aInternalValue ) const
117 {
118 return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserYOrigin(), invertYAxis() );
119 }
120
121 template<typename T>
122 T FromDisplayAbsX( T aDisplayValue ) const
123 {
125 }
126
127 template<typename T>
128 T FromDisplayAbsY( T aDisplayValue ) const
129 {
131 }
132
133
134 // =============== Two-axis Transforms ===============
135
136 template<typename T>
137 T ToDisplayAbs( T aInternalValue ) const
138 {
139 T displayValue;
140
141 displayValue.x = ToDisplayAbsX( aInternalValue.x );
142 displayValue.y = ToDisplayAbsY( aInternalValue.y );
143
144 return displayValue;
145 }
146
147 template<typename T>
148 T FromDisplayAbs( T aDisplayValue ) const
149 {
150 T internalValue;
151
152 internalValue.x = FromDisplayAbsX( aDisplayValue.x );
153 internalValue.y = FromDisplayAbsY( aDisplayValue.y );
154
155 return internalValue;
156 }
157
158 template<typename T>
159 T ToDisplayRel( T aInternalValue ) const
160 {
161 T displayValue;
162
163 displayValue.x = ToDisplayRelX( aInternalValue.x );
164 displayValue.y = ToDisplayRelY( aInternalValue.y );
165
166 return displayValue;
167 }
168
169 template<typename T>
170 T FromDisplayRel( T aDisplayValue ) const
171 {
172 T internalValue;
173
174 internalValue.x = FromDisplayRelX( aDisplayValue.x );
175 internalValue.y = FromDisplayRelY( aDisplayValue.y );
176
177 return internalValue;
178 }
179
180protected:
181 int getUserXOrigin() const;
182 int getUserYOrigin() const;
183
184 bool invertXAxis() const;
185 bool invertYAxis() const;
186
187protected:
189};
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
Transform a 2-D coordinate point referenced to the user-selected display origin to the equivalent poi...
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
Transform a relative 2-D coordinate delta referenced to the user-selected display origin to the equiv...
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
Transform a relative 2-D coordinate delta referenced to the user-selected display origin to the equiv...