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