def effect(self): """ Draws as basic elliptical box, based on provided parameters """ # input sanity check error = False if min(self.options.height, self.options.width, self.options.depth) == 0: inkex.errormsg('Error: Dimensions must be non zero') error = True if self.options.cut_nr < 1: inkex.errormsg('Error: Number of cuts should be at least 1') error = True if (self.options.centralRibLid or self.options.centralRibBody) and self.options.cut_nr % 2 == 1: inkex.errormsg( 'Error: Central rib is only valid with an even number of cuts') error = True if self.options.unit not in self.knownUnits: inkex.errormsg('Error: unknown unit. ' + self.options.unit) error = True if error: exit() # convert units unit = self.options.unit H = self.unittouu(str(self.options.height) + unit) W = self.unittouu(str(self.options.width) + unit) D = self.unittouu(str(self.options.depth) + unit) thickness = self.unittouu(str(self.options.thickness) + unit) cutSpacing = self.unittouu(str(self.options.cut_dist) + unit) cutNr = self.options.cut_nr svg = self.document.getroot() docWidth = self.unittouu(svg.get('width')) docHeigh = self.unittouu(svg.attrib['height']) layer = doc.layer(svg, 'Elliptical Box') ell = doc.Ellipse(W, H) #body and lid lidAngleRad = self.options.lid_angle * 2 * pi / 360 lidStartAngle = pi / 2 - lidAngleRad / 2 lidEndAngle = pi / 2 + lidAngleRad / 2 lidLength = ell.distFromAngles(lidStartAngle, lidEndAngle) bodyLength = ell.distFromAngles(lidEndAngle, lidStartAngle) # do not put elements right at the edge of the page xMargin = 3 yMargin = 3 bodyNotches = _makeCurvedSurface(doc.Coordinate(xMargin, yMargin), bodyLength, D, cutSpacing, cutNr, thickness, layer, False, self.options.centralRibBody) lidNotches = _makeCurvedSurface( doc.Coordinate(xMargin, D + 2 * yMargin), lidLength, D, cutSpacing, cutNr, thickness, layer, not self.options.invert_lid_notches, self.options.centralRibLid) a1 = lidEndAngle # create elliptical sides sidesGrp = doc.group(layer) elCenter = doc.Coordinate(xMargin + thickness + W / 2, 2 * D + H / 2 + thickness + 3 * yMargin) # indicate the division between body and lid if self.options.invert_lid_notches: doc.draw_line( sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(ell.rAngle(lidStartAngle + pi)), greenStyle) doc.draw_line( sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(ell.rAngle(lidEndAngle + pi)), greenStyle) else: angleA = ell.angleFromDist(lidStartAngle, lidNotches[2]) angleB = ell.angleFromDist(lidStartAngle, lidNotches[-2]) doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(angleA + pi), greenStyle) doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(angleB + pi), greenStyle) _makeNotchedEllipse(elCenter, ell, lidEndAngle, thickness, bodyNotches, sidesGrp, False) _makeNotchedEllipse(elCenter, ell, lidStartAngle, thickness, lidNotches, sidesGrp, not self.options.invert_lid_notches) # ribs spacer = doc.Coordinate(0, 10) innerRibCenter = doc.Coordinate( xMargin + thickness + W / 2, 2 * D + 1.5 * (H + 2 * thickness) + 4 * yMargin) innerRibGrp = doc.group(layer) outerRibCenter = doc.Coordinate( 2 * xMargin + 1.5 * (W + 2 * thickness), 2 * D + 1.5 * (H + 2 * thickness) + 4 * yMargin) outerRibGrp = doc.group(layer) if self.options.centralRibLid: _makeNotchedEllipse(innerRibCenter, ell, lidStartAngle, thickness, lidNotches, innerRibGrp, False) _makeNotchedEllipse(outerRibCenter, ell, lidStartAngle, thickness, lidNotches, outerRibGrp, True) if self.options.centralRibBody: _makeNotchedEllipse(innerRibCenter + spacer, ell, lidEndAngle, thickness, bodyNotches, innerRibGrp, False) _makeNotchedEllipse(outerRibCenter + spacer, ell, lidEndAngle, thickness, bodyNotches, outerRibGrp, True) if self.options.centralRibLid or self.options.centralRibBody: doc.draw_text(sidesGrp, elCenter, 'side (duplicate this)') doc.draw_text(innerRibGrp, innerRibCenter, 'inside rib') doc.draw_text(outerRibGrp, outerRibCenter, 'outside rib')
def effect(self): """ Draws as basic elliptical box, based on provided parameters """ # input sanity check error = False if min(self.options.height, self.options.width, self.options.depth) == 0: inkex.errormsg('Error: Dimensions must be non zero') error = True if self.options.cut_nr < 1: inkex.errormsg('Error: Number of cuts should be at least 1') error = True if (self.options.centralRibLid or self.options.centralRibBody) and self.options.cut_nr % 2 == 1: inkex.errormsg('Error: Central rib is only valid with an even number of cuts') error = True if self.options.unit not in self.knownUnits: inkex.errormsg('Error: unknown unit. '+ self.options.unit) error = True if error: exit() # convert units unit = self.options.unit H = self.unittouu(str(self.options.height) + unit) W = self.unittouu(str(self.options.width) + unit) D = self.unittouu(str(self.options.depth) + unit) thickness = self.unittouu(str(self.options.thickness) + unit) cutSpacing = self.unittouu(str(self.options.cut_dist) + unit) cutNr = self.options.cut_nr svg = self.document.getroot() docWidth = self.unittouu(svg.get('width')) docHeigh = self.unittouu(svg.attrib['height']) layer = doc.layer(svg, 'Elliptical Box') ell = doc.Ellipse(W, H) #body and lid lidAngleRad = self.options.lid_angle * 2 * pi / 360 lidStartAngle = pi / 2 - lidAngleRad / 2 lidEndAngle = pi / 2 + lidAngleRad / 2 lidLength = ell.distFromAngles(lidStartAngle, lidEndAngle) bodyLength = ell.distFromAngles(lidEndAngle, lidStartAngle) # do not put elements right at the edge of the page xMargin = 3 yMargin = 3 bodyNotches = _makeCurvedSurface(doc.Coordinate(xMargin, yMargin), bodyLength, D, cutSpacing, cutNr, thickness, layer, False, self.options.centralRibBody) lidNotches = _makeCurvedSurface(doc.Coordinate(xMargin, D + 2 * yMargin), lidLength, D, cutSpacing, cutNr, thickness, layer, not self.options.invert_lid_notches, self.options.centralRibLid) a1 = lidEndAngle # create elliptical sides sidesGrp = doc.group(layer) elCenter = doc.Coordinate(xMargin + thickness + W / 2, 2 * D + H / 2 + thickness + 3 * yMargin) # indicate the division between body and lid if self.options.invert_lid_notches: doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(ell.rAngle(lidStartAngle + pi)), greenStyle) doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(ell.rAngle(lidEndAngle + pi)), greenStyle) else: angleA = ell.angleFromDist(lidStartAngle, lidNotches[2]) angleB = ell.angleFromDist(lidStartAngle, lidNotches[-2]) doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(angleA + pi), greenStyle) doc.draw_line(sidesGrp, elCenter, elCenter + ell.coordinateFromAngle(angleB + pi), greenStyle) _makeNotchedEllipse(elCenter, ell, lidEndAngle, thickness, bodyNotches, sidesGrp, False) _makeNotchedEllipse(elCenter, ell, lidStartAngle, thickness, lidNotches, sidesGrp, not self.options.invert_lid_notches) # ribs spacer = doc.Coordinate(0, 10) innerRibCenter = doc.Coordinate(xMargin + thickness + W / 2, 2 * D + 1.5 * (H + 2 *thickness) + 4 * yMargin) innerRibGrp = doc.group(layer) outerRibCenter = doc.Coordinate(2 * xMargin + 1.5 * (W + 2 * thickness) , 2 * D + 1.5 * (H + 2 * thickness) + 4 * yMargin) outerRibGrp = doc.group(layer) if self.options.centralRibLid: _makeNotchedEllipse(innerRibCenter, ell, lidStartAngle, thickness, lidNotches, innerRibGrp, False) _makeNotchedEllipse(outerRibCenter, ell, lidStartAngle, thickness, lidNotches, outerRibGrp, True) if self.options.centralRibBody: _makeNotchedEllipse(innerRibCenter + spacer, ell, lidEndAngle, thickness, bodyNotches, innerRibGrp, False) _makeNotchedEllipse(outerRibCenter + spacer, ell, lidEndAngle, thickness, bodyNotches, outerRibGrp, True) if self.options.centralRibLid or self.options.centralRibBody: doc.draw_text(sidesGrp, elCenter, 'side (duplicate this)') doc.draw_text(innerRibGrp, innerRibCenter, 'inside rib') doc.draw_text(outerRibGrp, outerRibCenter, 'outside rib')
def _makeCurvedSurface(topLeft, w, h, cutSpacing, hCutCount, thickness, parent, invertNotches=False, centralRib=False): group = doc.group(parent) width = doc.Coordinate(w, 0) height = doc.Coordinate(0, h) wCutCount = int(floor(w / cutSpacing)) if wCutCount % 2 == 0: wCutCount += 1 # make sure we have an odd number of cuts xCutDist = w / wCutCount xSpacing = doc.Coordinate(xCutDist, 0) ySpacing = doc.Coordinate(0, cutSpacing) cut = height / hCutCount - ySpacing plateThickness = doc.Coordinate(0, thickness) notchEdges = [0] topHCuts = [] bottomHCuts = [] for cutIndex in range(wCutCount): if (cutIndex % 2 == 1) != invertNotches: # make a notch here inset = plateThickness else: inset = doc.Coordinate(0, 0) # A-column of cuts aColStart = topLeft + xSpacing * cutIndex notchEdges.append((aColStart - topLeft).x) if cutIndex > 0: # no cuts at x == 0 doc.draw_line(group, aColStart, aColStart + cut / 2) for j in range(hCutCount - 1): pos = aColStart + cut / 2 + ySpacing + (cut + ySpacing) * j doc.draw_line(group, pos, pos + cut) doc.draw_line(group, aColStart + height - cut / 2, aColStart + height) # B-column of cuts, offset by half the cut length; these cuts run in the opposite direction bColStart = topLeft + xSpacing * cutIndex + xSpacing / 2 for j in reversed(range(hCutCount)): end = bColStart + ySpacing / 2 + (cut + ySpacing) * j start = end + cut if centralRib and hCutCount % 2 == 0 and cutIndex % 2 == 1: holeTopLeft = start + (ySpacing - plateThickness - xSpacing) / 2 if j == hCutCount // 2 - 1: start -= plateThickness / 2 doc.draw_line(group, holeTopLeft + plateThickness + xSpacing, holeTopLeft + plateThickness) doc.draw_line(group, holeTopLeft, holeTopLeft + xSpacing) elif j == hCutCount // 2: end += plateThickness / 2 if j == 0: # first row end += inset elif j == hCutCount - 1: # last row start -= inset doc.draw_line(group, start, end) #horizontal cuts (should be done last) topHCuts.append((aColStart + inset, aColStart + inset + xSpacing)) bottomHCuts.append((aColStart + height - inset, aColStart + height - inset + xSpacing)) # draw the outline for c in reversed(bottomHCuts): doc.draw_line(group, c[1], c[0]) doc.draw_line(group, topLeft + height, topLeft) for c in topHCuts: doc.draw_line(group, c[0], c[1]) doc.draw_line(group, topLeft + width, topLeft + width + height) notchEdges.append(w) return notchEdges
def _makeCurvedSurface(topLeft, w, h, cutSpacing, hCutCount, thickness, parent, invertNotches = False, centralRib = False): group = doc.group(parent) width = doc.Coordinate(w, 0) height = doc.Coordinate(0, h) wCutCount = int(floor(w / cutSpacing)) if wCutCount % 2 == 0: wCutCount += 1 # make sure we have an odd number of cuts xCutDist = w / wCutCount xSpacing = doc.Coordinate(xCutDist, 0) ySpacing = doc.Coordinate(0, cutSpacing) cut = height / hCutCount - ySpacing plateThickness = doc.Coordinate(0, thickness) notchEdges = [0] topHCuts = [] bottomHCuts = [] for cutIndex in range(wCutCount): if (cutIndex % 2 == 1) != invertNotches: # make a notch here inset = plateThickness else: inset = doc.Coordinate(0, 0) # A-column of cuts aColStart = topLeft + xSpacing * cutIndex notchEdges.append((aColStart - topLeft).x) if cutIndex > 0: # no cuts at x == 0 doc.draw_line(group, aColStart, aColStart + cut / 2) for j in range(hCutCount - 1): pos = aColStart + cut / 2 + ySpacing + (cut + ySpacing) * j doc.draw_line(group, pos, pos + cut) doc.draw_line(group, aColStart + height - cut / 2, aColStart + height) # B-column of cuts, offset by half the cut length; these cuts run in the opposite direction bColStart = topLeft + xSpacing * cutIndex + xSpacing / 2 for j in reversed(range(hCutCount)): end = bColStart + ySpacing / 2 + (cut + ySpacing) * j start = end + cut if centralRib and hCutCount % 2 == 0 and cutIndex % 2 == 1: holeTopLeft = start + (ySpacing - plateThickness - xSpacing) / 2 if j == hCutCount // 2 - 1: start -= plateThickness / 2 doc.draw_line(group, holeTopLeft + plateThickness + xSpacing, holeTopLeft + plateThickness) doc.draw_line(group, holeTopLeft, holeTopLeft + xSpacing) elif j == hCutCount // 2: end += plateThickness / 2 if j == 0: # first row end += inset elif j == hCutCount - 1: # last row start -= inset doc.draw_line(group, start, end) #horizontal cuts (should be done last) topHCuts.append((aColStart + inset, aColStart + inset + xSpacing)) bottomHCuts.append((aColStart + height - inset, aColStart + height - inset + xSpacing)) # draw the outline for c in reversed(bottomHCuts): doc.draw_line(group, c[1], c[0]) doc.draw_line(group, topLeft + height, topLeft) for c in topHCuts: doc.draw_line(group, c[0], c[1]) doc.draw_line(group, topLeft + width, topLeft + width + height) notchEdges.append(w) return notchEdges