/*! \brief create a new embedded object * \par Function Description * This function creates a new embedded object. * * \param [in] toplevel The TOPLEVEL object * \param [in] type The type of the object (usually OBJ_COMLEX) * \param [in] color The color of the object * \param [in] x The x location of the complex object * \param [in] y The y location of the complex object * \param [in] angle The rotation angle * \param [in] mirror The mirror status * \param [in] basename The basic name the embedded was created of * \param [in] selectable whether the object can be selected with the mouse * \return a new complex object */ OBJECT *o_complex_new_embedded(TOPLEVEL *toplevel, char type, int color, int x, int y, int angle, int mirror, const gchar *basename, int selectable) { OBJECT *new_node=NULL; new_node = s_basic_new_object(type, "complex"); new_node->complex = (COMPLEX *) g_malloc(sizeof(COMPLEX)); new_node->complex->x = x; new_node->complex->y = y; new_node->complex->angle = angle; new_node->complex->mirror = mirror; new_node->complex_basename = g_strdup(basename); new_node->complex_embedded = TRUE; new_node->color = color; new_node->selectable = selectable; new_node->complex->prim_objs = NULL; /* don't have to translate/rotate/mirror here at all since the */ /* object is in place */ return new_node; }
/*! \brief create a new net object * \par Function Description * This function creates and returns a new net object. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type The OBJECT type (usually OBJ_NET) * \param [in] color The color of the net * \param [in] x1 x-coord of the first point * \param [in] y1 y-coord of the first point * \param [in] x2 x-coord of the second point * \param [in] y2 y-coord of the second point * \return A new net OBJECT */ OBJECT *o_net_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; new_node = s_basic_new_object(type, "net"); new_node->color = color; new_node->line = (LINE *) g_malloc(sizeof(LINE)); /* check for null */ new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; new_node->line_width = NET_WIDTH; o_net_recalc (toplevel, new_node); new_node->draw_func = net_draw_func; new_node->sel_func = select_func; if (!toplevel->ADDING_SEL) { s_tile_add_object (toplevel, new_node); s_conn_update_object (toplevel, new_node); } return new_node; }
/*! \brief Create and add line OBJECT to list. * \par Function Description * This function creates a new object representing a line. * * The line is described by its two ends - <B>x1</B>,<B>y1</B> and * <B>x2</B>,<B>y2</B>. * The <B>type</B> parameter must be equal to #OBJ_LINE. * The <B>color</B> parameter corresponds to the color the box * will be drawn with. * * The #OBJECT structure is allocated with the #s_basic_new_object() * function. The structure describing the line 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 the #o_set_line_options() and * #o_set_fill_options(). * * \param [in] toplevel The TOPLEVEL object. * \param [in] type Must be OBJ_LINE. * \param [in] color Circle line color. * \param [in] x1 Upper x coordinate. * \param [in] y1 Upper y coordinate. * \param [in] x2 Lower x coordinate. * \param [in] y2 Lower y coordinate. * \return A pointer to the new end of the object list. */ OBJECT *o_line_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; /* create the object */ new_node = s_basic_new_object(type, "line"); new_node->color = color; new_node->line = (LINE *) g_malloc(sizeof(LINE)); /* describe the line with its two ends */ new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; /* line type and filling initialized to default */ o_set_line_options(toplevel, new_node, DEFAULT_OBJECT_END, TYPE_SOLID, 0, -1, -1); o_set_fill_options(toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); /* compute bounding box */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief Create a BOX OBJECT * \par Function Description * This function creates a new object representing a box. * * The box is described by its upper left corner - <B>x1</B>, <B>y1</B> - and * its lower right corner - <B>x2</B>, <B>y2</B>. * The <B>type</B> parameter must be equal to <B>OBJ_BOX</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 box 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 the #o_set_line_options() and #o_set_fill_options(). * * \param [in] toplevel The TOPLEVEL object. * \param [in] type Box type. * \param [in] color Box border color. * \param [in] x1 Upper x coordinate. * \param [in] y1 Upper y coordinate. * \param [in] x2 Lower x coordinate. * \param [in] y2 Lower y coordinate. * \return The new OBJECT */ OBJECT *o_box_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; BOX *box; /* create the object */ new_node = s_basic_new_object(type, "box"); new_node->color = color; box = (BOX *) g_malloc(sizeof(BOX)); new_node->box = box; /* describe the box with its upper left and lower right corner */ box->upper_x = x1; box->upper_y = y1; box->lower_x = x2; box->lower_y = y2; /* 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 */ o_box_recalc(toplevel, new_node); return new_node; }
/*! \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 new path object. * \par Function Description * This function creates and returns a new OBJECT representing a path * using the path shape data stored in \a path_data. The \a * path_data is subsequently owned by the returned OBJECT. * * \see geda_path_object_new(). * * \param [in] toplevel The TOPLEVEL object. * \param [in] type Must be OBJ_PATH. * \param [in] color The path color. * \param [in] path_data The #PATH data structure to use. * \return A pointer to the new end of the object list. */ OBJECT* geda_path_object_new_take_path (TOPLEVEL *toplevel, char type, int color, PATH *path_data) { OBJECT *new_node; /* create the object */ new_node = s_basic_new_object (type, "path"); new_node->color = color; new_node->path = path_data; /* path type and filling initialized to default */ o_set_line_options (toplevel, new_node, DEFAULT_OBJECT_END, TYPE_SOLID, LINE_WIDTH, -1, -1); o_set_fill_options (toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); /* compute bounding box */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief Create and add picture OBJECT to list. * \par Function Description * This function creates a new object representing a picture. * * The picture is described by its upper left corner - <B>x1</B>, <B>y1</B> - * and its lower right corner - <B>x2</B>, <B>y2</B>. * The <B>type</B> parameter must be equal to #OBJ_PICTURE. * * The #OBJECT structure is allocated with the #s_basic_init_object() * function. The structure describing the picture is allocated and * initialized with the parameters given to the function. * * \param [in] toplevel The TOPLEVEL object. * \param [in] pixbuf The GdkPixbuf picture to add. * A copy of this pixbuf is made. * \param [in] file_content Raw data of the image file. * NULL for non embedded loading. The object * object takes ownership of this buffer, and it * should not be free'd by the caller. * \param [in] file_length Length of raw data buffer * \param [in] filename File name backing this picture. * A copy of this string is made. * \param [in] ratio Picture height to width ratio. * \param [in] type Must be OBJ_PICTURE. * \param [in] x1 Upper x coordinate. * \param [in] y1 Upper y coordinate. * \param [in] x2 Lower x coordinate. * \param [in] y2 Lower y coordinate. * \param [in] angle Picture rotation angle. * \param [in] mirrored Whether the image should be mirrored or not. * \param [in] embedded Whether the embedded flag should be set or not. * \return A pointer to the new end of the object list. */ OBJECT *o_picture_new(TOPLEVEL *toplevel, GdkPixbuf *pixbuf, gchar *file_content, gsize file_length, char *filename, double ratio, char type, int x1, int y1, int x2, int y2, int angle, char mirrored, char embedded) { OBJECT *new_node; PICTURE *picture; /* create the object */ new_node = s_basic_new_object(type, "picture"); picture = (PICTURE *) g_malloc(sizeof(PICTURE)); new_node->picture = picture; /* describe the picture with its upper left and lower right corner */ picture->upper_x = x1; picture->upper_y = y1; picture->lower_x = x2; picture->lower_y = y2; picture->file_content = file_content; picture->file_length = file_length; picture->filename = g_strdup (filename); picture->ratio = ratio; picture->pixbuf = gdk_pixbuf_copy (pixbuf); picture->angle = angle; picture->mirrored = mirrored; picture->embedded = embedded; /* compute the bounding picture */ o_picture_recalc(toplevel, new_node); return new_node; }
/*! \brief create a new bus object * \par Function Description * This function creates and returns a new bus object. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type The OBJECT type (usually OBJ_BUS) * \param [in] color The color of the bus * \param [in] x1 x-coord of the first point * \param [in] y1 y-coord of the first point * \param [in] x2 x-coord of the second point * \param [in] y2 y-coord of the second point * \param [in] bus_ripper_direction direction of the bus rippers * \return A new bus OBJECT */ OBJECT *o_bus_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2, int bus_ripper_direction) { OBJECT *new_node; new_node = s_basic_new_object(type, "bus"); new_node->color = color; new_node->line = (LINE *) g_malloc(sizeof(LINE)); /* check for null */ new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; new_node->line_width = BUS_WIDTH; new_node->bus_ripper_direction = bus_ripper_direction; o_bus_recalc (toplevel, new_node); return new_node; }
/*! \brief create a new arc object * * The line and fill type of the created arc are set to default. * * \param [in] toplevel The TOPLEVEL object. * \param [in] color the color index of the arc * \param [in] center_x the x coordinate of the center * \param [in] center_y the y coordinate of the center * \param [in] radius the radius of the arc * \param [in] start_angle the starting angle in degrees * \param [in] sweep_angle the sweep angle in degrees * \return the new arc object */ GedaObject* geda_arc_object_new (TOPLEVEL *toplevel, gint color, gint center_x, gint center_y, gint radius, gint start_angle, gint sweep_angle) { GedaObject *new_node; new_node = s_basic_new_object (OBJ_ARC, "arc"); new_node->color = color; new_node->arc = geda_arc_new (); /*! \note * The ARC structure is initialized with the parameters. * A default initialization is performed for the line and * fill type to avoid misunderstanding. * * The functions relative to the use of the object are sets. */ /* World coordinates */ new_node->arc->x = center_x; new_node->arc->y = center_y; new_node->arc->radius = radius; /* must check the sign of start_angle, sweep_angle ... */ if(sweep_angle < 0) { start_angle = start_angle + sweep_angle; sweep_angle = -sweep_angle; } if(start_angle < 0) start_angle = 360 + start_angle; new_node->arc->start_angle = start_angle; new_node->arc->sweep_angle = sweep_angle; /* Default init */ o_set_line_options (toplevel, new_node, DEFAULT_OBJECT_END, TYPE_SOLID, LINE_WIDTH, -1, -1); o_set_fill_options(toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); new_node->w_bounds_valid_for = NULL; /* new_node->graphical = arc; eventually */ return new_node; }
/*! \brief Create a copy of a picture. * \par Function Description * This function creates a verbatim copy of the object pointed by * <B>o_current</B> describing a picture. * * \param [in] toplevel The TOPLEVEL object. * \param [in] object Picture OBJECT to copy. * \return The new OBJECT */ OBJECT *o_picture_copy(TOPLEVEL *toplevel, OBJECT *object) { OBJECT *new_node; PICTURE *picture; /* create the object */ new_node = s_basic_new_object(object->type, "picture"); picture = g_malloc(sizeof(PICTURE)); new_node->picture = picture; if (object->saved_color == -1) { new_node->color = object->color; } else { new_node->color = object->saved_color; } /* describe the picture with its upper left and lower right corner */ picture->upper_x = object->picture->upper_x; picture->upper_y = object->picture->upper_y; picture->lower_x = object->picture->lower_x; picture->lower_y = object->picture->lower_y; if (object->picture->file_content != NULL) { picture->file_content = g_malloc (object->picture->file_length); memcpy (picture->file_content, object->picture->file_content, object->picture->file_length); } else { picture->file_content = NULL; } picture->file_length = object->picture->file_length; picture->filename = g_strdup (object->picture->filename); picture->ratio = object->picture->ratio; picture->angle = object->picture->angle; picture->mirrored = object->picture->mirrored; picture->embedded = object->picture->embedded; /* Copy the picture data */ picture->original_picture = gdk_pixbuf_copy(object->picture->original_picture); picture->displayed_picture = gdk_pixbuf_copy(object->picture->displayed_picture); new_node->draw_func = object->draw_func; new_node->sel_func = object->sel_func; /* compute the bounding picture */ o_picture_recalc(toplevel, new_node); return new_node; }
/*! \brief * \par Function Description * The function creates a new OBJECT of type arc. * * The arc is defined by its center in parameters x and y. * The radius parameter specifies the radius of the arc. The start * angle is given by start_angle and the end angle by end_angle. * The line and fill type of the created arc are set to default. * * All dimensions are in world unit, except start_angle and * end_angle in degrees. * * A new object of type OBJECT is allocated. Its type and color * are initilized. The description of the arc characteristics * are stored in a new ARC structure. * * Now fixed for world coordinates. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type * \param [in] color * \param [in] x * \param [in] y * \param [in] radius * \param [in] start_angle * \param [in] end_angle * \return */ OBJECT *o_arc_new(TOPLEVEL *toplevel, char type, int color, int x, int y, int radius, int start_angle, int end_angle) { OBJECT *new_node; new_node = s_basic_new_object(type, "arc"); new_node->color = color; new_node->arc = (ARC *) g_malloc(sizeof(ARC)); /*! \note * The ARC structure is initialized with the parameters. * A default initialization is performed for the line and * fill type to avoid misunderstanding. * * The functions relative to the use of the object are sets. */ /* World coordinates */ new_node->arc->x = x; new_node->arc->y = y; new_node->arc->width = 2 * radius; new_node->arc->height = 2 * radius; /* must check the sign of start_angle, end_angle ... */ if(end_angle < 0) { start_angle = start_angle + end_angle; end_angle = -end_angle; } if(start_angle < 0) start_angle = 360 + start_angle; new_node->arc->start_angle = start_angle; new_node->arc->end_angle = end_angle; /* Default init */ o_set_line_options(toplevel, new_node, o_get_line_end(toplevel->print_output_capstyle), TYPE_SOLID, 0, -1, -1); o_set_fill_options(toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); o_arc_recalc(toplevel, new_node); /* new_node->graphical = arc; eventually */ return new_node; }
/*! \brief Create a copy of a COMPLEX object * \par Function Description * This function creates a copy of the complex object \a o_current. * * \param [in] toplevel The TOPLEVEL object * \param [in] o_current The object that is copied * \return a new COMPLEX object */ OBJECT *o_complex_copy(TOPLEVEL *toplevel, OBJECT *o_current) { OBJECT *o_new; GList *iter; g_return_val_if_fail(o_current != NULL, NULL); o_new = s_basic_new_object(o_current->type, "complex"); o_new->color = o_current->color; o_new->selectable = o_current->selectable; o_new->complex_basename = g_strdup(o_current->complex_basename); o_new->complex_embedded = o_current->complex_embedded; o_new->complex = g_malloc0(sizeof(COMPLEX)); o_new->complex->x = o_current->complex->x; o_new->complex->y = o_current->complex->y; o_new->complex->angle = o_current->complex->angle; o_new->complex->mirror = o_current->complex->mirror; /* Copy contents and set the parent pointers on the copied objects. */ o_new->complex->prim_objs = o_glist_copy_all (toplevel, o_current->complex->prim_objs, NULL); for (iter = o_new->complex->prim_objs; iter != NULL; iter = g_list_next (iter)) { ((OBJECT*) iter->data)->parent = o_new; } /* Recalculate bounds */ o_complex_recalc(toplevel, o_new); /* Delete or hide attributes eligible for promotion inside the complex */ o_complex_remove_promotable_attribs (toplevel, o_new); s_slot_update_object (toplevel, o_new); /* deal with stuff that has changed */ /* here you need to create a list of attributes which need to be * connected to the new list, probably make an attribute list and * fill it with sid's of the attributes */ return o_new; }
/*! \brief Creates a text OBJECT and the graphical objects representing it * \par Function Description * Create an OBJECT of type OBJ_TEXT. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type OBJ_TEXT (TODO: why bother) * \param [in] color The color of the text. * \param [in] x World x coord of text. * \param [in] y World y coord of text. * \param [in] alignment How text bounding box aligns on (x, y). * \param [in] angle Angle at which text will appear. * \param [in] string The text (TODO: can be char const *)! * \param [in] size Text size. * \param [in] visibility VISIBLE or INVISIBLE. * \param [in] show_name_value SHOW_NAME_VALUE or friends. * \return Pointer to text OBJECT. * * \note * Caller is responsible for string; this function allocates its own copy. */ GedaObject* geda_text_object_new (TOPLEVEL *toplevel, gint color, gint x, gint y, gint alignment, gint angle, const gchar *string, gint size, gint visibility, gint show_name_value) { GedaObject *new_node=NULL; TEXT *text; g_return_val_if_fail (string != NULL, NULL); new_node = s_basic_new_object (OBJ_TEXT, "text"); text = (TEXT *) g_malloc(sizeof(TEXT)); text->string = g_strdup (string); text->disp_string = NULL; /* We'll fix this up later */ text->length = strlen(string); text->size = size; text->alignment = alignment; text->x = x; text->y = y; text->angle = angle; text->name = NULL; new_node->text = text; new_node->color = color; o_set_visibility (toplevel, new_node, visibility); new_node->show_name_value = show_name_value; update_disp_string (new_node); /* Update bounding box */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \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] color Circle line color. * \param [in] center_x Center x coordinate. * \param [in] center_y Center y coordinate. * \param [in] radius Radius of new circle. * \return A pointer to the new end of the object list. */ GedaObject* geda_circle_object_new (TOPLEVEL *toplevel, gint color, gint center_x, gint center_y, gint radius) { GedaObject *new_node; /* create the object */ new_node = s_basic_new_object (OBJ_CIRCLE, "circle"); new_node->color = color; new_node->circle = geda_circle_new (); /* describe the circle with its center and radius */ new_node->circle->center_x = center_x; new_node->circle->center_y = center_y; new_node->circle->radius = radius; /* line type and filling initialized to default */ o_set_line_options (toplevel, new_node, DEFAULT_OBJECT_END, TYPE_SOLID, LINE_WIDTH, -1, -1); o_set_fill_options (toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); /* compute the bounding box coords */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief Create a copy of a picture. * \par Function Description * This function creates a verbatim copy of the object pointed by * <B>o_current</B> describing a picture. * * \param [in] toplevel The TOPLEVEL object. * \param [in] object Picture OBJECT to copy. * \return The new OBJECT */ OBJECT *o_picture_copy(TOPLEVEL *toplevel, OBJECT *object) { OBJECT *new_node; PICTURE *picture; /* create the object */ new_node = s_basic_new_object(object->type, "picture"); picture = (PICTURE*) g_malloc (sizeof(PICTURE)); new_node->picture = picture; new_node->color = geda_object_get_color (object); new_node->selectable = geda_object_get_selectable (object); /* describe the picture with its upper left and lower right corner */ picture->upper_x = object->picture->upper_x; picture->upper_y = object->picture->upper_y; picture->lower_x = object->picture->lower_x; picture->lower_y = object->picture->lower_y; if (object->picture->file_content != NULL) { picture->file_content = (gchar*) g_memdup (object->picture->file_content, object->picture->file_length); } else { picture->file_content = NULL; } picture->file_length = object->picture->file_length; picture->filename = g_strdup (object->picture->filename); picture->ratio = object->picture->ratio; picture->angle = object->picture->angle; picture->mirrored = object->picture->mirrored; picture->embedded = object->picture->embedded; /* Get the picture data */ picture->pixbuf = o_picture_get_pixbuf (toplevel, object); /* compute the bounding picture */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief create a new net object * \par Function Description * This function creates and returns a new net object. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type The OBJECT type (usually OBJ_NET) * \param [in] color The color of the net * \param [in] x1 x-coord of the first point * \param [in] y1 y-coord of the first point * \param [in] x2 x-coord of the second point * \param [in] y2 y-coord of the second point * \return A new net OBJECT */ OBJECT *o_net_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; new_node = s_basic_new_object(type, "net"); new_node->color = color; new_node->line = (LINE *) g_malloc(sizeof(LINE)); /* check for null */ new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; new_node->line_width = NET_WIDTH; o_net_recalc (toplevel, new_node); return new_node; }
/*! \brief create a new net object * \par Function Description * This function creates and returns a new net object. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type The OBJECT type (usually OBJ_NET) * \param [in] color The color of the net * \param [in] x1 x-coord of the first point * \param [in] y1 y-coord of the first point * \param [in] x2 x-coord of the second point * \param [in] y2 y-coord of the second point * \return A new net OBJECT */ OBJECT* geda_net_object_new (TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; new_node = s_basic_new_object(type, "net"); new_node->color = color; new_node->line = geda_line_new (); new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; new_node->line_width = NET_WIDTH; new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief Create a BOX OBJECT * \par Function Description * This function creates a new object representing a box. * * The box is described by its upper left corner - <B>x1</B>, <B>y1</B> - and * its lower right corner - <B>x2</B>, <B>y2</B>. * The <B>type</B> parameter must be equal to <B>OBJ_BOX</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 box 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 the #o_set_line_options() and #o_set_fill_options(). * * \param [in] toplevel The TOPLEVEL object. * \param [in] type Box type. * \param [in] color Box border color. * \param [in] x1 Upper x coordinate. * \param [in] y1 Upper y coordinate. * \param [in] x2 Lower x coordinate. * \param [in] y2 Lower y coordinate. * \return The new OBJECT */ OBJECT* geda_box_object_new (TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2) { OBJECT *new_node; BOX *box; /* create the object */ new_node = s_basic_new_object(type, "box"); new_node->color = color; box = geda_box_new (); new_node->box = box; /* describe the box with its upper left and lower right corner */ box->upper_x = x1; box->upper_y = y1; box->lower_x = x2; box->lower_y = y2; /* line type and filling initialized to default */ o_set_line_options (toplevel, new_node, DEFAULT_OBJECT_END, TYPE_SOLID, LINE_WIDTH, -1, -1); o_set_fill_options(toplevel, new_node, FILLING_HOLLOW, -1, -1, -1, -1, -1); /* compute the bounding box */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief create a new pin object * \par Function Description * This function creates and returns a new pin object. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type The OBJECT type (usually OBJ_PIN) * \param [in] color The color of the pin * \param [in] x1 x-coord of the first point * \param [in] y1 y-coord of the first point * \param [in] x2 x-coord of the second point * \param [in] y2 y-coord of the second point * \param [in] pin_type type of pin (PIN_TYPE_NET or PIN_TYPE_BUS) * \param [in] whichend The connectable end of the pin * \return A new pin OBJECT */ OBJECT *o_pin_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2, int pin_type, int whichend) { OBJECT *new_node; new_node = s_basic_new_object(type, "pin"); new_node->color = color; new_node->line = (LINE *) g_malloc(sizeof(LINE)); new_node->line->x[0] = x1; new_node->line->y[0] = y1; new_node->line->x[1] = x2; new_node->line->y[1] = y2; o_pin_set_type (toplevel, new_node, pin_type); o_pin_recalc (toplevel, new_node); new_node->whichend = whichend; return new_node; }
/*! \brief Create a picture object. * \par Function Description * This function creates a new object representing a picture. * * The picture is described by its upper left corner (\a x1, \a y1) * and its lower right corner (\a x2, \a y2). The \a type parameter * must be equal to #OBJ_PICTURE. * * If \a file_content is non-NULL, it must be a pointer to a buffer * containing raw image data. If loading data from \a file_content * is unsuccessful, and \a filename is non-NULL, an image will * attempt to be loaded from \a filename. Otherwise, the picture * object will be initially empty. * * \param [in] toplevel The TOPLEVEL object. * \param [in] file_content Raw data of the image file, or NULL. * \param [in] file_length Length of raw data buffer * \param [in] filename File name backing this picture, or NULL. * \param [in] type Must be OBJ_PICTURE. * \param [in] x1 Upper x coordinate. * \param [in] y1 Upper y coordinate. * \param [in] x2 Lower x coordinate. * \param [in] y2 Lower y coordinate. * \param [in] angle Picture rotation angle. * \param [in] mirrored Whether the image should be mirrored or not. * \param [in] embedded Whether the embedded flag should be set or not. * \return A pointer to a new picture #OBJECT. */ OBJECT *o_picture_new (TOPLEVEL *toplevel, const gchar *file_content, gsize file_length, const gchar *filename, char type, int x1, int y1, int x2, int y2, int angle, int mirrored, int embedded) { OBJECT *new_node; PICTURE *picture; /* create the object */ new_node = s_basic_new_object(type, "picture"); picture = geda_picture_new (); new_node->picture = picture; /* describe the picture with its upper left and lower right corner */ picture->upper_x = (x1 > x2) ? x2 : x1; picture->upper_y = (y1 > y2) ? y1 : y2; picture->lower_x = (x1 > x2) ? x1 : x2; picture->lower_y = (y1 > y2) ? y2 : y1; picture->pixbuf = NULL; picture->file_content = NULL; picture->file_length = 0; picture->ratio = abs ((double) (x1 - x2) / (y1 - y2)); picture->filename = g_strdup (filename); picture->angle = angle; picture->mirrored = mirrored; picture->embedded = embedded; if (file_content != NULL) { GError *error = NULL; if (!o_picture_set_from_buffer (toplevel, new_node, filename, file_content, file_length, &error)) { s_log_message (_("Failed to load buffer image [%1$s]: %2$s"), filename, error->message); g_error_free (error); /* Force the data into the object anyway, so as to prevent data * loss of embedded images. */ picture->file_content = (gchar*) g_memdup (file_content, file_length); picture->file_length = file_length; } } if (picture->pixbuf == NULL && filename != NULL) { GError *error = NULL; if (!o_picture_set_from_file (toplevel, new_node, filename, &error)) { s_log_message (_("Failed to load image from [%1$s]: %2$s"), filename, error->message); g_error_free (error); /* picture not found; try to open a fall back pixbuf */ picture->pixbuf = o_picture_get_fallback_pixbuf(toplevel); } } /* compute the bounding picture */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief * \par Function Description * */ OBJECT *o_complex_new(TOPLEVEL *toplevel, char type, int color, int x, int y, int angle, int mirror, const CLibSymbol *clib, const gchar *basename, int selectable) { OBJECT *new_node=NULL; GList *iter; gchar *buffer = NULL; new_node = s_basic_new_object(type, "complex"); if (clib != NULL) { new_node->complex_basename = g_strdup (s_clib_symbol_get_name (clib)); } else { new_node->complex_basename = g_strdup (basename); } new_node->complex_embedded = FALSE; new_node->color = color; new_node->selectable = selectable; new_node->complex = (COMPLEX *) g_malloc(sizeof(COMPLEX)); new_node->complex->prim_objs = NULL; new_node->complex->angle = angle; new_node->complex->mirror = mirror; new_node->complex->x = x; new_node->complex->y = y; /* get the symbol data */ if (clib != NULL) { buffer = s_clib_symbol_get_data (clib); } if (clib == NULL || buffer == NULL) create_placeholder(toplevel, new_node, x, y); else { GError * err = NULL; /* add connections till translated */ new_node->complex->prim_objs = o_read_buffer (toplevel, NULL, buffer, -1, new_node->complex_basename, &err); if (err) { g_error_free(err); /* If reading fails, replace with placeholder object */ create_placeholder(toplevel, new_node, x, y); } else { if (mirror) { geda_object_list_mirror (new_node->complex->prim_objs, 0, 0, toplevel); } geda_object_list_rotate (new_node->complex->prim_objs, 0, 0, angle, toplevel); geda_object_list_translate (new_node->complex->prim_objs, x, y); } g_free (buffer); } /* set the parent field now */ for (iter = new_node->complex->prim_objs; iter != NULL; iter = g_list_next (iter)) { OBJECT *tmp = iter->data; tmp->parent = new_node; } new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief * \par Function Description * */ OBJECT *o_complex_new(TOPLEVEL *toplevel, char type, int color, int x, int y, int angle, int mirror, const CLibSymbol *clib, const gchar *basename, int selectable) { OBJECT *new_node=NULL; OBJECT *new_prim_obj; GList *prim_objs; GList *iter; int loaded_normally = FALSE; gchar *buffer = NULL; new_node = s_basic_new_object(type, "complex"); if (clib != NULL) { new_node->complex_basename = g_strdup (s_clib_symbol_get_name (clib)); } else { new_node->complex_basename = g_strdup (basename); } new_node->complex_embedded = FALSE; new_node->color = color; new_node->selectable = selectable; new_node->complex = (COMPLEX *) g_malloc(sizeof(COMPLEX)); new_node->complex->angle = angle; new_node->complex->mirror = mirror; new_node->complex->x = x; new_node->complex->y = y; prim_objs = NULL; /* get the symbol data */ if (clib != NULL) { buffer = s_clib_symbol_get_data (clib); } if (clib == NULL || buffer == NULL) { char *not_found_text = NULL; int left, right, top, bottom; int x_offset, y_offset; /* filename was NOT found */ loaded_normally = FALSE; /* Put placeholder into object list. Changed by SDB on * 1.19.2005 to fix problem that symbols were silently * deleted by gattrib when RC files were messed up. */ new_node->type = OBJ_PLACEHOLDER; /* Mark the origin of the missing component */ new_prim_obj = o_line_new(toplevel, OBJ_LINE, DETACHED_ATTRIBUTE_COLOR, x - 50, y, x + 50, y); prim_objs = g_list_append (prim_objs, new_prim_obj); new_prim_obj = o_line_new(toplevel, OBJ_LINE, DETACHED_ATTRIBUTE_COLOR, x, y + 50, x, y - 50); prim_objs = g_list_append (prim_objs, new_prim_obj); /* Add some useful text */ not_found_text = g_strdup_printf (_("Component not found:\n %s"), new_node->complex_basename); new_prim_obj = o_text_new(toplevel, OBJ_TEXT, DETACHED_ATTRIBUTE_COLOR, x + NOT_FOUND_TEXT_X, y + NOT_FOUND_TEXT_Y, LOWER_LEFT, 0, not_found_text, 8, VISIBLE, SHOW_NAME_VALUE); prim_objs = g_list_append (prim_objs, new_prim_obj); g_free(not_found_text); /* figure out where to put the hazard triangle */ world_get_text_bounds (toplevel, new_prim_obj, &left, &top, &right, &bottom); x_offset = (right - left) / 4; y_offset = bottom - top + 100; /* 100 is just an additional offset */ /* add hazard triangle */ new_prim_obj = o_line_new(toplevel, OBJ_LINE, DETACHED_ATTRIBUTE_COLOR, x + NOT_FOUND_TEXT_X + x_offset, y + NOT_FOUND_TEXT_Y + y_offset, x + NOT_FOUND_TEXT_X + x_offset + 600, y + NOT_FOUND_TEXT_Y + y_offset); o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID, 50, -1, -1); prim_objs = g_list_append (prim_objs, new_prim_obj); new_prim_obj = o_line_new(toplevel, OBJ_LINE, DETACHED_ATTRIBUTE_COLOR, x + NOT_FOUND_TEXT_X + x_offset, y + NOT_FOUND_TEXT_Y + y_offset, x + NOT_FOUND_TEXT_X + x_offset + 300, y + NOT_FOUND_TEXT_Y + y_offset + 500); o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID, 50, -1, -1); prim_objs = g_list_append (prim_objs, new_prim_obj); new_prim_obj = o_line_new(toplevel, OBJ_LINE, DETACHED_ATTRIBUTE_COLOR, x + NOT_FOUND_TEXT_X + x_offset + 300, y + NOT_FOUND_TEXT_Y + y_offset + 500, x + NOT_FOUND_TEXT_X + x_offset + 600, y + NOT_FOUND_TEXT_Y + y_offset); o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID, 50, -1, -1); prim_objs = g_list_append (prim_objs, new_prim_obj); new_prim_obj = o_text_new(toplevel, OBJ_TEXT, DETACHED_ATTRIBUTE_COLOR, x + NOT_FOUND_TEXT_X + x_offset + 270, y + NOT_FOUND_TEXT_Y + y_offset + 90, LOWER_LEFT, 0, "!", 18, VISIBLE, SHOW_NAME_VALUE); prim_objs = g_list_append (prim_objs, new_prim_obj); } else { /* filename was found */ loaded_normally = TRUE; /* add connections till translated */ prim_objs = o_read_buffer (toplevel, prim_objs, buffer, -1, new_node->complex_basename); g_free (buffer); } /* do not mirror/rotate/translate/connect the primitive objects if the * component was not loaded via o_read */ if (loaded_normally == TRUE) { if (mirror) { o_glist_mirror_world (toplevel, 0, 0, prim_objs); } o_glist_rotate_world (toplevel, 0, 0, angle, prim_objs); o_glist_translate_world (toplevel, x, y, prim_objs); } new_node->complex->prim_objs = prim_objs; /* set the parent field now */ for (iter = prim_objs; iter != NULL; iter = g_list_next (iter)) { OBJECT *tmp = iter->data; tmp->parent = new_node; } o_complex_recalc(toplevel, new_node); return new_node; }