예제 #1
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()
예제 #2
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()
예제 #3
0
def SimpleScale(data, factor):
    objs = data.get_sorted_selected()
    if len(objs) == 0:
        objs = data.active_layer.objects
    scaleFailed = {}
    for o in objs:
        pos = o.properties["obj_pos"].value
        hSE = None  # the 'south east' handle to size the object
        if "elem_width" in o.properties:
            hLR = o.handles[7]  # HANDLE_RESIZE_SE
            try:
                #if 0 == hLR.type : # HANDLE_NON_MOVABLE
                #	raise RuntimeError, "non moveable handle"
                x = pos.x * factor
                y = pos.y * factor
                x2 = x + (hLR.pos.x - pos.x) * factor
                y2 = y + (hLR.pos.y - pos.y) * factor
                # calculate all points before movement, handle is still connected and move moves it too
                o.move(x, y)
                o.move_handle(hLR, (x2, y2), 0, 0)
                ScaleLens(o, factor)
            except RuntimeError as msg:
                if o.type.name in scaleFailed:
                    scaleFailed[o.type.name] += 1
                else:
                    scaleFailed[o.type.name] = 1
        else:
            # must move all handles
            try:
                x = pos.x * factor
                y = pos.y * factor
                handles = []
                for h in o.handles:
                    #if 0 == h.type : # HANDLE_NON_MOVABLE
                    #	continue
                    handles.append((h, (x + (h.pos.x - pos.x) * factor,
                                        y + (h.pos.y - pos.y) * factor)))
                # handles are not necessary independent
                for h in handles:
                    o.move_handle(h[0], h[1], 0, 0)
                ScaleLens(o, factor)
            except RuntimeError as msg:
                if o.type.name in scaleFailed:
                    scaleFailed[o.type.name] += 1
                else:
                    scaleFailed[o.type.name] = 1
    if len(list(scaleFailed.keys())) > 0:
        sMsg = "Scaling failed for : "
        for s in list(scaleFailed.keys()):
            sMsg = sMsg + "\n%s (%d)" % (s, scaleFailed[s])
        dia.message(1, sMsg)
    data.update_extents()
    dia.active_display().add_update_all()
def research(data, flags) :
  print dia.active_display().diagram.get_sorted_selected()
  print data
  print flags
  
  objs = dia.active_display().diagram.get_sorted_selected()
  print " "
  
  for obj in objs:
    print "obj.type = ", obj.type
    print "obj.properties = ", obj.properties.keys() 

    print "prop obj_bb = ", obj.properties['obj_bb'].value
    print "prop meta = ",obj.properties.get('meta').value
def research(data, flags):
    print "argument 'data' = ", data
    print "argument 'flags' = ", flags
    print "sorted_selected = ", dia.active_display(
    ).diagram.get_sorted_selected()

    objs = dia.active_display().diagram.get_sorted_selected()
    print " "

    for obj in objs:
        print "obj.type = ", obj.type
        print "obj.properties = ", obj.properties.keys()
        print "prop obj_bb = ", obj.properties['obj_bb'].value
        print "prop meta = ", obj.properties.get('meta').value
예제 #6
0
def select_empty_cb(data, flags):
    diagram = dia.active_display().diagram
    objs = data.active_layer.objects
    for o in objs:
        if o.bounding_box.right == o.bounding_box.left \
         or o.bounding_box.top == o.bounding_box.bottom :
            diagram.select(o)
예제 #7
0
파일: pygen.py 프로젝트: exippy/dia_pygen
def start_codegen(data,flags):
    ui=GenCodeDialog(gladefile="/home/e140741/git/dia_pygen/dia_pygen/src/dia_pygen/gui/gladefiles/gencode.glade")
    gtk.main()
    project_name="testing"
    layer_id=ui.selected_layer
    folder=ui.dest_folder
    if ui.validated:
        #narrowing down to selected layer:
        dia_objects=dia.active_display().diagram.data.layers[layer_id].objects
        uml_obj_factory=UMLObjFactory(dia2UML_sp())
        renderer=PrintRenderer()
        builder=Dia2umlTreeBuilder(dia_objects, uml_obj_factory)
        #uml_objects=[]
        #for i in dia_objects:
        #    uml_objects.append(uml_obj_factory.new_uml_obj(i))
        
        #init new uml project
        root_package= LargePackage(project_name,path=folder)
        root_package.accept(builder)
        root_package.accept(renderer)
        
        #init strategy and language
        #convert dia object to uml
        #build hierarchy
        #generate code
        pass
예제 #8
0
    def UpdateCurrentDiagramAndDir(self):
        # set current diagram infos
        self.diagram = dia.active_display().diagram
        self.diagramPath = str(self.diagram)
        self.diagramDir = os.path.split(self.diagramPath)[0]
        self.diagramParentDir = os.path.split(self.diagramDir)[0]

        # set initial base execution dir to parent of current diagram's dir
        self.baseDir = self.diagramParentDir

        # retrieve selected layer num and name
        self.selectedLayerNum = 0
        i = 0
        self.previousLayersObjects = 0
        self.selectedId = ""
        for l in self.diagram.data.layers:
            if l == self.diagram.data.active_layer:
                self.selectedLayerNum = i

                # build selected id list string
                for o in self.diagram.data.selected:
                    self.selectedId += "O" + str(self.diagram.data.active_layer.object_index(o) + \
                                                  self.previousLayersObjects) + " "
                break
            else:
                i += 1
                self.previousLayersObjects += len(l.objects)
        self.selectedLayerName = self.diagram.data.layers[self.selectedLayerNum].name
예제 #9
0
def line_v_sub(data, flags) :
    diagram = dia.active_display().diagram
    for o in data.selected :
        print 'selected: ', o, 
        print o.properties.keys(), o.properties['obj_pos']
        print 'dir(o)', dir(o)
        pos = o.properties["obj_pos"].value
        print dir(pos), pos
        print pos.x, pos.y
        o.move(0.1, 0.1)
        print o.bounding_box
        print dir(o.bounding_box)
        print o.bounding_box.bottom, o.bounding_box.left, o.bounding_box.right , o.bounding_box.top 
        #o.properties['obj_bb']['right'] = o.bounding_box['left'] 
        o.properties['obj_bb'] = ((1,1),(0.473637,4.011794))

        #o.bounding_box
        #pos['x'] -= 1
        #pos.y -= 1

    data.active_layer.update_extents() 
    diagram.add_update_all()
    diagram.update_extents ()
    diagram.flush()
    return data
예제 #10
0
def dia_objects_props_cb (data, flags) :

	d = dia.active_display().diagram
	
	# display the dialog
	data = None
	allProps = None
	dlg = CuonDia(d, data, allProps)
예제 #11
0
def dia_group_resize_db(data, flags):
    diagram = dia.active_display().diagram
    group = diagram.get_sorted_selected()
    if len(group) > 0:
        win = ResizeWindow(group, data)
        win.show()
    else:
        dia.message(gtk.MESSAGE_INFO, "Please select a group of objects")
예제 #12
0
 def __init__(self, d, data):
     import os, subprocess, time
     filename = dia.active_display().diagram.filename
     sFilename = '%s' % (filename)
     subprocess.Popen([
         'xterm', '-hold', '-title', 'Simular', '-e', 'simusol', sFilename
     ])
     time.sleep(10)
예제 #13
0
def dia_group_resize_db (data,flags):
    diagram = dia.active_display().diagram
    group = diagram.get_sorted_selected()
    if len(group) > 0:
        win = ResizeWindow(group, data)
        win.show()
    else:
        dia.message(gtk.MESSAGE_INFO, "Please select a group of objects")
예제 #14
0
def width_sub(data, flags) :
    diagram = dia.active_display().diagram
    for o in data.selected :
        o.properties["elem_width"] = o.properties["elem_width"].value - 1
    data.active_layer.update_extents() 
    diagram.add_update_all()
    diagram.update_extents ()
    diagram.flush()
    return data
예제 #15
0
def main(data, flags):
    try:
        active_display = dia.active_display()
        diagram = active_display.diagram
        active_layer = diagram.data.active_layer
        PgImportDialog(active_layer)

    except ImportError:

        dia.message(0, "Dialog creation failed. Missing pygtk?")
예제 #16
0
    def clickAplicar(self, *args):
        optWidth = self.getSelectedGroupOption(self.widthOptions)
        optHeight = self.getSelectedGroupOption(self.heightOptions)

        try:
            if optWidth[0] != 'ignore':
                width = self.getValue(optWidth[0], optWidth[1], 'elem_width')
                self.adjustWidth(width)
            if optHeight[0] != 'ignore':
                height = self.getValue(optHeight[0], optHeight[1], 'elem_height')
                self.adjustHeight(height)

            if dia.active_display():
                diagram = dia.active_display().diagram
                for obj in self.group:
                    diagram.update_connections(obj)
                    
        except Exception,e:
            dia.message(gtk.MESSAGE_ERROR, repr(e))
예제 #17
0
    def clickAplicar(self, *args):
        optWidth = self.getSelectedGroupOption(self.widthOptions)
        optHeight = self.getSelectedGroupOption(self.heightOptions)

        try:
            if optWidth[0] != 'ignore':
                width = self.getValue(optWidth[0], optWidth[1], 'elem_width')
                self.adjustWidth(width)
            if optHeight[0] != 'ignore':
                height = self.getValue(optHeight[0], optHeight[1],
                                       'elem_height')
                self.adjustHeight(height)

            if dia.active_display():
                diagram = dia.active_display().diagram
                for obj in self.group:
                    diagram.update_connections(obj)

        except Exception, e:
            dia.message(gtk.MESSAGE_ERROR, repr(e))
예제 #18
0
def select_by_selected (data, name) :
	d = dia.active_display().diagram
	grp = data.get_sorted_selected()
	bFoundAny = 0
	for o in grp :
		if o.properties.has_key(name) :
			select_by (d, data, name, o.properties[name].value)
			bFoundAny = 1
	if not bFoundAny :
		dia.message(0, "No selected object has the property '%s'." % name)
	data.update_extents ()
예제 #19
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 = {}
    for o in objs:
        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()
예제 #20
0
	def __init__(self, diagram, data, props):
		import pygtk
		pygtk.require("2.0")
		import gtk
		print 'cuon dia'
		props = ['1', '2']
		self.diagram  = dia.active_display().diagram
		self.data = data
		self.props = props

		self.win = gtk.Window ()
		self.win.connect("delete_event", self.on_delete)
		self.win.set_title("Cuon")
        
		box1 = gtk.VBox()
		self.win.add(box1)
		box1.show()
        
		box2 = gtk.VBox(spacing=2)
		box2.set_border_width(10)
		box1.pack_start(box2)
		box2.show()
        
		self.checkboxes = []
		self.optionmenues = []
		table = gtk.Table(2, len(props), 0)
		table.set_row_spacings(2)
		table.set_col_spacings(5)
		table.set_border_width(5)
		y = 0
        
		box2.pack_start(table)
		table.show()
        
		separator = gtk.HSeparator()
		box1.pack_start(separator, expand=0)
		separator.show()
        
		box2 = gtk.VBox(spacing=10)
		box2.set_border_width(10)
		box1.pack_start(box2, expand=0)
		box2.show()
        
		button = gtk.Button("Ok")
		button.connect("clicked", self.on_ok)
		box2.pack_start(button)
		button.set_flags(gtk.CAN_DEFAULT)
		button.grab_default()
		button.show()
		self.win.show()
		self.rpc = MyXmlrpc()
예제 #21
0
    def width_eq(data, flags) :
        diagram = dia.active_display().diagram
        max_w = max([ o.properties["elem_width"].value for o in data.selected ])
        min_w = min([ o.properties["elem_width"].value for o in data.selected ])

        for o in data.selected :
            print 'selected: ', o
            if use_max:
                o.properties["elem_width"] = max_w
            else : 
                o.properties["elem_width"] = min_w

        data.active_layer.update_extents() 
        diagram.add_update_all()
        diagram.update_extents ()
        diagram.flush()
예제 #22
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()
예제 #23
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()
예제 #24
0
def dia_objects_props_cb(data, flags):
    d = dia.active_display().diagram
    grp = d.get_sorted_selected()
    allProps = {}
    numProps = len(grp)
    # check for properties common to all select objects
    for o in grp:
        props = o.properties
        for s in props.keys():
            if props[s].visible:
                if allProps.has_key(s):
                    allProps[s].Add(props[s])
                else:
                    allProps[s] = PropInfo(props[s].type, props[s].name,
                                           props[s])
    # now eliminate all props not common ...
    for s in allProps.keys():
        if allProps[s].num < numProps:
            del allProps[s]
    # ... and all props already equal
    for s in allProps.keys():
        o1 = allProps[s].opts[0]
        for o in allProps[s].opts:
            if o1.value != o.value:
                o1 = None
                break
        if o1 != None:
            del allProps[s]
        else:
            # if there is something left ensure unique values
            uniques = {}
            for o in allProps[s].opts:
                if uniques.has_key(o.value):
                    continue
                uniques[o.value] = o
            allProps[s].opts = []
            for v in uniques.keys():
                allProps[s].opts.append(uniques[v])
    # display the dialog
    try:
        dlg = CPropsDialog(d, data, allProps)
    except ImportError:
        dia.message(0, "Dialog creation failed. Missing pygtk?")
예제 #25
0
def dia_objects_props_cb (data, flags) :
	d = dia.active_display().diagram
	grp = d.get_sorted_selected()
	allProps = {}
	numProps = len(grp)
	# check for properties common to all select objects
	for o in grp :
		props = o.properties
		for s in props.keys() :
			if props[s].visible :
				if allProps.has_key(s) :
					allProps[s].Add(props[s])
				else :
					allProps[s] = PropInfo(props[s].type, props[s].name, props[s])
	# now eliminate all props not common ...
	for s in allProps.keys() :
		if allProps[s].num < numProps :
			del allProps[s]
	# ... and all props already equal
	for s in allProps.keys() :
		o1 = allProps[s].opts[0]
		for o in allProps[s].opts :
			if o1.value != o.value :
				o1 = None
				break
		if o1 != None :
			del allProps[s]
		else :
			# if there is something left ensure unique values
			uniques = {}
			for o in allProps[s].opts :
				if uniques.has_key(o.value) :
					continue
				uniques[o.value] = o
			allProps[s].opts = []
			for v in uniques.keys() :
				allProps[s].opts.append(uniques[v])
	# display the dialog
	try :
		dlg = CPropsDialog(d, data, allProps)
	except ImportError :
		dia.message(0, "Dialog creation failed. Missing pygtk?")
예제 #26
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()
예제 #27
0
def layout_force_cb (data, flags) :
	diagram = dia.active_display().diagram
	# the things (nodes) we are moving around are all connected 'elements', 
	# connection objects are only moving as a side effect
	nodes = []
	for o in data.selected :
		for cpt in o.connections : # ConnectionPoint
			if len (cpt.connected) > 0 :
				nodes.append (o)
				break
	# this ususally is an iterative process, finished if no energy is left
	#FIXME: layout_force (nodes, 2.0, 2.0, 0.2, 0.5) PASSES 0.0, 0.0
	e = layout_force (nodes, 2.0, 3.0, 2e-1, 5e-1)
	n = 0 # arbitrary limit to avoid endless loop
	while (e[0] > 1 or e[1] > 1) and n < 100 :
		e = layout_force (nodes, 2.0, 3.0, 2e-1, 5e-1)
		n += 1
	for o in nodes :
		diagram.update_connections (o)
	data.active_layer.update_extents() # data/diagram _update_extents don't recalculate?
	diagram.update_extents ()
	diagram.flush()
	print n, "iterations"
예제 #28
0
def select_by_size_cb(data, flags):
    """ From the diagrams selection derive the minimum and maximum object size.
	    Select every other object within this range.
	"""
    d = dia.active_display().diagram
    grp = data.get_sorted_selected()
    smin = 100000
    smax = 0
    for o in grp:
        w = o.bounding_box.right - o.bounding_box.left
        h = o.bounding_box.bottom - o.bounding_box.top
        s = w * h
        if s > smax:
            smax = s
        if s < smin:
            smin = s
    objs = data.active_layer.objects
    for o in objs:
        w = o.bounding_box.right - o.bounding_box.left
        h = o.bounding_box.bottom - o.bounding_box.top
        s = w * h
        if s >= smin and s <= smax:
            d.select(o)
    d.flush()
예제 #29
0
파일: select_by.py 프로젝트: AmiGanguli/dia
def select_by_size_cb (data, flags) :
	""" From the diagrams selection derive the minimum and maximum object size.
	    Select every other object within this range.
	"""
	d = dia.active_display().diagram
	grp = data.get_sorted_selected()
	smin = 100000
	smax = 0
	for o in grp :
		w = o.bounding_box.right - o.bounding_box.left
		h = o.bounding_box.bottom - o.bounding_box.top
		s = w * h
		if s > smax :
			smax = s
		if s < smin :
			smin = s
	objs = data.active_layer.objects
	for o in objs :
		w = o.bounding_box.right - o.bounding_box.left
		h = o.bounding_box.bottom - o.bounding_box.top
		s = w * h
		if s >= smin and s <= smax :
			d.select(o)
	d.flush()
예제 #30
0
class ResizeWindow(object):
    def __init__(self, group, data):
        self.group = group
        self.data = data
        self.initWindow()

    def initWindow(self):
        self.dlg = gtk.Dialog()
        self.dlg.set_title('Group Resize')
        self.dlg.set_border_width(6)
        self.dlg.vbox.pack_start(self.dialogContents(),
                                 fill=True,
                                 expand=True,
                                 padding=5)
        self.dlg.add_button(gtk.STOCK_APPLY, gtk.RESPONSE_APPLY)
        self.dlg.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
        self.dlg.set_has_separator(True)
        self.dlg.set_modal(False)
        self.dlg.get_widget_for_response(gtk.RESPONSE_CLOSE).connect(
            "clicked", self.hide, None)
        self.dlg.get_widget_for_response(gtk.RESPONSE_APPLY).connect(
            "clicked", self.clickAplicar, None)

    def dimensionsFrame(self, label):
        frame = gtk.Frame(label)
        table = gtk.Table(rows=4, columns=2)
        ignore = gtk.RadioButton(group=None, label="do not change")
        ignore.show()
        smallest = gtk.RadioButton(group=ignore, label="shrink to smallest")
        smallest.show()
        largest = gtk.RadioButton(group=ignore, label="enlarge to largest")
        largest.show()
        specify = gtk.RadioButton(group=ignore, label="resize to:")
        specify.show()
        value = gtk.Entry()
        value.show()
        specify.connect("toggled", self.enableValueEntry, value)
        self.enableValueEntry(specify, value)
        table.attach(ignore, 0, 1, 0, 1)
        table.attach(smallest, 0, 1, 1, 2)
        table.attach(largest, 0, 1, 2, 3)
        table.attach(specify, 0, 1, 3, 4)
        table.attach(value, 1, 2, 3, 4)
        frame.add(table)
        table.show()
        frame.show()

        options = {
            'ignore': ignore,
            'smallest': smallest,
            'largest': largest,
            'specify': specify,
            'value': value
        }
        return frame, options

    def enableValueEntry(self, radioSpecify, entrySpecify, *args):
        entrySpecify.set_sensitive(radioSpecify.get_active())

    def contentsFrameWidth(self):
        frame, self.widthOptions = self.dimensionsFrame('Width')
        return frame

    def contentsFrameHeight(self):
        frame, self.heightOptions = self.dimensionsFrame('Height')
        return frame

    def dialogContents(self):
        contents = gtk.VBox(spacing=5)
        contents.pack_start(self.contentsFrameWidth(), fill=True, expand=True)
        contents.pack_start(self.contentsFrameHeight(), fill=True, expand=True)
        contents.show()
        return contents

    def getSelectedGroupOption(self, options):
        value = options['value'].get_text()
        for opt in 'ignore', 'smallest', 'largest', 'specify':
            if options[opt].get_active():
                return (opt, value)
        return ('ignore', value)

    def getValue(self, opt, value, elProperty):
        if opt == 'specify':
            return self.toFloat(value)
        else:
            values = [
                x.properties[elProperty].value for x in self.group
                if x.properties.has_key(elProperty)
            ]
            if opt == 'smallest':
                return min(values)
            else:
                return max(values)

    def adjustWidth(self, value):
        for obj in self.group:
            pos = obj.properties['obj_pos'].value
            if obj.properties.has_key("elem_width"):
                difference = value - obj.properties['elem_width'].value
                handleLeft = obj.handles[3]
                handleRight = obj.handles[4]
                amount = difference / 2
                obj.move_handle(handleLeft,
                                (handleLeft.pos.x - amount, handleLeft.pos.y),
                                0, 0)
                obj.move_handle(
                    handleRight,
                    (handleRight.pos.x + amount, handleRight.pos.y), 0, 0)
                obj.move(pos.x, pos.y)

    def adjustHeight(self, value):
        for obj in self.group:
            pos = obj.properties['obj_pos'].value
            if obj.properties.has_key("elem_height"):
                difference = value - obj.properties['elem_height'].value
                handleTop = obj.handles[1]
                handleBottom = obj.handles[6]
                amount = difference / 2
                obj.move_handle(handleTop,
                                (handleTop.pos.x, handleTop.pos.y - amount), 0,
                                0)
                obj.move_handle(
                    handleBottom,
                    (handleBottom.pos.x, handleBottom.pos.y + amount), 0, 0)
                obj.move(pos.x, pos.y)

    def toFloat(self, valor):
        return locale.atof(valor)

    def clickAplicar(self, *args):
        optWidth = self.getSelectedGroupOption(self.widthOptions)
        optHeight = self.getSelectedGroupOption(self.heightOptions)

        try:
            if optWidth[0] != 'ignore':
                width = self.getValue(optWidth[0], optWidth[1], 'elem_width')
                self.adjustWidth(width)
            if optHeight[0] != 'ignore':
                height = self.getValue(optHeight[0], optHeight[1],
                                       'elem_height')
                self.adjustHeight(height)

            if dia.active_display():
                diagram = dia.active_display().diagram
                for obj in self.group:
                    diagram.update_connections(obj)

        except Exception, e:
            dia.message(gtk.MESSAGE_ERROR, repr(e))

        if dia.active_display():
            dia.active_display().add_update_all()
            dia.active_display().flush()
예제 #31
0
def dia_objects_center_cb(data, flags):
    grp = data.get_sorted_selected()
    if (len(grp) > 1):
        center_objects(grp)
        data.update_extents()
    dia.active_display().diagram.add_update_all()
예제 #32
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)..
    ## specify arrows directly as tuple (type, length, width):
예제 #33
0
파일: select_empty.py 프로젝트: dwbxm/dia
def select_empty_cb(data, flags):
    diagram = dia.active_display().diagram
    objs = data.active_layer.objects
    for o in objs:
        if o.bounding_box.right == o.bounding_box.left or o.bounding_box.top == o.bounding_box.bottom:
            diagram.select(o)
예제 #34
0
def simu(data, flags):
    dlg = CSimusol(dia.active_display().diagram, data)
예제 #35
0
				y = pos.y * factor
				handles = []
				for h in o.handles :
					#if 0 == h.type : # HANDLE_NON_MOVABLE
					#	continue
					handles.append((h, (x + (h.pos.x - pos.x) * factor,
									  y + (h.pos.y - pos.y) * factor)))
				# handles are not necessary independent
				for h in handles :
					o.move_handle(h[0], h[1],  0, 0)
				ScaleLens(o, factor)
			except RuntimeError, msg :
				if scaleFailed.has_key(o.type.name) :
					scaleFailed[o.type.name] += 1
				else :
					scaleFailed[o.type.name] = 1
	if len(scaleFailed.keys()) > 0 :
		sMsg = "Scaling failed for : "
		for s in scaleFailed.keys() :
			sMsg = sMsg + "\n%s (%d)" % (s, scaleFailed[s])
		dia.message(1, sMsg)
	data.update_extents ()
	dia.active_display().add_update_all()

def scale_cb(data, flags) :
	dlg = CScaleDialog(dia.active_display().diagram, data)

dia.register_action ("ObjectsSimplescaling", "Simple Scaling",
		     "/DisplayMenu/Objects/ObjectsExtensionStart", 
		     scale_cb)
예제 #36
0
def scale_cb(data, flags) :
	dlg = CScaleDialog(dia.active_display().diagram, data)
예제 #37
0
def select_by_name_cb (data, flags) :
	d = dia.active_display().diagram
	do_dialog (d, data)
예제 #38
0
def arrange_connected (data, flags) :
	
	diagram = dia.active_display().diagram
	data = diagram.data 
	
	objs = data.get_sorted_selected()
	if len(objs) == 0 :
		objs = data.active_layer.objects
	# all objects having at least one connection
	bs = {}
	print "objs", len(objs)
	edges = {}

	for o in objs :
		
		o.properties["fill_colour"] = "lightcyan"

		for c in o.connections: # ConnectionPoint

			for n in c.connected: # connection object

				if not (n.handles[0].connected_to and n.handles[1].connected_to):
					continue
				a = n.handles[0].connected_to.object
				b = n.handles[1].connected_to.object
				ak = a.properties["name"].value
				bk = b.properties["name"].value
				# create an edge key
				ek = ak + "->" + bk
				if edges.has_key (ek) :
					continue # already seen
				print ek
				edges[ek] = 1
				if bs.has_key (ak) :
					use = bs[ak]
					use[2].append (bk)
					bs[ak] = use
				else :
					bs[ak] = [a, 0, [bk]]
				if bs.has_key (bk) :
					use = bs[bk]
					use[1] += 1
					bs[bk] = use
				else :
					bs[bk] = [b, 1, []]

	# sort by number of connections
	bst = []
	dx = 0
	dy = 0
	for key in bs.keys() :
		o = bs[key][0]
		if not o.properties["elem_width"] :
			print o
			continue
		if o.properties["elem_width"].value > dx : dx = o.properties["elem_width"].value
		if o.properties["elem_height"].value > dy : dy = o.properties["elem_height"].value
		n = bs[key][1] # (use count, dependencies)
		bst.append ((o, n, DeepCalc (bs, key)))
	bst.sort (lambda a, b : cmp(a[1], b[1]))
	if len(bs) < 2 :
		return
	# average weight gives the number of rows
	aw = 0.0
	for t in bst :
		aw += (t[1] + t[2])
	aw = aw / len(bst)
	rows = int (len(bst) / math.sqrt(aw))
	if rows < 2 :
		rows = 2
	offsets = []
	for i in range(0, rows) : offsets.append(0)
	dx *= 1.4
	dy *= 1.8
	for t in bst :
		y = t[1] # t[1] = 0 :  start, noone uses it
		# correction to move further down
		c = rows - (rows * t[2] / aw)
		if t[1] : # the less users the far below
			if t[2] == 0 :
				y = rows - 1
			elif t[1] >= rows :
				# compensate for some of the weight, FIXME: better guess needed
				y = int(rows - 2 * aw / (t[2] + t[1]))
		print t[0].properties["name"].value, t[1], t[2], y, c
		# move the object to it's new place
		x = offsets[y]
		t[0].move (x * dx, y * dy)
		offsets[y] += 1
	data.update_extents ()
예제 #39
0
def rotate_cb(data, flags) :
	dlg = CRotateDialog(dia.active_display().diagram, data)
예제 #40
0
def load_file(fn):
    import_file(fn, dia.active_display().diagram.data)
예제 #41
0
def rotate_cb(data, flags):
    dlg = CRotateDialog(dia.active_display().diagram, data)
예제 #42
0
def GetSelectedLineLength(data, flags) :
  dlg = CLengthDialog(dia.active_display().diagram,data)
예제 #43
0
def change_class_colors(html_col, layer=None):
    layer = layer or dia.active_display().diagram.data.active_layer
    color = parse_html_color(html_col)
    for o in (layer.objects[i] for i in xrange(len(layer.objects))):
        if not is_class(o): continue
        o.properties["fill_colour"] = color