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.

147 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2021 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. #ifndef STROKE_PARAMS_H
  24. #define STROKE_PARAMS_H
  25. #include <map>
  26. #include <bitmaps.h>
  27. #include <units_provider.h>
  28. #include <gal/color4d.h>
  29. #include <wx/translation.h>
  30. #include <geometry/shape.h>
  31. #include <stroke_params_lexer.h>
  32. class STROKE_PARAMS_LEXER;
  33. class MSG_PANEL_ITEM;
  34. namespace KIGFX
  35. {
  36. class RENDER_SETTINGS;
  37. }
  38. /**
  39. * Dashed line types.
  40. */
  41. enum class LINE_STYLE
  42. {
  43. DEFAULT = -1,
  44. SOLID = 0,
  45. FIRST_TYPE = SOLID,
  46. DASH,
  47. DOT,
  48. DASHDOT,
  49. DASHDOTDOT,
  50. LAST_TYPE = DASHDOTDOT
  51. };
  52. struct LINE_STYLE_DESC
  53. {
  54. wxString name;
  55. const BITMAPS bitmap;
  56. };
  57. /*
  58. * Conversion map between LINE_STYLE values and style names displayed
  59. */
  60. extern const std::map<LINE_STYLE, struct LINE_STYLE_DESC> lineTypeNames;
  61. #define DEFAULT_STYLE _( "Default" )
  62. #define INDETERMINATE_STYLE _( "Leave unchanged" )
  63. /**
  64. * Simple container to manage line stroke parameters.
  65. */
  66. class STROKE_PARAMS
  67. {
  68. public:
  69. STROKE_PARAMS( int aWidth = 0, LINE_STYLE aLineStyle = LINE_STYLE::DEFAULT,
  70. const KIGFX::COLOR4D& aColor = KIGFX::COLOR4D::UNSPECIFIED ) :
  71. m_width( aWidth ),
  72. m_lineStyle( aLineStyle ),
  73. m_color( aColor )
  74. {
  75. }
  76. int GetWidth() const { return m_width; }
  77. void SetWidth( int aWidth ) { m_width = aWidth; }
  78. LINE_STYLE GetLineStyle() const { return m_lineStyle; }
  79. void SetLineStyle( LINE_STYLE aLineStyle ) { m_lineStyle = aLineStyle; }
  80. KIGFX::COLOR4D GetColor() const { return m_color; }
  81. void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
  82. bool operator!=( const STROKE_PARAMS& aOther )
  83. {
  84. return m_width != aOther.m_width
  85. || m_lineStyle != aOther.m_lineStyle
  86. || m_color != aOther.m_color;
  87. }
  88. void Format( OUTPUTFORMATTER* out, const EDA_IU_SCALE& aIuScale, int nestLevel ) const;
  89. void GetMsgPanelInfo( UNITS_PROVIDER* aUnitsProvider, std::vector<MSG_PANEL_ITEM>& aList,
  90. bool aIncludeStyle = true, bool aIncludeWidth = true );
  91. // Helper functions
  92. static wxString GetLineStyleToken( LINE_STYLE aStyle );
  93. static void Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWidth,
  94. const KIGFX::RENDER_SETTINGS* aRenderSettings,
  95. const std::function<void( const VECTOR2I& a, const VECTOR2I& b )>& aStroker );
  96. private:
  97. int m_width;
  98. LINE_STYLE m_lineStyle;
  99. KIGFX::COLOR4D m_color;
  100. };
  101. class STROKE_PARAMS_PARSER : public STROKE_PARAMS_LEXER
  102. {
  103. public:
  104. STROKE_PARAMS_PARSER( LINE_READER* aReader, int iuPerMM ) :
  105. STROKE_PARAMS_LEXER( aReader ),
  106. m_iuPerMM( iuPerMM )
  107. {
  108. }
  109. void ParseStroke( STROKE_PARAMS& aStroke );
  110. private:
  111. int parseInt( const char* aText );
  112. double parseDouble( const char* aText );
  113. private:
  114. int m_iuPerMM;
  115. };
  116. #endif // STROKE_PARAMS_H