KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_origin_transforms.cpp
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#include <wx/debug.h> // for wxASSERT
26#include <pcb_base_frame.h>
27#include <pcbnew_settings.h>
30
32
36
37
38long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const
39{
40 long long int value = aValue;
41
42 switch( aCoordType )
43 {
44 case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
45 case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
46 case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
47 case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
48 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
49 default: wxASSERT( false ); break;
50 };
51
52 return value;
53}
54
55
56double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const
57{
58 double value = aValue;
59
60 switch( aCoordType )
61 {
62 case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
63 case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
64 case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
65 case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
66 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
67 default: wxASSERT( false ); break;
68 };
69
70 return value;
71}
72
73
74double PCB_ORIGIN_TRANSFORMS::ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const
75{
76 if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) )
77 return -aValue.AsDegrees();
78
79 return aValue.AsDegrees();
80}
81
82
83long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const
84{
85 long long value = aValue;
86
87 switch( aCoordType )
88 {
89 case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
90 case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
91 case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
92 case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
93 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
94 default: wxASSERT( false ); break;
95 };
96
97 return value;
98}
99
100
101double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const
102{
103 double value = aValue;
104
105 switch( aCoordType )
106 {
107 case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
108 case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
109 case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
110 case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
111 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
112 default: wxASSERT( false ); break;
113 };
114
115 return value;
116}
117
118
120{
121 if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) )
122 return -aValue;
123
124 return aValue;
125}
126
127
129{
130 return m_pcbBaseFrame.GetUserOrigin().x;
131}
132
133
135{
136 return m_pcbBaseFrame.GetUserOrigin().y;
137}
138
139
141{
142 if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR )
143 return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertXAxis;
144 else
145 return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertXAxis;
146}
147
148
150{
151 if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR )
152 return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis;
153 else
154 return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertYAxis;
155}
double AsDegrees() const
Definition eda_angle.h:116
COORD_TYPES_T
The supported Display Origin Transform types.
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(PCB_BASE_FRAME &aPcbBaseFrame)
virtual long long int FromDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
const PCB_BASE_FRAME & m_pcbBaseFrame
T FromDisplayRelY(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
@ FRAME_PCB_EDITOR
Definition frame_type.h:42
ORIGIN_TRANSFORMS::COORD_TYPES_T COORD_TYPE