KiCad PCB EDA Suite
pcb_screen.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 <pcb_screen.h>
32 #include <eda_text.h> // FILLED
33 #include <base_units.h>
34 
35 #include <pcbnew.h>
36 #include <board_design_settings.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, x * IU_PER_MILS / 10 )
44 #define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM )
45 
46 
57 static const double pcbZoomList[] =
58 {
59  ZOOM_FACTOR( 0.035 ),
60  ZOOM_FACTOR( 0.05 ),
61  ZOOM_FACTOR( 0.08 ),
62  ZOOM_FACTOR( 0.13 ),
63  ZOOM_FACTOR( 0.22 ),
64  ZOOM_FACTOR( 0.35 ),
65  ZOOM_FACTOR( 0.6 ),
66  ZOOM_FACTOR( 1.0 ),
67  ZOOM_FACTOR( 1.5 ),
68  ZOOM_FACTOR( 2.2 ),
69  ZOOM_FACTOR( 3.5 ),
70  ZOOM_FACTOR( 5.0 ),
71  ZOOM_FACTOR( 8.0 ),
72  ZOOM_FACTOR( 13.0 ),
73  ZOOM_FACTOR( 20.0 ),
74  ZOOM_FACTOR( 35.0 ),
75  ZOOM_FACTOR( 50.0 ),
76  ZOOM_FACTOR( 80.0 ),
77  ZOOM_FACTOR( 130.0 ),
78  ZOOM_FACTOR( 220.0 ),
79  ZOOM_FACTOR( 350.0 )
80 /*
81  The largest distance that wx can support is INT_MAX, since it represents
82  distance often in a wxCoord or wxSize. As a scalar, a distance is always
83  positive. On most machines which run KiCad, int is 32 bits and INT_MAX is
84  2147483647. The most difficult distance for a virtual (world) cartesian
85  space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
86  puts the most stress on the distance magnitude within the bounded virtual
87  space. So if we allow this distance to be our constraint of <= INT_MAX, this
88  constraint then propagates to the maximum distance in X and in Y that can be
89  supported on each axis. Remember that the hypotenuse of a 1x1 square is
90  sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
91 
92  hypotenuse of any square = sqrt(2) * deltaX;
93 
94  Let maximum supported hypotenuse be INT_MAX, then:
95 
96  MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
97 
98  This maximum distance is imposed by wxWidgets, not by KiCad. The imposition
99  comes in the form of the data structures used in the graphics API at the
100  wxDC level. Obviously when we are not interacting with wx we can use double
101  to compute distances larger than this. For example the computation of the
102  total length of a net, can and should be done in double, since it might
103  actually be longer than a single diagonal line.
104 
105  The next choice is what to use for internal units (IU), sometimes called
106  world units. If nanometers, then the virtual space must be limited to
107  about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
108 
109  The maximum zoom factor then depends on the client window size. If we ask
110  wx to handle something outside INT_MIN to INT_MAX, there are unreported
111  problems in the non-Debug build because wxRound() goes silent.
112 
113  Let:
114  const double MAX_AXIS = 1518500251;
115 
116  Then a maximum zoom factor for a screen of 1920 pixels wide is
117  1518500251 / 1920 = 790885.
118 
119  The largest ZOOM_FACTOR in above table is ZOOM_FACTOR( 300 ), which computes
120  out to 762000 just below 790885.
121 */
122 };
123 
124 
125 // Default grid sizes for PCB editor screens.
127 {
128  // predefined grid list in 0.0001 inches
129  { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) },
141 
142  // predefined grid list in mm
143  { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) },
145  { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) },
147  { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) },
153 };
154 
155 
156 PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
158 {
159  for( double zoom : pcbZoomList )
160  m_ZoomList.push_back( zoom );
161 
162  for( GRID_TYPE grid : pcbGridList )
163  AddGrid( grid );
164 
165  // Set the working grid size to a reasonable value (in 1/10000 inch)
166  SetGrid( DMIL_GRID( 500 ) );
167 
168  m_Active_Layer = F_Cu; // default active layer = front layer
169  m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top)
171 
172  InitDataPoints( aPageSizeIU );
173 }
174 
175 
177 {
179 }
Implementation of conversion functions that require both schematic and board internal units.
#define MM_GRID(x)
Definition: pcb_screen.cpp:44
static const double pcbZoomList[]
Default Pcbnew zoom values.
Definition: pcb_screen.cpp:57
PCB_SCREEN(const wxSize &aPageSizeIU)
Constructor.
Definition: pcb_screen.cpp:156
void AddGrid(const GRID_TYPE &aGrid)
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:44
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:63
#define DMIL_GRID(x)
Definition: pcb_screen.cpp:43
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:46
#define ZOOM_FACTOR(x)
Definition: pcb_screen.cpp:42
Board layer functions and definitions.
Class GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
static GRID_TYPE pcbGridList[]
Definition: pcb_screen.cpp:126
The common library.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:45
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
Definition: base_screen.h:138