You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
8.7 KiB

17 years ago
17 years ago
  1. /**
  2. * @file classpcb.cpp
  3. * @brief Member functions of classes used in Pcbnew (see pcbstruct.h)
  4. * except for tracks (see class_track.cpp).
  5. */
  6. /*
  7. * This program source code file is part of KiCad, a free EDA CAD application.
  8. *
  9. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  10. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  11. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  12. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, you may find one here:
  26. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  27. * or you may search the http://www.gnu.org website for the version 2 license,
  28. * or you may write to the Free Software Foundation, Inc.,
  29. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  30. */
  31. #include <fctsys.h>
  32. #include <common.h>
  33. #include <macros.h>
  34. #include <trigo.h>
  35. #include <class_pcb_screen.h>
  36. #include <eda_text.h> // FILLED
  37. #include <base_units.h>
  38. #include <pcbnew.h>
  39. #include <class_board_design_settings.h>
  40. #include <layers_id_colors_and_visibility.h>
  41. #include <pcbnew_id.h>
  42. #define ZOOM_FACTOR( x ) ( x * IU_PER_DECIMILS )
  43. #define DMIL_GRID( x ) wxRealPoint( x * IU_PER_DECIMILS,\
  44. x * IU_PER_DECIMILS )
  45. #define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\
  46. x * IU_PER_MM )
  47. /**
  48. Default Pcbnew zoom values.
  49. Limited to 19 values to keep a decent size to menus.
  50. Roughly a 1.5 progression.
  51. The last 2 values are handy when somebody uses a library import of a module
  52. (or foreign data) which has a bad coordinate.
  53. Also useful in GerbView for this reason.
  54. Zoom 5 and 10 can create artefacts when drawing (integer overflow in low level graphic
  55. functions )
  56. */
  57. static const double pcbZoomList[] =
  58. {
  59. #if defined( USE_PCBNEW_NANOMETRES )
  60. ZOOM_FACTOR( 0.1 ),
  61. ZOOM_FACTOR( 0.2 ),
  62. ZOOM_FACTOR( 0.3 ),
  63. #endif
  64. ZOOM_FACTOR( 0.5 ),
  65. ZOOM_FACTOR( 1.0 ),
  66. ZOOM_FACTOR( 1.5 ),
  67. ZOOM_FACTOR( 2.0 ),
  68. ZOOM_FACTOR( 3.0 ),
  69. ZOOM_FACTOR( 4.5 ),
  70. ZOOM_FACTOR( 7.0 ),
  71. ZOOM_FACTOR( 10.0 ),
  72. ZOOM_FACTOR( 15.0 ),
  73. ZOOM_FACTOR( 22.0 ),
  74. ZOOM_FACTOR( 35.0 ),
  75. ZOOM_FACTOR( 50.0 ),
  76. ZOOM_FACTOR( 80.0 ),
  77. ZOOM_FACTOR( 120.0 ),
  78. ZOOM_FACTOR( 200.0 ),
  79. ZOOM_FACTOR( 300.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. hypotenuse of any square = sqrt(2) * deltaX;
  92. Let maximum supported hypotenuse be INT_MAX, then:
  93. MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
  94. This maximum distance is imposed by wxWidgets, not by KiCad. The imposition
  95. comes in the form of the data structures used in the graphics API at the
  96. wxDC level. Obviously when we are not interacting with wx we can use double
  97. to compute distances larger than this. For example the computation of the
  98. total length of a net, can and should be done in double, since it might
  99. actually be longer than a single diagonal line.
  100. The next choice is what to use for internal units (IU), sometimes called
  101. world units. If nanometers, then the virtual space must be limited to
  102. about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
  103. The maximum zoom factor then depends on the client window size. If we ask
  104. wx to handle something outside INT_MIN to INT_MAX, there are unreported
  105. problems in the non-Debug build because wxRound() goes silent.
  106. Let:
  107. const double MAX_AXIS = 1518500251;
  108. Then a maximum zoom factor for a screen of 1920 pixels wide is
  109. 1518500251 / 1920 = 790885.
  110. The largest ZOOM_FACTOR in above table is ZOOM_FACTOR( 300 ), which computes
  111. out to 762000 just below 790885.
  112. */
  113. #if !defined( USE_PCBNEW_NANOMETRES )
  114. ZOOM_FACTOR( 500.0 ),
  115. ZOOM_FACTOR( 1000.0 ),
  116. ZOOM_FACTOR( 2000.0 )
  117. #endif
  118. };
  119. // Default grid sizes for PCB editor screens.
  120. static GRID_TYPE pcbGridList[] =
  121. {
  122. // predefined grid list in 0.0001 inches
  123. { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) },
  124. { ID_POPUP_GRID_LEVEL_500, DMIL_GRID( 500 ) },
  125. { ID_POPUP_GRID_LEVEL_250, DMIL_GRID( 250 ) },
  126. { ID_POPUP_GRID_LEVEL_200, DMIL_GRID( 200 ) },
  127. { ID_POPUP_GRID_LEVEL_100, DMIL_GRID( 100 ) },
  128. { ID_POPUP_GRID_LEVEL_50, DMIL_GRID( 50 ) },
  129. { ID_POPUP_GRID_LEVEL_25, DMIL_GRID( 25 ) },
  130. { ID_POPUP_GRID_LEVEL_20, DMIL_GRID( 20 ) },
  131. { ID_POPUP_GRID_LEVEL_10, DMIL_GRID( 10 ) },
  132. { ID_POPUP_GRID_LEVEL_5, DMIL_GRID( 5 ) },
  133. { ID_POPUP_GRID_LEVEL_2, DMIL_GRID( 2 ) },
  134. { ID_POPUP_GRID_LEVEL_1, DMIL_GRID( 1 ) },
  135. // predefined grid list in mm
  136. { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) },
  137. { ID_POPUP_GRID_LEVEL_2_5MM, MM_GRID( 2.5 ) },
  138. { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) },
  139. { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) },
  140. { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) },
  141. { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) },
  142. { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) },
  143. { ID_POPUP_GRID_LEVEL_0_0_5MM, MM_GRID( 0.05 ) },
  144. { ID_POPUP_GRID_LEVEL_0_0_25MM, MM_GRID( 0.025 ) },
  145. { ID_POPUP_GRID_LEVEL_0_0_1MM, MM_GRID( 0.01 ) }
  146. };
  147. PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
  148. BASE_SCREEN( SCREEN_T )
  149. {
  150. // D(wxSize displayz = wxGetDisplaySize();)
  151. // D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
  152. for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
  153. m_ZoomList.push_back( pcbZoomList[i] );
  154. for( unsigned i = 0; i < DIM( pcbGridList ); ++i )
  155. AddGrid( pcbGridList[i] );
  156. // Set the working grid size to a reasonable value (in 1/10000 inch)
  157. SetGrid( DMIL_GRID( 500 ) );
  158. m_Active_Layer = LAYER_N_BACK; // default active layer = bottom layer
  159. m_Route_Layer_TOP = LAYER_N_FRONT; // default layers pair for vias (bottom to top)
  160. m_Route_Layer_BOTTOM = LAYER_N_BACK;
  161. SetZoom( ZOOM_FACTOR( 120 ) ); // a default value for zoom
  162. InitDataPoints( aPageSizeIU );
  163. }
  164. PCB_SCREEN::~PCB_SCREEN()
  165. {
  166. ClearUndoRedoList();
  167. }
  168. int PCB_SCREEN::MilsToIuScalar()
  169. {
  170. return (int)IU_PER_MILS;
  171. }
  172. DISPLAY_OPTIONS::DISPLAY_OPTIONS()
  173. {
  174. DisplayPadFill = FILLED;
  175. DisplayViaFill = FILLED;
  176. DisplayPadNum = true;
  177. DisplayPadIsol = true;
  178. DisplayModEdge = true;
  179. DisplayModText = true;
  180. DisplayPcbTrackFill = true; // false = sketch , true = filled
  181. ShowTrackClearanceMode = SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS;
  182. m_DisplayViaMode = VIA_HOLE_NOT_SHOW;
  183. DisplayPolarCood = false; /* false = display absolute coordinates,
  184. * true = display polar cordinates */
  185. DisplayZonesMode = 0; /* 0 = Show filled areas outlines in zones,
  186. * 1 = do not show filled areas outlines
  187. * 2 = show outlines of filled areas */
  188. DisplayNetNamesMode = 3; /* 0 do not show netnames,
  189. * 1 show netnames on pads
  190. * 2 show netnames on tracks
  191. * 3 show netnames on tracks and pads */
  192. DisplayDrawItems = true;
  193. ContrastModeDisplay = false;
  194. }