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.

1135 lines
32 KiB

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
16 years ago
16 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
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
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
16 years ago
16 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
16 years ago
16 years ago
16 years ago
16 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
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
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
16 years ago
16 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
  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. * @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 <pcbcommon.h>
  42. #include <macros.h>
  43. #include <base_units.h>
  44. #include <class_board.h>
  45. #include <class_module.h>
  46. #include <class_edge_mod.h>
  47. #include <pcbnew.h>
  48. #define COEFF_COUNT 6
  49. static std::vector< double > PolyEdges;
  50. static double ShapeScaleX, ShapeScaleY;
  51. static wxSize ShapeSize;
  52. static int PolyShapeType;
  53. static void Exit_Self( EDA_DRAW_PANEL* Panel, wxDC* DC );
  54. static void gen_arc( std::vector <wxPoint>& aBuffer,
  55. wxPoint aStartPoint,
  56. wxPoint aCenter,
  57. int a_ArcAngle );
  58. static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* apanel,
  59. wxDC* aDC,
  60. const wxPoint& aPosition,
  61. bool aErase );
  62. int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
  63. wxPoint aStartPoint, wxPoint aEndPoint,
  64. int aLength, int aWidth );
  65. class SELFPCB
  66. {
  67. public:
  68. int forme; // Shape: coil, spiral, etc ..
  69. wxPoint m_Start;
  70. wxPoint m_End;
  71. wxSize m_Size;
  72. int lng; // Trace length.
  73. int m_Width; // Trace width.
  74. };
  75. static SELFPCB Mself;
  76. static int Self_On;
  77. /* This function shows on screen the bounding box of the inductor that will be
  78. * created at the end of the build inductor process
  79. */
  80. static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  81. const wxPoint& aPosition, bool aErase )
  82. {
  83. /* Calculate the orientation and size of the box containing the inductor:
  84. * the box is a rectangle with height = lenght/2
  85. * the shape is defined by a rectangle, nor necessary horizontal or vertical
  86. */
  87. GRSetDrawMode( aDC, GR_XOR );
  88. wxPoint poly[5];
  89. wxPoint pt = Mself.m_End - Mself.m_Start;
  90. double angle = -ArcTangente( pt.y, pt.x );
  91. int len = KiROUND( EuclideanNorm( pt ) );
  92. // calculate corners
  93. pt.x = 0; pt.y = len / 4;
  94. RotatePoint( &pt, angle );
  95. poly[0] = Mself.m_Start + pt;
  96. poly[1] = Mself.m_End + pt;
  97. pt.x = 0; pt.y = -len / 4;
  98. RotatePoint( &pt, angle );
  99. poly[2] = Mself.m_End + pt;
  100. poly[3] = Mself.m_Start + pt;
  101. poly[4] = poly[0];
  102. if( aErase )
  103. {
  104. GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
  105. }
  106. Mself.m_End = aPanel->GetParent()->GetCrossHairPosition();
  107. pt = Mself.m_End - Mself.m_Start;
  108. angle = -ArcTangente( pt.y, pt.x );
  109. len = KiROUND( EuclideanNorm( pt ) );
  110. // calculate new corners
  111. pt.x = 0; pt.y = len / 4;
  112. RotatePoint( &pt, angle );
  113. poly[0] = Mself.m_Start + pt;
  114. poly[1] = Mself.m_End + pt;
  115. pt.x = 0; pt.y = -len / 4;
  116. RotatePoint( &pt, angle );
  117. poly[2] = Mself.m_End + pt;
  118. poly[3] = Mself.m_Start + pt;
  119. poly[4] = poly[0];
  120. GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
  121. }
  122. void Exit_Self( EDA_DRAW_PANEL* Panel, wxDC* DC )
  123. {
  124. if( Self_On )
  125. {
  126. Self_On = 0;
  127. Panel->CallMouseCapture( DC, wxDefaultPosition, 0 );
  128. }
  129. }
  130. void PCB_EDIT_FRAME::Begin_Self( wxDC* DC )
  131. {
  132. if( Self_On )
  133. {
  134. Genere_Self( DC );
  135. return;
  136. }
  137. Mself.m_Start = GetCrossHairPosition();
  138. Mself.m_End = Mself.m_Start;
  139. Self_On = 1;
  140. // Update the initial coordinates.
  141. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  142. UpdateStatusBar();
  143. m_canvas->SetMouseCapture( ShowBoundingBoxMicroWaveInductor, Exit_Self );
  144. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  145. }
  146. MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
  147. {
  148. D_PAD* pad;
  149. int ll;
  150. wxString msg;
  151. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  152. m_canvas->SetMouseCapture( NULL, NULL );
  153. if( Self_On == 0 )
  154. {
  155. DisplayError( this, wxT( "Starting point not init.." ) );
  156. return NULL;
  157. }
  158. Self_On = 0;
  159. Mself.m_End = GetCrossHairPosition();
  160. wxPoint pt = Mself.m_End - Mself.m_Start;
  161. int min_len = KiROUND( EuclideanNorm( pt ) );
  162. Mself.lng = min_len;
  163. // Enter the desired length.
  164. msg = StringFromValue( g_UserUnit, Mself.lng );
  165. wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg );
  166. if( dlg.ShowModal() != wxID_OK )
  167. return NULL; // canceled by user
  168. msg = dlg.GetValue();
  169. Mself.lng = ValueFromString( g_UserUnit, msg );
  170. // Control values (ii = minimum length)
  171. if( Mself.lng < min_len )
  172. {
  173. DisplayError( this, _( "Requested length < minimum length" ) );
  174. return NULL;
  175. }
  176. // Calculate the elements.
  177. Mself.m_Width = GetBoard()->GetCurrentTrackWidth();
  178. std::vector <wxPoint> buffer;
  179. ll = BuildCornersList_S_Shape( buffer, Mself.m_Start, Mself.m_End, Mself.lng, Mself.m_Width );
  180. if( !ll )
  181. {
  182. DisplayError( this, _( "Requested length too large" ) );
  183. return NULL;
  184. }
  185. // Generate module.
  186. MODULE* module;
  187. module = Create_1_Module( wxEmptyString );
  188. if( module == NULL )
  189. return NULL;
  190. // here the module is already in the BOARD, Create_1_Module() does that.
  191. module->SetFPID( FPID( std::string( "MuSelf" ) ) );
  192. module->SetAttributes( MOD_VIRTUAL | MOD_CMS );
  193. module->ClearFlags();
  194. module->SetPosition( Mself.m_End );
  195. // Generate segments
  196. for( unsigned jj = 1; jj < buffer.size(); jj++ )
  197. {
  198. EDGE_MODULE* PtSegm;
  199. PtSegm = new EDGE_MODULE( module );
  200. PtSegm->SetStart( buffer[jj - 1] );
  201. PtSegm->SetEnd( buffer[jj] );
  202. PtSegm->SetWidth( Mself.m_Width );
  203. PtSegm->SetLayer( module->GetLayer() );
  204. PtSegm->SetShape( S_SEGMENT );
  205. PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() );
  206. PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() );
  207. module->GraphicalItems().PushBack( PtSegm );
  208. }
  209. // Place a pad on each end of coil.
  210. pad = new D_PAD( module );
  211. module->Pads().PushFront( pad );
  212. pad->SetPadName( wxT( "1" ) );
  213. pad->SetPosition( Mself.m_End );
  214. pad->SetPos0( pad->GetPosition() - module->GetPosition() );
  215. pad->SetSize( wxSize( Mself.m_Width, Mself.m_Width ) );
  216. pad->SetLayerMask( GetLayerMask( module->GetLayer() ) );
  217. pad->SetAttribute( PAD_SMD );
  218. pad->SetShape( PAD_CIRCLE );
  219. D_PAD* newpad = new D_PAD( *pad );
  220. module->Pads().Insert( newpad, pad->Next() );
  221. pad = newpad;
  222. pad->SetPadName( wxT( "2" ) );
  223. pad->SetPosition( Mself.m_Start );
  224. pad->SetPos0( pad->GetPosition() - module->GetPosition() );
  225. // Modify text positions.
  226. SetMsgPanel( module );
  227. wxPoint refPos( ( Mself.m_Start.x + Mself.m_End.x ) / 2,
  228. ( Mself.m_Start.y + Mself.m_End.y ) / 2 );
  229. wxPoint valPos = refPos;
  230. refPos.y -= module->Reference().GetSize().y;
  231. module->Reference().SetTextPosition( refPos );
  232. valPos.y += module->Value().GetSize().y;
  233. module->Value().SetTextPosition( valPos );
  234. module->Reference().SetPos0( module->Reference().GetTextPosition() - module->GetPosition() );
  235. module->Value().SetPos0( module->Value().GetTextPosition() - module->GetPosition() );
  236. module->CalculateBoundingBox();
  237. module->Draw( m_canvas, DC, GR_OR );
  238. return module;
  239. }
  240. /**
  241. * Function gen_arc
  242. * generates an arc using arc approximation by lines:
  243. * Center aCenter
  244. * Angle "angle" (in 0.1 deg)
  245. * @param aBuffer = a buffer to store points.
  246. * @param aStartPoint = starting point of arc.
  247. * @param aCenter = arc centre.
  248. * @param a_ArcAngle = arc length in 0.1 degrees.
  249. */
  250. static void gen_arc( std::vector <wxPoint>& aBuffer,
  251. wxPoint aStartPoint,
  252. wxPoint aCenter,
  253. int a_ArcAngle )
  254. {
  255. #define SEGM_COUNT_PER_360DEG 16
  256. wxPoint first_point = aStartPoint - aCenter;
  257. int seg_count = ( ( abs( a_ArcAngle ) ) * SEGM_COUNT_PER_360DEG ) / 3600;
  258. if( seg_count == 0 )
  259. seg_count = 1;
  260. double increment_angle = (double) a_ArcAngle * M_PI / 1800 / seg_count;
  261. // Creates nb_seg point to approximate arc by segments:
  262. for( int ii = 1; ii <= seg_count; ii++ )
  263. {
  264. double rot_angle = increment_angle * ii;
  265. double fcos = cos( rot_angle );
  266. double fsin = sin( rot_angle );
  267. wxPoint currpt;
  268. // Rotate current point:
  269. currpt.x = KiROUND( ( first_point.x * fcos + first_point.y * fsin ) );
  270. currpt.y = KiROUND( ( first_point.y * fcos - first_point.x * fsin ) );
  271. wxPoint corner = aCenter + currpt;
  272. aBuffer.push_back( corner );
  273. }
  274. }
  275. /**
  276. * Function BuildCornersList_S_Shape
  277. * Create a path like a S-shaped coil
  278. * @param aBuffer = a buffer where to store points (ends of segments)
  279. * @param aStartPoint = starting point of the path
  280. * @param aEndPoint = ending point of the path
  281. * @param aLength = full lenght of the path
  282. * @param aWidth = segment width
  283. */
  284. int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
  285. wxPoint aStartPoint, wxPoint aEndPoint,
  286. int aLength, int aWidth )
  287. {
  288. /* We must determine:
  289. * segm_count = number of segments perpendicular to the direction
  290. * segm_len = length of a strand
  291. * radius = radius of rounded parts of the coil
  292. * stubs_len = length of the 2 stubs( segments parallel to the direction)
  293. * connecting the start point to the start point of the S shape
  294. * and the ending point to the end point of the S shape
  295. * The equations are (assuming the area size of the entire shape is Size:
  296. * Size.x = 2 * radius + segm_len
  297. * Size.y = (segm_count + 2 ) * 2 * radius + 2 * stubs_len
  298. * Mself.lng = 2 * delta // connections to the coil
  299. * + (segm_count-2) * segm_len // length of the strands except 1st and last
  300. * + (segm_count) * (PI * radius) // length of rounded
  301. * segm_len + / 2 - radius * 2) // length of 1st and last bit
  302. *
  303. * The constraints are:
  304. * segm_count >= 2
  305. * radius < m_Size.x
  306. * Size.y = (radius * 4) + (2 * stubs_len)
  307. * segm_len > radius * 2
  308. *
  309. * The calculation is conducted in the following way:
  310. * first:
  311. * segm_count = 2
  312. * radius = 4 * Size.x (arbitrarily fixed value)
  313. * Then:
  314. * Increasing the number of segments to the desired length
  315. * (radius decreases if necessary)
  316. */
  317. wxSize size;
  318. // This scale factor adjusts the arc length to handle
  319. // the arc to segment approximation.
  320. // because we use SEGM_COUNT_PER_360DEG segment to approximate a circle,
  321. // the trace len must be corrected when calculated using arcs
  322. // this factor adjust calculations and must be changed if SEGM_COUNT_PER_360DEG is modified
  323. // because trace using segment is shorter the corresponding arc
  324. // ADJUST_SIZE is the ratio between tline len and the arc len for an arc
  325. // of 360/ADJUST_SIZE angle
  326. #define ADJUST_SIZE 0.988
  327. wxPoint pt = aEndPoint - aStartPoint;
  328. double angle = -ArcTangente( pt.y, pt.x );
  329. int min_len = KiROUND( EuclideanNorm( pt ) );
  330. int segm_len = 0; // length of segments
  331. int full_len; // full len of shape (sum of lenght of all segments + arcs)
  332. /* Note: calculations are made for a vertical coil (more easy calculations)
  333. * and after points are rotated to their actual position
  334. * So the main direction is the Y axis.
  335. * the 2 stubs are on the Y axis
  336. * the others segments are parallel to the X axis.
  337. */
  338. // Calculate the size of area (for a vertical shape)
  339. size.x = min_len / 2;
  340. size.y = min_len;
  341. // Choose a reasonable starting value for the radius of the arcs.
  342. int radius = std::min( aWidth * 5, size.x / 4 );
  343. int segm_count; // number of full len segments
  344. // the half size segments (first and last segment) are not counted here
  345. int stubs_len = 0; // lenght of first or last segment (half size of others segments)
  346. for( segm_count = 0; ; segm_count++ )
  347. {
  348. stubs_len = ( size.y - ( radius * 2 * (segm_count + 2 ) ) ) / 2;
  349. if( stubs_len < size.y / 10 ) // Reduce radius.
  350. {
  351. stubs_len = size.y / 10;
  352. radius = ( size.y - (2 * stubs_len) ) / ( 2 * (segm_count + 2) );
  353. if( radius < aWidth ) // Radius too small.
  354. {
  355. // Unable to create line: Requested length value is too large for room
  356. return 0;
  357. }
  358. }
  359. segm_len = size.x - ( radius * 2 );
  360. full_len = 2 * stubs_len; // Length of coil connections.
  361. full_len += segm_len * segm_count; // Length of full length segments.
  362. full_len += KiROUND( ( segm_count + 2 ) * M_PI * ADJUST_SIZE * radius ); // Ard arcs len
  363. full_len += segm_len - (2 * radius); // Length of first and last segments
  364. // (half size segments len = segm_len/2 - radius).
  365. if( full_len >= aLength )
  366. break;
  367. }
  368. // Adjust len by adjusting segm_len:
  369. int delta_size = full_len - aLength;
  370. // reduce len of the segm_count segments + 2 half size segments (= 1 full size segment)
  371. segm_len -= delta_size / (segm_count + 1);
  372. // Generate first line (the first stub) and first arc (90 deg arc)
  373. pt = aStartPoint;
  374. aBuffer.push_back( pt );
  375. pt.y += stubs_len;
  376. aBuffer.push_back( pt );
  377. wxPoint centre = pt;
  378. centre.x -= radius;
  379. gen_arc( aBuffer, pt, centre, -900 );
  380. pt = aBuffer.back();
  381. int half_size_seg_len = segm_len / 2 - radius;
  382. if( half_size_seg_len )
  383. {
  384. pt.x -= half_size_seg_len;
  385. aBuffer.push_back( pt );
  386. }
  387. // Create shape.
  388. int ii;
  389. int sign = 1;
  390. segm_count += 1; // increase segm_count to create the last half_size segment
  391. for( ii = 0; ii < segm_count; ii++ )
  392. {
  393. int arc_angle;
  394. if( ii & 1 ) // odd order arcs are greater than 0
  395. sign = -1;
  396. else
  397. sign = 1;
  398. arc_angle = 1800 * sign;
  399. centre = pt;
  400. centre.y += radius;
  401. gen_arc( aBuffer, pt, centre, arc_angle );
  402. pt = aBuffer.back();
  403. pt.x += segm_len * sign;
  404. aBuffer.push_back( pt );
  405. }
  406. // The last point is false:
  407. // it is the end of a full size segment, but must be
  408. // the end of the second half_size segment. Change it.
  409. sign *= -1;
  410. aBuffer.back().x = aStartPoint.x + radius * sign;
  411. // create last arc
  412. pt = aBuffer.back();
  413. centre = pt;
  414. centre.y += radius;
  415. gen_arc( aBuffer, pt, centre, 900 * sign ); pt = aBuffer.back();
  416. // Rotate point
  417. angle += 900;
  418. for( unsigned jj = 0; jj < aBuffer.size(); jj++ )
  419. {
  420. RotatePoint( &aBuffer[jj].x, &aBuffer[jj].y, aStartPoint.x, aStartPoint.y, angle );
  421. }
  422. // push last point (end point)
  423. aBuffer.push_back( aEndPoint );
  424. return 1;
  425. }
  426. MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_count )
  427. {
  428. MODULE* module;
  429. int pad_num = 1;
  430. wxString Line;
  431. module = Create_1_Module( name );
  432. if( module == NULL )
  433. return NULL;
  434. #define DEFAULT_SIZE 30
  435. module->SetTimeStamp( GetNewTimeStamp() );
  436. module->Value().SetSize( wxSize( DEFAULT_SIZE, DEFAULT_SIZE ) );
  437. module->Value().SetPos0( wxPoint( 0, -DEFAULT_SIZE ) );
  438. module->Value().Offset( wxPoint( 0, module->Value().GetPos0().y ) );
  439. module->Value().SetThickness( DEFAULT_SIZE / 4 );
  440. module->Reference().SetSize( wxSize( DEFAULT_SIZE, DEFAULT_SIZE ) );
  441. module->Reference().SetPos0( wxPoint( 0, DEFAULT_SIZE ) );
  442. module->Reference().Offset( wxPoint( 0, module->Reference().GetPos0().y ) );
  443. module->Reference().SetThickness( DEFAULT_SIZE / 4 );
  444. // Create 2 pads used in gaps and stubs. The gap is between these 2 pads
  445. // the stub is the pad 2
  446. while( pad_count-- )
  447. {
  448. D_PAD* pad = new D_PAD( module );
  449. module->Pads().PushFront( pad );
  450. int tw = GetBoard()->GetCurrentTrackWidth();
  451. pad->SetSize( wxSize( tw, tw ) );
  452. pad->SetPosition( module->GetPosition() );
  453. pad->SetShape( PAD_RECT );
  454. pad->SetAttribute( PAD_SMD );
  455. pad->SetLayerMask( LAYER_FRONT );
  456. Line.Printf( wxT( "%d" ), pad_num );
  457. pad->SetPadName( Line );
  458. pad_num++;
  459. }
  460. return module;
  461. }
  462. MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
  463. {
  464. int oX;
  465. D_PAD* pad;
  466. MODULE* module;
  467. wxString msg, cmp_name;
  468. int pad_count = 2;
  469. int angle = 0;
  470. // Enter the size of the gap or stub
  471. int gap_size = GetBoard()->GetCurrentTrackWidth();
  472. switch( shape_type )
  473. {
  474. case 0:
  475. msg = _( "Gap" );
  476. cmp_name = wxT( "GAP" );
  477. break;
  478. case 1:
  479. msg = _( "Stub" );
  480. cmp_name = wxT( "STUB" );
  481. pad_count = 2;
  482. break;
  483. case 2:
  484. msg = _( "Arc Stub" );
  485. cmp_name = wxT( "ASTUB" );
  486. pad_count = 1;
  487. break;
  488. default:
  489. msg = wxT( "???" );
  490. break;
  491. }
  492. wxString value = StringFromValue( g_UserUnit, gap_size );
  493. wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value );
  494. if( dlg.ShowModal() != wxID_OK )
  495. {
  496. m_canvas->MoveCursorToCrossHair();
  497. return NULL; // cancelled by user
  498. }
  499. value = dlg.GetValue();
  500. gap_size = ValueFromString( g_UserUnit, value );
  501. bool abort = false;
  502. if( shape_type == 2 )
  503. {
  504. double fcoeff = 10.0, fval;
  505. msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
  506. wxTextEntryDialog angledlg( this, _( "Angle (0.1deg):" ),
  507. _( "Create microwave module" ), msg );
  508. if( angledlg.ShowModal() != wxID_OK )
  509. {
  510. m_canvas->MoveCursorToCrossHair();
  511. return NULL; // cancelled by user
  512. }
  513. msg = angledlg.GetValue();
  514. if( !msg.ToDouble( &fval ) )
  515. {
  516. DisplayError( this, _( "Incorrect number, abort" ) );
  517. abort = true;
  518. }
  519. angle = std::abs( KiROUND( fval * fcoeff ) );
  520. if( angle > 1800 )
  521. angle = 1800;
  522. }
  523. if( abort )
  524. {
  525. m_canvas->MoveCursorToCrossHair();
  526. return NULL;
  527. }
  528. module = Create_MuWaveBasicShape( cmp_name, pad_count );
  529. pad = module->Pads();
  530. switch( shape_type )
  531. {
  532. case 0: //Gap :
  533. oX = -( gap_size + pad->GetSize().x ) / 2;
  534. pad->SetX0( oX );
  535. pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
  536. pad = pad->Next();
  537. pad->SetX0( oX + gap_size + pad->GetSize().x );
  538. pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
  539. break;
  540. case 1: //Stub :
  541. pad->SetPadName( wxT( "1" ) );
  542. pad = pad->Next();
  543. pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 );
  544. pad->SetSize( wxSize( pad->GetSize().x, gap_size ) );
  545. pad->SetY( pad->GetPos0().y + pad->GetPosition().y );
  546. break;
  547. case 2: // Arc Stub created by a polygonal approach:
  548. {
  549. EDGE_MODULE* edge = new EDGE_MODULE( module );
  550. module->GraphicalItems().PushFront( edge );
  551. edge->SetShape( S_POLYGON );
  552. edge->SetLayer( LAYER_N_FRONT );
  553. int numPoints = angle / 50 + 3; // Note: angles are in 0.1 degrees
  554. std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
  555. polyPoints.reserve( numPoints );
  556. edge->m_Start0.y = -pad->GetSize().y / 2;
  557. polyPoints.push_back( wxPoint( 0, 0 ) );
  558. int theta = -angle / 2;
  559. for( int ii = 1; ii<numPoints - 1; ii++ )
  560. {
  561. wxPoint pt( 0, -gap_size );
  562. RotatePoint( &pt.x, &pt.y, theta );
  563. polyPoints.push_back( pt );
  564. theta += 50;
  565. if( theta > angle / 2 )
  566. theta = angle / 2;
  567. }
  568. // Close the polygon:
  569. polyPoints.push_back( polyPoints[0] );
  570. }
  571. break;
  572. default:
  573. break;
  574. }
  575. module->CalculateBoundingBox();
  576. GetBoard()->m_Status_Pcb = 0;
  577. OnModify();
  578. return module;
  579. }
  580. /**************** Polygon Shapes ***********************/
  581. enum id_mw_cmd {
  582. ID_READ_SHAPE_FILE = 1000
  583. };
  584. /* Setting polynomial form parameters
  585. */
  586. class WinEDA_SetParamShapeFrame : public wxDialog
  587. {
  588. private:
  589. PCB_EDIT_FRAME* m_Parent;
  590. wxRadioBox* m_ShapeOptionCtrl;
  591. EDA_SIZE_CTRL* m_SizeCtrl;
  592. public:
  593. WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, const wxPoint& pos );
  594. ~WinEDA_SetParamShapeFrame() { };
  595. private:
  596. void OnOkClick( wxCommandEvent& event );
  597. void OnCancelClick( wxCommandEvent& event );
  598. /**
  599. * Function ReadDataShapeDescr
  600. * read a description shape file
  601. * File format is
  602. * Unit=MM
  603. * XScale=271.501
  604. * YScale=1.00133
  605. *
  606. * $COORD
  607. * 0 0.6112600148417837
  608. * 0.001851851851851852 0.6104800531118608
  609. * ....
  610. * $ENDCOORD
  611. *
  612. * Each line is the X Y coord (normalized units from 0 to 1)
  613. */
  614. void ReadDataShapeDescr( wxCommandEvent& event );
  615. void AcceptOptions( wxCommandEvent& event );
  616. DECLARE_EVENT_TABLE()
  617. };
  618. BEGIN_EVENT_TABLE( WinEDA_SetParamShapeFrame, wxDialog )
  619. EVT_BUTTON( wxID_OK, WinEDA_SetParamShapeFrame::OnOkClick )
  620. EVT_BUTTON( wxID_CANCEL, WinEDA_SetParamShapeFrame::OnCancelClick )
  621. EVT_BUTTON( ID_READ_SHAPE_FILE, WinEDA_SetParamShapeFrame::ReadDataShapeDescr )
  622. END_EVENT_TABLE()
  623. WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent,
  624. const wxPoint& framepos ) :
  625. wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ),
  626. wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
  627. {
  628. m_Parent = parent;
  629. PolyEdges.clear();
  630. wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  631. SetSizer( MainBoxSizer );
  632. wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
  633. wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
  634. MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
  635. MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  636. wxButton* Button = new wxButton( this, wxID_OK, _( "OK" ) );
  637. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  638. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  639. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  640. Button = new wxButton( this, ID_READ_SHAPE_FILE,
  641. _( "Read Shape Description File..." ) );
  642. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  643. wxString shapelist[3] =
  644. {
  645. _( "Normal" ), _( "Symmetrical" ),
  646. _( "Mirrored" )
  647. };
  648. m_ShapeOptionCtrl = new wxRadioBox( this, -1, _( "Shape Option" ),
  649. wxDefaultPosition, wxDefaultSize, 3,
  650. shapelist, 1,
  651. wxRA_SPECIFY_COLS );
  652. LeftBoxSizer->Add( m_ShapeOptionCtrl, 0, wxGROW | wxALL, 5 );
  653. m_SizeCtrl = new EDA_SIZE_CTRL( this, _( "Size" ), ShapeSize, g_UserUnit, LeftBoxSizer );
  654. GetSizer()->Fit( this );
  655. GetSizer()->SetSizeHints( this );
  656. }
  657. void WinEDA_SetParamShapeFrame::OnCancelClick( wxCommandEvent& event )
  658. {
  659. PolyEdges.clear();
  660. EndModal( -1 );
  661. }
  662. void WinEDA_SetParamShapeFrame::OnOkClick( wxCommandEvent& event )
  663. {
  664. ShapeSize = m_SizeCtrl->GetValue();
  665. PolyShapeType = m_ShapeOptionCtrl->GetSelection();
  666. EndModal( 1 );
  667. }
  668. void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
  669. {
  670. wxString FullFileName;
  671. wxString ext, mask;
  672. FILE* File;
  673. char* Line;
  674. double unitconv = 10000;
  675. char* param1, * param2;
  676. ext = wxT( ".txt" );
  677. mask = wxT( "*" ) + ext;
  678. FullFileName = EDA_FileSelector( _( "Read descr shape file" ),
  679. wxEmptyString,
  680. FullFileName,
  681. ext,
  682. mask,
  683. this,
  684. wxFD_OPEN,
  685. true );
  686. if( FullFileName.IsEmpty() )
  687. return;
  688. File = wxFopen( FullFileName, wxT( "rt" ) );
  689. if( File == NULL )
  690. {
  691. DisplayError( this, _( "File not found" ) );
  692. return;
  693. }
  694. FILE_LINE_READER fileReader( File, FullFileName );
  695. FILTER_READER reader( fileReader );
  696. LOCALE_IO toggle;
  697. while( reader.ReadLine() )
  698. {
  699. Line = reader.Line();
  700. param1 = strtok( Line, " =\n\r" );
  701. param2 = strtok( NULL, " \t\n\r" );
  702. if( strnicmp( param1, "Unit", 4 ) == 0 )
  703. {
  704. if( strnicmp( param2, "inch", 4 ) == 0 )
  705. unitconv = 10000;
  706. if( strnicmp( param2, "mm", 2 ) == 0 )
  707. unitconv = 10000 / 25.4;
  708. }
  709. if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
  710. break;
  711. if( strnicmp( param1, "$COORD", 6 ) == 0 )
  712. {
  713. while( reader.ReadLine() )
  714. {
  715. Line = reader.Line();
  716. param1 = strtok( Line, " \t\n\r" );
  717. param2 = strtok( NULL, " \t\n\r" );
  718. if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
  719. break;
  720. PolyEdges.push_back( atof( param1 ) );
  721. PolyEdges.push_back( atof( param2 ) );
  722. }
  723. }
  724. if( strnicmp( Line, "XScale", 6 ) == 0 )
  725. {
  726. ShapeScaleX = atof( param2 );
  727. }
  728. if( strnicmp( Line, "YScale", 6 ) == 0 )
  729. {
  730. ShapeScaleY = atof( param2 );
  731. }
  732. }
  733. ShapeScaleX *= unitconv;
  734. ShapeScaleY *= unitconv;
  735. m_SizeCtrl->SetValue( (int) ShapeScaleX, (int) ShapeScaleY );
  736. }
  737. MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
  738. {
  739. D_PAD* pad1, * pad2;
  740. MODULE* module;
  741. wxString cmp_name;
  742. int pad_count = 2;
  743. EDGE_MODULE* edge;
  744. WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( this, wxPoint( -1, -1 ) );
  745. int ok = frame->ShowModal();
  746. frame->Destroy();
  747. m_canvas->MoveCursorToCrossHair();
  748. if( ok != 1 )
  749. {
  750. PolyEdges.clear();
  751. }
  752. if( PolyShapeType == 2 ) // mirrored
  753. ShapeScaleY = -ShapeScaleY;
  754. ShapeSize.x = KiROUND( ShapeScaleX );
  755. ShapeSize.y = KiROUND( ShapeScaleY );
  756. if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
  757. {
  758. DisplayError( this, _( "Shape has a null size!" ) );
  759. return NULL;
  760. }
  761. if( PolyEdges.size() == 0 )
  762. {
  763. DisplayError( this, _( "Shape has no points!" ) );
  764. return NULL;
  765. }
  766. cmp_name = wxT( "POLY" );
  767. module = Create_MuWaveBasicShape( cmp_name, pad_count );
  768. pad1 = module->Pads();
  769. pad1->SetX0( -ShapeSize.x / 2 );
  770. pad1->SetX( pad1->GetPos0().x + pad1->GetPosition().x );
  771. pad2 = (D_PAD*) pad1->Next();
  772. pad2->SetX0( pad1->GetPos0().x + ShapeSize.x );
  773. pad2->SetX( pad2->GetPos0().x + pad2->GetPosition().x );
  774. edge = new EDGE_MODULE( module );
  775. module->GraphicalItems().PushFront( edge );
  776. edge->SetShape( S_POLYGON );
  777. edge->SetLayer( LAYER_N_FRONT );
  778. std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
  779. polyPoints.reserve( 2 * PolyEdges.size() + 2 );
  780. // Init start point coord:
  781. polyPoints.push_back( wxPoint( pad1->GetPos0().x, 0 ) );
  782. wxPoint first_coordinate, last_coordinate;
  783. for( unsigned ii = 0; ii < PolyEdges.size(); ii++ ) // Copy points
  784. {
  785. last_coordinate.x = KiROUND( PolyEdges[ii] * ShapeScaleX ) + pad1->GetPos0().x;
  786. last_coordinate.y = -KiROUND( PolyEdges[ii] * ShapeScaleY );
  787. polyPoints.push_back( last_coordinate );
  788. }
  789. first_coordinate.y = polyPoints[1].y;
  790. switch( PolyShapeType )
  791. {
  792. case 0: // Single
  793. case 2: // Single mirrored
  794. // Init end point coord:
  795. pad2->SetX0( last_coordinate.x );
  796. polyPoints.push_back( wxPoint( last_coordinate.x, 0 ) );
  797. pad1->SetSize( wxSize( std::abs( first_coordinate.y ),
  798. std::abs( first_coordinate.y ) ) );
  799. pad2->SetSize( wxSize( std::abs( last_coordinate.y ),
  800. std::abs( last_coordinate.y ) ) );
  801. pad1->SetY0( first_coordinate.y / 2 );
  802. pad2->SetY0( last_coordinate.y / 2 );
  803. pad1->SetY( pad1->GetPos0().y + module->GetPosition().y );
  804. pad2->SetY( pad2->GetPos0().y + module->GetPosition().y );
  805. break;
  806. case 1: // Symmetric
  807. for( int ndx = polyPoints.size() - 1; ndx>=0; --ndx )
  808. {
  809. wxPoint pt = polyPoints[ndx];
  810. pt.y = -pt.y; // mirror about X axis
  811. polyPoints.push_back( pt );
  812. }
  813. pad1->SetSize( wxSize( 2 * std::abs( first_coordinate.y ),
  814. 2 * std::abs( first_coordinate.y ) ) );
  815. pad2->SetSize( wxSize( 2 * std::abs( last_coordinate.y ),
  816. 2 * std::abs( last_coordinate.y ) ) );
  817. break;
  818. }
  819. PolyEdges.clear();
  820. module->CalculateBoundingBox();
  821. GetBoard()->m_Status_Pcb = 0;
  822. OnModify();
  823. return module;
  824. }
  825. void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* aModule )
  826. {
  827. int gap_size, oX;
  828. D_PAD* pad, * next_pad;
  829. wxString msg;
  830. if( aModule == NULL )
  831. return;
  832. // Test if module is a gap type (name begins with GAP, and has 2 pads).
  833. msg = aModule->GetReference().Left( 3 );
  834. if( msg != wxT( "GAP" ) )
  835. return;
  836. pad = aModule->Pads();
  837. if( pad == NULL )
  838. {
  839. DisplayError( this, _( "No pad for this module" ) );
  840. return;
  841. }
  842. next_pad = (D_PAD*) pad->Next();
  843. if( next_pad == NULL )
  844. {
  845. DisplayError( this, _( "Only one pad for this module" ) );
  846. return;
  847. }
  848. aModule->Draw( m_canvas, DC, GR_XOR );
  849. // Calculate the current dimension.
  850. gap_size = next_pad->GetPos0().x - pad->GetPos0().x - pad->GetSize().x;
  851. // Entrer the desired length of the gap.
  852. msg = StringFromValue( g_UserUnit, gap_size );
  853. wxTextEntryDialog dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg );
  854. if( dlg.ShowModal() != wxID_OK )
  855. return; // cancelled by user
  856. msg = dlg.GetValue();
  857. gap_size = ValueFromString( g_UserUnit, msg );
  858. // Updating sizes of pads forming the gap.
  859. int tw = GetBoard()->GetCurrentTrackWidth();
  860. pad->SetSize( wxSize( tw, tw ) );
  861. pad->SetY0( 0 );
  862. oX = -( gap_size + pad->GetSize().x ) / 2;
  863. pad->SetX0( oX );
  864. wxPoint padpos = pad->GetPos0() + aModule->GetPosition();
  865. RotatePoint( &padpos.x, &padpos.y,
  866. aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
  867. pad->SetPosition( padpos );
  868. tw = GetBoard()->GetCurrentTrackWidth();
  869. next_pad->SetSize( wxSize( tw, tw ) );
  870. next_pad->SetY0( 0 );
  871. next_pad->SetX0( oX + gap_size + next_pad->GetSize().x );
  872. padpos = next_pad->GetPos0() + aModule->GetPosition();
  873. RotatePoint( &padpos.x, &padpos.y,
  874. aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
  875. next_pad->SetPosition( padpos );
  876. aModule->Draw( m_canvas, DC, GR_OR );
  877. }