def draw_element(self,
                     x,
                     y,
                     sizex,
                     sizey,
                     shape,
                     properties,
                     default=None):
        shape = {'shape - page': 'shape - notebook_path'}.get(shape, shape)
        if type(default) == type(1) and shape == 'shape - boolean':
            shape = 'shape - boolean_on'
        if shape:
            oType = dia.get_object_type(shape)
            o, h1, h2 = oType.create(0, 0)
            if ('elem_width' and 'elem_height') in o.properties.keys():
                o.properties['elem_width'] = sizex
                o.properties['elem_height'] = sizey
            for k, v in properties.items():
                o.properties[k] = v
            o.move(x, y)
            self.data.active_layer.add_object(o)

        if default and type(default) != type(1):
            oType = dia.get_object_type('Standard - Text')
            o, h1, h2 = oType.create(x + 0.25, y + 1.25)
            o.properties['text'] = str(default)
            self.data.active_layer.add_object(o)
예제 #2
0
	def import_classes (classes, diagramData) :
		class_map = {}
		layer = diagramData.active_layer
		# create the classes
		for c in classes :
			o, h1, h2 = dia.get_object_type("UML - Class").create(0,0)
			# origin and dia object mapped by id
			class_map[c.id] = (c, o)
			# set some properties
			o.properties["name"] = str(c.name)
			o.properties["abstract"] = c.IsAbstract ()
			try :
				o.properties["operations"] = c.GetMethods()
			except TypeError as msg :
				print("Failed assigning 'operations':", msg, c.GetMethods())
			o.properties["attributes"] = c.GetAttributes()

			layer.add_object(o)
		# create the links (inhertiance, maybe containement, refernces, factory, ...)
		for s in list(class_map.keys ()) :
			c, o = class_map[s]
			print(s, c, c.bases)
			for b in c.bases :
				if b in class_map :
					k, p = class_map[b]
					print(c.id, "->", k.id)
					con, h1, h2 = dia.get_object_type("UML - Generalization").create(0,0)
					layer.add_object (con)
					h1.connect (p.connections[6])
					h2.connect (o.connections[1])
		# ... and move appropriately

		# update placement depending on number of parents ?
		layer.update_extents()
예제 #3
0
def ImportFile (filename, diagramData) :
    """ read the dot file and create diagram objects """
    layer = diagramData.active_layer # can do better, e.g. layer per graph
    nodeType = dia.get_object_type('Flowchart - Box')

    x = 0
    structs = parse_file(filename)
    oType = dia.get_object_type ("UML - Class")
    for [name, fields, methods] in structs:
        x += 10
        obj, h1, h2 = oType.create (x,0) # p.x, p.y
        obj.properties["name"] = name

        dia_fields = []
        dia_methods = []
        for f in fields:
            #print f
            dia_fields.append((f[1],f[0],'','doc',0,0,0))
        for m in methods:
            #print m
            dia_methods.append((m[1],m[0],'doc','',0,0,0,0,()))
        obj.properties["operations"] = dia_methods
        obj.properties["attributes"] = dia_fields
        layer.add_object(obj)
    if diagramData :
        diagramData.update_extents()
예제 #4
0
def SimpleRotate(data, angle) :
	# Rotation center
	xm = 0.0
	ym = 0.0

	# Convert to radians
	angle_rad = 2*math.pi - 2*math.pi*angle/360

	objs = data.get_sorted_selected()
	if len(objs) == 0 :
		objs = data.active_layer.objects
	scaleFailed = {}
	ptype = dia.get_object_type('Standard - Polygon')
	for o in objs :
		if o.type.name == 'Standard - Box' :
			r = o.properties['obj_bb'].value
			p = ptype.create(0,0)
			p = p[0]
			p.properties['poly_points'] = [(r.left, r.top), (r.right, r.top), (r.right, r.bottom), (r.left, r.bottom)]
			p.properties['line_width'] = o.properties['line_width']
			p.properties['line_colour'] = o.properties['line_colour']
			p.properties['line_style'] = o.properties['line_style']
			p.properties['line_colour'] = o.properties['line_colour']
			p.properties['fill_colour'] = o.properties['fill_colour']
			p.properties['show_background'] = o.properties['show_background']
			data.active_layer.add_object(p)
			data.active_layer.remove_object(o)
			o = p
		for h in o.handles:
			x = math.cos(angle_rad)*(h.pos.x+xm)-math.sin(angle_rad)*(h.pos.y+ym)
			y = math.sin(angle_rad)*(h.pos.x+xm)+math.cos(angle_rad)*(h.pos.y)
			o.move_handle(h, (x,y), 0, 0)

	data.update_extents ()
	dia.active_display().add_update_all()
예제 #5
0
def SimpleRotate(data, angle) :
	# Rotation center
	xm = 0.0
	ym = 0.0

	# Convert to radians
	angle_rad = 2*math.pi - 2*math.pi*angle/360

	objs = data.get_sorted_selected()
	if len(objs) == 0 :
		objs = data.active_layer.objects
	scaleFailed = {}
	ptype = dia.get_object_type('Standard - Polygon')
	for o in objs :
		if o.type.name == 'Standard - Box' :			
			r = o.properties['obj_bb'].value
			p = ptype.create(0,0)
			p = p[0]
			p.properties['poly_points'] = [(r.left, r.top), (r.right, r.top), (r.right, r.bottom), (r.left, r.bottom)]
			p.properties['line_width'] = o.properties['line_width']
			p.properties['line_colour'] = o.properties['line_colour']
			p.properties['line_style'] = o.properties['line_style']
			p.properties['line_colour'] = o.properties['line_colour']
			p.properties['fill_colour'] = o.properties['fill_colour']
			p.properties['show_background'] = o.properties['show_background']
			data.active_layer.add_object(p)
			data.active_layer.remove_object(o)
			o = p
		for h in o.handles:
			x = math.cos(angle_rad)*(h.pos.x+xm)-math.sin(angle_rad)*(h.pos.y+ym)
			y = math.sin(angle_rad)*(h.pos.x+xm)+math.cos(angle_rad)*(h.pos.y)
			o.move_handle(h, (x,y), 0, 0)
					
	data.update_extents ()
	dia.active_display().add_update_all()
예제 #6
0
def create_stub_class(name, layer):
    o, _, _ = dia.get_object_type("UML - Class").create(0,0)
    o.properties["name"] = fix_kerning(name)
    if any(x in name for x in ["<T", "<S", "<ID", "<U", "<V"]):
        o.properties["stereotype"] = "generic"
    o.properties["fill_colour"] = default_color
    layer.add_object(o)
    return o
예제 #7
0
def newAssociation(oName, data ) :

    oType = dia.get_object_type("UML - Association")        
    layer = data.active_layer
    
    o, h1, h2 = oType.create (0,0) # p.x, p.y
    layer.add_object (o)
    o.properties["name"] = oName 

    return o 
예제 #8
0
 def loaddB(self, fil_path, dia_obj_filpath, load_all):
     used_ind = []
     f = open(fil_path, "r")
     csvreader = csv.reader(f)
     for row in csvreader:
         if row:
             used_ind.append(int(row[0]))
             shrt_path = os.path.realpath(row[2])
             spl = shrt_path.split(self.Seperator)
             s = self.Seperator
             shrt_path = s.join(spl[(len(spl) - 2):(len(spl))])
             set_already = False
             for ind in range(0, len(dia_obj_filpath)):
                 if shrt_path == dia_obj_filpath[ind]:
                     row_num = self.Add_row()
                     self.applist[row_num].Index = str(row[0])
                     self.applist[row_num].entered_val = str(row[1])
                     self.applist[row_num].entry.set_text(str(row[1]))
                     self.applist[row_num].image_loc = os.path.realpath(
                         row[2])
                     self.applist[row_num].update_image()
                     self.applist[row_num].dia_object = self.obj_list.pop(
                         ind)
                     del dia_obj_filpath[ind]
                     set_already = True
                     break
             if not set_already:
                 if load_all:
                     row_num = self.Add_row()
                     self.applist[row_num].Index = str(row[0])
                     self.applist[row_num].entered_val = str(row[1])
                     self.applist[row_num].entry.set_text(str(row[1]))
                     self.applist[row_num].image_loc = os.path.realpath(
                         row[2])
                     self.applist[row_num].update_image()
                     #Need to write code to create image in dia
                     ot = dia.get_object_type("Standard - Image")
                     o, h1, h2 = ot.create(0, 0)
                     o.properties['image_file'] = os.path.realpath(row[2])
                     layer = self.data.active_layer
                     layer.add_object(o)
                     layer.update_extents()
                     self.data.update_extents()
                     self.applist[row_num].dia_object = o
                 else:
                     self.no_apps_nl = self.no_apps_nl + 1
                     self.not_loaded = self.not_loaded + [row]
     f.close()
     if used_ind:
         all_ind = range(1, max(used_ind) + 1)
         self.unused_ind = [x for x in all_ind if x not in used_ind]
     savedB(self.db_fil, self.applist, self.not_loaded)
예제 #9
0
파일: bbox.py 프로젝트: AmiGanguli/dia
def annotate_cb (data, flags) :

	layer = data.active_layer
	dest = data.add_layer ("Annotated '%s' (%s)" % (layer.name, sys.platform), -1)
	ann_type = dia.get_object_type ("Standard - Text")

	for o in layer.objects :
		bb = o.bounding_box
		a, h1, h2 = ann_type.create (bb.right, bb.top)
		
		a.properties["text"] = "h: %g w: %g" % (bb.bottom - bb.top, bb.right - bb.left)

		dest.add_object (a)
 def draw_element(self, x,y, sizex, sizey, shape, properties, default = None):
     shape = {
         'shape - page': 'shape - notebook_path'
     }.get(shape, shape)
     if type(default) == type(1) and shape == 'shape - boolean':
         shape = 'shape - boolean_on'
     if shape:
         oType = dia.get_object_type (shape)
         o, h1, h2 = oType.create(0,0)
         if ('elem_width'  and 'elem_height' ) in o.properties.keys():
             o.properties['elem_width'] = sizex
             o.properties['elem_height'] = sizey
         for k,v in properties.items():
                 o.properties[k] = v
         o.move(x,y)
         self.data.active_layer.add_object(o)
         
     if default and type(default) != type(1):
         oType = dia.get_object_type ('Standard - Text')
         o, h1, h2 = oType.create(x+0.25,y+1.25)
         o.properties['text'] = str(default)
         self.data.active_layer.add_object(o)
예제 #11
0
파일: bbox.py 프로젝트: AmiGanguli/dia
def bbox_cb (data, flags) :

	layer = data.active_layer
	dest = data.add_layer ("BBox of '%s' (%s)" % (layer.name, sys.platform), -1)
	box_type = dia.get_object_type ("Standard - Box")

	for o in layer.objects :
		bb = o.bounding_box
		b, h1, h2 = box_type.create (bb.left, bb.top)
		b.move_handle (b.handles[7], (bb.right, bb.bottom), 0, 0)
		b.properties["show_background"] = 0
		b.properties["line_width"] = 0
		b.properties["line_colour"] = 'red'
		dest.add_object (b)
예제 #12
0
파일: bbox.py 프로젝트: linuxmaniajp/monpe
def bbox_cb(data, flags):

    layer = data.active_layer
    dest = data.add_layer("BBox of '%s' (%s)" % (layer.name, sys.platform), -1)
    box_type = dia.get_object_type("Standard - Box")

    for o in layer.objects:
        bb = o.bounding_box
        b, h1, h2 = box_type.create(bb.left, bb.top)
        b.move_handle(b.handles[7], (bb.right, bb.bottom), 0, 0)
        b.properties["show_background"] = 0
        b.properties["line_width"] = 0
        b.properties["line_colour"] = 'red'
        dest.add_object(b)
예제 #13
0
def genObjects():
    # usualyrly alyr is 'Background' on empty diagram
    alyr = dia.active_display().diagram.data.active_layer
    print alyr, dir(alyr)
    obj, h1, h2 = dia.get_object_type("Standard - Polygon").create(10.0, 10.0)
    w = obj.bounding_box.right - obj.bounding_box.left
    h = obj.bounding_box.bottom - obj.bounding_box.top
    obj.move(w, h)

    alyr.add_object(obj)
    alyr.update_extents()

    obj2, h1, h2 = dia.get_object_type("Standard - Line").create(
        4.0, 1.0
    )  # x,y - arrow seems always to be sqrt(2) long, at 45 degrees angle, when generated like this
    applyStyle(obj2, lpaStyle)

    alyr.add_object(obj2)
    alyr.update_extents()

    obj3a = dia.get_object_type("Standard - Text").create(8.0, 1.0)
    alyr.add_object(obj3a)
    alyr.update_extents()
예제 #14
0
파일: bbox.py 프로젝트: linuxmaniajp/monpe
def annotate_cb(data, flags):

    layer = data.active_layer
    dest = data.add_layer("Annotated '%s' (%s)" % (layer.name, sys.platform),
                          -1)
    ann_type = dia.get_object_type("Standard - Text")

    for o in layer.objects:
        bb = o.bounding_box
        a, h1, h2 = ann_type.create(bb.right, bb.top)

        a.properties["text"] = "h: %g w: %g" % (bb.bottom - bb.top,
                                                bb.right - bb.left)

        dest.add_object(a)
예제 #15
0
 def Create(self):
     ot = dia.get_object_type(self.dt)
     o, h1, h2 = ot.create(self.props["x"], self.props["y"])
     # apply common props
     if self.props.has_key("stroke-width") and o.properties.has_key(
             "line_width"):
         o.properties["line_width"] = self.props["stroke-width"]
     if self.props.has_key("stroke") and o.properties.has_key(
             "line_colour"):
         if self.props["stroke"] != "none":
             try:
                 o.properties["line_colour"] = Color(self.props["stroke"])
             except:
                 # rgb(192,27,38) handled by Color() but ...
                 # o.properties["line_colour"] = self.props["stroke"]
                 pass
         else:
             # Dia can't really display stroke none, some workaround :
             if self.props.has_key("fill") and self.props["fill"] != "none":
                 #does it really matter ?
                 try:
                     o.properties["line_colour"] = Color(self.props["fill"])
                 except:
                     pass
             o.properties["line_width"] = 0.0
     if self.props.has_key("fill") and o.properties.has_key("fill_colour"):
         if self.props["fill"] == "none":
             o.properties["show_background"] = 0
         else:
             color_key = "fill_colour"
             try:
                 o.properties["show_background"] = 1
             except KeyError:
                 # not sure if this is always true
                 color_key = "text_colour"
             try:
                 o.properties[color_key] = Color(self.props["fill"])
             except:
                 # rgb(192,27,38) handled by Color() but ...
                 # o.properties["fill_colour"] =self.props["fill"]
                 pass
     if self.props.has_key("line-style") and o.properties.has_key(
             "line_style"):
         o.properties["line_style"] = self.props["line-style"]
     if self.props.has_key("meta") and o.properties.has_key("meta"):
         o.properties["meta"] = self.props["meta"]
     self.ApplyProps(o)
     return o
예제 #16
0
파일: mark-cps.py 프로젝트: AmiGanguli/dia
def mark_cps (data, flags) :
	objs = data.get_sorted_selected()
	layer = data.active_layer
	if len(objs) == 0 :
		dia.message (1, "Select objects for marking it's connection points!")
		return
	textType = dia.get_object_type("Standard - Text")
	for o in objs:
		for i in range(0, len(o.connections)):
			cp = o.connections[i]
			t, h1, h2 = textType.create (cp.pos.x, cp.pos.y)
			t.properties["text"] = str(i)
			# align the text based on the given directions
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_vert_alignment"] = 3 # first line
			if cp.directions & 0x1: # north
				t.properties["text_vert_alignment"] = 1 # bottom
			elif cp.directions & 0x4: # south
				t.properties["text_vert_alignment"] = 0 # top
			else :
				t.properties["text_vert_alignment"] = 2 # center
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_alignment"] = 1 # middle
			elif cp.directions & 0x2: # east
				t.properties["text_alignment"] = 0 # left
			elif cp.directions & 0x8: # west
				t.properties["text_alignment"] = 2 # right
			else :
				t.properties["text_alignment"] = 1 # middle
			# tint it with the connection point color
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_colour"] = "red"
			elif cp.directions == 0 : # not necessarily a bug
				t.properties["text_colour"] = "green"
			else :
				t.properties["text_colour"] = "blue"
			# add it to the diagram
			layer.add_object(t)
			# connect the object with the cp at hand
			h2.connect(cp)
		# update the object and it's connected?
	data.update_extents ()
	adisp = dia.active_display()
	if adisp :
		adisp.diagram.update_extents()
		adisp.diagram.flush()
예제 #17
0
def mark_cps (data, flags) :
	objs = data.get_sorted_selected()
	layer = data.active_layer
	if len(objs) == 0 :
		dia.message (1, "Select objects for marking it's connection points!")
		return
	textType = dia.get_object_type("Standard - Text")
	for o in objs:
		for i in range(0, len(o.connections)):
			cp = o.connections[i]
			t, h1, h2 = textType.create (cp.pos.x, cp.pos.y)
			t.properties["text"] = str(i)
			# align the text based on the given directions
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_vert_alignment"] = 3 # first line
			if cp.directions & 0x1: # north
				t.properties["text_vert_alignment"] = 1 # bottom
			elif cp.directions & 0x4: # south
				t.properties["text_vert_alignment"] = 0 # top
			else :
				t.properties["text_vert_alignment"] = 2 # center
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_alignment"] = 1 # middle
			elif cp.directions & 0x2: # east
				t.properties["text_alignment"] = 0 # left
			elif cp.directions & 0x8: # west
				t.properties["text_alignment"] = 2 # right
			else :
				t.properties["text_alignment"] = 1 # middle
			# tint it with the connection point color
			if cp.flags & 0x3 : #CP_FLAGS_MAIN
				t.properties["text_colour"] = "red"
			elif cp.directions == 0 : # not necessarily a bug
				t.properties["text_colour"] = "green"
			else :
				t.properties["text_colour"] = "blue"
			# add it to the diagram
			layer.add_object(t)
			# connect the object with the cp at hand
			h2.connect(cp)
		# update the object and it's connected?
	data.update_extents ()
	adisp = dia.active_display()
	if adisp :
		adisp.diagram.update_extents()
		adisp.diagram.flush()
예제 #18
0
	def Create(self) :
		ot = dia.get_object_type (self.dt)
		o, h1, h2 = ot.create(self.props["x"], self.props["y"])
		# apply common props
		if self.props.has_key("stroke-width") and o.properties.has_key("line_width") :
			o.properties["line_width"] = self.props["stroke-width"]
		if self.props.has_key("stroke") and o.properties.has_key("line_colour") :
			if self.props["stroke"] != "none" :
				try :
					o.properties["line_colour"] = Color(self.props["stroke"])
				except :
					# rgb(192,27,38) handled by Color() but ...
					# o.properties["line_colour"] = self.props["stroke"]
					pass
			else :
				# Dia can't really display stroke none, some workaround :
				if self.props.has_key("fill") and self.props["fill"] != "none" : 
					#does it really matter ?
					try :
						o.properties["line_colour"] = Color(self.props["fill"])
					except :
						pass
				o.properties["line_width"] = 0.0
		if self.props.has_key("fill") and o.properties.has_key("fill_colour") :
			if self.props["fill"] == "none" :
				o.properties["show_background"] = 0
			else :
				color_key = "fill_colour"
				try :
					o.properties["show_background"] = 1
				except KeyError :
					# not sure if this is always true
					color_key = "text_colour"
				try :
					o.properties[color_key] =Color(self.props["fill"])
				except :
					# rgb(192,27,38) handled by Color() but ...
					# o.properties["fill_colour"] =self.props["fill"]
					pass
		if self.props.has_key("line-style") and o.properties.has_key("line_style") :
			o.properties["line_style"] = self.props["line-style"]
		if self.props.has_key("meta") and o.properties.has_key("meta") :
			o.properties["meta"] = self.props["meta"]
		self.ApplyProps(o)
		return o
예제 #19
0
    def _add_view(self, view, x, y, schema_prefix=False):
        dia_table, h1, h2 = (dia.get_object_type("Database - Table")
                                .create(x, y))

        dia_table.properties['name'] = (schema_prefix and
                                        "{0}.{1}".format(view.schema.name,
                                                         view.name)
                                        or view.name)

        dia_table.properties['attributes'] = tuple(
            [attribute(name=c.name, ftype=c.data_type, nullable=False)
             for c in view.columns]
        )

        dia_table.properties['comment'] = 'view'
        dia_table.properties['visible_comment'] = True
        self.dia_layer.add_object(dia_table)
        return dia_table
예제 #20
0
    def import_classes(classes, diagramData):
        class_map = {}
        layer = diagramData.active_layer
        # create the classes
        for c in classes:
            o, h1, h2 = dia.get_object_type("UML - Class").create(0, 0)
            # origin and dia object mapped by id
            class_map[c.id] = (c, o)
            # set some properties
            o.properties["name"] = str(c.name)
            o.properties["abstract"] = c.IsAbstract()
            try:
                o.properties["operations"] = c.GetMethods()
            except TypeError, msg:
                print "Failed assigning 'operations':", msg, c.GetMethods()
            o.properties["attributes"] = c.GetAttributes()

            layer.add_object(o)
예제 #21
0
파일: doxrev.py 프로젝트: AmiGanguli/dia
	def import_classes (classes, diagramData) :
		class_map = {}
		layer = diagramData.active_layer
		# create the classes
		for c in classes :
			o, h1, h2 = dia.get_object_type("UML - Class").create(0,0)
			# origin and dia object mapped by id
			class_map[c.id] = (c, o)
			# set some properties 
			o.properties["name"] = str(c.name)
			o.properties["abstract"] = c.IsAbstract ()
			try :
				o.properties["operations"] = c.GetMethods()
			except TypeError, msg :
				print "Failed assigning 'operations':", msg, c.GetMethods()
			o.properties["attributes"] = c.GetAttributes()

			layer.add_object(o)
예제 #22
0
    def _add_table(self, table, x, y, schema_prefix=False):
        dia_table, h1, h2 = (dia.get_object_type("Database - Table")
                             .create(x, y))

        dia_table.properties['name'] = (schema_prefix and
                                        "{0}.{1}".format(table.schema.name,
                                                         table.name)
                                        or table.name)

        dia_table.properties['bold_primary_keys'] = True

        dia_table.properties['attributes'] = tuple(
            [attribute(name=c.name, ftype=c.data_type, nullable=c.is_nullable,
                       pk=c.is_pk, unique=c.is_unique)
             for c in table.columns]
        )

        self.dia_layer.add_object(dia_table)
        return dia_table
예제 #23
0
	def createCuonObject(self,st,cx,cy):


		diagram = dia.new("Cuon Objects.dia")
		data = diagram.data
		#layer = data.active_layer
		layer = data.add_layer ('Network')
		print layer
		o, h1, h2 = dia.get_object_type(st).create (cx, cy)
		print 'o = ',  o
		w = o.bounding_box.right - o.bounding_box.left
		h = o.bounding_box.bottom - o.bounding_box.top
		o.move (cx, cy)               
		print 'move',  cx,  cy
		layer.add_object (o)
		layer.update_extents()
		data.update_extents()
		print 'data updated'
		if diagram :
			print 'show diagram'
			diagram.display()
			diagram.flush()
예제 #24
0
 def Add_latex_object(self, *args):
     row_num = self.Add_row()
     def_val = "0.0"
     if not self.unused_ind:
         self.applist[row_num].set_ind(self.no_apps + self.no_apps_nl,
                                       row_num)
     else:
         self.applist[row_num].set_ind(self.unused_ind.pop(), row_num)
     self.applist[row_num].entered_val = def_val
     self.applist[row_num].entry.set_text(def_val)
     self.applist[row_num].image_loc = tex_compile(
         def_val, self.applist[row_num].get_ind(),
         self.project + self.build_d, self.Miktex_path)
     #tex_compile(self.entered_val,self.Index,self.wino.project+self.wino.build_d,self.wino.Miktex_path)
     self.applist[row_num].update_image()
     ot = dia.get_object_type("Standard - Image")
     o, h1, h2 = ot.create(0, 0)
     o.properties['image_file'] = self.applist[row_num].image_loc
     layer = self.data.active_layer
     layer.add_object(o)
     layer.update_extents()
     self.data.update_extents()
     self.applist[row_num].dia_object = o
     savedB(self.db_fil, self.applist, self.not_loaded)
예제 #25
0
	def __init__(self, obj, cls):
		'''
		@param obj: object to wrap
		'''
		object.__setattr__(self, "attributes", [])
		object.__setattr__(self, "operations", [])

		if obj :
			object.__setattr__(self, "obj", obj)
			"""
			attribs = []
			for item in obj.properties.get("attributes").value :
				attribs.append(DiaObjectAttr(*item))
			object.__setattr__(self, "attributes", attribs)
			ops = []
			for item in obj.properties.get("operations").value :
				ops.append(DiaObjectOps(*item))
			object.__setattr__(self, "operations", ops)
			"""
		else :
			oType = dia.get_object_type (cls)
			# we only need the object and not the handles
			diaobj = oType.create(0,0)[0] # p.x, p.y
			object.__setattr__(self, "obj", diaobj)
예제 #26
0
def autodoc_cb(module_name):
    diagram_name = module_name + '.dia'
    diagram = dia.new(diagram_name)
    data = diagram.data
    display = diagram.display()

    layer = data.active_layer

    oType = dia.get_object_type('UML - Class')

    module = __import__(module_name)
    theDir = dir(module)
    # for reflection we need some objects ...
    theObjects = [data, layer, oType]
    try:
        theObjects.append(data.paper)
    except AttributeError:
        pass  # no reason to fail with new bindings
    if diagram:
        theObjects.append(diagram)
    if display:
        theObjects.append(display)
    # add some objects with interesting properties
    #theObjects.append(dia.DiaImage())
    once = 1
    for s in [
            'Standard - Image', 'Standard - BezierLine', 'Standard - Text',
            'UML - Class', 'UML - Dependency'
    ]:
        o, h1, h2 = dia.get_object_type(s).create(0, 0)
        for p in o.properties.keys():
            v = o.properties[p].value
            theObjects.append(v)
            if type(v) is types.TupleType and len(v) > 0:
                theObjects.append(v[0])
        if once:
            theObjects.append(o)
            theObjects.append(h1)
            theObjects.append(o.bounding_box)
            theObjects.append(o.connections[0])
            theObjects.append(o.handles[0])
            theObjects.append(o.properties)
            theObjects.append(o.properties['obj_pos'])
            once = 0
        # o is leaked here
    # print theObjects
    theTypes = {}
    for s in theDir:
        if s == '_dia':
            continue  # avoid all the messy details ;)
        if theTypes.has_key(s):
            continue
        for o in theObjects:
            is_a = eval('type(o) is module.' + s)
            #print s, o
            if is_a:
                theTypes[s] = o
                break
        if not theTypes.has_key(s):
            theTypes[s] = eval('module.' + s)
    # add UML classes for every object in dir
    #print theTypes

    theGlobals = []
    # remove all objects prefixed with '__'
    for s in theDir:
        if s[:2] == '__' or s[:6] == '_swig_':
            continue
        if s == '__doc__' or s == '__name__':
            continue  # hidden in the diagram objects but used below
        doc = eval('module.' + s + '.__doc__')
        is_a = eval('type(module.' + s + ') is types.BuiltinMethodType')
        if is_a:
            theGlobals.append((s, doc))
            continue
        o, h1, h2 = oType.create(0, 0)  # p.x, p.y
        if doc:
            o.properties['comment'] = doc
        layer.add_object(o)
        # set the objects name
        o.properties['name'] = s
        # now populate the object with ...
        if theTypes.has_key(s):
            t = theTypes[s]
            # ... methods and ...
            methods = []
            # ... attributes
            attributes = []
            members = dir(t)
            stereotype = ''
            if '__getitem__' in members:
                if '__len__' in members:
                    stereotype = 'sequence'
                elif 'has_key' in members and 'keys' in members:
                    stereotype = 'dictionary'
            for m in members:
                # again ignoring underscore prefixed
                if m[:2] == '__' or m == 'thisown':  # ignore swig boilerplate
                    continue
                try:
                    is_m = eval('callable(t.' + m + ')')
                except:
                    print 'type(t.' + m + ')?'
                    is_m = 0
                doc = ''
                tt = ''
                if 0:  # does not work well enough, giving only sometimes 'int' and often 'property'?
                    try:  # to detect the (return) type
                        if is_m:
                            oo = t()
                            tt = eval('oo.' + m + '().__class__.__name__')
                        else:
                            tt = eval('t.' + m + '.__class__.__name__')
                    except TypeError, msg:
                        print m, msg
                    except AttributeError, msg:
                        print m, msg  # No constructor defined
                try:
                    doc = eval('t.' + m + '.__doc__')
                except:
                    doc = str(t) + '.' + m
                if is_m:  # (name, type, comment, stereotype, visibility, inheritance_type, query,class_scope, params)
                    methods.append((m, tt, doc, '', 0, 0, 0, 0, ()))
                else:  # (name,type,value,comment,visibility,abstract,class_scope)
                    attributes.append((m, tt, '', doc, 0, 0, 0))
            o.properties['operations'] = methods
            o.properties['attributes'] = attributes
            if stereotype != '':
                o.properties['stereotype'] = stereotype
예제 #27
0
def add_extends(child, parent, layer):
    con, h1, h2 = dia.get_object_type("UML - Generalization").create(0,0)
    h1.connect(parent.connections[6])
    h2.connect(child.connections[1])
    layer.add_object(con)
예제 #28
0
def autodoc_cb (data, flags) :
	if not data : # not set when called by the toolbox menu
		diagram = dia.new("PyDiaObjects.dia")
		# passed in data is not necessary valid - we are called from the Toolbox menu
		data = diagram.data
		display = diagram.display()
	else :
		diagram = None
		display = None
	layer = data.active_layer

	oType = dia.get_object_type ("UML - Class")		
	
	theDir = dir(dia)
	# for reflection we need some objects ...
	theObjects = [data, layer, oType]
	try :
		theObjects.append (data.paper)
	except AttributeError :
		pass # no reason to fail with new bindings
	if diagram : 
		theObjects.append (diagram)
	if display : 
		theObjects.append (display)
	# add some objects with interesting properties
	#theObjects.append(dia.DiaImage())
	once = 1
	for s in ["Standard - Image", "Standard - BezierLine", "Standard - Text", 
		"UML - Class", "UML - Dependency"] :
		o, h1, h2 = dia.get_object_type(s).create(0,0)
		for p in o.properties.keys() :
			v = o.properties[p].value
			theObjects.append(v)
			if type(v) is types.TupleType and len(v) > 0 :
				theObjects.append(v[0])
		if once :
			theObjects.append(o)
			theObjects.append(h1)
			theObjects.append(o.bounding_box)
			theObjects.append(o.connections[0])
			theObjects.append(o.handles[0])
			theObjects.append(o.properties)
			theObjects.append(o.properties["obj_pos"])
			once = 0
		# o is leaked here
	#print theObjects
	theTypes = {}
	for s in theDir :
		if s == "_dia" :
			continue # avoid all the messy details ;)
		if theTypes.has_key(s) :
			continue
		for o in theObjects :
			is_a = eval("type(o) is dia." + s)
			#print s, o
			if is_a :
				theTypes[s] = o
				break
		if not theTypes.has_key (s) :
			theTypes[s] = eval ("dia." + s)
	# add UML classes for every object in dir
	#print theTypes

	theGlobals = []
	# remove all objects prefixed with '__'
	for s in theDir :
		if s[:2] == '__' or s[:6] == '_swig_' :
			continue
		if s == "__doc__" or s == "__name__" :
			continue # hidden in the diagram objects but used below
		doc = eval("dia." + s + ".__doc__")
		is_a = eval("type(dia." + s + ") is types.BuiltinMethodType")
		if is_a :
			theGlobals.append((s,doc))
			continue
		o, h1, h2 = oType.create (0,0) # p.x, p.y
		if doc :
			o.properties["comment"] = doc
		layer.add_object (o)
		# set the objects name
		o.properties["name"] = s
		# now populate the object with ...
		if theTypes.has_key(s) :
			t = theTypes[s]
			# ... methods and ...
			methods = []
			# ... attributes
			attributes = []
			members = dir(t)
			stereotype = ""
			if "__getitem__" in members :
				if "__len__" in members :
					stereotype = "sequence"
				elif "has_key" in members and "keys" in members :
					stereotype = "dictionary"
			for m in members :
				# again ignoring underscore prefixed
				if m[:2] == "__" or m == "thisown" : # ignore swig boilerplate
					continue
				try :
					is_m = eval("callable(t." + m + ")")
				except :
					print "type(t." + m + ")?"
					is_m = 0
				doc = ""
				tt = ""
				if 0 : # does not work well enough, giving only sometimes 'int' and often 'property'?
					try : # to detect the (return) type
						if is_m :
							oo = t()
							tt = eval("oo." + m + "().__class__.__name__")
						else :
							tt = eval("t." + m + ".__class__.__name__")
					except TypeError, msg :
						print m, msg
					except AttributeError, msg :
						print m, msg # No constructor defined
				try :
					doc = eval("t." + m + ".__doc__")
				except :
					doc = str(t) + "." + m
				if is_m : # (name, type, comment, stereotype, visibility, inheritance_type, query,class_scope, params)
					methods.append((m,tt,doc,'',0,0,0,0,()))
				else : # (name,type,value,comment,visibility,abstract,class_scope)
					attributes.append((m,tt,'',doc,0,0,0))
			o.properties["operations"] = methods
			o.properties["attributes"] = attributes
			if stereotype != "" :
				o.properties["stereotype"] = stereotype
예제 #29
0
파일: doxrev.py 프로젝트: AmiGanguli/dia
			try :
				o.properties["operations"] = c.GetMethods()
			except TypeError, msg :
				print "Failed assigning 'operations':", msg, c.GetMethods()
			o.properties["attributes"] = c.GetAttributes()

			layer.add_object(o)
		# create the links (inhertiance, maybe containement, refernces, factory, ...)
		for s in class_map.keys () :
			c, o = class_map[s]
			print s, c, c.bases
			for b in c.bases :
				if class_map.has_key (b) :
					k, p = class_map[b]
					print c.id, "->", k.id
					con, h1, h2 = dia.get_object_type("UML - Generalization").create(0,0)
					layer.add_object (con)
					h1.connect (p.connections[6])
					h2.connect (o.connections[1])
		# ... and move appropriately
		
		# update placement depending on number of parents ?
		layer.update_extents()

	def import_files (sFile, diagramData) :
		# maybe we should select single file/directory, add inlude directories here
		files = glob.glob (os.path.dirname (sFile) + "/class*.xml")
		files.extend (glob.glob (os.path.dirname (sFile) + "/struct*.xml"))
		classes = GetClasses (files)
		return import_classes (classes, diagramData)
예제 #30
0
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
예제 #31
0
import dia_python
dia_python.genObjects()

## To avoid restarting Dia 
## when modifying this python script [after import], 
## use 'reload' from the Python Dia Console: 
dia_python = reload(dia_python) 

"""

# example from page
import sys, dia

# make a tml line; extract props as 'default' style
tline, th1, th2 = dia.get_object_type("Standard - Line").create(10.0, 10.0)
dia.active_display().diagram.data.active_layer.add_object(tline)
dia.active_display().diagram.data.active_layer.update_extents()

linepropsA = tline.properties  # <DiaProperty at 0x8c156c0, "obj_pos", point>
print dir(linepropsA.get('obj_pos').value)  # ['x', 'y']
print tline.properties["obj_pos"]
## see wrong syntax (#A1) below (was here)

dia.active_display().diagram.data.active_layer.remove_object(tline)

lpaStyle = {
    'line_width': 0.5,
    'line_colour': (0.000000, 0.500000, 0.000000),
    'line_style': (0, 1.0),
    ## see wrong syntax (#A2) below (was here)..
예제 #32
0
파일: otypes.py 프로젝트: AmiGanguli/dia
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
def main2(data, flags):
    layer = data.active_layer
    oType = dia.get_object_type ("shape - char") 
    o, h1, h2 = oType.create (1.4,7.95)
    layer.add_object(o)
예제 #34
0
파일: dia_util.py 프로젝트: aitatanit/gmes
def autodoc_cb(module_name):
	diagram_name = module_name + '.dia'
	diagram = dia.new(diagram_name)
	data = diagram.data
	display = diagram.display()

	layer = data.active_layer

	oType = dia.get_object_type('UML - Class')		
	
	module = __import__(module_name)
	theDir = dir(module)
	# for reflection we need some objects ...
	theObjects = [data, layer, oType]
	try:
		theObjects.append (data.paper)
	except AttributeError:
		pass # no reason to fail with new bindings
	if diagram: 
		theObjects.append (diagram)
	if display: 
		theObjects.append (display)
	# add some objects with interesting properties
	#theObjects.append(dia.DiaImage())
	once = 1
	for s in ['Standard - Image', 'Standard - BezierLine', 'Standard - Text', 
		'UML - Class', 'UML - Dependency']:
		o, h1, h2 = dia.get_object_type(s).create(0,0)
		for p in o.properties.keys():
			v = o.properties[p].value
			theObjects.append(v)
			if type(v) is types.TupleType and len(v) > 0:
				theObjects.append(v[0])
		if once:
			theObjects.append(o)
			theObjects.append(h1)
			theObjects.append(o.bounding_box)
			theObjects.append(o.connections[0])
			theObjects.append(o.handles[0])
			theObjects.append(o.properties)
			theObjects.append(o.properties['obj_pos'])
			once = 0
		# o is leaked here
	# print theObjects
	theTypes = {}
	for s in theDir:
		if s == '_dia':
			continue # avoid all the messy details ;)
		if theTypes.has_key(s):
			continue
		for o in theObjects:
			is_a = eval('type(o) is module.' + s)
			#print s, o
			if is_a:
				theTypes[s] = o
				break
		if not theTypes.has_key (s):
			theTypes[s] = eval ('module.' + s)
	# add UML classes for every object in dir
	#print theTypes

	theGlobals = []
	# remove all objects prefixed with '__'
	for s in theDir:
		if s[:2] == '__' or s[:6] == '_swig_':
			continue
		if s == '__doc__' or s == '__name__':
			continue # hidden in the diagram objects but used below
		doc = eval('module.' + s + '.__doc__')
		is_a = eval('type(module.' + s + ') is types.BuiltinMethodType')
		if is_a:
			theGlobals.append((s,doc))
			continue
		o, h1, h2 = oType.create (0,0) # p.x, p.y
		if doc:
			o.properties['comment'] = doc
		layer.add_object (o)
		# set the objects name
		o.properties['name'] = s
		# now populate the object with ...
		if theTypes.has_key(s):
			t = theTypes[s]
			# ... methods and ...
			methods = []
			# ... attributes
			attributes = []
			members = dir(t)
			stereotype = ''
			if '__getitem__' in members:
				if '__len__' in members:
					stereotype = 'sequence'
				elif 'has_key' in members and 'keys' in members:
					stereotype = 'dictionary'
			for m in members:
				# again ignoring underscore prefixed
				if m[:2] == '__' or m == 'thisown': # ignore swig boilerplate
					continue
				try:
					is_m = eval('callable(t.' + m + ')')
				except:
					print 'type(t.' + m + ')?'
					is_m = 0
				doc = ''
				tt = ''
				if 0: # does not work well enough, giving only sometimes 'int' and often 'property'?
					try: # to detect the (return) type
						if is_m:
							oo = t()
							tt = eval('oo.' + m + '().__class__.__name__')
						else:
							tt = eval('t.' + m + '.__class__.__name__')
					except TypeError, msg:
						print m, msg
					except AttributeError, msg:
						print m, msg # No constructor defined
				try:
					doc = eval('t.' + m + '.__doc__')
				except:
					doc = str(t) + '.' + m
				if is_m: # (name, type, comment, stereotype, visibility, inheritance_type, query,class_scope, params)
					methods.append((m,tt,doc,'',0,0,0,0,()))
				else: # (name,type,value,comment,visibility,abstract,class_scope)
					attributes.append((m,tt,'',doc,0,0,0))
			o.properties['operations'] = methods
			o.properties['attributes'] = attributes
			if stereotype != '':
				o.properties['stereotype'] = stereotype
예제 #35
0
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 main2(data, flags):
    layer = data.active_layer
    oType = dia.get_object_type("shape - char")
    o, h1, h2 = oType.create(1.4, 7.95)
    layer.add_object(o)
예제 #37
0
            try:
                o.properties["operations"] = c.GetMethods()
            except TypeError, msg:
                print "Failed assigning 'operations':", msg, c.GetMethods()
            o.properties["attributes"] = c.GetAttributes()

            layer.add_object(o)
        # create the links (inhertiance, maybe containement, refernces, factory, ...)
        for s in class_map.keys():
            c, o = class_map[s]
            print s, c, c.bases
            for b in c.bases:
                if class_map.has_key(b):
                    k, p = class_map[b]
                    print c.id, "->", k.id
                    con, h1, h2 = dia.get_object_type(
                        "UML - Generalization").create(0, 0)
                    layer.add_object(con)
                    h1.connect(p.connections[6])
                    h2.connect(o.connections[1])
        # ... and move appropriately

        # update placement depending on number of parents ?
        layer.update_extents()

    def import_files(sFile, diagramData):
        # maybe we should select single file/directory, add inlude directories here
        files = glob.glob(os.path.dirname(sFile) + "/class*.xml")
        files.extend(glob.glob(os.path.dirname(sFile) + "/struct*.xml"))
        classes = GetClasses(files)
        return import_classes(classes, diagramData)
예제 #38
0
파일: allprops.py 프로젝트: AmiGanguli/dia
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
예제 #39
0
파일: pydiadoc.py 프로젝트: davinciwei/dia
def autodoc_cb (data, flags, update) :
	show_comments = 1 # maybe this should be selectable
	if not data : # not set when called by the toolbox menu
		diagram = dia.new("PyDiaObjects.dia")
		# passed in data is not necessary valid - we are called from the Toolbox menu
		data = diagram.data
		display = diagram.display()
	else :
		diagram = None
		display = None
	layer = data.active_layer

	oType = dia.get_object_type ("UML - Class")

	theDir = dir(dia)
	# for reflection we need some objects ...
	theObjects = [data, layer, oType]
	try :
		theObjects.append (data.paper)
	except AttributeError :
		pass # no reason to fail with new bindings
	if diagram :
		theObjects.append (diagram)
	if display :
		theObjects.append (display)
	# add some objects with interesting properties
	#theObjects.append(dia.DiaImage())
	once = 1
	for s in ["Standard - Image", "Standard - BezierLine", "Standard - Text",
		"UML - Class", "UML - Dependency"] :
		o, h1, h2 = dia.get_object_type(s).create(0,0)
		for p in o.properties.keys() :
			v = o.properties[p].value
			theObjects.append(v)
			if type(v) is types.TupleType and len(v) > 0 :
				theObjects.append(v[0])
		if once :
			theObjects.append(o)
			theObjects.append(h1)
			theObjects.append(o.bounding_box)
			theObjects.append(o.connections[0])
			theObjects.append(o.handles[0])
			theObjects.append(o.properties)
			theObjects.append(o.properties["obj_pos"])
			once = 0
		# o is leaked here
	#print theObjects
	theTypes = {}
	for s in theDir :
		if s == "_dia" :
			continue # avoid all the messy details ;)
		if theTypes.has_key(s) :
			continue
		for o in theObjects :
			is_a = eval("type(o) is dia." + s)
			#print s, o
			if is_a :
				theTypes[s] = o
				break
		if not theTypes.has_key (s) :
			theTypes[s] = eval ("dia." + s)
	# add UML classes for every object in dir
	#print theTypes

	fresh = [] # list of newly created objects
	theGlobals = []
	# remove all objects prefixed with '__'
	for s in theDir :
		if s[:2] == '__' or s[:6] == '_swig_' :
			continue
		if s == "__doc__" or s == "__name__" :
			continue # hidden in the diagram objects but used below
		doc = eval("dia." + s + ".__doc__")
		is_a = eval("type(dia." + s + ") is types.BuiltinMethodType")
		if is_a :
			theGlobals.append((s,doc))
			continue
		# search the class we would create in the diagram and if found, modify rather than create
		o = None
		if update :
			o = find_class(data, s)
			h1 = h2 = None
			if o :
				show_comments = o.properties["visible_comments"].value
		if not o :
			o, h1, h2 = oType.create (0,0) # p.x, p.y
			layer.add_object (o)
			fresh.append(o)
		if doc :
			o.properties["comment"] = doc
		# set the objects name
		o.properties["name"] = s
		# now populate the object with ...
		if theTypes.has_key(s) :
			t = theTypes[s]
			# ... methods and ...
			methods = []
			# ... attributes
			attributes = []
			members = dir(t)
			stereotype = ""
			if "__getitem__" in members :
				if "__len__" in members :
					stereotype = "sequence"
				elif "has_key" in members and "keys" in members :
					stereotype = "dictionary"
			for m in members :
				# again ignoring underscore prefixed
				if m[:2] == "__" or m == "thisown" : # ignore swig boilerplate
					continue
				try :
					is_m = eval("callable(t." + m + ")")
				except :
					print "type(t." + m + ")?"
					is_m = 0
				doc = ""
				tt = ""
				if 0 : # does not work well enough, giving only sometimes 'int' and often 'property'?
					try : # to detect the (return) type
						if is_m :
							oo = t()
							tt = eval("oo." + m + "().__class__.__name__")
						else :
							tt = eval("t." + m + ".__class__.__name__")
					except TypeError, msg :
						print m, msg
					except AttributeError, msg :
						print m, msg # No constructor defined
				try :
					# try to get the member's docstring from the type
					doc = eval("dia." + s + "." + m + ".__doc__")
					# fallback to object?
					#doc = eval("t." + m + ".__doc__")
				except AttributeError :
					doc = str(t) + "." + m
				if is_m : # (name, type, comment, stereotype, visibility, inheritance_type, query,class_scope, params)
					methods.append((m,tt,doc,'',0,0,0,0,()))
				else : # (name,type,value,comment,visibility,abstract,class_scope)
					attributes.append((m,tt,'',doc,0,0,0))
			o.properties["operations"] = methods
			o.properties["attributes"] = attributes
			o.properties["comment_line_length"] = 120
			o.properties["visible_comments"] = show_comments
			if stereotype != "" :
				o.properties["stereotype"] = stereotype
예제 #40
0
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
예제 #41
0
파일: aobjects.py 프로젝트: AmiGanguli/dia
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