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.

108 lines
3.0 KiB

1 year ago
  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <eda_dde.h>
  20. #include <kiface_base.h>
  21. #include <kiface_ids.h>
  22. #include <kipython_frame.h>
  23. #include <kipython_settings.h>
  24. #include <kiway.h>
  25. #include <pgm_base.h>
  26. #include <python_scripting.h>
  27. #include <settings/settings_manager.h>
  28. //-----<KIFACE>-----------------------------------------------------------------
  29. namespace KIPYTHON {
  30. static struct IFACE : public KIFACE_BASE
  31. {
  32. bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
  33. void OnKifaceEnd() override;
  34. wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
  35. int aCtlBits = 0 ) override
  36. {
  37. KIPYTHON_FRAME* frame = new KIPYTHON_FRAME( aKiway, aParent );
  38. if( Kiface().IsSingle() )
  39. {
  40. // only run this under single_top, not under a project manager.
  41. frame->CreateServer( KICAD_PY_PORT_SERVICE_NUMBER );
  42. }
  43. return frame;
  44. }
  45. /**
  46. * Function IfaceOrAddress
  47. * return a pointer to the requested object. The safest way to use this
  48. * is to retrieve a pointer to a static instance of an interface, similar to
  49. * how the KIFACE interface is exported. But if you know what you are doing
  50. * use it to retrieve anything you want.
  51. *
  52. * @param aDataId identifies which object you want the address of.
  53. *
  54. * @return void* - and must be cast into the know type.
  55. */
  56. void* IfaceOrAddress( int aDataId ) override
  57. {
  58. return NULL;
  59. }
  60. IFACE( const char* aDSOname, KIWAY::FACE_T aType ) :
  61. KIFACE_BASE( aDSOname, aType )
  62. {}
  63. } kiface( "KIPYTHON", KIWAY::FACE_PYTHON );
  64. } // namespace KIPYTHON
  65. using namespace KIPYTHON;
  66. KIFACE_BASE& Kiface()
  67. {
  68. return kiface;
  69. }
  70. // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
  71. // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
  72. KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
  73. {
  74. return &kiface;
  75. }
  76. bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
  77. {
  78. InitSettings( new KIPYTHON_SETTINGS );
  79. Pgm().GetSettingsManager().RegisterSettings( KifaceSettings() );
  80. return start_common( aCtlBits );
  81. }
  82. void IFACE::OnKifaceEnd()
  83. {
  84. end_common();
  85. }