double lang, index, done, offset_value, marker_count; double Flow[1]; double x[4],y[4]; double metric; object Obj[2]; double HideObj[2]; selection current_selection; point current_point; object current_object; object Mrk[2]; double temp; double do_counter, do_max, do_logic; double Var[0]; double Table[0]; initDefs() { ; } initCode() { ; } main() { double read; initDefs(); initCode(); init_xarc_array(); lang = get_language(); metric = unit_mode(); if ( (lang != 0) && ( (lang != 1) && ( (lang != 2) && ( (lang != 3) && ( (lang != 4) && ( (lang != 5) && ( (lang != 6) && ( (lang != 7))))))))) { lang=0; } //Insert Registration here while (!done) { if (index == 0) { Popup0(); } } if (Flow[0] == 0) { Flow0View1(); } if (Flow[0] == 1) { Flow0View2(); } if (Flow[0] == 0) { Flow0View1Objects(); } if (Flow[0] == 1) { Flow0View2Objects(); } current_selection=newselection("OBJECT"); for (temp=0; temp < 2; temp=temp+1) { if (Mrk[temp] != 0) { select(current_selection, Mrk[temp]); } } check_overlap(current_selection); deselect(current_selection); run_command("ZOOMALL"); } Backward0() { ; } Exclusion0(double item_index) { if (item_index == 0) { return 0; } if (item_index == 1) { return 0; } return 1; } NumberOfPopupOptions0() { double index, ret; ret = 0; for (index=0; index<2; index++) { if (Exclusion0(index)==0 ) { ret = ret+1; } } return ret; } MapPopupToFlow0(double popup) { double flow_index; flow_index = 0; for (flow_index = 0; flow_index <= 1; flow_index = flow_index + 1) { if (Exclusion0(flow_index) == 1) { popup = popup + 1; } else { if (popup == flow_index) { return flow_index; } } } return 0; } MapFlowToPopup0(double flow) { double skipped; double flow_index; flow_index = 0; skipped = 0; for (flow_index = 0; flow_index <= 1; flow_index = flow_index + 1) { if (Exclusion0(flow_index) == 1) { skipped = skipped + 1; } else { if (flow == flow_index) { return flow - skipped; } } } return 0; } Popup0() { if (NumberOfPopupOptions0() == 0) { Flow[0] = -1; index = index + 1; done = 1; return; } if (NumberOfPopupOptions0() == 1) { Flow[0] = MapFlowToPopup0(1); index = index + 1; done = 1; return; } if (lang == 0) { start_pict_dialog("Base"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 1) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 2) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 3) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 4) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 5) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 6) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } if (lang == 7) { start_pict_dialog("Base"); if (Exclusion0(0) == 0) add_pict_item("Square","rectangle.jpg"); if (Exclusion0(1) == 0) add_pict_item("Triangle","triangle.jpg"); run_pict("Done" ); Flow[0] = MapPopupToFlow0(get_pict_result()); index = index + 1; done = 1; } } Flow0View1() { do_counter=0; do_max=0; if (is_function("macgen_write")) { macgen_write("Flow0View1"); } Flow0View1Points(); } Flow0View1Points() { x[0] = 0 + 0 / 1 + 10; y[0] = 0 + 0 / 1 + 0; x[1] = x[0] + 0 / 1 + 0; y[1] = y[0] + 0 / 1 + 10; x[2] = x[1] + 0 / 1 + -10; y[2] = y[1] + 0 / 1 + 0; } Flow0View1Objects() { //Object Square if (HideObj[0] == 0) { Obj[0] = newobject("poly"); current_point=addpoint(0/2.540000,0/2.540000,"LINE"); current_point=addpoint(x[0]/2.540000,y[0]/2.540000,"LINE"); current_point=addpoint(x[1]/2.540000,y[1]/2.540000,"LINE"); current_point=addpoint(x[2]/2.540000,y[2]/2.540000,"LINE"); if (lang == 0) { name_object(Obj[0],"Square"); } if (lang == 1) { name_object(Obj[0],"Square"); } if (lang == 2) { name_object(Obj[0],"Square"); } if (lang == 3) { name_object(Obj[0],"Square"); } if (lang == 4) { name_object(Obj[0],"Square"); } if (lang == 5) { name_object(Obj[0],"Square"); } if (lang == 6) { name_object(Obj[0],"Square"); } if (lang == 7) { name_object(Obj[0],"Square"); } } } Flow0View2() { do_counter=0; do_max=0; if (is_function("macgen_write")) { macgen_write("Flow0View2"); } Flow0View2Points(); } Flow0View2Points() { x[0] = 0 + 0 / 1 + 10; y[0] = 0 + 0 / 1 + 0; x[1] = x[0] + 0 / 1 + 0; y[1] = y[0] + 0 / 1 + 10; x[2] = x[1] + 0 / 1 + -10; y[2] = y[1] + 0 / 1 + 0; x[3] = (x[2] + x[1]) / 2; y[3] = (y[2] + y[1]) / 2; } Flow0View2Objects() { //Object Triangle if (HideObj[1] == 0) { Obj[1] = newobject("poly"); current_point=addpoint(0/2.540000,0/2.540000,"LINE"); current_point=addpoint(x[0]/2.540000,y[0]/2.540000,"LINE"); current_point=addpoint(x[3]/2.540000,y[3]/2.540000,"LINE"); if (lang == 0) { name_object(Obj[1],"Triangle"); } if (lang == 1) { name_object(Obj[1],"Triangle"); } if (lang == 2) { name_object(Obj[1],"Triangle"); } if (lang == 3) { name_object(Obj[1],"Triangle"); } if (lang == 4) { name_object(Obj[1],"Triangle"); } if (lang == 5) { name_object(Obj[1],"Triangle"); } if (lang == 6) { name_object(Obj[1],"Triangle"); } if (lang == 7) { name_object(Obj[1],"Triangle"); } } } mark(double pass_index) { if (Obj[pass_index]==0) { return; } Obj[pass_index]=marker_piece(Obj[pass_index],1); Mrk[marker_count] = Obj[pass_index]; marker_count = marker_count + 1; } offset_mark(double pass_index, double value) { point pnt, test; double save_x, save_y; if (Obj[pass_index]==0) { current_selection=newselection("OBJECT"); return; } if (value != 0) { current_selection=newselection("OBJECT"); select(current_selection,Obj[pass_index]); sel_push(current_selection); var_push(value); run_command("OFFSET"); deselect(current_selection); Mrk[marker_count] = marker_piece(last_obj(),1); current_selection=newselection("OBJECT"); select(current_selection, Mrk[marker_count]); select(current_selection, Obj[pass_index]); marker_count = marker_count + 1; } else { Obj[pass_index]=marker_piece(Obj[pass_index],1); Mrk[marker_count] = Obj[pass_index]; current_selection=newselection("OBJECT"); select(current_selection, Mrk[marker_count]); marker_count = marker_count + 1; } } offset(double pass_index, double value) { point pnt, test; double save_x, save_y; if (Obj[pass_index]==0) { current_selection=newselection("OBJECT"); return; } if (value != 0) { current_selection=newselection("OBJECT"); select(current_selection,Obj[pass_index]); sel_push(current_selection); var_push(value); run_command("OFFSET"); deselect(current_selection); current_selection=newselection("OBJECT"); select(current_selection, last_obj()); select(current_selection, Obj[pass_index]); } else { current_selection=newselection("OBJECT"); select(current_selection, Obj[pass_index]); } } get_x(double index) { if (index < 0) return 0; return x[index]; } get_y(double index) { if (index < 0) return 0; return y[index]; } double t0[2], t1[2]; double ftc[2]; double xar[13], yar[13]; double rx, ry; arclength(double start, double corner, double end) { double ct, last_x, last_y; double a_dist; last_x = get_x(start); last_y = get_y(start); a_dist = 0; fts(start, corner, end, 0); for (ct = 1; ct < 12; ct = ct + 1) { fts(start, corner, end, ct); a_dist = a_dist + distance(rx, ry, last_x, last_y); last_x = rx; last_y = ry; } return a_dist; } ArcArcIntersect(double dest, double start, double corner, double end, double a2start, double a2corner, double a2end) { double success; success = arc_arc_intersect( get_x(start), get_y(start), get_x(corner), get_y(corner), get_x(end), get_y(end), get_x(a2start), get_y(a2start), get_x(a2corner), get_y(a2corner), get_x(a2end), get_y(a2end), 1 ); if (success) { x[dest] = getresultx(); y[dest] = getresulty(); } else { x[dest] = 0; y[dest] = 0; } } LineArcIntersect(double dest, double start, double corner, double end, double lstart, double lend) { double success; success = arc_line_intersect( get_x(start), get_y(start), get_x(corner), get_y(corner), get_x(end), get_y(end), get_x(lstart), get_y(lstart), get_x(lend), get_y(lend), 1 ); if (success) { x[dest] = getresultx(); y[dest] = getresulty(); } else { x[dest] = 0; y[dest] = 0; } } cont(double dest, double start, double end, double distance) { double ang; ang = angle( get_x(start), get_y(start), get_x(end), get_y(end) ); polar(get_x(end), get_y(end), ang, distance ); x[dest] = getresultx(); y[dest] = getresulty(); } Dart(double dest, double start, double end, double dist2, double dir) { double dist, ang, dx, dy, h; double xstart, ystart, xend, yend; xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); dx = xstart - xend; dy = ystart - yend; dist = sqrt(dx * dx + dy * dy); h = sqrt((dist * dist) + (dist2 / 2) * (dist2 / 2)); ang = atan(h, (dist2 / 2)); if (dir == 0) { ang = ang + angle(xstart, ystart, xend, yend); } else { ang = angle(xstart, ystart, xend, yend) - ang; } x[dest] = xstart + dist2 * cos(ang); y[dest] = ystart + dist2 * sin(ang); } LinePointDist(double dest, double line_start, double line_end, double from, double dist, double clockwise) { double calc_dist, ang; double xfrom, yfrom; xfrom = get_x(from); yfrom = get_y(from); LinePnt(dest, line_start, line_end, from); calc_dist = distance(xfrom, yfrom, x[dest], y[dest]); if (dist <= calc_dist) { // NOTE: If the line does not come with `dist` of the point, // place the result at the origin to indicate failure x[dest] = 0; y[dest] = 0; } else { calc_dist = sqrt(dist * dist - calc_dist * calc_dist); ang = angle(xfrom, yfrom, x[dest], y[dest]); if (clockwise == 1) { ang = ang + 3.14159 / 2; } else { ang = ang - 3.14159 / 2; } // NOTE: reuses the intermedate `dest` calculated by `LinePnt` x[dest] = x[dest] + calc_dist * cos(ang); y[dest] = y[dest] + calc_dist * sin(ang); } } LinePnt(double dest, double start, double end, double from) { double v2x, v2y; double v1x, v1y; double dot; double norm2; double xfrom, yfrom; double xstart, xend, ystart, yend; xfrom = get_x(from); yfrom = get_y(from); xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); v1x = xfrom - xstart; v1y = yfrom - ystart; v2x = xend - xstart; v2y = yend - ystart; dot = v1x * v2x + v1y * v2y; norm2 = sqrt(v2x * v2x + v2y * v2y); if (norm2 == 0) { x[dest] = xstart; y[dest] = ystart; } else { x[dest] = xstart + dot * v2x / (norm2 * norm2); y[dest] = ystart + dot * v2y / (norm2 * norm2); } } Mirror(double dest, double from, double start, double end) { double v2x, v2y; double v1x, v1y; double dot; double norm2; double xfrom, yfrom; double xstart, xend, ystart, yend; xfrom = get_x(from); yfrom = get_y(from); xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); v1x = xfrom - xstart; v1y = yfrom - ystart; v2x = xend - xstart; v2y = yend - ystart; dot = v1x * v2x + v1y * v2y; norm2 = sqrt(v2x * v2x + v2y * v2y); if (norm2 == 0) { x[dest] = xstart; y[dest] = ystart; } else { x[dest] = xstart + dot * v2x / (norm2 * norm2); y[dest] = ystart + dot * v2y / (norm2 * norm2); } x[dest] = xfrom + 2 * (x[dest] - xfrom); y[dest] = yfrom + 2 * (y[dest] - yfrom); } OffsetDistance(double dest, double previous, double base, double next, double odistp, double odistn, double iside) { double prev_ang, next_ang, temp_ang; double sin_of_ang, sin_of_temp; double off_dist; double xbase, ybase, xprevious, yprevious; double xnext, ynext; xbase = get_x(base); ybase = get_y(base); xprevious = get_x(previous); yprevious = get_y(previous); xnext = get_x(next); ynext = get_y(next); prev_ang = angle(xbase, ybase, xprevious, yprevious); next_ang = angle(xbase, ybase, xnext,ynext); prev_ang = normalizeangle(prev_ang); next_ang = normalizeangle(next_ang); if (prev_ang > next_ang) { temp_ang = (prev_ang + next_ang) / 2; } else { temp_ang = (prev_ang + next_ang) / 2 + 3.14159; } if (iside > 0) { temp_ang = temp_ang + 3.14159; } temp_ang = normalizeangle(temp_ang); sin_of_ang = sin(prev_ang - temp_ang); if (sin_of_ang < 0) { sin_of_ang = -sin_of_ang; } if (sin_of_ang < 0.1) { off_dist = odistp; } else { off_dist = odistp / sin_of_ang; } polar(xbase, ybase, temp_ang, off_dist); x[dest] = getresultx(); y[dest] = getresulty(); if (sin_of_ang >= 0.1) { sin_of_temp = sin(next_ang - prev_ang); if (sin_of_temp < 0) { sin_of_temp = -sin_of_temp; } if ( sin_of_temp >= 0.1 ) { polar(x[dest], y[dest], prev_ang + (1 - iside) * 3.14159, (odistn - odistp) / sin_of_temp); x[dest] = getresultx(); y[dest] = getresulty(); } } } ResizeXY(double dest, double first, double second, double pass_xscale, double pass_yscale) { double dx, dy; double xfirst, yfirst, xsecond, ysecond; xfirst = get_x(first); yfirst = get_y(first); xsecond = get_x(second); ysecond = get_y(second); dx = xfirst - xsecond; dy = yfirst - ysecond; x[dest] = xfirst - dx * pass_xscale; y[dest] = yfirst - dy * pass_yscale; } right_ang(double dest, double start, double end, double dist, double clockwise) { double ang; double xstart, xend, ystart, yend; xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); ang = angle(xstart, ystart, xend, yend); if (clockwise) { ang = ang + 3.14159 / 2; } else { ang = ang - 3.14159 / 2; } x[dest] = xstart + dist * cos(ang); y[dest] = ystart + dist * sin(ang); } Rotate(double dest, double start, double end, double pass_angle) { double dist, ang; double xstart, xend, ystart, yend; xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); dist = distance(xstart, ystart, xend, yend); if (dist > 0.01) { ang = (pass_angle * 3.14159) / 180 + angle(xstart, ystart, xend, yend); } else { ang = 0; } x[dest] = xstart + dist * cos(ang); y[dest] = ystart + dist * sin(ang); } RotDist(double dest, double start, double end, double to_rot, double rdist) { double dist, ang, ang2; double xstart, xend, ystart, yend; double xto_rot, yto_rot; xstart = get_x(start); ystart = get_y(start); xend = get_x(end); yend = get_y(end); xto_rot = get_x(to_rot); yto_rot = get_y(to_rot); dist = distance(xstart, ystart, xend, yend); if (dist > 0.01) { ang2 = 2 * asin(rdist / (2 * dist)); ang = angle(xstart, ystart, xto_rot, yto_rot); dist = distance(xstart, ystart, xto_rot, yto_rot); x[dest] = xstart + dist * cos(ang + ang2); y[dest] = ystart + dist * sin(ang + ang2); } else { x[dest] = xto_rot; y[dest] = yto_rot; } } ResizeX(double dest, double first, double second, double pass_scale) { double dx, dy; dx = get_x(first) - get_x(second); dy = get_y(first) - get_y(second); x[dest] = get_x(first) - dx * pass_scale; y[dest] = get_y(first) - dy * pass_scale; } double A1, A2, B1, B2; //transformation vectors double sx, sy, cx, cy, ex, ey; fts(double start, double corner, double end, double pos) { if (pos<1) { rx=x[start]; ry=y[start]; } else { if (pos<2) { sx = x[start]; sy = y[start]; cx = x[corner]; cy = y[corner]; ex = x[end]; ey = y[end]; A1=cx - sx; A2=cy - sy; B1=cx - ex; B2=cy - ey; A1=-A1; B1=-B1; A2=-A2; B2=-B2; t0[0]=A1; t0[1]=B1; t1[0]=A2; t1[1]=B2; ftc[0]= cx + (t0[0] + t0[1]); ftc[1]= cy + (t1[0] + t1[1]); rx = t0[0]*(xar[pos])+t0[1]*(yar[pos])+ ftc[0]; ry = t1[0]*(xar[pos])+t1[1]*(yar[pos])+ ftc[1]; } else {if (pos>10) { rx=x[end]; ry=y[end]; } else { rx = t0[0]*(xar[pos])+t0[1]*(yar[pos])+ ftc[0]; ry = t1[0]*(xar[pos])+t1[1]*(yar[pos])+ ftc[1]; }}} } init_xarc_array() { double ang_start, ang_end, step, theta, ct; double XARC_PIECES; XARC_PIECES = 12; ang_start = -3.14159/2; ang_end= -3.14159; ct=0; step= (ang_end - ang_start)/(XARC_PIECES-1); for (theta=ang_start; ct < XARC_PIECES; theta = theta + step) { xar[ct] = cos(theta); yar[ct] = sin(theta); ct=ct+1; } } CheckToMetric(double pass) { if (metric==0) { pass=pass/2.540000; } return pass; } CheckFromMetric(double pass) { if (metric==0) { pass=pass*2.540000; } return pass; }