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.

138 lines
3.7 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, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #pragma once
  24. #include <map>
  25. #include <bitmaps.h>
  26. #include <units_provider.h>
  27. #include <gal/color4d.h>
  28. #include <wx/translation.h>
  29. #include <geometry/shape.h>
  30. class OUTPUTFORMATTER;
  31. class MSG_PANEL_ITEM;
  32. namespace KIGFX
  33. {
  34. class RENDER_SETTINGS;
  35. }
  36. /**
  37. * Dashed line types.
  38. */
  39. enum class LINE_STYLE
  40. {
  41. DEFAULT = -1,
  42. SOLID = 0,
  43. FIRST_TYPE = SOLID,
  44. DASH,
  45. DOT,
  46. DASHDOT,
  47. DASHDOTDOT,
  48. LAST_TYPE = DASHDOTDOT
  49. };
  50. struct LINE_STYLE_DESC
  51. {
  52. wxString name;
  53. const BITMAPS bitmap;
  54. };
  55. // A cover of LINE_STYLE for the properties manager (so that it can have different
  56. // strings from the normal LINE_STYLE)
  57. enum class WIRE_STYLE
  58. {
  59. DEFAULT = -1,
  60. SOLID = 0,
  61. DASH,
  62. DOT,
  63. DASHDOT,
  64. DASHDOTDOT
  65. };
  66. /**
  67. * Conversion map between LINE_STYLE values and style names displayed.
  68. */
  69. extern const std::map<LINE_STYLE, struct LINE_STYLE_DESC> lineTypeNames;
  70. #define DEFAULT_LINE_STYLE_LABEL _( "Solid" )
  71. #define DEFAULT_WIRE_STYLE_LABEL _( "Default" )
  72. #define INDETERMINATE_STYLE _( "Leave unchanged" )
  73. /**
  74. * Simple container to manage line stroke parameters.
  75. */
  76. class STROKE_PARAMS
  77. {
  78. public:
  79. STROKE_PARAMS( int aWidth = 0, LINE_STYLE aLineStyle = LINE_STYLE::DEFAULT,
  80. const KIGFX::COLOR4D& aColor = KIGFX::COLOR4D::UNSPECIFIED ) :
  81. m_width( aWidth ),
  82. m_lineStyle( aLineStyle ),
  83. m_color( aColor )
  84. {
  85. }
  86. int GetWidth() const { return m_width; }
  87. void SetWidth( int aWidth ) { m_width = aWidth; }
  88. LINE_STYLE GetLineStyle() const { return m_lineStyle; }
  89. void SetLineStyle( LINE_STYLE aLineStyle ) { m_lineStyle = aLineStyle; }
  90. KIGFX::COLOR4D GetColor() const { return m_color; }
  91. void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
  92. bool operator!=( const STROKE_PARAMS& aOther ) const
  93. {
  94. return m_width != aOther.m_width
  95. || m_lineStyle != aOther.m_lineStyle
  96. || m_color != aOther.m_color;
  97. }
  98. void Format( OUTPUTFORMATTER* out, const EDA_IU_SCALE& aIuScale ) const;
  99. void GetMsgPanelInfo( UNITS_PROVIDER* aUnitsProvider, std::vector<MSG_PANEL_ITEM>& aList,
  100. bool aIncludeStyle = true, bool aIncludeWidth = true );
  101. // Helper functions
  102. static wxString GetLineStyleToken( LINE_STYLE aStyle );
  103. static void Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWidth,
  104. const KIGFX::RENDER_SETTINGS* aRenderSettings,
  105. const std::function<void( const VECTOR2I& a,
  106. const VECTOR2I& b )>& aStroker );
  107. private:
  108. int m_width;
  109. LINE_STYLE m_lineStyle;
  110. KIGFX::COLOR4D m_color;
  111. };