KiCad PCB EDA Suite
classpcb.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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <fctsys.h>
28 #include <common.h>
29 #include <macros.h>
30 #include <trigo.h>
31 #include <class_pcb_screen.h>
32 #include <eda_text.h> // FILLED
33 #include <base_units.h>
34 
35 #include <pcbnew.h>
38 
39 #include <pcbnew_id.h>
40 
41 
42 #define ZOOM_FACTOR( x ) ( x * IU_PER_MILS / 10 )
43 #define DMIL_GRID( x ) wxRealPoint( x * IU_PER_MILS / 10,\
44  x * IU_PER_MILS / 10 )
45 #define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\
46  x * IU_PER_MM )
47 
48 
59 #define DEFAULT_ZOOM ZOOM_FACTOR( 120 )
60 
61 static const double pcbZoomList[] =
62 {
63  ZOOM_FACTOR( 0.1 ),
64  ZOOM_FACTOR( 0.2 ),
65  ZOOM_FACTOR( 0.3 ),
66  ZOOM_FACTOR( 0.5 ),
67  ZOOM_FACTOR( 1.0 ),
68  ZOOM_FACTOR( 1.5 ),
69  ZOOM_FACTOR( 2.0 ),
70  ZOOM_FACTOR( 3.0 ),
71  ZOOM_FACTOR( 4.5 ),
72  ZOOM_FACTOR( 6.0 ),
73  ZOOM_FACTOR( 8.0 ),
74  ZOOM_FACTOR( 11.0 ),
75  ZOOM_FACTOR( 15.0 ),
76  ZOOM_FACTOR( 22.0 ),
77  ZOOM_FACTOR( 35.0 ),
78  ZOOM_FACTOR( 50.0 ),
79  ZOOM_FACTOR( 80.0 ),
80  ZOOM_FACTOR( 110.0 ),
81  ZOOM_FACTOR( 150.0 ),
82  ZOOM_FACTOR( 200.0 ),
83  ZOOM_FACTOR( 300.0 ),
84 /*
85  The largest distance that wx can support is INT_MAX, since it represents
86  distance often in a wxCoord or wxSize. As a scalar, a distance is always
87  positive. On most machines which run KiCad, int is 32 bits and INT_MAX is
88  2147483647. The most difficult distance for a virtual (world) cartesian
89  space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
90  puts the most stress on the distance magnitude within the bounded virtual
91  space. So if we allow this distance to be our constraint of <= INT_MAX, this
92  constraint then propagates to the maximum distance in X and in Y that can be
93  supported on each axis. Remember that the hypotenuse of a 1x1 square is
94  sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
95 
96  hypotenuse of any square = sqrt(2) * deltaX;
97 
98  Let maximum supported hypotenuse be INT_MAX, then:
99 
100  MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
101 
102  This maximum distance is imposed by wxWidgets, not by KiCad. The imposition
103  comes in the form of the data structures used in the graphics API at the
104  wxDC level. Obviously when we are not interacting with wx we can use double
105  to compute distances larger than this. For example the computation of the
106  total length of a net, can and should be done in double, since it might
107  actually be longer than a single diagonal line.
108 
109  The next choice is what to use for internal units (IU), sometimes called
110  world units. If nanometers, then the virtual space must be limited to
111  about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
112 
113  The maximum zoom factor then depends on the client window size. If we ask
114  wx to handle something outside INT_MIN to INT_MAX, there are unreported
115  problems in the non-Debug build because wxRound() goes silent.
116 
117  Let:
118  const double MAX_AXIS = 1518500251;
119 
120  Then a maximum zoom factor for a screen of 1920 pixels wide is
121  1518500251 / 1920 = 790885.
122 
123  The largest ZOOM_FACTOR in above table is ZOOM_FACTOR( 300 ), which computes
124  out to 762000 just below 790885.
125 */
126 };
127 
128 
129 // Default grid sizes for PCB editor screens.
131 {
132  // predefined grid list in 0.0001 inches
133  { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) },
145 
146  // predefined grid list in mm
147  { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) },
149  { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) },
151  { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) },
157 };
158 
159 
160 PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
162 {
163  // D(wxSize displayz = wxGetDisplaySize();)
164  // D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
165 
166  for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
167  m_ZoomList.push_back( pcbZoomList[i] );
168 
169  for( unsigned i = 0; i < DIM( pcbGridList ); ++i )
170  AddGrid( pcbGridList[i] );
171 
172  // Set the working grid size to a reasonable value (in 1/10000 inch)
173  SetGrid( DMIL_GRID( 500 ) );
174 
175  m_Active_Layer = F_Cu; // default active layer = front layer
176  m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top)
178 
179  SetZoom( DEFAULT_ZOOM ); // a default value for zoom
180 
181  InitDataPoints( aPageSizeIU );
182 }
183 
184 
186 {
188 }
189 
190 
192 {
193  return (int)IU_PER_MILS;
194 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
static const double pcbZoomList[]
Definition: classpcb.cpp:61
Implementation of conversion functions that require both schematic and board internal units...
PCB_SCREEN(const wxSize &aPageSizeIU)
Constructor.
Definition: classpcb.cpp:160
#define ZOOM_FACTOR(x)
Definition: classpcb.cpp:42
#define MM_GRID(x)
Definition: classpcb.cpp:45
#define DMIL_GRID(x)
Definition: classpcb.cpp:43
Definition of base KiCad text object.
PCB_LAYER_ID m_Active_Layer
not really an item, used to identify a screen
Definition: typeinfo.h:86
This file contains miscellaneous commonly used macros and functions.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:69
#define DEFAULT_ZOOM
Default Pcbnew zoom values.
Definition: classpcb.cpp:59
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
PCB_LAYER_ID m_Route_Layer_BOTTOM
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
virtual int MilsToIuScalar() override
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: classpcb.cpp:191
static GRID_TYPE pcbGridList[]
Definition: classpcb.cpp:130
void AddGrid(const GRID_TYPE &grid)
Board layer functions and definitions.
Class GRID_TYPE is for grid arrays.
The common library.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
PCB_LAYER_ID m_Route_Layer_TOP
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.