def effect(self):
		node_pos={}
		node_R=[]
		for node in self.selected.values() :
			if node.tag == inkex.addNS('path','svg') and node.get(inkex.addNS("cx","sodipodi")) is not None :#assume circle
				node_pos[node]=simpleprimitive.element_center(node)
				rx,ry=simpleprimitive.element_size(node)
				node_R.append((rx+ry)/2.)
		if len(node_pos)>2 :
			size=sum(node_R)/len(node_R)
			cx,cy=bary(node_pos.values())
			node_ref=iter(node_pos).next()
			parent=node_ref.getparent()
			box=simpleprimitive.box(parent,cx,cy,size,size,{"fill":simplestyle.svgcolors["blue"]})
			box.set("id",self.uniqueId("rect"))
			angles=[(angle(node_pos[node_ref],pt,(cx,cy)),node) for node,pt in node_pos.iteritems()]
			angles.sort()
			nb=len(angles)
			for i in xrange(nb) :
				n1=angles[i][1]
				n2=angles[(i+1)%nb][1]
				wall=self.test_connection(n1,n2)
				if wall is None :
					x,y=bary([node_pos[node] for node in (n1,n2)])
					wall=simpleprimitive.box(parent,x,y,size,size,{"fill":simplestyle.svgcolors["magenta"]})
					wall.set("id",self.uniqueId("rect"))
					for node in (n1,n2) :
						con=simpleprimitive.connect(parent,wall,node,{"stroke":simplestyle.svgcolors["blue"]})
						if con is not None :
							con.set("id",self.uniqueId("con"))
				con=simpleprimitive.connect(parent,box,wall,{"stroke":simplestyle.svgcolors["green"]})
				con.set("id",self.uniqueId("con"))
		else :
			raise UserWarning("must select at least 3 elements")
	def effect(self):
		node_pos={}
		node_R=[]
		for node in self.selected.values() :
			if node.tag == inkex.addNS('path','svg') and node.get(inkex.addNS("cx","sodipodi")) is not None :#assume circle
				node_pos[node]=simpleprimitive.element_center(node)
				node_R.append(float(node.get(inkex.addNS("rx","sodipodi"))))
		if len(node_pos)>2 :
			size=sum(node_R)/len(node_R)*2.
			cx=sum([pt[0] for pt in node_pos.itervalues()])/len(node_pos)
			cy=sum([pt[1] for pt in node_pos.itervalues()])/len(node_pos)
			node_ref=iter(node_pos).next()
			parent=node_ref.getparent()
			box=simpleprimitive.box(parent,cx,cy,size,size,{"fill":simplestyle.svgcolors["blue"]})
			box.set("id",self.uniqueId("rect"))
			angles=[(angle(node_pos[node_ref],pt,(cx,cy)),node) for node,pt in node_pos.iteritems()]
			angles.sort()
			nb=len(angles)
			for i in xrange(nb) :
				con=simpleprimitive.connect(parent,angles[i][1],angles[(i+1)%nb][1],{"stroke":simplestyle.svgcolors["magenta"]})
				if con is not None :
					con.set("id",self.uniqueId("con"))
			for node in node_pos :
				con=simpleprimitive.connect(parent,box,node,{"stroke":simplestyle.svgcolors["green"]})
				con.set("id",self.uniqueId("con"))
		else :
			raise UserWarning("must select at least 3 elements")
Ejemplo n.º 3
0
 def effect(self):
     node_pos = {}
     node_R = []
     for node in self.selected.values():
         if node.tag == inkex.addNS('path', 'svg') and node.get(
                 inkex.addNS("cx", "sodipodi")) is not None:  #assume circle
             node_pos[node] = simpleprimitive.element_center(node)
             node_R.append(float(node.get(inkex.addNS("rx", "sodipodi"))))
     if len(node_pos) > 2:
         size = sum(node_R) / len(node_R) * 2.
         cx = sum([pt[0] for pt in node_pos.itervalues()]) / len(node_pos)
         cy = sum([pt[1] for pt in node_pos.itervalues()]) / len(node_pos)
         node_ref = iter(node_pos).next()
         parent = node_ref.getparent()
         box = simpleprimitive.box(parent, cx, cy, size, size,
                                   {"fill": simplestyle.svgcolors["blue"]})
         box.set("id", self.uniqueId("rect"))
         angles = [(angle(node_pos[node_ref], pt, (cx, cy)), node)
                   for node, pt in node_pos.iteritems()]
         angles.sort()
         nb = len(angles)
         for i in xrange(nb):
             con = simpleprimitive.connect(
                 parent, angles[i][1], angles[(i + 1) % nb][1],
                 {"stroke": simplestyle.svgcolors["magenta"]})
             if con is not None:
                 con.set("id", self.uniqueId("con"))
         for node in node_pos:
             con = simpleprimitive.connect(
                 parent, box, node,
                 {"stroke": simplestyle.svgcolors["green"]})
             con.set("id", self.uniqueId("con"))
     else:
         raise UserWarning("must select at least 3 elements")