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 <filename_resolver.h>
#include "gr_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 <convert_basic_shapes_to_polygon.h>
#include <geometry/geometry_utils.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 *item)
 
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 61 of file export_vrml.cpp.

◆ MIN_VRML_LINEWIDTH

#define MIN_VRML_LINEWIDTH   0.05

Definition at line 58 of file export_vrml.cpp.

◆ PLATE_OFFSET

#define PLATE_OFFSET   0.005

Definition at line 63 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 132 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 1291 of file export_vrml.cpp.

1292 {
1293  double sina = sin( a / 2 );
1294 
1295  q[0] = x * sina;
1296  q[1] = y * sina;
1297  q[2] = z * sina;
1298  q[3] = cos( a / 2 );
1299 }

Referenced by export_vrml_module().

◆ compose_quat()

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

Definition at line 1315 of file export_vrml.cpp.

1316 {
1317  double tmp[4];
1318 
1319  tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
1320  tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
1321  tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
1322  tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
1323 
1324  qr[0] = tmp[0];
1325  qr[1] = tmp[1];
1326  qr[2] = tmp[2];
1327  qr[3] = tmp[3];
1328 }

Referenced by export_vrml_module().

◆ compute_layer_Zs()

static void compute_layer_Zs ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 564 of file export_vrml.cpp.

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

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(), 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 1690 of file export_vrml.cpp.

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

References IFSG_NORMALS::AddNormal(), IFSG_NODE::GetRawPtr(), getSGColor(), S3D::GetSGNodeParent(), NULL, 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 1768 of file export_vrml.cpp.

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

901 {
902  LAYER_NUM layer = top_layer;
903  bool thru = true;
904 
905  // if not a thru hole do not put a hole in the board
906  if( top_layer != F_Cu || bottom_layer != B_Cu )
907  thru = false;
908 
909  if( thru && hole > 0 )
910  aModel.m_holes.AddCircle( x, -y, hole, true );
911 
912  if( aModel.m_plainPCB )
913  return;
914 
915  while( 1 )
916  {
917  if( layer == B_Cu )
918  {
919  aModel.m_bot_copper.AddCircle( x, -y, r );
920 
921  if( hole > 0 && !thru )
922  aModel.m_bot_copper.AddCircle( x, -y, hole, true );
923 
924  }
925  else if( layer == F_Cu )
926  {
927  aModel.m_top_copper.AddCircle( x, -y, r );
928 
929  if( hole > 0 && !thru )
930  aModel.m_top_copper.AddCircle( x, -y, hole, true );
931 
932  }
933 
934  if( layer == bottom_layer )
935  break;
936 
937  layer = bottom_layer;
938  }
939 }
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 658 of file export_vrml.cpp.

662 {
663  VRML_LAYER* vlayer;
664 
665  if( !GetLayer( aModel, layer, &vlayer ) )
666  return;
667 
668  if( width < aModel.m_minLineWidth )
669  width = aModel.m_minLineWidth;
670 
671  centery = -centery;
672  arc_starty = -arc_starty;
673 
674  if( !vlayer->AddArc( centerx, centery, arc_startx, arc_starty, width, -arc_angle, false ) )
675  throw( std::runtime_error( vlayer->GetError() ) );
676 
677 }
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 839 of file export_vrml.cpp.

840 {
841  SHAPE_POLY_SET pcbOutlines; // stores the board main outlines
842  wxString msg;
843 
844  if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) )
845  {
846  msg << "\n\n" <<
847  _( "Unable to calculate the board outlines; fall back to using the board boundary box." );
848  wxMessageBox( msg );
849  }
850 
851  int seg;
852 
853  for( int cnt = 0; cnt < pcbOutlines.OutlineCount(); cnt++ )
854  {
855  const SHAPE_LINE_CHAIN& outline = pcbOutlines.COutline( cnt );
856 
857  seg = aModel.m_board.NewContour();
858 
859  for( int j = 0; j < outline.PointCount(); j++ )
860  {
861  aModel.m_board.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
862  -((double)outline.CPoint(j).y * BOARD_SCALE ) );
863 
864  }
865 
866  aModel.m_board.EnsureWinding( seg, false );
867 
868  // Generate holes:
869  for( int ii = 0; ii < pcbOutlines.HoleCount( cnt ); ii++ )
870  {
871  const SHAPE_LINE_CHAIN& hole = pcbOutlines.Hole( cnt, ii );
872 
873  seg = aModel.m_holes.NewContour();
874 
875  if( seg < 0 )
876  {
877  msg << "\n\n" <<
878  _( "VRML Export Failed: Could not add holes to contours." );
879  wxMessageBox( msg );
880 
881  return;
882  }
883 
884  for( int j = 0; j < hole.PointCount(); j++ )
885  {
886  aModel.m_holes.AddVertex( seg, (double)hole.CPoint(j).x * BOARD_SCALE,
887  -((double)hole.CPoint(j).y * BOARD_SCALE ) );
888 
889  }
890 
891  aModel.m_holes.EnsureWinding( seg, true );
892  }
893  }
894 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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 Point()
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
#define _(s)
Definition: 3d_actions.cpp:33
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 627 of file export_vrml.cpp.

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

◆ export_vrml_drawings()

static void export_vrml_drawings ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 811 of file export_vrml.cpp.

812 {
813  // draw graphic items
814  for( auto drawing : pcb->Drawings() )
815  {
816  PCB_LAYER_ID layer = drawing->GetLayer();
817 
818  if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
819  continue;
820 
821  switch( drawing->Type() )
822  {
823  case PCB_LINE_T:
824  export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing );
825  break;
826 
827  case PCB_TEXT_T:
828  export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing );
829  break;
830 
831  default:
832  break;
833  }
834  }
835 }
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
DRAWINGS & Drawings()
Definition: class_board.h:238

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 717 of file export_vrml.cpp.

718 {
719  LAYER_NUM layer = drawseg->GetLayer();
720  double w = drawseg->GetWidth() * BOARD_SCALE;
721  double x = drawseg->GetStart().x * BOARD_SCALE;
722  double y = drawseg->GetStart().y * BOARD_SCALE;
723  double xf = drawseg->GetEnd().x * BOARD_SCALE;
724  double yf = drawseg->GetEnd().y * BOARD_SCALE;
725  double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) );
726 
727  // Items on the edge layer are handled elsewhere; just return
728  if( layer == Edge_Cuts )
729  return;
730 
731  switch( drawseg->GetShape() )
732  {
733  case S_ARC:
734  export_vrml_arc( aModel, layer,
735  (double) drawseg->GetCenter().x * BOARD_SCALE,
736  (double) drawseg->GetCenter().y * BOARD_SCALE,
737  (double) drawseg->GetArcStart().x * BOARD_SCALE,
738  (double) drawseg->GetArcStart().y * BOARD_SCALE,
739  w, drawseg->GetAngle() / 10 );
740  break;
741 
742  case S_CIRCLE:
743  // Break circles into two 180 arcs to prevent the vrml hole from obscuring objects
744  // within the hole area of the circle.
745  export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 );
746  export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 );
747  break;
748 
749  case S_POLYGON:
750  export_vrml_polygon( aModel, layer, drawseg, 0.0, wxPoint( 0, 0 ) );
751  break;
752 
753  default:
754  export_vrml_line( aModel, layer, x, y, xf, yf, w );
755  break;
756  }
757 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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, S_POLYGON, wxPoint::x, and wxPoint::y.

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 1044 of file export_vrml.cpp.

1046 {
1047  LAYER_NUM layer = aOutline->GetLayer();
1048  double x = aOutline->GetStart().x * BOARD_SCALE;
1049  double y = aOutline->GetStart().y * BOARD_SCALE;
1050  double xf = aOutline->GetEnd().x * BOARD_SCALE;
1051  double yf = aOutline->GetEnd().y * BOARD_SCALE;
1052  double w = aOutline->GetWidth() * BOARD_SCALE;
1053 
1054  switch( aOutline->GetShape() )
1055  {
1056  case S_SEGMENT:
1057  export_vrml_line( aModel, layer, x, y, xf, yf, w );
1058  break;
1059 
1060  case S_ARC:
1061  export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
1062  break;
1063 
1064  case S_CIRCLE:
1065  export_vrml_circle( aModel, layer, x, y, xf, yf, w );
1066  break;
1067 
1068  case S_POLYGON:
1069  export_vrml_polygon( aModel, layer, aOutline, aModule->GetOrientationRadians(),
1070  aModule->GetPosition() );
1071  break;
1072 
1073  default:
1074  break;
1075  }
1076 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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:217
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:210

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, S_SEGMENT, wxPoint::x, and wxPoint::y.

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 602 of file export_vrml.cpp.

605 {
606  VRML_LAYER* vlayer;
607 
608  if( !GetLayer( aModel, layer, &vlayer ) )
609  return;
610 
611  if( width < aModel.m_minLineWidth)
612  width = aModel.m_minLineWidth;
613 
614  starty = -starty;
615  endy = -endy;
616 
617  double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI;
618  double length = Distance( startx, starty, endx, endy ) + width;
619  double cx = ( startx + endx ) / 2.0;
620  double cy = ( starty + endy ) / 2.0;
621 
622  if( !vlayer->AddSlot( cx, cy, length, width, angle, false ) )
623  throw( std::runtime_error( vlayer->GetError() ) );
624 }
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

References PNS::angle(), 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 1331 of file export_vrml.cpp.

1333 {
1334  if( !aModel.m_plainPCB )
1335  {
1336  // Reference and value
1337  if( aModule->Reference().IsVisible() )
1338  export_vrml_text_module( &aModule->Reference() );
1339 
1340  if( aModule->Value().IsVisible() )
1341  export_vrml_text_module( &aModule->Value() );
1342 
1343  // Export module edges
1344 
1345  for( auto item : aModule->GraphicalItems() )
1346  {
1347  switch( item->Type() )
1348  {
1349  case PCB_MODULE_TEXT_T:
1350  export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
1351  break;
1352 
1353  case PCB_MODULE_EDGE_T:
1354  export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ),
1355  aModule );
1356  break;
1357 
1358  default:
1359  break;
1360  }
1361  }
1362  }
1363 
1364  // Export pads
1365  for( auto pad : aModule->Pads() )
1366  export_vrml_pad( aModel, aPcb, pad );
1367 
1368  bool isFlipped = aModule->GetLayer() == B_Cu;
1369 
1370  // Export the object VRML model(s)
1371  auto sM = aModule->Models().begin();
1372  auto eM = aModule->Models().end();
1373 
1374  wxFileName subdir( SUBDIR_3D, "" );
1375 
1376  while( sM != eM )
1377  {
1378  SGNODE* mod3d = (SGNODE*) cache->Load( sM->m_Filename );
1379 
1380  if( NULL == mod3d )
1381  {
1382  ++sM;
1383  continue;
1384  }
1385 
1386  /* Calculate 3D shape rotation:
1387  * this is the rotation parameters, with an additional 180 deg rotation
1388  * for footprints that are flipped
1389  * When flipped, axis rotation is the horizontal axis (X axis)
1390  */
1391  double rotx = -sM->m_Rotation.x;
1392  double roty = -sM->m_Rotation.y;
1393  double rotz = -sM->m_Rotation.z;
1394 
1395  if( isFlipped )
1396  {
1397  rotx += 180.0;
1398  roty = -roty;
1399  rotz = -rotz;
1400  }
1401 
1402  // Do some quaternion munching
1403  double q1[4], q2[4], rot[4];
1404  build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
1405  build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
1406  compose_quat( q1, q2, q1 );
1407  build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
1408  compose_quat( q1, q2, q1 );
1409 
1410  // Note here aModule->GetOrientation() is in 0.1 degrees,
1411  // so module rotation has to be converted to radians
1412  build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
1413  compose_quat( q1, q2, q1 );
1414  from_quat( q1, rot );
1415 
1416  double offsetFactor = 1000.0f * IU_PER_MILS / 25.4f;
1417 
1418  // adjust 3D shape local offset position
1419  // they are given in mm, so they are converted in board IU.
1420  double offsetx = sM->m_Offset.x * offsetFactor;
1421  double offsety = sM->m_Offset.y * offsetFactor;
1422  double offsetz = sM->m_Offset.z * offsetFactor;
1423 
1424  if( isFlipped )
1425  offsetz = -offsetz;
1426  else // In normal mode, Y axis is reversed in Pcbnew.
1427  offsety = -offsety;
1428 
1429  RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
1430 
1431  SGPOINT trans;
1432  trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.m_tx;
1433  trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.m_ty;
1434  trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() );
1435 
1436  if( USE_INLINES )
1437  {
1438  wxFileName srcFile = cache->GetResolver()->ResolvePath( sM->m_Filename );
1439  wxFileName dstFile;
1440  dstFile.SetPath( SUBDIR_3D );
1441  dstFile.SetName( srcFile.GetName() );
1442  dstFile.SetExt( "wrl" );
1443 
1444  // copy the file if necessary
1445  wxDateTime srcModTime = srcFile.GetModificationTime();
1446  wxDateTime destModTime = srcModTime;
1447 
1448  destModTime.SetToCurrent();
1449 
1450  if( dstFile.FileExists() )
1451  destModTime = dstFile.GetModificationTime();
1452 
1453  if( srcModTime != destModTime )
1454  {
1455  wxLogDebug( "Copying 3D model %s to %s.",
1456  GetChars( srcFile.GetFullPath() ),
1457  GetChars( dstFile.GetFullPath() ) );
1458 
1459  wxString fileExt = srcFile.GetExt();
1460  fileExt.LowerCase();
1461 
1462  // copy VRML models and use the scenegraph library to
1463  // translate other model types
1464  if( fileExt == "wrl" )
1465  {
1466  if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
1467  continue;
1468  }
1469  else
1470  {
1471  if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
1472  continue;
1473  }
1474  }
1475 
1476  (*aOutputFile) << "Transform {\n";
1477 
1478  // only write a rotation if it is >= 0.1 deg
1479  if( std::abs( rot[3] ) > 0.0001745 )
1480  {
1481  (*aOutputFile) << " rotation " << std::setprecision( 5 );
1482  (*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
1483  }
1484 
1485  (*aOutputFile) << " translation " << std::setprecision( PRECISION );
1486  (*aOutputFile) << trans.x << " ";
1487  (*aOutputFile) << trans.y << " ";
1488  (*aOutputFile) << trans.z << "\n";
1489 
1490  (*aOutputFile) << " scale ";
1491  (*aOutputFile) << sM->m_Scale.x << " ";
1492  (*aOutputFile) << sM->m_Scale.y << " ";
1493  (*aOutputFile) << sM->m_Scale.z << "\n";
1494 
1495  (*aOutputFile) << " children [\n Inline {\n url \"";
1496 
1497  if( USE_RELPATH )
1498  {
1499  wxFileName tmp = dstFile;
1500  tmp.SetExt( "" );
1501  tmp.SetName( "" );
1502  tmp.RemoveLastDir();
1503  dstFile.MakeRelativeTo( tmp.GetPath() );
1504  }
1505 
1506  wxString fn = dstFile.GetFullPath();
1507  fn.Replace( "\\", "/" );
1508  (*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
1509  (*aOutputFile) << " }\n";
1510  }
1511  else
1512  {
1513  IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( aModel.m_OutputPCB.GetRawPtr() );
1514 
1515  // only write a rotation if it is >= 0.1 deg
1516  if( std::abs( rot[3] ) > 0.0001745 )
1517  modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
1518 
1519  modelShape->SetTranslation( trans );
1520  modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
1521 
1522  if( NULL == S3D::GetSGNodeParent( mod3d ) )
1523  {
1524  aModel.m_components.push_back( mod3d );
1525  modelShape->AddChildNode( mod3d );
1526  }
1527  else
1528  {
1529  modelShape->AddRefNode( mod3d );
1530  }
1531 
1532  }
1533 
1534  ++sM;
1535  }
1536 }
bool SetTranslation(const SGPOINT &aTranslation)
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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:215
TEXTE_MODULE & Reference()
Definition: class_module.h:477
static S3D_CACHE * cache
Definition: export_vrml.cpp:65
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:66
static void export_vrml_text_module(TEXTE_MODULE *item)
bool IsVisible() const
Definition: eda_text.h:170
PADS & Pads()
Definition: class_module.h:173
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
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
bool SetScale(const SGPOINT &aScale)
IFSG_TRANSFORM m_OutputPCB
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
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:48
#define NULL
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
static bool USE_RELPATH
Definition: export_vrml.cpp:68
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
static wxString SUBDIR_3D
Definition: export_vrml.cpp:72
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:205
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:101
double DEG2RAD(double deg)
Definition: trigo.h:214
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
double DECIDEG2RAD(double deg)
Definition: trigo.h:218
static void from_quat(double q[4], double rot[4])
#define IU_PER_MILS
Definition: plotter.cpp:137
static const int PRECISION
Definition: export_vrml.cpp:71
static bool USE_DEFS
Definition: export_vrml.cpp:67
FILENAME_RESOLVER * GetResolver(void)
Definition: 3d_cache.cpp:690
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:283
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:210
double GetLayerZ(LAYER_NUM aLayer)

References 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::GraphicalItems(), 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(), NULL, MODULE::Pads(), 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(), wxPoint::x, SGPOINT::x, and wxPoint::y.

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 1211 of file export_vrml.cpp.

1212 {
1213  double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0;
1214  double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0;
1215  double hole_drill = std::min( hole_drill_w, hole_drill_h );
1216  double hole_x = aPad->GetPosition().x * BOARD_SCALE;
1217  double hole_y = aPad->GetPosition().y * BOARD_SCALE;
1218 
1219  // Export the hole on the edge layer
1220  if( hole_drill > 0 )
1221  {
1222  bool pth = false;
1223 
1224  if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
1225  && !aModel.m_plainPCB )
1226  pth = true;
1227 
1228  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1229  {
1230  // Oblong hole (slot)
1231 
1232  if( pth )
1233  {
1234  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
1235  hole_drill_h * 2.0 + PLATE_OFFSET,
1236  aPad->GetOrientation()/10.0, true, true );
1237 
1238  aModel.m_plated_holes.AddSlot( hole_x, -hole_y,
1239  hole_drill_w * 2.0, hole_drill_h * 2.0,
1240  aPad->GetOrientation()/10.0, true, false );
1241  }
1242  else
1243  {
1244  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
1245  aPad->GetOrientation()/10.0, true, false );
1246 
1247  }
1248  }
1249  else
1250  {
1251  // Drill a round hole
1252 
1253  if( pth )
1254  {
1255  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
1256  aModel.m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1257  }
1258  else
1259  {
1260  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1261  }
1262 
1263  }
1264  }
1265 
1266  if( aModel.m_plainPCB )
1267  return;
1268 
1269  // The pad proper, on the selected layers
1270  LSET layer_mask = aPad->GetLayerSet();
1271 
1272  if( layer_mask[B_Cu] )
1273  {
1274  if( layer_mask[B_Mask] )
1275  export_vrml_padshape( aModel, &aModel.m_bot_tin, aPad );
1276  else
1277  export_vrml_padshape( aModel, &aModel.m_bot_copper, aPad );
1278  }
1279  if( layer_mask[F_Cu] )
1280  {
1281  if( layer_mask[F_Mask] )
1282  export_vrml_padshape( aModel, &aModel.m_top_tin, aPad );
1283  else
1284  export_vrml_padshape( aModel, &aModel.m_top_copper, aPad );
1285  }
1286 
1287 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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:449
static void export_vrml_padshape(MODEL_VRML &aModel, VRML_LAYER *aTinLayer, D_PAD *aPad)
LSET is a set of PCB_LAYER_IDs.
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:432
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:446
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:426
const wxSize & GetDrillSize() const
Definition: class_pad.h:306
#define PLATE_OFFSET
Definition: export_vrml.cpp:63
VRML_LAYER m_top_copper
const wxPoint GetPosition() const override
Definition: class_pad.h:241
VRML_LAYER m_top_tin

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, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_DRILL_SHAPE_OBLONG, PLATE_OFFSET, wxPoint::x, and wxPoint::y.

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 1079 of file export_vrml.cpp.

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

References BOARD_SCALE, SHAPE_LINE_CHAIN::CPoint(), D_PAD::GetDelta(), D_PAD::GetOrientation(), D_PAD::GetRoundRectCornerRadius(), D_PAD::GetShape(), D_PAD::GetSize(), 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::PointCount(), RotatePoint(), D_PAD::ShapePos(), TransformRoundChamferedRectToPolygon(), wxPoint::x, VECTOR2< T >::x, wxPoint::y, 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 774 of file export_vrml.cpp.

775 {
776  model_vrml->m_text_layer = text->GetLayer();
778 
779  wxSize size = text->GetTextSize();
780 
781  if( text->IsMirrored() )
782  size.x = -size.x;
783 
784  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
785 
786  if( text->IsMultilineAllowed() )
787  {
788  wxArrayString strings_list;
789  wxStringSplit( text->GetShownText(), strings_list, '\n' );
790  std::vector<wxPoint> positions;
791  positions.reserve( strings_list.Count() );
792  text->GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
793 
794  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
795  {
796  wxString& txt = strings_list.Item( ii );
797  GRText( NULL, positions[ii], color, txt, text->GetTextAngle(), size,
798  text->GetHorizJustify(), text->GetVertJustify(), text->GetThickness(),
799  text->IsItalic(), true, vrml_text_callback );
800  }
801  }
802  else
803  {
804  GRText( NULL, text->GetTextPos(), color, text->GetShownText(), text->GetTextAngle(),
805  size, text->GetHorizJustify(), text->GetVertJustify(), text->GetThickness(),
806  text->IsItalic(), true, vrml_text_callback );
807  }
808 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:336
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:184
bool IsMirrored() const
Definition: eda_text.h:173
int color
Definition: DXF_plotter.cpp:61
double GetTextAngle() const
Definition: eda_text.h:158
static MODEL_VRML * model_vrml
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
bool IsItalic() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
#define NULL
const wxSize & GetTextSize() const
Definition: eda_text.h:223
bool IsMultilineAllowed() const
Definition: eda_text.h:181
LAYER_NUM m_text_layer
void GRText(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 GRText Draw a graphic text (like module texts)
Definition: gr_text.cpp:143
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
void GetPositionsOfLinesOfMultilineText(std::vector< wxPoint > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
Definition: eda_text.cpp:384
virtual wxString GetShownText() const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:129
Definition: colors.h:45
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40

References BLACK, color, 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(), GRText(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), EDA_TEXT::IsMultilineAllowed(), MODEL_VRML::m_text_layer, MODEL_VRML::m_text_width, model_vrml, NULL, 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 680 of file export_vrml.cpp.

682 {
683  if( aOutline->IsPolyShapeValid() )
684  {
685  SHAPE_POLY_SET shape = aOutline->GetPolyShape();
686  VRML_LAYER* vlayer;
687 
688  if( !GetLayer( aModel, layer, &vlayer ) )
689  return;
690 
691  if( aOutline->GetWidth() )
692  {
693  int numSegs = std::max(
694  GetArcToSegmentCount( aOutline->GetWidth() / 2, ARC_HIGH_DEF, 360.0 ), 6 );
695  shape.Inflate( aOutline->GetWidth() / 2, numSegs );
697  }
698 
699  shape.Rotate( -aOrientation, VECTOR2I( 0, 0 ) );
700  shape.Move( aPos );
701  const SHAPE_LINE_CHAIN& outline = shape.COutline( 0 );
702 
703  int seg = vlayer->NewContour();
704 
705  for( int j = 0; j < outline.PointCount(); j++ )
706  {
707  if( !vlayer->AddVertex( seg, outline.CPoint( j ).x * BOARD_SCALE,
708  -outline.CPoint( j ).y * BOARD_SCALE ) )
709  throw( std::runtime_error( vlayer->GetError() ) );
710  }
711 
712  vlayer->EnsureWinding( seg, false );
713  }
714 }
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 })
Function Rotate rotates all vertices by a given angle.
static double BOARD_SCALE
Definition: export_vrml.cpp:70
void Inflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Performs outline inflation/deflation.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void Move(const VECTOR2I &aVector) override
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
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)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)

References BOARD_SCALE, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_POLY_SET::Fracture(), GetArcToSegmentCount(), 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 item)
static

Definition at line 1025 of file export_vrml.cpp.

1026 {
1027  if( item->IsVisible() )
1028  {
1029  wxSize size = item->GetTextSize();
1030 
1031  if( item->IsMirrored() )
1032  size.x = -size.x; // Text is mirrored
1033 
1034  model_vrml->m_text_layer = item->GetLayer();
1036 
1037  GRText( NULL, item->GetTextPos(), BLACK, item->GetShownText(), item->GetDrawRotation(),
1038  size, item->GetHorizJustify(), item->GetVertJustify(), item->GetThickness(),
1039  item->IsItalic(), true, vrml_text_callback );
1040  }
1041 }
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:184
bool IsMirrored() const
Definition: eda_text.h:173
bool IsVisible() const
Definition: eda_text.h:170
static MODEL_VRML * model_vrml
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
virtual wxString GetShownText() const override
Return the string actually shown after processing of the base text.
bool IsItalic() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
#define NULL
const wxSize & GetTextSize() const
Definition: eda_text.h:223
LAYER_NUM m_text_layer
void GRText(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 GRText Draw a graphic text (like module texts)
Definition: gr_text.cpp:143
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
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, TEXTE_MODULE::GetDrawRotation(), EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), TEXTE_MODULE::GetShownText(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetThickness(), EDA_TEXT::GetVertJustify(), GRText(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), EDA_TEXT::IsVisible(), MODEL_VRML::m_text_layer, MODEL_VRML::m_text_width, model_vrml, NULL, 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 962 of file export_vrml.cpp.

963 {
964  for( auto track : pcb->Tracks() )
965  {
966  if( track->Type() == PCB_VIA_T )
967  {
968  export_vrml_via( aModel, pcb, (const VIA*) track );
969  }
970  else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
971  && !aModel.m_plainPCB )
972  export_vrml_line( aModel, track->GetLayer(),
973  track->GetStart().x * BOARD_SCALE,
974  track->GetStart().y * BOARD_SCALE,
975  track->GetEnd().x * BOARD_SCALE,
976  track->GetEnd().y * BOARD_SCALE,
977  track->GetWidth() * BOARD_SCALE );
978  }
979 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
static void export_vrml_via(MODEL_VRML &aModel, BOARD *aPcb, const VIA *aVia)
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
TRACKS & Tracks()
Definition: class_board.h:220

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

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 942 of file export_vrml.cpp.

943 {
944  double x, y, r, hole;
945  PCB_LAYER_ID top_layer, bottom_layer;
946 
947  hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0;
948  r = aVia->GetWidth() * BOARD_SCALE / 2.0;
949  x = aVia->GetStart().x * BOARD_SCALE;
950  y = aVia->GetStart().y * BOARD_SCALE;
951  aVia->LayerPair( &top_layer, &bottom_layer );
952 
953  // do not render a buried via
954  if( top_layer != F_Cu && bottom_layer != B_Cu )
955  return;
956 
957  // Export the via padstack
958  export_round_padstack( aModel, aPcb, x, y, r, bottom_layer, top_layer, hole );
959 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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:111
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:105

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

Referenced by export_vrml_tracks().

◆ export_vrml_zones()

static void export_vrml_zones ( MODEL_VRML aModel,
BOARD aPcb 
)
static

Definition at line 982 of file export_vrml.cpp.

983 {
984 
985  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
986  {
987  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
988 
989  VRML_LAYER* vl;
990 
991  if( !GetLayer( aModel, zone->GetLayer(), &vl ) )
992  continue;
993 
994  // fixme: this modifies the board where it shouldn't, but I don't have the time
995  // to clean this up - TW
996  if( !zone->IsFilled() )
997  {
998  ZONE_FILLER filler( aPcb );
999  zone->SetFillMode( ZONE_FILL_MODE::POLYGONS ); // use filled polygons
1000  filler.Fill( { zone } );
1001  }
1002 
1003  const SHAPE_POLY_SET& poly = zone->GetFilledPolysList();
1004 
1005  for( int i = 0; i < poly.OutlineCount(); i++ )
1006  {
1007  const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
1008 
1009  int seg = vl->NewContour();
1010 
1011  for( int j = 0; j < outline.PointCount(); j++ )
1012  {
1013  if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * BOARD_SCALE,
1014  -((double)outline.CPoint( j ).y * BOARD_SCALE ) ) )
1015  throw( std::runtime_error( vl->GetError() ) );
1016 
1017  }
1018 
1019  vl->EnsureWinding( seg, false );
1020  }
1021  }
1022 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool IsFilled() const
Definition: class_zone.h:188
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:213
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:919
SHAPE_POLY_SET.
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:155
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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:884
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:571

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(), ZONE_CONTAINER::IsFilled(), SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), POLYGONS, ZONE_CONTAINER::SetFillMode(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ from_quat()

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

Definition at line 1303 of file export_vrml.cpp.

1304 {
1305  rot[3] = acos( q[3] ) * 2;
1306 
1307  for( int i = 0; i < 3; i++ )
1308  {
1309  rot[i] = q[i] / sin( rot[3] / 2 );
1310  }
1311 }

Referenced by export_vrml_module().

◆ GetLayer()

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

Definition at line 290 of file export_vrml.cpp.

291 {
292  switch( layer )
293  {
294  case B_Cu:
295  *vlayer = &aModel.m_bot_copper;
296  break;
297 
298  case F_Cu:
299  *vlayer = &aModel.m_top_copper;
300  break;
301 
302  case B_SilkS:
303  *vlayer = &aModel.m_bot_silk;
304  break;
305 
306  case F_SilkS:
307  *vlayer = &aModel.m_top_silk;
308  break;
309 
310  default:
311  return false;
312  }
313 
314  return true;
315 }
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 SCH_EAGLE_PLUGIN::addBusEntries(), BuildBoardPolygonOutlines(), export_vrml_arc(), export_vrml_circle(), export_vrml_line(), export_vrml_polygon(), export_vrml_zones(), EE_COLLECTOR::IsCorner(), MODULE::IsFlipped(), DIALOG_FOOTPRINT_FP_EDITOR::OnAddField(), and DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField().

◆ getSGColor()

static SGNODE* getSGColor ( VRML_COLOR_INDEX  colorIdx)
static

Definition at line 1663 of file export_vrml.cpp.

1664 {
1665  if( colorIdx == -1 )
1666  colorIdx = VRML_COLOR_PCB;
1667  else if( colorIdx == VRML_COLOR_LAST )
1668  return NULL;
1669 
1670  if( sgmaterial[colorIdx] )
1671  return sgmaterial[colorIdx];
1672 
1673  IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
1674  VRML_COLOR* cp = &colors[colorIdx];
1675 
1676  vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
1677  vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
1678  vcolor.SetShininess( cp->shiny );
1679  // NOTE: XXX - replace with a better equation; using this definition
1680  // of ambient will not yield the best results
1681  vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
1682  vcolor.SetTransparency( cp->transp );
1683 
1684  sgmaterial[colorIdx] = vcolor.GetRawPtr();
1685 
1686  return sgmaterial[colorIdx];
1687 }
float transp
Definition: export_vrml.cpp:90
static SGNODE * sgmaterial[VRML_COLOR_LAST]
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
float spec_blu
Definition: export_vrml.cpp:83
float ambient
Definition: export_vrml.cpp:89
float diffuse_grn
Definition: export_vrml.cpp:78
#define NULL
float spec_red
Definition: export_vrml.cpp:81
float spec_grn
Definition: export_vrml.cpp:82
float diffuse_red
Definition: export_vrml.cpp:77
float diffuse_blu
Definition: export_vrml.cpp:79
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(), NULL, 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 762 of file export_vrml.cpp.

763 {
764  LAYER_NUM m_text_layer = model_vrml->m_text_layer;
765  int m_text_width = model_vrml->m_text_width;
766 
767  export_vrml_line( *model_vrml, m_text_layer,
768  x0 * BOARD_SCALE, y0 * BOARD_SCALE,
769  xf * BOARD_SCALE, yf * BOARD_SCALE,
770  m_text_width * BOARD_SCALE );
771 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
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 423 of file export_vrml.cpp.

425 {
426  // VRML_LAYER board;
427  aModel.m_board.Tesselate( &aModel.m_holes );
428  double brdz = aModel.m_brd_thickness / 2.0
429  - ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE;
430 
431  if( USE_INLINES )
432  {
433  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ),
434  &aModel.m_board, false, false, brdz, -brdz );
435  }
436  else
437  {
438  create_vrml_shell( aModel.m_OutputPCB, VRML_COLOR_PCB, &aModel.m_board, brdz, -brdz );
439  }
440 
441  if( aModel.m_plainPCB )
442  {
443  if( !USE_INLINES )
444  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), USE_DEFS, true );
445 
446  return;
447  }
448 
449  // VRML_LAYER m_top_copper;
450  aModel.m_top_copper.Tesselate( &aModel.m_holes );
451 
452  if( USE_INLINES )
453  {
454  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
455  &aModel.m_top_copper, true, true,
456  aModel.GetLayerZ( F_Cu ), 0 );
457  }
458  else
459  {
461  aModel.GetLayerZ( F_Cu ), true );
462  }
463 
464  // VRML_LAYER m_top_tin;
465  aModel.m_top_tin.Tesselate( &aModel.m_holes );
466 
467  if( USE_INLINES )
468  {
469  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
470  &aModel.m_top_tin, true, true,
471  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
472  0 );
473  }
474  else
475  {
477  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
478  true );
479  }
480 
481  // VRML_LAYER m_bot_copper;
482  aModel.m_bot_copper.Tesselate( &aModel.m_holes );
483 
484  if( USE_INLINES )
485  {
486  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
487  &aModel.m_bot_copper, true, false,
488  aModel.GetLayerZ( B_Cu ), 0 );
489  }
490  else
491  {
493  aModel.GetLayerZ( B_Cu ), false );
494  }
495 
496  // VRML_LAYER m_bot_tin;
497  aModel.m_bot_tin.Tesselate( &aModel.m_holes );
498 
499  if( USE_INLINES )
500  {
501  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
502  &aModel.m_bot_tin, true, false,
503  aModel.GetLayerZ( B_Cu )
504  - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
505  0 );
506  }
507  else
508  {
510  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
511  false );
512  }
513 
514  // VRML_LAYER PTH;
515  aModel.m_plated_holes.Tesselate( NULL, true );
516 
517  if( USE_INLINES )
518  {
519  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
520  &aModel.m_plated_holes, false, false,
521  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
522  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
523  }
524  else
525  {
527  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
528  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
529  }
530 
531  // VRML_LAYER m_top_silk;
532  aModel.m_top_silk.Tesselate( &aModel.m_holes );
533 
534  if( USE_INLINES )
535  {
536  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk,
537  true, true, aModel.GetLayerZ( F_SilkS ), 0 );
538  }
539  else
540  {
542  aModel.GetLayerZ( F_SilkS ), true );
543  }
544 
545  // VRML_LAYER m_bot_silk;
546  aModel.m_bot_silk.Tesselate( &aModel.m_holes );
547 
548  if( USE_INLINES )
549  {
550  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk,
551  true, false, aModel.GetLayerZ( B_SilkS ), 0 );
552  }
553  else
554  {
556  aModel.GetLayerZ( B_SilkS ), false );
557  }
558 
559  if( !USE_INLINES )
560  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), true, true );
561 }
static double BOARD_SCALE
Definition: export_vrml.cpp:70
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
static bool USE_INLINES
Definition: export_vrml.cpp:66
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
#define NULL
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:67
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:61

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, NULL, 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 323 of file export_vrml.cpp.

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

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 73 of file export_vrml.cpp.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ sgmaterial

SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }
static

Definition at line 143 of file export_vrml.cpp.

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

◆ SUBDIR_3D

wxString SUBDIR_3D
static

Definition at line 72 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 68 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 69 of file export_vrml.cpp.

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