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 "drawtxt.h"
#include "macros.h"
#include "pgm_base.h"
#include "plugins/3dapi/ifsg_all.h"
#include "streamwrapper.h"
#include "vrml_layer.h"
#include "wxPcbStruct.h"
#include "../../kicad/kicad.h"

Go to the source code of this file.

Classes

struct  VRML_COLOR
 
class  MODEL_VRML
 

Macros

#define MIN_VRML_LINEWIDTH   0.12
 
#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_drawsegment (MODEL_VRML &aModel, DRAWSEGMENT *drawseg)
 
static void vrml_text_callback (int x0, int y0, int xf, int yf)
 
static void export_vrml_pcbtext (MODEL_VRML &aModel, TEXTE_PCB *text)
 
static void export_vrml_drawings (MODEL_VRML &aModel, BOARD *pcb)
 
static void export_vrml_board (MODEL_VRML &aModel, BOARD *aPcb)
 
static void export_round_padstack (MODEL_VRML &aModel, BOARD *pcb, double x, double y, double r, LAYER_NUM bottom_layer, LAYER_NUM top_layer, double hole)
 
static void export_vrml_via (MODEL_VRML &aModel, BOARD *aPcb, const VIA *aVia)
 
static void export_vrml_tracks (MODEL_VRML &aModel, BOARD *pcb)
 
static void export_vrml_zones (MODEL_VRML &aModel, BOARD *aPcb)
 
static void export_vrml_text_module (TEXTE_MODULE *module)
 
static void export_vrml_edge_module (MODEL_VRML &aModel, EDGE_MODULE *aOutline, double aOrientation)
 
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

#define ART_OFFSET   0.025

Definition at line 56 of file export_vrml.cpp.

Referenced by compute_layer_Zs(), and write_layers().

#define MIN_VRML_LINEWIDTH   0.12

Definition at line 53 of file export_vrml.cpp.

Referenced by MODEL_VRML::MODEL_VRML().

#define PLATE_OFFSET   0.005

Definition at line 58 of file export_vrml.cpp.

Referenced by export_vrml_pad().

Enumeration Type Documentation

Enumerator
VRML_COLOR_NONE 
VRML_COLOR_PCB 
VRML_COLOR_TRACK 
VRML_COLOR_SILK 
VRML_COLOR_TIN 
VRML_COLOR_LAST 

Definition at line 127 of file export_vrml.cpp.

Function Documentation

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

Definition at line 1228 of file export_vrml.cpp.

Referenced by export_vrml_module().

1229 {
1230  double sina = sin( a / 2 );
1231 
1232  q[0] = x * sina;
1233  q[1] = y * sina;
1234  q[2] = z * sina;
1235  q[3] = cos( a / 2 );
1236 }
static void compose_quat ( double  q1[4],
double  q2[4],
double  qr[4] 
)
static

Definition at line 1252 of file export_vrml.cpp.

Referenced by export_vrml_module().

1253 {
1254  double tmp[4];
1255 
1256  tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
1257  tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
1258  tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
1259  tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
1260 
1261  qr[0] = tmp[0];
1262  qr[1] = tmp[1];
1263  qr[2] = tmp[2];
1264  qr[3] = tmp[3];
1265 }
static void compute_layer_Zs ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 559 of file export_vrml.cpp.

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().

560 {
561  int copper_layers = pcb->GetCopperLayerCount();
562 
563  // We call it 'layer' thickness, but it's the whole board thickness!
565  double half_thickness = aModel.m_brd_thickness / 2;
566 
567  // Compute each layer's Z value, more or less like the 3d view
568  for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq )
569  {
570  LAYER_ID i = *seq;
571 
572  if( i < copper_layers )
573  aModel.SetLayerZ( i, half_thickness - aModel.m_brd_thickness * i / (copper_layers - 1) );
574  else
575  aModel.SetLayerZ( i, - half_thickness ); // bottom layer
576  }
577 
578  /* To avoid rounding interference, we apply an epsilon to each
579  * successive layer */
580  double epsilon_z = Millimeter2iu( ART_OFFSET ) * BOARD_SCALE;
581  aModel.SetLayerZ( B_Paste, -half_thickness - epsilon_z * 4 );
582  aModel.SetLayerZ( B_Adhes, -half_thickness - epsilon_z * 3 );
583  aModel.SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 2 );
584  aModel.SetLayerZ( B_Mask, -half_thickness - epsilon_z );
585  aModel.SetLayerZ( F_Mask, half_thickness + epsilon_z );
586  aModel.SetLayerZ( F_SilkS, half_thickness + epsilon_z * 2 );
587  aModel.SetLayerZ( F_Adhes, half_thickness + epsilon_z * 3 );
588  aModel.SetLayerZ( F_Paste, half_thickness + epsilon_z * 4 );
589  aModel.SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
590  aModel.SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
591  aModel.SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
592  aModel.SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
593  aModel.SetLayerZ( Edge_Cuts, 0 );
594 }
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 LAYER_IDs.
Definition: lset.cpp:638
static double BOARD_SCALE
Definition: export_vrml.cpp:65
int GetCopperLayerCount() const
Function GetCopperLayerCount.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
Class LSEQ is a sequence (and therefore also a set) of LAYER_IDs.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
double m_brd_thickness
#define ART_OFFSET
Definition: export_vrml.cpp:56
static void create_vrml_plane ( IFSG_TRANSFORM PcbOutput,
VRML_COLOR_INDEX  colorID,
VRML_LAYER *  layer,
double  aHeight,
bool  aTopPlane 
)
static

Definition at line 1624 of file export_vrml.cpp.

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

Referenced by write_layers().

1626 {
1627  std::vector< double > vertices;
1628  std::vector< int > idxPlane;
1629  std::vector< int > idxSide;
1630 
1631  if( !(*layer).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
1632  {
1633 #ifdef DEBUG
1634  do {
1635  std::ostringstream ostr;
1636  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1637  ostr << " * [INFO] no vertex data";
1638  wxLogDebug( "%s\n", ostr.str().c_str() );
1639  } while( 0 );
1640 #endif
1641 
1642  return;
1643  }
1644 
1645  if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
1646  {
1647 #ifdef DEBUG
1648  do {
1649  std::ostringstream ostr;
1650  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1651  ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
1652  wxLogDebug( "%s\n", ostr.str().c_str() );
1653  } while( 0 );
1654 #endif
1655 
1656  throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
1657  }
1658 
1659  std::vector< SGPOINT > vlist;
1660  size_t nvert = vertices.size() / 3;
1661  size_t j = 0;
1662 
1663  for( size_t i = 0; i < nvert; ++i, j+= 3 )
1664  vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
1665 
1666  // create the intermediate scenegraph
1667  IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
1668  IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
1669  IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
1670  IFSG_COORDS cp( face ); // coordinates for all faces
1671  cp.SetCoordsList( nvert, &vlist[0] );
1672  IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
1673  coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
1674  IFSG_NORMALS norms( face ); // normals for the top and bottom planes
1675 
1676  // set the normals
1677  if( aTopPlane )
1678  {
1679  for( size_t i = 0; i < nvert; ++i )
1680  norms.AddNormal( 0.0, 0.0, 1.0 );
1681  }
1682  else
1683  {
1684  for( size_t i = 0; i < nvert; ++i )
1685  norms.AddNormal( 0.0, 0.0, -1.0 );
1686  }
1687 
1688  // assign a color from the palette
1689  SGNODE* modelColor = getSGColor( colorID );
1690 
1691  if( NULL != modelColor )
1692  {
1693  if( NULL == S3D::GetSGNodeParent( modelColor ) )
1694  shape.AddChildNode( modelColor );
1695  else
1696  shape.AddRefNode( modelColor );
1697  }
1698 
1699  return;
1700 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
Class IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
Class IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:643
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
Class IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
static SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
Class IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH...
Class IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40
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 1703 of file export_vrml.cpp.

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

Referenced by write_layers().

1705 {
1706  std::vector< double > vertices;
1707  std::vector< int > idxPlane;
1708  std::vector< int > idxSide;
1709 
1710  if( top_z < bottom_z )
1711  {
1712  double tmp = top_z;
1713  top_z = bottom_z;
1714  bottom_z = tmp;
1715  }
1716 
1717  if( !(*layer).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z ) )
1718  {
1719 #ifdef DEBUG
1720  do {
1721  std::ostringstream ostr;
1722  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1723  ostr << " * [INFO] no vertex data";
1724  wxLogDebug( "%s\n", ostr.str().c_str() );
1725  } while( 0 );
1726 #endif
1727 
1728  return;
1729  }
1730 
1731  if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
1732  {
1733 #ifdef DEBUG
1734  do {
1735  std::ostringstream ostr;
1736  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
1737  ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
1738  wxLogDebug( "%s\n", ostr.str().c_str() );
1739  } while( 0 );
1740 #endif
1741 
1742  throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
1743  }
1744 
1745  std::vector< SGPOINT > vlist;
1746  size_t nvert = vertices.size() / 3;
1747  size_t j = 0;
1748 
1749  for( size_t i = 0; i < nvert; ++i, j+= 3 )
1750  vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
1751 
1752  // create the intermediate scenegraph
1753  IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
1754  IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
1755  IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
1756  IFSG_COORDS cp( face ); // coordinates for all faces
1757  cp.SetCoordsList( nvert, &vlist[0] );
1758  IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
1759  coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
1760  IFSG_NORMALS norms( face ); // normals for the top and bottom planes
1761 
1762  // number of TOP (and bottom) vertices
1763  j = nvert / 2;
1764 
1765  // set the TOP normals
1766  for( size_t i = 0; i < j; ++i )
1767  norms.AddNormal( 0.0, 0.0, 1.0 );
1768 
1769  // set the BOTTOM normals
1770  for( size_t i = 0; i < j; ++i )
1771  norms.AddNormal( 0.0, 0.0, -1.0 );
1772 
1773  // assign a color from the palette
1774  SGNODE* modelColor = getSGColor( colorID );
1775 
1776  if( NULL != modelColor )
1777  {
1778  if( NULL == S3D::GetSGNodeParent( modelColor ) )
1779  shape.AddChildNode( modelColor );
1780  else
1781  shape.AddRefNode( modelColor );
1782  }
1783 
1784  // create a second shape describing the vertical walls of the extrusion
1785  // using per-vertex-per-face-normals
1786  shape.NewNode( tx0 );
1787  shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom
1788  face.NewNode( shape );
1789  cp.NewNode( face ); // new vertex list
1790  norms.NewNode( face ); // new normals list
1791  coordIdx.NewNode( face ); // new index list
1792 
1793  // populate the new per-face vertex list and its indices and normals
1794  std::vector< int >::iterator sI = idxSide.begin();
1795  std::vector< int >::iterator eI = idxSide.end();
1796 
1797  size_t sidx = 0; // index to the new coord set
1798  SGPOINT p1, p2, p3;
1799  SGVECTOR vnorm;
1800 
1801  while( sI != eI )
1802  {
1803  p1 = vlist[*sI];
1804  cp.AddCoord( p1 );
1805  ++sI;
1806 
1807  p2 = vlist[*sI];
1808  cp.AddCoord( p2 );
1809  ++sI;
1810 
1811  p3 = vlist[*sI];
1812  cp.AddCoord( p3 );
1813  ++sI;
1814 
1815  vnorm.SetVector( S3D::CalcTriNorm( p1, p2, p3 ) );
1816  norms.AddNormal( vnorm );
1817  norms.AddNormal( vnorm );
1818  norms.AddNormal( vnorm );
1819 
1820  coordIdx.AddIndex( (int)sidx );
1821  ++sidx;
1822  coordIdx.AddIndex( (int)sidx );
1823  ++sidx;
1824  coordIdx.AddIndex( (int)sidx );
1825  ++sidx;
1826  }
1827 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
Class IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
Class IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
void SetVector(double aXVal, double aYVal, double aZVal)
Definition: sg_base.cpp:292
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:643
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
Class IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
static SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
SGLIB_API SGVECTOR CalcTriNorm(const SGPOINT &p1, const SGPOINT &p2, const SGPOINT &p3)
Function CalcTriNorm returns the normal vector of a triangle described by vertices p1...
Definition: ifsg_api.cpp:613
Class IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH...
Class IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40
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 857 of file export_vrml.cpp.

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().

861 {
862  LAYER_NUM layer = top_layer;
863  bool thru = true;
864 
865  // if not a thru hole do not put a hole in the board
866  if( top_layer != F_Cu || bottom_layer != B_Cu )
867  thru = false;
868 
869  if( thru && hole > 0 )
870  aModel.m_holes.AddCircle( x, -y, hole, true );
871 
872  if( aModel.m_plainPCB )
873  return;
874 
875  while( 1 )
876  {
877  if( layer == B_Cu )
878  {
879  aModel.m_bot_copper.AddCircle( x, -y, r );
880 
881  if( hole > 0 && !thru )
882  aModel.m_bot_copper.AddCircle( x, -y, hole, true );
883 
884  }
885  else if( layer == F_Cu )
886  {
887  aModel.m_top_copper.AddCircle( x, -y, r );
888 
889  if( hole > 0 && !thru )
890  aModel.m_top_copper.AddCircle( x, -y, hole, true );
891 
892  }
893 
894  if( layer == bottom_layer )
895  break;
896 
897  layer = bottom_layer;
898  }
899 }
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
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 653 of file export_vrml.cpp.

References GetLayer(), and MODEL_VRML::m_minLineWidth.

Referenced by export_vrml_drawsegment(), and export_vrml_edge_module().

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

Definition at line 799 of file export_vrml.cpp.

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().

800 {
801  SHAPE_POLY_SET pcbOutlines; // stores the board main outlines
802  wxString msg;
803 
804  if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) )
805  {
806  msg << "\n\n" <<
807  _( "Unable to calculate the board outlines; fall back to using the board boundary box." );
808  wxMessageBox( msg );
809  }
810 
811  int seg;
812 
813  for( int cnt = 0; cnt < pcbOutlines.OutlineCount(); cnt++ )
814  {
815  const SHAPE_LINE_CHAIN& outline = pcbOutlines.COutline( cnt );
816 
817  seg = aModel.m_board.NewContour();
818 
819  for( int j = 0; j < outline.PointCount(); j++ )
820  {
821  aModel.m_board.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
822  -((double)outline.CPoint(j).y * BOARD_SCALE ) );
823 
824  }
825 
826  aModel.m_board.EnsureWinding( seg, false );
827 
828  // Generate holes:
829  for( int ii = 0; ii < pcbOutlines.HoleCount( cnt ); ii++ )
830  {
831  const SHAPE_LINE_CHAIN& hole = pcbOutlines.Hole( cnt, ii );
832 
833  seg = aModel.m_holes.NewContour();
834 
835  if( seg < 0 )
836  {
837  msg << "\n\n" <<
838  _( "VRML Export Failed: Could not add holes to contours." );
839  wxMessageBox( msg );
840 
841  return;
842  }
843 
844  for( int j = 0; j < hole.PointCount(); j++ )
845  {
846  aModel.m_holes.AddVertex( seg, (double)hole.CPoint(j).x * BOARD_SCALE,
847  -((double)hole.CPoint(j).y * BOARD_SCALE ) );
848 
849  }
850 
851  aModel.m_holes.EnsureWinding( seg, true );
852  }
853  }
854 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, wxString *aErrorText=NULL)
Function GetBoardPolygonOutlines Extracts the board outlines and build a closed polygon from lines...
int PointCount() const
Function PointCount()
VRML_LAYER m_holes
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Returns the reference to aHole-th hole in the aIndex-th outline
int OutlineCount() const
Returns the number of outlines in the set
Class SHAPE_POLY_SET.
VRML_LAYER m_board
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Class SHAPE_LINE_CHAIN.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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 622 of file export_vrml.cpp.

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

Referenced by export_vrml_edge_module().

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

Definition at line 771 of file export_vrml.cpp.

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

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

772 {
773  // draw graphic items
774  for( BOARD_ITEM* drawing = pcb->m_Drawings; drawing != 0; drawing = drawing->Next() )
775  {
776  LAYER_ID layer = drawing->GetLayer();
777 
778  if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
779  continue;
780 
781  switch( drawing->Type() )
782  {
783  case PCB_LINE_T:
784  export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing );
785  break;
786 
787  case PCB_TEXT_T:
788  export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing );
789  break;
790 
791  default:
792  break;
793  }
794  }
795 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
BOARD_ITEM * Next() const
static void export_vrml_drawsegment(MODEL_VRML &aModel, DRAWSEGMENT *drawseg)
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:242
static void export_vrml_pcbtext(MODEL_VRML &aModel, TEXTE_PCB *text)
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
static void export_vrml_drawsegment ( MODEL_VRML aModel,
DRAWSEGMENT drawseg 
)
static

Definition at line 675 of file export_vrml.cpp.

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

Referenced by export_vrml_drawings().

676 {
677  LAYER_NUM layer = drawseg->GetLayer();
678  double w = drawseg->GetWidth() * BOARD_SCALE;
679  double x = drawseg->GetStart().x * BOARD_SCALE;
680  double y = drawseg->GetStart().y * BOARD_SCALE;
681  double xf = drawseg->GetEnd().x * BOARD_SCALE;
682  double yf = drawseg->GetEnd().y * BOARD_SCALE;
683  double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) );
684 
685  // Items on the edge layer are handled elsewhere; just return
686  if( layer == Edge_Cuts )
687  return;
688 
689  switch( drawseg->GetShape() )
690  {
691  case S_ARC:
692  export_vrml_arc( aModel, layer,
693  (double) drawseg->GetCenter().x * BOARD_SCALE,
694  (double) drawseg->GetCenter().y * BOARD_SCALE,
695  (double) drawseg->GetArcStart().x * BOARD_SCALE,
696  (double) drawseg->GetArcStart().y * BOARD_SCALE,
697  w, drawseg->GetAngle() / 10 );
698  break;
699 
700  case S_CIRCLE:
701  // Break circles into two 180 arcs to prevent the vrml hole from obscuring objects
702  // within the hole area of the circle.
703  export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 );
704  export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 );
705  break;
706 
707  default:
708  export_vrml_line( aModel, layer, x, y, xf, yf, w );
709  break;
710  }
711 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
const wxPoint GetCenter() const override
Function GetCenter()
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint & GetArcStart() const
STROKE_T GetShape() const
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)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double GetAngle() const
int GetWidth() const
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
static void export_vrml_edge_module ( MODEL_VRML aModel,
EDGE_MODULE aOutline,
double  aOrientation 
)
static

Definition at line 1004 of file export_vrml.cpp.

References BOARD_SCALE, export_vrml_arc(), export_vrml_circle(), export_vrml_line(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetEnd(), BOARD_ITEM::GetLayer(), GetLayer(), DRAWSEGMENT::GetPolyPoints(), DRAWSEGMENT::GetPosition(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), DRAWSEGMENT::GetWidth(), RotatePoint(), S_ARC, S_CIRCLE, S_POLYGON, S_SEGMENT, wxPoint::x, and wxPoint::y.

Referenced by export_vrml_module().

1006 {
1007  LAYER_NUM layer = aOutline->GetLayer();
1008  double x = aOutline->GetStart().x * BOARD_SCALE;
1009  double y = aOutline->GetStart().y * BOARD_SCALE;
1010  double xf = aOutline->GetEnd().x * BOARD_SCALE;
1011  double yf = aOutline->GetEnd().y * BOARD_SCALE;
1012  double w = aOutline->GetWidth() * BOARD_SCALE;
1013 
1014  switch( aOutline->GetShape() )
1015  {
1016  case S_SEGMENT:
1017  export_vrml_line( aModel, layer, x, y, xf, yf, w );
1018  break;
1019 
1020  case S_ARC:
1021  export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
1022  break;
1023 
1024  case S_CIRCLE:
1025  export_vrml_circle( aModel, layer, x, y, xf, yf, w );
1026  break;
1027 
1028  case S_POLYGON:
1029  {
1030  VRML_LAYER* vl;
1031 
1032  if( !GetLayer( aModel, layer, &vl ) )
1033  break;
1034 
1035  int nvert = aOutline->GetPolyPoints().size() - 1;
1036  int i = 0;
1037 
1038  if( nvert < 3 ) break;
1039 
1040  int seg = vl->NewContour();
1041 
1042  if( seg < 0 )
1043  break;
1044 
1045  while( i < nvert )
1046  {
1047  CPolyPt corner( aOutline->GetPolyPoints()[i] );
1048  RotatePoint( &corner.x, &corner.y, aOrientation );
1049  corner.x += aOutline->GetPosition().x;
1050  corner.y += aOutline->GetPosition().y;
1051 
1052  x = corner.x * BOARD_SCALE;
1053  y = - ( corner.y * BOARD_SCALE );
1054 
1055  if( !vl->AddVertex( seg, x, y ) )
1056  throw( std::runtime_error( vl->GetError() ) );
1057 
1058  ++i;
1059  }
1060  vl->EnsureWinding( seg, false );
1061  }
1062  break;
1063 
1064  default:
1065  break;
1066  }
1067 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
polygon (not yet used for tracks, but could be in microwave apps)
usual segment : line with rounded ends
const std::vector< wxPoint > & GetPolyPoints() const
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static void export_vrml_circle(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
STROKE_T GetShape() const
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)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double GetAngle() const
int GetWidth() const
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
static void export_vrml_line(MODEL_VRML &aModel, LAYER_NUM layer, double startx, double starty, double endx, double endy, double width)
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
const wxPoint & GetPosition() const override
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 597 of file export_vrml.cpp.

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

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

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

Definition at line 1268 of file export_vrml.cpp.

References abs, IFSG_NODE::AddChildNode(), IFSG_NODE::AddRefNode(), B_Cu, BOARD_SCALE, build_quat(), 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(), 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(), D_PAD::Next(), BOARD_ITEM::Next(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PRECISION, MODULE::Reference(), S3D_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().

1270 {
1271  if( !aModel.m_plainPCB )
1272  {
1273  // Reference and value
1274  if( aModule->Reference().IsVisible() )
1275  export_vrml_text_module( &aModule->Reference() );
1276 
1277  if( aModule->Value().IsVisible() )
1278  export_vrml_text_module( &aModule->Value() );
1279 
1280  // Export module edges
1281  for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() )
1282  {
1283  switch( item->Type() )
1284  {
1285  case PCB_MODULE_TEXT_T:
1286  export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
1287  break;
1288 
1289  case PCB_MODULE_EDGE_T:
1290  export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ),
1291  aModule->GetOrientation() );
1292  break;
1293 
1294  default:
1295  break;
1296  }
1297  }
1298  }
1299 
1300  // Export pads
1301  for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
1302  export_vrml_pad( aModel, aPcb, pad );
1303 
1304  bool isFlipped = aModule->GetLayer() == B_Cu;
1305 
1306  // Export the object VRML model(s)
1307  std::list<S3D_INFO>::iterator sM = aModule->Models().begin();
1308  std::list<S3D_INFO>::iterator eM = aModule->Models().end();
1309 
1310  wxFileName subdir( SUBDIR_3D, "" );
1311 
1312  while( sM != eM )
1313  {
1314  SGNODE* mod3d = (SGNODE*) cache->Load( sM->m_Filename );
1315 
1316  if( NULL == mod3d )
1317  {
1318  ++sM;
1319  continue;
1320  }
1321 
1322  /* Calculate 3D shape rotation:
1323  * this is the rotation parameters, with an additional 180 deg rotation
1324  * for footprints that are flipped
1325  * When flipped, axis rotation is the horizontal axis (X axis)
1326  */
1327  double rotx = -sM->m_Rotation.x;
1328  double roty = -sM->m_Rotation.y;
1329  double rotz = -sM->m_Rotation.z;
1330 
1331  if( isFlipped )
1332  {
1333  rotx += 180.0;
1334  roty = -roty;
1335  rotz = -rotz;
1336  }
1337 
1338  // Do some quaternion munching
1339  double q1[4], q2[4], rot[4];
1340  build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
1341  build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
1342  compose_quat( q1, q2, q1 );
1343  build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
1344  compose_quat( q1, q2, q1 );
1345 
1346  // Note here aModule->GetOrientation() is in 0.1 degrees,
1347  // so module rotation has to be converted to radians
1348  build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
1349  compose_quat( q1, q2, q1 );
1350  from_quat( q1, rot );
1351 
1352  // adjust 3D shape local offset position
1353  // they are given in inch, so they are converted in board IU.
1354  double offsetx = sM->m_Offset.x * IU_PER_MILS * 1000.0;
1355  double offsety = sM->m_Offset.y * IU_PER_MILS * 1000.0;
1356  double offsetz = sM->m_Offset.z * IU_PER_MILS * 1000.0;
1357 
1358  if( isFlipped )
1359  offsetz = -offsetz;
1360  else // In normal mode, Y axis is reversed in Pcbnew.
1361  offsety = -offsety;
1362 
1363  RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
1364 
1365  SGPOINT trans;
1366  trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.m_tx;
1367  trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.m_ty;
1368  trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() );
1369 
1370  if( USE_INLINES )
1371  {
1372  wxFileName srcFile = cache->GetResolver()->ResolvePath( sM->m_Filename );
1373  wxFileName dstFile;
1374  dstFile.SetPath( SUBDIR_3D );
1375  dstFile.SetName( srcFile.GetName() );
1376  dstFile.SetExt( "wrl" );
1377 
1378  // copy the file if necessary
1379  wxDateTime srcModTime = srcFile.GetModificationTime();
1380  wxDateTime destModTime = srcModTime;
1381 
1382  destModTime.SetToCurrent();
1383 
1384  if( dstFile.FileExists() )
1385  destModTime = dstFile.GetModificationTime();
1386 
1387  if( srcModTime != destModTime )
1388  {
1389  wxLogDebug( "Copying 3D model %s to %s.",
1390  GetChars( srcFile.GetFullPath() ),
1391  GetChars( dstFile.GetFullPath() ) );
1392 
1393  wxString fileExt = srcFile.GetExt();
1394  fileExt.LowerCase();
1395 
1396  // copy VRML models and use the scenegraph library to
1397  // translate other model types
1398  if( fileExt == "wrl" )
1399  {
1400  if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
1401  continue;
1402  }
1403  else
1404  {
1405  if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
1406  continue;
1407  }
1408  }
1409 
1410  (*aOutputFile) << "Transform {\n";
1411 
1412  // only write a rotation if it is >= 0.1 deg
1413  if( std::abs( rot[3] ) > 0.0001745 )
1414  {
1415  (*aOutputFile) << " rotation " << std::setprecision( 5 );
1416  (*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
1417  }
1418 
1419  (*aOutputFile) << " translation " << std::setprecision( PRECISION );
1420  (*aOutputFile) << trans.x << " ";
1421  (*aOutputFile) << trans.y << " ";
1422  (*aOutputFile) << trans.z << "\n";
1423 
1424  (*aOutputFile) << " scale ";
1425  (*aOutputFile) << sM->m_Scale.x << " ";
1426  (*aOutputFile) << sM->m_Scale.y << " ";
1427  (*aOutputFile) << sM->m_Scale.z << "\n";
1428 
1429  (*aOutputFile) << " children [\n Inline {\n url \"";
1430 
1431  if( USE_RELPATH )
1432  {
1433  wxFileName tmp = dstFile;
1434  tmp.SetExt( "" );
1435  tmp.SetName( "" );
1436  tmp.RemoveLastDir();
1437  dstFile.MakeRelativeTo( tmp.GetPath() );
1438  }
1439 
1440  wxString fn = dstFile.GetFullPath();
1441  fn.Replace( "\\", "/" );
1442  (*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
1443  (*aOutputFile) << " }\n";
1444  }
1445  else
1446  {
1447  IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( aModel.m_OutputPCB.GetRawPtr() );
1448 
1449  // only write a rotation if it is >= 0.1 deg
1450  if( std::abs( rot[3] ) > 0.0001745 )
1451  modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
1452 
1453  modelShape->SetTranslation( trans );
1454  modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
1455 
1456  if( NULL == S3D::GetSGNodeParent( mod3d ) )
1457  {
1458  aModel.m_components.push_back( mod3d );
1459  modelShape->AddChildNode( mod3d );
1460  }
1461  else
1462  {
1463  modelShape->AddRefNode( mod3d );
1464  }
1465 
1466  }
1467 
1468  ++sM;
1469  }
1470 }
bool SetTranslation(const SGPOINT &aTranslation)
static double BOARD_SCALE
Definition: export_vrml.cpp:65
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
TEXTE_MODULE & Reference()
Definition: class_module.h:455
static S3D_CACHE * cache
Definition: export_vrml.cpp:60
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:61
const wxPoint & GetPosition() const override
Definition: class_module.h:143
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:643
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
std::list< S3D_INFO > & Models()
Definition: class_module.h:139
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
bool SetScale(const SGPOINT &aScale)
IFSG_TRANSFORM m_OutputPCB
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
#define abs(a)
Definition: auxiliary.h:84
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
static void export_vrml_text_module(TEXTE_MODULE *module)
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
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])
BOARD_ITEM * Next() const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
double GetOrientation() const
Definition: class_module.h:147
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
D_PAD * Next() const
Definition: class_pad.h:106
static bool USE_RELPATH
Definition: export_vrml.cpp:63
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
static wxString SUBDIR_3D
Definition: export_vrml.cpp:67
S3D_FILENAME_RESOLVER * GetResolver(void)
Definition: 3d_cache.cpp:739
std::list< SGNODE * > m_components
static void export_vrml_edge_module(MODEL_VRML &aModel, EDGE_MODULE *aOutline, double aOrientation)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
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:92
double DEG2RAD(double deg)
Definition: trigo.h:191
wxString ResolvePath(const wxString &aFileName)
Function ResolvePath determines the full path of the given file name.
bool IsVisible() const
Definition: eda_text.h:176
Class IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH...
double DECIDEG2RAD(double deg)
Definition: trigo.h:195
static void from_quat(double q[4], double rot[4])
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
static const int PRECISION
Definition: export_vrml.cpp:66
static bool USE_DEFS
Definition: export_vrml.cpp:62
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
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:271
double GetLayerZ(LAYER_NUM aLayer)
static void export_vrml_pad ( MODEL_VRML aModel,
BOARD aPcb,
D_PAD aPad 
)
static

Definition at line 1154 of file export_vrml.cpp.

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

Referenced by export_vrml_module().

1155 {
1156  double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0;
1157  double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0;
1158  double hole_drill = std::min( hole_drill_w, hole_drill_h );
1159  double hole_x = aPad->GetPosition().x * BOARD_SCALE;
1160  double hole_y = aPad->GetPosition().y * BOARD_SCALE;
1161 
1162  // Export the hole on the edge layer
1163  if( hole_drill > 0 )
1164  {
1165  bool pth = false;
1166 
1167  if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
1168  && !aModel.m_plainPCB )
1169  pth = true;
1170 
1171  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1172  {
1173  // Oblong hole (slot)
1174 
1175  if( pth )
1176  {
1177  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
1178  hole_drill_h * 2.0 + PLATE_OFFSET,
1179  aPad->GetOrientation()/10.0, true, true );
1180 
1181  aModel.m_plated_holes.AddSlot( hole_x, -hole_y,
1182  hole_drill_w * 2.0, hole_drill_h * 2.0,
1183  aPad->GetOrientation()/10.0, true, false );
1184  }
1185  else
1186  {
1187  aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
1188  aPad->GetOrientation()/10.0, true, false );
1189 
1190  }
1191  }
1192  else
1193  {
1194  // Drill a round hole
1195 
1196  if( pth )
1197  {
1198  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
1199  aModel.m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1200  }
1201  else
1202  {
1203  aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
1204  }
1205 
1206  }
1207  }
1208 
1209  if( aModel.m_plainPCB )
1210  return;
1211 
1212  // The pad proper, on the selected layers
1213  LSET layer_mask = aPad->GetLayerSet();
1214 
1215  if( layer_mask[B_Cu] )
1216  {
1217  export_vrml_padshape( aModel, &aModel.m_bot_tin, aPad );
1218  }
1219 
1220  if( layer_mask[F_Cu] )
1221  {
1222  export_vrml_padshape( aModel, &aModel.m_top_tin, aPad );
1223  }
1224 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:238
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
VRML_LAYER m_bot_tin
VRML_LAYER m_plated_holes
VRML_LAYER m_holes
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:221
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
static void export_vrml_padshape(MODEL_VRML &aModel, VRML_LAYER *aTinLayer, D_PAD *aPad)
Class LSET is a set of LAYER_IDs.
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
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:235
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
#define PLATE_OFFSET
Definition: export_vrml.cpp:58
VRML_LAYER m_top_tin
#define min(a, b)
Definition: auxiliary.h:85
static void export_vrml_padshape ( MODEL_VRML aModel,
VRML_LAYER *  aTinLayer,
D_PAD aPad 
)
static

Definition at line 1070 of file export_vrml.cpp.

References BOARD_SCALE, D_PAD::GetDelta(), D_PAD::GetOrientation(), D_PAD::GetShape(), D_PAD::GetSize(), PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_TRAPEZOID, RotatePoint(), D_PAD::ShapePos(), wxPoint::x, and wxPoint::y.

Referenced by export_vrml_pad().

1071 {
1072  // The (maybe offset) pad position
1073  wxPoint pad_pos = aPad->ShapePos();
1074  double pad_x = pad_pos.x * BOARD_SCALE;
1075  double pad_y = pad_pos.y * BOARD_SCALE;
1076  wxSize pad_delta = aPad->GetDelta();
1077 
1078  double pad_dx = pad_delta.x * BOARD_SCALE / 2.0;
1079  double pad_dy = pad_delta.y * BOARD_SCALE / 2.0;
1080 
1081  double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0;
1082  double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0;
1083 
1084  switch( aPad->GetShape() )
1085  {
1086  case PAD_SHAPE_CIRCLE:
1087 
1088  if( !aTinLayer->AddCircle( pad_x, -pad_y, pad_w, false ) )
1089  throw( std::runtime_error( aTinLayer->GetError() ) );
1090 
1091  break;
1092 
1093  case PAD_SHAPE_OVAL:
1094 
1095  if( !aTinLayer->AddSlot( pad_x, -pad_y, pad_w * 2.0, pad_h * 2.0,
1096  aPad->GetOrientation()/10.0, false ) )
1097  throw( std::runtime_error( aTinLayer->GetError() ) );
1098 
1099  break;
1100 
1101  case PAD_SHAPE_RECT:
1102  // Just to be sure :D
1103  pad_dx = 0;
1104  pad_dy = 0;
1105 
1106  case PAD_SHAPE_TRAPEZOID:
1107  {
1108  double coord[8] =
1109  {
1110  -pad_w + pad_dy, -pad_h - pad_dx,
1111  -pad_w - pad_dy, pad_h + pad_dx,
1112  +pad_w - pad_dy, -pad_h + pad_dx,
1113  +pad_w + pad_dy, pad_h - pad_dx
1114  };
1115 
1116  for( int i = 0; i < 4; i++ )
1117  {
1118  RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
1119  coord[i * 2] += pad_x;
1120  coord[i * 2 + 1] += pad_y;
1121  }
1122 
1123  int lines;
1124 
1125  lines = aTinLayer->NewContour();
1126 
1127  if( lines < 0 )
1128  throw( std::runtime_error( aTinLayer->GetError() ) );
1129 
1130  if( !aTinLayer->AddVertex( lines, coord[0], -coord[1] ) )
1131  throw( std::runtime_error( aTinLayer->GetError() ) );
1132 
1133  if( !aTinLayer->AddVertex( lines, coord[4], -coord[5] ) )
1134  throw( std::runtime_error( aTinLayer->GetError() ) );
1135 
1136  if( !aTinLayer->AddVertex( lines, coord[6], -coord[7] ) )
1137  throw( std::runtime_error( aTinLayer->GetError() ) );
1138 
1139  if( !aTinLayer->AddVertex( lines, coord[2], -coord[3] ) )
1140  throw( std::runtime_error( aTinLayer->GetError() ) );
1141 
1142  if( !aTinLayer->EnsureWinding( lines, false ) )
1143  throw( std::runtime_error( aTinLayer->GetError() ) );
1144 
1145  break;
1146  }
1147 
1148  default:
1149  break;
1150  }
1151 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
const wxSize & GetSize() const
Definition: class_pad.h:182
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
const wxSize & GetDelta() const
Definition: class_pad.h:185
wxPoint ShapePos() const
Definition: class_pad.cpp:367
static void export_vrml_pcbtext ( MODEL_VRML aModel,
TEXTE_PCB text 
)
static

Definition at line 728 of file export_vrml.cpp.

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

Referenced by export_vrml_drawings().

729 {
730  model_vrml->m_text_layer = text->GetLayer();
732 
733  wxSize size = text->GetTextSize();
734 
735  if( text->IsMirrored() )
736  size.x = -size.x;
737 
738  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by DrawGraphicText
739 
740  if( text->IsMultilineAllowed() )
741  {
742  wxArrayString strings_list;
743  wxStringSplit( text->GetShownText(), strings_list, '\n' );
744  std::vector<wxPoint> positions;
745  positions.reserve( strings_list.Count() );
746  text->GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
747 
748  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
749  {
750  wxString& txt = strings_list.Item( ii );
751  DrawGraphicText( NULL, NULL, positions[ii], color,
752  txt, text->GetTextAngle(), size,
753  text->GetHorizJustify(), text->GetVertJustify(),
754  text->GetThickness(), text->IsItalic(),
755  true,
757  }
758  }
759  else
760  {
761  DrawGraphicText( NULL, NULL, text->GetTextPos(), color,
762  text->GetShownText(), text->GetTextAngle(), size,
763  text->GetHorizJustify(), text->GetVertJustify(),
764  text->GetThickness(), text->IsItalic(),
765  true,
767  }
768 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Function wxStringSplit splits aString to a string list separated at aSplitter.
Definition: common.cpp:237
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf), PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
Definition: drawtxt.cpp:122
bool IsMultilineAllowed() const
Definition: eda_text.h:188
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
static MODEL_VRML * model_vrml
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
double GetTextAngle() const
Definition: eda_text.h:164
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:135
void GetPositionsOfLinesOfMultilineText(std::vector< wxPoint > &aPositions, int aLineCount) const
Function GetPositionsOfLinesOfMultilineText Populates aPositions with the position of each line of a ...
Definition: eda_text.cpp:327
LAYER_NUM m_text_layer
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsMirrored() const
Definition: eda_text.h:179
static void vrml_text_callback(int x0, int y0, int xf, int yf)
Definition: colors.h:45
const wxSize & GetTextSize() const
Definition: eda_text.h:215
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
static void export_vrml_text_module ( TEXTE_MODULE module)
static

Definition at line 982 of file export_vrml.cpp.

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

Referenced by export_vrml_module().

983 {
984  if( module->IsVisible() )
985  {
986  wxSize size = module->GetTextSize();
987 
988  if( module->IsMirrored() )
989  size.x = -size.x; // Text is mirrored
990 
991  model_vrml->m_text_layer = module->GetLayer();
992  model_vrml->m_text_width = module->GetThickness();
993 
994  DrawGraphicText( NULL, NULL, module->GetTextPos(), BLACK,
995  module->GetShownText(), module->GetDrawRotation(), size,
996  module->GetHorizJustify(), module->GetVertJustify(),
997  module->GetThickness(), module->IsItalic(),
998  true,
1000  }
1001 }
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf), PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
Definition: drawtxt.cpp:122
double GetDrawRotation() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
static MODEL_VRML * model_vrml
virtual wxString GetShownText() const override
Returns the string actually shown after processing of the base text.
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
LAYER_NUM m_text_layer
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsMirrored() const
Definition: eda_text.h:179
bool IsVisible() const
Definition: eda_text.h:176
static void vrml_text_callback(int x0, int y0, int xf, int yf)
Definition: colors.h:45
const wxSize & GetTextSize() const
Definition: eda_text.h:215
static void export_vrml_tracks ( MODEL_VRML aModel,
BOARD pcb 
)
static

Definition at line 922 of file export_vrml.cpp.

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

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

923 {
924  for( TRACK* track = pcb->m_Track; track; track = track->Next() )
925  {
926  if( track->Type() == PCB_VIA_T )
927  {
928  export_vrml_via( aModel, pcb, (const VIA*) track );
929  }
930  else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
931  && !aModel.m_plainPCB )
932  export_vrml_line( aModel, track->GetLayer(),
933  track->GetStart().x * BOARD_SCALE,
934  track->GetStart().y * BOARD_SCALE,
935  track->GetEnd().x * BOARD_SCALE,
936  track->GetEnd().y * BOARD_SCALE,
937  track->GetWidth() * BOARD_SCALE );
938  }
939 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
TRACK * Next() const
Definition: class_track.h:97
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
static void export_vrml_via(MODEL_VRML &aModel, BOARD *aPcb, const VIA *aVia)
DLIST< TRACK > m_Track
Definition: class_board.h:244
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_via ( MODEL_VRML aModel,
BOARD aPcb,
const VIA aVia 
)
static

Definition at line 902 of file export_vrml.cpp.

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().

903 {
904  double x, y, r, hole;
905  LAYER_ID top_layer, bottom_layer;
906 
907  hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0;
908  r = aVia->GetWidth() * BOARD_SCALE / 2.0;
909  x = aVia->GetStart().x * BOARD_SCALE;
910  y = aVia->GetStart().y * BOARD_SCALE;
911  aVia->LayerPair( &top_layer, &bottom_layer );
912 
913  // do not render a buried via
914  if( top_layer != F_Cu && bottom_layer != B_Cu )
915  return;
916 
917  // Export the via padstack
918  export_round_padstack( aModel, aPcb, x, y, r, bottom_layer, top_layer, hole );
919 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
const wxPoint & GetStart() const
Definition: class_track.h:120
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)
void LayerPair(LAYER_ID *top_layer, LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
int GetWidth() const
Definition: class_track.h:114
static void export_vrml_zones ( MODEL_VRML aModel,
BOARD aPcb 
)
static

Definition at line 942 of file export_vrml.cpp.

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

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

943 {
944 
945  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
946  {
947  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
948 
949  VRML_LAYER* vl;
950 
951  if( !GetLayer( aModel, zone->GetLayer(), &vl ) )
952  continue;
953 
954  if( !zone->IsFilled() )
955  {
956  zone->SetFillMode( 0 ); // use filled polygons
957  zone->BuildFilledSolidAreasPolygons( aPcb );
958  }
959 
960  const SHAPE_POLY_SET& poly = zone->GetFilledPolysList();
961 
962  for( int i = 0; i < poly.OutlineCount(); i++ )
963  {
964  const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
965 
966  int seg = vl->NewContour();
967 
968  for( int j = 0; j < outline.PointCount(); j++ )
969  {
970  if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * BOARD_SCALE,
971  -((double)outline.CPoint( j ).y * BOARD_SCALE ) ) )
972  throw( std::runtime_error( vl->GetError() ) );
973 
974  }
975 
976  vl->EnsureWinding( seg, false );
977  }
978  }
979 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
int PointCount() const
Function PointCount()
bool BuildFilledSolidAreasPolygons(BOARD *aPcb, SHAPE_POLY_SET *aOutlineBuffer=NULL)
Function BuildFilledSolidAreasPolygons Build the filled solid areas data from real outlines (stored i...
bool IsFilled() const
Definition: class_zone.h:187
int OutlineCount() const
Returns the number of outlines in the set
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Class SHAPE_POLY_SET.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:470
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
Class SHAPE_LINE_CHAIN.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
void SetFillMode(int aFillMode)
How to fill areas: 0 = use filled polygons, 1 => fill with segments.
Definition: class_zone.h:172
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
static void from_quat ( double  q[4],
double  rot[4] 
)
static

Definition at line 1240 of file export_vrml.cpp.

Referenced by export_vrml_module().

1241 {
1242  rot[3] = acos( q[3] ) * 2;
1243 
1244  for( int i = 0; i < 3; i++ )
1245  {
1246  rot[i] = q[i] / sin( rot[3] / 2 );
1247  }
1248 }
static bool GetLayer ( MODEL_VRML aModel,
LAYER_NUM  layer,
VRML_LAYER **  vlayer 
)
static

Definition at line 285 of file export_vrml.cpp.

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

Referenced by BuildBoardPolygonOutlines(), export_vrml_arc(), export_vrml_circle(), export_vrml_edge_module(), export_vrml_line(), export_vrml_zones(), DRAWING_TOOL::PlaceDXF(), and PCB_EDIT_FRAME::Process_Special_Functions().

286 {
287  switch( layer )
288  {
289  case B_Cu:
290  *vlayer = &aModel.m_bot_copper;
291  break;
292 
293  case F_Cu:
294  *vlayer = &aModel.m_top_copper;
295  break;
296 
297  case B_SilkS:
298  *vlayer = &aModel.m_bot_silk;
299  break;
300 
301  case F_SilkS:
302  *vlayer = &aModel.m_top_silk;
303  break;
304 
305  default:
306  return false;
307  }
308 
309  return true;
310 }
VRML_LAYER m_bot_silk
VRML_LAYER m_top_silk
VRML_LAYER m_bot_copper
VRML_LAYER m_top_copper
static SGNODE* getSGColor ( VRML_COLOR_INDEX  colorIdx)
static

Definition at line 1597 of file export_vrml.cpp.

References VRML_COLOR::ambient, VRML_COLOR::diffuse_blu, VRML_COLOR::diffuse_grn, VRML_COLOR::diffuse_red, IFSG_NODE::GetRawPtr(), IFSG_APPEARANCE::SetAmbient(), IFSG_APPEARANCE::SetDiffuse(), IFSG_APPEARANCE::SetShininess(), IFSG_APPEARANCE::SetSpecular(), IFSG_APPEARANCE::SetTransparency(), 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().

1598 {
1599  if( colorIdx == -1 )
1600  colorIdx = VRML_COLOR_PCB;
1601  else if( colorIdx == VRML_COLOR_LAST )
1602  return NULL;
1603 
1604  if( sgmaterial[colorIdx] )
1605  return sgmaterial[colorIdx];
1606 
1607  IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
1608  VRML_COLOR* cp = &colors[colorIdx];
1609 
1610  vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
1611  vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
1612  vcolor.SetShininess( cp->shiny );
1613  // NOTE: XXX - replace with a better equation; using this definition
1614  // of ambient will not yield the best results
1615  vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
1616  vcolor.SetTransparency( cp->transp );
1617 
1618  sgmaterial[colorIdx] = vcolor.GetRawPtr();
1619 
1620  return sgmaterial[colorIdx];
1621 };
float transp
Definition: export_vrml.cpp:85
static SGNODE * sgmaterial[VRML_COLOR_LAST]
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
float spec_blu
Definition: export_vrml.cpp:78
float ambient
Definition: export_vrml.cpp:84
float diffuse_grn
Definition: export_vrml.cpp:73
float spec_red
Definition: export_vrml.cpp:76
float spec_grn
Definition: export_vrml.cpp:77
float diffuse_red
Definition: export_vrml.cpp:72
float diffuse_blu
Definition: export_vrml.cpp:74
static VRML_COLOR colors[VRML_COLOR_LAST]
static void vrml_text_callback ( int  x0,
int  y0,
int  xf,
int  yf 
)
static

Definition at line 716 of file export_vrml.cpp.

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

Referenced by export_vrml_pcbtext(), and export_vrml_text_module().

717 {
718  LAYER_NUM m_text_layer = model_vrml->m_text_layer;
719  int m_text_width = model_vrml->m_text_width;
720 
721  export_vrml_line( *model_vrml, m_text_layer,
722  x0 * BOARD_SCALE, y0 * BOARD_SCALE,
723  xf * BOARD_SCALE, yf * BOARD_SCALE,
724  m_text_width * BOARD_SCALE );
725 }
static double BOARD_SCALE
Definition: export_vrml.cpp:65
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)
static void write_layers ( MODEL_VRML aModel,
BOARD aPcb,
const char *  aFileName,
OSTREAM aOutputFile 
)
static

Definition at line 418 of file export_vrml.cpp.

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

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

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

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().

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

Variable Documentation

S3D_CACHE* cache
static

Definition at line 60 of file export_vrml.cpp.

MODEL_VRML* model_vrml
static

Definition at line 280 of file export_vrml.cpp.

const int PRECISION = 6
static
wxString PROJ_DIR
static

Definition at line 68 of file export_vrml.cpp.

Referenced by PCB_EDIT_FRAME::ExportVRML_File().

SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }
static

Definition at line 138 of file export_vrml.cpp.

wxString SUBDIR_3D
static

Definition at line 67 of file export_vrml.cpp.

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

bool USE_DEFS
static
bool USE_INLINES
static
bool USE_RELPATH
static

Definition at line 63 of file export_vrml.cpp.

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

double WORLD_SCALE = 1.0
static

Definition at line 64 of file export_vrml.cpp.

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