Go to the documentation of this file.00001
00002
00003
00004 '''rtsprofile
00005
00006 Copyright (C) 2009-2010
00007 Geoffrey Biggs
00008 RT-Synthesis Research Group
00009 Intelligent Systems Research Institute,
00010 National Institute of Advanced Industrial Science and Technology (AIST),
00011 Japan
00012 All rights reserved.
00013 Licensed under the Eclipse Public License -v 1.0 (EPL)
00014 http://www.opensource.org/licenses/eclipse-1.0.txt
00015
00016 File: direction.py
00017
00018 Enumeration for directions.
00019
00020 This module stores the possible types of component direction.
00021
00022 Valid types are UP, DOWN, LEFT, RIGHT.
00023
00024 '''
00025
00026 __version__ = '$Revision: $'
00027
00028
00029
00030 from rtsprofile.exceptions import InvalidDirectionError
00031
00032
00033 UP = 'UP'
00034 DOWN = 'DOWN'
00035 LEFT = 'LEFT'
00036 RIGHT = 'RIGHT'
00037
00038
00039
00040 const_type = str
00041
00042
00043 def from_string(dir_string):
00044 '''Returns the correct constant for a given string.
00045
00046 @raises InvalidDirectionError
00047
00048 '''
00049 dir_string = dir_string.upper()
00050 if dir_string == UP:
00051 return UP
00052 elif dir_string == DOWN:
00053 return DOWN
00054 elif dir_string == LEFT:
00055 return LEFT
00056 elif dir_string == RIGHT:
00057 return RIGHT
00058 else:
00059 raise InvalidDirectionError(dir_string)
00060
00061
00062 def to_string(direction):
00063 '''Returns the correct string for a given direction.
00064
00065 @raises InvalidDirectionError
00066
00067 '''
00068 if direction == UP:
00069 return UP
00070 elif direction == DOWN:
00071 return DOWN
00072 elif direction == LEFT:
00073 return LEFT
00074 elif direction == RIGHT:
00075 return RIGHT
00076 else:
00077 raise InvalidDirectionError(type_string)
00078
00079
00080
00081