// Copyright (C) 1996 Leena L�hteenm�ki, Finland // Copyright (C) 2012 PatternMaker Software // 2011/11/04 //TBpants.mac //Boys' pants double x[300], y[300]; double current_point,ang; //VARIABLES double length,sp,sip,vy,aly,py,lsy, language, sv; point current_point; selection current_selection; object group_obj[200]; double index, done; object marker_array[20]; double marker_count, loop; double result; object current_object; double metric; main() { //testimitat vy=87; aly=90; length=104; sp=80.5; py=43; lsy=37; //ease vy=vy+1; aly=aly+4; language=get_language(); if ( language != 0 ) { language = 0; } if (language == 0) { check_reg(0, "Leena","MB_macros", "This macro needs to be properly installed before running it."); } if (is_function("unit_mode")==1) { metric = unit_mode(); } else { metric=2*pop_up("Units","Inches","Centimeters"); // 0 = inches, 2=cm } if (metric<1) { sv=3/8; vy=vy/2.54; aly=aly/2.54; length=length/2.54; sp=sp/2.54; py=py/2.54; lsy=lsy/2.54; } else { sv=1; } //Measurements table double read; read = 0; if (is_function("measure_table")==1) { if (measure_table("default_youths")==1) { read = 1; } } if (read==0) { if (is_function("start_picture_input")) { start_picture_input("BOY'S PANTS"); add_picture_input("Outside length", length, "m_trousers_outside_length"); add_picture_input("Inside length", sp, "m_trousers_inside_length"); add_picture_input("Waist circumference", vy, "m_waist_circumference_trousers"); add_picture_input("Hip circumference", aly, "m_hip_circumference"); add_picture_input("Knee circumference", py, "m_knee_circumference"); if (language == 0) { run_picture_input(); } } else { dialog_box("MEN'S PANTS - 1 of 1", "Outside length", length, "Inside length", sp, "Waist circumference", vy, "Hip circumference", aly, "Knee circumference", py); } } if (is_function("start_picture_input")) { start_picture_input("CUSTOM MEASUREMENTS"); add_picture_input("Cuff circumference",lsy, "m_cuff_circumference_trousers"); add_picture_input("Seam Allowance", sv, "meas_seamallow"); if (language == 0) { run_picture_input(); } } else { dialog_box("CUSTOM MEASUREMENTS", "Cuff circumference",lsy, "Seam Allowance",sv); } if (metric<1) { vy=vy*2.54; aly=aly*2.54; length=length*2.54; sp=sp*2.54; py=py*2.54; lsy=lsy*2.54; } //STARTING POINT x[0]=0; y[0]=0; //ETUHOUSU coord(0,1,0,0); coord(1,2,0,-length); coord(2,3,0,sp); center(2,3,4); y[4]=y[4]+6; coord(3,5,0,aly/20+3); coord(5,6,aly/4+1,0); coord(6,7,aly/20+1,0); center(5,7,8); x[9]=x[8]; y[9]=y[1]; x[10]=x[8]; y[10]=y[3]; x[11]=x[8]; y[11]=y[4]; x[12]=x[8]; y[12]=y[2]; x[13]=x[6]; y[13]=y[1]; x[14]=x[6]; y[14]=y[3]; coord(11,15,py/4,0); coord(11,16,-py/4,0); coord(12,17,lsy/4-1,0); coord(12,18,-lsy/4+1,0); //apuviiva vaakasuoraan oikealle coord(3,103,100,0); line_intersect(3,103,5,16,19); line_intersect(3,103,7,15,20); coord(16,116,-1,dist(16,19)/2); coord(15,115,1,dist(15,20)/2); coord(14,21,0,dist(14,20)/2); coord(13,22,-1,0); coord(22,23,-vy/4,0); coord(23,24,0,1); coord(6,25,0.5,0); //PR�SSIVIIVA group_obj[0] = newobject("POLY"); addpoint((x[9])/2.54, (y[9])/2.54, "LINE"); addpoint((x[12])/2.54, (y[12])/2.54, "LINE"); //ETUHOUSU group_obj[1] = newobject("poly"); addpoint(x[24]/2.54, y[24]/2.54, "xarc_start"); coord(5,124,0,dist(5,24)/2); addpoint(x[124]/2.54, y[124]/2.54, "xarc_corner"); addpoint(x[5]/2.54, y[5]/2.54, "line"); addpoint(x[19]/2.54, y[19]/2.54, "xarc_start"); addpoint(x[116]/2.54, y[116]/2.54, "xarc_corner"); addpoint(x[16]/2.54, y[16]/2.54, "line"); addpoint(x[18]/2.54, y[18]/2.54, "LINE"); addpoint(x[12]/2.54, y[12]/2.54, "LINE"); addpoint(x[17]/2.54, y[17]/2.54, "LINE"); addpoint(x[15]/2.54, y[15]/2.54, "xarc_start"); addpoint(x[115]/2.54, y[115]/2.54, "xarc_corner"); addpoint(x[20]/2.54, y[20]/2.54, "xarc_start"); addpoint(x[14]/2.54, y[14]/2.54, "xarc_corner"); addpoint(x[25]/2.54, y[25]/2.54, "LINE"); addpoint(x[22]/2.54, y[22]/2.54, "LINE"); addpoint(x[9]/2.54, y[9]/2.54, "LINE"); //TASKUNSUU cont(9,24,109,-7); linecirc(109,24,5,17,0,105); group_obj[2] = newobject("poly"); addpoint(x[109]/2.54, y[109]/2.54, "line"); addpoint(x[105]/2.54, y[105]/2.54, "line"); //TASKU group_obj[3] = newobject("poly"); addpoint(x[9]/2.54, y[9]/2.54, "line"); addpoint(x[8]/2.54, y[8]/2.54, "xarc_start"); addpoint(x[10]/2.54, (y[10]-5)/2.54, "xarc_corner"); addpoint(x[19]/2.54, y[19]/2.54, "line"); addpoint(x[5]/2.54, y[5]/2.54, "xarc_start"); addpoint(x[124]/2.54, y[124]/2.54, "xarc_corner"); addpoint(x[24]/2.54, y[24]/2.54, "line"); //SISATASKU group_obj[4] = newobject("poly"); addpoint(x[9]/2.54, y[9]/2.54, "line"); addpoint(x[8]/2.54, y[8]/2.54, "xarc_start"); addpoint(x[10]/2.54, (y[10]-5)/2.54, "xarc_corner"); addpoint(x[19]/2.54, y[19]/2.54, "line"); addpoint(x[105]/2.54, y[105]/2.54, "line"); addpoint(x[109]/2.54, y[109]/2.54, "line"); //VETOKETJUVARA coord(22,113,3,0); ang=angle(x[25],x[25],y[22],x[22])-angle(x[25],y[25],x[113],y[133]); rotate(133,25,ang); group_obj[5] = newobject("poly"); addpoint(x[25]/2.54, y[25]/2.54, "line"); addpoint((x[25]+3)/2.54, y[25]/2.54, "line"); addpoint(x[113]/2.54, y[113]/2.54, "line"); addpoint(x[22]/2.54, y[22]/2.54, "line"); //TAKAHOUSU //26)puuttuu //28)lantion kt, jossa aly/20="x" coord(8,28,aly/20+1,aly/20-1); //29)lantion sivu, jossa aly/20="x" coord(28,29,-aly/4,-(aly/20-1)); //30 puuttuu //31)polven sis�piste coord(15,31,2,0); //32)lahkeensuun sis�piste coord(17,32,2,0); //33)polven sivu, jossa 2=vakio coord(16,33,-2,0); //34)lahkeensuun sivu, jossa 2=vakio coord(18,34,-2,0); //35)puuttuu //36)vy�t�r�n kt, jossa 2*1.5=vakio ja aly/20="x" coord(9,36,1.5+1.5,aly/20-1.5); //37)vy�t�r�n sivu, jossa aly/20="x" ja +1=sivun korotusta coord(36,37,-vy/4,-(aly/20-1.5)+1); //38)haarakulman sis�piste, jossa aly/20="x" ja -1=takakaaren alennusta coord(20,38,aly/20,-1); //39)haarakulman toinen piste coord(20,39,0,-1); //40)haarakulman kulmapiste coord(39,40,-aly/20,0); //41)sivun kaartopiste coord(33,41,-1,dist(33,29)/2); //42)reiden kaartopiste coord(31,42,0,dist(31,38)/2); //PR�SSIVIIVA group_obj[6] = newobject("POLY"); addpoint((x[12]+aly/2)/2.54, (y[12])/2.54, "LINE"); addpoint((x[8]+aly/2)/2.54, (y[36]-1)/2.54, "LINE"); //TAKAHOUSU group_obj[7] = newobject("poly"); addpoint((x[32]+aly/2)/2.54, (y[32])/2.54, "line"); addpoint((x[31]+aly/2)/2.54, (y[31])/2.54, "xarc_start"); addpoint((x[42]+aly/2)/2.54, (y[42])/2.54, "XARC_CORNER"); addpoint((x[38]+aly/2)/2.54, (y[38])/2.54, "line"); addpoint((x[39]+aly/2)/2.54, (y[39])/2.54, "xarc_start"); addpoint((x[40]+aly/2)/2.54, (y[40])/2.54, "xarc_corner"); //addpoint((x[26]+aly/2)/2.54, (y[26])/2.54, "line"); addpoint((x[28]+aly/2)/2.54, (y[28])/2.54, "line"); addpoint((x[36]+aly/2)/2.54, (y[36])/2.54, "line"); addpoint((x[37]+aly/2)/2.54, (y[37])/2.54, "line"); addpoint((x[29]+aly/2)/2.54, (y[29])/2.54, "xarc_start"); addpoint((x[41]+aly/2)/2.54, (y[41])/2.54, "xarc_corner"); addpoint((x[33]+aly/2)/2.54, (y[33])/2.54, "line"); addpoint((x[34]+aly/2)/2.54, (y[34])/2.54, "line"); addpoint((x[12]+aly/2)/2.54, (y[12])/2.54, "line"); //VYOTARONAUHA group_obj[8] = newobject("poly"); addpoint((x[24])/2.54, (y[37]+4)/2.54, "line"); addpoint((x[24]+vy/2)/2.54, (y[37]+4)/2.54, "line"); addpoint((x[24]+vy/2)/2.54, (y[37]+4+7)/2.54, "line"); addpoint((x[24])/2.54, (y[37]+4+7)/2.54, "line"); if(sv>0) { offset_mark(1); select(current_selection,group_obj[0]); select(current_selection,group_obj[2]); select(current_selection,group_obj[3]); select(current_selection,group_obj[4]); select(current_selection,group_obj[5]); group(current_selection); deselect(current_selection); } else { mark(1); current_selection=newselection("OBJECT"); select(current_selection,group_obj[0]); select(current_selection,group_obj[1]); select(current_selection,group_obj[2]); select(current_selection,group_obj[3]); select(current_selection,group_obj[4]); select(current_selection,group_obj[5]); group(current_selection); deselect(current_selection); } if(sv>0) { offset_mark(7); select(current_selection,group_obj[6]); group(current_selection); deselect(current_selection); } else { mark(7); current_selection=newselection("OBJECT"); select(current_selection,group_obj[7]); select(current_selection,group_obj[6]); group(current_selection); deselect(current_selection); } if(sv>0) { offset_mark(8); group(current_selection); deselect(current_selection); } else { mark(8); } current_selection=newselection("OBJECT"); for (loop = 0; loop < 20; loop = loop + 1) { if (marker_array[loop] != 0) { select(current_selection, marker_array[loop]); } } check_overlap(current_selection); if (is_function("origin_arrange")==1) { origin_arrange(current_selection); } deselect(current_selection); if (is_function("set_marker")==1) { for (loop = 0; loop < 20; loop = loop + 1) { if (marker_array[loop] != 0) { set_marker(marker_array[loop], 0); } } } run_command("zoomall"); //LOPPU } coord(double orig, double dest, double xxx, double yyy) { x[dest]=x[orig]+xxx; y[dest]=y[orig]+yyy; } center(double one, double two, double result) { x[result]=(x[one]+x[two])/2; y[result]=(y[one]+y[two])/2; } dist(double p1, double p2) { return distance(x[p1],y[p1],x[p2],y[p2]); } line_intersect(double start1, double end1, double start2, double end2, double dest) { double tempx; double tempy; intersect(x[start1],y[start1],x[end1],y[end1],x[start2],y[start2],x[end2],y[end2],0); x[dest]=getresultx(); y[dest]=getresulty(); } cont(double cstart, double cend, double cdest, double cvdistanceance) { double ang; ang=angle(x[cstart], y[cstart], x[cend], y[cend]); polar(x[cend], y[cend], ang, cvdistanceance); x[cdest]=getresultx(); y[cdest]=getresulty(); } right_ang(double start, double end, double to_point, double dest) { double m,b; if (x[start]==x[end]) { x[dest]=x[end]; y[dest]=y[to_point]; } else { if (y[start]==y[end]) { x[dest]=x[to_point]; y[dest]=y[end]; } else { m=(y[start]-y[end])/(x[start]-x[end]); m=-1/m; b=y[to_point]-m*x[to_point]; intersect(x[start],y[start],x[end],y[end],x[to_point],y[to_point],0,b,0); x[dest]=getresultx(); y[dest]=getresulty(); } } } shift(double orig, double xxx, double yyy) { x[orig]=x[orig]+xxx; y[orig]=y[orig]+yyy; } /* rect (double x1, double y1, double x2, double y2) { newobject("poly"); addpoint( x1/2.54,y1/2.54,"LINE"); addpoint( x2/2.54,y1/2.54,"LINE"); addpoint( x2/2.54,y2/2.54,"LINE"); addpoint( x1/2.54,y2/2.54,"LINE"); } */ /* dot (double x, double y) { newobject("poly"); addpoint( x/2.54,y/2.54,"LINE"); } */ /* line (double x3, double y3, double x4,double y4) { newobject("poly"); addpoint( x3/2.54,y3/2.54,"LINE"); addpoint( x4/2.54,y4/2.54,"LINE"); } */ rotate(double rpoint,double rcenter, double rangle) { double vdistance, vang; vdistance=dist(rpoint, rcenter); vang=angle(x[rcenter],y[rcenter],x[rpoint],y[rpoint]); polar(x[rcenter],y[rcenter],vang+rangle,vdistance); x[rpoint]=getresultx(); y[rpoint]=getresulty(); } linecirc(double PA,double PB,double PC,double dradius,double which, double PD) { // PA = center of circle, PB and PC determine line, dradius is radius of // circle, "which" is 0 or 1 (which of 2 possible intersections) // PD is output point i.e. 4 means put results in Point 4. double mslope, dist0, dist1, dist2, xtemp; double tx, ty; //coordinates of Point T // Since we will use slope calculations, horizontal or vertical lines // have to be handled separately to avoid dividing by 0. xtemp = (x[PB]-x[PC])*(x[PB]-x[PC]); if (xtemp > 0) { // not vertical xtemp = (y[PB]-y[PC])*(y[PB]-y[PC]); if ( xtemp > 0) { // not horizontal mslope = (y[PC] - y[PB])/(x[PC] - x[PB]); // slope of line //plot a perpendicular line through pt. A // First, find any point on this line tx = x[PA] + 1; ty = y[PA] - 1/mslope; // Then intersection of the 2 lines (Point T) intersect(x[PA], y[PA], tx, ty, x[PB], y[PB], x[PC], y[PC], 0); tx = getresultx(); ty = getresulty(); dist1 = distance(x[PA], y[PA], tx, ty); // Here is a special function that calculates the third leg // of a right triangle. First two inputs give the two ends // of one short leg. The third input is the hypotenuse // (here, it equals the dradius of the circle) // Won't work if the line and circle don't intersect! dist2 = interceptline(0, dist1, dradius); // distance from T to // desired point P1 or P2 dist0 = sqrt(1+mslope*mslope); xtemp = dist2/dist0; if (which) { x[PD] = tx+xtemp; // first intersection point y[PD] = ty+ xtemp*mslope; } else { x[PD] = tx-xtemp; // second intersection point y[PD] = ty- xtemp*mslope; } } else // horizontal line { x[PD] = x[PD] = x[PB]; if (which) { y[PD] = y[PA] + interceptline(x[PA], x[PB], dradius); } else { y[PD] = y[PA] - interceptline(x[PA], x[PB], dradius); } } } else //vertical line { y[PD] = y[PD] = y[PB]; if (which) { x[PD] = x[PA] + interceptline(y[PA], y[PB], dradius); } else { x[PD] = x[PA] - interceptline(y[PA], y[PB], dradius); } } } mark(double pass_index) { group_obj[pass_index]=marker_piece(group_obj[pass_index],1); marker_array[marker_count] = group_obj[pass_index]; marker_count = marker_count + 1; } offset_mark(double pass_index) { point pnt, test; double save_x, save_y; current_selection=newselection("OBJECT"); select(current_selection,group_obj[pass_index]); sel_push(current_selection); var_push(sv); run_command("OFFSET"); deselect(current_selection); current_object=last_obj(); marker_array[marker_count] = marker_piece(current_object,1); current_selection=newselection("OBJECT"); select(current_selection, marker_array[marker_count]); select(current_selection, group_obj[pass_index]); marker_count = marker_count + 1; } Forward() { index = index + 1; if (index == 0) { done = 1; } } Backward() { index = index - 1; }