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.

111 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
  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. /**
  24. * @file base.h
  25. * provides declarations of items which are basic to all
  26. * kicad2mcad code.
  27. */
  28. #ifndef KICADBASE_H
  29. #define KICADBASE_H
  30. #include <core/optional.h>
  31. #include <ostream>
  32. ///> Minimum distance between points to treat them as separate ones (mm)
  33. static constexpr double MIN_DISTANCE = 0.001;
  34. namespace SEXPR
  35. {
  36. class SEXPR;
  37. }
  38. enum CURVE_TYPE
  39. {
  40. CURVE_NONE = 0, // invalid curve
  41. CURVE_LINE,
  42. CURVE_ARC,
  43. CURVE_CIRCLE
  44. };
  45. /*
  46. * Layers of importance to MCAD export:
  47. * LAYER_TOP: specifies that a module is on the top of the PCB
  48. * LAYER_BOTTOM: specifies that a module is on the bottom of the PCB
  49. * LAYER_EDGE: specifies that a Curve is associated with the PCB edge
  50. */
  51. enum LAYERS
  52. {
  53. LAYER_NONE = 0, // no layer specified (bad object)
  54. LAYER_TOP, // top side
  55. LAYER_BOTTOM, // bottom side
  56. LAYER_EDGE // edge data
  57. };
  58. struct DOUBLET
  59. {
  60. double x;
  61. double y;
  62. DOUBLET() : x( 0.0 ), y( 0.0 ) { return; }
  63. DOUBLET( double aX, double aY ) : x( aX ), y( aY ) { return; }
  64. };
  65. std::ostream& operator<<( std::ostream& aStream, const DOUBLET& aDoublet );
  66. struct TRIPLET
  67. {
  68. double x;
  69. double y;
  70. union
  71. {
  72. double z;
  73. double angle;
  74. };
  75. TRIPLET() : x( 0.0 ), y( 0.0 ), z( 0.0 ) { return; }
  76. TRIPLET( double aX, double aY, double aZ ) : x( aX ), y( aY ), z( aZ ) { return; }
  77. };
  78. std::ostream& operator<<( std::ostream& aStream, const TRIPLET& aTriplet );
  79. bool Get2DPositionAndRotation( SEXPR::SEXPR* data, DOUBLET& aPosition, double& aRotation );
  80. bool Get2DCoordinate( SEXPR::SEXPR* data, DOUBLET& aCoordinate );
  81. bool Get3DCoordinate( SEXPR::SEXPR* data, TRIPLET& aCoordinate );
  82. bool GetXYZRotation( SEXPR::SEXPR* data, TRIPLET& aRotation );
  83. /**
  84. * Get the layer name from a layer element, if the layer is syntactically
  85. * valid.
  86. *
  87. * E.g. (layer "Edge.Cuts") -> "Edge.Cuts"
  88. *
  89. * @param aLayerElem the s-expr element to get the name from
  90. * @return the layer name if valid, else empty
  91. */
  92. OPT<std::string> GetLayerName( const SEXPR::SEXPR& aLayerElem );
  93. #endif // KICADBASE_H