From 3e71ed2421f5df433c11a554e0756f6898e25b06 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 14 Nov 2017 20:53:59 +1100 Subject: [PATCH] Changed model offset in file to mm - Written in mm - Read as mm if newer than 20171114 - Read as inches if older than 20171114 - Added some documentation --- pcbnew/class_module.h | 6 +++--- pcbnew/kicad_plugin.cpp | 1 + pcbnew/kicad_plugin.h | 3 ++- pcbnew/pcb_parser.cpp | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index daeb814fd2..9b742b061b 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -95,9 +95,9 @@ class MODULE_3D_SETTINGS double x, y, z; }; - VECTOR3D m_Scale; - VECTOR3D m_Rotation; - VECTOR3D m_Offset; + VECTOR3D m_Scale; ///< 3D model scaling factor (dimensionless) + VECTOR3D m_Rotation; ///< 3D model rotation (degrees) + VECTOR3D m_Offset; ///< 3D model offset (mm) wxString m_Filename; ///< The 3D shape filename in 3D library }; diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 85f4f8e92c..c4477ad0a2 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -1140,6 +1140,7 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const m_out->Print( aNestLevel+1, "(model %s\n", m_out->Quotew( bs3D->m_Filename ).c_str() ); + // Model offset is in mm m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n", Double2Str( bs3D->m_Offset.x ).c_str(), Double2Str( bs3D->m_Offset.y ).c_str(), diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index eff75906e5..87dc736bf3 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -44,7 +44,8 @@ class NETINFO_MAPPING; //#define SEXPR_BOARD_FILE_VERSION 20160815 // differential pair settings per net class //#define SEXPR_BOARD_FILE_VERSION 20170123 // EDA_TEXT refactor, moved 'hide' //#define SEXPR_BOARD_FILE_VERSION 20170920 // long pad names and custom pad shape -#define SEXPR_BOARD_FILE_VERSION 20170922 // Keepout zones can exist on multiple layers +//#define SEXPR_BOARD_FILE_VERSION 20170922 // Keepout zones can exist on multiple layers +#define SEXPR_BOARD_FILE_VERSION 20171114 // Save 3D model offset in mm, instead of inches #define CTL_STD_LAYER_NAMES (1 << 0) ///< Use English Standard layer names #define CTL_OMIT_NETS (1 << 1) ///< Omit pads net names (useless in library) diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index b96d9bb218..13a118933e 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -359,9 +359,26 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel() if( token != T_xyz ) Expecting( T_xyz ); + /* Note: + * Prior to SEXPR_BOARD_FILE_VERSION 20171114, + * 3D model offset was read and written in inches + * + * Now, the offset is explicitly written in mm. + * If a board is read with an older version, + * the offset is converted from inches to mm + */ + n3D->m_Offset.x = parseDouble( "x value" ); n3D->m_Offset.y = parseDouble( "y value" ); n3D->m_Offset.z = parseDouble( "z value" ); + + if(m_requiredVersion < 20171114UL) + { + n3D->m_Offset.x *= 25.4f; + n3D->m_Offset.y *= 25.4f; + n3D->m_Offset.z *= 25.4f; + } + NeedRIGHT(); break;