Exemple #1
0
static ObjectChange*
box_move_handle(Box *box, Handle *handle,
		Point *to, ConnectionPoint *cp,
		HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(box!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  if (box->aspect != FREE_ASPECT){
    double width, height;
    double new_width, new_height;
    double to_width, aspect_width;
    Point corner = box->element.corner;
    Point se_to;

    width = box->element.width;
    height = box->element.height;
    switch (handle->id) {
    case HANDLE_RESIZE_N:
    case HANDLE_RESIZE_S:
      new_height = fabs(to->y - corner.y);
      new_width = new_height / height * width;
      break;
    case HANDLE_RESIZE_W:
    case HANDLE_RESIZE_E:
      new_width = fabs(to->x - corner.x);
      new_height = new_width / width * height;
      break;
    case HANDLE_RESIZE_NW:
    case HANDLE_RESIZE_NE:
    case HANDLE_RESIZE_SW:
    case HANDLE_RESIZE_SE:
      to_width = fabs(to->x - corner.x);
      aspect_width = fabs(to->y - corner.y) / height * width;
      new_width = to_width > aspect_width ? to_width : aspect_width;
      new_height = new_width / width * height;
      break;
    default: 
      new_width = width;
      new_height = height;
      break;
    }
	
    se_to.x = corner.x + new_width;
    se_to.y = corner.y + new_height;
        
    element_move_handle(&box->element, HANDLE_RESIZE_SE, &se_to, cp, reason, modifiers);
  } else {
    element_move_handle(&box->element, handle->id, to, cp, reason, modifiers);
  }

  box_update_data(box);

  return NULL;
}
Exemple #2
0
static ObjectChange*
transition_move_handle(Transition *transition, Handle *handle,
		       Point *to, ConnectionPoint *cp,
		       HandleMoveReason reason, 
		       ModifierKeys modifiers)
{
  g_assert(transition!=NULL);
  g_assert(handle!=NULL);
  g_assert(to!=NULL);

  switch(handle->id) {
  case HANDLE_NORTH:
    transition->north.pos = *to;
    if (transition->north.pos.y > transition->A.y) 
      transition->north.pos.y = transition->A.y;
    break;
  case HANDLE_SOUTH:
    transition->south.pos = *to;
    if (transition->south.pos.y < transition->B.y) 
      transition->south.pos.y = transition->B.y;
    break;
  default:
    element_move_handle(&transition->element, handle->id, to, cp, 
			reason, modifiers);
  }

  transition_update_data(transition);

  return NULL;
}
Exemple #3
0
static ObjectChange*
step_move_handle(Step *step, Handle *handle,
		Point *to, ConnectionPoint *cp,
		 HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(step!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  switch(handle->id) {
  case HANDLE_NORTH:
    step->north.pos = *to;
    if (step->north.pos.y > step->A.y) step->north.pos.y = step->A.y;
    break;
  case HANDLE_SOUTH:
    step->south.pos = *to;
    if (step->south.pos.y < step->D.y) step->south.pos.y = step->D.y;
    break;
  default:
    element_move_handle(&step->element, handle->id, to, cp, reason, modifiers);
  }

  step_update_data(step);

  return NULL;
}
Exemple #4
0
static ObjectChange*
chronoref_move_handle(Chronoref *chronoref, Handle *handle,
		      Point *to, ConnectionPoint *cp,
		      HandleMoveReason reason, ModifierKeys modifiers)
{
  g_assert(chronoref!=NULL);
  g_assert(handle!=NULL);
  g_assert(to!=NULL);

  element_move_handle(&chronoref->element, handle->id, to, cp, 
		      reason, modifiers);
  chronoref_update_data(chronoref);

  return NULL;
}
Exemple #5
0
static ObjectChange*
newgroup_move_handle(NewGroup *group, Handle *handle,
		Point *to, ConnectionPoint *cp,
		HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(group!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  element_move_handle(&group->element, handle->id, to, cp, reason, modifiers);

  newgroup_update_data(group);

  return NULL;
}
Exemple #6
0
static ObjectChange*
grid_object_move_handle(Grid_Object *grid_object, Handle *handle,
			 Point *to, ConnectionPoint *cp, 
			 HandleMoveReason reason, ModifierKeys modifiers)
{
  g_assert(grid_object!=NULL);
  g_assert(handle!=NULL);
  g_assert(to!=NULL);

  element_move_handle(&grid_object->element, handle->id, to, cp, 
		      reason, modifiers);
  grid_object_update_data(grid_object);

  return NULL;
}
Exemple #7
0
static ObjectChange*
analog_clock_move_handle(Analog_Clock *analog_clock, Handle *handle,
			 Point *to, ConnectionPoint *cp, 
			 HandleMoveReason reason, ModifierKeys modifiers)
{
  g_assert(analog_clock!=NULL);
  g_assert(handle!=NULL);
  g_assert(to!=NULL);

  element_move_handle(&analog_clock->element, handle->id, to, cp, 
		      reason, modifiers);
  analog_clock_update_data(analog_clock);

  return NULL;
}
Exemple #8
0
static ObjectChange*
ellipse_move_handle(Ellipse *ellipse, Handle *handle,
		    Point *to, ConnectionPoint *cp,
		    HandleMoveReason reason, ModifierKeys modifiers)
{
  AnchorShape horiz = ANCHOR_MIDDLE, vert = ANCHOR_MIDDLE;
  Point corner;
  real width, height;

  assert(ellipse!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  /* remember ... */
  corner = ellipse->element.corner;
  width = ellipse->element.width;
  height = ellipse->element.height;

  element_move_handle(&ellipse->element, handle->id, to, cp, 
		      reason, modifiers);

  switch (handle->id) {
  case HANDLE_RESIZE_NW:
    horiz = ANCHOR_END; vert = ANCHOR_END; break;
  case HANDLE_RESIZE_N:
    vert = ANCHOR_END; break;
  case HANDLE_RESIZE_NE:
    horiz = ANCHOR_START; vert = ANCHOR_END; break;
  case HANDLE_RESIZE_E:
    horiz = ANCHOR_START; break;
  case HANDLE_RESIZE_SE:
    horiz = ANCHOR_START; vert = ANCHOR_START; break;
  case HANDLE_RESIZE_S:
    vert = ANCHOR_START; break;
  case HANDLE_RESIZE_SW:
    horiz = ANCHOR_END; vert = ANCHOR_START; break;
  case HANDLE_RESIZE_W:
    horiz = ANCHOR_END; break;
  default:
    break;
  }
  ellipse_update_data(ellipse, horiz, vert);

  if (width != ellipse->element.width && height != ellipse->element.height)
    return element_change_new (&corner, width, height, &ellipse->element);

  return NULL;
}
Exemple #9
0
static ObjectChange*
node_move_handle(Node *node, Handle *handle,
		 Point *to, ConnectionPoint *cp,
		 HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(node!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  assert(handle->id < 8);
  
  element_move_handle(&node->element, handle->id, to, cp, reason, modifiers);
  node_update_data(node);

  return NULL;
}
Exemple #10
0
static ObjectChange*
attribute_move_handle(Attribute *attribute, Handle *handle,
		      Point *to, ConnectionPoint *cp,
		      HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(attribute!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  assert(handle->id < 8);
  element_move_handle(&attribute->element, handle->id, to, cp, 
		      reason, modifiers);
  attribute_update_data(attribute);

  return NULL;
}
Exemple #11
0
static ObjectChange*
largepackage_move_handle(LargePackage *pkg, Handle *handle,
			 Point *to, ConnectionPoint *cp,
			 HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(pkg!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  assert(handle->id < 8);
  
  element_move_handle(&pkg->element, handle->id, to, cp, reason, modifiers);
  largepackage_update_data(pkg);

  return NULL;
}
Exemple #12
0
static ObjectChange*
basestation_move_handle(Basestation *basestation, Handle *handle,
                        Point *to, ConnectionPoint *cp,
                        HandleMoveReason reason, ModifierKeys modifiers)
{
    ObjectChange* oc;

    assert(basestation!=NULL);
    assert(handle!=NULL);
    assert(to!=NULL);
    assert(handle->id < 8);

    if (handle->type == HANDLE_NON_MOVABLE)
        return NULL;

    oc = element_move_handle (&(basestation->element), handle->id, to, cp, reason, modifiers);

    return oc;
}
Exemple #13
0
static ObjectChange*
goal_move_handle(Goal *goal, Handle *handle,
		Point *to, ConnectionPoint *cp,
		HandleMoveReason reason, ModifierKeys modifiers)
{
  AnchorShape horiz = ANCHOR_MIDDLE, vert = ANCHOR_MIDDLE;

  assert(goal!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  element_move_handle(&goal->element, handle->id, to, cp, reason, modifiers);

  switch (handle->id) {
  case HANDLE_RESIZE_NW:
    horiz = ANCHOR_END; vert = ANCHOR_END; break;
  case HANDLE_RESIZE_N:
    vert = ANCHOR_END; break;
  case HANDLE_RESIZE_NE:
    horiz = ANCHOR_START; vert = ANCHOR_END; break;
  case HANDLE_RESIZE_E:
    horiz = ANCHOR_START; break;
  case HANDLE_RESIZE_SE:
    horiz = ANCHOR_START; vert = ANCHOR_START; break;
  case HANDLE_RESIZE_S:
    vert = ANCHOR_START; break;
  case HANDLE_RESIZE_SW:
    horiz = ANCHOR_END; vert = ANCHOR_START; break;
  case HANDLE_RESIZE_W:
    horiz = ANCHOR_END; break;
  default:
    break;
  }
  goal_update_data(goal, horiz, vert);
  return NULL;
}
Exemple #14
0
static ObjectChange*
image_move_handle(EImage *image, Handle *handle,
		  Point *to, ConnectionPoint *cp,
		  HandleMoveReason reason, ModifierKeys modifiers)
{
  Element *elem = &image->element;
  assert(image!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  if (image->keep_aspect) {
    float width, height;
    float new_width, new_height;
    width = image->element.width;
    height = image->element.height;

    switch (handle->id) {
    case HANDLE_RESIZE_NW:
      new_width = -(to->x-image->element.corner.x)+width;
      new_height = -(to->y-image->element.corner.y)+height;
      if (new_height == 0 || new_width/new_height > width/height) {
	new_height = new_width*height/width;
      } else {
	new_width = new_height*width/height;
      }
      to->x = image->element.corner.x+(image->element.width-new_width);
      to->y = image->element.corner.y+(image->element.height-new_height);
      element_move_handle(elem, HANDLE_RESIZE_NW, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_N:
      new_width = (-(to->y-image->element.corner.y)+height)*width/height;
      to->x = image->element.corner.x+new_width;
      element_move_handle(elem, HANDLE_RESIZE_NE, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_NE:
      new_width = to->x-image->element.corner.x;
      new_height = -(to->y-image->element.corner.y)+height;
      if (new_height == 0 || new_width/new_height > width/height) {
	new_height = new_width*height/width;
      } else {
	new_width = new_height*width/height;
      }
      to->x = image->element.corner.x+new_width;
      to->y = image->element.corner.y+(image->element.height-new_height);
      element_move_handle(elem, HANDLE_RESIZE_NE, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_E:
      new_height = (to->x-image->element.corner.x)*height/width;
      to->y = image->element.corner.y+new_height;
      element_move_handle(elem, HANDLE_RESIZE_SE, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_SE:
      new_width = to->x-image->element.corner.x;
      new_height = to->y-image->element.corner.y;
      if (new_height == 0 || new_width/new_height > width/height) {
	new_height = new_width*height/width;
      } else {
	new_width = new_height*width/height;
      }
      to->x = image->element.corner.x+new_width;
      to->y = image->element.corner.y+new_height;
      element_move_handle(elem, HANDLE_RESIZE_SE, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_S:
      new_width = (to->y-image->element.corner.y)*width/height;
      to->x = image->element.corner.x+new_width;
      element_move_handle(elem, HANDLE_RESIZE_SE, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_SW:
      new_width = -(to->x-image->element.corner.x)+width;
      new_height = to->y-image->element.corner.y;
      if (new_height == 0 || new_width/new_height > width/height) {
	new_height = new_width*height/width;
      } else {
	new_width = new_height*width/height;
      }
      to->x = image->element.corner.x+(image->element.width-new_width);
      to->y = image->element.corner.y+new_height;
      element_move_handle(elem, HANDLE_RESIZE_SW, to, cp, reason, modifiers);
      break;
    case HANDLE_RESIZE_W:
      new_height = (-(to->x-image->element.corner.x)+width)*height/width;
      to->y = image->element.corner.y+new_height;
      element_move_handle(elem, HANDLE_RESIZE_SW, to, cp, reason, modifiers);
      break;
    default:
      message_warning("Unforeseen handle in image_move_handle: %d\n",
		      handle->id);
      
    }
  } else {
    element_move_handle(elem, handle->id, to, cp, reason, modifiers);
  }
  image_update_data(image);

  return NULL;
}
Exemple #15
0
static ObjectChange*
ellipse_move_handle(Ellipse *ellipse, Handle *handle,
		    Point *to, ConnectionPoint *cp,
		    HandleMoveReason reason, ModifierKeys modifiers)
{
  Element *elem = &ellipse->element;
  Point nw_to, se_to;

  assert(ellipse!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);

  assert(handle->id < 8 || handle->id == HANDLE_CUSTOM1);
  if (handle->id == HANDLE_CUSTOM1) {
    Point delta, corner_to;
    delta.x = to->x - (elem->corner.x + elem->width/2);
    delta.y = to->y - (elem->corner.y + elem->height/2);
    corner_to.x = elem->corner.x + delta.x;
    corner_to.y = elem->corner.y + delta.y;
    return ellipse_move(ellipse, &corner_to);
  } else {
    if (ellipse->aspect != FREE_ASPECT){
        float width, height;
        float new_width, new_height;
        float to_width, aspect_width;
        Point center;

        width = ellipse->element.width;
        height = ellipse->element.height;
        center.x = elem->corner.x + width/2;
        center.y = elem->corner.y + height/2;
        switch (handle->id) {
        case HANDLE_RESIZE_E:
        case HANDLE_RESIZE_W:
            new_width = 2 * fabs(to->x - center.x);
            new_height = new_width / width * height;
            break;
        case HANDLE_RESIZE_N:
        case HANDLE_RESIZE_S:
            new_height = 2 * fabs(to->y - center.y);
            new_width = new_height / height * width;
            break;
        case HANDLE_RESIZE_NW:
        case HANDLE_RESIZE_NE:
        case HANDLE_RESIZE_SW:
        case HANDLE_RESIZE_SE:
            to_width = 2 * fabs(to->x - center.x);
            aspect_width = 2 * fabs(to->y - center.y) / height * width;
            new_width = to_width < aspect_width ? to_width : aspect_width;
            new_height = new_width / width * height;
            break;
	default: 
	    new_width = width;
	    new_height = height;
	    break;
        }
	
        nw_to.x = center.x - new_width/2;
        nw_to.y = center.y - new_height/2;
        se_to.x = center.x + new_width/2;
        se_to.y = center.y + new_height/2;
        
        element_move_handle(&ellipse->element, HANDLE_RESIZE_NW, &nw_to, cp, reason, modifiers);
        element_move_handle(&ellipse->element, HANDLE_RESIZE_SE, &se_to, cp, reason, modifiers);
    } else {
        Point center;
        Point opposite_to;
        center.x = elem->corner.x + elem->width/2;
        center.y = elem->corner.y + elem->height/2;
        opposite_to.x = center.x - (to->x-center.x);
        opposite_to.y = center.y - (to->y-center.y);

        element_move_handle(&ellipse->element, handle->id, to, cp, reason, modifiers);
        /* this second move screws the intended object size, e.g. from dot2dia.py
	 * but without it the 'centered' behaviour during edit is screwed 
	 */
        element_move_handle(&ellipse->element, 7-handle->id, &opposite_to, cp, reason, modifiers);
    }

    ellipse_update_data(ellipse);

    return NULL;
  }
}
Exemple #16
0
ObjectChange*
aadlbox_move_handle(Aadlbox *aadlbox, Handle *handle,
		 Point *to, ConnectionPoint *cp,
		 HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(aadlbox!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);
  
  if (handle->id < 8) {   /* box resizing */
    
    Element *element = &aadlbox->element;
    Point oldcorner, newcorner;
    real oldw, neww, oldh, newh;
    real w_factor, h_factor;
    Aadlport *p;
    ConnectionPoint *c;
    int i;
    
    point_copy(&oldcorner, &element->corner);
    oldw = element->width;
    oldh = element->height;
        
    element_move_handle( &aadlbox->element, handle->id, to, cp,
			 reason, modifiers);
    
    point_copy(&newcorner, &element->corner);
    neww = element->width;
    newh = element->height;
    
    /* update ports positions proportionally */
    for (i=0; i < aadlbox->num_ports; i++)
    {
      p = aadlbox->ports[i];

      w_factor = (p->handle->pos.x - oldcorner.x) / oldw; 
      h_factor = (p->handle->pos.y - oldcorner.y) / oldh;
      
      p->handle->pos.x = newcorner.x + w_factor * neww;
      p->handle->pos.y = newcorner.y + h_factor * newh;
    }

    /* update connection points proportionally */
    for (i=0; i < aadlbox->num_connections; i++)
    {
      c = aadlbox->connections[i];
      
      w_factor = (c->pos.x - oldcorner.x) / oldw; 
      h_factor = (c->pos.y - oldcorner.y) / oldh;
      
      c->pos.x = newcorner.x + w_factor * neww;
      c->pos.y = newcorner.y + h_factor * newh;
    }
    
  }

  else {    /* port handles */

    handle->pos.x = to->x;
    handle->pos.y = to->y;
  }
  
  aadlbox_update_data(aadlbox);
  
  /* FIXME !!  Should I free the given structures (to, ...) ? */
  return NULL;
}