KiCad PCB EDA Suite
export_vrml.cpp File Reference
#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 "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, COMMIT *aCommit)
 
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 57 of file export_vrml.cpp.

◆ MIN_VRML_LINEWIDTH

#define MIN_VRML_LINEWIDTH   0.05

Definition at line 54 of file export_vrml.cpp.

◆ PLATE_OFFSET

#define PLATE_OFFSET   0.005

Definition at line 59 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 128 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 1322 of file export_vrml.cpp.

1323 {
1324  double sina = sin( a / 2 );
1325 
1326  q[0] = x * sina;
1327  q[1] = y * sina;
1328  q[2] = z * sina;
1329  q[3] = cos( a / 2 );
1330 }

Referenced by export_vrml_module().

◆ compose_quat()

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

Definition at line 1344 of file export_vrml.cpp.

1345 {
1346  double tmp[4];
1347 
1348  tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
1349  tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
1350  tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
1351  tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
1352 
1353  qr[0] = tmp[0];
1354  qr[1] = tmp[1];
1355  qr[2] = tmp[2];
1356  qr[3] = tmp[3];
1357 }

Referenced by export_vrml_module().

◆ compute_layer_Zs()

static void compute_layer_Zs ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 545 of file export_vrml.cpp.

546 {
547  int copper_layers = pcb->GetCopperLayerCount();
548 
549  // We call it 'layer' thickness, but it's the whole board thickness!
551  double half_thickness = aModel.m_brd_thickness / 2;
552 
553  // Compute each layer's Z value, more or less like the 3d view
554  for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq )
555  {
556  PCB_LAYER_ID i = *seq;
557 
558  if( i < copper_layers )
559  aModel.SetLayerZ( i, half_thickness - aModel.m_brd_thickness * i / (copper_layers - 1) );
560  else
561  aModel.SetLayerZ( i, - half_thickness ); // bottom layer
562  }
563 
564  /* To avoid rounding interference, we apply an epsilon to each
565  * successive layer */
566  double epsilon_z = Millimeter2iu( ART_OFFSET ) * BOARD_SCALE;
567  aModel.SetLayerZ( B_Paste, -half_thickness - epsilon_z * 4 );
568  aModel.SetLayerZ( B_Adhes, -half_thickness - epsilon_z * 3 );
569  aModel.SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 2 );
570  aModel.SetLayerZ( B_Mask, -half_thickness - epsilon_z );
571  aModel.SetLayerZ( F_Mask, half_thickness + epsilon_z );
572  aModel.SetLayerZ( F_SilkS, half_thickness + epsilon_z * 2 );
573  aModel.SetLayerZ( F_Adhes, half_thickness + epsilon_z * 3 );
574  aModel.SetLayerZ( F_Paste, half_thickness + epsilon_z * 4 );
575  aModel.SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
576  aModel.SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
577  aModel.SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
578  aModel.SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
579  aModel.SetLayerZ( Edge_Cuts, 0 );
580 }
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:719
static double BOARD_SCALE
Definition: export_vrml.cpp:66
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
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
static constexpr int Millimeter2iu(double mm)
#define ART_OFFSET
Definition: export_vrml.cpp:57

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

1718 {
1719  std::vector< double > vertices;
1720  std::vector< int > idxPlane;
1721 
1722  if( !( *layer ).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
1723  {
1724  return;
1725  }
1726 
1727  if( ( idxPlane.size() % 3 ) )
1728  {
1729  throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
1730  }
1731 
1732  std::vector< SGPOINT > vlist;
1733  size_t nvert = vertices.size() / 3;
1734  size_t j = 0;
1735 
1736  for( size_t i = 0; i < nvert; ++i, j+= 3 )
1737  vlist.emplace_back( vertices[j], vertices[j+1], vertices[j+2] );
1738 
1739  // create the intermediate scenegraph
1740  IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
1741  IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
1742  IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
1743  IFSG_COORDS cp( face ); // coordinates for all faces
1744  cp.SetCoordsList( nvert, &vlist[0] );
1745  IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
1746  coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
1747  IFSG_NORMALS norms( face ); // normals for the top and bottom planes
1748 
1749  // set the normals
1750  if( aTopPlane )
1751  {
1752  for( size_t i = 0; i < nvert; ++i )
1753  norms.AddNormal( 0.0, 0.0, 1.0 );
1754  }
1755  else
1756  {
1757  for( size_t i = 0; i < nvert; ++i )
1758  norms.AddNormal( 0.0, 0.0, -1.0 );
1759  }
1760 
1761  // assign a color from the palette
1762  SGNODE* modelColor = getSGColor( colorID );
1763 
1764  if( NULL != modelColor )
1765  {
1766  if( NULL == S3D::GetSGNodeParent( modelColor ) )
1767  shape.AddChildNode( modelColor );
1768  else
1769  shape.AddRefNode( modelColor );
1770  }
1771 }
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
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
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 1774 of file export_vrml.cpp.

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

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

643 {
644  VRML_LAYER* vlayer;
645 
646  if( !GetLayer( aModel, layer, &vlayer ) )
647  return;
648 
649  if( width < aModel.m_minLineWidth )
650  width = aModel.m_minLineWidth;
651 
652  centery = -centery;
653  arc_starty = -arc_starty;
654 
655  if( !vlayer->AddArc( centerx, centery, arc_startx, arc_starty, width, -arc_angle, false ) )
656  throw( std::runtime_error( vlayer->GetError() ) );
657 
658 }
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(), export_vrml_edge_module(), and export_vrml_tracks().

◆ export_vrml_board()

static void export_vrml_board ( MODEL_VRML aModel,
BOARD aPcb 
)
static

Definition at line 830 of file export_vrml.cpp.

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

611 {
612  VRML_LAYER* vlayer;
613 
614  if( !GetLayer( aModel, layer, &vlayer ) )
615  return;
616 
617  if( width < aModel.m_minLineWidth )
618  width = aModel.m_minLineWidth;
619 
620  starty = -starty;
621  endy = -endy;
622 
623  double hole, radius;
624 
625  radius = Distance( startx, starty, endx, endy ) + ( width / 2);
626  hole = radius - width;
627 
628  if( !vlayer->AddCircle( startx, starty, radius, false ) )
629  throw( std::runtime_error( vlayer->GetError() ) );
630 
631  if( hole > 0.0001 )
632  {
633  if( !vlayer->AddCircle( startx, starty, hole, true ) )
634  throw( std::runtime_error( vlayer->GetError() ) );
635  }
636 }
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 802 of file export_vrml.cpp.

803 {
804  // draw graphic items
805  for( auto drawing : pcb->Drawings() )
806  {
807  PCB_LAYER_ID layer = drawing->GetLayer();
808 
809  if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
810  continue;
811 
812  switch( drawing->Type() )
813  {
814  case PCB_LINE_T:
815  export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing );
816  break;
817 
818  case PCB_TEXT_T:
819  export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing );
820  break;
821 
822  default:
823  break;
824  }
825  }
826 }
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:252

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

698 {
699  LAYER_NUM layer = drawseg->GetLayer();
700  double w = drawseg->GetWidth() * BOARD_SCALE;
701  double x = drawseg->GetStart().x * BOARD_SCALE;
702  double y = drawseg->GetStart().y * BOARD_SCALE;
703  double xf = drawseg->GetEnd().x * BOARD_SCALE;
704  double yf = drawseg->GetEnd().y * BOARD_SCALE;
705  double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) );
706 
707  // Items on the edge layer are handled elsewhere; just return
708  if( layer == Edge_Cuts )
709  return;
710 
711  switch( drawseg->GetShape() )
712  {
713  case S_ARC:
714  export_vrml_arc( aModel, layer,
715  (double) drawseg->GetCenter().x * BOARD_SCALE,
716  (double) drawseg->GetCenter().y * BOARD_SCALE,
717  (double) drawseg->GetArcStart().x * BOARD_SCALE,
718  (double) drawseg->GetArcStart().y * BOARD_SCALE,
719  w, drawseg->GetAngle() / 10 );
720  break;
721 
722  case S_CIRCLE:
723  // Break circles into two 180 arcs to prevent the vrml hole from obscuring objects
724  // within the hole area of the circle.
725  export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 );
726  export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 );
727  break;
728 
729  case S_POLYGON:
730  export_vrml_polygon( aModel, layer, drawseg, 0.0, wxPoint( 0, 0 ) );
731  break;
732 
733  case S_SEGMENT:
734  export_vrml_line( aModel, layer, x, y, xf, yf, w );
735  break;
736 
737  case S_RECT:
738  export_vrml_line( aModel, layer, x, y, xf, y, w );
739  export_vrml_line( aModel, layer, xf, y, xf, yf, w );
740  export_vrml_line( aModel, layer, xf, yf, x, yf, w );
741  export_vrml_line( aModel, layer, x, yf, x, y, w );
742  break;
743 
744  default:
745  break;
746  }
747 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
wxPoint GetArcStart() const
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.
segment with non rounded ends
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)
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.
wxPoint GetCenter() const override
Function GetCenter()

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, S_RECT, S_SEGMENT, 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 1067 of file export_vrml.cpp.

1069 {
1070  LAYER_NUM layer = aOutline->GetLayer();
1071  double x = aOutline->GetStart().x * BOARD_SCALE;
1072  double y = aOutline->GetStart().y * BOARD_SCALE;
1073  double xf = aOutline->GetEnd().x * BOARD_SCALE;
1074  double yf = aOutline->GetEnd().y * BOARD_SCALE;
1075  double w = aOutline->GetWidth() * BOARD_SCALE;
1076 
1077  switch( aOutline->GetShape() )
1078  {
1079  case S_SEGMENT:
1080  export_vrml_line( aModel, layer, x, y, xf, yf, w );
1081  break;
1082 
1083  case S_ARC:
1084  export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
1085  break;
1086 
1087  case S_CIRCLE:
1088  export_vrml_circle( aModel, layer, x, y, xf, yf, w );
1089  break;
1090 
1091  case S_POLYGON:
1092  export_vrml_polygon( aModel, layer, aOutline, aModule->GetOrientationRadians(),
1093  aModule->GetPosition() );
1094  break;
1095 
1096  case S_RECT:
1097  export_vrml_line( aModel, layer, x, y, xf, y, w );
1098  export_vrml_line( aModel, layer, xf, y, xf, yf, w );
1099  export_vrml_line( aModel, layer, xf, yf, x, yf, w );
1100  export_vrml_line( aModel, layer, x, yf, x, y, w );
1101  break;
1102 
1103  default:
1104  break;
1105  }
1106 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
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)
segment with non rounded ends
Arcs (with rounded ends)
double GetOrientationRadians() const
Definition: class_module.h:219
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.
wxPoint GetPosition() const override
Definition: class_module.h:212
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, 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_RECT, 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 583 of file export_vrml.cpp.

586 {
587  VRML_LAYER* vlayer;
588 
589  if( !GetLayer( aModel, layer, &vlayer ) )
590  return;
591 
592  if( width < aModel.m_minLineWidth)
593  width = aModel.m_minLineWidth;
594 
595  starty = -starty;
596  endy = -endy;
597 
598  double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI;
599  double length = Distance( startx, starty, endx, endy ) + width;
600  double cx = ( startx + endx ) / 2.0;
601  double cy = ( starty + endy ) / 2.0;
602 
603  if( !vlayer->AddSlot( cx, cy, length, width, angle, false ) )
604  throw( std::runtime_error( vlayer->GetError() ) );
605 }
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 1360 of file export_vrml.cpp.

1362 {
1363  if( !aModel.m_plainPCB )
1364  {
1365  // Reference and value
1366  if( aModule->Reference().IsVisible() )
1367  export_vrml_text_module( &aModule->Reference() );
1368 
1369  if( aModule->Value().IsVisible() )
1370  export_vrml_text_module( &aModule->Value() );
1371 
1372  // Export module edges
1373 
1374  for( BOARD_ITEM* item : aModule->GraphicalItems() )
1375  {
1376  switch( item->Type() )
1377  {
1378  case PCB_MODULE_TEXT_T:
1379  export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
1380  break;
1381 
1382  case PCB_MODULE_EDGE_T:
1383  export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ), aModule );
1384  break;
1385 
1386  default:
1387  break;
1388  }
1389  }
1390  }
1391 
1392  // Export pads
1393  for( D_PAD* pad : aModule->Pads() )
1394  export_vrml_pad( aModel, aPcb, pad );
1395 
1396  bool isFlipped = aModule->GetLayer() == B_Cu;
1397 
1398  // Export the object VRML model(s)
1399  auto sM = aModule->Models().begin();
1400  auto eM = aModule->Models().end();
1401 
1402  wxFileName subdir( SUBDIR_3D, "" );
1403 
1404  while( sM != eM )
1405  {
1406  SGNODE* mod3d = (SGNODE*) cache->Load( sM->m_Filename );
1407 
1408  if( NULL == mod3d )
1409  {
1410  ++sM;
1411  continue;
1412  }
1413 
1414  /* Calculate 3D shape rotation:
1415  * this is the rotation parameters, with an additional 180 deg rotation
1416  * for footprints that are flipped
1417  * When flipped, axis rotation is the horizontal axis (X axis)
1418  */
1419  double rotx = -sM->m_Rotation.x;
1420  double roty = -sM->m_Rotation.y;
1421  double rotz = -sM->m_Rotation.z;
1422 
1423  if( isFlipped )
1424  {
1425  rotx += 180.0;
1426  roty = -roty;
1427  rotz = -rotz;
1428  }
1429 
1430  // Do some quaternion munching
1431  double q1[4], q2[4], rot[4];
1432  build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
1433  build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
1434  compose_quat( q1, q2, q1 );
1435  build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
1436  compose_quat( q1, q2, q1 );
1437 
1438  // Note here aModule->GetOrientation() is in 0.1 degrees,
1439  // so module rotation has to be converted to radians
1440  build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
1441  compose_quat( q1, q2, q1 );
1442  from_quat( q1, rot );
1443 
1444  double offsetFactor = 1000.0f * IU_PER_MILS / 25.4f;
1445 
1446  // adjust 3D shape local offset position
1447  // they are given in mm, so they are converted in board IU.
1448  double offsetx = sM->m_Offset.x * offsetFactor;
1449  double offsety = sM->m_Offset.y * offsetFactor;
1450  double offsetz = sM->m_Offset.z * offsetFactor;
1451 
1452  if( isFlipped )
1453  offsetz = -offsetz;
1454  else // In normal mode, Y axis is reversed in Pcbnew.
1455  offsety = -offsety;
1456 
1457  RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
1458 
1459  SGPOINT trans;
1460  trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.m_tx;
1461  trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.m_ty;
1462  trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() );
1463 
1464  if( USE_INLINES )
1465  {
1466  wxFileName srcFile = cache->GetResolver()->ResolvePath( sM->m_Filename );
1467  wxFileName dstFile;
1468  dstFile.SetPath( SUBDIR_3D );
1469  dstFile.SetName( srcFile.GetName() );
1470  dstFile.SetExt( "wrl" );
1471 
1472  // copy the file if necessary
1473  wxDateTime srcModTime = srcFile.GetModificationTime();
1474  wxDateTime destModTime = srcModTime;
1475 
1476  destModTime.SetToCurrent();
1477 
1478  if( dstFile.FileExists() )
1479  destModTime = dstFile.GetModificationTime();
1480 
1481  if( srcModTime != destModTime )
1482  {
1483  wxString fileExt = srcFile.GetExt();
1484  fileExt.LowerCase();
1485 
1486  // copy VRML models and use the scenegraph library to
1487  // translate other model types
1488  if( fileExt == "wrl" )
1489  {
1490  if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
1491  continue;
1492  }
1493  else
1494  {
1495  if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
1496  continue;
1497  }
1498  }
1499 
1500  (*aOutputFile) << "Transform {\n";
1501 
1502  // only write a rotation if it is >= 0.1 deg
1503  if( std::abs( rot[3] ) > 0.0001745 )
1504  {
1505  (*aOutputFile) << " rotation " << std::setprecision( 5 );
1506  (*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
1507  }
1508 
1509  (*aOutputFile) << " translation " << std::setprecision( PRECISION );
1510  (*aOutputFile) << trans.x << " ";
1511  (*aOutputFile) << trans.y << " ";
1512  (*aOutputFile) << trans.z << "\n";
1513 
1514  (*aOutputFile) << " scale ";
1515  (*aOutputFile) << sM->m_Scale.x << " ";
1516  (*aOutputFile) << sM->m_Scale.y << " ";
1517  (*aOutputFile) << sM->m_Scale.z << "\n";
1518 
1519  (*aOutputFile) << " children [\n Inline {\n url \"";
1520 
1521  if( USE_RELPATH )
1522  {
1523  wxFileName tmp = dstFile;
1524  tmp.SetExt( "" );
1525  tmp.SetName( "" );
1526  tmp.RemoveLastDir();
1527  dstFile.MakeRelativeTo( tmp.GetPath() );
1528  }
1529 
1530  wxString fn = dstFile.GetFullPath();
1531  fn.Replace( "\\", "/" );
1532  (*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
1533  (*aOutputFile) << " }\n";
1534  }
1535  else
1536  {
1537  IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( aModel.m_OutputPCB.GetRawPtr() );
1538 
1539  // only write a rotation if it is >= 0.1 deg
1540  if( std::abs( rot[3] ) > 0.0001745 )
1541  modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
1542 
1543  modelShape->SetTranslation( trans );
1544  modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
1545 
1546  if( NULL == S3D::GetSGNodeParent( mod3d ) )
1547  {
1548  aModel.m_components.push_back( mod3d );
1549  modelShape->AddChildNode( mod3d );
1550  }
1551  else
1552  {
1553  modelShape->AddRefNode( mod3d );
1554  }
1555 
1556  }
1557 
1558  ++sM;
1559  }
1560 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
static void export_vrml_pad(MODEL_VRML &aModel, BOARD *aPcb, D_PAD *aPad)
double GetOrientation() const
Definition: class_module.h:217
TEXTE_MODULE & Reference()
Definition: class_module.h:485
static S3D_CACHE * cache
Definition: export_vrml.cpp:61
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:62
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
static void export_vrml_text_module(TEXTE_MODULE *item)
bool IsVisible() const
Definition: eda_text.h:186
PADS & Pads()
Definition: class_module.h:174
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:184
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
IFSG_TRANSFORM m_OutputPCB
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
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:100
#define NULL
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:484
static bool USE_RELPATH
Definition: export_vrml.cpp:64
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
static wxString SUBDIR_3D
Definition: export_vrml.cpp:68
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:207
double DEG2RAD(double deg)
Definition: trigo.h:219
FILENAME_RESOLVER * GetResolver() noexcept
Definition: 3d_cache.cpp:627
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
double DECIDEG2RAD(double deg)
Definition: trigo.h:223
static void from_quat(double q[4], double rot[4])
#define IU_PER_MILS
Definition: plotter.cpp:138
bool SetTranslation(const SGPOINT &aTranslation) noexcept
bool SetScale(const SGPOINT &aScale) noexcept
static const int PRECISION
Definition: export_vrml.cpp:67
static bool USE_DEFS
Definition: export_vrml.cpp:63
static void export_vrml_edge_module(MODEL_VRML &aModel, EDGE_MODULE *aOutline, MODULE *aModule)
wxPoint GetPosition() const override
Definition: class_module.h:212
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:285
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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(), 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 1242 of file export_vrml.cpp.

1243 {
1244  double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0;
1245  double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0;
1246  double hole_drill = std::min( hole_drill_w, hole_drill_h );
1247  double hole_x = aPad->GetPosition().x * BOARD_SCALE;
1248  double hole_y = aPad->GetPosition().y * BOARD_SCALE;
1249 
1250  // Export the hole on the edge layer
1251  if( hole_drill > 0 )
1252  {
1253  bool pth = false;
1254 
1255  if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
1256  && !aModel.m_plainPCB )
1257  pth = true;
1258 
1259  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1260  {
1261  // Oblong hole (slot)
1262 
1263  if( pth )
1264  {
1265  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
1266  hole_drill_h * 2.0 + PLATE_OFFSET,
1267  aPad->GetOrientation()/10.0, true, true );
1268 
1269  aModel.m_plated_holes.AddSlot( hole_x, -hole_y,
1270  hole_drill_w * 2.0, hole_drill_h * 2.0,
1271  aPad->GetOrientation()/10.0, true, false );
1272  }
1273  else
1274  {
1275  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
1276  aPad->GetOrientation()/10.0, true, false );
1277 
1278  }
1279  }
1280  else
1281  {
1282  // Drill a round hole
1283 
1284  if( pth )
1285  {
1286  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
1287  aModel.m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1288  }
1289  else
1290  {
1291  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1292  }
1293 
1294  }
1295  }
1296 
1297  if( aModel.m_plainPCB )
1298  return;
1299 
1300  // The pad proper, on the selected layers
1301  LSET layer_mask = aPad->GetLayerSet();
1302 
1303  if( layer_mask[B_Cu] )
1304  {
1305  if( layer_mask[B_Mask] )
1306  export_vrml_padshape( aModel, &aModel.m_bot_tin, aPad );
1307  else
1308  export_vrml_padshape( aModel, &aModel.m_bot_copper, aPad );
1309  }
1310  if( layer_mask[F_Cu] )
1311  {
1312  if( layer_mask[F_Mask] )
1313  export_vrml_padshape( aModel, &aModel.m_top_tin, aPad );
1314  else
1315  export_vrml_padshape( aModel, &aModel.m_top_copper, aPad );
1316  }
1317 
1318 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
wxPoint GetPosition() const override
Definition: class_pad.h:165
VRML_LAYER m_bot_tin
VRML_LAYER m_plated_holes
VRML_LAYER m_holes
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:334
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:326
LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_pad.h:331
VRML_LAYER m_bot_copper
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in a variety of units (the basic call r...
Definition: class_pad.h:321
const wxSize & GetDrillSize() const
Definition: class_pad.h:230
#define PLATE_OFFSET
Definition: export_vrml.cpp:59
VRML_LAYER m_top_copper
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 1109 of file export_vrml.cpp.

1110 {
1111  // The (maybe offset) pad position
1112  wxPoint pad_pos = aPad->ShapePos();
1113  double pad_x = pad_pos.x * BOARD_SCALE;
1114  double pad_y = pad_pos.y * BOARD_SCALE;
1115  wxSize pad_delta = aPad->GetDelta();
1116 
1117  double pad_dx = pad_delta.x * BOARD_SCALE / 2.0;
1118  double pad_dy = pad_delta.y * BOARD_SCALE / 2.0;
1119 
1120  double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0;
1121  double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0;
1122 
1123  switch( aPad->GetShape() )
1124  {
1125  case PAD_SHAPE_CIRCLE:
1126 
1127  if( !aTinLayer->AddCircle( pad_x, -pad_y, pad_w, false ) )
1128  throw( std::runtime_error( aTinLayer->GetError() ) );
1129 
1130  break;
1131 
1132  case PAD_SHAPE_OVAL:
1133 
1134  if( !aTinLayer->AddSlot( pad_x, -pad_y, pad_w * 2.0, pad_h * 2.0,
1135  aPad->GetOrientation()/10.0, false ) )
1136  throw( std::runtime_error( aTinLayer->GetError() ) );
1137 
1138  break;
1139 
1140  case PAD_SHAPE_ROUNDRECT:
1142  {
1143  SHAPE_POLY_SET polySet;
1144  const int corner_radius = aPad->GetRoundRectCornerRadius();
1145  TransformRoundChamferedRectToPolygon( polySet, wxPoint( 0, 0 ), aPad->GetSize(),
1146  0.0, corner_radius, 0.0, 0, ARC_HIGH_DEF );
1147  std::vector< wxRealPoint > cornerList;
1148  // TransformRoundChamferedRectToPolygon creates only one convex polygon
1149  SHAPE_LINE_CHAIN poly( polySet.Outline( 0 ) );
1150 
1151  cornerList.reserve( poly.PointCount() );
1152  for( int ii = 0; ii < poly.PointCount(); ++ii )
1153  cornerList.emplace_back(
1154  poly.CPoint( ii ).x * BOARD_SCALE, -poly.CPoint( ii ).y * BOARD_SCALE );
1155 
1156  // Close polygon
1157  cornerList.push_back( cornerList[0] );
1158  if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
1159  throw( std::runtime_error( aTinLayer->GetError() ) );
1160 
1161  break;
1162  }
1163 
1164  case PAD_SHAPE_CUSTOM:
1165  {
1166  SHAPE_POLY_SET polySet;
1167  std::vector< wxRealPoint > cornerList;
1168  aPad->MergePrimitivesAsPolygon( &polySet, UNDEFINED_LAYER );
1169 
1170  for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
1171  {
1172  SHAPE_LINE_CHAIN& poly = polySet.Outline( cnt );
1173  cornerList.clear();
1174 
1175  for( int ii = 0; ii < poly.PointCount(); ++ii )
1176  cornerList.emplace_back(
1177  poly.CPoint( ii ).x * BOARD_SCALE, -poly.CPoint( ii ).y * BOARD_SCALE );
1178 
1179  // Close polygon
1180  cornerList.push_back( cornerList[0] );
1181 
1182  if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
1183  throw( std::runtime_error( aTinLayer->GetError() ) );
1184  }
1185 
1186  break;
1187  }
1188 
1189  case PAD_SHAPE_RECT:
1190  // Just to be sure :D
1191  pad_dx = 0;
1192  pad_dy = 0;
1193 
1194  // Intentionally fall through and treat a rectangle as a trapezoid with no sloped sides
1196 
1197  case PAD_SHAPE_TRAPEZOID:
1198  {
1199  double coord[8] =
1200  {
1201  -pad_w + pad_dy, -pad_h - pad_dx,
1202  -pad_w - pad_dy, pad_h + pad_dx,
1203  +pad_w - pad_dy, -pad_h + pad_dx,
1204  +pad_w + pad_dy, pad_h - pad_dx
1205  };
1206 
1207  for( int i = 0; i < 4; i++ )
1208  {
1209  RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
1210  coord[i * 2] += pad_x;
1211  coord[i * 2 + 1] += pad_y;
1212  }
1213 
1214  int lines;
1215 
1216  lines = aTinLayer->NewContour();
1217 
1218  if( lines < 0 )
1219  throw( std::runtime_error( aTinLayer->GetError() ) );
1220 
1221  if( !aTinLayer->AddVertex( lines, coord[0], -coord[1] ) )
1222  throw( std::runtime_error( aTinLayer->GetError() ) );
1223 
1224  if( !aTinLayer->AddVertex( lines, coord[4], -coord[5] ) )
1225  throw( std::runtime_error( aTinLayer->GetError() ) );
1226 
1227  if( !aTinLayer->AddVertex( lines, coord[6], -coord[7] ) )
1228  throw( std::runtime_error( aTinLayer->GetError() ) );
1229 
1230  if( !aTinLayer->AddVertex( lines, coord[2], -coord[3] ) )
1231  throw( std::runtime_error( aTinLayer->GetError() ) );
1232 
1233  if( !aTinLayer->EnsureWinding( lines, false ) )
1234  throw( std::runtime_error( aTinLayer->GetError() ) );
1235 
1236  break;
1237  }
1238  }
1239 }
void MergePrimitivesAsPolygon(SHAPE_POLY_SET *aMergedPolygon, PCB_LAYER_ID aLayer) const
Merge all basic shapes to a SHAPE_POLY_SET Note: The results are relative to the pad position,...
static double BOARD_SCALE
Definition: export_vrml.cpp:66
int OutlineCount() const
Returns the number of outlines in the set
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:88
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()
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:227
SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in a variety of units (the basic call r...
Definition: class_pad.h:321
wxPoint ShapePos() const
Definition: class_pad.cpp:595
int GetRoundRectCornerRadius() const
Definition: class_pad.cpp:224
PAD_SHAPE_T GetShape() const
Definition: class_pad.h:157
const wxSize & GetSize() const
Definition: class_pad.h:224
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aError)
convert a rectangle with rounded corners and/or chamfered corners to a polygon Convert rounded corner...

References BOARD_SCALE, SHAPE_LINE_CHAIN::CPoint(), D_PAD::GetDelta(), D_PAD::GetOrientation(), D_PAD::GetRoundRectCornerRadius(), D_PAD::GetShape(), D_PAD::GetSize(), KI_FALLTHROUGH, 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(), UNDEFINED_LAYER, 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 764 of file export_vrml.cpp.

765 {
766  wxSize size = text->GetTextSize();
767 
768  if( text->IsMirrored() )
769  size.x = -size.x;
770 
771  bool forceBold = true;
772  int penWidth = text->GetEffectiveTextPenWidth();
773  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
774 
775  model_vrml->m_text_layer = text->GetLayer();
776  model_vrml->m_text_width = penWidth;
777 
778  if( text->IsMultilineAllowed() )
779  {
780  wxArrayString strings_list;
781  wxStringSplit( text->GetShownText(), strings_list, '\n' );
782  std::vector<wxPoint> positions;
783  positions.reserve( strings_list.Count() );
784  text->GetLinePositions( positions, strings_list.Count() );
785 
786  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
787  {
788  GRText( nullptr, positions[ii], color, strings_list[ii], text->GetTextAngle(), size,
789  text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
790  forceBold, vrml_text_callback );
791  }
792  }
793  else
794  {
795  GRText( nullptr, text->GetTextPos(), color, text->GetShownText(), text->GetTextAngle(),
796  size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
797  forceBold, vrml_text_callback );
798  }
799 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:343
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:200
bool IsMirrored() const
Definition: eda_text.h:189
int color
Definition: DXF_plotter.cpp:61
double GetTextAngle() const
Definition: eda_text.h:174
static MODEL_VRML * model_vrml
Definition: color4d.h:44
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
bool IsItalic() const
Definition: eda_text.h:180
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
const wxSize & GetTextSize() const
Definition: eda_text.h:239
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
bool IsMultilineAllowed() const
Definition: eda_text.h:197
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:134
void GetLinePositions(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:423
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
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:99

References BLACK, color, EDA_TEXT::GetEffectiveTextPenWidth(), EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), EDA_TEXT::GetLinePositions(), TEXTE_PCB::GetShownText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), 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, 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 661 of file export_vrml.cpp.

663 {
664  if( aOutline->IsPolyShapeValid() )
665  {
666  SHAPE_POLY_SET shape = aOutline->GetPolyShape();
667  VRML_LAYER* vlayer;
668 
669  if( !GetLayer( aModel, layer, &vlayer ) )
670  return;
671 
672  if( aOutline->GetWidth() )
673  {
674  int numSegs = GetArcToSegmentCount( aOutline->GetWidth() / 2, ARC_HIGH_DEF, 360.0 );
675  shape.Inflate( aOutline->GetWidth() / 2, numSegs );
677  }
678 
679  shape.Rotate( -aOrientation, VECTOR2I( 0, 0 ) );
680  shape.Move( aPos );
681  const SHAPE_LINE_CHAIN& outline = shape.COutline( 0 );
682 
683  int seg = vlayer->NewContour();
684 
685  for( int j = 0; j < outline.PointCount(); j++ )
686  {
687  if( !vlayer->AddVertex( seg, outline.CPoint( j ).x * BOARD_SCALE,
688  -outline.CPoint( j ).y * BOARD_SCALE ) )
689  throw( std::runtime_error( vlayer->GetError() ) );
690  }
691 
692  vlayer->EnsureWinding( seg, false );
693  }
694 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Function Rotate rotates all vertices by a given angle.
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 1045 of file export_vrml.cpp.

1046 {
1047  if( item->IsVisible() )
1048  {
1049  wxSize size = item->GetTextSize();
1050 
1051  if( item->IsMirrored() )
1052  size.x = -size.x; // Text is mirrored
1053 
1054  bool forceBold = true;
1055  int penWidth = item->GetEffectiveTextPenWidth();
1056 
1057  model_vrml->m_text_layer = item->GetLayer();
1058  model_vrml->m_text_width = penWidth;
1059 
1060  GRText( NULL, item->GetTextPos(), BLACK, item->GetShownText(), item->GetDrawRotation(),
1061  size, item->GetHorizJustify(), item->GetVertJustify(), penWidth, item->IsItalic(),
1062  forceBold, vrml_text_callback );
1063  }
1064 }
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:200
bool IsMirrored() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: eda_text.h:186
static MODEL_VRML * model_vrml
Definition: color4d.h:44
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
bool IsItalic() const
Definition: eda_text.h:180
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
#define NULL
const wxSize & GetTextSize() const
Definition: eda_text.h:239
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:134
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
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::GetEffectiveTextPenWidth(), EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), TEXTE_MODULE::GetShownText(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), 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 953 of file export_vrml.cpp.

954 {
955  for( TRACK* track : pcb->Tracks() )
956  {
957  if( track->Type() == PCB_VIA_T )
958  {
959  export_vrml_via( aModel, pcb, (const VIA*) track );
960  }
961  else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
962  && !aModel.m_plainPCB )
963  {
964  if( track->Type() == PCB_ARC_T )
965  {
966  ARC* arc = static_cast<ARC*>( track );
967  VECTOR2D center( arc->GetCenter() );
968  double arc_angle_degree = arc->GetAngle()/10;
969 
970  // Vrml exporter does not export arcs with angle < 1.0 degree
971  // ( to avoid issues with vrml viewers).
972  // The best way is to convert them to a small straight line
973  if( arc_angle_degree < -1.0 || arc_angle_degree > 1.0 )
974  {
975  export_vrml_arc( aModel, track->GetLayer(),
976  center.x * BOARD_SCALE, center.y * BOARD_SCALE,
977  arc->GetStart().x * BOARD_SCALE,
978  arc->GetStart().y * BOARD_SCALE,
979  arc->GetWidth() * BOARD_SCALE, arc_angle_degree );
980  }
981  else
982  {
983  export_vrml_line( aModel, arc->GetLayer(),
984  arc->GetStart().x * BOARD_SCALE,
985  arc->GetStart().y * BOARD_SCALE,
986  arc->GetEnd().x * BOARD_SCALE,
987  arc->GetEnd().y * BOARD_SCALE,
988  arc->GetWidth() * BOARD_SCALE );
989  }
990  }
991  else
992  {
993  export_vrml_line( aModel, track->GetLayer(),
994  track->GetStart().x * BOARD_SCALE,
995  track->GetStart().y * BOARD_SCALE,
996  track->GetEnd().x * BOARD_SCALE,
997  track->GetEnd().y * BOARD_SCALE,
998  track->GetWidth() * BOARD_SCALE );
999  }
1000  }
1001  }
1002 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
const wxPoint & GetStart() const
Definition: class_track.h:116
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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)
virtual wxPoint GetCenter() const
Function GetCenter()
double GetAngle() const
int GetWidth() const
Definition: class_track.h:110
const wxPoint & GetEnd() const
Definition: class_track.h:113
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)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
TRACKS & Tracks()
Definition: class_board.h:246

References B_Cu, BOARD_SCALE, export_vrml_arc(), export_vrml_line(), export_vrml_via(), F_Cu, ARC::GetAngle(), BOARD_ITEM::GetCenter(), TRACK::GetEnd(), BOARD_ITEM::GetLayer(), TRACK::GetStart(), TRACK::GetWidth(), MODEL_VRML::m_plainPCB, PCB_ARC_T, PCB_VIA_T, BOARD::Tracks(), wxPoint::x, and wxPoint::y.

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

934 {
935  double x, y, r, hole;
936  PCB_LAYER_ID top_layer, bottom_layer;
937 
938  hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0;
939  r = aVia->GetWidth() * BOARD_SCALE / 2.0;
940  x = aVia->GetStart().x * BOARD_SCALE;
941  y = aVia->GetStart().y * BOARD_SCALE;
942  aVia->LayerPair( &top_layer, &bottom_layer );
943 
944  // do not render a buried via
945  if( top_layer != F_Cu && bottom_layer != B_Cu )
946  return;
947 
948  // Export the via padstack
949  export_round_padstack( aModel, aPcb, x, y, r, bottom_layer, top_layer, hole );
950 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
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:116
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:110

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,
COMMIT aCommit 
)
static

Definition at line 1005 of file export_vrml.cpp.

1006 {
1007  for( ZONE_CONTAINER* zone : aPcb->Zones() )
1008  {
1009  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1010  {
1011  VRML_LAYER* vl;
1012 
1013  if( !GetLayer( aModel, layer, &vl ) )
1014  continue;
1015 
1016  if( !zone->IsFilled() )
1017  {
1018  ZONE_FILLER filler( aPcb, aCommit );
1019  zone->SetFillMode( ZONE_FILL_MODE::POLYGONS ); // use filled polygons
1020  filler.Fill( { zone } );
1021  }
1022 
1023  const SHAPE_POLY_SET& poly = zone->GetFilledPolysList( layer );
1024 
1025  for( int i = 0; i < poly.OutlineCount(); i++ )
1026  {
1027  const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
1028 
1029  int seg = vl->NewContour();
1030 
1031  for( int j = 0; j < outline.PointCount(); j++ )
1032  {
1033  if( !vl->AddVertex( seg, (double) outline.CPoint( j ).x * BOARD_SCALE,
1034  -( (double) outline.CPoint( j ).y * BOARD_SCALE ) ) )
1035  throw( std::runtime_error( vl->GetError() ) );
1036  }
1037 
1038  vl->EnsureWinding( seg, false );
1039  }
1040  }
1041  }
1042 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
int OutlineCount() const
Returns the number of outlines in the set
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
PCB_LAYER_ID
A quick note on layer IDs:
SHAPE_POLY_SET.
ZONE_CONTAINERS & Zones()
Definition: class_board.h:254
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)

References BOARD_SCALE, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), ZONE_FILLER::Fill(), GetLayer(), SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), POLYGONS, VECTOR2< T >::x, VECTOR2< T >::y, and BOARD::Zones().

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ from_quat()

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

Definition at line 1334 of file export_vrml.cpp.

1335 {
1336  rot[3] = acos( q[3] ) * 2;
1337 
1338  for( int i = 0; i < 3; i++ )
1339  rot[i] = q[i] / sin( rot[3] / 2 );
1340 }

Referenced by export_vrml_module().

◆ GetLayer()

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

◆ getSGColor()

static SGNODE* getSGColor ( VRML_COLOR_INDEX  colorIdx)
static

Definition at line 1689 of file export_vrml.cpp.

1690 {
1691  if( colorIdx == -1 )
1692  colorIdx = VRML_COLOR_PCB;
1693  else if( colorIdx == VRML_COLOR_LAST )
1694  return NULL;
1695 
1696  if( sgmaterial[colorIdx] )
1697  return sgmaterial[colorIdx];
1698 
1699  IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
1700  VRML_COLOR* cp = &colors[colorIdx];
1701 
1702  vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
1703  vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
1704  vcolor.SetShininess( cp->shiny );
1705  // NOTE: XXX - replace with a better equation; using this definition
1706  // of ambient will not yield the best results
1707  vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
1708  vcolor.SetTransparency( cp->transp );
1709 
1710  sgmaterial[colorIdx] = vcolor.GetRawPtr();
1711 
1712  return sgmaterial[colorIdx];
1713 }
float transp
Definition: export_vrml.cpp:86
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:79
float ambient
Definition: export_vrml.cpp:85
float diffuse_grn
Definition: export_vrml.cpp:74
#define NULL
float spec_red
Definition: export_vrml.cpp:77
float spec_grn
Definition: export_vrml.cpp:78
float diffuse_red
Definition: export_vrml.cpp:73
float diffuse_blu
Definition: export_vrml.cpp:75
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 752 of file export_vrml.cpp.

753 {
754  LAYER_NUM m_text_layer = model_vrml->m_text_layer;
755  int m_text_width = model_vrml->m_text_width;
756 
757  export_vrml_line( *model_vrml, m_text_layer,
758  x0 * BOARD_SCALE, y0 * BOARD_SCALE,
759  xf * BOARD_SCALE, yf * BOARD_SCALE,
760  m_text_width * BOARD_SCALE );
761 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
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 404 of file export_vrml.cpp.

406 {
407  // VRML_LAYER board;
408  aModel.m_board.Tesselate( &aModel.m_holes );
409  double brdz = aModel.m_brd_thickness / 2.0
410  - ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE;
411 
412  if( USE_INLINES )
413  {
414  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ),
415  &aModel.m_board, false, false, brdz, -brdz );
416  }
417  else
418  {
419  create_vrml_shell( aModel.m_OutputPCB, VRML_COLOR_PCB, &aModel.m_board, brdz, -brdz );
420  }
421 
422  if( aModel.m_plainPCB )
423  {
424  if( !USE_INLINES )
425  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), USE_DEFS, true );
426 
427  return;
428  }
429 
430  // VRML_LAYER m_top_copper;
431  aModel.m_top_copper.Tesselate( &aModel.m_holes );
432 
433  if( USE_INLINES )
434  {
435  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
436  &aModel.m_top_copper, true, true,
437  aModel.GetLayerZ( F_Cu ), 0 );
438  }
439  else
440  {
442  aModel.GetLayerZ( F_Cu ), true );
443  }
444 
445  // VRML_LAYER m_top_tin;
446  aModel.m_top_tin.Tesselate( &aModel.m_holes );
447 
448  if( USE_INLINES )
449  {
450  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
451  &aModel.m_top_tin, true, true,
452  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
453  0 );
454  }
455  else
456  {
458  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
459  true );
460  }
461 
462  // VRML_LAYER m_bot_copper;
463  aModel.m_bot_copper.Tesselate( &aModel.m_holes );
464 
465  if( USE_INLINES )
466  {
467  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
468  &aModel.m_bot_copper, true, false,
469  aModel.GetLayerZ( B_Cu ), 0 );
470  }
471  else
472  {
474  aModel.GetLayerZ( B_Cu ), false );
475  }
476 
477  // VRML_LAYER m_bot_tin;
478  aModel.m_bot_tin.Tesselate( &aModel.m_holes );
479 
480  if( USE_INLINES )
481  {
482  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
483  &aModel.m_bot_tin, true, false,
484  aModel.GetLayerZ( B_Cu )
485  - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
486  0 );
487  }
488  else
489  {
491  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
492  false );
493  }
494 
495  // VRML_LAYER PTH;
496  aModel.m_plated_holes.Tesselate( NULL, true );
497 
498  if( USE_INLINES )
499  {
500  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
501  &aModel.m_plated_holes, false, false,
502  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
503  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
504  }
505  else
506  {
508  aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
509  aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
510  }
511 
512  // VRML_LAYER m_top_silk;
513  aModel.m_top_silk.Tesselate( &aModel.m_holes );
514 
515  if( USE_INLINES )
516  {
517  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk,
518  true, true, aModel.GetLayerZ( F_SilkS ), 0 );
519  }
520  else
521  {
523  aModel.GetLayerZ( F_SilkS ), true );
524  }
525 
526  // VRML_LAYER m_bot_silk;
527  aModel.m_bot_silk.Tesselate( &aModel.m_holes );
528 
529  if( USE_INLINES )
530  {
531  write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk,
532  true, false, aModel.GetLayerZ( B_SilkS ), 0 );
533  }
534  else
535  {
537  aModel.GetLayerZ( B_SilkS ), false );
538  }
539 
540  if( !USE_INLINES )
541  S3D::WriteVRML( aFileName, true, aModel.m_OutputPCB.GetRawPtr(), true, true );
542 }
static double BOARD_SCALE
Definition: export_vrml.cpp:66
static bool USE_INLINES
Definition: export_vrml.cpp:62
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
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
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:63
VRML_LAYER m_top_copper
VRML_LAYER m_top_tin
static constexpr int Millimeter2iu(double mm)
VRML_COLOR & GetColor(VRML_COLOR_INDEX aIndex)
double GetLayerZ(LAYER_NUM aLayer)
#define ART_OFFSET
Definition: export_vrml.cpp:57

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

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

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

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

◆ sgmaterial

SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }
static

Definition at line 139 of file export_vrml.cpp.

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

◆ SUBDIR_3D

wxString SUBDIR_3D
static

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

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