Ejemplo n.º 1
0
int
exit_tk()
{
  int code;

  if (Tk_GetNumMainWindows() > 0) {
    sprintf(tcl_command_buffer, "done_calculation");
    code = Tcl_Eval(interp, tcl_command_buffer);
    if (code != TCL_OK) {
      fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
      return code;
    }
  }

  while (Tk_GetNumMainWindows() > 0) {
    sprintf(tcl_command_buffer, "tkwait variable window_changed");
    code = Tcl_Eval(interp, tcl_command_buffer);
    if (code != TCL_OK) {
      fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
      return code;
    }
    draw_graph(maxstep);
  }

  sprintf(tcl_command_buffer, "exit");
  Tcl_Eval(interp, tcl_command_buffer);
  Tcl_DeleteInterp(interp);
}
Ejemplo n.º 2
0
bool
ParadynTkGUI::IsDoneHandlingEvents( void ) const
{
   return (Tk_GetNumMainWindows() == 0);
}
Ejemplo n.º 3
0
int
  draw_graph(int step)
{
  int code;
  double display_width, display_height;
  double xscale, yscale;
  double xoff, yoff;

  struct vertex *v, *w;
  struct point t;
  int n, i, j;
  static int angle = 90;
  static int count = 0;
  int steps;
  double s, c;
  double xc, yc, zc;
  double d, dmax, avglen;
  double f1, f2;
  double xmin, xmax, ymin, ymax, zmin, zmax;
  double elevation;

  struct edge *edges;
  int e;

  edges = (struct edge *) malloc( sizeof(struct edge) * nedges );
  if (edges == NULL) {
    fprintf(stderr, "Not enough memory");
    return;
  }

  /* --- determine number of interpolation steps  --- */

  dmax = 0.0;
  avglen = 0.0;

  for (i = 1; i <= nvertices; i++) {
    v = &(vertices[i]);
    d = norm( difference( v->pos, v->saved_pos ) );
    if (d > dmax)
      dmax = d;
    for (j = 0; j < v->valency; j++) {
      if (v->adj[j] > i) {
	w = &(vertices[v->adj[j]]);
	avglen += norm( difference( v->saved_pos, w->saved_pos ) );
      }
    }
  }

  avglen /= nedges;
  steps = (int) ( dmax / maxdist ) + 1;


  /* --- interpolate and display --- */

  if (count_only)
    count += steps;
  else {
    for (n = 1; n <= steps; n++) {
      /* --- initialize Tk stuff --- */

      if (Tk_GetNumMainWindows() <= 0) {
	free(edges);
	return TCL_RETURN;
      }

      sprintf(tcl_command_buffer, "update; set step %d", step);
      code = Tcl_Eval(interp, tcl_command_buffer);
      if (code != TCL_OK) {
	fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
	free(edges);
	return code;
      }

      if (Tk_GetNumMainWindows() <= 0) {
	free(edges);
	return TCL_RETURN;
      }

      sprintf(tcl_command_buffer, "get_canvas_size");
      code = Tcl_Eval(interp, tcl_command_buffer);
      if (code != TCL_OK) {
	fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
	free(edges);
	return code;
      }
      sscanf(interp->result, "%lf %lf", &display_width, &display_height);

      xscale = (display_width  / 2.0 - 10.0) / height;
      yscale = (display_height / 2.0 - 10.0) / height;

      if (xscale <= yscale)
	yscale = xscale;
      else
	xscale = yscale;

      yscale *= -1;

      xoff = display_width / 2.0;
      yoff = display_height - 10.0;

      sprintf(tcl_command_buffer, "clear_canvas");
      code = Tcl_Eval(interp, tcl_command_buffer);
      if (code != TCL_OK) {
	fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
	free(edges);
	return code;
      }


      /* --- compute current transformation parameters --- */

      f2 = (double)n / (double)steps;
      f1 = 1.0 - f2;

      s = sin( angle * M_PI / 180.0);
      c = cos( angle * M_PI / 180.0);
      angle = ( angle - 1 ) % 360;

      /* --- compute center of gravity to rotate about --- */

      xc = yc = zc = 0.0;

      for (i = 1; i <= nvertices; i++) {
	v = &(vertices[i]);
	xc += f1 * v->saved_pos.x + f2 * v->pos.x;
	yc += f1 * v->saved_pos.y + f2 * v->pos.y;
	zc += f1 * v->saved_pos.z + f2 * v->pos.z;
      }
      xc /= nvertices;
      yc /= nvertices;
      zc /= nvertices;


      /* --- compute endpoints of all the edges --- */

      e = 0;
      for (i = 1; i <= nvertices; i++) {
	v = &(vertices[i]);

	for (j = 0; j < v->valency; j++) {
	  if (v->adj[j] > i) {
	    w = &(vertices[v->adj[j]]);

	    t.x = f1 * w->saved_pos.x + f2 * w->pos.x - xc;
	    t.y = f1 * w->saved_pos.y + f2 * w->pos.y - yc;
	    t.z = f1 * w->saved_pos.z + f2 * w->pos.z - zc;

	    edges[e].p.x = t.x * c - t.z * s;
	    edges[e].p.y = t.y;
	    edges[e].p.z = t.x * s + t.z * c;

	    t.x = f1 * v->saved_pos.x + f2 * v->pos.x - xc;
	    t.y = f1 * v->saved_pos.y + f2 * v->pos.y - yc;
	    t.z = f1 * v->saved_pos.z + f2 * v->pos.z - zc;

	    edges[e].q.x = t.x * c - t.z * s;
	    edges[e].q.y = t.y;
	    edges[e].q.z = t.x * s + t.z * c;

	    ++e;
	  }
	}
      }

      nedges = e;

      /* --- compute bounding box --- */

      for (e = 0; e < nedges; e++) {
	if (e == 0) {
	  xmin = xmax = edges[e].p.x;
	  ymin = ymax = edges[e].p.y;
	  zmin = zmax = edges[e].p.z;
	}

	if (edges[e].p.x < xmin) xmin = edges[e].p.x;
	if (edges[e].p.x > xmax) xmax = edges[e].p.x;
	if (edges[e].p.y < ymin) ymin = edges[e].p.y;
	if (edges[e].p.y > ymax) ymax = edges[e].p.y;
	if (edges[e].p.z < zmin) zmin = edges[e].p.z;
	if (edges[e].p.z > zmax) zmax = edges[e].p.z;

	if (edges[e].q.x < xmin) xmin = edges[e].q.x;
	if (edges[e].q.x > xmax) xmax = edges[e].q.x;
	if (edges[e].q.y < ymin) ymin = edges[e].q.y;
	if (edges[e].q.y > ymax) ymax = edges[e].q.y;
	if (edges[e].q.z < zmin) zmin = edges[e].q.z;
	if (edges[e].q.z > zmax) zmax = edges[e].q.z;
      }


      /* --- compute elevation --- */

      if ( - ymin > 0.9 * height)
	elevation = - ymin + 0.1 * height;
      else
	elevation = height;

      for (e = 0; e < nedges; e++) {
	edges[e].p.y += elevation;
	edges[e].q.y += elevation;
      }

      /* --- now do the drawing --- */

      qsort((void *)edges, nedges, sizeof(struct edge), cmp_edges);

      for (e = 0; e < nedges; e++) {
	edges[e].shade = 
	  (int) (0.5 + 14.0 * ((zmax - (edges[e].p.z + edges[e].q.z) / 2.0)
			       / (zmax - zmin)));

	sprintf(tcl_command_buffer,
		"add_closer_line %lf %lf %lf %lf #%x%xf",
		edges[e].p.x * xscale + xoff,
		edges[e].p.y * yscale + yoff,
		edges[e].q.x * xscale + xoff,
		edges[e].q.y * yscale + yoff,
		edges[e].shade, edges[e].shade
		);
	code = Tcl_Eval(interp, tcl_command_buffer);
	if (code != TCL_OK) {
	  fprintf(stderr, "in Tcl_VarEval: %s\n", interp->result);
	  free(edges);
	  return code;
	}
      }

      /* --- update screen and pause if requested --- */

      sprintf(tcl_command_buffer, "update idletasks");
      code = Tcl_Eval(interp, tcl_command_buffer);
      if (code != TCL_OK) {
	fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
	free(edges);
	return code;
      }

      Tcl_Sleep(sleep_ms);
    }
  }

  for (i = 1; i <= nvertices; i++) {
    v = &vertices[i];
    v->saved_pos.x = v->pos.x;
    v->saved_pos.y = v->pos.y;
    v->saved_pos.z = v->pos.z;
  }

  free(edges);
  return count;
}
Ejemplo n.º 4
0
void	kit::loop() const
// Adjusted version of Tk_MainLoop()
{
	while((Tk_GetNumMainWindows() > 0) && !_quit)
		Tcl_DoOneEvent(0);
}