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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <wx/debug.h> // for wxASSERT
22#include <pcb_base_frame.h>
23#include <pcbnew_settings.h>
26
28
32
33
34long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const
35{
36 long long int value = aValue;
37
38 switch( aCoordType )
39 {
40 case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
41 case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
42 case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
43 case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
44 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
45 default: wxASSERT( false ); break;
46 };
47
48 return value;
49}
50
51
52double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const
53{
54 double value = aValue;
55
56 switch( aCoordType )
57 {
58 case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
59 case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
60 case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
61 case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
62 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
63 default: wxASSERT( false ); break;
64 };
65
66 return value;
67}
68
69
70double PCB_ORIGIN_TRANSFORMS::ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const
71{
72 if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) )
73 return -aValue.AsDegrees();
74
75 return aValue.AsDegrees();
76}
77
78
79long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const
80{
81 long long value = aValue;
82
83 switch( aCoordType )
84 {
85 case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
86 case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
87 case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
88 case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
89 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
90 default: wxASSERT( false ); break;
91 };
92
93 return value;
94}
95
96
97double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const
98{
99 double value = aValue;
100
101 switch( aCoordType )
102 {
103 case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
104 case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
105 case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
106 case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
107 case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
108 default: wxASSERT( false ); break;
109 };
110
111 return value;
112}
113
114
116{
117 if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) )
118 return -aValue;
119
120 return aValue;
121}
122
123
125{
126 return m_pcbBaseFrame.GetUserOrigin().x;
127}
128
129
131{
132 return m_pcbBaseFrame.GetUserOrigin().y;
133}
134
135
137{
138 if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR )
139 return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertXAxis;
140 else
141 return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertXAxis;
142}
143
144
146{
147 if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR )
148 return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis;
149 else
150 return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertYAxis;
151}
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:38
ORIGIN_TRANSFORMS::COORD_TYPES_T COORD_TYPE