← Back to team overview

kicad-developers team mailing list archive

[RFC 2/2] Compatibility functions for new coordinate system

 

---
 CMakeLists.txt        |  4 ++++
 common/base_units.cpp | 13 +++++++++++++
 include/base_units.h  | 10 ++++++++++
 include/point.h       | 30 ++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 982209910..08fe26918 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -244,6 +244,10 @@ if( WIN32 )
 endif()
 
 
+# Transition
+add_definitions(-DLEGACY_COORDS)
+
+
 #================================================
 # Provide access to CCACHE
 #================================================
diff --git a/common/base_units.cpp b/common/base_units.cpp
index 0caff8137..d2a69d03c 100644
--- a/common/base_units.cpp
+++ b/common/base_units.cpp
@@ -42,6 +42,19 @@
 #include "libeval/numeric_evaluator.h"
 
 
+#if defined(EESCHEMA)
+const length legacy_iu = 1_mil;
+#elif defined(GERBVIEW)
+const length legacy_iu = 10_nm;
+#elif defined(PL_EDITOR)
+const length legacy_iu = 1_um;
+#elif defined(PCBNEW) || defined(CVPCB)
+const length legacy_iu = 1_nm;
+#else
+#error missing unit definition
+#endif
+
+
 #if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
 #define IU_TO_MM( x )       ( x / IU_PER_MM )
 #define IU_TO_IN( x )       ( x / IU_PER_MILS / 1000 )
diff --git a/include/base_units.h b/include/base_units.h
index 20450115c..f9ac4a84b 100644
--- a/include/base_units.h
+++ b/include/base_units.h
@@ -38,6 +38,16 @@
 #include <convert_to_biu.h>
 
 
+#ifndef LEGACY_COORDS
+#warning you are not supposed to be here
+#endif
+
+#include "length.h"
+
+
+extern const length legacy_iu;
+
+
 /**
  * Used for holding indeterminate values, such as with multiple selections
  * holding different values or controls which do not wish to set a value.
diff --git a/include/point.h b/include/point.h
index 06e1f9e56..d7bb86abb 100644
--- a/include/point.h
+++ b/include/point.h
@@ -24,12 +24,30 @@
 #include "length.h"
 
 
+#ifdef LEGACY_COORDS
+#include <base_units.h>
+#include <wx/gdicmn.h>
+#endif
+
+
 class point
 {
 public:
     constexpr point() : x(), y() { }
     constexpr point(length nx, length ny) : x(nx), y(ny) { }
 
+#ifdef LEGACY_COORDS
+#ifdef __GNUC__
+    __attribute__((warning("Boundary between old and new coordinate code")))
+#endif
+    constexpr point(wxPoint const &p) : x(p.x * legacy_iu), y(p.y * legacy_iu) { }
+
+#ifdef __GNUC__
+    __attribute__((warning("Boundary between old and new coordinate code")))
+#endif
+    operator wxPoint() const { return wxPoint(x / legacy_iu, y / legacy_iu); }
+#endif
+
     length x, y;
 };
 
@@ -42,5 +60,17 @@ public:
 
     constexpr explicit operator bool() const { return x || y; }
 
+#ifdef LEGACY_COORDS
+#ifdef __GNUC__
+    __attribute__((warning("Boundary between old and new coordinate code")))
+#endif
+    constexpr vector(wxPoint const &p) : x(p.x * legacy_iu), y(p.y * legacy_iu) { }
+
+#ifdef __GNUC__
+    __attribute__((warning("Boundary between old and new coordinate code")))
+#endif
+    operator wxPoint() const { return wxPoint(x / legacy_iu, y / legacy_iu); }
+#endif
+
     length x, y;
 };

References