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.

167 lines
4.9 KiB

  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. * Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef FOOTPRINT_PREVIEW_WIDGET_H
  21. #define FOOTPRINT_PREVIEW_WIDGET_H
  22. #include <wx/panel.h>
  23. #include <functional>
  24. #include <import_export.h>
  25. #include <lib_id.h>
  26. #include <eda_units.h>
  27. #include <gal/color4d.h>
  28. class FOOTPRINT_PREVIEW_PANEL_BASE;
  29. class BOARD;
  30. class FOOTPRINT;
  31. class KIWAY;
  32. class TOOL_DISPATCHER;
  33. class EDA_DRAW_PANEL_GAL;
  34. class wxStaticText;
  35. class wxSizer;
  36. class FOOTPRINT_PREVIEW_WIDGET: public wxPanel
  37. {
  38. public:
  39. /**
  40. * Construct a footprint preview widget.
  41. *
  42. * @param aParent - parent window
  43. * @param aKiway - an active Kiway instance
  44. */
  45. FOOTPRINT_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway );
  46. /**
  47. * Return whether the widget initialized properly. This could return false if Kiway is
  48. * not available. If this returns false, no other methods should be called.
  49. */
  50. bool IsInitialized() const { return m_prev_panel != nullptr; }
  51. /**
  52. * Set the contents of the status label and display it.
  53. */
  54. void SetStatusText( const wxString& aText );
  55. /**
  56. * Clear the contents of the status label and hide it.
  57. */
  58. void ClearStatus();
  59. /**
  60. * Set the units for the preview.
  61. */
  62. void SetUserUnits( EDA_UNITS aUnits );
  63. /**
  64. * Set the pin functions from the symbol's netlist. This allows us to display them in
  65. * the corresponding pads.
  66. * @param aPinFunctions a map from pin_number to pin_function
  67. */
  68. void SetPinFunctions( const std::map<wxString, wxString>& aPinFunctions );
  69. /**
  70. * Set the currently displayed footprint. Any footprint passed in here *MUST* have been
  71. * passed to CacheFootprint before.
  72. */
  73. void DisplayFootprint( const LIB_ID& aFPID );
  74. /**
  75. * Display a pair of footprints. (Normally used for diff'ing.)
  76. */
  77. void DisplayFootprints( std::shared_ptr<FOOTPRINT> aFootprintA,
  78. std::shared_ptr<FOOTPRINT> aFootprintB );
  79. /**
  80. * Force the redrawing of all contents.
  81. */
  82. void RefreshAll();
  83. FOOTPRINT_PREVIEW_PANEL_BASE* GetPreviewPanel() { return m_prev_panel; }
  84. protected:
  85. FOOTPRINT_PREVIEW_PANEL_BASE* m_prev_panel;
  86. wxStaticText* m_status;
  87. wxPanel* m_statusPanel;
  88. wxSizer* m_statusSizer;
  89. wxSizer* m_outerSizer;
  90. LIB_ID m_libid;
  91. };
  92. /**
  93. * Base class for the actual viewer panel. The implementation is in
  94. * pcbnew/footprint_preview_panel.cpp, accessed via kiface.
  95. */
  96. class APIEXPORT FOOTPRINT_PREVIEW_PANEL_BASE
  97. {
  98. public:
  99. virtual ~FOOTPRINT_PREVIEW_PANEL_BASE() {}
  100. virtual void SetUserUnits( EDA_UNITS aUnits ) = 0;
  101. /**
  102. * Set the pin functions from the symbol's netlist. This allows us to display them in
  103. * the corresponding pads.
  104. * @param aPinFunctions a map from pin_number to pin_function
  105. */
  106. virtual void SetPinFunctions( const std::map<wxString, wxString>& aPinFunctions ) = 0;
  107. /**
  108. * Set the currently displayed footprint. Any footprint passed in here *MUST* have been
  109. * passed to CacheFootprint before.
  110. */
  111. virtual bool DisplayFootprint( LIB_ID const& aFPID ) = 0;
  112. /**
  113. * Display a pair of footprints. (Normally used for diff'ing.)
  114. */
  115. virtual void DisplayFootprints( std::shared_ptr<FOOTPRINT> aFootprintA,
  116. std::shared_ptr<FOOTPRINT> aFootprintB ) = 0;
  117. /**
  118. * Force the redrawing of all contents.
  119. */
  120. virtual void RefreshAll() = 0;
  121. /**
  122. * Get the GAL canvas.
  123. */
  124. virtual EDA_DRAW_PANEL_GAL* GetCanvas() = 0;
  125. virtual BOARD* GetBoard() = 0;
  126. /**
  127. * Get the colors to use in a preview widget to match the preview panel.
  128. */
  129. virtual const KIGFX::COLOR4D& GetBackgroundColor() const = 0;
  130. virtual const KIGFX::COLOR4D& GetForegroundColor() const = 0;
  131. /**
  132. * Return a footprint preview panel instance via Kiface. May return null if Kiway is not
  133. * available or there is any error on load.
  134. */
  135. static FOOTPRINT_PREVIEW_PANEL_BASE* Create( wxWindow* aParent, KIWAY& aKiway );
  136. };
  137. #endif // FOOTPRINT_PREVIEW_WIDGET_H