KiCad PCB EDA Suite
exporter_vrml.h
Go to the documentation of this file.
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 
24 #pragma once
25 
26 // offset for art layers, mm (silk, paste, etc)
27 #define ART_OFFSET 0.025
28 // offset for plating
29 #define PLATE_OFFSET 0.005
30 
31 
33 {
40  VRML_COLOR_LAST // Sentinel
41 };
42 
43 
44 struct VRML_COLOR
45 {
46  float diffuse_red;
47  float diffuse_grn;
48  float diffuse_blu;
49 
50  float spec_red;
51  float spec_grn;
52  float spec_blu;
53 
54  float emit_red;
55  float emit_grn;
56  float emit_blu;
57 
58  float ambient;
59  float transp;
60  float shiny;
61 
63  {
64  // default green
65  diffuse_red = 0.13f;
66  diffuse_grn = 0.81f;
67  diffuse_blu = 0.22f;
68  spec_red = 0.01f;
69  spec_grn = 0.08f;
70  spec_blu = 0.02f;
71  emit_red = 0.0f;
72  emit_grn = 0.0f;
73  emit_blu = 0.0f;
74 
75  ambient = 0.8f;
76  transp = 0.0f;
77  shiny = 0.02f;
78  }
79 
80  VRML_COLOR( float dr, float dg, float db,
81  float sr, float sg, float sb,
82  float er, float eg, float eb,
83  float am, float tr, float sh )
84  {
85  diffuse_red = dr;
86  diffuse_grn = dg;
87  diffuse_blu = db;
88  spec_red = sr;
89  spec_grn = sg;
90  spec_blu = sb;
91  emit_red = er;
92  emit_grn = eg;
93  emit_blu = eb;
94 
95  ambient = am;
96  transp = tr;
97  shiny = sh;
98  }
99 };
100 
101 
102 // Handle the board ans its board items to convert them to a VRML representation:
104 {
105 private:
108  SHAPE_POLY_SET m_pcbOutlines; // stores the board main outlines
109 
110  int m_precision; // precision factor when exportin fp shapes
111  // to separate files
113 
114 public:
116  VRML_LAYER m_holes;
117  VRML_LAYER m_3D_board;
118  VRML_LAYER m_top_copper;
119  VRML_LAYER m_bot_copper;
120  VRML_LAYER m_top_silk;
121  VRML_LAYER m_bot_silk;
122  VRML_LAYER m_top_soldermask;
123  VRML_LAYER m_bot_soldermask;
124  VRML_LAYER m_top_paste;
125  VRML_LAYER m_bot_paste;
126  VRML_LAYER m_plated_holes;
127 
128  std::list< SGNODE* > m_components;
131 
132  /* true to use VRML inline{} syntax for footprint 3D models, like:
133  * Inline { url "F:/tmp/pic_programmer/shapes3D/DIP-18_W7.62mm_Socket.wrl" }
134  * false to merge VRML 3D modeles in the .wrl board file
135  */
137 
138  // 3D subdirectory to copy footprint vrml 3D models when not merged in board file
140 
141  // true to use relative paths in VRML inline{} for footprint 3D models
142  // used only if m_UseInlineModelsInBrdfile = true
144 
145  // true to reuse component definitions
147 
148  // scaling from 0.1 inch to desired VRML unit
149  double m_WorldScale = 1.0;
150 
151  // scaling from mm to desired VRML world scale
153 
154  double m_tx; // global translation along X
155  double m_ty; // global translation along Y
156 
157  double m_brd_thickness; // depth of the PCB
158 
161 
163  {
164  return vrml_colors_list[aIndex];
165  }
166 
167  void SetOffset( double aXoff, double aYoff );
168 
169  double GetLayerZ( LAYER_NUM aLayer )
170  {
171  if( unsigned( aLayer ) >= arrayDim( m_layer_z ) )
172  return 0;
173 
174  return m_layer_z[ aLayer ];
175  }
176 
177  void SetLayerZ( LAYER_NUM aLayer, double aValue )
178  {
179  m_layer_z[aLayer] = aValue;
180  }
181 
182  // set the scaling of the VRML world
183  bool SetScale( double aWorldScale );
184 
185  // Build and export the solder mask layer, that is a negative layer
186  void ExportVrmlSolderMask();
187 
188  // Build and export the 4 layers F_Cu, B_Cu, F_SilkS, B_SilkS
189  void ExportStandardLayers();
190 
191  void ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile );
192 
193  // Build and exports the board outlines (board body)
194  void ExportVrmlBoard();
195 
196  void ExportVrmlVia( const VIA* aVia );
197 
198  // Export all via holes
199  void ExportVrmlViaHoles();
200 
201  void ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName );
202 
203  void ExportVrmlPadHole( PAD* aPad );
204 
205  // Exoprt a set of polygons without holes.
206  // Polygons in SHAPE_POLY_SET must be without hole, i.e. holes must be linked
207  // previously to their main outline.
208  void ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines );
209 
210  void writeLayers( const char* aFileName, OSTREAM* aOutputFile );
211 
212  // select the VRML layer object to draw on
213  // return true if a layer has been selected.
214  bool GetLayer3D( LAYER_NUM layer, VRML_LAYER** vlayer );
215 
216  // Build the Z position of 3D layers
217  void ComputeLayer3D_Zpos();
218 
219 private:
220  void write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor,
221  VRML_LAYER* aLayer, bool aPlane, bool aTop,
222  double aTop_z, double aBottom_z );
223 
224  void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
225  VRML_LAYER* layer, double top_z, double bottom_z );
226 
227  void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
228  VRML_LAYER* layer, double aHeight, bool aTopPlane );
229 
230  SGNODE* getSGColor( VRML_COLOR_INDEX colorIdx );
231 };
Definition: track.h:343
void ExportVrmlFootprint(FOOTPRINT *aFootprint, std::ostream *aOutputFile)
IFSG_TRANSFORM m_OutputPCB
VRML_LAYER m_plated_holes
double GetLayerZ(LAYER_NUM aLayer)
std::list< SGNODE * > m_components
void ExportVrmlPadHole(PAD *aPad)
float transp
Definition: exporter_vrml.h:59
void ExportVrmlVia(const VIA *aVia)
VRML_COLOR vrml_colors_list[VRML_COLOR_LAST]
VRML_COLOR_INDEX
Definition: exporter_vrml.h:32
#define OSTREAM
void SetLayerZ(LAYER_NUM aLayer, double aValue)
SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
Cache for storing the 3D shapes.
Definition: 3d_cache.h:52
float spec_blu
Definition: exporter_vrml.h:52
VRML_LAYER m_top_silk
VRML_LAYER m_top_copper
void ExportFp3DModelsAsLinkedFile(const wxString &aFullFileName)
VRML_LAYER m_bot_silk
VRML_LAYER m_bot_soldermask
void write_triangle_bag(std::ostream &aOut_file, const VRML_COLOR &aColor, VRML_LAYER *aLayer, bool aPlane, bool aTop, double aTop_z, double aBottom_z)
void writeLayers(const char *aFileName, OSTREAM *aOutputFile)
float ambient
Definition: exporter_vrml.h:58
float diffuse_grn
Definition: exporter_vrml.h:47
wxString m_Subdir3DFpModels
VRML_LAYER m_bot_copper
bool m_UseRelPathIn3DModelFilename
Represent a set of closed polygons.
void ComputeLayer3D_Zpos()
VRML_LAYER m_top_soldermask
VRML_COLOR & GetColor(VRML_COLOR_INDEX aIndex)
bool GetLayer3D(LAYER_NUM layer, VRML_LAYER **vlayer)
float spec_red
Definition: exporter_vrml.h:50
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void create_vrml_shell(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double top_z, double bottom_z)
void create_vrml_plane(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double aHeight, bool aTopPlane)
SGNODE * m_sgmaterial[VRML_COLOR_LAST]
float spec_grn
Definition: exporter_vrml.h:51
int LAYER_NUM
This can be replaced with int and removed.
float emit_grn
Definition: exporter_vrml.h:55
void ExportVrmlSolderMask()
bool SetScale(double aWorldScale)
SHAPE_POLY_SET m_pcbOutlines
float emit_blu
Definition: exporter_vrml.h:56
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
float diffuse_red
Definition: exporter_vrml.h:46
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
S3D_CACHE * m_Cache3Dmodels
void SetOffset(double aXoff, double aYoff)
VRML_LAYER m_bot_paste
VRML_LAYER m_holes
void ExportStandardLayers()
VRML_LAYER m_top_paste
Definition: pad.h:60
VRML_LAYER m_3D_board
float emit_red
Definition: exporter_vrml.h:54
float diffuse_blu
Definition: exporter_vrml.h:48
bool m_UseInlineModelsInBrdfile
void ExportVrmlPolygonSet(VRML_LAYER *aVlayer, const SHAPE_POLY_SET &aOutlines)
VRML_COLOR(float dr, float dg, float db, float sr, float sg, float sb, float er, float eg, float eb, float am, float tr, float sh)
Definition: exporter_vrml.h:80
double m_layer_z[PCB_LAYER_ID_COUNT]