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.

214 lines
7.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file info3d_visu.h
  27. */
  28. #ifndef __INFO3D_VISU_H__
  29. #define __INFO3D_VISU_H__
  30. #include <layers_id_colors_and_visibility.h> // Layers id definitions
  31. #include <wx/glcanvas.h>
  32. #ifdef __WXMAC__
  33. # ifdef __DARWIN__
  34. # include <OpenGL/glu.h>
  35. # else
  36. # include <glu.h>
  37. # endif
  38. #else
  39. # include <GL/glu.h>
  40. #endif
  41. #include <3d_struct.h>
  42. #define m_ROTX m_Rot[0]
  43. #define m_ROTY m_Rot[1]
  44. #define m_ROTZ m_Rot[2]
  45. class BOARD_DESIGN_SETTINGS;
  46. /** Minor class to store a 3D color (R, G, B) 3 floats range 0 to 1.0
  47. */
  48. class S3D_COLOR
  49. {
  50. public:
  51. double m_Red, m_Green, m_Blue;
  52. public: S3D_COLOR()
  53. {
  54. m_Red = m_Green = m_Blue = 0;
  55. }
  56. };
  57. enum DISPLAY3D_FLG {
  58. FL_AXIS=0, FL_MODULE, FL_ZONE,
  59. FL_ADHESIVE, FL_SILKSCREEN, FL_SOLDERMASK, FL_SOLDERPASTE,
  60. FL_COMMENTS, FL_ECO,
  61. FL_GRID,
  62. FL_USE_COPPER_THICKNESS,
  63. FL_SHOW_BOARD_BODY,
  64. FL_MOUSEWHEEL_PANNING,
  65. FL_USE_REALISTIC_MODE,
  66. FL_RENDER_SHADOWS,
  67. FL_RENDER_SHOW_HOLES_IN_ZONES,
  68. FL_RENDER_TEXTURES,
  69. FL_RENDER_SMOOTH_NORMALS,
  70. FL_RENDER_USE_MODEL_NORMALS,
  71. FL_RENDER_MATERIAL,
  72. FL_RENDER_SHOW_MODEL_BBOX,
  73. FL_LAST
  74. };
  75. /** Helper class to handle information needed to display 3D board
  76. */
  77. class INFO3D_VISU
  78. {
  79. public:
  80. double m_Beginx, m_Beginy; // position of mouse (used in drag commands)
  81. double m_Quat[4]; // orientation of 3D view
  82. double m_Rot[4]; // rotation parameters of 3D view
  83. double m_Zoom; // 3D zoom value
  84. double m_3D_Grid; // 3D grid value, in mm
  85. S3D_COLOR m_BgColor;
  86. S3D_COLOR m_BgColor_Top;
  87. S3D_COLOR m_BoardBodyColor; // in realistic mode: FR4 board color
  88. S3D_COLOR m_SolderMaskColor; // in realistic mode: solder mask color
  89. S3D_COLOR m_SolderPasteColor; // in realistic mode: solder paste color
  90. S3D_COLOR m_SilkScreenColor; // in realistic mode: SilkScreen color
  91. S3D_COLOR m_CopperColor; // in realistic mode: copper color
  92. wxPoint m_BoardPos; // center board actual position in board units
  93. wxSize m_BoardSize; // board actual size in board units
  94. int m_CopperLayersCount; // Number of copper layers actually used by the board
  95. const BOARD_DESIGN_SETTINGS* m_BoardSettings; // Link to current board design settings
  96. double m_BiuTo3Dunits; // Normalization scale to convert board
  97. // internal units to 3D units
  98. // to normalize 3D units between -1.0 and +1.0
  99. double zpos_offset;
  100. private:
  101. double m_layerZcoord[LAYER_ID_COUNT]; // Z position of each layer (normalized)
  102. double m_copperThickness; // Copper thickness (normalized)
  103. double m_epoxyThickness; // Epoxy thickness (normalized)
  104. double m_nonCopperLayerThickness; // Non copper layers thickness
  105. std::bitset<FL_LAST> m_drawFlags; // Enable/disable flags (see DISPLAY3D_FLG list)
  106. public: INFO3D_VISU();
  107. ~INFO3D_VISU();
  108. // Accessors
  109. bool GetFlag( DISPLAY3D_FLG aFlag ) const { return m_drawFlags[aFlag]; }
  110. void SetFlag( DISPLAY3D_FLG aFlag, bool aState )
  111. {
  112. m_drawFlags[aFlag] = aState;
  113. }
  114. /**
  115. * Initialize 3D Parameters depending on aBoard
  116. * @param aBoard: the board to display
  117. */
  118. void InitSettings( BOARD* aBoard );
  119. /**
  120. * @return the Z position of 3D shapes, in 3D Units
  121. * @param aIsFlipped: true for modules on Front (top) layer, false
  122. * if on back (bottom) layer
  123. */
  124. double GetModulesZcoord3DIU( bool aIsFlipped );
  125. /**
  126. * @return the Z coordinate of the layer aLayer, in Board Internal Units
  127. * @param aLayerId: the layer number
  128. */
  129. int GetLayerZcoordBIU( int aLayerId )
  130. {
  131. return KiROUND( m_layerZcoord[aLayerId] / m_BiuTo3Dunits );
  132. }
  133. /**
  134. * @return the thickness (Z size) of the copper, in Board Internal Units
  135. * note: the thickness (Z size) of the copper is not the thickness
  136. * of the layer (the thickness of the layer is the epoxy thickness / layer count)
  137. *
  138. * Note: if m_drawFlags[FL_USE_COPPER_THICKNESS] is not set,
  139. * and normal mode, returns 0
  140. */
  141. int GetCopperThicknessBIU() const
  142. {
  143. bool use_thickness = GetFlag( FL_USE_COPPER_THICKNESS );
  144. return use_thickness ?
  145. KiROUND( m_copperThickness / m_BiuTo3Dunits )
  146. : 0;
  147. }
  148. /**
  149. * function GetEpoxyThicknessBIU
  150. * @return the thickness (Z size) of the epoxy board, in Board Internal Units
  151. */
  152. int GetEpoxyThicknessBIU() const
  153. {
  154. return KiROUND( m_epoxyThickness / m_BiuTo3Dunits );
  155. }
  156. /**
  157. * function GetNonCopperLayerThicknessBIU
  158. * @return the thickness (Z size) of a technical layer,
  159. * in Board Internal Units
  160. *
  161. * Note: if m_drawFlags[FL_USE_COPPER_THICKNESS] is not set, returns 0
  162. */
  163. int GetNonCopperLayerThicknessBIU() const
  164. {
  165. bool use_thickness = GetFlag( FL_USE_COPPER_THICKNESS );
  166. return use_thickness ?
  167. KiROUND( m_nonCopperLayerThickness / m_BiuTo3Dunits )
  168. : 0;
  169. }
  170. /**
  171. * function GetNonCopperLayerThicknessBIU
  172. * @return the thickness (Z size) of the copper or a technical layer,
  173. * in Board Internal Units, depending on the layer id
  174. *
  175. * Note: if m_drawFlags[FL_USE_COPPER_THICKNESS] is not set, returns 0
  176. */
  177. int GetLayerObjectThicknessBIU( int aLayerId ) const
  178. {
  179. return IsCopperLayer( aLayerId ) ?
  180. GetCopperThicknessBIU() :
  181. GetNonCopperLayerThicknessBIU();
  182. }
  183. bool IsRealisticMode() { return GetFlag( FL_USE_REALISTIC_MODE ); }
  184. };
  185. extern INFO3D_VISU g_Parm_3D_Visu;
  186. #endif /* __INFO3D_VISU_H__ */