Example #1
0
/*! \brief Create a copy of a circle.
 *  \par Function Description
 *  The function #o_circle_copy() creates a verbatim copy of the object
 *  pointed by <B>o_current</B> describing a circle.
 *
 *  \param [in]  toplevel  The TOPLEVEL object.
 *  \param [in]  o_current  Circle OBJECT to copy.
 *  \return The new OBJECT
 */
OBJECT *o_circle_copy(TOPLEVEL *toplevel, OBJECT *o_current)
{
    OBJECT *new_obj;

    /* A new circle object is created with #o_circle_new().
     * Values for its fields are default and need to be modified. */
    new_obj = o_circle_new (toplevel, OBJ_CIRCLE, o_current->color, 0, 0, 0);

    /*
     * The parameters of the new circle are set with the ones of the original
     * circle. The two circle have the same line type and the same filling
     * options.
     *
     * The bounding box coordinates are computed with
     * #o_circle_recalc().
     */
    /* modify */
    new_obj->circle->center_x = o_current->circle->center_x;
    new_obj->circle->center_y = o_current->circle->center_y;
    new_obj->circle->radius   = o_current->circle->radius;

    o_set_line_options(toplevel, new_obj, o_current->line_end,
                       o_current->line_type, o_current->line_width,
                       o_current->line_length, o_current->line_space);
    o_set_fill_options(toplevel, new_obj,
                       o_current->fill_type, o_current->fill_width,
                       o_current->fill_pitch1, o_current->fill_angle1,
                       o_current->fill_pitch2, o_current->fill_angle2);

    o_circle_recalc(toplevel, new_obj);

    /*	new_obj->attribute = 0;*/

    return new_obj;
}
Example #2
0
/*! \brief End the input of a circle.
 *  \par Function Description
 *  This function ends the input of the radius of the circle.
 *  The (<B>w_x</B>,<B>w_y</B>) point is taken as the other end of the radius
 *  segment, i.e. on the circle. The distance between this point and the
 *  center is the radius of the circle.
 *  <B>w_x</B> and <B>w_y</B> are in world coords.
 *
 *  The center has previously been input and saved as
 *  (<B>w_current->first_wx</B>,<B>w_current->first_wy</B>).
 *
 *  The temporary circle drawn during the input of the radius is erased.
 *  A new object is allocated, initialized and linked in the object list.
 *  This new object is finally drawn.
 *
 *  \param [in] w_current  The GschemToplevel object.
 *  \param [in] w_x        (unused)
 *  \param [in] w_y        (unused)
 */
void o_circle_end(GschemToplevel *w_current, int w_x, int w_y)
{
  OBJECT *new_obj;

  GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current);
  g_return_if_fail (page_view != NULL);

  g_assert( w_current->inside_action != 0 );

  PAGE *page = gschem_page_view_get_page (page_view);
  g_return_if_fail (page != NULL);

  TOPLEVEL *toplevel = page->toplevel;
  g_return_if_fail (toplevel != NULL);

  /* erase the temporary circle */
  /* o_circle_invalidate_rubber (w_current); */
  w_current->rubber_visible = 0;

  /* circle with null radius are not allowed */
  if (w_current->distance == 0) {
    /* cancel the object creation */
    return;
  }

  /* create the object */
  new_obj = o_circle_new (toplevel, OBJ_CIRCLE, GRAPHIC_COLOR,
                          w_current->first_wx, w_current->first_wy,
                          w_current->distance);
  s_page_append (toplevel, page, new_obj);

  /* Call add-objects-hook */
  g_run_hook_object (w_current, "%add-objects-hook", new_obj);

  gschem_toplevel_page_content_changed (w_current, page);
  o_undo_savestate(w_current, page, UNDO_ALL);

  i_action_stop (w_current);
}
Example #3
0
/*! \brief Create circle OBJECT from character string.
 *  \par Function Description
 *  The #o_circle_read() function gets from the character string <B>*buff</B> the
 *  description of a circle.
 *
 *  Depending on <B>*version</B>, the right file format is considered.
 *  Currently two file format revisions are supported :
 *  <DL>
 *    <DT>*</DT><DD>the file format used until 2000704 release.
 *    <DT>*</DT><DD>the file format used for the releases after 20000704.
 *  </DL>
 *
 *  \param [in]  toplevel       The TOPLEVEL object.
 *  \param [in]  buf             Character string with circle description.
 *  \param [in]  release_ver     libgeda release version number.
 *  \param [in]  fileformat_ver  libgeda file format version number.
 *  \return A pointer to the new circle object.
 */
OBJECT *o_circle_read (TOPLEVEL *toplevel, char buf[],
                       unsigned int release_ver, unsigned int fileformat_ver)
{
    OBJECT *new_obj;
    char type;
    int x1, y1;
    int radius;
    int color;
    int circle_width, circle_space, circle_length;
    int fill_width, angle1, pitch1, angle2, pitch2;
    int circle_end;
    int circle_type;
    int circle_fill;

    if(release_ver <= VERSION_20000704) {
        /*
         * The old geda file format, i.e. releases 20000704 and older, does not
         * handle the line type and the filling of the box object. They are set
         * to default.
         */
        sscanf(buf, "%c %d %d %d %d\n", &type, &x1, &y1, &radius, &color);

        circle_width = 0;
        circle_end   = END_NONE;
        circle_type  = TYPE_SOLID;
        circle_length= -1;
        circle_space = -1;

        circle_fill  = FILLING_HOLLOW;
        fill_width  = 0;
        angle1      = -1;
        pitch1      = -1;
        angle2      = -1;
        pitch2      = -1;

    } else {

        /*
         * The current line format to describe a circle is a space separated
         * list of characters and numbers in plain ASCII on a single line. The
         * meaning of each item is described in the file format documentation.
         */
        sscanf(buf, "%c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
               &type, &x1, &y1, &radius, &color,
               &circle_width, &circle_end, &circle_type,
               &circle_length, &circle_space, &circle_fill,
               &fill_width, &angle1, &pitch1, &angle2, &pitch2);
    }


    if (radius == 0) {
        s_log_message(_("Found a zero radius circle [ %c %d %d %d %d ]\n"),
                      type, x1, y1, radius, color);

    }

    if (color < 0 || color > MAX_COLORS) {
        s_log_message(_("Found an invalid color [ %s ]\n"), buf);
        s_log_message(_("Setting color to default color\n"));
        color = DEFAULT_COLOR;
    }

    /*
     * A circle is internally described by its center and its radius.
     *
     * A new object is allocated, initialized and added to the object list.
     * Its filling and line type are set according to the values of the field
     * on the line.
     */
    new_obj = o_circle_new(toplevel, type, color, x1, y1, radius);
    o_set_line_options(toplevel, new_obj,
                       circle_end, circle_type, circle_width,
                       circle_length, circle_space);
    o_set_fill_options(toplevel, new_obj,
                       circle_fill, fill_width, pitch1, angle1, pitch2, angle2);

    return new_obj;
}