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.

205 lines
5.2 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file kicad.i
  26. * @brief General wrappers for kicad / wx structures and classes
  27. */
  28. %include <std_deque.i>
  29. %include <std_vector.i>
  30. %include <std_list.i>
  31. %include <std_basic_string.i>
  32. %include <std_string.i>
  33. %include <std_map.i>
  34. %include <std_shared_ptr.i>
  35. %include <std_set.i>
  36. %include <stdint.i>
  37. // SWIG is awful and cant just ignore declspec
  38. #define KICOMMON_API
  39. #define GAL_API
  40. %include "ki_exception.i" // affects all that follow it
  41. /*
  42. http://www.swig.org/Doc3.0/CPlusPlus11.html
  43. 7.3.3 Hash tables
  44. The new hash tables in the STL are unordered_set, unordered_multiset,
  45. unordered_map, unordered_multimap. These are not available in SWIG, but in
  46. principle should be easily implemented by adapting the current STL containers.
  47. %include <std_unordered_map.i>
  48. */
  49. // ignore some constructors of EDA_ITEM that will make the build fail
  50. %nodefaultctor EDA_ITEM;
  51. %ignore EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
  52. %ignore EDA_ITEM::EDA_ITEM( KICAD_T idType );
  53. %ignore EDA_ITEM::EDA_ITEM( const EDA_ITEM& base );
  54. %warnfilter(401) EDA_ITEM;
  55. %warnfilter(509) UTF8;
  56. /* swig tries to wrap SetBack/SetNext on derived classes, but this method is
  57. private for most children, so if we don't ignore it won't compile */
  58. %ignore EDA_ITEM::SetBack;
  59. %ignore EDA_ITEM::SetNext;
  60. // ignore other functions that cause trouble
  61. %ignore InitKiCadAbout;
  62. %ignore GetCommandOptions;
  63. %rename(getWxRect) operator wxRect;
  64. %rename(getBOX2I) operator BOX2I;
  65. %ignore operator <<;
  66. %ignore operator=;
  67. %ignore to_json;
  68. %ignore from_json;
  69. // headers/imports that must be included in the _wrapper.cpp at top
  70. %{
  71. #include <macros_swig.h>
  72. #include <kiid.h>
  73. #include <cstddef>
  74. #include <base_units.h>
  75. #include <eda_item.h>
  76. #include <eda_units.h>
  77. #include <common.h>
  78. #include <richio.h>
  79. #include <wx_python_helpers.h>
  80. #include <cstddef>
  81. #include <vector>
  82. #include <bitset>
  83. #include <title_block.h>
  84. #include <marker_base.h>
  85. #include <eda_text.h>
  86. #include <id.h>
  87. #include <build_version.h>
  88. #include <layer_ids.h>
  89. #include <settings/settings_manager.h>
  90. #include <pcbnew_utils_3d.h>
  91. %}
  92. // all the wx wrappers for wxString, wxPoint, wxRect, wxChar ..
  93. %include wx.i
  94. // SWIG is incompatible with std::unique_ptr
  95. %ignore GetNewConfig;
  96. // TODO: wrapper of BASE_SET (see std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;)
  97. // header files that must be wrapped
  98. %include macros_swig.h
  99. %include kiid.h
  100. %include core/typeinfo.h
  101. %include eda_item.h
  102. %include base_units.h
  103. %include eda_units.h
  104. %include common.h
  105. %include richio.h
  106. %include title_block.h
  107. %include gal/color4d.h
  108. %include marker_base.h
  109. %include eda_text.h
  110. %include build_version.h
  111. %include layer_ids.h
  112. %include settings/settings_manager.h
  113. %include pcbnew_utils_3d.h
  114. // Cast time_t to known type for Python
  115. typedef long time_t;
  116. // std template mappings
  117. %template(intVector) std::vector<int>;
  118. %template(str_utf8_Map) std::map< std::string,UTF8 >;
  119. // KiCad plugin handling
  120. %include "kicadplugins.i"
  121. // Contains VECTOR2I
  122. %include math.i
  123. %template(VECTOR_VECTOR2I) std::vector<VECTOR2I>;
  124. // Shapes/geometry
  125. %include shape.i
  126. // std::optional type mappings
  127. %include optional.i
  128. // Mirror defs
  129. %include mirror.i
  130. // ignore warning relative to operator = and operator ++:
  131. #pragma SWIG nowarn=362,383
  132. // Rename operators defined in utf8.h
  133. %rename(utf8_to_charptr) operator char* () const;
  134. %rename(utf8_to_wxstring) operator wxString () const;
  135. %rename(utf8_to_string) operator const std::string& () const;
  136. #include <core/utf8.h>
  137. %include <core/utf8.h>
  138. %extend EDA_ITEM
  139. {
  140. wxString PyGetClass() const { return self->GetClass(); }
  141. %pythoncode
  142. %{
  143. def GetClass(self):
  144. return self.PyGetClass()
  145. %}
  146. }
  147. %extend UTF8
  148. {
  149. const char* Cast_to_CChar() { return (self->c_str()); }
  150. %pythoncode
  151. %{
  152. # Get the char buffer of the UTF8 string
  153. def GetChars(self):
  154. return self.Cast_to_CChar()
  155. # Convert the UTF8 string to a python string
  156. # Same as GetChars(), but more easy to use in print command
  157. def __str__(self):
  158. return self.GetChars()
  159. %}
  160. }