def GetElement(self, path): node = self.root for i in path.split('/')[1:]: node = node.GetChild(i) if node is None: raise UMLException("BadPath") return node
def __LoadAppearance(self, root): if root.tagName not in ALL: raise UMLException("XMLError", root.tagName) cls = ALL[root.tagName] params = {} for i in root.attributes.values(): params[str(i.name)] = i.nodeValue obj = cls(**params) for child in root.childNodes: if child.nodeType not in (xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue obj.AppendChild(self.__LoadAppearance(child)) return obj
def __init__(self): self.wTrees = {} if self.glade is not None: self.wTrees[abspath( self.glade)] = self.wTrees[None] = gtk.glade.XML(self.glade) for windowClass in self.windows: if windowClass.glade is None: glade = None else: glade = abspath(windowClass.glade) if glade not in self.wTrees: if glade is None: raise UMLException("ApplicationError") wTree = self.wTrees[glade] = gtk.glade.XML(glade) else: wTree = self.wTrees[glade] self.wins[windowClass.name] = windowClass(self, wTree)
def Fill(self, Element): self.element = Element if Element is None: self.txtNotes.get_buffer().set_text("") self.txtNotes.set_sensitive(False) return attrs = Element.GetObject().GetAttributes() type = Element.GetObject().GetType() cnt = 0 for k in type.GetAttributes(): # attrs.items(): v = attrs[k] atrtype = type.GetAttribute(k) if atrtype[0] == 'note': if cnt > 0: self.element = None raise UMLException("TooMuchNotes") self.txtNotes.get_buffer().set_text(v) self.txtNotes.set_sensitive(True) self.attr = k cnt += 1
def Paint(self, x, y, angle, Connection): if self.possible is False: return rotationMatrix = self.__RotationMatrix(angle) points = [] if self.style in ARROW_TYPES.keys(): for i in ARROW_TYPES[self.style][1]: matrix = self.__MultiplyMatrix(rotationMatrix, i) points.append((int(matrix[0][0] * self.size + x), int(matrix[1][0] * self.size + y))) wgt = Connection.GetDrawingArea().GetDrawable() cmap = wgt.get_colormap() gc = wgt.new_gc() if ARROW_TYPES[self.style][0] == 'polyline': gc.foreground = cmap.alloc_color(self.color) wgt.draw_lines(gc, points) elif ARROW_TYPES[self.style][0] == 'polygon': gc.foreground = cmap.alloc_color(self.fill) wgt.draw_polygon(gc, True, points) gc.foreground = cmap.alloc_color(self.color) wgt.draw_polygon(gc, False, points) elif ARROW_TYPES[self.style][0] == 'fillPolygon': gc.foreground = cmap.alloc_color(self.color) wgt.draw_polygon(gc, True, points) elif ARROW_TYPES[self.style][0] == 'line': if self.style == 'crosscircle': gc.foreground = cmap.alloc_color(self.fill) wgt.draw_arc(gc, True, x - self.size / 2, y - self.size / 2, self.size, self.size, 0, 360 * 64) gc.foreground = cmap.alloc_color(self.color) wgt.draw_arc(gc, False, x - self.size / 2, y - self.size / 2, self.size, self.size, 0, 360 * 64) for i in xrange(0, len(points) - 1, 2): gc.foreground = cmap.alloc_color(self.color) wgt.draw_line(gc, points[i][0], points[i][1], points[i + 1][0], points[i + 1][1]) else: raise UMLException("UndefinedStyleArrow")
def RemoveConnection(self, connection): if connection in self.connections: self.connections.remove else: raise UMLException("ConnectionNotFound")
def AddConnection(self, connection): if connection not in self.connections: self.connections.append(connection) else: raise UMLException("ConnectionAlreadyExists")
def GetDiagram(self, type): if self.types.has_key(type): return self.types[type] else: raise UMLException("KeyError")
def __Load(self, file_path): dom = xml.dom.minidom.parse(file_path) root = dom.documentElement if root.tagName != 'DiagramType': raise UMLException("XMLError") if not root.hasAttribute('id'): raise UMLException("XMLError") if not root.hasAttribute('umlversion'): raise UMLException("XMLError") umlver = root.getAttribute('umlversion') if (umlver != self.umlVersion) and (umlver != '*'): return obj = CDiagramType(root.getAttribute('id')) for i in root.childNodes: if i.nodeType not in (xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue en = i.tagName if en == 'Special': swimlines = False lifelines = False if root.hasAttribute('swimlines'): swimlines = i.getAttribute('swimlines') if root.hasAttribute('lifelines'): lifelines = i.getAttribute('lifelines') obj.SetSpecial(swimlines, lifelines) elif en == 'Elements': for item in i.childNodes: if item.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if item.tagName != 'Item': raise UMLException("XMLError") if not item.hasAttribute('value'): raise UMLException("XMLError") if not item.hasAttribute('umlversion'): raise UMLException("XMLError") value = item.getAttribute('value') umlver = item.getAttribute('umlversion') if (umlver == self.umlVersion) or (umlver == '*'): obj.AppendElement(value) elif en == 'Connections': for item in i.childNodes: if item.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if item.tagName != 'Item': raise UMLException("XMLError") if not item.hasAttribute('value'): raise UMLException("XMLError") if not item.hasAttribute('umlversion'): raise UMLException("XMLError") value = item.getAttribute('value') umlver = item.getAttribute('umlversion') if (umlver == self.umlVersion) or (umlver == '*'): obj.AppendConnection(value) self.types[root.getAttribute('id')] = obj
def RemoveChild(self, child): if child in self.childs: self.childs.remove(child) else: raise UMLException("ChildNotExists")
def RemoveDrawingArea(self, area): if area in self.drawingareas: self.drawingareas.remove(area) else: raise UMLException("AreaNotExists")
def AddDrawingArea(self, area): if area not in self.drawingareas: self.drawingareas.append(area) else: raise UMLException("ExistsArea")
def GetIndexChild(self, index): if index <= len(self.childs) - 1: return self.childs[index] else: raise UMLException("NodeNotExists")
def GetName(self): if 'Name' in self.attribs: return self.attribs['Name'] else: raise UMLException("KeyError")
def AppendChild(self, child): if len(self.GetChilds()) > 0: raise UMLException("SCChildCount") CContainer.AppendChild(self, child)
def AddElement(self, element): if element not in self.elements: self.elements.append(element) self.elementsreverse.insert(0, element) else: raise UMLException("ElementAlreadyExists")
def __Load(self, file_path): dom = xml.dom.minidom.parse(file_path) root = dom.documentElement if root.tagName != 'ConnectionType': raise UMLException("XMLError", root.tagName) if not root.hasAttribute('id'): raise UMLException("XMLError", ('ConnectionType', 'id')) id = root.getAttribute('id') sarr = {} darr = {} ls = {} icon = None labels = [] attrs = [] for i in root.childNodes: if i.nodeType not in (xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue en = i.tagName if en == 'Icon': if not i.hasAttribute('path'): raise UMLException("XMLError", ('Icon', 'path')) icon = pixbuf_new_from_file(i.getAttribute('path')) elif en == 'SrcArrow': if i.hasAttribute('possible'): sarr['possible'] = i.getAttribute('possible') if i.hasAttribute('default'): sarr['default'] = i.getAttribute('default') elif en == 'DestArrow': if i.hasAttribute('possible'): darr['possible'] = i.getAttribute('possible') if i.hasAttribute('default'): darr['default'] = i.getAttribute('default') elif en == 'Attributes': for item in i.childNodes: if item.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if item.tagName != 'Item': raise UMLException("XMLError", item.tagName) if not item.hasAttribute('value'): raise UMLException("XMLError", ('Item', 'value')) value = item.getAttribute('value') if not item.hasAttribute('type'): raise UMLException("XMLError", ('Item', 'type')) type = item.getAttribute('type') propid = None options = [] if item.hasAttribute('propid'): propid = item.getAttribute('propid') if item.hasChildNodes(): options = [] for opt in item.childNodes: if opt.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if opt.tagName != 'Option': raise UMLException("XMLError", opt.tagName) if not opt.hasAttribute('value'): raise UMLException("XMLError", ('Option', 'value')) options.append(opt.getAttribute('value')) attrs.append((value, type, propid, options)) elif en == 'Appearance': for j in i.childNodes: if j.nodeType not in (xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue en = j.tagName if en == 'LineStyle': if j.hasAttribute('color'): ls['color'] = j.getAttribute('color') if j.hasAttribute('style'): ls['style'] = j.getAttribute('style') if j.hasAttribute('width'): ls['width'] = j.getAttribute('width') elif en == 'ArrowStyle': if j.hasAttribute('fill'): darr['fill'] = sarr['fill'] = j.getAttribute( 'fill') if j.hasAttribute('color'): darr['color'] = sarr['color'] = j.getAttribute( 'color') if j.hasAttribute('style'): darr['style'] = sarr['style'] = j.getAttribute( 'style') if j.hasAttribute('size'): darr['size'] = sarr['size'] = j.getAttribute( 'size') elif en == 'Label': if not j.hasAttribute('position'): raise UMLException("XMLError", ('Label', 'position')) tmp = None for k in j.childNodes: if k.nodeType == xml.dom.minidom.Node.ELEMENT_NODE: if tmp is not None: raise UMLException("XMLError", 'Label') tmp = k labels.append((j.getAttribute('position'), self.__LoadAppearance(tmp))) else: raise UMLException('XMLError', en) else: raise UMLException('XMLError', en) tmp = self.types[id] = CConnectionType(id, CConnectionLine(**ls), CConnectionArrow(**sarr), CConnectionArrow(**darr), icon) for pos, lbl in labels: tmp.AddLabel(pos, lbl) for attr in attrs: tmp.AppendAttribute(*attr)
def DeleteElement(self, element): if element in self.elements: self.elements.remove(element) self.elementsreverse.remove(element) else: raise UMLException("ElementDoesNotExists")
def __Load(self, file_path): dom = xml.dom.minidom.parse(file_path) root = dom.documentElement if root.tagName != 'ElementType': raise UMLException("XMLError", root.tagName) if not root.hasAttribute('id'): raise UMLException("XMLError", ('ElementType', 'id')) obj = CElementType(root.getAttribute('id')) for i in root.childNodes: if i.nodeType not in (xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue en = i.tagName if en == 'Icon': if not i.hasAttribute('path'): raise UMLException("XMLError", ('Icon', 'path')) obj.SetIcon(pixbuf_new_from_file(i.getAttribute('path'))) elif en == 'Connections': for item in i.childNodes: if item.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if item.tagName != 'Item': raise UMLException("XMLError", item.tagName) if not item.hasAttribute('value'): raise UMLException("XMLError", ('Item', 'value')) value = item.getAttribute('value') with_what = None allow_recursive = False if item.hasAttribute('with'): with_what = item.getAttribute('with') if item.hasAttribute('allowrecursive'): allow_recursive = item.getAttribute( 'allowrecursive').lower() in ('1', 'true', 'yes') obj.AppendConnection(value, with_what, allow_recursive) elif en == 'Attributes': for item in i.childNodes: if item.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if item.tagName != 'Item': raise UMLException("XMLError", item.tagName) if not item.hasAttribute('value'): raise UMLException("XMLError", ('Item', 'value')) value = item.getAttribute('value') if not item.hasAttribute('type'): raise UMLException("XMLError", ('Item', 'type')) type = item.getAttribute('type') propid = None options = [] if item.hasAttribute('propid'): propid = item.getAttribute('propid') if item.hasChildNodes(): options = [] for opt in item.childNodes: if opt.nodeType not in ( xml.dom.minidom.Node.ELEMENT_NODE, xml.dom.minidom.Node.DOCUMENT_NODE): continue if opt.tagName != 'Option': raise UMLException("XMLError", opt.tagName) if not opt.hasAttribute('value'): raise UMLException("XMLError", ('Option', 'value')) options.append(opt.getAttribute('value')) obj.AppendAttribute(value, type, propid, options) elif en == 'Appearance': tmp = None for j in i.childNodes: if j.nodeType == xml.dom.minidom.Node.ELEMENT_NODE: if tmp is not None: raise UMLException("XMLError", 'Appearance') tmp = j obj.SetAppearance(self.__LoadAppearance(tmp)) else: raise UMLException('XMLError', en) self.types[root.getAttribute('id')] = obj
def DeleteConnection(self, connection): if connection in self.connections: self.connections.remove(connection) else: raise UMLException("ConnectionDoesNotExists")
def RemoveAttribute(self, key): if self.attribs.has_key(key): del self.attribs[key] else: raise UMLException("KeyError")
def AddChild(self, child): if child not in self.childs: self.childs.append(child) child.parent = self else: raise UMLException("ExistsChild")