KiCad PCB EDA Suite
export_vrml.cpp File Reference
#include <cmath>
#include <exception>
#include <fstream>
#include <iomanip>
#include <vector>
#include <wx/dir.h>
#include "3d_cache/3d_cache.h"
#include "3d_cache/3d_info.h"
#include "class_board.h"
#include "class_edge_mod.h"
#include "class_module.h"
#include "class_pcb_text.h"
#include "class_track.h"
#include "class_zone.h"
#include "convert_to_biu.h"
#include "draw_graphic_text.h"
#include "macros.h"
#include "pgm_base.h"
#include "plugins/3dapi/ifsg_all.h"
#include "streamwrapper.h"
#include "vrml_layer.h"
#include "pcb_edit_frame.h"
#include "../../kicad/kicad.h"
#include <convert_basic_shapes_to_polygon.h>
#include <zone_filler.h>

Go to the source code of this file.

Classes

struct  VRML_COLOR
 
class  MODEL_VRML
 

Macros

#define MIN_VRML_LINEWIDTH   0.05
 
#define ART_OFFSET   0.025
 
#define PLATE_OFFSET   0.005
 

Enumerations

enum  VRML_COLOR_INDEX {
  VRML_COLOR_NONE = -1, VRML_COLOR_PCB = 0, VRML_COLOR_TRACK, VRML_COLOR_SILK,
  VRML_COLOR_TIN, VRML_COLOR_LAST
}
 

Functions

static bool GetLayer (MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
 
static void create_vrml_shell (IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double top_z, double bottom_z)
 
static void create_vrml_plane (IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double aHeight, bool aTopPlane)
 
static void write_triangle_bag (std::ostream &aOut_file, VRML_COLOR &aColor, VRML_LAYER *aLayer, bool aPlane, bool aTop, double aTop_z, double aBottom_z)
 
static void write_layers (MODEL_VRML &aModel, BOARD *aPcb, const char *aFileName, OSTREAM *aOutputFile)
 
static void compute_layer_Zs (MODEL_VRML &aModel, BOARD *pcb)
 
static void export_vrml_line (MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
 
static void export_vrml_circle (MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
 
static void export_vrml_arc (MODEL_VRML &aModel, LAYER_NUM layer, double centerx, double centery, double arc_startx, double arc_starty, double width, double arc_angle)
 
static void export_vrml_polygon (MODEL_VRML &aModel, LAYER_NUM layer, DRAWSEGMENT *aOutline, double aOrientation, wxPoint aPos)
 
static void export_vrml_drawsegment (MODEL_VRML &aModel, DRAWSEGMENT *drawseg)
 
static void vrml_text_callback (int x0, int y0, int xf, int yf, void *aData)
 
static void export_vrml_pcbtext (MODEL_VRML &aModel, TEXTE_PCB *text)
 
static void export_vrml_drawings (MODEL_VRML &aModel, BOARD *pcb)
 
static void export_vrml_board (MODEL_VRML &aModel, BOARD *aPcb)
 
static void export_round_padstack (MODEL_VRML &aModel, BOARD *pcb, double x, double y, double r, LAYER_NUM bottom_layer, LAYER_NUM top_layer, double hole)
 
static void export_vrml_via (MODEL_VRML &aModel, BOARD *aPcb, const VIA *aVia)
 
static void export_vrml_tracks (MODEL_VRML &aModel, BOARD *pcb)
 
static void export_vrml_zones (MODEL_VRML &aModel, BOARD *aPcb)
 
static void export_vrml_text_module (TEXTE_MODULE *module)
 
static void export_vrml_edge_module (MODEL_VRML &aModel, EDGE_MODULE *aOutline, MODULE *aModule)
 
static void export_vrml_padshape (MODEL_VRML &aModel, VRML_LAYER *aTinLayer, D_PAD *aPad)
 
static void export_vrml_pad (MODEL_VRML &aModel, BOARD *aPcb, D_PAD *aPad)
 
static void build_quat (double x, double y, double z, double a, double q[4])
 
static void from_quat (double q[4], double rot[4])
 
static void compose_quat (double q1[4], double q2[4], double qr[4])
 
static void export_vrml_module (MODEL_VRML &aModel, BOARD *aPcb, MODULE *aModule, std::ostream *aOutputFile)
 
static SGNODEgetSGColor (VRML_COLOR_INDEX colorIdx)
 

Variables

static S3D_CACHEcache
 
static bool USE_INLINES
 
static bool USE_DEFS
 
static bool USE_RELPATH
 
static double WORLD_SCALE = 1.0
 
static double BOARD_SCALE
 
static const int PRECISION = 6
 
static wxString SUBDIR_3D
 
static wxString PROJ_DIR
 
static VRML_COLOR colors [VRML_COLOR_LAST]
 
static SGNODEsgmaterial [VRML_COLOR_LAST] = { NULL }
 
static MODEL_VRMLmodel_vrml
 

Macro Definition Documentation

◆ ART_OFFSET

#define ART_OFFSET   0.025

Definition at line 60 of file export_vrml.cpp.

◆ MIN_VRML_LINEWIDTH

#define MIN_VRML_LINEWIDTH   0.05

Definition at line 57 of file export_vrml.cpp.

◆ PLATE_OFFSET

#define PLATE_OFFSET   0.005

Definition at line 62 of file export_vrml.cpp.

Enumeration Type Documentation

◆ VRML_COLOR_INDEX

Enumerator
VRML_COLOR_NONE 
VRML_COLOR_PCB 
VRML_COLOR_TRACK 
VRML_COLOR_SILK 
VRML_COLOR_TIN 
VRML_COLOR_LAST 

Definition at line 131 of file export_vrml.cpp.

Function Documentation

◆ build_quat()

static void build_quat ( double  x,
double  y,
double  z,
double  a,
double  q[4] 
)
static

Definition at line 1298 of file export_vrml.cpp.

1299 {
1300  double sina = sin( a / 2 );
1301 
1302  q[0] = x * sina;
1303  q[1] = y * sina;
1304  q[2] = z * sina;
1305  q[3] = cos( a / 2 );
1306 }

Referenced by export_vrml_module().

◆ compose_quat()

static void compose_quat ( double  q1[4],
double  q2[4],
double  qr[4] 
)
static

Definition at line 1322 of file export_vrml.cpp.

1323 {
1324  double tmp[4];
1325 
1326  tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
1327  tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
1328  tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
1329  tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
1330 
1331  qr[0] = tmp[0];
1332  qr[1] = tmp[1];
1333  qr[2] = tmp[2];
1334  qr[3] = tmp[3];
1335 }

Referenced by export_vrml_module().

◆ compute_layer_Zs()

static void compute_layer_Zs ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 563 of file export_vrml.cpp.

564 {
565  int copper_layers = pcb->GetCopperLayerCount();
566 
567  // We call it 'layer' thickness, but it's the whole board thickness!
569  double half_thickness = aModel.m_brd_thickness / 2;
570 
571  // Compute each layer's Z value, more or less like the 3d view
572  for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq )
573  {
574  PCB_LAYER_ID i = *seq;
575 
576  if( i < copper_layers )
577  aModel.SetLayerZ( i, half_thickness - aModel.m_brd_thickness * i / (copper_layers - 1) );
578  else
579  aModel.SetLayerZ( i, - half_thickness ); // bottom layer
580  }
581 
582  /* To avoid rounding interference, we apply an epsilon to each
583  * successive layer */
584  double epsilon_z = Millimeter2iu( ART_OFFSET ) * BOARD_SCALE;
585  aModel.SetLayerZ( B_Paste, -half_thickness - epsilon_z * 4 );
586  aModel.SetLayerZ( B_Adhes, -half_thickness - epsilon_z * 3 );
587  aModel.SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 2 );
588  aModel.SetLayerZ( B_Mask, -half_thickness - epsilon_z );
589  aModel.SetLayerZ( F_Mask, half_thickness + epsilon_z );
590  aModel.SetLayerZ( F_SilkS, half_thickness + epsilon_z * 2 );
591  aModel.SetLayerZ( F_Adhes, half_thickness + epsilon_z * 3 );
592  aModel.SetLayerZ( F_Paste, half_thickness + epsilon_z * 4 );
593  aModel.SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
594  aModel.SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
595  aModel.SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
596  aModel.SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
597  aModel.SetLayerZ( Edge_Cuts, 0 );
598 }
void SetLayerZ(LAYER_NUM aLayer, double aValue)
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
static double BOARD_SCALE
Definition: export_vrml.cpp:69
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:534
PCB_LAYER_ID
A quick note on layer IDs:
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
size_t i
Definition: json11.cpp:597
int GetCopperLayerCount() const
Function GetCopperLayerCount.
double m_brd_thickness
#define ART_OFFSET
Definition: export_vrml.cpp:60

References LSET::AllCuMask(), ART_OFFSET, B_Adhes, B_Mask, B_Paste, B_SilkS, BOARD_SCALE, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Mask, F_Paste, F_SilkS, BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetCopperLayerCount(), BOARD::GetDesignSettings(), i, MODEL_VRML::m_brd_thickness, and MODEL_VRML::SetLayerZ().

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ create_vrml_plane()

static void create_vrml_plane ( IFSG_TRANSFORM PcbOutput,
VRML_COLOR_INDEX  colorID,
VRML_LAYER *  layer,
double  aHeight,
bool  aTopPlane 
)
static

Definition at line 1696 of file export_vrml.cpp.

1698 {
1699  std::vector< double > vertices;
1700  std::vector< int > idxPlane;
1701  std::vector< int > idxSide;
1702 
1703  if( !(*layer).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
1704  {
1705 #ifdef DEBUG
1706  do {
1707  std::ostringstream ostr;
1708  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1709  ostr << " * [INFO] no vertex data";
1710  wxLogDebug( "%s\n", ostr.str().c_str() );
1711  } while( 0 );
1712 #endif
1713 
1714  return;
1715  }
1716 
1717  if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
1718  {
1719 #ifdef DEBUG
1720  do {
1721  std::ostringstream ostr;
1722  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1723  ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
1724  wxLogDebug( "%s\n", ostr.str().c_str() );
1725  } while( 0 );
1726 #endif
1727 
1728  throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
1729  }
1730 
1731  std::vector< SGPOINT > vlist;
1732  size_t nvert = vertices.size() / 3;
1733  size_t j = 0;
1734 
1735  for( size_t i = 0; i < nvert; ++i, j+= 3 )
1736  vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
1737 
1738  // create the intermediate scenegraph
1739  IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
1740  IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
1741  IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
1742  IFSG_COORDS cp( face ); // coordinates for all faces
1743  cp.SetCoordsList( nvert, &vlist[0] );
1744  IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
1745  coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
1746  IFSG_NORMALS norms( face ); // normals for the top and bottom planes
1747 
1748  // set the normals
1749  if( aTopPlane )
1750  {
1751  for( size_t i = 0; i < nvert; ++i )
1752  norms.AddNormal( 0.0, 0.0, 1.0 );
1753  }
1754  else
1755  {
1756  for( size_t i = 0; i < nvert; ++i )
1757  norms.AddNormal( 0.0, 0.0, -1.0 );
1758  }
1759 
1760  // assign a color from the palette
1761  SGNODE* modelColor = getSGColor( colorID );
1762 
1763  if( NULL != modelColor )
1764  {
1765  if( NULL == S3D::GetSGNodeParent( modelColor ) )
1766  shape.AddChildNode( modelColor );
1767  else
1768  shape.AddRefNode( modelColor );
1769  }
1770 
1771  return;
1772 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
Class IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
Class IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
Class IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
static SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
Class IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
size_t i
Definition: json11.cpp:597
Class IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NORMALS::AddNormal(), IFSG_NODE::GetRawPtr(), getSGColor(), S3D::GetSGNodeParent(), i, IFSG_COORDS::SetCoordsList(), and IFSG_INDEX::SetIndices().

Referenced by write_layers().

◆ create_vrml_shell()

static void create_vrml_shell ( IFSG_TRANSFORM PcbOutput,
VRML_COLOR_INDEX  colorID,
VRML_LAYER *  layer,
double  top_z,
double  bottom_z 
)
static

Definition at line 1775 of file export_vrml.cpp.

1777 {
1778  std::vector< double > vertices;
1779  std::vector< int > idxPlane;
1780  std::vector< int > idxSide;
1781 
1782  if( top_z < bottom_z )
1783  {
1784  double tmp = top_z;
1785  top_z = bottom_z;
1786  bottom_z = tmp;
1787  }
1788 
1789  if( !(*layer).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z ) )
1790  {
1791 #ifdef DEBUG
1792  do {
1793  std::ostringstream ostr;
1794  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1795  ostr << " * [INFO] no vertex data";
1796  wxLogDebug( "%s\n", ostr.str().c_str() );
1797  } while( 0 );
1798 #endif
1799 
1800  return;
1801  }
1802 
1803  if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
1804  {
1805 #ifdef DEBUG
1806  do {
1807  std::ostringstream ostr;
1808  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1809  ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
1810  wxLogDebug( "%s\n", ostr.str().c_str() );
1811  } while( 0 );
1812 #endif
1813 
1814  throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
1815  }
1816 
1817  std::vector< SGPOINT > vlist;
1818  size_t nvert = vertices.size() / 3;
1819  size_t j = 0;
1820 
1821  for( size_t i = 0; i < nvert; ++i, j+= 3 )
1822  vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
1823 
1824  // create the intermediate scenegraph
1825  IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
1826  IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
1827  IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
1828  IFSG_COORDS cp( face ); // coordinates for all faces
1829  cp.SetCoordsList( nvert, &vlist[0] );
1830  IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
1831  coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
1832  IFSG_NORMALS norms( face ); // normals for the top and bottom planes
1833 
1834  // number of TOP (and bottom) vertices
1835  j = nvert / 2;
1836 
1837  // set the TOP normals
1838  for( size_t i = 0; i < j; ++i )
1839  norms.AddNormal( 0.0, 0.0, 1.0 );
1840 
1841  // set the BOTTOM normals
1842  for( size_t i = 0; i < j; ++i )
1843  norms.AddNormal( 0.0, 0.0, -1.0 );
1844 
1845  // assign a color from the palette
1846  SGNODE* modelColor = getSGColor( colorID );
1847 
1848  if( NULL != modelColor )
1849  {
1850  if( NULL == S3D::GetSGNodeParent( modelColor ) )
1851  shape.AddChildNode( modelColor );
1852  else
1853  shape.AddRefNode( modelColor );
1854  }
1855 
1856  // create a second shape describing the vertical walls of the extrusion
1857  // using per-vertex-per-face-normals
1858  shape.NewNode( tx0 );
1859  shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom
1860  face.NewNode( shape );
1861  cp.NewNode( face ); // new vertex list
1862  norms.NewNode( face ); // new normals list
1863  coordIdx.NewNode( face ); // new index list
1864 
1865  // populate the new per-face vertex list and its indices and normals
1866  std::vector< int >::iterator sI = idxSide.begin();
1867  std::vector< int >::iterator eI = idxSide.end();
1868 
1869  size_t sidx = 0; // index to the new coord set
1870  SGPOINT p1, p2, p3;
1871  SGVECTOR vnorm;
1872 
1873  while( sI != eI )
1874  {
1875  p1 = vlist[*sI];
1876  cp.AddCoord( p1 );
1877  ++sI;
1878 
1879  p2 = vlist[*sI];
1880  cp.AddCoord( p2 );
1881  ++sI;
1882 
1883  p3 = vlist[*sI];
1884  cp.AddCoord( p3 );
1885  ++sI;
1886 
1887  vnorm.SetVector( S3D::CalcTriNorm( p1, p2, p3 ) );
1888  norms.AddNormal( vnorm );
1889  norms.AddNormal( vnorm );
1890  norms.AddNormal( vnorm );
1891 
1892  coordIdx.AddIndex( (int)sidx );
1893  ++sidx;
1894  coordIdx.AddIndex( (int)sidx );
1895  ++sidx;
1896  coordIdx.AddIndex( (int)sidx );
1897  ++sidx;
1898  }
1899 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
Class IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
Class IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
void SetVector(double aXVal, double aYVal, double aZVal)
Definition: sg_base.cpp:292
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
Class IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
static SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
SGLIB_API SGVECTOR CalcTriNorm(const SGPOINT &p1, const SGPOINT &p2, const SGPOINT &p3)
Function CalcTriNorm returns the normal vector of a triangle described by vertices p1,...
Definition: ifsg_api.cpp:606
Class IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
size_t i
Definition: json11.cpp:597
Class IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_COORDS::AddCoord(), IFSG_INDEX::AddIndex(), IFSG_NORMALS::AddNormal(), S3D::CalcTriNorm(), IFSG_NODE::GetRawPtr(), getSGColor(), S3D::GetSGNodeParent(), i, IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::SetCoordsList(), IFSG_INDEX::SetIndices(), and SGVECTOR::SetVector().

Referenced by write_layers().

◆ export_round_padstack()

static void export_round_padstack ( MODEL_VRML aModel,
BOARD pcb,
double  x,
double  y,
double  r,
LAYER_NUM  bottom_layer,
LAYER_NUM  top_layer,
double  hole 
)
static

Definition at line 902 of file export_vrml.cpp.

906 {
907  LAYER_NUM layer = top_layer;
908  bool thru = true;
909 
910  // if not a thru hole do not put a hole in the board
911  if( top_layer != F_Cu || bottom_layer != B_Cu )
912  thru = false;
913 
914  if( thru && hole > 0 )
915  aModel.m_holes.AddCircle( x, -y, hole, true );
916 
917  if( aModel.m_plainPCB )
918  return;
919 
920  while( 1 )
921  {
922  if( layer == B_Cu )
923  {
924  aModel.m_bot_copper.AddCircle( x, -y, r );
925 
926  if( hole > 0 && !thru )
927  aModel.m_bot_copper.AddCircle( x, -y, hole, true );
928 
929  }
930  else if( layer == F_Cu )
931  {
932  aModel.m_top_copper.AddCircle( x, -y, r );
933 
934  if( hole > 0 && !thru )
935  aModel.m_top_copper.AddCircle( x, -y, hole, true );
936 
937  }
938 
939  if( layer == bottom_layer )
940  break;
941 
942  layer = bottom_layer;
943  }
944 }
VRML_LAYER m_holes
VRML_LAYER m_bot_copper
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
VRML_LAYER m_top_copper

References B_Cu, F_Cu, MODEL_VRML::m_bot_copper, MODEL_VRML::m_holes, MODEL_VRML::m_plainPCB, and MODEL_VRML::m_top_copper.

Referenced by export_vrml_via().

◆ export_vrml_arc()

static void export_vrml_arc ( MODEL_VRML aModel,
LAYER_NUM  layer,
double  centerx,
double  centery,
double  arc_startx,
double  arc_starty,
double  width,
double  arc_angle 
)
static

Definition at line 657 of file export_vrml.cpp.

661 {
662  VRML_LAYER* vlayer;
663 
664  if( !GetLayer( aModel, layer, &vlayer ) )
665  return;
666 
667  if( width < aModel.m_minLineWidth )
668  width = aModel.m_minLineWidth;
669 
670  centery = -centery;
671  arc_starty = -arc_starty;
672 
673  if( !vlayer->AddArc( centerx, centery, arc_startx, arc_starty, width, -arc_angle, false ) )
674  throw( std::runtime_error( vlayer->GetError() ) );
675 
676 }
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
double m_minLineWidth

References GetLayer(), and MODEL_VRML::m_minLineWidth.

Referenced by export_vrml_drawsegment(), and export_vrml_edge_module().

◆ export_vrml_board()

static void export_vrml_board ( MODEL_VRML aModel,
BOARD aPcb 
)
static

Definition at line 844 of file export_vrml.cpp.

845 {
846  SHAPE_POLY_SET pcbOutlines; // stores the board main outlines
847  wxString msg;
848 
849  if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) )
850  {
851  msg << "\n\n" <<
852  _( "Unable to calculate the board outlines; fall back to using the board boundary box." );
853  wxMessageBox( msg );
854  }
855 
856  int seg;
857 
858  for( int cnt = 0; cnt < pcbOutlines.OutlineCount(); cnt++ )
859  {
860  const SHAPE_LINE_CHAIN& outline = pcbOutlines.COutline( cnt );
861 
862  seg = aModel.m_board.NewContour();
863 
864  for( int j = 0; j < outline.PointCount(); j++ )
865  {
866  aModel.m_board.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
867  -((double)outline.CPoint(j).y * BOARD_SCALE ) );
868 
869  }
870 
871  aModel.m_board.EnsureWinding( seg, false );
872 
873  // Generate holes:
874  for( int ii = 0; ii < pcbOutlines.HoleCount( cnt ); ii++ )
875  {
876  const SHAPE_LINE_CHAIN& hole = pcbOutlines.Hole( cnt, ii );
877 
878  seg = aModel.m_holes.NewContour();
879 
880  if( seg < 0 )
881  {
882  msg << "\n\n" <<
883  _( "VRML Export Failed: Could not add holes to contours." );
884  wxMessageBox( msg );
885 
886  return;
887  }
888 
889  for( int j = 0; j < hole.PointCount(); j++ )
890  {
891  aModel.m_holes.AddVertex( seg, (double)hole.CPoint(j).x * BOARD_SCALE,
892  -((double)hole.CPoint(j).y * BOARD_SCALE ) );
893 
894  }
895 
896  aModel.m_holes.EnsureWinding( seg, true );
897  }
898  }
899 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
int OutlineCount() const
Returns the number of outlines in the set
VRML_LAYER m_holes
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Returns the reference to aHole-th hole in the aIndex-th outline
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
Class SHAPE_POLY_SET.
VRML_LAYER m_board
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, wxString *aErrorText=nullptr, wxPoint *aErrorLocation=nullptr)
Function GetBoardPolygonOutlines Extracts the board outlines and build a closed polygon from lines,...
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const

References BOARD_SCALE, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), BOARD::GetBoardPolygonOutlines(), SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::HoleCount(), MODEL_VRML::m_board, MODEL_VRML::m_holes, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ export_vrml_circle()

static void export_vrml_circle ( MODEL_VRML aModel,
LAYER_NUM  layer,
double  startx,
double  starty,
double  endx,
double  endy,
double  width 
)
static

Definition at line 626 of file export_vrml.cpp.

629 {
630  VRML_LAYER* vlayer;
631 
632  if( !GetLayer( aModel, layer, &vlayer ) )
633  return;
634 
635  if( width < aModel.m_minLineWidth )
636  width = aModel.m_minLineWidth;
637 
638  starty = -starty;
639  endy = -endy;
640 
641  double hole, radius;
642 
643  radius = Distance( startx, starty, endx, endy ) + ( width / 2);
644  hole = radius - width;
645 
646  if( !vlayer->AddCircle( startx, starty, radius, false ) )
647  throw( std::runtime_error( vlayer->GetError() ) );
648 
649  if( hole > 0.0001 )
650  {
651  if( !vlayer->AddCircle( startx, starty, hole, true ) )
652  throw( std::runtime_error( vlayer->GetError() ) );
653  }
654 }
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
double m_minLineWidth
double Distance(double x1, double y1, double x2, double y2)

References Distance(), GetLayer(), and MODEL_VRML::m_minLineWidth.

Referenced by export_vrml_edge_module().

◆ export_vrml_drawings()

static void export_vrml_drawings ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 816 of file export_vrml.cpp.

817 {
818  // draw graphic items
819  for( auto drawing : pcb->Drawings() )
820  {
821  PCB_LAYER_ID layer = drawing->GetLayer();
822 
823  if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
824  continue;
825 
826  switch( drawing->Type() )
827  {
828  case PCB_LINE_T:
829  export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing );
830  break;
831 
832  case PCB_TEXT_T:
833  export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing );
834  break;
835 
836  default:
837  break;
838  }
839  }
840 }
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
PCB_LAYER_ID
A quick note on layer IDs:
static void export_vrml_drawsegment(MODEL_VRML &aModel, DRAWSEGMENT *drawseg)
static void export_vrml_pcbtext(MODEL_VRML &aModel, TEXTE_PCB *text)
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:253

References B_Cu, B_SilkS, BOARD::Drawings(), export_vrml_drawsegment(), export_vrml_pcbtext(), F_Cu, F_SilkS, PCB_LINE_T, and PCB_TEXT_T.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ export_vrml_drawsegment()

static void export_vrml_drawsegment ( MODEL_VRML aModel,
DRAWSEGMENT drawseg 
)
static

Definition at line 716 of file export_vrml.cpp.

717 {
718  LAYER_NUM layer = drawseg->GetLayer();
719  double w = drawseg->GetWidth() * BOARD_SCALE;
720  double x = drawseg->GetStart().x * BOARD_SCALE;
721  double y = drawseg->GetStart().y * BOARD_SCALE;
722  double xf = drawseg->GetEnd().x * BOARD_SCALE;
723  double yf = drawseg->GetEnd().y * BOARD_SCALE;
724  double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) );
725 
726  // Items on the edge layer are handled elsewhere; just return
727  if( layer == Edge_Cuts )
728  return;
729 
730  switch( drawseg->GetShape() )
731  {
732  case S_ARC:
733  export_vrml_arc( aModel, layer,
734  (double) drawseg->GetCenter().x * BOARD_SCALE,
735  (double) drawseg->GetCenter().y * BOARD_SCALE,
736  (double) drawseg->GetArcStart().x * BOARD_SCALE,
737  (double) drawseg->GetArcStart().y * BOARD_SCALE,
738  w, drawseg->GetAngle() / 10 );
739  break;
740 
741  case S_CIRCLE:
742  // Break circles into two 180 arcs to prevent the vrml hole from obscuring objects
743  // within the hole area of the circle.
744  export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 );
745  export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 );
746  break;
747 
748  case S_POLYGON:
749  export_vrml_polygon( aModel, layer, drawseg, 0.0, wxPoint( 0, 0 ) );
750  break;
751 
752  default:
753  export_vrml_line( aModel, layer, x, y, xf, yf, w );
754  break;
755  }
756 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
const wxPoint GetCenter() const override
Function GetCenter()
STROKE_T GetShape() const
polygon (not yet used for tracks, but could be in microwave apps)
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Arcs (with rounded ends)
static void export_vrml_arc(MODEL_VRML &aModel, LAYER_NUM layer, double centerx, double centery, double arc_startx, double arc_starty, double width, double arc_angle)
const wxPoint & GetArcStart() const
int GetWidth() const
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double GetAngle() const
static void export_vrml_polygon(MODEL_VRML &aModel, LAYER_NUM layer, DRAWSEGMENT *aOutline, double aOrientation, wxPoint aPos)
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.

References BOARD_SCALE, Edge_Cuts, export_vrml_arc(), export_vrml_line(), export_vrml_polygon(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetArcStart(), DRAWSEGMENT::GetCenter(), DRAWSEGMENT::GetEnd(), BOARD_ITEM::GetLayer(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), DRAWSEGMENT::GetWidth(), S_ARC, S_CIRCLE, and S_POLYGON.

Referenced by export_vrml_drawings().

◆ export_vrml_edge_module()

static void export_vrml_edge_module ( MODEL_VRML aModel,
EDGE_MODULE aOutline,
MODULE aModule 
)
static

Definition at line 1052 of file export_vrml.cpp.

1054 {
1055  LAYER_NUM layer = aOutline->GetLayer();
1056  double x = aOutline->GetStart().x * BOARD_SCALE;
1057  double y = aOutline->GetStart().y * BOARD_SCALE;
1058  double xf = aOutline->GetEnd().x * BOARD_SCALE;
1059  double yf = aOutline->GetEnd().y * BOARD_SCALE;
1060  double w = aOutline->GetWidth() * BOARD_SCALE;
1061 
1062  switch( aOutline->GetShape() )
1063  {
1064  case S_SEGMENT:
1065  export_vrml_line( aModel, layer, x, y, xf, yf, w );
1066  break;
1067 
1068  case S_ARC:
1069  export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
1070  break;
1071 
1072  case S_CIRCLE:
1073  export_vrml_circle( aModel, layer, x, y, xf, yf, w );
1074  break;
1075 
1076  case S_POLYGON:
1077  export_vrml_polygon( aModel, layer, aOutline, aModule->GetOrientationRadians(),
1078  aModule->GetPosition() );
1079  break;
1080 
1081  default:
1082  break;
1083  }
1084 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
STROKE_T GetShape() const
polygon (not yet used for tracks, but could be in microwave apps)
usual segment : line with rounded ends
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
static void export_vrml_circle(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
Arcs (with rounded ends)
double GetOrientationRadians() const
Definition: class_module.h:190
static void export_vrml_arc(MODEL_VRML &aModel, LAYER_NUM layer, double centerx, double centery, double arc_startx, double arc_starty, double width, double arc_angle)
int GetWidth() const
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double GetAngle() const
static void export_vrml_polygon(MODEL_VRML &aModel, LAYER_NUM layer, DRAWSEGMENT *aOutline, double aOrientation, wxPoint aPos)
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint GetPosition() const override
Definition: class_module.h:183

References BOARD_SCALE, export_vrml_arc(), export_vrml_circle(), export_vrml_line(), export_vrml_polygon(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetEnd(), BOARD_ITEM::GetLayer(), MODULE::GetOrientationRadians(), MODULE::GetPosition(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), DRAWSEGMENT::GetWidth(), S_ARC, S_CIRCLE, S_POLYGON, and S_SEGMENT.

Referenced by export_vrml_module().

◆ export_vrml_line()

static void export_vrml_line ( MODEL_VRML aModel,
LAYER_NUM  layer,
double  startx,
double  starty,
double  endx,
double  endy,
double  width 
)
static

Definition at line 601 of file export_vrml.cpp.

604 {
605  VRML_LAYER* vlayer;
606 
607  if( !GetLayer( aModel, layer, &vlayer ) )
608  return;
609 
610  if( width < aModel.m_minLineWidth)
611  width = aModel.m_minLineWidth;
612 
613  starty = -starty;
614  endy = -endy;
615 
616  double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI;
617  double length = Distance( startx, starty, endx, endy ) + width;
618  double cx = ( startx + endx ) / 2.0;
619  double cy = ( starty + endy ) / 2.0;
620 
621  if( !vlayer->AddSlot( cx, cy, length, width, angle, false ) )
622  throw( std::runtime_error( vlayer->GetError() ) );
623 }
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
double m_minLineWidth
double Distance(double x1, double y1, double x2, double y2)

References PNS::angle(), Distance(), GetLayer(), and MODEL_VRML::m_minLineWidth.

Referenced by export_vrml_drawsegment(), export_vrml_edge_module(), export_vrml_tracks(), and vrml_text_callback().

◆ export_vrml_module()

static void export_vrml_module ( MODEL_VRML aModel,
BOARD aPcb,
MODULE aModule,
std::ostream *  aOutputFile 
)
static

Definition at line 1338 of file export_vrml.cpp.

1340 {
1341  if( !aModel.m_plainPCB )
1342  {
1343  // Reference and value
1344  if( aModule->Reference().IsVisible() )
1345  export_vrml_text_module( &aModule->Reference() );
1346 
1347  if( aModule->Value().IsVisible() )
1348  export_vrml_text_module( &aModule->Value() );
1349 
1350  // Export module edges
1351  for( EDA_ITEM* item = aModule->GraphicalItemsList(); item; item = item->Next() )
1352  {
1353  switch( item->Type() )
1354  {
1355  case PCB_MODULE_TEXT_T:
1356  export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
1357  break;
1358 
1359  case PCB_MODULE_EDGE_T:
1360  export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ),
1361  aModule );
1362  break;
1363 
1364  default:
1365  break;
1366  }
1367  }
1368  }
1369 
1370  // Export pads
1371  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
1372  export_vrml_pad( aModel, aPcb, pad );
1373 
1374  bool isFlipped = aModule->GetLayer() == B_Cu;
1375 
1376  // Export the object VRML model(s)
1377  auto sM = aModule->Models().begin();
1378  auto eM = aModule->Models().end();
1379 
1380  wxFileName subdir( SUBDIR_3D, "" );
1381 
1382  while( sM != eM )
1383  {
1384  SGNODE* mod3d = (SGNODE*) cache->Load( sM->m_Filename );
1385 
1386  if( NULL == mod3d )
1387  {
1388  ++sM;
1389  continue;
1390  }
1391 
1392  /* Calculate 3D shape rotation:
1393  * this is the rotation parameters, with an additional 180 deg rotation
1394  * for footprints that are flipped
1395  * When flipped, axis rotation is the horizontal axis (X axis)
1396  */
1397  double rotx = -sM->m_Rotation.x;
1398  double roty = -sM->m_Rotation.y;
1399  double rotz = -sM->m_Rotation.z;
1400 
1401  if( isFlipped )
1402  {
1403  rotx += 180.0;
1404  roty = -roty;
1405  rotz = -rotz;
1406  }
1407 
1408  // Do some quaternion munching
1409  double q1[4], q2[4], rot[4];
1410  build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
1411  build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
1412  compose_quat( q1, q2, q1 );
1413  build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
1414  compose_quat( q1, q2, q1 );
1415 
1416  // Note here aModule->GetOrientation() is in 0.1 degrees,
1417  // so module rotation has to be converted to radians
1418  build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
1419  compose_quat( q1, q2, q1 );
1420  from_quat( q1, rot );
1421 
1422  double offsetFactor = 1000.0f * IU_PER_MILS / 25.4f;
1423 
1424  // adjust 3D shape local offset position
1425  // they are given in mm, so they are converted in board IU.
1426  double offsetx = sM->m_Offset.x * offsetFactor;
1427  double offsety = sM->m_Offset.y * offsetFactor;
1428  double offsetz = sM->m_Offset.z * offsetFactor;
1429 
1430  if( isFlipped )
1431  offsetz = -offsetz;
1432  else // In normal mode, Y axis is reversed in Pcbnew.
1433  offsety = -offsety;
1434 
1435  RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
1436 
1437  SGPOINT trans;
1438  trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.m_tx;
1439  trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.m_ty;
1440  trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() );
1441 
1442  if( USE_INLINES )
1443  {
1444  wxFileName srcFile = cache->GetResolver()->ResolvePath( sM->m_Filename );
1445  wxFileName dstFile;
1446  dstFile.SetPath( SUBDIR_3D );
1447  dstFile.SetName( srcFile.GetName() );
1448  dstFile.SetExt( "wrl" );
1449 
1450  // copy the file if necessary
1451  wxDateTime srcModTime = srcFile.GetModificationTime();
1452  wxDateTime destModTime = srcModTime;
1453 
1454  destModTime.SetToCurrent();
1455 
1456  if( dstFile.FileExists() )
1457  destModTime = dstFile.GetModificationTime();
1458 
1459  if( srcModTime != destModTime )
1460  {
1461  wxLogDebug( "Copying 3D model %s to %s.",
1462  GetChars( srcFile.GetFullPath() ),
1463  GetChars( dstFile.GetFullPath() ) );
1464 
1465  wxString fileExt = srcFile.GetExt();
1466  fileExt.LowerCase();
1467 
1468  // copy VRML models and use the scenegraph library to
1469  // translate other model types
1470  if( fileExt == "wrl" )
1471  {
1472  if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
1473  continue;
1474  }
1475  else
1476  {
1477  if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
1478  continue;
1479  }
1480  }
1481 
1482  (*aOutputFile) << "Transform {\n";
1483 
1484  // only write a rotation if it is >= 0.1 deg
1485  if( std::abs( rot[3] ) > 0.0001745 )
1486  {
1487  (*aOutputFile) << " rotation " << std::setprecision( 5 );
1488  (*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
1489  }
1490 
1491  (*aOutputFile) << " translation " << std::setprecision( PRECISION );
1492  (*aOutputFile) << trans.x << " ";
1493  (*aOutputFile) << trans.y << " ";
1494  (*aOutputFile) << trans.z << "\n";
1495 
1496  (*aOutputFile) << " scale ";
1497  (*aOutputFile) << sM->m_Scale.x << " ";
1498  (*aOutputFile) << sM->m_Scale.y << " ";
1499  (*aOutputFile) << sM->m_Scale.z << "\n";
1500 
1501  (*aOutputFile) << " children [\n Inline {\n url \"";
1502 
1503  if( USE_RELPATH )
1504  {
1505  wxFileName tmp = dstFile;
1506  tmp.SetExt( "" );
1507  tmp.SetName( "" );
1508  tmp.RemoveLastDir();
1509  dstFile.MakeRelativeTo( tmp.GetPath() );
1510  }
1511 
1512  wxString fn = dstFile.GetFullPath();
1513  fn.Replace( "\\", "/" );
1514  (*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
1515  (*aOutputFile) << " }\n";
1516  }
1517  else
1518  {
1519  IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( aModel.m_OutputPCB.GetRawPtr() );
1520 
1521  // only write a rotation if it is >= 0.1 deg
1522  if( std::abs( rot[3] ) > 0.0001745 )
1523  modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
1524 
1525  modelShape->SetTranslation( trans );
1526  modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
1527 
1528  if( NULL == S3D::GetSGNodeParent( mod3d ) )
1529  {
1530  aModel.m_components.push_back( mod3d );
1531  modelShape->AddChildNode( mod3d );
1532  }
1533  else
1534  {
1535  modelShape->AddRefNode( mod3d );
1536  }
1537 
1538  }
1539 
1540  ++sM;
1541  }
1542 }
bool SetTranslation(const SGPOINT &aTranslation)
static double BOARD_SCALE
Definition: export_vrml.cpp:69
static void export_vrml_pad(MODEL_VRML &aModel, BOARD *aPcb, D_PAD *aPad)
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
double GetOrientation() const
Definition: class_module.h:188
TEXTE_MODULE & Reference()
Definition: class_module.h:503
static S3D_CACHE * cache
Definition: export_vrml.cpp:64
double x
Definition: sg_base.h:70
static void compose_quat(double q1[4], double q2[4], double qr[4])
static bool USE_INLINES
Definition: export_vrml.cpp:65
bool IsVisible() const
Definition: eda_text.h:193
bool AddRefNode(SGNODE *aNode)
Function AddRefNode adds a reference to an existing node which is not owned by (not a child of) this ...
Definition: ifsg_node.cpp:199
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
bool SetScale(const SGPOINT &aScale)
IFSG_TRANSFORM m_OutputPCB
#define abs(a)
Definition: auxiliary.h:84
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
static void export_vrml_text_module(TEXTE_MODULE *module)
bool AddChildNode(SGNODE *aNode)
Function AddChildNode adds a node as a child owned by this node.
Definition: ifsg_node.cpp:249
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Function WriteVRML writes out the given node and its subnodes to a VRML2 file.
Definition: ifsg_api.cpp:81
static void build_quat(double x, double y, double z, double a, double q[4])
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:502
static bool USE_RELPATH
Definition: export_vrml.cpp:67
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
static wxString SUBDIR_3D
Definition: export_vrml.cpp:71
std::list< SGNODE * > m_components
wxString ResolvePath(const wxString &aFileName)
Function ResolvePath determines the full path of the given file name.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:178
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
double DEG2RAD(double deg)
Definition: trigo.h:208
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
double DECIDEG2RAD(double deg)
Definition: trigo.h:212
static void from_quat(double q[4], double rot[4])
#define IU_PER_MILS
Definition: plotter.cpp:134
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
static const int PRECISION
Definition: export_vrml.cpp:70
static bool USE_DEFS
Definition: export_vrml.cpp:66
FILENAME_RESOLVER * GetResolver(void)
Definition: 3d_cache.cpp:683
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
static void export_vrml_edge_module(MODEL_VRML &aModel, EDGE_MODULE *aOutline, MODULE *aModule)
SCENEGRAPH * Load(const wxString &aModelFile)
Function Load attempts to load the scene data for a model; it will consult the internal cache list an...
Definition: 3d_cache.cpp:276
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint GetPosition() const override
Definition: class_module.h:183
double GetLayerZ(LAYER_NUM aLayer)

References abs, IFSG_NODE::AddChildNode(), IFSG_NODE::AddRefNode(), B_Cu, BOARD_SCALE, build_quat(), cache, compose_quat(), DECIDEG2RAD(), DEG2RAD(), export_vrml_edge_module(), export_vrml_pad(), export_vrml_text_module(), from_quat(), GetChars(), BOARD_ITEM::GetLayer(), MODEL_VRML::GetLayerZ(), MODULE::GetOrientation(), MODULE::GetPosition(), IFSG_NODE::GetRawPtr(), S3D_CACHE::GetResolver(), S3D::GetSGNodeParent(), MODULE::GraphicalItemsList(), EDA_TEXT::IsVisible(), IU_PER_MILS, S3D_CACHE::Load(), MODEL_VRML::m_components, MODEL_VRML::m_OutputPCB, MODEL_VRML::m_plainPCB, MODEL_VRML::m_tx, MODEL_VRML::m_ty, MODULE::Models(), MODULE::PadsList(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PRECISION, MODULE::Reference(), FILENAME_RESOLVER::ResolvePath(), RotatePoint(), IFSG_TRANSFORM::SetRotation(), IFSG_TRANSFORM::SetScale(), IFSG_TRANSFORM::SetTranslation(), SUBDIR_3D, TO_UTF8, USE_DEFS, USE_INLINES, USE_RELPATH, MODULE::Value(), S3D::WriteVRML(), and SGPOINT::x.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ export_vrml_pad()

static void export_vrml_pad ( MODEL_VRML aModel,
BOARD aPcb,
D_PAD aPad 
)
static

Definition at line 1218 of file export_vrml.cpp.

1219 {
1220  double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0;
1221  double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0;
1222  double hole_drill = std::min( hole_drill_w, hole_drill_h );
1223  double hole_x = aPad->GetPosition().x * BOARD_SCALE;
1224  double hole_y = aPad->GetPosition().y * BOARD_SCALE;
1225 
1226  // Export the hole on the edge layer
1227  if( hole_drill > 0 )
1228  {
1229  bool pth = false;
1230 
1231  if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
1232  && !aModel.m_plainPCB )
1233  pth = true;
1234 
1235  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1236  {
1237  // Oblong hole (slot)
1238 
1239  if( pth )
1240  {
1241  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
1242  hole_drill_h * 2.0 + PLATE_OFFSET,
1243  aPad->GetOrientation()/10.0, true, true );
1244 
1245  aModel.m_plated_holes.AddSlot( hole_x, -hole_y,
1246  hole_drill_w * 2.0, hole_drill_h * 2.0,
1247  aPad->GetOrientation()/10.0, true, false );
1248  }
1249  else
1250  {
1251  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
1252  aPad->GetOrientation()/10.0, true, false );
1253 
1254  }
1255  }
1256  else
1257  {
1258  // Drill a round hole
1259 
1260  if( pth )
1261  {
1262  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
1263  aModel.m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1264  }
1265  else
1266  {
1267  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1268  }
1269 
1270  }
1271  }
1272 
1273  if( aModel.m_plainPCB )
1274  return;
1275 
1276  // The pad proper, on the selected layers
1277  LSET layer_mask = aPad->GetLayerSet();
1278 
1279  if( layer_mask[B_Cu] )
1280  {
1281  if( layer_mask[B_Mask] )
1282  export_vrml_padshape( aModel, &aModel.m_bot_tin, aPad );
1283  else
1284  export_vrml_padshape( aModel, &aModel.m_bot_copper, aPad );
1285  }
1286  if( layer_mask[F_Cu] )
1287  {
1288  if( layer_mask[F_Mask] )
1289  export_vrml_padshape( aModel, &aModel.m_top_tin, aPad );
1290  else
1291  export_vrml_padshape( aModel, &aModel.m_top_copper, aPad );
1292  }
1293 
1294 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
VRML_LAYER m_bot_tin
VRML_LAYER m_plated_holes
VRML_LAYER m_holes
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:417
static void export_vrml_padshape(MODEL_VRML &aModel, VRML_LAYER *aTinLayer, D_PAD *aPad)
Class LSET is a set of PCB_LAYER_IDs.
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:400
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:414
VRML_LAYER m_bot_copper
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:394
const wxSize & GetDrillSize() const
Definition: class_pad.h:277
#define PLATE_OFFSET
Definition: export_vrml.cpp:62
VRML_LAYER m_top_copper
const wxPoint GetPosition() const override
Definition: class_pad.h:222
VRML_LAYER m_top_tin
#define min(a, b)
Definition: auxiliary.h:85

References B_Cu, B_Mask, BOARD_SCALE, export_vrml_padshape(), F_Cu, F_Mask, D_PAD::GetAttribute(), D_PAD::GetDrillShape(), D_PAD::GetDrillSize(), D_PAD::GetLayerSet(), D_PAD::GetOrientation(), D_PAD::GetPosition(), MODEL_VRML::m_bot_copper, MODEL_VRML::m_bot_tin, MODEL_VRML::m_holes, MODEL_VRML::m_plainPCB, MODEL_VRML::m_plated_holes, MODEL_VRML::m_top_copper, MODEL_VRML::m_top_tin, min, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_DRILL_SHAPE_OBLONG, and PLATE_OFFSET.

Referenced by export_vrml_module().

◆ export_vrml_padshape()

static void export_vrml_padshape ( MODEL_VRML aModel,
VRML_LAYER *  aTinLayer,
D_PAD aPad 
)
static

Definition at line 1087 of file export_vrml.cpp.

1088 {
1089  // The (maybe offset) pad position
1090  wxPoint pad_pos = aPad->ShapePos();
1091  double pad_x = pad_pos.x * BOARD_SCALE;
1092  double pad_y = pad_pos.y * BOARD_SCALE;
1093  wxSize pad_delta = aPad->GetDelta();
1094 
1095  double pad_dx = pad_delta.x * BOARD_SCALE / 2.0;
1096  double pad_dy = pad_delta.y * BOARD_SCALE / 2.0;
1097 
1098  double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0;
1099  double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0;
1100 
1101  switch( aPad->GetShape() )
1102  {
1103  case PAD_SHAPE_CIRCLE:
1104 
1105  if( !aTinLayer->AddCircle( pad_x, -pad_y, pad_w, false ) )
1106  throw( std::runtime_error( aTinLayer->GetError() ) );
1107 
1108  break;
1109 
1110  case PAD_SHAPE_OVAL:
1111 
1112  if( !aTinLayer->AddSlot( pad_x, -pad_y, pad_w * 2.0, pad_h * 2.0,
1113  aPad->GetOrientation()/10.0, false ) )
1114  throw( std::runtime_error( aTinLayer->GetError() ) );
1115 
1116  break;
1117 
1118  case PAD_SHAPE_ROUNDRECT:
1120  {
1121  SHAPE_POLY_SET polySet;
1122  int segmentToCircleCount = ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF;
1123  const int corner_radius = aPad->GetRoundRectCornerRadius( aPad->GetSize() );
1124  TransformRoundChamferedRectToPolygon( polySet, wxPoint( 0, 0 ), aPad->GetSize(),
1125  0.0, corner_radius, 0.0, 0, segmentToCircleCount );
1126  std::vector< wxRealPoint > cornerList;
1127  // TransformRoundChamferedRectToPolygon creates only one convex polygon
1128  SHAPE_LINE_CHAIN poly( polySet.Outline( 0 ) );
1129 
1130  for( int ii = 0; ii < poly.PointCount(); ++ii )
1131  cornerList.push_back( wxRealPoint( poly.Point( ii ).x * BOARD_SCALE,
1132  -poly.Point( ii ).y * BOARD_SCALE ) );
1133 
1134  // Close polygon
1135  cornerList.push_back( cornerList[0] );
1136  if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
1137  throw( std::runtime_error( aTinLayer->GetError() ) );
1138 
1139  break;
1140  }
1141 
1142  case PAD_SHAPE_CUSTOM:
1143  {
1144  SHAPE_POLY_SET polySet;
1145  int segmentToCircleCount = ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF;
1146  std::vector< wxRealPoint > cornerList;
1147  aPad->MergePrimitivesAsPolygon( &polySet, segmentToCircleCount );
1148 
1149  for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
1150  {
1151  SHAPE_LINE_CHAIN& poly = polySet.Outline( cnt );
1152  cornerList.clear();
1153 
1154  for( int ii = 0; ii < poly.PointCount(); ++ii )
1155  cornerList.push_back( wxRealPoint( poly.Point( ii ).x * BOARD_SCALE,
1156  -poly.Point( ii ).y * BOARD_SCALE ) );
1157 
1158  // Close polygon
1159  cornerList.push_back( cornerList[0] );
1160 
1161  if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
1162  throw( std::runtime_error( aTinLayer->GetError() ) );
1163  }
1164 
1165  break;
1166  }
1167 
1168  case PAD_SHAPE_RECT:
1169  // Just to be sure :D
1170  pad_dx = 0;
1171  pad_dy = 0;
1172 
1173  case PAD_SHAPE_TRAPEZOID:
1174  {
1175  double coord[8] =
1176  {
1177  -pad_w + pad_dy, -pad_h - pad_dx,
1178  -pad_w - pad_dy, pad_h + pad_dx,
1179  +pad_w - pad_dy, -pad_h + pad_dx,
1180  +pad_w + pad_dy, pad_h - pad_dx
1181  };
1182 
1183  for( int i = 0; i < 4; i++ )
1184  {
1185  RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
1186  coord[i * 2] += pad_x;
1187  coord[i * 2 + 1] += pad_y;
1188  }
1189 
1190  int lines;
1191 
1192  lines = aTinLayer->NewContour();
1193 
1194  if( lines < 0 )
1195  throw( std::runtime_error( aTinLayer->GetError() ) );
1196 
1197  if( !aTinLayer->AddVertex( lines, coord[0], -coord[1] ) )
1198  throw( std::runtime_error( aTinLayer->GetError() ) );
1199 
1200  if( !aTinLayer->AddVertex( lines, coord[4], -coord[5] ) )
1201  throw( std::runtime_error( aTinLayer->GetError() ) );
1202 
1203  if( !aTinLayer->AddVertex( lines, coord[6], -coord[7] ) )
1204  throw( std::runtime_error( aTinLayer->GetError() ) );
1205 
1206  if( !aTinLayer->AddVertex( lines, coord[2], -coord[3] ) )
1207  throw( std::runtime_error( aTinLayer->GetError() ) );
1208 
1209  if( !aTinLayer->EnsureWinding( lines, false ) )
1210  throw( std::runtime_error( aTinLayer->GetError() ) );
1211 
1212  break;
1213  }
1214  }
1215 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
int OutlineCount() const
Returns the number of outlines in the set
bool MergePrimitivesAsPolygon(SHAPE_POLY_SET *aMergedPolygon=NULL, int aCircleToSegmentsCount=ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF)
Merge all basic shapes, converted to a polygon in one polygon, in m_customShapeAsPolygon.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aCircleToSegmentsCount)
convert a rectangle with rounded corners and/or chamfered corners to a polygon Convert rounded corner...
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
int PointCount() const
Function PointCount()
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
const wxSize & GetDelta() const
Definition: class_pad.h:274
Class SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:394
size_t i
Definition: json11.cpp:597
wxPoint ShapePos() const
Definition: class_pad.cpp:562
int GetRoundRectCornerRadius() const
Function GetRoundRectCornerRadius Has meaning only for rounded rect pads.
Definition: class_pad.h:543
VECTOR2I & Point(int aIndex)
Function Point()
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:218
const wxSize & GetSize() const
Definition: class_pad.h:271
#define ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF
Definition: pcbnew.h:42

References ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF, BOARD_SCALE, D_PAD::GetDelta(), D_PAD::GetOrientation(), D_PAD::GetRoundRectCornerRadius(), D_PAD::GetShape(), D_PAD::GetSize(), i, D_PAD::MergePrimitivesAsPolygon(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, SHAPE_LINE_CHAIN::Point(), SHAPE_LINE_CHAIN::PointCount(), RotatePoint(), D_PAD::ShapePos(), TransformRoundChamferedRectToPolygon(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_vrml_pad().

◆ export_vrml_pcbtext()

static void export_vrml_pcbtext ( MODEL_VRML aModel,
TEXTE_PCB text 
)
static

Definition at line 773 of file export_vrml.cpp.

774 {
775  model_vrml->m_text_layer = text->GetLayer();
777 
778  wxSize size = text->GetTextSize();
779 
780  if( text->IsMirrored() )
781  size.x = -size.x;
782 
783  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by DrawGraphicText
784 
785  if( text->IsMultilineAllowed() )
786  {
787  wxArrayString strings_list;
788  wxStringSplit( text->GetShownText(), strings_list, '\n' );
789  std::vector<wxPoint> positions;
790  positions.reserve( strings_list.Count() );
791  text->GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
792 
793  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
794  {
795  wxString& txt = strings_list.Item( ii );
796  DrawGraphicText( NULL, NULL, positions[ii], color,
797  txt, text->GetTextAngle(), size,
798  text->GetHorizJustify(), text->GetVertJustify(),
799  text->GetThickness(), text->IsItalic(),
800  true,
802  }
803  }
804  else
805  {
806  DrawGraphicText( NULL, NULL, text->GetTextPos(), color,
807  text->GetShownText(), text->GetTextAngle(), size,
808  text->GetHorizJustify(), text->GetVertJustify(),
809  text->GetThickness(), text->IsItalic(),
810  true,
812  }
813 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:188
static void vrml_text_callback(int x0, int y0, int xf, int yf, void *aData)
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:208
bool IsMirrored() const
Definition: eda_text.h:196
int color
Definition: DXF_plotter.cpp:62
double GetTextAngle() const
Definition: eda_text.h:181
static MODEL_VRML * model_vrml
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:171
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
bool IsItalic() const
Definition: eda_text.h:187
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:207
const wxSize & GetTextSize() const
Definition: eda_text.h:232
bool IsMultilineAllowed() const
Definition: eda_text.h:205
LAYER_NUM m_text_layer
const wxPoint & GetTextPos() const
Definition: eda_text.h:241
void GetPositionsOfLinesOfMultilineText(std::vector< wxPoint > &aPositions, int aLineCount) const
Function GetPositionsOfLinesOfMultilineText Populates aPositions with the position of each line of a ...
Definition: eda_text.cpp:331
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:152
Definition: colors.h:45
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References BLACK, color, DrawGraphicText(), EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), EDA_TEXT::GetPositionsOfLinesOfMultilineText(), EDA_TEXT::GetShownText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetThickness(), EDA_TEXT::GetVertJustify(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), EDA_TEXT::IsMultilineAllowed(), MODEL_VRML::m_text_layer, MODEL_VRML::m_text_width, model_vrml, vrml_text_callback(), and wxStringSplit().

Referenced by export_vrml_drawings().

◆ export_vrml_polygon()

static void export_vrml_polygon ( MODEL_VRML aModel,
LAYER_NUM  layer,
DRAWSEGMENT aOutline,
double  aOrientation,
wxPoint  aPos 
)
static

Definition at line 679 of file export_vrml.cpp.

681 {
682  const int circleSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF;
683 
684  if( aOutline->IsPolyShapeValid() )
685  {
686  SHAPE_POLY_SET shape = aOutline->GetPolyShape();
687  VRML_LAYER* vlayer;
688 
689  if( !GetLayer( aModel, layer, &vlayer ) )
690  return;
691 
692  if( aOutline->GetWidth() )
693  {
694  shape.Inflate( aOutline->GetWidth()/2, circleSegmentsCount );
696  }
697 
698  shape.Rotate( -aOrientation, VECTOR2I( 0, 0 ) );
699  shape.Move( aPos );
700  const SHAPE_LINE_CHAIN& outline = shape.COutline( 0 );
701 
702  int seg = vlayer->NewContour();
703 
704  for( int j = 0; j < outline.PointCount(); j++ )
705  {
706  if( !vlayer->AddVertex( seg, outline.CPoint( j ).x * BOARD_SCALE,
707  -outline.CPoint( j ).y * BOARD_SCALE ) )
708  throw( std::runtime_error( vlayer->GetError() ) );
709  }
710 
711  vlayer->EnsureWinding( seg, false );
712  }
713 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
void Move(const VECTOR2I &aVector) override
Class SHAPE_POLY_SET.
SHAPE_POLY_SET & GetPolyShape()
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
int GetWidth() const
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
bool IsPolyShapeValid() const
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
void Rotate(double aAngle, const VECTOR2I &aCenter)
Function Rotate rotates all vertices by a given angle.
#define ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF
Definition: pcbnew.h:42

References ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF, BOARD_SCALE, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_POLY_SET::Fracture(), GetLayer(), DRAWSEGMENT::GetPolyShape(), DRAWSEGMENT::GetWidth(), SHAPE_POLY_SET::Inflate(), DRAWSEGMENT::IsPolyShapeValid(), SHAPE_POLY_SET::Move(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, SHAPE_LINE_CHAIN::PointCount(), SHAPE_POLY_SET::Rotate(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_vrml_drawsegment(), and export_vrml_edge_module().

◆ export_vrml_text_module()

static void export_vrml_text_module ( TEXTE_MODULE module)
static

Definition at line 1030 of file export_vrml.cpp.

1031 {
1032  if( module->IsVisible() )
1033  {
1034  wxSize size = module->GetTextSize();
1035 
1036  if( module->IsMirrored() )
1037  size.x = -size.x; // Text is mirrored
1038 
1039  model_vrml->m_text_layer = module->GetLayer();
1040  model_vrml->m_text_width = module->GetThickness();
1041 
1042  DrawGraphicText( NULL, NULL, module->GetTextPos(), BLACK,
1043  module->GetShownText(), module->GetDrawRotation(), size,
1044  module->GetHorizJustify(), module->GetVertJustify(),
1045  module->GetThickness(), module->IsItalic(),
1046  true,
1048  }
1049 }
static void vrml_text_callback(int x0, int y0, int xf, int yf, void *aData)
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:208
bool IsMirrored() const
Definition: eda_text.h:196
bool IsVisible() const
Definition: eda_text.h:193
static MODEL_VRML * model_vrml
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:171
virtual wxString GetShownText() const override
Returns the string actually shown after processing of the base text.
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
bool IsItalic() const
Definition: eda_text.h:187
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:207
const wxSize & GetTextSize() const
Definition: eda_text.h:232
LAYER_NUM m_text_layer
const wxPoint & GetTextPos() const
Definition: eda_text.h:241
Definition: colors.h:45
double GetDrawRotation() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.

References BLACK, DrawGraphicText(), TEXTE_MODULE::GetDrawRotation(), EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), TEXTE_MODULE::GetShownText(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetThickness(), EDA_TEXT::GetVertJustify(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), EDA_TEXT::IsVisible(), MODEL_VRML::m_text_layer, MODEL_VRML::m_text_width, model_vrml, and vrml_text_callback().

Referenced by export_vrml_module().

◆ export_vrml_tracks()

static void export_vrml_tracks ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 967 of file export_vrml.cpp.

968 {
969  for( TRACK* track = pcb->m_Track; track; track = track->Next() )
970  {
971  if( track->Type() == PCB_VIA_T )
972  {
973  export_vrml_via( aModel, pcb, (const VIA*) track );
974  }
975  else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
976  && !aModel.m_plainPCB )
977  export_vrml_line( aModel, track->GetLayer(),
978  track->GetStart().x * BOARD_SCALE,
979  track->GetStart().y * BOARD_SCALE,
980  track->GetEnd().x * BOARD_SCALE,
981  track->GetEnd().y * BOARD_SCALE,
982  track->GetWidth() * BOARD_SCALE );
983  }
984 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
static void export_vrml_via(MODEL_VRML &aModel, BOARD *aPcb, const VIA *aVia)
DLIST< TRACK > m_Track
Definition: class_board.h:249
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)

References B_Cu, BOARD_SCALE, export_vrml_line(), export_vrml_via(), F_Cu, MODEL_VRML::m_plainPCB, BOARD::m_Track, and PCB_VIA_T.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ export_vrml_via()

static void export_vrml_via ( MODEL_VRML aModel,
BOARD aPcb,
const VIA aVia 
)
static

Definition at line 947 of file export_vrml.cpp.

948 {
949  double x, y, r, hole;
950  PCB_LAYER_ID top_layer, bottom_layer;
951 
952  hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0;
953  r = aVia->GetWidth() * BOARD_SCALE / 2.0;
954  x = aVia->GetStart().x * BOARD_SCALE;
955  y = aVia->GetStart().y * BOARD_SCALE;
956  aVia->LayerPair( &top_layer, &bottom_layer );
957 
958  // do not render a buried via
959  if( top_layer != F_Cu && bottom_layer != B_Cu )
960  return;
961 
962  // Export the via padstack
963  export_round_padstack( aModel, aPcb, x, y, r, bottom_layer, top_layer, hole );
964 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
const wxPoint & GetStart() const
Definition: class_track.h:133
PCB_LAYER_ID
A quick note on layer IDs:
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
static void export_round_padstack(MODEL_VRML &aModel, BOARD *pcb, double x, double y, double r, LAYER_NUM bottom_layer, LAYER_NUM top_layer, double hole)
int GetWidth() const
Definition: class_track.h:127

References B_Cu, BOARD_SCALE, export_round_padstack(), F_Cu, VIA::GetDrillValue(), TRACK::GetStart(), TRACK::GetWidth(), and VIA::LayerPair().

Referenced by export_vrml_tracks().

◆ export_vrml_zones()

static void export_vrml_zones ( MODEL_VRML aModel,
BOARD aPcb 
)
static

Definition at line 987 of file export_vrml.cpp.

988 {
989 
990  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
991  {
992  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
993 
994  VRML_LAYER* vl;
995 
996  if( !GetLayer( aModel, zone->GetLayer(), &vl ) )
997  continue;
998 
999  // fixme: this modifies the board where it shouldn't, but I don't have the time
1000  // to clean this up - TW
1001  if( !zone->IsFilled() )
1002  {
1003  ZONE_FILLER filler( aPcb );
1004  zone->SetFillMode( ZFM_POLYGONS ); // use filled polygons
1005  filler.Fill( { zone } );
1006  }
1007 
1008  const SHAPE_POLY_SET& poly = zone->GetFilledPolysList();
1009 
1010  for( int i = 0; i < poly.OutlineCount(); i++ )
1011  {
1012  const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
1013 
1014  int seg = vl->NewContour();
1015 
1016  for( int j = 0; j < outline.PointCount(); j++ )
1017  {
1018  if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * BOARD_SCALE,
1019  -((double)outline.CPoint( j ).y * BOARD_SCALE ) ) )
1020  throw( std::runtime_error( vl->GetError() ) );
1021 
1022  }
1023 
1024  vl->EnsureWinding( seg, false );
1025  }
1026  }
1027 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
bool IsFilled() const
Definition: class_zone.h:187
int OutlineCount() const
Returns the number of outlines in the set
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:185
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:981
Class SHAPE_POLY_SET.
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:169
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
size_t i
Definition: json11.cpp:597
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:952
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:580

References BOARD_SCALE, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), ZONE_FILLER::Fill(), BOARD::GetArea(), BOARD::GetAreaCount(), ZONE_CONTAINER::GetFilledPolysList(), ZONE_CONTAINER::GetLayer(), GetLayer(), i, ZONE_CONTAINER::IsFilled(), SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), ZONE_CONTAINER::SetFillMode(), VECTOR2< T >::x, VECTOR2< T >::y, and ZFM_POLYGONS.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ from_quat()

static void from_quat ( double  q[4],
double  rot[4] 
)
static

Definition at line 1310 of file export_vrml.cpp.

1311 {
1312  rot[3] = acos( q[3] ) * 2;
1313 
1314  for( int i = 0; i < 3; i++ )
1315  {
1316  rot[i] = q[i] / sin( rot[3] / 2 );
1317  }
1318 }
size_t i
Definition: json11.cpp:597

References i.

Referenced by export_vrml_module().

◆ GetLayer()

static bool GetLayer ( MODEL_VRML aModel,
LAYER_NUM  layer,
VRML_LAYER **  vlayer 
)
static

Definition at line 289 of file export_vrml.cpp.

290 {
291  switch( layer )
292  {
293  case B_Cu:
294  *vlayer = &aModel.m_bot_copper;
295  break;
296 
297  case F_Cu:
298  *vlayer = &aModel.m_top_copper;
299  break;
300 
301  case B_SilkS:
302  *vlayer = &aModel.m_bot_silk;
303  break;
304 
305  case F_SilkS:
306  *vlayer = &aModel.m_top_silk;
307  break;
308 
309  default:
310  return false;
311  }
312 
313  return true;
314 }
VRML_LAYER m_bot_silk
VRML_LAYER m_top_silk
VRML_LAYER m_bot_copper
VRML_LAYER m_top_copper

References B_Cu, B_SilkS, F_Cu, F_SilkS, MODEL_VRML::m_bot_copper, MODEL_VRML::m_bot_silk, MODEL_VRML::m_top_copper, and MODEL_VRML::m_top_silk.

Referenced by BuildBoardPolygonOutlines(), export_vrml_arc(), export_vrml_circle(), export_vrml_line(), export_vrml_polygon(), export_vrml_zones(), EE_COLLECTOR::IsCorner(), DIALOG_FOOTPRINT_FP_EDITOR::OnAddField(), DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField(), and PCB_EDIT_FRAME::Process_Special_Functions().

◆ getSGColor()

static SGNODE* getSGColor ( VRML_COLOR_INDEX  colorIdx)
static

Definition at line 1669 of file export_vrml.cpp.

1670 {
1671  if( colorIdx == -1 )
1672  colorIdx = VRML_COLOR_PCB;
1673  else if( colorIdx == VRML_COLOR_LAST )
1674  return NULL;
1675 
1676  if( sgmaterial[colorIdx] )
1677  return sgmaterial[colorIdx];
1678 
1679  IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
1680  VRML_COLOR* cp = &colors[colorIdx];
1681 
1682  vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
1683  vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
1684  vcolor.SetShininess( cp->shiny );
1685  // NOTE: XXX - replace with a better equation; using this definition
1686  // of ambient will not yield the best results
1687  vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
1688  vcolor.SetTransparency( cp->transp );
1689 
1690  sgmaterial[colorIdx] = vcolor.GetRawPtr();
1691 
1692  return sgmaterial[colorIdx];
1693 }
float transp
Definition: export_vrml.cpp:89
static SGNODE * sgmaterial[VRML_COLOR_LAST]
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
float spec_blu
Definition: export_vrml.cpp:82
float ambient
Definition: export_vrml.cpp:88
float diffuse_grn
Definition: export_vrml.cpp:77
float spec_red
Definition: export_vrml.cpp:80
float spec_grn
Definition: export_vrml.cpp:81
float diffuse_red
Definition: export_vrml.cpp:76
float diffuse_blu
Definition: export_vrml.cpp:78
static VRML_COLOR colors[VRML_COLOR_LAST]

References VRML_COLOR::ambient, colors, VRML_COLOR::diffuse_blu, VRML_COLOR::diffuse_grn, VRML_COLOR::diffuse_red, IFSG_NODE::GetRawPtr(), IFSG_APPEARANCE::SetAmbient(), IFSG_APPEARANCE::SetDiffuse(), IFSG_APPEARANCE::SetShininess(), IFSG_APPEARANCE::SetSpecular(), IFSG_APPEARANCE::SetTransparency(), sgmaterial, VRML_COLOR::shiny, VRML_COLOR::spec_blu, VRML_COLOR::spec_grn, VRML_COLOR::spec_red, VRML_COLOR::transp, VRML_COLOR_LAST, and VRML_COLOR_PCB.

Referenced by create_vrml_plane(), and create_vrml_shell().

◆ vrml_text_callback()

static void vrml_text_callback ( int  x0,
int  y0,
int  xf,
int  yf,
void *  aData 
)
static

Definition at line 761 of file export_vrml.cpp.

762 {
763  LAYER_NUM m_text_layer = model_vrml->m_text_layer;
764  int m_text_width = model_vrml->m_text_width;
765 
766  export_vrml_line( *model_vrml, m_text_layer,
767  x0 * BOARD_SCALE, y0 * BOARD_SCALE,
768  xf * BOARD_SCALE, yf * BOARD_SCALE,
769  m_text_width * BOARD_SCALE );
770 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
static MODEL_VRML * model_vrml
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
LAYER_NUM m_text_layer
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)

References BOARD_SCALE, export_vrml_line(), MODEL_VRML::m_text_layer, MODEL_VRML::m_text_width, and model_vrml.

Referenced by export_vrml_pcbtext(), and export_vrml_text_module().

◆ write_layers()

static void write_layers ( MODEL_VRML aModel,
BOARD aPcb,
const char *  aFileName,
OSTREAM aOutputFile 
)
static

Definition at line 422 of file export_vrml.cpp.

424 {
425  // VRML_LAYER board;
426  aModel.m_board.Tesselate( &aModel.m_holes );
427  double brdz = aModel.m_brd_thickness / 2.0
428  - ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE;
429 
430  if( USE_INLINES )
431  {
432  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ),
433  &aModel.m_board, false, false, brdz, -brdz );
434  }
435  else
436  {
437  create_vrml_shell( aModel.m_OutputPCB, VRML_COLOR_PCB, &aModel.m_board, brdz, -brdz );
438  }
439 
440  if( aModel.m_plainPCB )
441  {
442  if( !USE_INLINES )
443  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), USE_DEFS, true );
444 
445  return;
446  }
447 
448  // VRML_LAYER m_top_copper;
449  aModel.m_top_copper.Tesselate( &aModel.m_holes );
450 
451  if( USE_INLINES )
452  {
453  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
454  &aModel.m_top_copper, true, true,
455  aModel.GetLayerZ( F_Cu ), 0 );
456  }
457  else
458  {
460  aModel.GetLayerZ( F_Cu ), true );
461  }
462 
463  // VRML_LAYER m_top_tin;
464  aModel.m_top_tin.Tesselate( &aModel.m_holes );
465 
466  if( USE_INLINES )
467  {
468  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
469  &aModel.m_top_tin, true, true,
470  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
471  0 );
472  }
473  else
474  {
476  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
477  true );
478  }
479 
480  // VRML_LAYER m_bot_copper;
481  aModel.m_bot_copper.Tesselate( &aModel.m_holes );
482 
483  if( USE_INLINES )
484  {
485  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
486  &aModel.m_bot_copper, true, false,
487  aModel.GetLayerZ( B_Cu ), 0 );
488  }
489  else
490  {
492  aModel.GetLayerZ( B_Cu ), false );
493  }
494 
495  // VRML_LAYER m_bot_tin;
496  aModel.m_bot_tin.Tesselate( &aModel.m_holes );
497 
498  if( USE_INLINES )
499  {
500  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
501  &aModel.m_bot_tin, true, false,
502  aModel.GetLayerZ( B_Cu )
503  - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
504  0 );
505  }
506  else
507  {
509  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
510  false );
511  }
512 
513  // VRML_LAYER PTH;
514  aModel.m_plated_holes.Tesselate( NULL, true );
515 
516  if( USE_INLINES )
517  {
518  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
519  &aModel.m_plated_holes, false, false,
520  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
521  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
522  }
523  else
524  {
526  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
527  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
528  }
529 
530  // VRML_LAYER m_top_silk;
531  aModel.m_top_silk.Tesselate( &aModel.m_holes );
532 
533  if( USE_INLINES )
534  {
535  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk,
536  true, true, aModel.GetLayerZ( F_SilkS ), 0 );
537  }
538  else
539  {
541  aModel.GetLayerZ( F_SilkS ), true );
542  }
543 
544  // VRML_LAYER m_bot_silk;
545  aModel.m_bot_silk.Tesselate( &aModel.m_holes );
546 
547  if( USE_INLINES )
548  {
549  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk,
550  true, false, aModel.GetLayerZ( B_SilkS ), 0 );
551  }
552  else
553  {
555  aModel.GetLayerZ( B_SilkS ), false );
556  }
557 
558  if( !USE_INLINES )
559  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), true, true );
560 }
static double BOARD_SCALE
Definition: export_vrml.cpp:69
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
static bool USE_INLINES
Definition: export_vrml.cpp:65
VRML_LAYER m_bot_tin
VRML_LAYER m_plated_holes
VRML_LAYER m_holes
static void create_vrml_plane(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double aHeight, bool aTopPlane)
static void write_triangle_bag(std::ostream &aOut_file, VRML_COLOR &aColor, VRML_LAYER *aLayer, bool aPlane, bool aTop, double aTop_z, double aBottom_z)
IFSG_TRANSFORM m_OutputPCB
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Function WriteVRML writes out the given node and its subnodes to a VRML2 file.
Definition: ifsg_api.cpp:81
VRML_LAYER m_bot_silk
VRML_LAYER m_top_silk
VRML_LAYER m_board
VRML_LAYER m_bot_copper
static void create_vrml_shell(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double top_z, double bottom_z)
double m_brd_thickness
static bool USE_DEFS
Definition: export_vrml.cpp:66
VRML_LAYER m_top_copper
VRML_LAYER m_top_tin
VRML_COLOR & GetColor(VRML_COLOR_INDEX aIndex)
double GetLayerZ(LAYER_NUM aLayer)
#define ART_OFFSET
Definition: export_vrml.cpp:60

References ART_OFFSET, B_Cu, B_SilkS, BOARD_SCALE, create_vrml_plane(), create_vrml_shell(), F_Cu, F_SilkS, MODEL_VRML::GetColor(), MODEL_VRML::GetLayerZ(), IFSG_NODE::GetRawPtr(), MODEL_VRML::m_board, MODEL_VRML::m_bot_copper, MODEL_VRML::m_bot_silk, MODEL_VRML::m_bot_tin, MODEL_VRML::m_brd_thickness, MODEL_VRML::m_holes, MODEL_VRML::m_OutputPCB, MODEL_VRML::m_plainPCB, MODEL_VRML::m_plated_holes, MODEL_VRML::m_top_copper, MODEL_VRML::m_top_silk, MODEL_VRML::m_top_tin, USE_DEFS, USE_INLINES, VRML_COLOR_PCB, VRML_COLOR_SILK, VRML_COLOR_TIN, VRML_COLOR_TRACK, write_triangle_bag(), and S3D::WriteVRML().

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ write_triangle_bag()

static void write_triangle_bag ( std::ostream &  aOut_file,
VRML_COLOR aColor,
VRML_LAYER *  aLayer,
bool  aPlane,
bool  aTop,
double  aTop_z,
double  aBottom_z 
)
static

Definition at line 322 of file export_vrml.cpp.

325 {
326  /* A lot of nodes are not required, but blender sometimes chokes
327  * without them */
328  static const char* shape_boiler[] =
329  {
330  "Transform {\n",
331  " children [\n",
332  " Group {\n",
333  " children [\n",
334  " Shape {\n",
335  " appearance Appearance {\n",
336  " material Material {\n",
337  0, // Material marker
338  " }\n",
339  " }\n",
340  " geometry IndexedFaceSet {\n",
341  " solid TRUE\n",
342  " coord Coordinate {\n",
343  " point [\n",
344  0, // Coordinates marker
345  " ]\n",
346  " }\n",
347  " coordIndex [\n",
348  0, // Index marker
349  " ]\n",
350  " }\n",
351  " }\n",
352  " ]\n",
353  " }\n",
354  " ]\n",
355  "}\n",
356  0 // End marker
357  };
358 
359  int marker_found = 0, lineno = 0;
360 
361  while( marker_found < 4 )
362  {
363  if( shape_boiler[lineno] )
364  aOut_file << shape_boiler[lineno];
365  else
366  {
367  marker_found++;
368 
369  switch( marker_found )
370  {
371  case 1: // Material marker
372  aOut_file << " diffuseColor " << std::setprecision(3);
373  aOut_file << aColor.diffuse_red << " ";
374  aOut_file << aColor.diffuse_grn << " ";
375  aOut_file << aColor.diffuse_blu << "\n";
376 
377  aOut_file << " specularColor ";
378  aOut_file << aColor.spec_red << " ";
379  aOut_file << aColor.spec_grn << " ";
380  aOut_file << aColor.spec_blu << "\n";
381 
382  aOut_file << " emissiveColor ";
383  aOut_file << aColor.emit_red << " ";
384  aOut_file << aColor.emit_grn << " ";
385  aOut_file << aColor.emit_blu << "\n";
386 
387  aOut_file << " ambientIntensity " << aColor.ambient << "\n";
388  aOut_file << " transparency " << aColor.transp << "\n";
389  aOut_file << " shininess " << aColor.shiny << "\n";
390  break;
391 
392  case 2:
393 
394  if( aPlane )
395  aLayer->WriteVertices( aTop_z, aOut_file, PRECISION );
396  else
397  aLayer->Write3DVertices( aTop_z, aBottom_z, aOut_file, PRECISION );
398 
399  aOut_file << "\n";
400  break;
401 
402  case 3:
403 
404  if( aPlane )
405  aLayer->WriteIndices( aTop, aOut_file );
406  else
407  aLayer->Write3DIndices( aOut_file );
408 
409  aOut_file << "\n";
410  break;
411 
412  default:
413  break;
414  }
415  }
416 
417  lineno++;
418  }
419 }
float transp
Definition: export_vrml.cpp:89
float spec_blu
Definition: export_vrml.cpp:82
float ambient
Definition: export_vrml.cpp:88
float diffuse_grn
Definition: export_vrml.cpp:77
float spec_red
Definition: export_vrml.cpp:80
float spec_grn
Definition: export_vrml.cpp:81
float emit_grn
Definition: export_vrml.cpp:85
float emit_blu
Definition: export_vrml.cpp:86
float diffuse_red
Definition: export_vrml.cpp:76
static const int PRECISION
Definition: export_vrml.cpp:70
float emit_red
Definition: export_vrml.cpp:84
float diffuse_blu
Definition: export_vrml.cpp:78

References VRML_COLOR::ambient, VRML_COLOR::diffuse_blu, VRML_COLOR::diffuse_grn, VRML_COLOR::diffuse_red, VRML_COLOR::emit_blu, VRML_COLOR::emit_grn, VRML_COLOR::emit_red, PRECISION, VRML_COLOR::shiny, VRML_COLOR::spec_blu, VRML_COLOR::spec_grn, VRML_COLOR::spec_red, and VRML_COLOR::transp.

Referenced by write_layers().

Variable Documentation

◆ BOARD_SCALE

◆ cache

◆ colors

◆ model_vrml

◆ PRECISION

const int PRECISION = 6
static

◆ PROJ_DIR

wxString PROJ_DIR
static

Definition at line 72 of file export_vrml.cpp.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ sgmaterial

SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }
static

Definition at line 142 of file export_vrml.cpp.

Referenced by getSGColor(), and MODEL_VRML::~MODEL_VRML().

◆ SUBDIR_3D

wxString SUBDIR_3D
static

Definition at line 71 of file export_vrml.cpp.

Referenced by export_vrml_module(), and PCB_EDIT_FRAME::ExportVRML_File().

◆ USE_DEFS

bool USE_DEFS
static

◆ USE_INLINES

bool USE_INLINES
static

◆ USE_RELPATH

bool USE_RELPATH
static

Definition at line 67 of file export_vrml.cpp.

Referenced by export_vrml_module(), and PCB_EDIT_FRAME::ExportVRML_File().

◆ WORLD_SCALE

double WORLD_SCALE = 1.0
static

Definition at line 68 of file export_vrml.cpp.

Referenced by PCB_EDIT_FRAME::ExportVRML_File(), and MODEL_VRML::SetScale().