units.i 2.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file units.i
 * @brief unit conversion code
 */

30
// Unit conversion, between internal units and mm or mils
31

32
%pythoncode
33
{
34
   def ToMM(iu):
35
      if type(iu) in [int,float]:
36
         return float(iu) / float(IU_PER_MM)
37
      elif type(iu) in [wxPoint,wxSize]:
38
         return tuple(map(ToMM,iu))
39 40

   def FromMM(mm):
41 42 43 44
      if type(mm) in [int,float]:
         return int(float(mm) * float(IU_PER_MM))
      elif type(mm) in [wxPoint,wxSize]:
        return tuple(map(FromMM,mm))
45 46

   def ToMils(iu):
47
      if type(iu) in [int,float]:
48
        return float(iu) / float(IU_PER_MILS)
49
      elif type(iu) in [wxPoint,wxSize]:
50
        return tuple(map(ToMils,iu))
51 52

   def FromMils(mils):
53 54 55
      if type(mils) in [int,float]:
         return int(float(mils)*float(IU_PER_MILS))
      elif type(mils) in [wxPoint,wxSize]:
56
        return tuple(map(FromMils,mils))
57

58 59
   def wxSizeMM(mmx,mmy): return wxSize(FromMM(mmx),FromMM(mmy))
   def wxSizeMils(mmx,mmy): return wxSize(FromMils(mmx),FromMils(mmy))
60

61 62
   def wxPointMM(mmx,mmy): return wxPoint(FromMM(mmx),FromMM(mmy))
   def wxPointMils(mmx,mmy): return wxPoint(FromMils(mmx),FromMils(mmy))
63

64
   def wxRectMM(x,y,wx,wy):
65 66 67 68 69
        x = int(FromMM(x))
        y = int(FromMM(y))
        wx = int(FromMM(wx))
        wy = int (FromMM(wy))
        return wxRect(x,y,wx,wy)
70

71
   def wxRectMils(x,y,wx,wy):
72 73 74 75 76
        x = int(FromMils(x))
        y = int(FromMils(y))
        wx = int(FromMils(wx))
        wy = int (FromMils(wy))
        return wxRect(x,y,wx,wy)
77

78
}