Exemplo n.º 1
0
void
polyconn_init(PolyConn *poly, int num_points)
{
  DiaObject *obj;
  int i;

  obj = &poly->object;

  object_init(obj, num_points, 0);
  
  poly->numpoints = num_points;

  poly->points = g_malloc(num_points*sizeof(Point));

  for (i=0;i<num_points;i++) {
    obj->handles[i] = g_malloc(sizeof(Handle));
    if (0 == i)
      setup_handle(obj->handles[i], PC_HANDLE_START);
    else if (i == num_points-1)
      setup_handle(obj->handles[i], PC_HANDLE_END);
    else
      setup_handle(obj->handles[i], PC_HANDLE_CORNER);
  }

  polyconn_update_data(poly);
}
Exemplo n.º 2
0
void
polyconn_copy(PolyConn *from, PolyConn *to)
{
  int i;
  DiaObject *toobj, *fromobj;

  toobj = &to->object;
  fromobj = &from->object;

  object_copy(fromobj, toobj);

  to->object.handles[0] = g_new(Handle,1);
  *to->object.handles[0] = *from->object.handles[0];

  for (i=1;i<toobj->num_handles-1;i++) {
    to->object.handles[i] = g_malloc(sizeof(Handle));
    setup_handle(to->object.handles[i], PC_HANDLE_CORNER);
  }

  to->object.handles[toobj->num_handles-1] = g_new(Handle,1);
  *to->object.handles[toobj->num_handles-1] =
      *from->object.handles[toobj->num_handles-1];
  polyconn_set_points(to, from->numpoints, from->points);
  
  memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
  polyconn_update_data(to);
}
Exemplo n.º 3
0
void
polyconn_copy(PolyConn *from, PolyConn *to)
{
  int i;
  Object *toobj, *fromobj;

  toobj = &to->object;
  fromobj = &from->object;

  object_copy(fromobj, toobj);

  to->numpoints = from->numpoints;

  to->points = g_malloc((to->numpoints)*sizeof(Point));

  for (i=0;i<to->numpoints;i++) {
    to->points[i] = from->points[i];
  }

  to->object.handles[0] = g_new(Handle,1);
  *to->object.handles[0] = *from->object.handles[0];
  for (i=1;i<to->numpoints-1;i++) {
    to->object.handles[i] = g_malloc(sizeof(Handle));
    setup_corner_handle(to->object.handles[i]);
  }
  to->object.handles[to->numpoints-1] = g_new(Handle,1);
  *to->object.handles[to->numpoints-1] = *from->object.handles[to->numpoints-1];

  polyconn_update_data(to);
}
Exemplo n.º 4
0
void
polyconn_init(PolyConn *poly)
{
  Object *obj;

  obj = &poly->object;

  object_init(obj, 2, 0);
  
  poly->numpoints = 2;

  poly->points = g_malloc(2*sizeof(Point));

  poly->object.handles[0] = g_malloc(sizeof(Handle));
  poly->object.handles[1] = g_malloc(sizeof(Handle));

  obj->handles[0]->connect_type = HANDLE_CONNECTABLE;
  obj->handles[0]->connected_to = NULL;
  obj->handles[0]->type = HANDLE_MAJOR_CONTROL;
  obj->handles[0]->id = HANDLE_MOVE_STARTPOINT;
  
  obj->handles[1]->connect_type = HANDLE_CONNECTABLE;
  obj->handles[1]->connected_to = NULL;
  obj->handles[1]->type = HANDLE_MAJOR_CONTROL;
  obj->handles[1]->id = HANDLE_MOVE_ENDPOINT;

  polyconn_update_data(poly);
}
Exemplo n.º 5
0
static void
polyline_update_data(Polyline *polyline)
{
  PolyConn *poly = &polyline->poly;
  DiaObject *obj = &poly->object;
  PolyBBExtras *extra = &poly->extra_spacing;
  Point gap_endpoints[2];

  polyconn_update_data(&polyline->poly);

  extra->start_trans =  (polyline->line_width / 2.0);
  extra->end_trans =     (polyline->line_width / 2.0);
  extra->middle_trans = (polyline->line_width / 2.0);
  extra->start_long = (polyline->line_width / 2.0);
  extra->end_long   = (polyline->line_width / 2.0);

  polyline_calculate_gap_endpoints(polyline, gap_endpoints);
  polyline_exchange_gap_points(polyline, gap_endpoints);

  polyconn_update_boundingbox(poly);

  if (polyline->start_arrow.type != ARROW_NONE) {
    Rectangle bbox;
    Point move_arrow, move_line;
    Point to = gap_endpoints[0];
    Point from = poly->points[1];
    calculate_arrow_point(&polyline->start_arrow, &to, &from,
                          &move_arrow, &move_line, polyline->line_width);
    /* move them */
    point_sub(&to, &move_arrow);
    point_sub(&from, &move_line);

    arrow_bbox (&polyline->start_arrow, polyline->line_width, &to, &from, &bbox);
    rectangle_union (&obj->bounding_box, &bbox);
  }
  if (polyline->end_arrow.type != ARROW_NONE) {
    Rectangle bbox;
    int n = polyline->poly.numpoints;
    Point move_arrow, move_line;
    Point to = gap_endpoints[1];
    Point from = poly->points[n-2];
    calculate_arrow_point(&polyline->end_arrow, &to, &from,
                          &move_arrow, &move_line, polyline->line_width);
    /* move them */
    point_sub(&to, &move_arrow);
    point_sub(&from, &move_line);

    arrow_bbox (&polyline->end_arrow, polyline->line_width, &to, &from, &bbox);
    rectangle_union (&obj->bounding_box, &bbox);
  }

  polyline_exchange_gap_points(polyline, gap_endpoints);

  obj->position = poly->points[0];
}
Exemplo n.º 6
0
void
polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Does object_init() */
{
  int i;
  AttributeNode attr;
  DataNode data;
  
  DiaObject *obj = &poly->object;

  object_load(obj, obj_node, ctx);

  attr = object_find_attribute(obj_node, "poly_points");

  if (attr != NULL)
    poly->numpoints = attribute_num_data(attr);
  else
    poly->numpoints = 0;

  object_init(obj, poly->numpoints, 0);

  data = attribute_first_data(attr);
  poly->points = g_malloc(poly->numpoints*sizeof(Point));
  for (i=0;i<poly->numpoints;i++) {
    data_point(data, &poly->points[i], ctx);
    data = data_next(data);
  }

  obj->handles[0] = g_malloc(sizeof(Handle));
  obj->handles[0]->connect_type = HANDLE_CONNECTABLE;
  obj->handles[0]->connected_to = NULL;
  obj->handles[0]->type = HANDLE_MAJOR_CONTROL;
  obj->handles[0]->id = HANDLE_MOVE_STARTPOINT;
  
  obj->handles[poly->numpoints-1] = g_malloc(sizeof(Handle));
  obj->handles[poly->numpoints-1]->connect_type = HANDLE_CONNECTABLE;
  obj->handles[poly->numpoints-1]->connected_to = NULL;
  obj->handles[poly->numpoints-1]->type = HANDLE_MAJOR_CONTROL;
  obj->handles[poly->numpoints-1]->id = HANDLE_MOVE_ENDPOINT;

  for (i=1;i<poly->numpoints-1;i++) {
    obj->handles[i] = g_malloc(sizeof(Handle));
    setup_handle(obj->handles[i], PC_HANDLE_CORNER);
  }

  polyconn_update_data(poly);
}
Exemplo n.º 7
0
ObjectChange *
polyconn_remove_point(PolyConn *poly, int pos)
{
  Handle *old_handle;
  ConnectionPoint *connectionpoint;
  Point old_point;
  
  old_handle = poly->object.handles[pos];
  old_point = poly->points[pos];
  connectionpoint = old_handle->connected_to;
  
  object_unconnect((DiaObject *)poly, old_handle);

  remove_handle(poly, pos);

  polyconn_update_data(poly);
  
  return polyconn_create_change(poly, TYPE_REMOVE_POINT,
				&old_point, pos, old_handle,
				connectionpoint);
}
Exemplo n.º 8
0
static void
polyline_select(Polyline *polyline, Point *clicked_point,
		  DiaRenderer *interactive_renderer)
{
  polyconn_update_data(&polyline->poly);
}