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.

134 lines
3.5 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. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #pragma once
  20. #include <map>
  21. #include <bitmaps.h>
  22. #include <units_provider.h>
  23. #include <gal/color4d.h>
  24. #include <wx/translation.h>
  25. #include <geometry/shape.h>
  26. class OUTPUTFORMATTER;
  27. class MSG_PANEL_ITEM;
  28. namespace KIGFX
  29. {
  30. class RENDER_SETTINGS;
  31. }
  32. /**
  33. * Dashed line types.
  34. */
  35. enum class LINE_STYLE
  36. {
  37. DEFAULT = -1,
  38. SOLID = 0,
  39. FIRST_TYPE = SOLID,
  40. DASH,
  41. DOT,
  42. DASHDOT,
  43. DASHDOTDOT,
  44. LAST_TYPE = DASHDOTDOT
  45. };
  46. struct LINE_STYLE_DESC
  47. {
  48. wxString name;
  49. const BITMAPS bitmap;
  50. };
  51. // A cover of LINE_STYLE for the properties manager (so that it can have different
  52. // strings from the normal LINE_STYLE)
  53. enum class WIRE_STYLE
  54. {
  55. DEFAULT = -1,
  56. SOLID = 0,
  57. DASH,
  58. DOT,
  59. DASHDOT,
  60. DASHDOTDOT
  61. };
  62. /**
  63. * Conversion map between LINE_STYLE values and style names displayed.
  64. */
  65. extern const std::map<LINE_STYLE, struct LINE_STYLE_DESC> lineTypeNames;
  66. #define DEFAULT_LINE_STYLE_LABEL _( "Solid" )
  67. #define DEFAULT_WIRE_STYLE_LABEL _( "Default" )
  68. #define INDETERMINATE_STYLE _( "Leave unchanged" )
  69. /**
  70. * Simple container to manage line stroke parameters.
  71. */
  72. class STROKE_PARAMS
  73. {
  74. public:
  75. STROKE_PARAMS( int aWidth = 0, LINE_STYLE aLineStyle = LINE_STYLE::DEFAULT,
  76. const KIGFX::COLOR4D& aColor = KIGFX::COLOR4D::UNSPECIFIED ) :
  77. m_width( aWidth ),
  78. m_lineStyle( aLineStyle ),
  79. m_color( aColor )
  80. {
  81. }
  82. int GetWidth() const { return m_width; }
  83. void SetWidth( int aWidth ) { m_width = aWidth; }
  84. LINE_STYLE GetLineStyle() const { return m_lineStyle; }
  85. void SetLineStyle( LINE_STYLE aLineStyle ) { m_lineStyle = aLineStyle; }
  86. KIGFX::COLOR4D GetColor() const { return m_color; }
  87. void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
  88. bool operator!=( const STROKE_PARAMS& aOther ) const
  89. {
  90. return m_width != aOther.m_width
  91. || m_lineStyle != aOther.m_lineStyle
  92. || m_color != aOther.m_color;
  93. }
  94. void Format( OUTPUTFORMATTER* out, const EDA_IU_SCALE& aIuScale ) const;
  95. void GetMsgPanelInfo( UNITS_PROVIDER* aUnitsProvider, std::vector<MSG_PANEL_ITEM>& aList,
  96. bool aIncludeStyle = true, bool aIncludeWidth = true );
  97. // Helper functions
  98. static wxString GetLineStyleToken( LINE_STYLE aStyle );
  99. static void Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWidth,
  100. const KIGFX::RENDER_SETTINGS* aRenderSettings,
  101. const std::function<void( const VECTOR2I& a,
  102. const VECTOR2I& b )>& aStroker );
  103. private:
  104. int m_width;
  105. LINE_STYLE m_lineStyle;
  106. KIGFX::COLOR4D m_color;
  107. };