kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #31878
Re: [PATCH] Fix for 3D model offset
JP, Wayne,
I have implemented JP's suggestion to write "at" if offset is zero
(default) as patch 0002 attached.
Wayne, you can choose to apply 0002 if you like this idea.
On Thu, Nov 23, 2017 at 9:35 PM, jp charras <jp.charras@xxxxxxxxxx> wrote:
> Le 23/11/2017 à 11:25, Oliver Walters a écrit :
> > Orson, Wayne,
> >
> > I would agree. Please find attached a patch that implements "offset"
>
> Hi Oliver,
> Because all our footprints in libraries have the "offset" set to O,O,O,
> (the default value) if could
> be worth to export the offset only if it is not 0,0,0
>
> This is an easy way to keep footprint libraries readable be the stable
> version.
>
> >
> > On Thu, Nov 23, 2017 at 7:05 PM, Maciej Sumiński <
> maciej.suminski@xxxxxxx
> > <mailto:maciej.suminski@xxxxxxx>> wrote:
> >
> > I think the master branch already has enough new features to make its
> > output incompatible with v4. 'Offset' approach seems the easiest and
> > cleanest solution IMHO.
> >
> > Cheers,
> > Orson
> >
>
>
> --
> Jean-Pierre CHARRAS
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
From 52d080dda4419ea4f554666f73db93a839bc4c56 Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@xxxxxxxxx>
Date: Thu, 23 Nov 2017 23:14:59 +1100
Subject: [PATCH 2/2] Write "at" if offset is (0, 0, 0)
- If non-zero offset, write "offset" instead
---
pcbnew/kicad_plugin.cpp | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp
index 2c75f27..d619a78 100644
--- a/pcbnew/kicad_plugin.cpp
+++ b/pcbnew/kicad_plugin.cpp
@@ -1142,8 +1142,20 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
/* Write 3D model offset in mm
* 4.0.x wrote "at" which was actually in inches
+ * To preserve files, "at" will be written for zero values
+ * If a non-zero offset is provided, it is written using "offset"
*/
- m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
+ wxString tag = "at";
+
+ if( ( fabs( bs3D->m_Offset.x ) > 0.0f ) ||
+ ( fabs( bs3D->m_Offset.y ) > 0.0f ) ||
+ ( fabs( bs3D->m_Offset.z ) > 0.0f ) )
+ {
+ tag = "offset";
+ }
+
+ m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
+ tag.ToStdString().c_str(),
Double2Str( bs3D->m_Offset.x ).c_str(),
Double2Str( bs3D->m_Offset.y ).c_str(),
Double2Str( bs3D->m_Offset.z ).c_str() );
--
2.7.4
From 476e6350fb8bd04fc9275038fa403823cc15c78e Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@xxxxxxxxx>
Date: Thu, 23 Nov 2017 21:21:48 +1100
Subject: [PATCH 1/2] CHANGE file format for 3D model offset
- Reverts behaviour of 3e71ed2421f5df433c11a554e0756f6898e25b06
- 3D model offset now explicitly written in mm, using "offset" tag
- Any read "at" tag is converted from inches to mm
- This will not break any 3D model offset when reading files
- It will however render files incompatible with old versions
---
pcbnew/kicad_plugin.cpp | 6 ++++--
pcbnew/kicad_plugin.h | 3 ++-
pcbnew/pcb_parser.cpp | 35 ++++++++++++++++++++---------------
3 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp
index c4477ad..2c75f27 100644
--- a/pcbnew/kicad_plugin.cpp
+++ b/pcbnew/kicad_plugin.cpp
@@ -1140,8 +1140,10 @@ 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",
+ /* Write 3D model offset in mm
+ * 4.0.x wrote "at" which was actually in inches
+ */
+ m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
Double2Str( bs3D->m_Offset.x ).c_str(),
Double2Str( bs3D->m_Offset.y ).c_str(),
Double2Str( bs3D->m_Offset.z ).c_str() );
diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h
index 87dc736..7423b4f 100644
--- a/pcbnew/kicad_plugin.h
+++ b/pcbnew/kicad_plugin.h
@@ -45,7 +45,8 @@ class NETINFO_MAPPING;
//#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 20171114 // Save 3D model offset in mm, instead of inches
+//#define SEXPR_BOARD_FILE_VERSION 20171114 // Save 3D model offset in mm, instead of inches
+#define SEXPR_BOARD_FILE_VERSION 20171123 // 3D model offset written using "offset" parameter
#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 494b91e..6bb40ff 100644
--- a/pcbnew/pcb_parser.cpp
+++ b/pcbnew/pcb_parser.cpp
@@ -360,25 +360,30 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
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
+ * Prior to KiCad v5, model offset was designated by "at",
+ * and the units were in inches.
+ * Now we use mm, but support reading of legacy files
*/
+ n3D->m_Offset.x = parseDouble( "x value" ) * 25.4f;
+ n3D->m_Offset.y = parseDouble( "y value" ) * 25.4f;
+ n3D->m_Offset.z = parseDouble( "z value" ) * 25.4f;
+ NeedRIGHT();
+ break;
+
+ case T_offset:
+ NeedLEFT();
+ token = NextTok();
+
+ if( token != T_xyz )
+ Expecting( T_xyz );
+
+ /*
+ * 3D model offset is in 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 < 20171114L)
- {
- n3D->m_Offset.x *= 25.4f;
- n3D->m_Offset.y *= 25.4f;
- n3D->m_Offset.z *= 25.4f;
- }
-
NeedRIGHT();
break;
@@ -409,7 +414,7 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
break;
default:
- Expecting( "at, scale, or rotate" );
+ Expecting( "at, offset, scale, or rotate" );
}
NeedRIGHT();
--
2.7.4
References
-
[PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-08
-
Re: [PATCH] Fix for 3D model offset
From: Maciej Suminski, 2017-11-15
-
Re: [PATCH] Fix for 3D model offset
From: easyw, 2017-11-21
-
Re: [PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-21
-
Re: [PATCH] Fix for 3D model offset
From: Wayne Stambaugh, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: easyw, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Wayne Stambaugh, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: José Ignacio, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Wayne Stambaugh, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Marcos Chaparro, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: easyw, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-22
-
Re: [PATCH] Fix for 3D model offset
From: Maciej Sumiński, 2017-11-23
-
Re: [PATCH] Fix for 3D model offset
From: Oliver Walters, 2017-11-23
-
Re: [PATCH] Fix for 3D model offset
From: jp charras, 2017-11-23