/*! \brief Get symbol data for a given symbol name. * \par Function Description * Return the data for the first symbol found with the given name. * This is a helper function for the schematic load system, as it * will always want to load symbols given only their name. * * On failure, returns \b NULL (the error will be logged). * * \param name The symbol name to match against. * \return Allocated buffer containing symbol data. */ gchar *s_clib_symbol_get_data_by_name (const gchar *name) { const CLibSymbol *symbol; symbol = s_clib_get_symbol_by_name (name); if (symbol == NULL) return NULL; return s_clib_symbol_get_data (symbol); }
/*! \brief unembed an object from a schematic * \par Function Description * This functions unembeds an object \a o_current from a * libgeda structure. Complex objects are just marked to * be not embedded. Picture objects are unembeded immediatly. * * \param toplevel The TOPLEVEL object * \param o_current The OBJECT to unembed */ void o_unembed(TOPLEVEL *toplevel, OBJECT *o_current) { const CLibSymbol *sym; PAGE *page = o_get_page_compat (toplevel, o_current); int page_modified = 0; /* check o_current is an embedded complex */ if (o_current->type == OBJ_COMPLEX && o_complex_is_embedded (o_current)) { /* search for the symbol in the library */ sym = s_clib_get_symbol_by_name (o_current->complex_basename); if (sym == NULL) { /* symbol not found in the symbol library: signal an error */ s_log_message (_("Could not find component [%s], while trying to " "unembed. Component is still embedded\n"), o_current->complex_basename); } else { /* clear the embedded flag */ o_current->complex_embedded = FALSE; s_log_message (_("Component [%s] has been successfully unembedded\n"), o_current->complex_basename); page_modified = 1; } } /* If it's a picture and it's embedded */ if ( (o_current->type == OBJ_PICTURE) && o_picture_is_embedded (toplevel, o_current)) { o_picture_unembed (toplevel, o_current); page_modified = 1; } if (page_modified && page != NULL) { page->CHANGED = 1; } }
/*! \brief read a complex object from a char buffer * \par Function Description * This function reads a complex object from the buffer \a buf. * If the complex object was read successfully, a new object is * allocated and appended to the \a object_list. * * \param [in] toplevel The TOPLEVEL object * \param [in] buf a text buffer (usually a line of a schematic file) * \param [in] release_ver The release number gEDA * \param [in] fileformat_ver a integer value of the file format * \return The object list */ OBJECT *o_complex_read (TOPLEVEL *toplevel, char buf[], unsigned int release_ver, unsigned int fileformat_ver) { OBJECT *new_obj; char type; int x1, y1; int angle; char *basename = g_malloc (1 + strlen (buf)); int selectable; int mirror; sscanf(buf, "%c %d %d %d %d %d %s\n", &type, &x1, &y1, &selectable, &angle, &mirror, basename); switch(angle) { case(0): case(90): case(180): case(270): break; default: s_log_message(_("Found a component with an invalid rotation [ %c %d %d %d %d %d %s ]\n"), type, x1, y1, selectable, angle, mirror, basename); break; } switch(mirror) { case(0): case(1): break; default: s_log_message(_("Found a component with an invalid mirror flag [ %c %d %d %d %d %d %s ]\n"), type, x1, y1, selectable, angle, mirror, basename); break; } if (strncmp(basename, "EMBEDDED", 8) == 0) { new_obj = o_complex_new_embedded(toplevel, type, DEFAULT_COLOR, x1, y1, angle, mirror, basename + 8, selectable); } else { const CLibSymbol *clib = s_clib_get_symbol_by_name (basename); new_obj = o_complex_new(toplevel, type, DEFAULT_COLOR, x1, y1, angle, mirror, clib, basename, selectable); /* Delete or hide attributes eligible for promotion inside the complex */ o_complex_remove_promotable_attribs (toplevel, new_obj); } g_free (basename); return new_obj; }
/*! \brief Update a component. * * \par Function Description * Updates \a o_current to the latest version of the symbol available * in the symbol library, while preserving any attributes set in the * current schematic. On success, returns the new OBJECT which * replaces \a o_current on the page; \a o_current is deleted. On * failure, returns NULL, and \a o_current is left unchanged. * * \param [in] w_current The GSCHEM_TOPLEVEL object. * \param [in,out] o_current The OBJECT to be updated. * * \return the new OBJECT that replaces \a o_current. */ OBJECT * o_update_component (GSCHEM_TOPLEVEL *w_current, OBJECT *o_current) { TOPLEVEL *toplevel = w_current->toplevel; OBJECT *o_new; PAGE *page; GList *new_attribs; GList *old_attribs; GList *iter; const CLibSymbol *clib; g_return_val_if_fail (o_current != NULL, NULL); g_return_val_if_fail (o_current->type == OBJ_COMPLEX, NULL); g_return_val_if_fail (o_current->complex_basename != NULL, NULL); page = o_get_page (toplevel, o_current); /* This should be replaced with API to invalidate only the specific * symbol name we want to update */ s_clib_flush_symbol_cache (); clib = s_clib_get_symbol_by_name (o_current->complex_basename); if (clib == NULL) { s_log_message (_("Could not find symbol [%s] in library. Update failed.\n"), o_current->complex_basename); return NULL; } /* Unselect the old object. */ o_selection_remove (toplevel, page->selection_list, o_current); /* Create new object and set embedded */ o_new = o_complex_new (toplevel, OBJ_COMPLEX, DEFAULT_COLOR, o_current->complex->x, o_current->complex->y, o_current->complex->angle, o_current->complex->mirror, clib, o_current->complex_basename, 1); if (o_complex_is_embedded (o_current)) { o_embed (toplevel, o_new); } new_attribs = o_complex_promote_attribs (toplevel, o_new); /* Cull any attributes from new COMPLEX that are already attached to * old COMPLEX. Note that the new_attribs list is kept consistent by * setting GList data pointers to NULL if their OBJECTs are * culled. At the end, the new_attribs list is updated by removing * all list items with NULL data. This is slightly magic, but * works. */ for (iter = new_attribs; iter != NULL; iter = g_list_next (iter)) { OBJECT *attr_new = iter->data; gchar *name; gchar *value; g_assert (attr_new->type == OBJ_TEXT); o_attrib_get_name_value (attr_new, &name, NULL); value = o_attrib_search_attached_attribs_by_name (o_current, name, 0); if (value != NULL) { o_attrib_remove (toplevel, &o_new->attribs, attr_new); s_delete_object (toplevel, attr_new); iter->data = NULL; } g_free (name); g_free (value); } new_attribs = g_list_remove_all (new_attribs, NULL); /* Detach attributes from old OBJECT and attach to new OBJECT */ old_attribs = g_list_copy (o_current->attribs); o_attrib_detach_all (toplevel, o_current); o_attrib_attach_list (toplevel, old_attribs, o_new, 1); g_list_free (old_attribs); /* Add new attributes to page */ s_page_append_list (toplevel, page, new_attribs); /* Update pinnumbers for current slot */ s_slot_update_object (toplevel, o_new); /* Replace old OBJECT with new OBJECT */ s_page_replace (toplevel, page, o_current, o_new); s_delete_object (toplevel, o_current); /* Select new OBJECT */ o_selection_add (toplevel, page->selection_list, o_new); /* mark the page as modified */ toplevel->page_current->CHANGED = 1; o_undo_savestate (w_current, UNDO_ALL); return o_new; }
/*! \brief Add a component to the page. * \par Function Description * Adds a component <B>scm_comp_name</B> to the schematic, at * position (<B>scm_x</B>, <B>scm_y</B>), with some properties set by * the parameters: * \param [in] scm_x Coordinate X of the symbol. * \param [in] scm_y Coordinate Y of the symbol. * \param [in] angle Angle of rotation of the symbol. * \param [in] selectable True if the symbol is selectable, false otherwise. * \param [in] mirror True if the symbol is mirrored, false otherwise. * If scm_comp_name is a scheme empty list, SCM_BOOL_F, or an empty * string (""), then g_add_component returns SCM_BOOL_F without writing * to the log. * \return TRUE if the component was added, FALSE otherwise. * */ SCM g_add_component(SCM page_smob, SCM scm_comp_name, SCM scm_x, SCM scm_y, SCM scm_angle, SCM scm_selectable, SCM scm_mirror) { TOPLEVEL *toplevel; PAGE *page; gboolean selectable, mirror; gchar *comp_name; int x, y, angle; OBJECT *new_obj; const CLibSymbol *clib; /* Return if scm_comp_name is NULL (an empty list) or scheme's FALSE */ if (SCM_NULLP(scm_comp_name) || (SCM_BOOLP(scm_comp_name) && !(SCM_NFALSEP(scm_comp_name))) ) { return SCM_BOOL_F; } /* Get toplevel and the page */ SCM_ASSERT (g_get_data_from_page_smob (page_smob, &toplevel, &page), page_smob, SCM_ARG1, "add-component-at-xy"); /* Check the arguments */ SCM_ASSERT (scm_is_string(scm_comp_name), scm_comp_name, SCM_ARG2, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_x), scm_x, SCM_ARG3, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_y), scm_y, SCM_ARG4, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_angle), scm_angle, SCM_ARG5, "add-component-at-xy"); SCM_ASSERT ( scm_boolean_p(scm_selectable), scm_selectable, SCM_ARG6, "add-component-at-xy"); SCM_ASSERT ( scm_boolean_p(scm_mirror), scm_mirror, SCM_ARG7, "add-component-at-xy"); /* Get the parameters */ comp_name = SCM_STRING_CHARS(scm_comp_name); x = scm_to_int(scm_y); y = scm_to_int(scm_y); angle = scm_to_int(scm_angle); selectable = SCM_NFALSEP(scm_selectable); mirror = SCM_NFALSEP(scm_mirror); SCM_ASSERT (comp_name, scm_comp_name, SCM_ARG2, "add-component-at-xy"); if (strcmp(comp_name, "") == 0) { return SCM_BOOL_F; } clib = s_clib_get_symbol_by_name (comp_name); new_obj = o_complex_new (toplevel, 'C', DEFAULT_COLOR, x, y, angle, mirror, clib, comp_name, selectable); s_page_append_list (page, o_complex_promote_attribs (toplevel, new_obj)); s_page_append (page, new_obj); /* * For now, do not redraw the newly added complex, since this might cause * flicker if you are zoom/panning right after this function executes */ #if 0 /* Now the new component should be added to the object's list and drawn in the screen */ o_invalidate (toplevel, new_object); #endif return SCM_BOOL_T; }