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.

173 lines
6.4 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. * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef OCE_VIS_OCE_UTILS_H
  25. #define OCE_VIS_OCE_UTILS_H
  26. #include <list>
  27. #include <map>
  28. #include <string>
  29. #include <utility>
  30. #include <vector>
  31. #include "base.h"
  32. #include "kicadpcb.h"
  33. #include "kicadcurve.h"
  34. #include <BRepBuilderAPI_MakeWire.hxx>
  35. #include <TDocStd_Document.hxx>
  36. #include <XCAFApp_Application.hxx>
  37. #include <XCAFDoc_ShapeTool.hxx>
  38. #include <TopoDS_Shape.hxx>
  39. #include <TopoDS_Edge.hxx>
  40. typedef std::pair< std::string, TDF_Label > MODEL_DATUM;
  41. typedef std::map< std::string, TDF_Label > MODEL_MAP;
  42. class KICADPAD;
  43. class OUTLINE
  44. {
  45. public:
  46. OUTLINE();
  47. virtual ~OUTLINE();
  48. void Clear();
  49. // attempt to add a curve to the outline; on success returns true
  50. bool AddSegment( const KICADCURVE& aCurve );
  51. bool IsClosed()
  52. {
  53. return m_closed;
  54. }
  55. void SetMinSqDistance( double aDistance )
  56. {
  57. m_minDistance2 = aDistance;
  58. }
  59. bool MakeShape( TopoDS_Shape& aShape, double aThickness );
  60. private:
  61. bool addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBLET& aLastPoint );
  62. bool testClosed( const KICADCURVE& aFrontCurve, const KICADCURVE& aBackCurve );
  63. public:
  64. std::list< KICADCURVE > m_curves; // list of contiguous segments
  65. private:
  66. bool m_closed; // set true if the loop is closed
  67. double m_minDistance2; // min squared distance to treat points as separate entities (mm)
  68. };
  69. class PCBMODEL
  70. {
  71. public:
  72. PCBMODEL( const wxString& aPcbName );
  73. virtual ~PCBMODEL();
  74. // add an outline segment (must be in final position)
  75. bool AddOutlineSegment( KICADCURVE* aCurve );
  76. // add a pad hole or slot (must be in final position)
  77. bool AddPadHole( const KICADPAD* aPad );
  78. // add a component at the given position and orientation
  79. bool AddComponent( const std::string& aFileName, const std::string& aRefDes,
  80. bool aBottom, DOUBLET aPosition, double aRotation,
  81. TRIPLET aOffset, TRIPLET aOrientation, TRIPLET aScale,
  82. bool aSubstituteModels = true );
  83. void SetBoardColor( double r, double g, double b );
  84. // set the thickness of the PCB (mm); the top of the PCB shall be at Z = aThickness
  85. // aThickness < 0.0 == use default thickness
  86. // aThickness <= THICKNESS_MIN == use THICKNESS_MIN
  87. // aThickness > THICKNESS_MIN == use aThickness
  88. void SetPCBThickness( double aThickness );
  89. // Set the minimum distance (in mm) to consider 2 points have the same coordinates
  90. void SetMinDistance( double aDistance );
  91. // create the PCB model using the current outlines and drill holes
  92. bool CreatePCB();
  93. #ifdef SUPPORTS_IGES
  94. // write the assembly model in IGES format
  95. bool WriteIGES( const wxString& aFileName );
  96. #endif
  97. // write the assembly model in STEP format
  98. bool WriteSTEP( const wxString& aFileName );
  99. private:
  100. /**
  101. * Load a 3D model data.
  102. *
  103. * @param aFileNameUTF8 is the filename encoded UTF8 (different formats allowed)
  104. * but for WRML files a model data can be loaded instead of the vrml data,
  105. * not suitable in a step file.
  106. * @param aScale is the X,Y,Z scaling factors.
  107. * @param aLabel is the TDF_Label to store the data.
  108. * @param aSubstituteModels = true to allows data substitution, false to disallow.
  109. * @param aErrorMessage (can be nullptr) is an error message to be displayed on error.
  110. * @return true if successfully loaded, false on error.
  111. */
  112. bool getModelLabel( const std::string& aFileNameUTF8, TRIPLET aScale, TDF_Label& aLabel,
  113. bool aSubstituteModels, wxString* aErrorMessage = nullptr );
  114. bool getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation, TRIPLET aOffset,
  115. TRIPLET aOrientation, TopLoc_Location& aLocation );
  116. bool readIGES( Handle( TDocStd_Document )& m_doc, const char* fname );
  117. bool readSTEP( Handle( TDocStd_Document )& m_doc, const char* fname );
  118. TDF_Label transferModel( Handle( TDocStd_Document )& source,
  119. Handle( TDocStd_Document )& dest, TRIPLET aScale );
  120. Handle( XCAFApp_Application ) m_app;
  121. Handle( TDocStd_Document ) m_doc;
  122. Handle( XCAFDoc_ShapeTool ) m_assy;
  123. TDF_Label m_assy_label;
  124. bool m_hasPCB; // set true if CreatePCB() has been invoked
  125. TDF_Label m_pcb_label; // label for the PCB model
  126. MODEL_MAP m_models; // map of file names to model labels
  127. int m_components; // number of successfully loaded components;
  128. double m_precision; // model (length unit) numeric precision
  129. double m_angleprec; // angle numeric precision
  130. double m_boardColor[3];// RGB values
  131. double m_thickness; // PCB thickness, mm
  132. double m_minx; // leftmost curve point
  133. double m_minDistance2; // minimum squared distance between items (mm)
  134. std::list<KICADCURVE>::iterator m_mincurve; // iterator to the leftmost curve
  135. std::list<KICADCURVE> m_curves;
  136. std::vector<TopoDS_Shape> m_cutouts;
  137. wxString m_pcbName; // name of the PCB, which will most likely be the file name of the path
  138. };
  139. #endif // OCE_VIS_OCE_UTILS_H