/*! \brief Modify the description of a circle OBJECT. * \par Function Description * This function modifies the description of the circle object <B>*object</B> * depending on <B>whichone</B> that give the meaning of the <B>x</B> and <B>y</B> * parameters. * * If <B>whichone</B> is equal to <B>CIRCLE_CENTER</B>, the new center of the * circle is given by (<B>x</B>,<B>y</B>) where <B>x</B> and <B>y</B> are in world units. * * If <B>whichone</B> is equal to <B>CIRCLE_RADIUS</B>, the radius is given by * <B>x</B> - in world units. <B>y</B> is ignored. * * The bounding box of the circle object is updated after the modification of its * parameters. * * \param [in] toplevel The TOPLEVEL object. * \param [in,out] object Circle OBJECT to modify. * \param [in] x New center x coordinate, or radius value. * \param [in] y New center y coordinate. * Unused if radius is being modified. * \param [in] whichone Which circle parameter to modify. * * <B>whichone</B> can have the following values: * <DL> * <DT>*</DT><DD>CIRCLE_CENTER * <DT>*</DT><DD>CIRCLE_RADIUS * </DL> */ void o_circle_modify(TOPLEVEL *toplevel, OBJECT *object, int x, int y, int whichone) { o_emit_pre_change_notify (toplevel, object); switch(whichone) { case CIRCLE_CENTER: /* modify the center of the circle */ object->circle->center_x = x; object->circle->center_y = y; break; case CIRCLE_RADIUS: /* modify the radius of the circle */ if (x == 0) { s_log_message(_("Null radius circles are not allowed\n")); return; } object->circle->radius = x; break; default: break; } /* recalculate the boundings */ o_circle_recalc(toplevel, object); o_emit_change_notify (toplevel, object); }
/*! \brief Create and add circle OBJECT to list. * \par Function Description * This function creates a new object representing a circle. * * The circle is described by its center (<B>x</B>,<B>y</B>) and its radius * <B>radius</B>. * The <B>type</B> parameter must be equal to <B>OBJ_CIRCLE</B>. The <B>color</B> * corresponds to the color the box will be drawn with. * * The <B>OBJECT</B> structure is allocated with the #s_basic_new_object() * function. The structure describing the circle is allocated and initialized * with the parameters given to the function. * * Both the line type and the filling type are set to default values : solid * line type with a width of 0, and no filling. It can be changed after * with #o_set_line_options() and #o_set_fill_options(). * * \param [in] toplevel The TOPLEVEL object. * \param [in] type Must be OBJ_CIRCLE. * \param [in] color Circle line color. * \param [in] x Center x coordinate. * \param [in] y Center y coordinate. * \param [in] radius Radius of new circle. * \return A pointer to the new end of the object list. */ OBJECT *o_circle_new(TOPLEVEL *toplevel, char type, int color, int x, int y, int radius) { OBJECT *new_node; /* create the object */ new_node = s_basic_new_object(type, "circle"); new_node->color = color; new_node->circle = (CIRCLE *) g_malloc(sizeof(CIRCLE)); /* describe the circle with its center and radius */ new_node->circle->center_x = x; new_node->circle->center_y = y; new_node->circle->radius = radius; /* line type and filling initialized to default */ o_set_line_options(toplevel, new_node, END_NONE, TYPE_SOLID, 0, -1, -1); o_set_fill_options(toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); /* compute the bounding box coords */ o_circle_recalc(toplevel, new_node); return new_node; }
/*! \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; }
/*! \brief Translate a circle position in WORLD coordinates by a delta. * \par Function Description * This function applies a translation of (<B>x1</B>,<B>y1</B>) to the circle * described by <B>*object</B>. <B>x1</B> and <B>y1</B> are in world unit. * * \param [in] toplevel The TOPLEVEL object. * \param [in] dx x distance to move. * \param [in] dy y distance to move. * \param [in,out] object Circle OBJECT to translate. */ void o_circle_translate_world(TOPLEVEL *toplevel, int dx, int dy, OBJECT *object) { /* Do world coords */ object->circle->center_x = object->circle->center_x + dx; object->circle->center_y = object->circle->center_y + dy; /* recalc the screen coords and the bounding box */ o_circle_recalc(toplevel, object); }
/*! \brief Recalculate position of the given object. * \par Function Description * This function will take an object and recalculate its * position on the screen. * * \param [in] toplevel The TOPLEVEL object. * \param [in,out] o_current OBJECT to recalculate. * */ void o_recalc_single_object(TOPLEVEL *toplevel, OBJECT *o_current) { if (o_current != NULL) { switch(o_current->type) { case(OBJ_LINE): o_line_recalc(toplevel, o_current); break; case(OBJ_NET): o_net_recalc(toplevel, o_current); break; case(OBJ_BUS): o_bus_recalc(toplevel, o_current); break; case(OBJ_BOX): o_box_recalc(toplevel, o_current); break; case(OBJ_PATH): o_path_recalc(toplevel, o_current); break; case(OBJ_PICTURE): o_picture_recalc(toplevel, o_current); break; case(OBJ_CIRCLE): o_circle_recalc(toplevel, o_current); break; case(OBJ_COMPLEX): case(OBJ_PLACEHOLDER): o_complex_recalc(toplevel, o_current); break; case(OBJ_PIN): o_pin_recalc(toplevel, o_current); break; case(OBJ_ARC): o_arc_recalc(toplevel, o_current); break; case(OBJ_TEXT): o_text_recalc(toplevel, o_current); break; } } }
/*! \brief Mirror circle using WORLD coordinates. * \par Function Description * This function recalculates the screen coords of the <B>o_current</B> pointed * circle object from its world coords. * * The circle coordinates and its bounding are recalculated as well as the * OBJECT specific (line width, filling ...). * * \param [in] toplevel The TOPLEVEL object. * \param [in] world_centerx Origin x coordinate in WORLD units. * \param [in] world_centery Origin y coordinate in WORLD units. * \param [in,out] object Circle OBJECT to mirror. */ void o_circle_mirror_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object) { /* translate object to origin */ object->circle->center_x -= world_centerx; object->circle->center_y -= world_centery; /* mirror the center of the circle */ object->circle->center_x = -object->circle->center_x; object->circle->center_y = object->circle->center_y; /* translate back in position */ object->circle->center_x += world_centerx; object->circle->center_y += world_centery; /* recalc boundings and screen coords */ o_circle_recalc(toplevel, object); }
/*! \brief Rotate Circle OBJECT using WORLD coordinates. * \par Function Description * The function #o_circle_rotate_world() 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 o_circle_rotate_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object) { int newx, newy; int x, y; /* 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; rotate_point_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; o_circle_recalc(toplevel, object); }