Ejemplo n.º 1
0
Archivo: sample.c Proyecto: caomw/grass
/* 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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
int D_set_clip_window(int Top, int Bottom, int Left, int Right)
{
    /* make sure top is above bottom, left is left of right */
    if (Top > Bottom)
	swap(Top, Bottom);
    if (Left > Right)
	swap(Left, Right);

    /* make sure edges are within the true window edges */
    D_get_screen_window(&top, &bottom, &left, &right);
    Top = limit(top, Top, bottom);
    Bottom = limit(top, Bottom, bottom);
    Left = limit(left, Left, right);
    Right = limit(left, Right, right);

    /* set the window */
    top = Top;
    bottom = Bottom;
    left = Left;
    right = Right;

    window_set = 1;

    R_move_abs(left, top);

    return 0;
}
Ejemplo n.º 5
0
int Text(char *text, int top, int bottom, int left, int right, int edge)
{
    R_set_window(top, bottom, left, right);
    R_move_abs(left + edge, bottom - edge);
    R_text(text);
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);

    return 0;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
int do_move(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)
	R_move_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_move_abs(l + (int)(xper * xincr), b - (int)(yper * yincr));
    }

    return (0);
}
Ejemplo n.º 8
0
static int dotext(char *text, int top, int bottom, int left, int right,
		  int centered)
{
    R_text_size(text_size, text_size);
    R_move_abs(left + 1 + edge, bottom - 1 - edge);
    if (centered)
	R_move_rel((right - left - strlen(text) * size) / 2, 0);
    R_set_window(top, bottom, left, right);	/* for text clipping */
    R_text(text);
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);

    return 0;
}
Ejemplo n.º 9
0
Archivo: sample.c Proyecto: caomw/grass
/* 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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
Archivo: sample.c Proyecto: caomw/grass
/* FOR STRATIFIED RANDOM DISTRIBUTION, DRAW THE STRATA ON THE SCREEN */
static void draw_grid(int l, int t, int w_w, int w_l, int h_d, int v_d,
		      int starty, int startx, double colratio,
		      double rowratio)
{
    int j, k, l0, t0, itmp, dx, dy, initl, tmp;

    /* VARIABLES:
       k    = the remainder after dividing the screen width/height
       by the number of strata
       dx   = how many screen cols per stratum
       dy   = how many screen rows per stratum
       l0   = left side of screen + dx
       t0   = top of screen + dy
       w_w  = width of screen
       w_l  = height of screen
       h_d  = number of horizontal strata
       v_d  = number of vertical strata
     */

    R_open_driver();
    R_standard_color(D_translate_color("orange"));
    if (startx > 0) {
	dx = (int)((double)((int)(colratio *
				  ((int)
				   ((double)(w_w - startx) /
				    (double)(h_d)))) / colratio + 0.5));
	l0 = l + startx;
    }
    else {
	dx = (int)((double)((int)(colratio *
				  ((int)((double)(w_w) / (double)(h_d)))) /
			    colratio + 0.5));
	l0 = l;
    }
    if (starty > 0) {
	dy = (int)((double)((int)(rowratio *
				  ((int)
				   ((double)(w_l - starty) /
				    (double)(v_d)))) / rowratio + 0.5));

	t0 = t + starty;
    }
    else {
	dy = (int)((double)((int)(rowratio *
				  ((int)((double)(w_l) / (double)(v_d)))) /
			    rowratio + 0.5));
	t0 = t;
    }
    initl = l0;

    /* draw the vertical strata */

    for (j = 1; j <= h_d - 1; j++) {
	l0 += dx;
	R_move_abs(l0, t0);
	R_cont_rel(0, w_l - starty);
    }

    /* draw the horizontal strata */

    for (j = 1; j <= v_d - 1; j++) {
	t0 += dy;
	R_move_abs(initl, t0);
	R_cont_rel(w_w - startx, 0);
    }

    R_close_driver();
    return;
}
Ejemplo n.º 12
0
Archivo: sample.c Proyecto: caomw/grass
static void graph_unit(int t, int b, int l, int r, char *n1, char *n2,
		       char *n3, double *mx, int fmask)
{
    int x0 = 0, y0 = 0, xp, yp, ux[250], uy[250], u_w, u_l, btn = 0, k = 0,
	w_w = 0, w_l = 0, *row_buf, at, ab, al, ar, circle = 0,
	tmpw, tmpl, au_w, au_l, lap = 0, l0 = 0, r0 = 0, t0 = 0, b0 = 0;
    FILE *fp;
    double tmp, radius = 0.0;
    register int i, j;

    /*  VARIABLES:
       COORDINATES IN THIS ROUTINE ARE IN CELLS

       t    =       top row of sampling frame
       b    =       bottom row of sampling frame
       l    =       left col of sampling frame
       r    =       right col of sampling frame
       n1   =
       n2   =
       n3   =
       mx[0]        =       cols of region/width of screen
       mx[1]        =       rows of region/height of screen
       xp   =       mouse x location in screen coordinates (col)
       yp   =       mouse y location in screen coordinates (row)
       ar   =       mouse x location in map coordinates (col)
       al   =       mouse y location in map coordinates (row)

     */


    l0 = l;
    r0 = r;
    t0 = t;
    b0 = b;

    l = (int)((double)(l * mx[0]) + 0.5);
    r = (int)((double)(r * mx[0]) + 0.5);
    t = (int)((double)(t * mx[1]) + 0.5);
    b = (int)((double)(b * mx[1]) + 0.5);
    w_w = r - l;
    w_l = b - t;

    /* draw the sampling frame */

    R_open_driver();
    R_standard_color(D_translate_color("grey"));
    draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]),
	     (int)(b / mx[1]), 1);
    R_close_driver();

    fp = fopen0("r.le.para/units", "w");
    G_sleep_on_error(0);

    /* get the number of scales */

    do {
	fprintf(stderr,
		"\n    How many different SCALES do you want? (1-15)  ");

	numtrap(1, &tmp);
	if (tmp < 1 || tmp > 15)
	    fprintf(stderr,
		    "    Too many (>15) or too few scales, try again.\n");
    }
    while (tmp < 1 || tmp > 15);
    fprintf(fp, "%10d    # of scales\n", (int)(tmp));

    /* for each scale */

    for (i = 0; i < tmp; i++) {
	G_system("clear");

	radius = 0.0;
	circle = 0;

	/* if sampling using circles */

	fprintf(stderr, "\n    SCALE %d\n", i + 1);
	fprintf(stderr, "\n    Do you want to sample using rectangles");

	if (!G_yes("\n       (including squares) (y) or circles (n)?   ", 1)) {
	    circle = 1;
	    fprintf(stderr,
		    "\n    Draw a rectangular area to contain a standard circular");
	    fprintf(stderr,
		    "\n    sampling unit of scale %d.  First select upper left",
		    i + 1);
	    fprintf(stderr, "\n    corner, then lower right:\n");
	    fprintf(stderr, "       Left button:     Check unit size\n");
	    fprintf(stderr,
		    "       Middle button:   Upper left corner of area here\n");
	    fprintf(stderr,
		    "       Right button:    Lower right corner of area here\n");

	}

	else {
	    fprintf(stderr,
		    "\n    Draw a standard rectangular unit of scale %d.",
		    i + 1);
	    fprintf(stderr,
		    "\n    First select upper left corner, then lower right:\n");
	    fprintf(stderr, "       Left button:     Check unit size\n");
	    fprintf(stderr,
		    "       Middle button:   Upper left corner of unit here\n");
	    fprintf(stderr,
		    "       Right button:    Lower right corner of unit here\n");

	}

	R_open_driver();

	do {
	  back1:
	    R_get_location_with_box(x0, y0, &xp, &yp, &btn);

	    /* convert the upper left screen coordinate
	       (x0, y0) and the mouse position (xp, yp)
	       on the screen to the nearest row and
	       column; do the same for the sampling
	       unit width (u_w) and height (u_l);
	       then convert back */

	    ar = (int)((double)(xp) * mx[0] + 0.5);
	    xp = (int)((double)(ar) / mx[0] + 0.5);
	    al = (int)((double)(x0) * mx[0] + 0.5);
	    x0 = (int)((double)(al) / mx[0] + 0.5);
	    au_w = ar - al;
	    u_w = (int)((double)(au_w) / mx[0] + 0.5);
	    ab = (int)((double)(yp) * mx[1] + 0.5);
	    yp = (int)((double)(ab) / mx[1] + 0.5);
	    at = (int)((double)(y0) * mx[1] + 0.5);
	    y0 = (int)((double)(at) / mx[1] + 0.5);
	    au_l = ab - at;
	    u_l = (int)((double)(au_l) / mx[1] + 0.5);


	    /* left button, check the size of the rubber
	       box in array system */

	    if (btn == 1) {
		if (ar > r || ab > b || ar < l || ab < t) {
		    fprintf(stderr,
			    "\n    This point is not in the sampling frame; try again\n");

		    goto back1;
		}
		if (x0 < l || y0 < t) {
		    fprintf(stderr,
			    "\n    Use the middle button to first put the upper left");
		    fprintf(stderr,
			    "\n    corner inside the sampling frame\n");

		    goto back1;
		}
		if (ar <= al || ab <= at) {
		    fprintf(stderr,
			    "\n    Please put the lower right corner down and to");
		    fprintf(stderr,
			    "\n    the right of the upper left corner\n");

		    goto back1;
		}
		else {
		    fprintf(stderr,
			    "\n    Unit would be %d columns wide by %d rows long\n",
			    abs(au_w), abs(au_l));
		    fprintf(stderr,
			    "    Width/length would be %5.2f and size %d pixels\n",
			    (double)abs((au_w)) / (double)abs((au_l)),
			    abs(au_w) * abs(au_l));

		}
	    }

	    /* mid button, move the start point of the
	       rubber box */

	    else if (btn == 2) {
		if (ar > r || ab > b || ar < l || ab < t) {
		    fprintf(stderr,
			    "\n    Point is not in the sampling frame; try again\n");

		    goto back1;
		}
		else {
		    R_move_abs(xp, yp);
		    x0 = xp;
		    y0 = yp;
		}
	    }

	    /* right button, outline the unit */

	    else if (btn == 3) {

		if (circle) {
		    if (u_w > u_l) {
			al = al + ((ar - al) - (ab - at)) / 2;
			ar = al + (ab - at);
			x0 = (int)((double)(al) / mx[0] + 0.5);
			xp = (int)((double)(ar) / mx[0] + 0.5);
			au_w = ar - al;
			u_w = u_l = (int)((double)(au_w) / mx[0] + 0.5);
		    }
		    if (u_l > u_w) {
			at = at + ((ab - at) - (ar - al)) / 2;
			ab = at + (ar - al);
			y0 = (int)((double)(at) / mx[1] + 0.5);
			yp = (int)((double)(ab) / mx[1] + 0.5);
			au_l = ab - at;
			u_w = u_l = (int)((double)(au_l) / mx[1] + 0.5);
		    }
		}

		if (ar > r || ab > b || al < l || at < t) {
		    fprintf(stderr,
			    "\n    The unit extends outside the sampling frame or map;");
		    fprintf(stderr, "\n       try again\n");

		    goto back1;
		}

		if (au_w > w_w || au_l > w_l) {
		    fprintf(stderr,
			    "\n    The unit is too big for the sampling frame; ");
		    fprintf(stderr, "try again\n");

		    goto back1;
		}

		/* if there is a mask, check to see that
		   the unit will be within the mask area,
		   by checking to see whether the four
		   corners of the unit are in the mask */

		if (fmask > 0) {
		    row_buf = Rast_allocate_c_buf();
		    Rast_get_c_row_nomask(fmask, row_buf, at);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again\n");

			G_free(row_buf);
			goto back1;
		    }
		    Rast_zero_c_buf(row_buf);
		    Rast_get_c_row_nomask(fmask, row_buf, ab - 1);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again\n");

			G_free(row_buf);
			goto back1;
		    }
		    G_free(row_buf);
		}

		if (xp - x0 > 0 && yp - y0 > 0) {
		    R_standard_color(D_translate_color("red"));
		    if (circle)
			draw_circle(x0, y0, xp, yp, 3);
		    else
			draw_box(x0, y0, xp, yp, 1);
		    G_system("clear");
		    if (circle) {
			fprintf(stderr,
				"\n\n    The standard circular sampling unit has:\n");
			fprintf(stderr, "       radius = %f pixels\n",
				(double)(ar - al) / 2.0);

		    }
		    else {
			fprintf(stderr,
				"\n\n    The standard sampling unit has:\n");
			fprintf(stderr, "       columns=%d    rows=%d\n",
				abs(ar - al), abs(ab - at));
			fprintf(stderr, "       width/length ratio=%5.2f\n",
				(double)abs(ar - al) / (double)abs(ab - at));
			fprintf(stderr, "       size=%d pixels\n",
				abs(ar - al) * abs(ab - at));

		    }
		    k = 0;
		    ux[0] = al;
		    uy[0] = at;
		}
		else if (xp - x0 == 0 || yp - y0 == 0) {
		    fprintf(stderr,
			    "\n    Unit has 0 rows and/or 0 columns; try again\n");

		    goto back1;
		}
		else {
		    fprintf(stderr,
			    "\n    You did not put the lower right corner below");
		    fprintf(stderr,
			    "\n       and to the right of the upper left corner. Please try again");

		    goto back1;
		}
	    }
	}
	while (btn != 3);
	R_close_driver();

	/* use the size and shape of the
	   standard unit to outline more units
	   in that scale */

	fprintf(stderr, "\n    Outline more sampling units of scale %d?\n",
		i + 1);
	fprintf(stderr, "       Left button:     Exit\n");
	fprintf(stderr, "       Middle button:   Check unit position\n");
	fprintf(stderr,
		"       Right button:    Lower right corner of next unit here\n");

	R_open_driver();

	/* if not the left button (to exit) */

      back2:
	while (btn != 1) {
	    R_get_location_with_box(xp - u_w, yp - u_l, &xp, &yp, &btn);

	    /* convert the left (x0), right (y0),
	       top (y0), bottom (yp) coordinates in
	       screen pixels to the nearest row and
	       column; do the same for the sampling
	       unit width (u_w) and height (u_l);
	       then convert back */

	    ar = (int)((double)(xp) * mx[0] + 0.5);
	    ab = (int)((double)(yp) * mx[1] + 0.5);
	    xp = (int)((double)(ar) / mx[0] + 0.5);
	    yp = (int)((double)(ab) / mx[1] + 0.5);
	    al = (int)((double)(xp - u_w) * mx[0] + 0.5);
	    at = (int)((double)(yp - u_l) * mx[0] + 0.5);
	    x0 = (int)((double)(al) / mx[0] + 0.5);
	    y0 = (int)((double)(at) / mx[1] + 0.5);


	    /* if right button, outline the unit */

	    if (btn == 3) {

		if (ar > r || ab > b || al < l || at < t) {
		    fprintf(stderr,
			    "\n    The unit would be outside the map; try again");
		    goto back2;

		}

		/* if there is a mask, check to see that
		   the unit will be within the mask area */

		if (fmask > 0) {
		    row_buf = Rast_allocate_c_buf();
		    Rast_get_c_row_nomask(fmask, row_buf, at);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again");

			G_free(row_buf);
			goto back2;
		    }
		    Rast_zero_c_buf(row_buf);
		    Rast_get_c_row_nomask(fmask, row_buf, ab - 1);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again");
			G_free(row_buf);
			goto back2;
		    }
		    G_free(row_buf);
		}

		/* check for sampling unit overlap */

		lap = 0;
		for (j = 0; j < k + 1; j++) {
		    if (overlap(al, at, ux[j], uy[j], au_w, au_l)) {
			fprintf(stderr,
				"\n    The unit would overlap a previously drawn ");
			fprintf(stderr, "unit; try again");

			lap = 1;
		    }
		}
		if (lap)
		    goto back2;

		k++;
		fprintf(stderr, "\n    %d sampling units have been placed",
			(k + 1));

		ux[k] = al;
		uy[k] = at;
		R_standard_color(D_translate_color("red"));
		if (circle)
		    draw_circle(x0, y0, xp, yp, 3);
		else
		    draw_box(x0, y0, xp, yp, 1);
	    }
	}
	R_close_driver();

	/* save the sampling units in the
	   r.le.para/units file */

	if (circle)
	    radius = (double)(ar - al) / 2.0;
	else
	    radius = 0.0;
	fprintf(fp, "%10d    # of units of scale %d\n", k + 1, i + 1);
	fprintf(fp, "%10d%10d   u_w, u_l of units in scale %d\n",
		(int)(u_w * mx[0]), (int)(u_l * mx[1]), i + 1);
	fprintf(fp, "%10.1f             radius of circles in scale %d\n",
		radius, (i + 1));
	for (j = 0; j < k + 1; j++)
	    fprintf(fp, "%10d%10d   left, top of unit[%d]\n", ux[j], uy[j],
		    j + 1);

	if (i < tmp - 1 && G_yes("\n    Refresh the screen?   ", 1)) {
	    paint_map(n1, n2, n3);
	    R_open_driver();
	    R_standard_color(D_translate_color("red"));
	    R_close_driver();
	}
    }

    fclose(fp);
    return;
}
Ejemplo n.º 13
0
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 */
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
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;

}
Ejemplo n.º 16
0
int draw_slice(struct Colors *colors, int fill_flag, DCELL fill_color1, DCELL fill_color2, int txt_color, double cx, double cy, double r,	/* in normalized coords. */
	       double a1, double a2	/* in degrees */
    )
{
    int tt, tb, tr, tl;
    int height, width;
    int yoffset, xoffset;
    int x[1000], y[1000];
    int lx, ly;
    int i = 1;
    char txt[512];
    double arc, arc_incr = 0.01;
    DCELL fill_color;

    D_get_screen_window(&tt, &tb, &tl, &tr);

    height = tb - tt;
    width = tr - tl;
    yoffset = tb;
    xoffset = tl;

    while (a2 / arc_incr > 998)
	arc_incr *= 2;

    x[0] = (int)((double)xoffset + cx * (double)width);
    y[0] = (int)((double)yoffset - cy * (double)height);

    arc = a1;
    if (fill_flag && fill_color1 != fill_color2) {
	i = 1;
	while (arc <= (a1 + a2)) {
	    fill_color = fill_color1 + (arc - a1) *
		(fill_color2 - fill_color1) / a2;
	    x[i] = x[0] + r * (width) * cos(arc / 57.296);
	    y[i] = y[0] - r * (height) * sin(arc / 57.296);
	    if (i == 2) {
		D_d_color(fill_color, colors);
		R_polygon_abs(x + i - 2, y + i - 2, 3);
		x[i - 1] = x[i];
		y[i - 1] = y[i];
	    }
	    else
		i++;
	    arc = arc + arc_incr;
	}
    }
    else {
	i = 1;
	while (arc <= (a1 + a2)) {
	    x[i] = x[0] + r * (width) * cos(arc / 57.296);
	    y[i] = y[0] - r * (height) * sin(arc / 57.296);
	    i++;
	    arc = arc + arc_incr;
	}

	if (!fill_flag) {
	    R_standard_color(txt_color);
	    R_polyline_abs(x, y, i);
	}
	else {
	    D_d_color(fill_color1, colors);
	    R_polygon_abs(x, y, i);
	}
    }

    if (a2 > 15.0) {
	/* draw a label */
	arc = a1 + a2 / 2;
	sprintf(txt, "%2.0f%s", (double)(a2 / (double)360.0) * (double)100.0,
		percent);
	R_get_text_box(txt, &tt, &tb, &tl, &tr);
	lx = x[0] + (r + 0.03) * (width) * cos(arc / 57.296) - (tr - tl) / 2;
	ly = y[0] - (r + 0.03) * (height) * sin(arc / 57.296) + (tb - tt) / 2;
	R_move_abs(lx, ly);
	R_standard_color(txt_color);
	R_text(txt);
    }

    return 0;
}