def check_objecttype_overlap (sheets) : types = dia.registered_types() # remove Standard objects, they do not have or need a sheet del types["Group"] for s in ["Arc", "Box", "BezierLine", "Beziergon", "Ellipse", "Image", "Line", "Outline", "Path", "Polygon", "PolyLine", "Text", "ZigZagLine"] : del types["Standard - %s" % (s,)] # got through all the sheets to match against registered types missing = [] for sheet in sheets : for ot, descr, fname in sheet.objects : if types.has_key (ot.name) : if ot == types[ot.name] : del types[ot.name] else : print "Mix-up:", ot.name else : # sheet referencing a type not available missing.append (ot.name) # from the dictionary removed every type referenced just once? print types
def allprops_cb(data, flags): # copied from otypes.py if data: diagram = None # we may be running w/o GUI else: diagram = dia.new("All Object Properties.dia") data = diagram.data layer = data.active_layer props_by_name = {} otypes = dia.registered_types() name_type_clashes = [] for oname in otypes: try: obj, h1, h2 = dia.get_object_type(oname).create(0, 0) except: print "Huh?", oname continue prop_keys = obj.properties.keys() for k in prop_keys: p = obj.properties[k] if props_by_name.has_key(k): # check if it is the same type p0, names = props_by_name[k] try: if p0.type != p.type: # construct a unique name uname = p.name + "<" + p.type + ">" if props_by_name.has_key(uname): props_by_name[uname][1].append(oname) else: props_by_name[uname] = (p, [oname]) name_type_clashes.append(oname + "::" + p.name + " as " + p0.type + " and " + p.type) else: # remember the origin of the property props_by_name[k][1].append(oname) except KeyError: print oname, "::", k, p, "?" else: props_by_name[k] = (p, [oname]) obj.destroy( ) # unsave delete, any method call will fail/crash afterweards obj = None grid = {} # one type per row dx = 1.0 dy = 5.0 ot = dia.get_object_type("UML - Class") props_keys = props_by_name.keys() # alpha-numeric sorting by type; after by number of users props_keys.sort( lambda a, b: len(props_by_name[b][1]) - len(props_by_name[a][1])) props_keys.sort( lambda a, b: cmp(props_by_name[a][0].type, props_by_name[b][0].type)) almost_all = 98 * len(otypes) / 100 # 98 % for pname in props_keys: p, names = props_by_name[pname] x = 0.0 y = 0.0 if grid.has_key(p.type): x, y = grid[p.type] else: x = 0.0 y = len(grid.keys()) * dy o, h1, h2 = ot.create(x, y) o.properties["name"] = pname o.properties["template"] = 1 o.properties["templates"] = [(p.type, '')] # coloring depending on use if len(names) > almost_all: o.properties["fill_colour"] = "lightgreen" elif len(names) > 100: o.properties["fill_colour"] = "lightblue" elif len(names) > 2: o.properties["fill_colour"] = "lightcyan" elif len(names) > 1: o.properties["fill_colour"] = "lightyellow" # if there is only one user show it if len(names) == 1: o.properties["comment"] = names[0] o.properties["visible_comments"] = 1 o.properties["comment_line_length"] = 60 else: o.properties["comment"] = string.join(names, "; ") o.properties["visible_comments"] = 0 o.properties["comment_line_length"] = 60 # store position for next in row x += (dx + o.properties["elem_width"].value) grid[p.type] = (x, y) layer.add_object(o) layer.update_extents() data.update_extents() if diagram: diagram.display() diagram.flush() if len(name_type_clashes) > 0: dia.message( 0, "One name, one type?!\n" + string.join(name_type_clashes, "\n")) return data
def otypes_cb(data, flags) : if data: diagram = None # we may be running w/o GUI else : diagram = dia.new("Object Types.dia") data = diagram layer = data.active_layer otypes = dia.registered_types() keys = otypes.keys() keys.sort() # property keys w/o overlap object_props = ["obj_pos", "obj_bb", "meta"] element_props = ["elem_corner", "elem_width", "elem_height"] orthconn_props = ["orth_points", "orth_orient", "orth_autoroute"] shape_props = ["flip_horizontal", "flip_vertical"] # the following are not exclusuve to any objects type line_props = ["line_width", "line_style", "line_colour"] fill_props = ["fill_colour", "show_background"] text_props = ["text_colour", "text_font", "text_height", "text"] # "text_alignment", "text_pos" packages = {} for s in keys : kt = string.split(s, " - ") if len(kt) == 2 : if len(kt[0]) == 0 : sp = "<unnamed>" else : sp = kt[0] st = kt[1] else : sp = "<broken>" st = kt[0] if packages.has_key(sp) : packages[sp].append(st) else : packages[sp] = [st] dtp = dia.get_object_type("UML - LargePackage") dtc = dia.get_object_type("UML - Class") cy = 0 maxy = 0 maxx = 0 for sp in packages.keys() : pkg = packages[sp] op, h1, h2 = dtp.create(0.0, cy + 1.0) op.properties["name"] = sp layer.add_object(op) cx = 0 for st in pkg : if st == "Group" : continue # too special to handle oc, h3, h4 = dtc.create(cx + 1.0, cy + 4.0) oc.properties["name"] = st attrs = [] # we detect inheritance by common props n_object = 0 n_element = 0 n_orthconn = 0 n_shape = 0 n_line = 0 n_fill = 0 n_text = 0 if otypes.has_key(st) : o_real, h5, h6 = dia.get_object_type(st).create(0,0) elif otypes.has_key(sp + " - " + st) : o_real, h5, h6 = dia.get_object_type(sp + " - " + st).create(0,0) else : o_real = None print "Failed to create object", sp, st formal_params = [] if not o_real is None : for p in o_real.properties.keys() : if p in object_props : n_object = n_object + 1 elif p in orthconn_props : n_orthconn = n_orthconn + 1 elif p in element_props : n_element = n_element + 1 elif p in shape_props : n_shape = n_shape + 1 elif p in line_props : n_line = n_line + 1 elif p in text_props : n_text = n_text + 1 elif p in fill_props : n_fill = n_fill + 1 else : # don't replicate common props attrs.append((p, o_real.properties[p].type, '', '', 0, 0, 0)) if n_line == len(line_props) : formal_params.append(('Line', '')) else : # need to add the incomplete set for pp in line_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_fill == len(fill_props) : formal_params.append(('Fill', '')) else : for pp in fill_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_text == len(text_props) : formal_params.append(('Text', '')) else : for pp in text_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_orthconn == len(orthconn_props) : oc.properties["stereotype"] = "OrthConn" oc.properties["fill_colour"] = "light blue" elif n_shape == len(shape_props) : oc.properties["stereotype"] = "Shape" oc.properties["fill_colour"] = "light cyan" elif n_element == len(element_props) : oc.properties["stereotype"] = "Element" oc.properties["fill_colour"] = "light yellow" elif n_object == len(object_props) : oc.properties["stereotype"] = "Object" else : print "Huh?", st oc.properties["fill_colour"] = "red" oc.properties["attributes"] = attrs if len(formal_params) > 0 : oc.properties["template"] = 1 oc.properties["templates"] = formal_params layer.add_object(oc) # XXX: there really should be a way to safely delete an object. This one will crash: # - when the object got added somewhere # - any object method gets called afterwards if not o_real is None : o_real.destroy() del o_real cx = oc.bounding_box.right if maxy < oc.bounding_box.bottom : maxy = oc.bounding_box.bottom if maxx < cx : maxx = cx # wrapping too long lines if cx > 300 : cx = 0 cy = maxy h = op.handles[7] # adjust the package size to fit the objects op.move_handle(h,(maxx + 1.0, maxy + 1.0), 0, 0) cy = maxy + 2.0 maxx = 0 # every package a new size data.update_extents() if diagram : diagram.display() diagram.flush() # make it work standalone return data
def aobjects_cb(data, flags): # copied from otypes.py if data: diagram = None # we may be running w/o GUI else: diagram = dia.new("All Objects.dia") data = diagram layer = data.active_layer otypes = dia.registered_types() keys = otypes.keys() keys.sort() packages = {} for s in keys: kt = string.split(s, " - ") if len(kt) == 2: if len(kt[0]) == 0: sp = "<unnamed>" else: sp = kt[0] st = kt[1] else: sp = "<broken>" st = kt[0] if packages.has_key(sp): packages[sp].append(s) else: packages[sp] = [s] for sp in packages.keys(): # add a layer per package layer = data.add_layer(sp) cx = 0.0 cy = 0.0 n = 0 # counting objects my = 0.0 pkg = packages[sp] for st in pkg: if st == "Group": continue # can't create empty group #print st o, h1, h2 = dia.get_object_type(st).create(cx, cy) # to make the resulting diagram more interesting we set every sting property with it's name set_object_string(o) w = o.bounding_box.right - o.bounding_box.left h = o.bounding_box.bottom - o.bounding_box.top o.move(cx, cy) cx += w * 1.5 if h > my: my = h n += 1 if n % 10 == 0: cx = 0.0 cy += my * 1.5 my = 0 layer.add_object(o) layer.update_extents() data.update_extents() if diagram: diagram.display() diagram.flush() return data
def aobjects_cb(data, flags) : # copied from otypes.py if data : diagram = None # we may be running w/o GUI else : diagram = dia.new("All Objects.dia") data = diagram.data layer = data.active_layer otypes = dia.registered_types() keys = otypes.keys() keys.sort() packages = {} for s in keys : kt = string.split(s, " - ") if len(kt) == 2 : if len(kt[0]) == 0 : sp = "<unnamed>" else : sp = kt[0] st = kt[1] else : sp = "<broken>" st = kt[0] if packages.has_key(sp) : packages[sp].append(s) else : packages[sp] = [s] for sp in packages.keys() : # add a layer per package layer = data.add_layer (sp) cx = 0.0 cy = 0.0 n = 0 # counting objects my = 0.0 pkg = packages[sp] for st in pkg : if st == "Group" : continue # can't create empty group #print st o, h1, h2 = dia.get_object_type(st).create (cx, cy) # to make the resulting diagram more interesting we set every sting property with it's name set_object_string (o) w = o.bounding_box.right - o.bounding_box.left h = o.bounding_box.bottom - o.bounding_box.top o.move (cx, cy) cx += w * 1.5 if h > my : my = h n += 1 if n % 10 == 0 : cx = 0.0 cy += my * 1.5 my = 0 layer.add_object (o) layer.update_extents() data.update_extents() if diagram : diagram.display() diagram.flush() return data
def allprops_cb(data, flags) : # copied from otypes.py if data : diagram = None # we may be running w/o GUI else : diagram = dia.new("All Object Properties.dia") data = diagram.data layer = data.active_layer props_by_name = {} otypes = dia.registered_types() name_type_clashes = [] for oname in otypes : try : obj, h1, h2 = dia.get_object_type(oname).create (0, 0) except : print "Huh?", oname continue prop_keys = obj.properties.keys() for k in prop_keys : p = obj.properties[k] if props_by_name.has_key(k) : # check if it is the same type p0, names = props_by_name[k] try : if p0.type != p.type : # construct a unique name uname = p.name + "<" + p.type + ">" if props_by_name.has_key(uname) : props_by_name[uname][1].append(oname) else : props_by_name[uname] = (p, [oname]) name_type_clashes.append (oname + "::" + p.name + " as " + p0.type + " and " + p.type) else : # remember the origin of the property props_by_name[k][1].append(oname) except KeyError : print oname, "::", k, p, "?" else : props_by_name[k] = (p, [oname]) obj.destroy() # unsave delete, any method call will fail/crash afterweards obj = None grid = {} # one type per row dx = 1.0 dy = 5.0 ot = dia.get_object_type("UML - Class") props_keys = props_by_name.keys() # alpha-numeric sorting by type; after by number of users props_keys.sort (lambda a,b : len(props_by_name[b][1]) - len(props_by_name[a][1])) props_keys.sort (lambda a,b : cmp(props_by_name[a][0].type, props_by_name[b][0].type)) almost_all = 98 * len(otypes) / 100 # 98 % for pname in props_keys : p, names = props_by_name[pname] x = 0.0 y = 0.0 if grid.has_key(p.type) : x, y = grid[p.type] else : x = 0.0 y = len(grid.keys()) * dy o, h1, h2 = ot.create (x,y) o.properties["name"] = pname o.properties["template"] = 1 o.properties["templates"] = [(p.type, '')] # coloring depending on use if len(names) > almost_all : o.properties["fill_colour"] = "lightgreen" elif len(names) > 100 : o.properties["fill_colour"] = "lightblue" elif len(names) > 2 : o.properties["fill_colour"] = "lightcyan" elif len(names) > 1 : o.properties["fill_colour"] = "lightyellow" # if there is only one user show it if len(names) == 1 : o.properties["comment"] = names[0] o.properties["visible_comments"] = 1 o.properties["comment_line_length"] = 60 else : o.properties["comment"] = string.join(names, "; ") o.properties["visible_comments"] = 0 o.properties["comment_line_length"] = 60 # store position for next in row x += (dx + o.properties["elem_width"].value) grid[p.type] = (x,y) layer.add_object(o) layer.update_extents() data.update_extents() if diagram : diagram.display() diagram.flush() if len(name_type_clashes) > 0 : dia.message(0, "One name, one type?!\n" + string.join(name_type_clashes, "\n")) return data
def otypes_cb(data, flags) : if data : diagram = None # we may be running w/o GUI else : diagram = dia.new("Object Types.dia") data = diagram.data layer = data.active_layer otypes = dia.registered_types() keys = otypes.keys() keys.sort() # property keys w/o overlap object_props = ["obj_pos", "obj_bb", "meta"] element_props = ["elem_corner", "elem_width", "elem_height"] orthconn_props = ["orth_points", "orth_orient", "orth_autoroute"] shape_props = ["flip_horizontal", "flip_vertical"] # the following are not exclusuve to any objects type line_props = ["line_width", "line_style", "line_colour"] fill_props = ["fill_colour", "show_background"] text_props = ["text_colour", "text_font", "text_height", "text"] # "text_alignment", "text_pos" packages = {} for s in keys : kt = string.split(s, " - ") if len(kt) == 2 : if len(kt[0]) == 0 : sp = "<unnamed>" else : sp = kt[0] st = kt[1] else : sp = "<broken>" st = kt[0] if packages.has_key(sp) : packages[sp].append(st) else : packages[sp] = [st] dtp = dia.get_object_type("UML - LargePackage") dtc = dia.get_object_type("UML - Class") cy = 0 maxy = 0 maxx = 0 for sp in packages.keys() : pkg = packages[sp] op, h1, h2 = dtp.create(0.0, cy + 1.0) op.properties["name"] = sp layer.add_object(op) cx = 0 for st in pkg : if st == "Group" : continue # too special to handle oc, h3, h4 = dtc.create(cx + 1.0, cy + 4.0) oc.properties["name"] = st attrs = [] # we detect inheritance by common props n_object = 0 n_element = 0 n_orthconn = 0 n_shape = 0 n_line = 0 n_fill = 0 n_text = 0 if otypes.has_key(st) : o_real, h5, h6 = dia.get_object_type(st).create(0,0) elif otypes.has_key(sp + " - " + st) : o_real, h5, h6 = dia.get_object_type(sp + " - " + st).create(0,0) else : o_real = None print "Failed to create object", sp, st formal_params = [] if not o_real is None : for p in o_real.properties.keys() : if p in object_props : n_object = n_object + 1 elif p in orthconn_props : n_orthconn = n_orthconn + 1 elif p in element_props : n_element = n_element + 1 elif p in shape_props : n_shape = n_shape + 1 elif p in line_props : n_line = n_line + 1 elif p in text_props : n_text = n_text + 1 elif p in fill_props : n_fill = n_fill + 1 else : # don't replicate common props attrs.append((p, o_real.properties[p].type, '', '', 0, 0, 0)) if n_line == len(line_props) : formal_params.append(('Line', '')) else : # need to add the incomplete set for pp in line_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_fill == len(fill_props) : formal_params.append(('Fill', '')) else : for pp in fill_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_text == len(text_props) : formal_params.append(('Text', '')) else : for pp in text_props : if o_real.properties.has_key(pp) : attrs.append((pp, o_real.properties[pp].type, '', '', 0, 0, 0)) if n_orthconn == len(orthconn_props) : oc.properties["stereotype"] = "OrthConn" oc.properties["fill_colour"] = "light blue" elif n_shape == len(shape_props) : oc.properties["stereotype"] = "Shape" oc.properties["fill_colour"] = "light cyan" elif n_element == len(element_props) : oc.properties["stereotype"] = "Element" oc.properties["fill_colour"] = "light yellow" elif n_object == len(object_props) : oc.properties["stereotype"] = "Object" else : print "Huh?", st oc.properties["fill_colour"] = "red" oc.properties["attributes"] = attrs if len(formal_params) > 0 : oc.properties["template"] = 1 oc.properties["templates"] = formal_params layer.add_object(oc) # XXX: there really should be a way to safely delete an object. This one will crash: # - when the object got added somewhere # - any object method gets called afterwards if not o_real is None : o_real.destroy() del o_real cx = oc.bounding_box.right if maxy < oc.bounding_box.bottom : maxy = oc.bounding_box.bottom if maxx < cx : maxx = cx # wrapping too long lines if cx > 300 : cx = 0 cy = maxy h = op.handles[7] # adjust the package size to fit the objects op.move_handle(h,(maxx + 1.0, maxy + 1.0), 0, 0) cy = maxy + 2.0 maxx = 0 # every package a new size data.update_extents() if diagram : diagram.display() diagram.flush() # make it work standalone return data