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.

1151 lines
35 KiB

14 years ago
14 years ago
14 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
15 years ago
15 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
15 years ago
15 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2016 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. * @file muonde.cpp
  28. * @brief Microwave pcb layout code.
  29. */
  30. #include <fctsys.h>
  31. #include <class_drawpanel.h>
  32. #include <confirm.h>
  33. #include <trigo.h>
  34. #include <kicad_string.h>
  35. #include <gestfich.h>
  36. #include <wxPcbStruct.h>
  37. #include <dialog_helpers.h>
  38. #include <richio.h>
  39. #include <filter_reader.h>
  40. #include <gr_basic.h>
  41. #include <macros.h>
  42. #include <base_units.h>
  43. #include <validators.h>
  44. #include <class_board.h>
  45. #include <class_module.h>
  46. #include <class_edge_mod.h>
  47. #include <pcbnew.h>
  48. static std::vector< wxRealPoint > PolyEdges;
  49. static double ShapeScaleX, ShapeScaleY;
  50. static wxSize ShapeSize;
  51. static int PolyShapeType;
  52. static void Exit_Self( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
  53. static void gen_arc( std::vector <wxPoint>& aBuffer,
  54. wxPoint aStartPoint,
  55. wxPoint aCenter,
  56. int a_ArcAngle );
  57. static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel,
  58. wxDC* aDC,
  59. const wxPoint& aPosition,
  60. bool aErase );
  61. static int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
  62. wxPoint aStartPoint, wxPoint aEndPoint,
  63. int aLength, int aWidth );
  64. /**
  65. * Creates a self-shaped coil for microwave applications.
  66. */
  67. static MODULE* CreateMicrowaveInductor( PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage );
  68. class MUWAVE_INDUCTOR
  69. {
  70. public:
  71. wxPoint m_Start;
  72. wxPoint m_End;
  73. wxSize m_Size;
  74. int m_length; // full length trace.
  75. int m_Width; // Trace width.
  76. // A flag set to true when mu-wave inductor is being created
  77. bool m_Flag;
  78. };
  79. // An instance of MUWAVE_INDUCTOR temporary used during mu-wave inductor creation
  80. static MUWAVE_INDUCTOR s_inductor_pattern;
  81. /* This function shows on screen the bounding box of the inductor that will be
  82. * created at the end of the build inductor process
  83. */
  84. static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  85. const wxPoint& aPosition, bool aErase )
  86. {
  87. /* Calculate the orientation and size of the box containing the inductor:
  88. * the box is a rectangle with height = length/2
  89. * the shape is defined by a rectangle, nor necessary horizontal or vertical
  90. */
  91. GRSetDrawMode( aDC, GR_XOR );
  92. wxPoint poly[5];
  93. wxPoint pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start;
  94. double angle = -ArcTangente( pt.y, pt.x );
  95. int len = KiROUND( EuclideanNorm( pt ) );
  96. // calculate corners
  97. pt.x = 0; pt.y = len / 4;
  98. RotatePoint( &pt, angle );
  99. poly[0] = s_inductor_pattern.m_Start + pt;
  100. poly[1] = s_inductor_pattern.m_End + pt;
  101. pt.x = 0; pt.y = -len / 4;
  102. RotatePoint( &pt, angle );
  103. poly[2] = s_inductor_pattern.m_End + pt;
  104. poly[3] = s_inductor_pattern.m_Start + pt;
  105. poly[4] = poly[0];
  106. if( aErase )
  107. {
  108. GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
  109. }
  110. s_inductor_pattern.m_End = aPanel->GetParent()->GetCrossHairPosition();
  111. pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start;
  112. angle = -ArcTangente( pt.y, pt.x );
  113. len = KiROUND( EuclideanNorm( pt ) );
  114. // calculate new corners
  115. pt.x = 0; pt.y = len / 4;
  116. RotatePoint( &pt, angle );
  117. poly[0] = s_inductor_pattern.m_Start + pt;
  118. poly[1] = s_inductor_pattern.m_End + pt;
  119. pt.x = 0; pt.y = -len / 4;
  120. RotatePoint( &pt, angle );
  121. poly[2] = s_inductor_pattern.m_End + pt;
  122. poly[3] = s_inductor_pattern.m_Start + pt;
  123. poly[4] = poly[0];
  124. GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
  125. }
  126. void Exit_Self( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
  127. {
  128. if( aPanel->IsMouseCaptured() )
  129. aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
  130. s_inductor_pattern.m_Flag = false;
  131. aPanel->SetMouseCapture( NULL, NULL );
  132. }
  133. void PCB_EDIT_FRAME::Begin_Self( wxDC* DC )
  134. {
  135. if( s_inductor_pattern.m_Flag )
  136. {
  137. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  138. m_canvas->SetMouseCapture( NULL, NULL );
  139. wxString errorMessage;
  140. // Prepare parameters for inductor
  141. // s_inductor_pattern.m_Start is already initialized,
  142. // when s_inductor_pattern.m_Flag == false
  143. s_inductor_pattern.m_Width = GetDesignSettings().GetCurrentTrackWidth();
  144. s_inductor_pattern.m_End = GetCrossHairPosition();
  145. MODULE* footprint = CreateMicrowaveInductor( this, errorMessage );
  146. if( footprint )
  147. {
  148. SetMsgPanel( footprint );
  149. footprint->Draw( m_canvas, DC, GR_OR );
  150. }
  151. else if( !errorMessage.IsEmpty() )
  152. DisplayError( this, errorMessage );
  153. return;
  154. }
  155. s_inductor_pattern.m_Start = GetCrossHairPosition();
  156. s_inductor_pattern.m_End = s_inductor_pattern.m_Start;
  157. s_inductor_pattern.m_Flag = true;
  158. // Update the initial coordinates.
  159. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  160. UpdateStatusBar();
  161. m_canvas->SetMouseCapture( ShowBoundingBoxMicroWaveInductor, Exit_Self );
  162. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  163. }
  164. MODULE* CreateMicrowaveInductor( PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage )
  165. {
  166. /* Build a microwave inductor footprint.
  167. * - Length Mself.lng
  168. * - Extremities Mself.m_Start and Mself.m_End
  169. * We must determine:
  170. * Mself.nbrin = number of segments perpendicular to the direction
  171. * (The coil nbrin will demicercles + 1 + 2 1 / 4 circle)
  172. * Mself.lbrin = length of a strand
  173. * Mself.radius = radius of rounded parts of the coil
  174. * Mself.delta = segments extremities connection between him and the coil even
  175. *
  176. * The equations are
  177. * Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin
  178. * Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius
  179. * Mself.lng = 2 * Mself.delta / / connections to the coil
  180. + (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last
  181. + (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded
  182. * Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit
  183. *
  184. * The constraints are:
  185. * Nbrin >= 2
  186. * Mself.radius < Mself.m_Size.x
  187. * Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord
  188. * Mself.lbrin> Mself.radius * 2
  189. *
  190. * The calculation is conducted in the following way:
  191. * Initially:
  192. * Nbrin = 2
  193. * Radius = 4 * m_Size.x (arbitrarily fixed value)
  194. * Then:
  195. * Increasing the number of segments to the desired length
  196. * (Radius decreases if necessary)
  197. */
  198. D_PAD* pad;
  199. int ll;
  200. wxString msg;
  201. wxASSERT( s_inductor_pattern.m_Flag );
  202. s_inductor_pattern.m_Flag = false;
  203. wxPoint pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start;
  204. int min_len = KiROUND( EuclideanNorm( pt ) );
  205. s_inductor_pattern.m_length = min_len;
  206. // Enter the desired length.
  207. msg = StringFromValue( g_UserUnit, s_inductor_pattern.m_length );
  208. wxTextEntryDialog dlg( NULL, wxEmptyString, _( "Length of Trace:" ), msg );
  209. if( dlg.ShowModal() != wxID_OK )
  210. return NULL; // canceled by user
  211. msg = dlg.GetValue();
  212. s_inductor_pattern.m_length = ValueFromString( g_UserUnit, msg );
  213. // Control values (ii = minimum length)
  214. if( s_inductor_pattern.m_length < min_len )
  215. {
  216. aErrorMessage = _( "Requested length < minimum length" );
  217. return NULL;
  218. }
  219. // Calculate the elements.
  220. std::vector <wxPoint> buffer;
  221. ll = BuildCornersList_S_Shape( buffer, s_inductor_pattern.m_Start,
  222. s_inductor_pattern.m_End, s_inductor_pattern.m_length,
  223. s_inductor_pattern.m_Width );
  224. if( !ll )
  225. {
  226. aErrorMessage = _( "Requested length too large" );
  227. return NULL;
  228. }
  229. // Generate footprint. the value is also used as footprint name.
  230. msg.Empty();
  231. wxTextEntryDialog cmpdlg( NULL, wxEmptyString, _( "Component Value:" ), msg );
  232. cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) );
  233. if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() )
  234. return NULL; // Aborted by user
  235. MODULE* module = aPcbFrame->CreateNewModule( msg );
  236. // here the module is already in the BOARD, CreateNewModule() does that.
  237. module->SetFPID( LIB_ID( std::string( "mw_inductor" ) ) );
  238. module->SetAttributes( MOD_VIRTUAL | MOD_CMS );
  239. module->ClearFlags();
  240. module->SetPosition( s_inductor_pattern.m_End );
  241. // Generate segments
  242. for( unsigned jj = 1; jj < buffer.size(); jj++ )
  243. {
  244. EDGE_MODULE* PtSegm;
  245. PtSegm = new EDGE_MODULE( module );
  246. PtSegm->SetStart( buffer[jj - 1] );
  247. PtSegm->SetEnd( buffer[jj] );
  248. PtSegm->SetWidth( s_inductor_pattern.m_Width );
  249. PtSegm->SetLayer( module->GetLayer() );
  250. PtSegm->SetShape( S_SEGMENT );
  251. PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() );
  252. PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() );
  253. module->GraphicalItems().PushBack( PtSegm );
  254. }
  255. // Place a pad on each end of coil.
  256. pad = new D_PAD( module );
  257. module->Pads().PushFront( pad );
  258. pad->SetPadName( wxT( "1" ) );
  259. pad->SetPosition( s_inductor_pattern.m_End );
  260. pad->SetPos0( pad->GetPosition() - module->GetPosition() );
  261. pad->SetSize( wxSize( s_inductor_pattern.m_Width, s_inductor_pattern.m_Width ) );
  262. pad->SetLayerSet( LSET( module->GetLayer() ) );
  263. pad->SetAttribute( PAD_ATTRIB_SMD );
  264. pad->SetShape( PAD_SHAPE_CIRCLE );
  265. D_PAD* newpad = new D_PAD( *pad );
  266. module->Pads().Insert( newpad, pad->Next() );
  267. pad = newpad;
  268. pad->SetPadName( wxT( "2" ) );
  269. pad->SetPosition( s_inductor_pattern.m_Start );
  270. pad->SetPos0( pad->GetPosition() - module->GetPosition() );
  271. // Modify text positions.
  272. wxPoint refPos( ( s_inductor_pattern.m_Start.x + s_inductor_pattern.m_End.x ) / 2,
  273. ( s_inductor_pattern.m_Start.y + s_inductor_pattern.m_End.y ) / 2 );
  274. wxPoint valPos = refPos;
  275. refPos.y -= module->Reference().GetTextSize().y;
  276. module->Reference().SetPosition( refPos );
  277. valPos.y += module->Value().GetTextSize().y;
  278. module->Value().SetPosition( valPos );
  279. module->CalculateBoundingBox();
  280. return module;
  281. }
  282. /**
  283. * Function gen_arc
  284. * generates an arc using arc approximation by lines:
  285. * Center aCenter
  286. * Angle "angle" (in 0.1 deg)
  287. * @param aBuffer = a buffer to store points.
  288. * @param aStartPoint = starting point of arc.
  289. * @param aCenter = arc centre.
  290. * @param a_ArcAngle = arc length in 0.1 degrees.
  291. */
  292. static void gen_arc( std::vector <wxPoint>& aBuffer,
  293. wxPoint aStartPoint,
  294. wxPoint aCenter,
  295. int a_ArcAngle )
  296. {
  297. #define SEGM_COUNT_PER_360DEG 16
  298. wxPoint first_point = aStartPoint - aCenter;
  299. int seg_count = ( ( abs( a_ArcAngle ) ) * SEGM_COUNT_PER_360DEG ) / 3600;
  300. if( seg_count == 0 )
  301. seg_count = 1;
  302. double increment_angle = (double) a_ArcAngle * M_PI / 1800 / seg_count;
  303. // Creates nb_seg point to approximate arc by segments:
  304. for( int ii = 1; ii <= seg_count; ii++ )
  305. {
  306. double rot_angle = increment_angle * ii;
  307. double fcos = cos( rot_angle );
  308. double fsin = sin( rot_angle );
  309. wxPoint currpt;
  310. // Rotate current point:
  311. currpt.x = KiROUND( ( first_point.x * fcos + first_point.y * fsin ) );
  312. currpt.y = KiROUND( ( first_point.y * fcos - first_point.x * fsin ) );
  313. wxPoint corner = aCenter + currpt;
  314. aBuffer.push_back( corner );
  315. }
  316. }
  317. /**
  318. * Function BuildCornersList_S_Shape
  319. * Create a path like a S-shaped coil
  320. * @param aBuffer = a buffer where to store points (ends of segments)
  321. * @param aStartPoint = starting point of the path
  322. * @param aEndPoint = ending point of the path
  323. * @param aLength = full length of the path
  324. * @param aWidth = segment width
  325. */
  326. int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
  327. wxPoint aStartPoint, wxPoint aEndPoint,
  328. int aLength, int aWidth )
  329. {
  330. /* We must determine:
  331. * segm_count = number of segments perpendicular to the direction
  332. * segm_len = length of a strand
  333. * radius = radius of rounded parts of the coil
  334. * stubs_len = length of the 2 stubs( segments parallel to the direction)
  335. * connecting the start point to the start point of the S shape
  336. * and the ending point to the end point of the S shape
  337. * The equations are (assuming the area size of the entire shape is Size:
  338. * Size.x = 2 * radius + segm_len
  339. * Size.y = (segm_count + 2 ) * 2 * radius + 2 * stubs_len
  340. * s_inductor_pattern.m_length = 2 * delta // connections to the coil
  341. * + (segm_count-2) * segm_len // length of the strands except 1st and last
  342. * + (segm_count) * (PI * radius) // length of rounded
  343. * segm_len + / 2 - radius * 2) // length of 1st and last bit
  344. *
  345. * The constraints are:
  346. * segm_count >= 2
  347. * radius < m_Size.x
  348. * Size.y = (radius * 4) + (2 * stubs_len)
  349. * segm_len > radius * 2
  350. *
  351. * The calculation is conducted in the following way:
  352. * first:
  353. * segm_count = 2
  354. * radius = 4 * Size.x (arbitrarily fixed value)
  355. * Then:
  356. * Increasing the number of segments to the desired length
  357. * (radius decreases if necessary)
  358. */
  359. wxSize size;
  360. // This scale factor adjusts the arc length to handle
  361. // the arc to segment approximation.
  362. // because we use SEGM_COUNT_PER_360DEG segment to approximate a circle,
  363. // the trace len must be corrected when calculated using arcs
  364. // this factor adjust calculations and must be changed if SEGM_COUNT_PER_360DEG is modified
  365. // because trace using segment is shorter the corresponding arc
  366. // ADJUST_SIZE is the ratio between tline len and the arc len for an arc
  367. // of 360/ADJUST_SIZE angle
  368. #define ADJUST_SIZE 0.988
  369. wxPoint pt = aEndPoint - aStartPoint;
  370. double angle = -ArcTangente( pt.y, pt.x );
  371. int min_len = KiROUND( EuclideanNorm( pt ) );
  372. int segm_len = 0; // length of segments
  373. int full_len; // full len of shape (sum of length of all segments + arcs)
  374. /* Note: calculations are made for a vertical coil (more easy calculations)
  375. * and after points are rotated to their actual position
  376. * So the main direction is the Y axis.
  377. * the 2 stubs are on the Y axis
  378. * the others segments are parallel to the X axis.
  379. */
  380. // Calculate the size of area (for a vertical shape)
  381. size.x = min_len / 2;
  382. size.y = min_len;
  383. // Choose a reasonable starting value for the radius of the arcs.
  384. int radius = std::min( aWidth * 5, size.x / 4 );
  385. int segm_count; // number of full len segments
  386. // the half size segments (first and last segment) are not counted here
  387. int stubs_len = 0; // length of first or last segment (half size of others segments)
  388. for( segm_count = 0; ; segm_count++ )
  389. {
  390. stubs_len = ( size.y - ( radius * 2 * (segm_count + 2 ) ) ) / 2;
  391. if( stubs_len < size.y / 10 ) // Reduce radius.
  392. {
  393. stubs_len = size.y / 10;
  394. radius = ( size.y - (2 * stubs_len) ) / ( 2 * (segm_count + 2) );
  395. if( radius < aWidth ) // Radius too small.
  396. {
  397. // Unable to create line: Requested length value is too large for room
  398. return 0;
  399. }
  400. }
  401. segm_len = size.x - ( radius * 2 );
  402. full_len = 2 * stubs_len; // Length of coil connections.
  403. full_len += segm_len * segm_count; // Length of full length segments.
  404. full_len += KiROUND( ( segm_count + 2 ) * M_PI * ADJUST_SIZE * radius ); // Ard arcs len
  405. full_len += segm_len - (2 * radius); // Length of first and last segments
  406. // (half size segments len = segm_len/2 - radius).
  407. if( full_len >= aLength )
  408. break;
  409. }
  410. // Adjust len by adjusting segm_len:
  411. int delta_size = full_len - aLength;
  412. // reduce len of the segm_count segments + 2 half size segments (= 1 full size segment)
  413. segm_len -= delta_size / (segm_count + 1);
  414. // Generate first line (the first stub) and first arc (90 deg arc)
  415. pt = aStartPoint;
  416. aBuffer.push_back( pt );
  417. pt.y += stubs_len;
  418. aBuffer.push_back( pt );
  419. wxPoint centre = pt;
  420. centre.x -= radius;
  421. gen_arc( aBuffer, pt, centre, -900 );
  422. pt = aBuffer.back();
  423. int half_size_seg_len = segm_len / 2 - radius;
  424. if( half_size_seg_len )
  425. {
  426. pt.x -= half_size_seg_len;
  427. aBuffer.push_back( pt );
  428. }
  429. // Create shape.
  430. int ii;
  431. int sign = 1;
  432. segm_count += 1; // increase segm_count to create the last half_size segment
  433. for( ii = 0; ii < segm_count; ii++ )
  434. {
  435. int arc_angle;
  436. if( ii & 1 ) // odd order arcs are greater than 0
  437. sign = -1;
  438. else
  439. sign = 1;
  440. arc_angle = 1800 * sign;
  441. centre = pt;
  442. centre.y += radius;
  443. gen_arc( aBuffer, pt, centre, arc_angle );
  444. pt = aBuffer.back();
  445. pt.x += segm_len * sign;
  446. aBuffer.push_back( pt );
  447. }
  448. // The last point is false:
  449. // it is the end of a full size segment, but must be
  450. // the end of the second half_size segment. Change it.
  451. sign *= -1;
  452. aBuffer.back().x = aStartPoint.x + radius * sign;
  453. // create last arc
  454. pt = aBuffer.back();
  455. centre = pt;
  456. centre.y += radius;
  457. gen_arc( aBuffer, pt, centre, 900 * sign );
  458. aBuffer.back();
  459. // Rotate point
  460. angle += 900;
  461. for( unsigned jj = 0; jj < aBuffer.size(); jj++ )
  462. {
  463. RotatePoint( &aBuffer[jj].x, &aBuffer[jj].y, aStartPoint.x, aStartPoint.y, angle );
  464. }
  465. // push last point (end point)
  466. aBuffer.push_back( aEndPoint );
  467. return 1;
  468. }
  469. MODULE* PCB_EDIT_FRAME::CreateMuWaveBaseFootprint( const wxString& aValue,
  470. int aTextSize, int aPadCount )
  471. {
  472. MODULE* module = CreateNewModule( aValue );
  473. if( aTextSize > 0 )
  474. {
  475. module->Reference().SetTextSize( wxSize( aTextSize, aTextSize ) );
  476. module->Reference().SetThickness( aTextSize/5 );
  477. module->Value().SetTextSize( wxSize( aTextSize, aTextSize ) );
  478. module->Value().SetThickness( aTextSize/5 );
  479. }
  480. // Create 2 pads used in gaps and stubs. The gap is between these 2 pads
  481. // the stub is the pad 2
  482. wxString Line;
  483. int pad_num = 1;
  484. while( aPadCount-- )
  485. {
  486. D_PAD* pad = new D_PAD( module );
  487. module->Pads().PushFront( pad );
  488. int tw = GetDesignSettings().GetCurrentTrackWidth();
  489. pad->SetSize( wxSize( tw, tw ) );
  490. pad->SetPosition( module->GetPosition() );
  491. pad->SetShape( PAD_SHAPE_RECT );
  492. pad->SetAttribute( PAD_ATTRIB_SMD );
  493. pad->SetLayerSet( F_Cu );
  494. Line.Printf( wxT( "%d" ), pad_num );
  495. pad->SetPadName( Line );
  496. pad_num++;
  497. }
  498. return module;
  499. }
  500. MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
  501. {
  502. int oX;
  503. D_PAD* pad;
  504. MODULE* module;
  505. wxString msg, cmp_name;
  506. int pad_count = 2;
  507. int angle = 0;
  508. // Ref and value text size (O = use board default value.
  509. // will be set to a value depending on the footprint size, if possible
  510. int text_size = 0;
  511. // Enter the size of the gap or stub
  512. int gap_size = GetDesignSettings().GetCurrentTrackWidth();
  513. switch( shape_type )
  514. {
  515. case 0:
  516. msg = _( "Gap" );
  517. cmp_name = wxT( "muwave_gap" );
  518. text_size = gap_size;
  519. break;
  520. case 1:
  521. msg = _( "Stub" );
  522. cmp_name = wxT( "muwave_stub" );
  523. text_size = gap_size;
  524. pad_count = 2;
  525. break;
  526. case 2:
  527. msg = _( "Arc Stub" );
  528. cmp_name = wxT( "muwave_arcstub" );
  529. pad_count = 1;
  530. break;
  531. default:
  532. msg = wxT( "???" );
  533. break;
  534. }
  535. wxString value = StringFromValue( g_UserUnit, gap_size );
  536. wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value );
  537. if( dlg.ShowModal() != wxID_OK )
  538. {
  539. m_canvas->MoveCursorToCrossHair();
  540. return NULL; // cancelled by user
  541. }
  542. value = dlg.GetValue();
  543. gap_size = ValueFromString( g_UserUnit, value );
  544. bool abort = false;
  545. if( shape_type == 2 )
  546. {
  547. double fcoeff = 10.0, fval;
  548. msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
  549. wxTextEntryDialog angledlg( this, _( "Angle in degrees:" ),
  550. _( "Create microwave module" ), msg );
  551. if( angledlg.ShowModal() != wxID_OK )
  552. {
  553. m_canvas->MoveCursorToCrossHair();
  554. return NULL; // cancelled by user
  555. }
  556. msg = angledlg.GetValue();
  557. if( !msg.ToDouble( &fval ) )
  558. {
  559. DisplayError( this, _( "Incorrect number, abort" ) );
  560. abort = true;
  561. }
  562. angle = std::abs( KiROUND( fval * fcoeff ) );
  563. if( angle > 1800 )
  564. angle = 1800;
  565. }
  566. if( abort )
  567. {
  568. m_canvas->MoveCursorToCrossHair();
  569. return NULL;
  570. }
  571. module = CreateMuWaveBaseFootprint( cmp_name, text_size, pad_count );
  572. pad = module->Pads();
  573. switch( shape_type )
  574. {
  575. case 0: //Gap :
  576. oX = -( gap_size + pad->GetSize().x ) / 2;
  577. pad->SetX0( oX );
  578. pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
  579. pad = pad->Next();
  580. pad->SetX0( oX + gap_size + pad->GetSize().x );
  581. pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
  582. break;
  583. case 1: //Stub :
  584. pad->SetPadName( wxT( "1" ) );
  585. pad = pad->Next();
  586. pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 );
  587. pad->SetSize( wxSize( pad->GetSize().x, gap_size ) );
  588. pad->SetY( pad->GetPos0().y + pad->GetPosition().y );
  589. break;
  590. case 2: // Arc Stub created by a polygonal approach:
  591. {
  592. EDGE_MODULE* edge = new EDGE_MODULE( module );
  593. module->GraphicalItems().PushFront( edge );
  594. edge->SetShape( S_POLYGON );
  595. edge->SetLayer( F_Cu );
  596. int numPoints = (angle / 50) + 3; // Note: angles are in 0.1 degrees
  597. std::vector<wxPoint>& polyPoints = edge->GetPolyPoints();
  598. polyPoints.reserve( numPoints );
  599. edge->m_Start0.y = -pad->GetSize().y / 2;
  600. polyPoints.push_back( wxPoint( 0, 0 ) );
  601. int theta = -angle / 2;
  602. for( int ii = 1; ii<numPoints - 1; ii++ )
  603. {
  604. wxPoint pt( 0, -gap_size );
  605. RotatePoint( &pt.x, &pt.y, theta );
  606. polyPoints.push_back( pt );
  607. theta += 50;
  608. if( theta > angle / 2 )
  609. theta = angle / 2;
  610. }
  611. // Close the polygon:
  612. polyPoints.push_back( polyPoints[0] );
  613. }
  614. break;
  615. default:
  616. break;
  617. }
  618. module->CalculateBoundingBox();
  619. GetBoard()->m_Status_Pcb = 0;
  620. OnModify();
  621. return module;
  622. }
  623. /**************** Polygon Shapes ***********************/
  624. enum id_mw_cmd {
  625. ID_READ_SHAPE_FILE = 1000
  626. };
  627. /* Setting polynomial form parameters
  628. */
  629. class MWAVE_POLYGONAL_SHAPE_DLG : public wxDialog
  630. {
  631. private:
  632. PCB_EDIT_FRAME* m_Parent;
  633. wxRadioBox* m_ShapeOptionCtrl;
  634. EDA_SIZE_CTRL* m_SizeCtrl;
  635. public:
  636. MWAVE_POLYGONAL_SHAPE_DLG( PCB_EDIT_FRAME* parent, const wxPoint& pos );
  637. ~MWAVE_POLYGONAL_SHAPE_DLG() { };
  638. private:
  639. void OnOkClick( wxCommandEvent& event );
  640. void OnCancelClick( wxCommandEvent& event );
  641. /**
  642. * Function ReadDataShapeDescr
  643. * read a description shape file
  644. * File format is
  645. * Unit=MM
  646. * XScale=271.501
  647. * YScale=1.00133
  648. *
  649. * $COORD
  650. * 0 0.6112600148417837
  651. * 0.001851851851851852 0.6104800531118608
  652. * ....
  653. * $ENDCOORD
  654. *
  655. * Each line is the X Y coord (normalized units from 0 to 1)
  656. */
  657. void ReadDataShapeDescr( wxCommandEvent& event );
  658. void AcceptOptions( wxCommandEvent& event );
  659. DECLARE_EVENT_TABLE()
  660. };
  661. BEGIN_EVENT_TABLE( MWAVE_POLYGONAL_SHAPE_DLG, wxDialog )
  662. EVT_BUTTON( wxID_OK, MWAVE_POLYGONAL_SHAPE_DLG::OnOkClick )
  663. EVT_BUTTON( wxID_CANCEL, MWAVE_POLYGONAL_SHAPE_DLG::OnCancelClick )
  664. EVT_BUTTON( ID_READ_SHAPE_FILE, MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr )
  665. END_EVENT_TABLE()
  666. MWAVE_POLYGONAL_SHAPE_DLG::MWAVE_POLYGONAL_SHAPE_DLG( PCB_EDIT_FRAME* parent,
  667. const wxPoint& framepos ) :
  668. wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ),
  669. wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
  670. {
  671. m_Parent = parent;
  672. PolyEdges.clear();
  673. wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  674. SetSizer( MainBoxSizer );
  675. wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
  676. wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
  677. MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
  678. MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  679. wxButton* Button = new wxButton( this, wxID_OK, _( "OK" ) );
  680. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  681. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  682. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  683. Button = new wxButton( this, ID_READ_SHAPE_FILE,
  684. _( "Read Shape Description File..." ) );
  685. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  686. wxString shapelist[3] =
  687. {
  688. _( "Normal" ), _( "Symmetrical" ), _( "Mirrored" )
  689. };
  690. m_ShapeOptionCtrl = new wxRadioBox( this, -1, _( "Shape Option" ),
  691. wxDefaultPosition, wxDefaultSize, 3,
  692. shapelist, 1,
  693. wxRA_SPECIFY_COLS );
  694. LeftBoxSizer->Add( m_ShapeOptionCtrl, 0, wxGROW | wxALL, 5 );
  695. m_SizeCtrl = new EDA_SIZE_CTRL( this, _( "Size" ), ShapeSize, g_UserUnit, LeftBoxSizer );
  696. GetSizer()->SetSizeHints( this );
  697. }
  698. void MWAVE_POLYGONAL_SHAPE_DLG::OnCancelClick( wxCommandEvent& event )
  699. {
  700. PolyEdges.clear();
  701. EndModal( wxID_CANCEL );
  702. }
  703. void MWAVE_POLYGONAL_SHAPE_DLG::OnOkClick( wxCommandEvent& event )
  704. {
  705. ShapeSize = m_SizeCtrl->GetValue();
  706. PolyShapeType = m_ShapeOptionCtrl->GetSelection();
  707. EndModal( wxID_OK );
  708. }
  709. void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
  710. {
  711. static wxString lastpath; // To remember the last open path during a session
  712. wxString mask = wxT( "*.*" );
  713. wxString FullFileName = EDA_FILE_SELECTOR( _( "Read descr shape file" ),
  714. lastpath, FullFileName,
  715. wxEmptyString, mask,
  716. this, wxFD_OPEN, true );
  717. if( FullFileName.IsEmpty() )
  718. return;
  719. wxFileName fn( FullFileName );
  720. lastpath = fn.GetPath();
  721. PolyEdges.clear();
  722. FILE* File = wxFopen( FullFileName, wxT( "rt" ) );
  723. if( File == NULL )
  724. {
  725. DisplayError( this, _( "File not found" ) );
  726. return;
  727. }
  728. double unitconv = IU_PER_MM;
  729. ShapeScaleX = ShapeScaleY = 1.0;
  730. FILE_LINE_READER fileReader( File, FullFileName );
  731. FILTER_READER reader( fileReader );
  732. LOCALE_IO toggle;
  733. while( reader.ReadLine() )
  734. {
  735. char* Line = reader.Line();
  736. char* param1 = strtok( Line, " =\n\r" );
  737. char* param2 = strtok( NULL, " \t\n\r" );
  738. if( strncasecmp( param1, "Unit", 4 ) == 0 )
  739. {
  740. if( strncasecmp( param2, "inch", 4 ) == 0 )
  741. unitconv = IU_PER_MILS*1000;
  742. if( strncasecmp( param2, "mm", 2 ) == 0 )
  743. unitconv = IU_PER_MM;
  744. }
  745. if( strncasecmp( param1, "$ENDCOORD", 8 ) == 0 )
  746. break;
  747. if( strncasecmp( param1, "$COORD", 6 ) == 0 )
  748. {
  749. while( reader.ReadLine() )
  750. {
  751. Line = reader.Line();
  752. param1 = strtok( Line, " \t\n\r" );
  753. param2 = strtok( NULL, " \t\n\r" );
  754. if( strncasecmp( param1, "$ENDCOORD", 8 ) == 0 )
  755. break;
  756. wxRealPoint coord( atof( param1 ), atof( param2 ) );
  757. PolyEdges.push_back( coord );
  758. }
  759. }
  760. if( strncasecmp( Line, "XScale", 6 ) == 0 )
  761. ShapeScaleX = atof( param2 );
  762. if( strncasecmp( Line, "YScale", 6 ) == 0 )
  763. ShapeScaleY = atof( param2 );
  764. }
  765. ShapeScaleX *= unitconv;
  766. ShapeScaleY *= unitconv;
  767. m_SizeCtrl->SetValue( (int) ShapeScaleX, (int) ShapeScaleY );
  768. }
  769. MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
  770. {
  771. D_PAD* pad1, * pad2;
  772. MODULE* module;
  773. wxString cmp_name;
  774. int pad_count = 2;
  775. EDGE_MODULE* edge;
  776. MWAVE_POLYGONAL_SHAPE_DLG dlg( this, wxPoint( -1, -1 ) );
  777. int ret = dlg.ShowModal();
  778. m_canvas->MoveCursorToCrossHair();
  779. if( ret != wxID_OK )
  780. {
  781. PolyEdges.clear();
  782. return NULL;
  783. }
  784. if( PolyShapeType == 2 ) // mirrored
  785. ShapeScaleY = -ShapeScaleY;
  786. ShapeSize.x = KiROUND( ShapeScaleX );
  787. ShapeSize.y = KiROUND( ShapeScaleY );
  788. if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
  789. {
  790. DisplayError( this, _( "Shape has a null size!" ) );
  791. return NULL;
  792. }
  793. if( PolyEdges.size() == 0 )
  794. {
  795. DisplayError( this, _( "Shape has no points!" ) );
  796. return NULL;
  797. }
  798. cmp_name = wxT( "muwave_polygon" );
  799. // Create a footprint with 2 pads, orientation = 0, pos 0
  800. module = CreateMuWaveBaseFootprint( cmp_name, 0, pad_count );
  801. // We try to place the footprint anchor to the middle of the shape len
  802. wxPoint offset;
  803. offset.x = -ShapeSize.x / 2;
  804. pad1 = module->Pads();
  805. pad1->SetX0( offset.x );
  806. pad1->SetX( pad1->GetPos0().x );
  807. pad2 = pad1->Next();
  808. pad2->SetX0( offset.x + ShapeSize.x );
  809. pad2->SetX( pad2->GetPos0().x );
  810. // Add a polygonal edge (corners will be added later) on copper layer
  811. edge = new EDGE_MODULE( module );
  812. edge->SetShape( S_POLYGON );
  813. edge->SetLayer( F_Cu );
  814. module->GraphicalItems().PushFront( edge );
  815. // Get the corner buffer of the polygonal edge
  816. std::vector<wxPoint>& polyPoints = edge->GetPolyPoints();
  817. polyPoints.reserve( PolyEdges.size() + 2 );
  818. // Init start point coord:
  819. polyPoints.push_back( wxPoint( offset.x, 0 ) );
  820. wxPoint last_coordinate;
  821. for( unsigned ii = 0; ii < PolyEdges.size(); ii++ ) // Copy points
  822. {
  823. last_coordinate.x = KiROUND( PolyEdges[ii].x * ShapeScaleX );
  824. last_coordinate.y = -KiROUND( PolyEdges[ii].y * ShapeScaleY );
  825. last_coordinate += offset;
  826. polyPoints.push_back( last_coordinate );
  827. }
  828. // finish the polygonal shape
  829. if( last_coordinate.y != 0 )
  830. polyPoints.push_back( wxPoint( last_coordinate.x, 0 ) );
  831. switch( PolyShapeType )
  832. {
  833. case 0: // shape from file
  834. case 2: // shape from file, mirrored (the mirror is already done)
  835. break;
  836. case 1: // Symmetric shape: add the symmetric (mirrored) shape
  837. for( int ndx = polyPoints.size() - 1; ndx >= 0; --ndx )
  838. {
  839. wxPoint pt = polyPoints[ndx];
  840. pt.y = -pt.y; // mirror about X axis
  841. polyPoints.push_back( pt );
  842. }
  843. break;
  844. }
  845. PolyEdges.clear();
  846. module->CalculateBoundingBox();
  847. GetBoard()->m_Status_Pcb = 0;
  848. OnModify();
  849. return module;
  850. }
  851. void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* aModule )
  852. {
  853. int gap_size, oX;
  854. D_PAD* pad, * next_pad;
  855. wxString msg;
  856. if( aModule == NULL )
  857. return;
  858. // Test if module is a gap type (name begins with GAP, and has 2 pads).
  859. msg = aModule->GetReference().Left( 3 );
  860. if( msg != wxT( "GAP" ) )
  861. return;
  862. pad = aModule->Pads();
  863. if( pad == NULL )
  864. {
  865. DisplayError( this, _( "No pad for this footprint" ) );
  866. return;
  867. }
  868. next_pad = pad->Next();
  869. if( next_pad == NULL )
  870. {
  871. DisplayError( this, _( "Only one pad for this footprint" ) );
  872. return;
  873. }
  874. aModule->Draw( m_canvas, DC, GR_XOR );
  875. // Calculate the current dimension.
  876. gap_size = next_pad->GetPos0().x - pad->GetPos0().x - pad->GetSize().x;
  877. // Entrer the desired length of the gap.
  878. msg = StringFromValue( g_UserUnit, gap_size );
  879. wxTextEntryDialog dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg );
  880. if( dlg.ShowModal() != wxID_OK )
  881. return; // cancelled by user
  882. msg = dlg.GetValue();
  883. gap_size = ValueFromString( g_UserUnit, msg );
  884. // Updating sizes of pads forming the gap.
  885. int tw = GetDesignSettings().GetCurrentTrackWidth();
  886. pad->SetSize( wxSize( tw, tw ) );
  887. pad->SetY0( 0 );
  888. oX = -( gap_size + pad->GetSize().x ) / 2;
  889. pad->SetX0( oX );
  890. wxPoint padpos = pad->GetPos0() + aModule->GetPosition();
  891. RotatePoint( &padpos.x, &padpos.y,
  892. aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
  893. pad->SetPosition( padpos );
  894. tw = GetDesignSettings().GetCurrentTrackWidth();
  895. next_pad->SetSize( wxSize( tw, tw ) );
  896. next_pad->SetY0( 0 );
  897. next_pad->SetX0( oX + gap_size + next_pad->GetSize().x );
  898. padpos = next_pad->GetPos0() + aModule->GetPosition();
  899. RotatePoint( &padpos.x, &padpos.y,
  900. aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
  901. next_pad->SetPosition( padpos );
  902. aModule->Draw( m_canvas, DC, GR_OR );
  903. }