KiCad PCB EDA Suite
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 <reece@his.com>
5  * Copyright (C) 1992-2019 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 <pcb_display_options.h>
28 #include <pcb_origin_transforms.h>
29 
31 
33  : m_pcbBaseFrame( aPcbBaseFrame ),
34  m_invertXAxis( aPcbBaseFrame.GetDisplayOptions().m_DisplayInvertXAxis ),
35  m_invertYAxis( aPcbBaseFrame.GetDisplayOptions().m_DisplayInvertYAxis )
36 {}
37 
39 {}
40 
41 long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue,
42  COORD_TYPES_T aCoordType ) const
43 {
44  long long int value = aValue;
45 
46  switch( aCoordType )
47  {
48  case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
49  case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
50  case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
51  case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
52  case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
53  default: wxASSERT( false ); break;
54  };
55 
56  return value;
57 }
58 
59 double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue,
60  COORD_TYPES_T aCoordType ) const
61 {
62  double value = aValue;
63 
64  switch( aCoordType )
65  {
66  case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
67  case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
68  case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
69  case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
70  case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
71  default: wxASSERT( false ); break;
72  };
73 
74  return value;
75 }
76 
77 long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue,
78  COORD_TYPES_T aCoordType ) const
79 {
80  long long value = aValue;
81 
82  switch( aCoordType )
83  {
84  case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
85  case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
86  case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
87  case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
88  case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
89  default: wxASSERT( false ); break;
90  };
91 
92  return value;
93 }
94 
95 double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue,
96  COORD_TYPES_T aCoordType ) const
97 {
98  double value = aValue;
99 
100  switch( aCoordType )
101  {
102  case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
103  case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
104  case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
105  case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
106  case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
107  default: wxASSERT( false ); break;
108  };
109 
110  return value;
111 }
112 
113 
115 {
116  return m_pcbBaseFrame.GetUserOrigin().x;
117 }
118 
120 {
121  return m_pcbBaseFrame.GetUserOrigin().y;
122 }
123 
T FromDisplayRelY(T aDisplayValue) const
virtual ~PCB_ORIGIN_TRANSFORMS() override
const wxPoint GetUserOrigin() const
T ToDisplayRelX(T aInternalValue) const
Transform a 2-D coordinate point referenced to the internal origin to the equivalent point referenced...
virtual long long int FromDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
T FromDisplayAbsX(T aDisplayValue) const
virtual long long int ToDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
Classes used in Pcbnew, CvPcb and GerbView.
T ToDisplayAbsY(T aInternalValue) const
T ToDisplayRelY(T aInternalValue) const
T FromDisplayAbsY(T aDisplayValue) const
COORD_TYPES_T
The supported Display Origin Transform types.
const PCB_BASE_FRAME & m_pcbBaseFrame
PCB_ORIGIN_TRANSFORMS(PCB_BASE_FRAME &aPcbBaseFrame)
T ToDisplayAbsX(T aInternalValue) const
Definition of PCB_DISPLAY_OPTIONS class.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
T FromDisplayRelX(T aDisplayValue) const