Ejemplo n.º 1
0
	def effect(self):
		if not len(self.selected) == 1:
			inkex.errormsg("You must select exactly 1 element.")
			return
		
		# Get script's values
		sensor_distance = self.options.sensor_distance		#defines where the lines are cut out
		arrow_size = self.options.line_thickness + 10
		self.gap = self.options.gap
		line_thickness = self.options.line_thickness
		
		# Get access to main SVG document element and get its dimensions.
		svg = self.document.getroot()
        
        # Create a new layer.
		layer = inkex.etree.SubElement(svg, 'g')
		layer.set(inkex.addNS('label', 'inkscape'), 'CurveLayer')
		layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
		
		converter = Converter()
        
		# from Inkscape svg to Path
		userInputObject = self.selected.values()[0]
		pathMask = Path(userInputObject)		
		
		degree = pathMask.getNumNodes()
		nodes = []
		points = []
		
		for i in range(0, degree):
			#Get the nodes from the control graph
			nodes.append(pathMask.getNodeXY(i))
		curve = Bezier(nodes)
		
		i = (100-sensor_distance) /1000.0
		for t in arange(0, 1+i, i):
			point = curve.point(t)
			points.append(point)
		
		#draw the bezier curve
		i = 0.005
		p0 = curve.point(0)
		for t in arange(0, 1, i):
			point = curve.point(t+i)
			self.draw_line(line_thickness, (p0[0], p0[1]), (point[0], point[1]), layer)
			p0 = curve.point(t)
		
		#cut out the sensors
		z = points[0]
		for p in points[1:]:
			self.calculatePoint(z[0],z[1],p[0],p[1],arrow_size,45, layer)
			z = p
			
		""" remove the line which describes the curve """
		for selected_element in self.selected.itervalues():
			self.remove(selected_element)
Ejemplo n.º 2
0
	def effect(self):
		if not len(self.selected) == 1:
			inkex.errormsg("You must select exactly 1 element.")
			return
		
		# Get script's values
		number_sensors = self.options.number_sensors
		sensor_size = self.options.sensor_size
		sensor_distance = self.options.sensor_distance
		bezier_type = self.options.bezier_type
		
		# Get access to main SVG document element and get its dimensions.
		svg = self.document.getroot()
        
        # Create a new layer.
		layer = inkex.etree.SubElement(svg, 'g')
		layer.set(inkex.addNS('label', 'inkscape'), 'CurveLayer')
		layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
		
		userInputObject = self.selected.values()[0]
		
		
		# from Inkscape svg to Path
		pathMask = Path(userInputObject)
		
		degree = pathMask.getNumNodes()
		if (bezier_type == 'cubic' and degree != 4) or (bezier_type == 'quatratic' and degree != 3):
			inkex.errormsg("The path is invalid. Either 3 or 4 points are allowed.")
		nodes = []
		points = []
		
		for i in range(0, degree):
			#Get the nodes from the control graph
			nodes.append(pathMask.getNodeXY(i))
			
		#Create Cubic/Quadratic Bezier with the control points
		if (bezier_type == 'cubic'):
			if (degree < 4):
				inkex.errormsg("The path is invalid. You need 4 points.")
			curve = CubicBezier(nodes[0], nodes[1], nodes[2], nodes[3])
		else:
			curve = QuadraticBezier(nodes[0], nodes[1], nodes[2])
		
		# triangle
		p1 = [0 , 0]
		p2 = [0 , sensor_size/2]
		p3 = [sensor_size , sensor_size/4]
		pts = ar([p3, p2, p1])
		#rotation point
		pr = [sensor_size/4, sensor_size/4]
		length = curve.length()
		offset = sensor_size * 0.25
		number_sensors = math.ceil(length / (sensor_size + offset))
		
		
		i = sensor_distance/1000.0
		tri0 = [[0, 0], [0, 1], [0.5, 0.5]]
		for j in np.arange(0, 1+i, i):
			
			#Calculation of slope and angle for rotation
			slope = curve.derivation(j)
			angle = angle_between(slope)
			if slope[1] < 0:
				angle = 2*pi - angle	
	
			point = curve.point(j)
			#DEBUGGING:draw squares without rotation to compare
			#self.draw_SVG_square((5,5), (point[0],point[1]), layer)
			points.append(point)
			ots = Rotate(pts,ar(pr),angle)
	
			#draw a triangle
			tri = [[point[0]+ots[0][0], point[1]+ots[0][1]] ,\
					[point[0]+ots[1][0], point[1]+ots[1][1]] ,\
					[point[0]+ots[2][0], point[1]+ots[2][1]] ]
			self.draw_triangle(tri, layer)