KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

position.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python3
  2. '''
  3. KLL Position Containers
  4. '''
  5. # Copyright (C) 2016 by Jacob Alexander
  6. #
  7. # This file is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This file is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  19. ### Imports ###
  20. ### Decorators ###
  21. ## Print Decorator Variables
  22. ERROR = '\033[5;1;31mERROR\033[0m:'
  23. WARNING = '\033[5;1;33mWARNING\033[0m:'
  24. ### Classes ###
  25. class Position:
  26. '''
  27. Identifier position
  28. Each position can have up to 6 different types of measurements
  29. Distance:
  30. x
  31. y
  32. z
  33. Angular:
  34. ry
  35. ry
  36. rz
  37. '''
  38. _parameters = [ 'x', 'y', 'z', 'rx', 'ry', 'rz' ]
  39. x = None
  40. y = None
  41. z = None
  42. rx = None
  43. ry = None
  44. rz = None
  45. def __init( self ):
  46. # Set all the _parameters to None
  47. for param in self._parameters:
  48. setattr( self, param, None )
  49. def positionSet( self ):
  50. '''
  51. Returns True if any position has been set
  52. '''
  53. for param in self._parameters:
  54. if getattr( self, param ) is not None:
  55. return True
  56. return False
  57. def setPosition( self, positions ):
  58. '''
  59. Applies given list of position measurements
  60. None signifies an undefined position which may be assigned at a later point.
  61. Otherwise, it will be set to 0 at a later stage
  62. If a position is already set, do not overwrite, expressions are read inside->out
  63. '''
  64. for position in positions:
  65. name = position[0]
  66. value = position[1]
  67. # Check to make sure parameter is valid
  68. if name not in self._parameters:
  69. print( "{0} '{1}' is not a valid position parameter.".format( ERROR, name ) )
  70. continue
  71. # Only set if None
  72. if getattr( self, name ) is None:
  73. setattr( self, name, value )
  74. def strPosition( self ):
  75. '''
  76. __repr__ of Position when multiple inheritance is used
  77. '''
  78. output = ""
  79. # Check each of the position parameters, only show the ones that are not None
  80. count = 0
  81. for param in self._parameters:
  82. value = getattr( self, param )
  83. if value is not None:
  84. if count > 0:
  85. output += ","
  86. output += "{0}:{1}".format( param, value )
  87. count += 1
  88. return output
  89. def __repr__( self ):
  90. return self.strPosition()