int do_draw(char *buff) { float xper, yper; if (2 != sscanf(buff, "%*s %f %f", &xper, &yper)) { G_warning(_("Problem parsing coordinates [%s]"), buff); return (-1); } if (mapunits) { /* skip check: clips segments if map coordinate is out of region. if( xper < D_get_u_west() || yper < D_get_u_south() || xper > D_get_u_east() || yper > D_get_u_north() ) return(-1); */ R_cont_abs((int)(D_u_to_d_col(xper) + 0.5), (int)(D_u_to_d_row(yper) + 0.5)); } else { if (xper < 0. || yper < 0. || xper > 100. || yper > 100.) return (-1); R_cont_abs(l + (int)(xper * xincr), b - (int)(yper * yincr)); } return (0); }
int Outline_box(int top, int bottom, int left, int right) { R_move_abs(left, top); R_cont_abs(left, bottom); R_cont_abs(right, bottom); R_cont_abs(right, top); R_cont_abs(left, top); return 0; }
/* DRAW A RECTANGULAR BOX WITH THICKNESS OF "THICK" */ void draw_box(int x0, int y0, int xp, int yp, int thick) { int i; /*PARAMETERS: x0 = leftmost position y0 = topmost position xp = rightmost position yp = bottommost position thick = thickness i = individual screen pixels */ for (i = 0; i <= thick; i++) { R_move_abs(x0 + i, y0 + i); R_cont_abs(x0 + i, yp - i); R_cont_abs(xp - i, yp - i); R_cont_abs(xp - i, y0 + i); R_cont_abs(x0 + i, y0 + i); R_move_abs(x0 - i, y0 - i); R_cont_abs(x0 - i, yp + i); R_cont_abs(xp + i, yp + i); R_cont_abs(xp + i, y0 - i); R_cont_abs(x0 - i, y0 - i); } R_flush(); return; }
int Downarrow(int top, int bottom, int left, int right) { R_move_abs((left + right) / 2, top); R_cont_abs((left + right) / 2, bottom); R_cont_rel((left - right) / 2, (top - bottom) / 2); R_move_abs((left + right) / 2, bottom); R_cont_rel((right - left) / 2, (top - bottom) / 2); return 0; }
int do_icon(char *buff) { double xper, yper; char type; int size; int ix, iy; if (4 != sscanf(buff, "%*s %c %d %lf %lf", &type, &size, &xper, &yper)) { G_warning(_("Problem parsing command [%s]"), buff); return (-1); } if (mapunits) { ix = (int)(D_u_to_d_col(xper) + 0.5); iy = (int)(D_u_to_d_row(yper) + 0.5); /* size in map units too? currently in percentage. use "size * D_get_u_to_d_yconv()" to convert? */ } else { if (xper < 0. || yper < 0. || xper > 100. || yper > 100.) return (-1); ix = l + (int)(xper * xincr); iy = b - (int)(yper * yincr); } switch (type & 0177) { case 'o': R_move_abs(ix - size, iy - size); R_cont_abs(ix - size, iy + size); R_cont_abs(ix + size, iy + size); R_cont_abs(ix + size, iy - size); R_cont_abs(ix - size, iy - size); break; case 'x': R_move_abs(ix - size, iy - size); R_cont_abs(ix + size, iy + size); R_move_abs(ix - size, iy + size); R_cont_abs(ix + size, iy - size); break; case '+': default: R_move_abs(ix, iy - size); R_cont_abs(ix, iy + size); R_move_abs(ix - size, iy); R_cont_abs(ix + size, iy); break; } return (0); }
/* DRAW A CIRCLE WITH THICKNESS OF "THICK" */ void draw_circle(int x0, int y0, int xp, int yp, int thick) { int i, j, xstart, ystart, x2, yr; double ang, xinc, yinc; /*PARAMETERS x0 = leftmost position of enclosing square y0 = topmost position of enclosing square xp = rightmost position of enclosing square yp = bottommost position of enclosing square thick = thickness in screen pixels for drawing lines i = index for incrementing process j = individual screen pixels x1 = x coordinate of point where circle touches enclosing square ang = angle in radians that is the angle to be moved in connecting a straight line segment to the previous location */ for (j = 0; j < thick; j++) { xstart = x0 + (xp - x0) / 2; ystart = y0 + j; ang = 0.049087385; R_move_abs(xstart, ystart); for (i = 1; i < 129; i++) { xinc = cos((double)i * ang / 2.0) * sin((double)i * ang / 2.0) * (double)(yp - y0 - 2 * j); yinc = sin((double)i * ang / 2.0) * sin((double)i * ang / 2.0) * (double)(yp - y0 - 2 * j); R_cont_abs(xstart + (int)xinc, ystart + (int)yinc); } } R_flush(); return; }
int D_cont_abs(int x, int y) { int clipped; x1 = curx; y1 = cury; x2 = x; y2 = y; curx = x; cury = y; if (!window_set) D_set_clip_window_to_map_window(); clipped = clip(); if (clipped >= 0) { R_move_abs(x1, y1); R_cont_abs(x2, y2); } return clipped; }
int analyze(void) { static int use = 1; static Objects objects[] = { MENU("DONE", done, &use), MENU("PRINT", to_printer, &use), MENU("FILE", to_file, &use), MENU("OVERLAY", do_warp, &use), MENU(delete_msg, delete_mark, &use), INFO("Transform->", &use), MENU(order_msg, get_order, &use), INFO(pick_msg, &use), OTHER(pick, &use), {0} }; int color; int tsize; int cury; int len; int line; int top, bottom, left, right, width, middle, nums; /* to give user a response of some sort */ Menu_msg("Preparing analysis ..."); /* * build a popup window at center of the screen. * 35% the height and wide enough to hold the report * */ /* height of 1 line, based on NLINES taking up 35% vertical space */ height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1; /* size of text, 80% of line height */ tsize = .8 * height; size = tsize - 2; /* fudge for computing pixels width of text */ /* indent for the text */ edge = .1 * height + 1; /* determine the length, in chars, of printed line */ FMT0(buf, 0); nums = strlen(buf) * size; FMT1(buf, 0.0, 0.0, 0.0); len = strlen(buf); middle = len * size; FMT2(buf, 0.0, 0.0, 0.0, 0.0); len += strlen(buf); /* width is for max chars plus sidecar for more/less */ width = len * size + nums + 2 * height; if ((SCREEN_RIGHT - SCREEN_LEFT) < width) width = SCREEN_RIGHT - SCREEN_LEFT; /* define the window */ bottom = VIEW_MENU->top - 1; top = bottom - height * NLINES; left = SCREEN_LEFT; right = left + width; middle += left + nums; nums += left; /* save what is under this area, so it can be restored */ R_panel_save(tempfile1, top, bottom + 1, left, right + 1); /* fill it with white */ R_standard_color(BACKGROUND); R_box_abs(left, top, right, bottom); right -= 2 * height; /* reduce it to exclude sidecar */ /* print messages in message area */ R_text_size(tsize, tsize); /* setup the more/less boxes in the sidecar */ R_standard_color(BLACK); less.top = top; less.bottom = top + 2 * height; less.left = right; less.right = right + 2 * height; Outline_box(less.top, less.bottom, less.left, less.right); more.top = bottom - 2 * height; more.bottom = bottom; more.left = right; more.right = right + 2 * height; Outline_box(more.top, more.bottom, more.left, more.right); /* * top two lines are for column labels * last two line is for overall rms error. */ nlines = NLINES - 3; first_point = 0; /* allocate predicted values */ xres = (double *)G_calloc(group.points.count, sizeof(double)); yres = (double *)G_calloc(group.points.count, sizeof(double)); gnd = (double *)G_calloc(group.points.count, sizeof(double)); /* compute transformation for the first time */ compute_transformation(); /* put head on the report */ cury = top; dotext(LHEAD1, cury, cury + height, left, middle, 0, BLACK); dotext(RHEAD1, cury, cury + height, middle, right - 1, 0, BLACK); cury += height; dotext(LHEAD2, cury, cury + height, left, middle, 0, BLACK); dotext(RHEAD2, cury, cury + height, middle, right - 1, 0, BLACK); cury += height; R_move_abs(left, cury - 1); R_cont_abs(right, cury - 1); /* isolate the sidecar */ R_move_abs(right, top); R_cont_abs(right, bottom); /* define report box */ report.top = cury; report.left = left; report.right = right; /* lets do it */ pager = 1; while (1) { R_text_size(tsize, tsize); line = 0; curp = first_point; cury = top + 2 * height; while (1) { if (line >= nlines || curp >= group.points.count) break; line++; if (!delete_mode) color = BLACK; else color = BLUE; if (group.equation_stat > 0 && group.points.status[curp] > 0) { /* color = BLACK; */ FMT1(buf, xres[curp], yres[curp], gnd[curp]); if (curp == xmax || curp == ymax || curp == gmax) color = RED; dotext(buf, cury, cury + height, nums, middle, 0, color); } else if (group.points.status[curp] > 0) dotext("?", cury, cury + height, nums, middle, 1, color); else dotext("not used", cury, cury + height, nums, middle, 1, color); if (pager) { FMT0(buf, curp + 1); dotext(buf, cury, cury + height, left, nums, 0, color); FMT2(buf, group.points.e1[curp], group.points.n1[curp], group.points.e2[curp], group.points.n2[curp]); dotext(buf, cury, cury + height, middle, right - 1, 0, color); } cury += height; curp++; } report.bottom = cury; downarrow(&more, curp < group.points.count ? color : BACKGROUND); uparrow(&less, first_point > 0 ? color : BACKGROUND); R_standard_color(BACKGROUND); R_box_abs(left, cury, right - 1, bottom); if (group.equation_stat < 0) { if (group.equation_stat == -1) { color = RED; strcpy(buf, "Poorly placed control points"); } else { if (group.equation_stat == -2) G_fatal_error("NOT ENOUGH MEMORY"); else G_fatal_error("PARAMETER ERROR"); } } else if (group.equation_stat == 0) { color = RED; strcpy(buf, "No active control points"); } else { color = BLACK; sprintf(buf, "Overall rms error: %.2f", rms); } dotext(buf, bottom - height, bottom, left, right - 1, 0, color); R_standard_color(BLACK); R_move_abs(left, bottom - height); R_cont_abs(right - 1, bottom - height); pager = 0; which = -1; if (Input_pointer(objects) < 0) break; display_points(1); } /* all done. restore what was under the window */ right += 2 * height; /* move it back over the sidecar */ R_standard_color(BACKGROUND); R_box_abs(left, top, right, bottom); R_panel_restore(tempfile1); R_panel_delete(tempfile1); R_flush(); G_free(xres); G_free(yres); G_free(gnd); I_put_control_points(group.name, &group.points); display_points(1); return 0; /* return but don't QUIT */ }
int draw_scale(char *save, int toptext, int size) { double meters; double line_len; int incr; int x_pos, y_pos; int t, b, l, r; int pt, pb, pl, pr; int i; int xarr[5], yarr[5]; double seg_len; const struct scale *scales = all_scales[use_feet]; /* Establish text size */ D_get_screen_window(&t, &b, &l, &r); R_set_window(t, b, l, r); R_text_size(size, size); x_pos = (int)(east * (r - l) / 100.); y_pos = (int)(north * (b - t) / 100.); if (draw == 1) { int w, h; w = 30; h = 17 + 2 * w; pl = x_pos; pt = y_pos; pr = x_pos + w + 2; /* 1 pixel margin for both sides */ pb = y_pos + h + 2; /* 1 pixel margin for both sides */ if (save) R_panel_save(save, pt, pb, pl, pr); if (do_background) { D_raster_use_color(color1); R_box_abs(pl, pt, pr, pb); } /* Draw legend */ D_raster_use_color(color2); R_move_abs(pl + w / 2 + 1, pt + 17 + 1); xarr[0] = 0; yarr[0] = 0; xarr[1] = -w / 2; yarr[1] = 2 * w; xarr[2] = w / 2; yarr[2] = -w / 2; xarr[3] = 0; yarr[3] = -1.5 * w; R_polyline_rel(xarr, yarr, 4); xarr[1] = -xarr[1]; xarr[2] = -xarr[2]; R_polygon_rel(xarr, yarr, 4); /* actual text width is 81% of size? from d.legend */ R_move_abs((int)(pl + w / 2 - 7 * .81), pt + 14); R_text("N"); R_stabilize(); return 0; } meters = D_get_u_east() - D_get_u_west(); meters *= G_database_units_to_meters_factor(); /* find the right scale */ for (incr = 0; incr < NUMSCALES; incr++) { if (meters <= scales[incr].limit) break; } if (!incr) return (-1); /* beyond the maximum just make the longest scale narrower */ if (incr >= NUMSCALES) incr = NUMSCALES - 1; line_len = D_get_u_to_d_xconv() * scales[incr].size / G_database_units_to_meters_factor(); seg_len = line_len / scales[incr].seg; /* work around round off */ line_len = ((int)seg_len) * scales[incr].seg; /* Blank out area with background color */ if (toptext) { pr = x_pos + 35 + (int)line_len; pt = y_pos - 15; if (pt < t) pt = t; } else { pr = x_pos + 35 + (int)line_len + size * strlen(scales[incr].name); pt = y_pos + 0; if (pt < t) pt = t; } pb = y_pos + 30; if (pb > b) pb = b; pl = x_pos + 0; if (pl < l) pl = l; pr = pr; if (pr > r) pr = r; if (save) R_panel_save(save, pt, pb, pl, pr); if (do_background) { D_raster_use_color(color1); R_box_abs(pl, pt, pr, pb); } /* Draw legend */ D_raster_use_color(color2); if (draw != 2) { R_move_abs(x_pos + 5, y_pos + 20); R_cont_rel(0, -10); R_cont_rel(10, 10); R_cont_rel(0, -10); R_move_rel(-5, 14); R_cont_rel(0, -17); R_cont_rel(-2, -0); R_cont_rel(2, -2); R_cont_rel(2, 2); R_cont_rel(-2, -0); } if (draw == 2) { R_move_abs(x_pos + 25 - draw * 10, y_pos + 17); /* actual width is line_len-1+1=line_len and height is 7+1=8 */ R_cont_rel((int)line_len - 1, 0); R_cont_rel(0, -7); R_cont_rel((int)(line_len * -1 + 1), 0); R_cont_rel(0, 7); R_move_rel(0, 1 - 4); for (i = 1; i <= scales[incr].seg; i++) { xarr[0] = 0; yarr[0] = 0; xarr[1] = (int)seg_len; yarr[1] = 0; xarr[2] = 0; yarr[2] = (i % 2 ? -4 : 4); xarr[3] = (int)-seg_len; yarr[3] = 0; xarr[4] = 0; yarr[4] = (i % 2 ? 4 : -4); /* width is seg_len and height is 4 */ R_polygon_rel(xarr, yarr, 4); R_move_rel((int)seg_len, 0); } } else if (do_bar) { R_move_abs(x_pos + 25, y_pos + 17); /* actual width is line_len-1+1=line_len and height is 4+1=5 */ R_cont_rel((int)line_len - 1, 0); R_cont_rel(0, -4); R_cont_rel((int)(line_len * -1 + 1), 0); R_cont_rel(0, 4); R_move_rel(0, 1); for (i = 1; i <= scales[incr].seg; i += 2) { /* width is seg_len and height is 5 */ R_box_rel((int)seg_len, -5); R_move_rel((int)(seg_len * 2), 0); } } else { /* draw simple line scale */ R_move_abs(x_pos + 25, y_pos + 5); R_cont_abs(x_pos + 25, y_pos + 25); R_move_abs(x_pos + 25, y_pos + 15); R_cont_abs(x_pos + 25 + (int)line_len, y_pos + 15); R_move_abs(x_pos + 25 + (int)line_len, y_pos + 5); R_cont_abs(x_pos + 25 + (int)line_len, y_pos + 25); } if (toptext) { R_move_abs(x_pos + 25 - draw * 10 + (int)(line_len / 2. - strlen(scales[incr].name) * size * 0.81 / 2), y_pos); R_text(scales[incr].name); } else { R_move_abs(x_pos + 35 - draw * 10 + (int)line_len, y_pos + 20); R_text(scales[incr].name); } R_stabilize(); return (0); }
static void set_rgn(double *msc, char *name, char *name1, char *name2) { char reg_name[20]; int x0, y0, xp, yp, *x, *y, xstart, ystart, btn, d, method, meth; static int pts, rgn_cnt = 0; double dtmp, etmp; FILE *tmp; char *tempfile; /* get the name of the regions map */ if (!G_ask_cell_new(" ENTER THE NEW REGION MAP NAME:", reg_name)) return; /* allocate memory for storing the points along the boundary of each region */ x = (int *)G_malloc(100 * sizeof(int)); y = (int *)G_malloc(100 * sizeof(int)); tempfile = G_tempfile(); tmp = fopen(tempfile, "w"); back2: G_system("clear"); fprintf(stderr, "\n\n CHOOSE AN OPTION:\n\n"); fprintf(stderr, " Draw a region 1\n"); fprintf(stderr, " Quit drawing regions and return"); fprintf(stderr, "\n to setup options menu 2\n"); fprintf(stderr, " Change the color for drawing 3\n\n"); do { fprintf(stderr, " Which Number? "); numtrap(1, &etmp); if ((meth = fabs(etmp)) > 3 || meth < 1) { fprintf(stderr, "\n Choice must between 1-3; try again"); } } while (meth > 3 || meth < 1); if (meth == 2) return; if (meth == 3) { R_open_driver(); change_draw(); } if (meth == 1) { R_open_driver(); rgn_cnt = 0; } /* ask the user to outline a region */ back: G_system("clear"); ppoint(NULL, 0, 0, -1); fprintf(stderr, "\n PLEASE OUTLINE REGION # %d\n", (++rgn_cnt)); pbutton(0); pts = 0; x0 = 0; y0 = 0; /* get the points along the boundary of the region as they are drawn */ do { btn = 0; R_get_location_with_line(x0, y0, &xp, &yp, &btn); if (btn == 1) ppoint(msc, xp, yp, 0); else if (btn == 2) { if (!pts) { pbutton(1); R_move_abs(xp, yp); xstart = xp; ystart = yp; } x[pts] = xp * msc[0]; y[pts] = yp * msc[1]; ppoint(msc, xp, yp, (++pts)); x0 = xp; y0 = yp; R_cont_abs(x0, y0); } else if (btn == 3 && pts < 3) { fprintf(stderr, "\n\n Please digitize more than 2 boundary points\n\n"); } } while (btn != 3 || pts < 3); R_cont_abs(xstart, ystart); R_close_driver(); R_open_driver(); x[pts] = x[0]; y[pts] = y[0]; pts++; /* redisplay the menu and find out what to do next */ back1: G_system("clear"); fprintf(stderr, "\n\n CHOOSE AN OPTION:\n\n"); fprintf(stderr, " Draw another region 1\n"); fprintf(stderr, " Start over drawing regions 2\n"); fprintf(stderr, " Quit drawing and save the region map 3\n"); fprintf(stderr, " Quit drawing and don't save the region map 4\n"); fprintf(stderr, " Change the color for drawing 5\n\n"); do { fprintf(stderr, " Which Number? "); numtrap(1, &dtmp); if ((method = fabs(dtmp)) > 5 || method < 1) { fprintf(stderr, "\n Choice must between 1-5; try again"); } } while (method > 5 || method < 1); /* save the region and draw another */ if (method == 1) { save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 1); goto back; } /* start over */ else if (method == 2) { fclose(tmp); if (!(tmp = fopen(tempfile, "w"))) G_fatal_error ("Can't open temporary file for storing region info\n"); rgn_cnt = 0; R_close_driver(); paint_map(name, name1, name2); goto back2; } /* save the region and exit */ else if (method == 3) save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 2); /* change the color for drawing */ else if (method == 5) { change_draw(); goto back1; } R_close_driver(); G_free(x); G_free(y); unlink(tempfile); return; }