location.py
Go to the documentation of this file.
1 # -*- Python -*-
2 # -*- coding: utf-8 -*-
3 
4 '''rtsprofile
5 
6 Copyright (C) 2009-2010
7  Geoffrey Biggs
8  RT-Synthesis Research Group
9  Intelligent Systems Research Institute,
10  National Institute of Advanced Industrial Science and Technology (AIST),
11  Japan
12  All rights reserved.
13 Licensed under the Eclipse Public License -v 1.0 (EPL)
14 http://www.opensource.org/licenses/eclipse-1.0.txt
15 
16 File: direction.py
17 
18 Location object storing the position of components in a graphical view.
19 
20 '''
21 
22 __version__ = '$Revision: $'
23 # $Source$
24 
25 
26 from rtsprofile import RTS_EXT_NS, RTS_EXT_NS_S
27 from rtsprofile import direction as dir
28 from rtsprofile.utils import validate_attribute
29 
30 
31 ##############################################################################
32 ## Location object
33 
34 class Location(object):
35  '''Stores the location of a component in a graphical view.'''
36 
37  def __init__(self, x=0, y=0, height=0, width=0, direction=dir.DOWN):
38  '''Constructor.
39 
40  @param x X position of the top-left of the component.
41  @type x int
42  @param y Y position of the top-left of the component.
43  @type y int
44  @param height Height of the component.
45  @type height int
46  @param width Width of the component.
47  @type width int
48  @param direction Direction the component faces.
49  @type direction direction.const_type
50 
51  '''
52  validate_attribute(x, 'Location.x',
53  expected_type=int, required=False)
54  self._x = x
55  validate_attribute(y, 'Location.y',
56  expected_type=int, required=False)
57  self._y = y
58  validate_attribute(height, 'Location.height',
59  expected_type=int, required=False)
60  self._height = height
61  validate_attribute(width, 'Location.width',
62  expected_type=int, required=False)
63  self._width = width
64  validate_attribute(direction, 'Location.direction',
65  expected_type=dir.const_type, required=False)
66  self._direction = direction
67 
68  def __str__(self):
69  return 'Position: {0}, {1}\nSize: {2}x{3}\nDirection: {4}'.format(\
70  self.x, self.y, self.width, self.height,
71  dir.to_string(self.direction))
72 
73  @property
74  def x(self):
75  '''The X position of the component in a graphical tool.'''
76  return self._x
77 
78  @x.setter
79  def x(self, x):
80  validate_attribute(x, 'Location.x',
81  expected_type=int, required=False)
82  self._x = x
83 
84  @property
85  def y(self):
86  '''The Y position of the component in a graphical tool.'''
87  return self._y
88 
89  @y.setter
90  def y(self, y):
91  validate_attribute(y, 'Location.y',
92  expected_type=int, required=False)
93  self._y = y
94 
95  @property
96  def height(self):
97  '''The height of the component in a graphical tool.'''
98  return self._height
99 
100  @height.setter
101  def height(self, height):
102  validate_attribute(height, 'Location.height',
103  expected_type=int, required=False)
104  self._height = height
105 
106  @property
107  def width(self):
108  '''The width of the component in a graphical tool.
109 
110  A value of -1 for this property indicates that the width should be as
111  wide as is necessary.
112 
113  '''
114  return self._width
115 
116  @width.setter
117  def width(self, width):
118  validate_attribute(width, 'Location.width',
119  expected_type=int, required=False)
120  self._width = width
121 
122  @property
123  def direction(self):
124  '''The direction of the component in a graphical tool.
125 
126  A value of -1 for this property indicates that the height should be as
127  wide as is necessary.
128 
129  '''
130  return self._direction
131 
132  @direction.setter
133  def direction(self, direction):
134  validate_attribute(direction, 'Location.direction',
135  expected_type=dir.const_type, required=False)
136  self._direction = direction
137 
138  def parse_xml_node(self, node):
139  '''Parse an xml.dom Node object representing a location into this
140  object.
141 
142  '''
143  self.x = int(node.getAttributeNS(RTS_EXT_NS, 'x'))
144  self.y = int(node.getAttributeNS(RTS_EXT_NS, 'y'))
145  self.height = int(node.getAttributeNS(RTS_EXT_NS, 'height'))
146  self.width = int(node.getAttributeNS(RTS_EXT_NS, 'width'))
147  self.direction = dir.from_string(node.getAttributeNS(RTS_EXT_NS,
148  'direction'))
149  return self
150 
151  def parse_yaml(self, y):
152  '''Parse a YAML specification of a location into this object.'''
153  self.x = int(y['x'])
154  self.y = int(y['y'])
155  self.height = int(y['height'])
156  self.width = int(y['width'])
157  self.direction = dir.from_string(y['direction'])
158  return self
159 
160  def save_xml(self, doc, element):
161  '''Save this location into an xml.dom.Element object.'''
162  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'x', str(self.x))
163  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'y', str(self.y))
164  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'height',
165  str(self.height))
166  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'width',
167  str(self.width))
168  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'direction',
169  dir.to_string(self.direction))
170 
171  def to_dict(self):
172  '''Save this location into a dictionary.'''
173  return {'x': self.x,
174  'y': self.y,
175  'height': self.height,
176  'width': self.width,
177  'direction': dir.to_string(self.direction)}
178 
179 
180 # vim: tw=79
181 
def parse_xml_node(self, node)
Definition: location.py:138
def validate_attribute(attr, name, expected_type=None, required=False)
Definition: utils.py:92
def save_xml(self, doc, element)
Definition: location.py:160
def __init__(self, x=0, y=0, height=0, width=0, direction=dir.DOWN)
Definition: location.py:37
Location object.
Definition: location.py:34


rtsprofile
Author(s): Geoffrey Biggs
autogenerated on Fri Jun 7 2019 21:52:35