Exemple #1
0
/*! \brief rotate a net object around a centerpoint
 *  \par Function Description
 *  This function rotates a net \a object around the point
 *  (\a world_centerx, \a world_centery).
 *
 *  \param [in] toplevel      The TOPLEVEL object
 *  \param [in] world_centerx x-coord of the rotation center
 *  \param [in] world_centery y-coord of the rotation center
 *  \param [in] angle         The angle to rotat the net object
 *  \param [in] object        The net object
 *  \note only steps of 90 degrees are allowed for the \a angle
 */
void geda_net_object_rotate (TOPLEVEL *toplevel,
			int world_centerx, int world_centery, int angle,
			OBJECT *object)
{
  int newx, newy;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->line != NULL);
  g_return_if_fail (object->type == OBJ_NET);

  if (angle == 0)
    return;

  /* translate object to origin */
  geda_net_object_translate (object, -world_centerx, -world_centery);

  geda_point_rotate_90 (object->line->x[0], object->line->y[0], angle,
                  &newx, &newy);

  object->line->x[0] = newx;
  object->line->y[0] = newy;

  geda_point_rotate_90 (object->line->x[1], object->line->y[1], angle,
                  &newx, &newy);

  object->line->x[1] = newx;
  object->line->y[1] = newy;

  geda_net_object_translate (object, world_centerx, world_centery);
}
Exemple #2
0
/*! \brief Rotate BOX OBJECT using WORLD coordinates.
 *  \par Function Description
 *  The function #o_box_rotate_world() rotate the box described by
 *  <B>*object</B> around the (<B>world_centerx</B>, <B>world_centery</B>) point by
 *  <B>angle</B> degrees.
 *  The center of rotation is in world unit.
 *
 *  \param [in]      toplevel      The TOPLEVEL object.
 *  \param [in]      world_centerx  Rotation center x coordinate in WORLD units.
 *  \param [in]      world_centery  Rotation center y coordinate in WORLD units.
 *  \param [in]      angle          Rotation angle in degrees (See note below).
 *  \param [in,out]  object         BOX OBJECT to rotate.
 *
 */
void geda_box_object_rotate (TOPLEVEL *toplevel,
			int world_centerx, int world_centery, int angle,
			OBJECT *object)
{
  int newx1, newy1;
  int newx2, newy2;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->box != NULL);
  g_return_if_fail (object->type == OBJ_BOX);

  /*! \note
   *  Only 90 degree multiple and positive angles are allowed.
   */

  /* angle must be positive */
  if(angle < 0) angle = -angle;
  /* angle must be a 90 multiple or no rotation performed */
  if((angle % 90) != 0) return;

  /*! \note
   *  The center of rotation (<B>world_centerx</B>, <B>world_centery</B>) is
   *  translated to the origin. The rotation of the upper left and lower right
   *  corner are then performed. Finally, the rotated box is translated back
   *  to its previous location.
   */
  /* translate object to origin */
  object->box->upper_x -= world_centerx;
  object->box->upper_y -= world_centery;
  object->box->lower_x -= world_centerx;
  object->box->lower_y -= world_centery;

  /* rotate the upper left corner of the box */
  geda_point_rotate_90 (object->box->upper_x, object->box->upper_y, angle,
		  &newx1, &newy1);

  /* rotate the lower left corner of the box */
  geda_point_rotate_90 (object->box->lower_x, object->box->lower_y, angle,
		  &newx2, &newy2);

  /* reorder the corners after rotation */
  object->box->upper_x = min(newx1,newx2);
  object->box->upper_y = max(newy1,newy2);
  object->box->lower_x = max(newx1,newx2);
  object->box->lower_y = min(newy1,newy2);

  /* translate object back to normal position */
  object->box->upper_x += world_centerx;
  object->box->upper_y += world_centery;
  object->box->lower_x += world_centerx;
  object->box->lower_y += world_centery;

  /* recalc boundings and world coords */
  object->w_bounds_valid_for = NULL;
}
Exemple #3
0
/*! \brief Rotates a complex object in world coordinates
 *  \par Function Description
 *  This function rotates a complex \a object around the
 *  (\a centerx,\a centery) point by \a angle degrees.
 *  The center of rotation is in world units.
 *
 *  \param [in]      toplevel  The toplevel environment.
 *  \param [in]      centerx   X coordinate of rotation center (world coords).
 *  \param [in]      centery   Y coordinate of rotation center (world coords).
 *  \param [in]      angle     Rotation angle in degrees.
 *  \param [in,out]  object    Complex object to rotate.
 */
void geda_complex_object_rotate (TOPLEVEL *toplevel,
                            int centerx, int centery,
                            int angle, OBJECT *object)
{
  int x, y;
  int newx, newy;

  g_return_if_fail (object!=NULL);
  g_return_if_fail ((object->type == OBJ_COMPLEX) ||
                    (object->type == OBJ_PLACEHOLDER));

  x = object->complex->x + (-centerx);
  y = object->complex->y + (-centery);

  geda_point_rotate_90 (x, y, angle, &newx, &newy);

  x = newx + (centerx);
  y = newy + (centery);

  geda_complex_object_translate (object, -object->complex->x, -object->complex->y);

  geda_object_list_rotate (object->complex->prim_objs, 0, 0, angle, toplevel);

  object->complex->x = 0;
  object->complex->y = 0;

  geda_complex_object_translate (object, x, y);

  object->complex->angle = ( object->complex->angle + angle ) % 360;
}
Exemple #4
0
/*! \brief rotate a text object around a centerpoint
 *  \par Function Description
 *  This function rotates a text \a object around the point
 *  (\a world_centerx, \a world_centery).
 *
 *  \param [in] toplevel      The TOPLEVEL object
 *  \param [in] world_centerx x-coord of the rotation center
 *  \param [in] world_centery y-coord of the rotation center
 *  \param [in] angle         The angle to rotate the text object
 *  \param [in] object        The text object
 *  \note only steps of 90 degrees are allowed for the \a angle
 */
void
geda_text_object_rotate (TOPLEVEL *toplevel,
                         int world_centerx,
                         int world_centery,
                         int angle,
                         OBJECT *object)
{
  int x, y;
  int newx, newy;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->text != NULL);
  g_return_if_fail (object->type == OBJ_TEXT);
  g_return_if_fail (geda_angle_is_ortho (angle));

  object->text->angle = geda_angle_normalize (object->text->angle + angle);

  x = object->text->x + (-world_centerx);
  y = object->text->y + (-world_centery);

  geda_point_rotate_90 (x, y, angle, &newx, &newy);

  x = newx + (world_centerx);
  y = newy + (world_centery);

  geda_text_object_translate (object, x-object->text->x, y-object->text->y);

  o_text_recreate(toplevel, object);
}
/*! \brief Rotate Line OBJECT using WORLD coordinates.
 *  \par Function Description
 *  This function rotates the path described by
 *  <B>*object</B> around the (<B>world_centerx</B>,<B>world_centery</B>)
 *  point by <B>angle</B> degrees.
 *  The center of rotation is in world units.
 *
 *  \param [in]      toplevel      The TOPLEVEL object.
 *  \param [in]      world_centerx  Rotation center x coordinate in WORLD units.
 *  \param [in]      world_centery  Rotation center y coordinate in WORLD units.
 *  \param [in]      angle          Rotation angle in degrees (See note below).
 *  \param [in,out]  object         Line OBJECT to rotate.
 */
void geda_path_object_rotate (TOPLEVEL *toplevel,
                          int world_centerx, int world_centery, int angle,
                          OBJECT *object)
{
  PATH_SECTION *section;
  int i;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->path != NULL);
  g_return_if_fail (object->type == OBJ_PATH);

  for (i = 0; i < object->path->num_sections; i++) {
    section = &object->path->sections[i];

    switch (section->code) {
    case PATH_CURVETO:
      /* Two control point grips */
      section->x1 -= world_centerx; section->y1 -= world_centery;
      section->x2 -= world_centerx; section->y2 -= world_centery;
      geda_point_rotate_90 (section->x1, section->y1, angle, &section->x1, &section->y1);
      geda_point_rotate_90 (section->x2, section->y2, angle, &section->x2, &section->y2);
      section->x1 += world_centerx; section->y1 += world_centery;
      section->x2 += world_centerx; section->y2 += world_centery;
      /* Fall through */
    case PATH_MOVETO:
    case PATH_MOVETO_OPEN:
    case PATH_LINETO:
      /* Destination point grip */
      section->x3 -= world_centerx; section->y3 -= world_centery;
      geda_point_rotate_90 (section->x3, section->y3, angle, &section->x3, &section->y3);
      section->x3 += world_centerx; section->y3 += world_centery;
      break;
    case PATH_END:
      break;
    }
  }
  object->w_bounds_valid_for = NULL;
}
Exemple #6
0
/*! \brief Rotate Circle OBJECT using WORLD coordinates.
 *  \par Function Description
 *  The function #geda_circle_object_rotate() rotate the circle described by
 *  <B>*object</B> around the (<B>world_centerx</B>,<B>world_centery</B>) point by
 *  angle <B>angle</B> degrees.
 *  The center of rotation is in world unit.
 *
 *  \param [in]      toplevel      The TOPLEVEL object.
 *  \param [in]      world_centerx  Rotation center x coordinate in WORLD units.
 *  \param [in]      world_centery  Rotation center y coordinate in WORLD units.
 *  \param [in]      angle          Rotation angle in degrees (See note below).
 *  \param [in,out]  object         Circle OBJECT to rotate.
 */
void
geda_circle_object_rotate (TOPLEVEL *toplevel,
                           gint world_centerx,
                           gint world_centery,
                           gint angle,
                           GedaObject *object)
{
  int newx, newy;
  int x, y;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->circle != NULL);
  g_return_if_fail (object->type == OBJ_CIRCLE);

  /* Only 90 degree multiple and positive angles are allowed. */
  /* angle must be positive */
  if(angle < 0) angle = -angle;
  /* angle must be a 90 multiple or no rotation performed */
  if((angle % 90) != 0) return;

  /*
   * The center of rotation (<B>world_centerx</B>,<B>world_centery</B>) is
   * translated to the origin. The rotation of the center around the origin
   * is then performed. Finally, the rotated circle is translated back to
   * its previous location.
   */

  /* translate object to origin */
  object->circle->center_x -= world_centerx;
  object->circle->center_y -= world_centery;

  /* rotate the center of the circle around the origin */
  x = object->circle->center_x;
  y = object->circle->center_y;
  geda_point_rotate_90 (x, y, angle, &newx, &newy);
  object->circle->center_x = newx;
  object->circle->center_y = newy;

  /* translate back in position */
  object->circle->center_x += world_centerx;
  object->circle->center_y += world_centery;

  object->w_bounds_valid_for = NULL;
}
/*! \brief
 *  \par Function Description
 *  This function rotates the world coordinates of an arc of an angle
 *  specified by <B>angle</B>. The center of the rotation is given by
 *  (<B>world_centerx</B>,<B>world_centery</B>).
 *
 *  The arc is translated in order to put the center of the rotation
 *  on the origin. The center of the arc is then rotated of the angle
 *  specified by <B>angle</B>. The start angle of the arc is incremented by <B>angle</B>.
 *
 *  The arc is finally back translated to its previous location on the page.
 *
 *  <B>world_centerx</B> and <B>world_centery</B> are in world units, <B>angle</B> is in degrees.
 *
 *  \param [in] toplevel      The TOPLEVEL object.
 *  \param [in] world_centerx
 *  \param [in] world_centery
 *  \param [in] angle
 *  \param [in] object
 */
void geda_arc_object_rotate (TOPLEVEL *toplevel,
			int world_centerx, int world_centery, int angle,
			OBJECT *object)
{
  int x, y, newx, newy;

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->arc != NULL);
  g_return_if_fail (object->type == OBJ_ARC);

  /* translate object to origin */
  object->arc->x -= world_centerx;
  object->arc->y -= world_centery;

  /* get center, and rotate center */
  x = object->arc->x;
  y = object->arc->y;
  if(angle % 90 == 0) {
    geda_point_rotate_90 (x, y, angle % 360, &newx, &newy);
  } else {
    geda_point_rotate (x, y, angle % 360, &newx, &newy);
  }
  object->arc->x = newx;
  object->arc->y = newy;

  /* apply rotation to angles */
  object->arc->start_angle = (object->arc->start_angle + angle) % 360;

  /* translate object to its previous place */
  object->arc->x += world_centerx;
  object->arc->y += world_centery;

  /* update the screen coords and the bounding box */
  object->w_bounds_valid_for = NULL;

}