fixed: compile issue
[opensg.git] / Bindings / Python / helpers / fcd_reflector.py
blobdd9978f844c29f62eb7827c48ea8f7d091490c84
1 # PyOpenSG is (C) Copyright 2005-2009 by Allen Bierbaum
3 # This file is part of PyOpenSG.
5 # PyOpenSG is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option)
8 # any later version.
10 # PyOpenSG is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13 # more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Simple wrapper for FCD XML data in field type
21 import osg2
22 try:
23 import xml.etree.ElementTree as ET
24 except:
25 import elementtree.ElementTree as ET
27 class FcdReflector(object):
28 def __init__(self, fctype, mergeParents=False):
29 """
30 @param mergeParents: If true, merge in the parent's fields.
31 """
32 self.fc_type = fctype
33 xml_data = fctype.getFcdXML()
34 if xml_data and xml_data != "":
35 self.element = ET.fromstring(xml_data)
36 else:
37 self.element = None
39 if self.element and mergeParents:
40 fc_type = fctype.getParent()
41 while fc_type:
42 xml_data = fc_type.getFcdXML()
43 if xml_data and xml_data != "":
44 new_elt = ET.fromstring(xml_data)
45 if new_elt:
46 for n in new_elt:
47 self.element.append(n)
48 fc_type = fc_type.getParent()
51 def hasData(self):
52 """ Return true if we wrap XML data successfully.
53 Note: Some object types may not have an fcd file as a backend so they
54 may return false.
55 """
56 return self.element != None
58 def fields(self):
59 """ return wrappers for all child fields. """
60 if len(self.element) == 0:
61 return []
62 else:
63 return [FieldReflector(f,self) for f in self.element.findall("Field")]
65 def getField(self, name):
66 """ Return a wrapper around the first field named name. """
67 for f in self.element.findall("Field"):
68 if name == f.attrib["name"]:
69 return FieldReflector(f,self)
70 return None
72 def getAttrib(self):
73 return self.element.attrib
74 attrib = property(getAttrib, doc='Return the element.attrib property')
76 def getName(self):
77 return self.element.get("name")
78 def getType(self):
79 return self.element.get("type")
81 def getDocumentation(self):
82 return self.element.text
83 def getCardinality(self):
84 return self.element.get("cardinality")
85 def getVisibility(self):
86 return self.element.get("visibility")
87 def getAccess(self):
88 return self.element.get("access")
91 class FieldReflector(FcdReflector):
92 def __init__(self, fieldElement, parent):
93 self.parent = parent
94 self.element = fieldElement