Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Given a waist, crotch, outseam size and a tapering factor, produce svg files of the zipper pants patterns
import sys
import csv
import numpy as np
import matplotlib.pyplot as plt
import math
import svgwrite
from svgwrite import inch
#######################################################################
#
# June 2019
# Program to size John's pants. Given a waist, crotch belly
# button to small of back, and outseam measurement, this
# spits out a plot and a new pattern saved as svg files.
# The svg file can be brought into a program like Inkscape and printed out.
#
# Run by: python PythonPatternGrading.py PatternName1 PatternName2 WaistMeasurement CrotchMeasurement OutseamMeasurement TaperingFactor
# NOTE: tapering factor... 1 = no tapering (expand pantscuff as much as waist), 0 = taper (no extending pants cuff)
# NOTE: pattern must be a .prn file
#########################################################################
def main():
InputFileOne = "{}.prn".format(sys.argv[1])
OutputFileOne = "{}-{}-{}-{}-Taper{}.svg".format(sys.argv[1],
sys.argv[3],
sys.argv[4],
sys.argv[5],
sys.argv[6])
OutputFileCasingOne = "{}Casing-{}-{}-{}.svg".format(sys.argv[1],
sys.argv[3],
sys.argv[4],
sys.argv[5])
WaistMeasurement = float(sys.argv[3])
CrotchMeasurement = float(sys.argv[4])
OutseamMeasurement = float(sys.argv[5])
TaperingFactor = float(sys.argv[6])
returnValues = PatternGrading(InputFileOne,
OutputFileOne,
OutputFileCasingOne,
WaistMeasurement,
CrotchMeasurement,
OutseamMeasurement,
TaperingFactor)
arWaistOne = returnValues[0]
arCrotchOne = returnValues[1]
arInseamOne = returnValues[2]
arCuffOne = returnValues[3]
arOutseamOne = returnValues[4]
WaistDistanceOne = returnValues[5]
NewWaistDistanceOne = returnValues[6]
CrotchDistanceOne = returnValues[7]
NewCrotchDistanceOne = returnValues[8]
InseamDistanceOne = returnValues[9]
NewInseamDistanceOne = returnValues[10]
ShortsInseamDistanceOne = returnValues[11]
NewShortsInseamDistanceOne = returnValues[12]
OutseamDistanceOne = returnValues[13]
NewOutseamDistanceOne = returnValues[14]
NominalWaistFactor = returnValues[15]
InputFileTwo = "{}.prn".format(sys.argv[2])
OutputFileTwo = "{}-{}-{}-{}-Taper{}.svg".format(sys.argv[2],
sys.argv[3],
sys.argv[4],
sys.argv[5],
sys.argv[6])
OutputFileCasingTwo = "{}Casing-{}-{}-{}.svg".format(sys.argv[2],
sys.argv[3],
sys.argv[4],
sys.argv[5])
returnValues = PatternGrading(InputFileTwo,
OutputFileTwo,
OutputFileCasingTwo,
WaistMeasurement,
CrotchMeasurement,
OutseamMeasurement,
TaperingFactor)
arWaistTwo = returnValues[0]
arCrotchTwo = returnValues[1]
arInseamTwo = returnValues[2]
arCuffTwo = returnValues[3]
arOutseamTwo = returnValues[4]
WaistDistanceTwo = returnValues[5]
NewWaistDistanceTwo = returnValues[6]
CrotchDistanceTwo = returnValues[7]
NewCrotchDistanceTwo = returnValues[8]
InseamDistanceTwo = returnValues[9]
NewInseamDistanceTwo = returnValues[10]
ShortsInseamDistanceTwo = returnValues[11]
NewShortsInseamDistanceTwo = returnValues[12]
OutseamDistanceTwo = returnValues[13]
NewOutseamDistanceTwo = returnValues[14]
GetStats( arWaistOne,
arCrotchOne,
arInseamOne,
arCuffOne,
arOutseamOne,
arWaistTwo,
arCrotchTwo,
arInseamTwo,
arCuffTwo,
arOutseamTwo,
WaistDistanceOne,NewWaistDistanceOne,
CrotchDistanceOne,NewCrotchDistanceOne,
InseamDistanceOne,NewInseamDistanceOne,
ShortsInseamDistanceOne,NewShortsInseamDistanceOne,
OutseamDistanceOne,NewOutseamDistanceOne,
WaistDistanceTwo,NewWaistDistanceTwo,
CrotchDistanceTwo,NewCrotchDistanceTwo,
InseamDistanceTwo,NewInseamDistanceTwo,
ShortsInseamDistanceTwo,NewShortsInseamDistanceTwo,
OutseamDistanceTwo,NewOutseamDistanceTwo,
NominalWaistFactor)
def PatternGrading(filename,
outputname,
outputnameCasing,
WaistMeasurement,
CrotchMeasurement,
OutseamMeasurement,
TaperingFactor):
returnValues = ReadPantsPattern(filename)
NominalWaistInch = 25
NominalWaistTotal = 37.95
NominalWaistFactor = float(NominalWaistInch) / NominalWaistTotal
NominalCrotchInch = 24.89 - 2.*(5./8.)
NominalOutseamInch = 29
arWaist = returnValues[0]
arCrotch = returnValues[1]
arInseam = returnValues[2]
arCuff = returnValues[3]
arOutseam = returnValues[4]
# DEBUG Print out
#print("WAIST:",arWaist)
#print("CROTCH:",arCrotch)
#print("INSEAM:",arInseam)
WaistDistance,nothing = GetDistance( arWaist,False)
print("originalwaist: ",WaistDistance)
CrotchDistance,nothing = GetDistance( arCrotch,True )
InseamDistance,ShortsInseamDistance = GetDistance( arInseam,True )
CuffDistance,nothing = GetDistance(arCuff,True)
OutseamDistance,nothing = GetDistance(arOutseam,True)
# Extend waist by inches
dAdjustWaistByInch = (WaistMeasurement-NominalWaistInch)/4.
dAdjustCuffByInch = (WaistMeasurement-NominalWaistInch)/4. * TaperingFactor
returnValues = ExtendWaist( dAdjustWaistByInch,
dAdjustCuffByInch,
arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam)
arWaistAdjustedByWaist = returnValues[0]
arCrotchAdjustedByWaist = returnValues[1]
arInseamAdjustedByWaist = returnValues[2]
arCuffAdjustedByWaist = returnValues[3]
arOutseamAdjustedByWaist = returnValues[4]
#debug
#print("WAIST:",arWaist)
#print("WAISTADJUSTED:",arWaistAdjustedByWaist)
# Extend outseam (its already going to be increased by crotch !!)
dAdjustByInch = OutseamMeasurement - NominalOutseamInch - ((CrotchMeasurement - NominalCrotchInch) / 2.)
returnValues = ExtendOutseam( dAdjustByInch,
arWaistAdjustedByWaist,
arCrotchAdjustedByWaist,
arInseamAdjustedByWaist,
arCuffAdjustedByWaist,
arOutseamAdjustedByWaist)
arWaistAdjustedByWaistAndInseam = returnValues[0]
arCrotchAdjustedByWaistAndInseam = returnValues[1]
arInseamAdjustedByWaistAndInseam = returnValues[2]
arCuffAdjustedByWaistAndInseam = returnValues[3]
arOutseamAdjustedByWaistAndInseam = returnValues[4]
#debug
#print("CROTCH:",arWaist)
#print("CROTCHADJUSTED2:",arCrotchAdjustedByWaistAndInseam)
# Extend Crotch
dAdjustByInch = (CrotchMeasurement - NominalCrotchInch) / 2.
returnValues = ExtendCrotch( dAdjustByInch,
arWaistAdjustedByWaistAndInseam,
arCrotchAdjustedByWaistAndInseam,
arInseamAdjustedByWaistAndInseam,
arCuffAdjustedByWaistAndInseam,
arOutseamAdjustedByWaistAndInseam,
TaperingFactor)
arWaistAdjustedByWaistAndInseamAndCrotch = returnValues[0]
arCrotchAdjustedByWaistAndInseamAndCrotch = returnValues[1]
arInseamAdjustedByWaistAndInseamAndCrotch = returnValues[2]
arCuffAdjustedByWaistAndInseamAndCrotch = returnValues[3]
arOutseamAdjustedByWaistAndInseamAndCrotch = returnValues[4]
CrotchYAdjustmentAtCrotch = returnValues[5]
CrotchYAdjustmentAtCuff = returnValues[6]
#Taper Inseam
print("dAdjustWaistByInch",dAdjustWaistByInch)
print("CrotchYAdjustmentAtCrotch",CrotchYAdjustmentAtCrotch)
print("dAdjustCuffByInch",dAdjustCuffByInch)
print("CrotchYAdjustmentAtCuff",CrotchYAdjustmentAtCuff)
dAdjustCrotchInYByInch = dAdjustWaistByInch + CrotchYAdjustmentAtCrotch
dAdjustCuffInYByInch = dAdjustCuffByInch + CrotchYAdjustmentAtCuff
returnValues = TaperInseam( dAdjustCrotchInYByInch,
dAdjustCuffInYByInch,
arInseamAdjustedByWaistAndInseamAndCrotch)
arInseamAdjustedByTaper = returnValues
#debug
#print("CROTCH:",arWaist)
#print("CROTCHADJUSTED3:",arCrotchAdjustedByWaistAndInseamAndCrotch)
NewWaistDistance,nothing = GetDistance( arWaistAdjustedByWaistAndInseamAndCrotch,False )
print ("Waist,NewWaist Distance: ",WaistDistance,NewWaistDistance)
NewCrotchDistance,nothing = GetDistance( arCrotchAdjustedByWaistAndInseamAndCrotch,True )
print ("Crotch,NewCrotch Distance: ",CrotchDistance,NewCrotchDistance)
NewInseamDistance,NewShortsInseamDistance = GetDistance( arInseamAdjustedByTaper,True )
print ("Inseam,NewInseam Distance: ",InseamDistance,NewInseamDistance )
NewCuffDistance,nothing = GetDistance( arCuffAdjustedByWaistAndInseamAndCrotch,True )
#print "Cuff,NewCuff Distance: ",CuffDistance,NewCuffDistance
NewOutseamDistance,nothing = GetDistance( arOutseamAdjustedByWaistAndInseamAndCrotch,True )
print ("Outseam,NewOutseam Distance: ",OutseamDistance,NewOutseamDistance )
Plot( arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam)
#Plot( arWaistAdjustedByWaist,
# arCrotchAdjustedByWaist,
# arInseamAdjustedByWaist,
# arCuffAdjustedByWaist,
# arOutseamAdjustedByWaist)
#Plot( arWaistAdjustedByWaistAndInseam,
# arCrotchAdjustedByWaistAndInseam,
# arInseamAdjustedByWaistAndInseam,
# arCuffAdjustedByWaistAndInseam,
# arOutseamAdjustedByWaistAndInseam)
Plot( arWaistAdjustedByWaistAndInseamAndCrotch,
arCrotchAdjustedByWaistAndInseamAndCrotch,
arInseamAdjustedByTaper,
arCuffAdjustedByWaistAndInseamAndCrotch,
arOutseamAdjustedByWaistAndInseamAndCrotch)
plt.show()
#Get zipper location
counter = 0
found = 0
for thisPoint in arWaist:
if thisPoint[2] == 0 and found == 0:
found = 1
zipperYInch = arWaist[counter,1]
counter = counter + 1
returnValues = convertTo2dArray( arWaistAdjustedByWaistAndInseamAndCrotch,
arCrotchAdjustedByWaistAndInseamAndCrotch,
arInseamAdjustedByTaper,
arCuffAdjustedByWaistAndInseamAndCrotch,
arOutseamAdjustedByWaistAndInseamAndCrotch)
arWaist2d = returnValues[0]
arCrotch2d = returnValues[1]
arInseam2d = returnValues[2]
arCuff2d = returnValues[3]
arOutseam2d = returnValues[4]
#Get shorts x coord location
xCoordInch = 0
for thisPoint in arInseamAdjustedByTaper:
if thisPoint[2] == 3:
xCoordInch = thisPoint[0]
writesvg( arWaist2d,
arCrotch2d,
arInseam2d,
arCuff2d,
arOutseam2d,
outputname,
zipperYInch,
xCoordInch)
returnValues = BuildCasing( arWaistAdjustedByWaistAndInseamAndCrotch, 2 )
arTopCasing = returnValues[0]
arBottomCasing = returnValues[1]
arCenterLine = returnValues[2]
writeCasingsvg( arTopCasing,
arBottomCasing,
arCenterLine,
outputnameCasing)
return( arWaistAdjustedByWaistAndInseamAndCrotch,
arCrotchAdjustedByWaistAndInseamAndCrotch,
arInseamAdjustedByTaper,
arCuffAdjustedByWaistAndInseamAndCrotch,
arOutseamAdjustedByWaistAndInseamAndCrotch,
WaistDistance,NewWaistDistance,
CrotchDistance,NewCrotchDistance,
InseamDistance,NewInseamDistance,
ShortsInseamDistance, NewShortsInseamDistance,
OutseamDistance,NewOutseamDistance,
NominalWaistFactor)
#####################################################################
#
# Read Input routine to read in a set of points for waist, crotch, inseam
#
#####################################################################
def ReadPantsPattern( filename ):
firstWaist = True
firstCrotch = True
firstInseam = True
firstCuff = True
firstOutseam = True
with open(filename,"r") as file:
data = file.readlines()
for line in data:
words = line.split()
firstword = words[0]
firstcharacter = firstword[0]
#print firstcharacter
#WAIST
if firstcharacter == 'w':
if firstWaist == True:
firstWaist = False
#print ("Waist :",words)
words.remove(firstword)
arWaist = np.asarray(words,dtype=float)
iWaistColumn = len(arWaist)
WaistLength = float(words[0])
else:
words.remove(firstword)
#print (words)
nextWaistRow = np.asarray(words,dtype=float)
arWaist = np.append(arWaist,nextWaistRow)
#CROTCH
if firstcharacter == 'c':
if firstCrotch == True:
firstCrotch = False
#print ("Crotch :",words)
words.remove(firstword)
arCrotch = np.asarray(words,dtype=float)
iCrotchColumn = len(arCrotch)
CrotchLength = float(words[0])
else:
words.remove(firstword)
#print (words)
nextCrotchRow = np.asarray(words,dtype=float)
arCrotch = np.append(arCrotch,nextCrotchRow)
#INSEAM
if firstcharacter == 'i':
if firstInseam == True:
firstInseam = False
#print ("Inseam :",words)
words.remove(firstword)
arInseam = np.asarray(words,dtype=float)
iInseamColumn = len(arInseam)
InseamLength = float(words[0])
else:
words.remove(firstword)
#print (words)
nextInseamRow = np.asarray(words,dtype=float)
arInseam = np.append(arInseam,nextInseamRow)
#CUFF
if firstcharacter == 'p':
if firstCuff == True:
firstCuff = False
#print ("Cuff :",words)
words.remove(firstword)
arCuff = np.asarray(words,dtype=float)
iCuffColumn = len(arCuff)
CuffLength = float(words[0])
else:
words.remove(firstword)
#print (words)
nextCuffRow = np.asarray(words,dtype=float)
arCuff = np.append(arCuff,nextCuffRow)
#OUTSEAM
if firstcharacter == 'o':
if firstOutseam == True:
firstOutseam = False
#print ("Outseam :",words)
words.remove(firstword)
arOutseam = np.asarray(words,dtype=float)
iOutseamColumn = len(arOutseam)
OutseamLength = float(words[0])
else:
words.remove(firstword)
#print (words)
nextOutseamRow = np.asarray(words,dtype=float)
arOutseam = np.append(arOutseam,nextOutseamRow)
arWaistxy = np.reshape(arWaist,(-1,3))
arCrotchxy = np.reshape(arCrotch,(-1,3))
arInseamxy = np.reshape(arInseam,(-1,3))
arCuffxy = np.reshape(arCuff,(-1,3))
arOutseamxy = np.reshape(arOutseam,(-1,3))
return(
arWaistxy,
arCrotchxy,
arInseamxy,
arCuffxy,
arOutseamxy)
#####################################################################
#
# Input a set of points, calculate total distance from point to point
# Assume points are ordered correctly in either x or y
#
#####################################################################
def GetDistance( Points, bCountAllPoints ):
Distance = 0;
TotalDistance = 0;
PointOne = Points[0]
#print "first point: ",PointOne
for thisPoint in Points:
Distance = math.sqrt(pow(thisPoint[0]-PointOne[0],2) + pow(thisPoint[1]-PointOne[1],2))
if bCountAllPoints or thisPoint[2] < 1 :
TotalDistance = TotalDistance + Distance
PointOne = thisPoint
Distance = 0;
DistanceToDesiredPoint = 0;
PointOne = Points[0]
found = 0;
#print "first point: ",PointOne
for thisPoint in Points:
Distance = math.sqrt(pow(thisPoint[0]-PointOne[0],2) + pow(thisPoint[1]-PointOne[1],2))
if thisPoint[2] == 3 :
found = 1
DistanceToDesiredPoint = DistanceToDesiredPoint + Distance
else:
if found == 0:
DistanceToDesiredPoint = DistanceToDesiredPoint + Distance
PointOne = thisPoint
return(TotalDistance,DistanceToDesiredPoint)
########################################################################
#
# Given a new waist size, update the waist, crotch, and inseam y-locations
#
#######################################################################
def ExtendWaist( dAdjustWaistByInch,
dAdjustCuffByInch,
arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam):
arWaistAdjustedByWaist = np.zeros( (len(arWaist[:,0]),3) )
arCrotchAdjustedByWaist = np.zeros( (len(arCrotch[:,0]),3) )
arInseamAdjustedByWaist = np.zeros( (len(arInseam[:,0]),3) )
arCuffAdjustedByWaist = np.zeros( (len(arCuff[:,0]),3) )
arOutseamAdjustedByWaist = np.zeros( (len(arOutseam[:,0]),3) )
# start wih crotch -- just move it up equally by the new waist length
counter = 0
for thisPoint in arCrotch:
arCrotchAdjustedByWaist[counter,0] = thisPoint[0]
arCrotchAdjustedByWaist[counter,1] = thisPoint[1] + dAdjustWaistByInch
arCrotchAdjustedByWaist[counter,2] = thisPoint[2]
counter = counter + 1
# inseam -- same as crotch - just move it up equally by the new length
# DONT MOVE INSEAM -- APPLY TAPERING IN LATER
counter = 0
for thisPoint in arInseam:
arInseamAdjustedByWaist[counter,0] = thisPoint[0]
arInseamAdjustedByWaist[counter,1] = thisPoint[1] #+ dAdjustByInch
arInseamAdjustedByWaist[counter,2] = thisPoint[2]
counter = counter + 1
# waist is slightly different -
# find length and uniformly divide new length along y
# do not include points that should not move
iNumberPoints = GetNumberOfActivePoints( arWaist )
AdjustmentPerPoint = dAdjustWaistByInch / float( iNumberPoints )
counter = 0
counterOfDistance = 0
for thisPoint in arWaist:
if counter == 0:
arWaistAdjustedByWaist[counter,0] = thisPoint[0]
arWaistAdjustedByWaist[counter,1] = thisPoint[1]
arWaistAdjustedByWaist[counter,2] = thisPoint[2]
else:
if thisPoint[2] == 1:
arWaistAdjustedByWaist[counter,0] = thisPoint[0]
arWaistAdjustedByWaist[counter,1] = thisPoint[1]
arWaistAdjustedByWaist[counter,2] = thisPoint[2]
else:
arWaistAdjustedByWaist[counter,0] = thisPoint[0]
arWaistAdjustedByWaist[counter,1] = counterOfDistance*AdjustmentPerPoint + thisPoint[1]
arWaistAdjustedByWaist[counter,2] = thisPoint[2]
counterOfDistance = counterOfDistance + 1
counter = counter + 1
# Cuff is same as waist
iNumberPoints = GetNumberOfActivePoints( arCuff )
AdjustmentPerPoint = dAdjustCuffByInch / float(iNumberPoints)
counter = 0;
counterOfDistance = 0
for thisPoint in arCuff:
if counter == 0:
arCuffAdjustedByWaist[counter,0] = thisPoint[0]
arCuffAdjustedByWaist[counter,1] = thisPoint[1]
arCuffAdjustedByWaist[counter,2] = thisPoint[2]
else:
if thisPoint[2] < 1:
arCuffAdjustedByWaist[counter,0] = thisPoint[0]
arCuffAdjustedByWaist[counter,1] = counterOfDistance*AdjustmentPerPoint + thisPoint[1]
arCuffAdjustedByWaist[counter,2] = thisPoint[2]
counterOfDistance = counterOfDistance + 1
else:
arCuffAdjustedByWaist[counter,0] = thisPoint[0]
arCuffAdjustedByWaist[counter,1] = thisPoint[1]
arCuffAdjustedByWaist[counter,2] = thisPoint[2]
counter = counter + 1
# Outseam requires no adjustment
counter = 0
for thisPoint in arOutseam:
arOutseamAdjustedByWaist[counter,0] = thisPoint[0]
arOutseamAdjustedByWaist[counter,1] = thisPoint[1]
arOutseamAdjustedByWaist[counter,2] = thisPoint[2]
counter = counter + 1
return( arWaistAdjustedByWaist,
arCrotchAdjustedByWaist,
arInseamAdjustedByWaist,
arCuffAdjustedByWaist,
arOutseamAdjustedByWaist)
########################################################################
#
# Given a new inseam size, update the waist, crotch, inseam,
# cuff, and outseam x-locations
#
#######################################################################
def ExtendOutseam( dAdjustByInch,
arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam):
arWaistAdjustedByInseam = np.zeros( (len(arWaist[:,0]),3) )
arCrotchAdjustedByInseam = np.zeros( (len(arCrotch[:,0]),3) )
arInseamAdjustedByInseam = np.zeros( (len(arInseam[:,0]),3) )
arCuffAdjustedByInseam = np.zeros( (len(arCuff[:,0]),3) )
arOutseamAdjustedByInseam = np.zeros( (len(arOutseam[:,0]),3) )
# Crotch requires no adjustment
counter = 0
for thisPoint in arCrotch:
arCrotchAdjustedByInseam[counter,0] = thisPoint[0]
arCrotchAdjustedByInseam[counter,1] = thisPoint[1]
arCrotchAdjustedByInseam[counter,2] = thisPoint[2]
counter = counter + 1
# Waist requires no adjustment
counter = 0
for thisPoint in arWaist:
arWaistAdjustedByInseam[counter,0] = thisPoint[0]
arWaistAdjustedByInseam[counter,1] = thisPoint[1]
arWaistAdjustedByInseam[counter,2] = thisPoint[2]
counter = counter + 1
# inseam - find length and uniformly divide new length along x
AdjustmentPerPoint = dAdjustByInch / float( len(arInseam[:,0]) )
counter = 0;
for thisPoint in arInseam:
if counter == 0:
arInseamAdjustedByInseam[counter,0] = thisPoint[0]
arInseamAdjustedByInseam[counter,1] = thisPoint[1]
arInseamAdjustedByInseam[counter,2] = thisPoint[2]
else:
arInseamAdjustedByInseam[counter,0] = counter*AdjustmentPerPoint + thisPoint[0]
arInseamAdjustedByInseam[counter,1] = thisPoint[1]
arInseamAdjustedByInseam[counter,2] = thisPoint[2]
counter=counter+1
# cuff -- same as crotch - transpose it in x equally by the new length
counter = 0
for thisPoint in arCuff:
arCuffAdjustedByInseam[counter,0] = thisPoint[0] + dAdjustByInch
arCuffAdjustedByInseam[counter,1] = thisPoint[1]
arCuffAdjustedByInseam[counter,2] = thisPoint[2]
counter = counter + 1
# Outseam - find length and uniformly divide new length along x
AdjustmentPerPoint = dAdjustByInch / float( len(arOutseam[:,0]) )
counter = 0;
for thisPoint in arOutseam:
if counter == 0:
arOutseamAdjustedByInseam[counter,0] = thisPoint[0]
arOutseamAdjustedByInseam[counter,1] = thisPoint[1]
arOutseamAdjustedByInseam[counter,2] = thisPoint[2]
else:
arOutseamAdjustedByInseam[counter,0] = counter*AdjustmentPerPoint + thisPoint[0]
arOutseamAdjustedByInseam[counter,1] = thisPoint[1]
arOutseamAdjustedByInseam[counter,2] = thisPoint[2]
counter=counter+1
return( arWaistAdjustedByInseam,
arCrotchAdjustedByInseam,
arInseamAdjustedByInseam,
arCuffAdjustedByInseam,
arOutseamAdjustedByInseam)
########################################################################
#
# Given a new crotch size, update the waist, crotch, inseam,
# cuff, and outseam x-locations
#
#######################################################################
def ExtendCrotch( dAdjustByInch,
arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam,
TaperingFactor):
arWaistAdjustedByCrotch = np.zeros( (len(arWaist[:,0]),3) )
arCrotchAdjustedByCrotch = np.zeros( (len(arCrotch[:,0]),3) )
arInseamAdjustedByCrotch = np.zeros( (len(arInseam[:,0]),3) )
arCuffAdjustedByCrotch = np.zeros( (len(arCuff[:,0]),3) )
arOutseamAdjustedByCrotch = np.zeros( (len(arOutseam[:,0]),3) )
# Waist requires no adjustment
counter = 0
for thisPoint in arWaist:
arWaistAdjustedByCrotch[counter,0] = thisPoint[0]
arWaistAdjustedByCrotch[counter,1] = thisPoint[1]
arWaistAdjustedByCrotch[counter,2] = thisPoint[2]
counter = counter + 1
# crotch is a lot different -
# find length and uniformly divide new length along x
# do not include points that should not move
# save a little distance to move in y for curve
iNumberActivePoints = GetNumberOfActivePoints( arCrotch )
AdjustmentPerPoint = dAdjustByInch / float( iNumberActivePoints )
counterToMoveInY = len(arCrotch[:,0]) - 3
counter = 0
counterOfDistance = 0
counterOfYDistance = 0
yAdjustmentInch = 0
for thisPoint in arCrotch:
if counter == 0:
arCrotchAdjustedByCrotch[counter,0] = thisPoint[0]
arCrotchAdjustedByCrotch[counter,1] = thisPoint[1]
arCrotchAdjustedByCrotch[counter,2] = thisPoint[2]
else:
if thisPoint[2] < 1:
counterOfDistance = counterOfDistance + 1
arCrotchAdjustedByCrotch[counter,0] = counterOfDistance*AdjustmentPerPoint + thisPoint[0]
arCrotchAdjustedByCrotch[counter,1] = thisPoint[1]
arCrotchAdjustedByCrotch[counter,2] = thisPoint[2]
else:
if counter > counterToMoveInY:
counterOfYDistance = counterOfYDistance + 1
arCrotchAdjustedByCrotch[counter,0] = thisPoint[0] + dAdjustByInch
arCrotchAdjustedByCrotch[counter,1] = counterOfYDistance*AdjustmentPerPoint + thisPoint[1]
arCrotchAdjustedByCrotch[counter,2] = thisPoint[2]
yAdjustmentInch = yAdjustmentInch+AdjustmentPerPoint
else:
arCrotchAdjustedByCrotch[counter,0] = thisPoint[0] + dAdjustByInch
arCrotchAdjustedByCrotch[counter,1] = thisPoint[1]
arCrotchAdjustedByCrotch[counter,2] = thisPoint[2]
counter = counter + 1
# inseam - transpose it in x equally by the new length -- and move in y
#DONT MOVE IN Y -- SAVE THAT FOR TAPERING
counter = 0
for thisPoint in arInseam:
arInseamAdjustedByCrotch[counter,0] = thisPoint[0] + dAdjustByInch
arInseamAdjustedByCrotch[counter,1] = thisPoint[1] #+ yAdjustmentInch
arInseamAdjustedByCrotch[counter,2] = thisPoint[2]
counter = counter + 1
# cuff -- same as crotch - transpose it in x equally by the new length
# and add tiny y distance with tapering
yAdjustmentCuffInch = yAdjustmentInch * TaperingFactor
AdjustmentPerPoint = yAdjustmentCuffInch / float( len(arCuff[:,0]) )
counter = 0
for thisPoint in arCuff:
arCuffAdjustedByCrotch[counter,0] = thisPoint[0] + dAdjustByInch
arCuffAdjustedByCrotch[counter,1] = thisPoint[1] + counter*AdjustmentPerPoint
arCuffAdjustedByCrotch[counter,2] = thisPoint[2]
counter = counter + 1
# Outseam - find length and uniformly divide new length along x
AdjustmentPerPoint = dAdjustByInch / float( len(arOutseam[:,0]) )
counter = 0;
for thisPoint in arOutseam:
if counter == 0:
arOutseamAdjustedByCrotch[counter,0] = thisPoint[0]
arOutseamAdjustedByCrotch[counter,1] = thisPoint[1]
arOutseamAdjustedByCrotch[counter,2] = thisPoint[2]
else:
arOutseamAdjustedByCrotch[counter,0] = counter*AdjustmentPerPoint + thisPoint[0]
arOutseamAdjustedByCrotch[counter,1] = thisPoint[1]
arOutseamAdjustedByCrotch[counter,2] = thisPoint[2]
counter=counter+1
return( arWaistAdjustedByCrotch,
arCrotchAdjustedByCrotch,
arInseamAdjustedByCrotch,
arCuffAdjustedByCrotch,
arOutseamAdjustedByCrotch,
yAdjustmentInch,
yAdjustmentCuffInch)
########################################################################
#
# Taper the inseam based on the YAdjustment at the Crotch and
# the YAdjustment at the cuff
#
#######################################################################
def TaperInseam( dAdjustCrotchInYByInch,
dAdjustCuffInYByInch,
arInseam):
arInseamAdjustedTapered = np.zeros( (len(arInseam[:,0]),3) )
#Find inseam length in X
x1 = arInseam[0,0]
x2 = arInseam[-1,0]
InseamLength = x2-x1
print("Inseam Length",InseamLength,x1)
# inseam - transpose it in y with tapering
counter = 0
for thisPoint in arInseam:
xLocationFactor = 1. - ((thisPoint[0]-x1) / InseamLength)
yAdjustmentInch = dAdjustCuffInYByInch + xLocationFactor*(dAdjustCrotchInYByInch-dAdjustCuffInYByInch)
print("counter:",counter,thisPoint[0],xLocationFactor,yAdjustmentInch)
arInseamAdjustedTapered[counter,0] = thisPoint[0]
arInseamAdjustedTapered[counter,1] = thisPoint[1] + yAdjustmentInch
arInseamAdjustedTapered[counter,2] = thisPoint[2]
counter = counter + 1
#print("INSEAM:",arInseam)
#print("INSEAMTAPERED:",arInseamAdjustedTapered)
return( arInseamAdjustedTapered)
########################################################################
#
# Get stats
#
#######################################################################
def GetStats( arWaistOne,
arCrotchOne,
arInseamOne,
arCuffOne,
arOutseamOne,
arWaistTwo,
arCrotchTwo,
arInseamTwo,
arCuffTwo,
arOutseamTwo,
WaistDistanceOne,NewWaistDistanceOne,
CrotchDistanceOne,NewCrotchDistanceOne,
InseamDistanceOne,NewInseamDistanceOne,
ShortsInseamDistanceOne,NewShortsInseamDistanceOne,
OutseamDistanceOne,NewOutseamDistanceOne,
WaistDistanceTwo,NewWaistDistanceTwo,
CrotchDistanceTwo,NewCrotchDistanceTwo,
InseamDistanceTwo,NewInseamDistanceTwo,
ShortsInseamDistanceTwo,NewShortsInseamDistanceTwo,
OutseamDistanceTwo,NewOutseamDistanceTwo,
NominalWaistFactor):
#GetWaistStats
# From first pattern
waistDistanceOne,nothing = GetDistance( arWaistOne, 0 )
numberActivePoints = GetNumberOfActivePoints( arWaistOne)
if( numberActivePoints == len(arWaistOne[:,0]) ):
waistDistanceOne = 2 * (waistDistanceOne - 2*(5./8.) )
else:
waistDistanceOne = 2 * (waistDistanceOne - (5./8.))
# From second pattern
waistDistanceTwo,nothing = GetDistance( arWaistTwo, 0 )
numberActivePoints = GetNumberOfActivePoints( arWaistTwo)
if( numberActivePoints == len(arWaistTwo[:,0]) ):
waistDistanceTwo = 2 * (waistDistanceTwo - 2*(5./8.) )
else:
waistDistanceTwo = 2 * (waistDistanceTwo - (5./8.))
WaistDistance = waistDistanceOne + waistDistanceTwo
WaistDistance = WaistDistance * NominalWaistFactor
#GetCrotchStats
crotchDistanceOne,nothing = GetDistance(arCrotchOne,1)
crotchDistanceTwo,nothing = GetDistance(arCrotchTwo,1)
CrotchDistance = crotchDistanceOne + crotchDistanceTwo - 2.*(5./8.)
#GetOutseamStats
#outseamDistanceOne = GetDistance(arOutseamOne,1) - (5./8.)
#outseamDistanceTwo = GetDistance(arOutseamTwo,1) - (5./8.)
#GetInseamStats
inseamDistanceOne,shortsInseamDistanceOne = GetDistance(arInseamOne,1)
inseamDistanceTwo,shortsInseamDistanceTwo = GetDistance(arInseamTwo,1)
inseamDistanceOne = inseamDistanceOne - 2.*(5./8.)
inseamDistanceTwo = inseamDistanceTwo - 2.*(5./8.)
#Find x coord of shorts
found = 0
xShortsOne = 0
for thisPoint in arInseamOne:
if thisPoint[2] == 3:
xShortsOne = thisPoint[0]
xShortsTwo = 0
for thisPoint in arInseamTwo:
if thisPoint[2] == 3:
xShortsTwo = thisPoint[0]
hem = 1
#Get outseam at zipper
found = 0
for thisPoint in arWaistOne:
if thisPoint[2] < 1 and found == 0:
x1 = thisPoint[0] + 5./8.
y1 = thisPoint[1]
found = 1
found = 0
for thisPoint in arCuffOne:
if thisPoint[1] > y1 and found == 0:
x2 = thisPoint[0]
y2 = thisPoint[1]
found = 1
zipperDistanceOne = x2 - x1 - 5./8. - hem
print("x1 y1 x2 y2",x1,y1,x2,y2)
found = 0
for thisPoint in arWaistTwo:
if thisPoint[2] < 1 and found == 0:
x1 = thisPoint[0] + 5./8.
y1 = thisPoint[1]
found = 1
found = 0
for thisPoint in arCuffTwo:
if thisPoint[1] > y1 and found == 0:
x2 = thisPoint[0]
y2 = thisPoint[1]
found = 1
zipperDistanceTwo = x2 - x1 - 5./8. - hem
print("x1 y1 x2 y2",x1,y1,x2,y2)
print("#################################")
print("## STATS ##")
print("## WAIST: ",WaistDistance)
print("## CROTCH: ",CrotchDistance)
print("## INSEAM: ",inseamDistanceOne,inseamDistanceTwo)
print("## SHORTS: ",shortsInseamDistanceOne,shortsInseamDistanceTwo)
print("## OUTSEAM AT ZIPPER: ",zipperDistanceOne, zipperDistanceTwo)
print("#################################")
print("## WAISTONE: ",WaistDistanceOne,NewWaistDistanceOne,WaistDistanceOne-NewWaistDistanceOne)
print("## CROTCHONE: ",CrotchDistanceOne,NewCrotchDistanceOne,CrotchDistanceOne-NewCrotchDistanceOne)
print("## INSEAMONE: ",InseamDistanceOne,NewInseamDistanceOne,InseamDistanceOne-NewInseamDistanceOne)
print("## SHORTS: ",shortsInseamDistanceOne,NewShortsInseamDistanceOne,ShortsInseamDistanceOne-NewShortsInseamDistanceOne)
print("## SHORTS XCoordONE: ",xShortsOne)
print("## OUTSEAMONE: ",OutseamDistanceOne,NewOutseamDistanceOne,OutseamDistanceOne-NewOutseamDistanceOne)
print("## WAISTTWO: ",WaistDistanceTwo,NewWaistDistanceTwo,WaistDistanceTwo-NewWaistDistanceTwo)
print("## CROTCHTWO: ",CrotchDistanceTwo,NewCrotchDistanceTwo,CrotchDistanceTwo-NewCrotchDistanceTwo)
print("## INSEAMTWO: ",InseamDistanceTwo,NewInseamDistanceTwo,InseamDistanceTwo-NewInseamDistanceTwo)
print("## SHORTS: ",ShortsInseamDistanceTwo,NewShortsInseamDistanceTwo,ShortsInseamDistanceTwo-NewShortsInseamDistanceTwo)
print("## SHORTS XCoordTWO: ",xShortsTwo)
print("## OUTSEAMTWO: ",OutseamDistanceTwo,NewOutseamDistanceTwo,OutseamDistanceTwo-NewOutseamDistanceTwo)
########################################################################
#
# Get number of active points allowed to move
#
#######################################################################
def GetNumberOfActivePoints( arPoints):
iNumberOfPoints = 0
for thisPoint in arPoints:
if thisPoint[2] < 1:
iNumberOfPoints = iNumberOfPoints + 1
return(iNumberOfPoints)
########################################################################
#
# Build Casing -- the casing is just the waistband (to put elastic through)
#
# Start with waist band, add a thickness and done (mostly)
#
#######################################################################
def BuildCasing( arWaist,
casingThicknessInch ):
arTopCasing = np.zeros( (len(arWaist[:,0]),2) )
arBottomCasing = np.zeros( (len(arWaist[:,0]),2) )
arCenterline = np.zeros( (2,2) )
bFrontCasingWithZipper = 0
# set the top of the casing and check if this has a zipper flap -- if so it is the pants front
counter =0
for thisPoint in arWaist:
if thisPoint[2] == 1:
bFrontCasingWithZipper = 1
arTopCasing[counter,0]=thisPoint[0]
arTopCasing[counter,1] = thisPoint[1]
counter = counter + 1
print("TopCasing: ",arTopCasing)
# if this is the pants front:
# the casing that extends over the zipper flap should be straight
if bFrontCasingWithZipper ==1:
for thisPoint in arWaist:
if thisPoint[2] == 1:
x1 = thisPoint[0]
x2 = thisPoint[0] + casingThicknessInch
# got the last x1,x2 of the zipper
counter = 0
for thisPoint in arWaist:
if thisPoint[2] == 1:
arTopCasing[counter,0]=x1
counter = counter + 1
print("TopCasingZipper: ",arTopCasing)
if bFrontCasingWithZipper == 0:
arTopCasing = np.insert(arTopCasing,0,0,axis=0)
arTopCasing[0,0] = arTopCasing[1,0]
arBottomCasing = np.insert(arBottomCasing,0,0,axis=0)
print("TopCasingBack: ",arTopCasing)
counter = 0
for thisPoint in arTopCasing:
if counter == 0:
beginPoint = arTopCasing[counter]
endPoint = arTopCasing[counter+1]
vector = endPoint-beginPoint
unitVector = vector/np.linalg.norm(vector)
vecPerpendicular = vector
vecPerpendicular[0] = unitVector[1]
vecPerpendicular[1] = unitVector[0] * float(-1)
arBottomCasing[counter] = thisPoint + casingThicknessInch * vecPerpendicular
if counter == len(arTopCasing)-1:
beginPoint = arTopCasing[counter-1]
endPoint = arTopCasing[counter]
vector = endPoint-beginPoint
unitVector = vector/np.linalg.norm(vector)
vecPerpendicular = vector
vecPerpendicular[0] = unitVector[1]
vecPerpendicular[1] = unitVector[0] * float(-1)
arBottomCasing[counter] = thisPoint + casingThicknessInch * vecPerpendicular
print("BottomCasing Last: ",arBottomCasing[counter])
if counter > 0 and counter < (len(arTopCasing)-1):
beginPoint = arTopCasing[counter-1]
endPoint = arTopCasing[counter+1]
vector = endPoint-beginPoint
unitVector = vector/np.linalg.norm(vector)
vecPerpendicular = vector
vecPerpendicular[0] = unitVector[1]
vecPerpendicular[1] = unitVector[0] * float(-1)
arBottomCasing[counter] = thisPoint + casingThicknessInch * vecPerpendicular
counter = counter + 1
if bFrontCasingWithZipper == 0:
arBottomCasing[0,0] = arTopCasing[0,0] + casingThicknessInch
arBottomCasing[0,1] = 0
#set the center line - it is 5/8 from edge in Y
counter = 0
for thisPoint in arWaist:
if thisPoint[2] == 3:
centerCounter = counter
counter = counter + 1
arCenterline[0,0] = arTopCasing[-1,0]
arCenterline[0,1] = arTopCasing[-1,1] - 5./8.
arCenterline[1,0] = arBottomCasing[-1,0]
arCenterline[1,1] = arBottomCasing[-1,1] - 5./8.
print("Top Casing: ",arTopCasing)
print("Bottom Casing: ",arBottomCasing)
#plot TopCasing
maxTop = np.amax(arTopCasing)
arTopCasingx = arTopCasing[:,0]
arTopCasingy = arTopCasing[:,1]
plt.plot(arTopCasingx,arTopCasingy,'.')
#plot BottomCasing
maxBottom = np.amax(arBottomCasing)
arBottomCasingx = arBottomCasing[:,0]
arBottomCasingy = arBottomCasing[:,1]
plt.plot(arBottomCasingx,arBottomCasingy,'.')
plt.ylim(0,maxBottom)
plt.xlim(0,maxBottom)
plt.show()
return(arTopCasing,arBottomCasing,arCenterline)
########################################################################
#
# Plot
#
#######################################################################
def Plot( arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam):
#find the line that fits through the waist
arWaistx = arWaist[:,0]
arWaisty = arWaist[:,1]
WaistFit = np.polyfit(arWaistx,arWaisty,4)
PolyWaist = np.poly1d(WaistFit)
maxWaistx = np.amax(arWaistx)
maxWaisty = np.amax(arWaisty)
minWaistx = np.amin(arWaistx)
minWaisty = np.amin(arWaisty)
#find the line that fits through the crotch
arCrotchx = arCrotch[:,0]
arCrotchy = arCrotch[:,1]
CrotchFit = np.polyfit(arCrotchx,arCrotchy,4)
PolyCrotch = np.poly1d(CrotchFit)
maxCrotchx = np.amax(arCrotchx)
maxCrotchy = np.amax(arCrotchy)
minCrotchx = np.amin(arCrotchx)
minCrotchy = np.amin(arCrotchy)
#find the line that fits through the inseam
arInseamx = arInseam[:,0]
arInseamy = arInseam[:,1]
InseamFit = np.polyfit(arInseamx,arInseamy,4)
PolyInseam = np.poly1d(InseamFit)
maxInseamx = np.amax(arInseamx)
maxInseamy = np.amax(arInseamy)
minInseamx = np.amin(arInseamx)
minInseamy = np.amin(arInseamy)
#find the line that fits through the pantscuff
arCuffx = arCuff[:,0]
arCuffy = arCuff[:,1]
CuffFit = np.polyfit(arCuffx,arCuffy,4)
PolyCuff = np.poly1d(CuffFit)
maxCuffx = np.amax(arCuffx)
maxCuffy = np.amax(arCuffy)
minCuffx = np.amin(arCuffx)
minCuffy = np.amin(arCuffy)
#find the line that fits through the outseam
arOutseamx = arOutseam[:,0]
arOutseamy = arOutseam[:,1]
OutseamFit = np.polyfit(arOutseamx,arOutseamy,4)
PolyOutseam = np.poly1d(OutseamFit)
maxOutseamx = np.amax(arOutseamx)
maxOutseamy = np.amax(arOutseamy)
minOutseamx = np.amin(arOutseamx)
minOutseamy = np.amin(arOutseamy)
#plot
#plot waist
xWaistLimits = np.linspace(minWaistx,maxWaistx,100)
plt.plot(arWaistx,arWaisty,'.',xWaistLimits,PolyWaist(xWaistLimits),'-')
#plot crotch
xCrotchLimits = np.linspace(minCrotchx,maxCrotchx,100)
plt.plot(arCrotchx,arCrotchy,'.',xCrotchLimits,PolyCrotch(xCrotchLimits),'-')
#plot inseam
xInseamLimits = np.linspace(minInseamx,maxInseamx,100)
plt.plot(arInseamx,arInseamy,'.',xInseamLimits,PolyInseam(xInseamLimits),'-')
#plot cuff
xCuffLimits = np.linspace(minCuffx,maxCuffx,100)
plt.plot(arCuffx,arCuffy,'.',xCuffLimits,PolyCuff(xCuffLimits),'-')
#plot outseam
xOutseamLimits = np.linspace(minOutseamx,maxOutseamx,100)
plt.plot(arOutseamx,arOutseamy,'.',xOutseamLimits,PolyOutseam(xOutseamLimits),'-')
plt.axis('equal')
plt.ylim(0,20)
#plt.show()
########################################################################
#
# convert to an array which can convert to tuple
#
#######################################################################
def convertTo2dArray( arWaist,
arCrotch,
arInseam,
arCuff,
arOutseam):
#1st change arrays to 2d
arWaist2d = np.zeros( (len(arWaist[:,0]),2) )
arCrotch2d = np.zeros( (len(arCrotch[:,0]),2) )
arInseam2d = np.zeros( (len(arInseam[:,0]),2) )
arCuff2d = np.zeros( (len(arCuff[:,0]),2) )
arOutseam2d = np.zeros( (len(arOutseam[:,0]),2) )
#shift every point 1,1 just to keep it away from 0,0 for
#better printing
counter = 0
for thisPoint in arWaist:
arWaist2d[counter,0] = thisPoint[0] +1
arWaist2d[counter,1] = thisPoint[1] +1
counter = counter + 1
counter = 0
for thisPoint in arCrotch:
arCrotch2d[counter,0] = thisPoint[0] +1
arCrotch2d[counter,1] = thisPoint[1] +1
counter = counter + 1
counter = 0
for thisPoint in arInseam:
arInseam2d[counter,0] = thisPoint[0] +1
arInseam2d[counter,1] = thisPoint[1] +1
counter = counter + 1
counter = 0
for thisPoint in arCuff:
arCuff2d[counter,0] = thisPoint[0] +1
arCuff2d[counter,1] = thisPoint[1] +1
counter = counter + 1
counter = 0
for thisPoint in arOutseam:
arOutseam2d[counter,0] = thisPoint[0] +1
arOutseam2d[counter,1] = thisPoint[1] +1
counter = counter + 1
return(arWaist2d,
arCrotch2d,
arInseam2d,
arCuff2d,
arOutseam2d)
########################################################################
#
# create svg file
#
#######################################################################
def writesvg( arWaist2d,
arCrotch2d,
arInseam2d,
arCuff2d,
arOutseam2d,
outputname,
zipperYInch,
shortsXInch):
cuffMaximums=arCuff2d.max(axis=0)
inseamMaximums=arInseam2d.max(axis=0)
print ("Maximums: ",cuffMaximums)
width = cuffMaximums[0] + 1
height = inseamMaximums[1] + 1
w_str = "{}in".format(width)
h_str = "{}in".format(height)
dwg = svgwrite.Drawing(filename=outputname,
size = (w_str, h_str),
viewBox=("0 0 {} {}".format(width,height)),
debug=True)
#pattern
lines = dwg.add(dwg.g(stroke_width=.1, stroke='black', fill='none'))
lines.add(dwg.polyline([tuple(p) for p in arWaist2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arCrotch2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arInseam2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arCuff2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arOutseam2d.tolist()]))
#Add shorts line -- add 1 inch because we have a 1 inch border around the pattern
if shortsXInch > 0:
arEnd1 = np.zeros( (2,2) )
arEnd1[0,0] = shortsXInch + 1
arEnd1[0,1] = 0
arEnd1[1,0] = shortsXInch + 1
arEnd1[1,1] = height
lines = dwg.add(dwg.g(stroke_width=.1, stroke='black',stroke_dasharray="2,2", fill='none'))
lines.add(dwg.polyline([tuple(p) for p in arEnd1.tolist()]))
dwg.add(dwg.text('ShortsLine', insert=(shortsXInch, height/3.),style="writing-mode:tb;",font_size='.7px'))
#Add zipper placement line -- add 1 inch because we have a 1 inch border around the pattern
if zipperYInch > 0:
arEnd1 = np.zeros( (2,2) )
arEnd1[0,0] = 0
arEnd1[0,1] = zipperYInch + 1
arEnd1[1,0] = width
arEnd1[1,1] = zipperYInch + 1
lines = dwg.add(dwg.g(stroke_width=.1, stroke='black',stroke_dasharray="2,2", fill='none'))
lines.add(dwg.polyline([tuple(p) for p in arEnd1.tolist()]))
dwg.add(dwg.text('ZipperPlacementLine', insert=(5, zipperYInch),font_size='.7px'))
#Add Fabric Grain Line
lines = dwg.add(dwg.g(stroke_width=.1, stroke='black', fill='none'))
lines.add(dwg.polyline([(width/2.-5., height-height/3.), (width/2.+5., height-height/3.)]))
dwg.add(dwg.text("DirectionOfFabricGrain", insert=(width/2.-4., height - height/3.),font_size='.7px'))
#Add Name
dwg.add(dwg.text(outputname, insert=(width/4., height/2.),style="letter-spacing:.5;",font_size='1px'))
#grid every inch to line it up
grid = dwg.add(dwg.g(stroke_width=.01, stroke='green', fill='none'))
counter =0
while counter < width:
grid.add(dwg.line(
start=(counter, 0), end=(counter, height), stroke_linecap='square'))
counter = counter + 1
counter =0
while counter < height:
grid.add(dwg.line(
start=(0, counter), end=(width, counter), stroke_linecap='square'))
counter = counter + 1
dwg.save()
return()
########################################################################
#
# create svg file for casings
#
#######################################################################
def writeCasingsvg( arTopCasing2d,
arBottomCasing2d,
arCenterline,
outputname):
#shift every point 1,1 just to keep it away from 0,0 for
#better printing
counter = 0
for thisPoint in arTopCasing2d:
arTopCasing2d[counter,0] = thisPoint[0] +1
arTopCasing2d[counter,1] = thisPoint[1] +1
counter = counter + 1
totalCounter = counter
halfCounter = int(totalCounter / 2)
counter = 0
for thisPoint in arBottomCasing2d:
arBottomCasing2d[counter,0] = thisPoint[0] +1
arBottomCasing2d[counter,1] = thisPoint[1] +1
counter = counter + 1
counter = 0
for thisPoint in arCenterline:
arCenterline[counter,0] = thisPoint[0] +1
arCenterline[counter,1] = thisPoint[1] +1
counter = counter + 1
#1st add two lines for endcaps
arEnd1 = np.zeros( (2,2) )
arEnd2 = np.zeros( (2,2) )
arEnd1[0,0] = arTopCasing2d[0,0]
arEnd1[0,1] = arTopCasing2d[0,1]
arEnd1[1,0] = arBottomCasing2d[0,0]
arEnd1[1,1] = arBottomCasing2d[0,1]
arEnd2[0,0] = arTopCasing2d[-1,0]
arEnd2[0,1] = arTopCasing2d[-1,1]
arEnd2[1,0] = arBottomCasing2d[-1,0]
arEnd2[1,1] = arBottomCasing2d[-1,1]
topCasingMaximums=arTopCasing2d.max(axis=0)
bottomCasingMaximums=arBottomCasing2d.max(axis=0)
print ("Maximums: ",topCasingMaximums)
width = bottomCasingMaximums[0] + 1
height = bottomCasingMaximums[1] + 1
w_str = "{}in".format(width)
h_str = "{}in".format(height)
dwg = svgwrite.Drawing(filename=outputname,
size = (w_str, h_str),
viewBox=("0 0 {} {}".format(width,height)),
debug=True)
#pattern
lines = dwg.add(dwg.g(stroke_width=.1, stroke='black', fill='none'))
lines.add(dwg.polyline([tuple(p) for p in arTopCasing2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arBottomCasing2d.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arEnd1.tolist()]))
lines.add(dwg.polyline([tuple(p) for p in arEnd2.tolist()]))
#centerline
centerline = dwg.add(dwg.g(stroke_width=.04, stroke='black', fill='none'))
centerline.add(dwg.polyline([tuple(p) for p in arCenterline.tolist()]))
#Add Name
dwg.add(dwg.text(outputname, insert=(arTopCasing2d[halfCounter,0], height/2.),font_size='.3px'))
#Add Centerline
dwg.add(dwg.text("CenterLine", insert=(arCenterline[0,0], arCenterline[0,1]-.3),font_size='.3px'))
#Add Centerline instruction
dwg.add(dwg.text("Cut On Fold", insert=(arTopCasing2d[-1,0], arTopCasing2d[-1,1]-.3),font_size='.3px'))
#Add raw edge
xCircle = arBottomCasing2d[halfCounter,0]
yCircle = arBottomCasing2d[halfCounter,1]
dwg.add(dwg.circle(center=(xCircle,yCircle), r=.3, fill='red'))
dwg.add(dwg.text('FinishThisRawEdge', insert=(xCircle-.5,yCircle-.5),font_size='.3px'))
#grid every inch to line it up
grid = dwg.add(dwg.g(stroke_width=.01, stroke='green', fill='none'))
counter =0
while counter < width:
grid.add(dwg.line(
start=(counter, 0), end=(counter, height), stroke_linecap='square'))
counter = counter + 1
counter =0
while counter < height:
grid.add(dwg.line(
start=(0, counter), end=(width, counter), stroke_linecap='square'))
counter = counter + 1
dwg.save()
return()
############################
# Main Routine
############################
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment