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.

228 lines
8.8 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_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. 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. #define DEFAULT_ZOOM ZOOM_FACTOR( 120 )
  58. static const double pcbZoomList[] =
  59. {
  60. ZOOM_FACTOR( 0.1 ),
  61. ZOOM_FACTOR( 0.2 ),
  62. ZOOM_FACTOR( 0.3 ),
  63. ZOOM_FACTOR( 0.5 ),
  64. ZOOM_FACTOR( 1.0 ),
  65. ZOOM_FACTOR( 1.5 ),
  66. ZOOM_FACTOR( 2.0 ),
  67. ZOOM_FACTOR( 3.0 ),
  68. ZOOM_FACTOR( 4.5 ),
  69. ZOOM_FACTOR( 6.0 ),
  70. ZOOM_FACTOR( 8.0 ),
  71. ZOOM_FACTOR( 11.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( 110.0 ),
  78. ZOOM_FACTOR( 150.0 ),
  79. ZOOM_FACTOR( 200.0 ),
  80. ZOOM_FACTOR( 300.0 ),
  81. /*
  82. The largest distance that wx can support is INT_MAX, since it represents
  83. distance often in a wxCoord or wxSize. As a scalar, a distance is always
  84. positive. On most machines which run KiCad, int is 32 bits and INT_MAX is
  85. 2147483647. The most difficult distance for a virtual (world) cartesian
  86. space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
  87. puts the most stress on the distance magnitude within the bounded virtual
  88. space. So if we allow this distance to be our constraint of <= INT_MAX, this
  89. constraint then propagates to the maximum distance in X and in Y that can be
  90. supported on each axis. Remember that the hypotenuse of a 1x1 square is
  91. sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
  92. hypotenuse of any square = sqrt(2) * deltaX;
  93. Let maximum supported hypotenuse be INT_MAX, then:
  94. MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
  95. This maximum distance is imposed by wxWidgets, not by KiCad. The imposition
  96. comes in the form of the data structures used in the graphics API at the
  97. wxDC level. Obviously when we are not interacting with wx we can use double
  98. to compute distances larger than this. For example the computation of the
  99. total length of a net, can and should be done in double, since it might
  100. actually be longer than a single diagonal line.
  101. The next choice is what to use for internal units (IU), sometimes called
  102. world units. If nanometers, then the virtual space must be limited to
  103. about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
  104. The maximum zoom factor then depends on the client window size. If we ask
  105. wx to handle something outside INT_MIN to INT_MAX, there are unreported
  106. problems in the non-Debug build because wxRound() goes silent.
  107. Let:
  108. const double MAX_AXIS = 1518500251;
  109. Then a maximum zoom factor for a screen of 1920 pixels wide is
  110. 1518500251 / 1920 = 790885.
  111. The largest ZOOM_FACTOR in above table is ZOOM_FACTOR( 300 ), which computes
  112. out to 762000 just below 790885.
  113. */
  114. };
  115. // Default grid sizes for PCB editor screens.
  116. static GRID_TYPE pcbGridList[] =
  117. {
  118. // predefined grid list in 0.0001 inches
  119. { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) },
  120. { ID_POPUP_GRID_LEVEL_500, DMIL_GRID( 500 ) },
  121. { ID_POPUP_GRID_LEVEL_250, DMIL_GRID( 250 ) },
  122. { ID_POPUP_GRID_LEVEL_200, DMIL_GRID( 200 ) },
  123. { ID_POPUP_GRID_LEVEL_100, DMIL_GRID( 100 ) },
  124. { ID_POPUP_GRID_LEVEL_50, DMIL_GRID( 50 ) },
  125. { ID_POPUP_GRID_LEVEL_25, DMIL_GRID( 25 ) },
  126. { ID_POPUP_GRID_LEVEL_20, DMIL_GRID( 20 ) },
  127. { ID_POPUP_GRID_LEVEL_10, DMIL_GRID( 10 ) },
  128. { ID_POPUP_GRID_LEVEL_5, DMIL_GRID( 5 ) },
  129. { ID_POPUP_GRID_LEVEL_2, DMIL_GRID( 2 ) },
  130. { ID_POPUP_GRID_LEVEL_1, DMIL_GRID( 1 ) },
  131. // predefined grid list in mm
  132. { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) },
  133. { ID_POPUP_GRID_LEVEL_2_5MM, MM_GRID( 2.5 ) },
  134. { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) },
  135. { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) },
  136. { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) },
  137. { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) },
  138. { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) },
  139. { ID_POPUP_GRID_LEVEL_0_0_5MM, MM_GRID( 0.05 ) },
  140. { ID_POPUP_GRID_LEVEL_0_0_25MM, MM_GRID( 0.025 ) },
  141. { ID_POPUP_GRID_LEVEL_0_0_1MM, MM_GRID( 0.01 ) }
  142. };
  143. PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
  144. BASE_SCREEN( SCREEN_T )
  145. {
  146. // D(wxSize displayz = wxGetDisplaySize();)
  147. // D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
  148. for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
  149. m_ZoomList.push_back( pcbZoomList[i] );
  150. for( unsigned i = 0; i < DIM( pcbGridList ); ++i )
  151. AddGrid( pcbGridList[i] );
  152. // Set the working grid size to a reasonable value (in 1/10000 inch)
  153. SetGrid( DMIL_GRID( 500 ) );
  154. m_Active_Layer = F_Cu; // default active layer = front layer
  155. m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top)
  156. m_Route_Layer_BOTTOM = B_Cu;
  157. SetZoom( DEFAULT_ZOOM ); // a default value for zoom
  158. InitDataPoints( aPageSizeIU );
  159. }
  160. PCB_SCREEN::~PCB_SCREEN()
  161. {
  162. ClearUndoRedoList();
  163. }
  164. int PCB_SCREEN::MilsToIuScalar()
  165. {
  166. return (int)IU_PER_MILS;
  167. }
  168. DISPLAY_OPTIONS::DISPLAY_OPTIONS()
  169. {
  170. m_DisplayPadFill = FILLED;
  171. m_DisplayViaFill = FILLED;
  172. m_DisplayPadNum = true;
  173. m_DisplayPadIsol = true;
  174. m_DisplayModEdgeFill = FILLED;
  175. m_DisplayModTextFill = FILLED;
  176. m_DisplayPcbTrackFill = FILLED; // false = sketch , true = filled
  177. m_ShowTrackClearanceMode = SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS;
  178. m_DisplayPolarCood = false; /* false = display absolute coordinates,
  179. * true = display polar cordinates */
  180. m_DisplayZonesMode = 0; /* 0 = Show filled areas outlines in zones,
  181. * 1 = do not show filled areas outlines
  182. * 2 = show outlines of filled areas */
  183. m_DisplayNetNamesMode = 3; /* 0 do not show netnames,
  184. * 1 show netnames on pads
  185. * 2 show netnames on tracks
  186. * 3 show netnames on tracks and pads */
  187. m_DisplayDrawItemsFill = FILLED;
  188. m_ContrastModeDisplay = false;
  189. m_MaxLinksShowed = 3; // in track creation: number of hairwires shown
  190. m_Show_Module_Ratsnest = true; // When moving a footprint: allows displaying a ratsnest
  191. }