/*! \brief Ends the process of arc input. * \par Function Description * The #o_arc_end4() function ends the process of the input of an arc. * <B>start_angle</B> and <B>sweep_angle</B> are the start and sweep angle of the * arc in degrees. The partial internal representation of the arc, i.e. * the center and the radius of the arc, are converted in world units. * A new object is created and linked to the object list. * * \param [in] w_current The GschemToplevel object. * \param [in] radius Radius of the arc * \param [in] start_angle Start of angle in degrees. * \param [in] sweep_angle Angle sweep in degrees. */ void o_arc_end4(GschemToplevel *w_current, int radius, int start_angle, int sweep_angle) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (page_view != NULL); 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); OBJECT *new_obj; /* create, initialize and link the new arc object */ new_obj = geda_arc_object_new (toplevel, GRAPHIC_COLOR, w_current->first_wx, w_current->first_wy, radius, start_angle, sweep_angle); s_page_append (toplevel, page, new_obj); w_current->first_wx = -1; w_current->first_wy = -1; w_current->distance = 0; /* 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); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void o_edit_show_specific_text (GschemToplevel *w_current, const GList *o_list, const char *stext) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *o_current; const GList *iter; iter = o_list; while (iter != NULL) { o_current = (OBJECT *)iter->data; if (o_current->type == OBJ_TEXT) { const gchar *str = o_text_get_string (w_current->toplevel, o_current); if (!strncmp (stext, str, strlen (stext))) { if (!o_is_visible (toplevel, o_current)) { o_set_visibility (toplevel, o_current, VISIBLE); o_text_recreate(toplevel, o_current); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); } } } iter = g_list_next (iter); } o_undo_savestate_old(w_current, UNDO_ALL); }
/* this cannot be called recursively */ void o_unlock(GschemToplevel *w_current) { OBJECT *object = NULL; GList *s_current = NULL; s_current = geda_list_get_glist( w_current->toplevel->page_current->selection_list ); while(s_current != NULL) { object = (OBJECT *) s_current->data; if (object) { /* only unlock if the object is locked */ if (object->selectable == FALSE) { object->selectable = TRUE; object->color = object->locked_color; object->locked_color = -1; gschem_toplevel_page_content_changed (w_current, w_current->toplevel->page_current); } else { s_log_message(_("Object already unlocked\n")); } } s_current = g_list_next(s_current); } o_undo_savestate_old(w_current, UNDO_ALL); }
/*! \brief Complete the text edit * * \par Function Description * This function completes the text edit by setting all the selected text * objects to the desired values. * * \param [in] w_current The topleval gschem struct. * \param [in] string The text to set the selected text objects to. If this * string is NULL or has zero length, then this function * leaves the text unchanged. * \param [in] color The color to set the selected text to. If the color * is less than zero, then this function leaves the color * unchanged. * \param [in] align The text alignment to set the selected text to. If * the alignment is less than zero, this function leaves * the alignment unchanged. * \param [in] rotate The rotation angle to set the selected text to. If * the rotation angle is less than zero, this function * leaves the rotation angle unchanged. * \param [in] size The size to set all the selected text to. If the * size is less than or equal to zero, this function * leaves the size unchanged. */ void o_text_edit_end(GschemToplevel *w_current, char *string, int color, int align, int rotate, int size) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); TOPLEVEL *toplevel = gschem_page_view_get_toplevel (page_view); PAGE *page = gschem_page_view_get_page (page_view); OBJECT *object; GList *s_current; char *textstr = string; g_return_if_fail (toplevel != NULL); g_return_if_fail (page != NULL); if ((textstr != NULL) && (g_utf8_strlen(textstr, -1) == 0)) { textstr = NULL; } /* skip over head */ s_current = geda_list_get_glist (page->selection_list); while(s_current != NULL) { object = (OBJECT *) s_current->data; if (object) { if (object->type == OBJ_TEXT) { if (size > 0) { object->text->size = size; } if (align >= 0) { object->text->alignment = align; } if (color >= 0) { object->color = color; } if (rotate >= 0) { object->text->angle = rotate; } if (textstr != NULL) { o_text_set_string (toplevel, object, textstr); /* handle slot= attribute, it's a special case */ if (object->attached_to != NULL && g_ascii_strncasecmp (textstr, "slot=", 5) == 0) { o_slot_end (w_current, object->attached_to, textstr); } } o_text_recreate(toplevel, object); } } s_current = g_list_next(s_current); } gschem_toplevel_page_content_changed (w_current, page); o_undo_savestate(w_current, page, UNDO_ALL); }
/* This locks the entire selected list. It does lock components, but does NOT * change the color (of primatives of the components) though * this cannot be called recursively */ void o_lock(GschemToplevel *w_current) { OBJECT *object = NULL; GList *s_current = NULL; /* skip over head */ s_current = geda_list_get_glist( w_current->toplevel->page_current->selection_list ); while(s_current != NULL) { object = (OBJECT *) s_current->data; if (object) { /* check to see if locked_color is already being used */ if (object->locked_color == -1) { object->selectable = FALSE; object->locked_color = object->color; object->color = LOCK_COLOR; gschem_toplevel_page_content_changed (w_current, w_current->toplevel->page_current); } else { s_log_message(_("Object already locked\n")); } } s_current = g_list_next(s_current); } if (!w_current->SHIFTKEY) o_select_unselect_all(w_current); o_undo_savestate_old(w_current, UNDO_ALL); i_update_menus(w_current); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * * \note * The object passed in should be the REAL object, NOT any copy in any * selection list */ void o_text_change(GschemToplevel *w_current, OBJECT *object, char *string, int visibility, int show) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); TOPLEVEL *toplevel = gschem_page_view_get_toplevel (page_view); PAGE *page = gschem_page_view_get_page (page_view); g_return_if_fail (toplevel != NULL); g_return_if_fail (page != NULL); if (object == NULL) { return; } if (object->type != OBJ_TEXT) { return; } o_text_set_string (toplevel, object, string); o_set_visibility (toplevel, object, visibility); object->show_name_value = show; o_text_recreate(toplevel, object); /* handle slot= attribute, it's a special case */ if (object->attached_to != NULL && g_ascii_strncasecmp (string, "slot=", 5) == 0) { o_slot_end (w_current, object->attached_to, string); } gschem_toplevel_page_content_changed (w_current, page); }
/** @brief Removes the number from the element. * * This function updates the text content of the \a o_current object. * * @param autotext Pointer to the state structure * @param o_current Pointer to the object from which to remove the number * */ void autonumber_remove_number(AUTONUMBER_TEXT * autotext, OBJECT *o_current) { OBJECT *o_parent, *o_slot; gchar *slot_str; gchar *str = NULL; /* replace old text */ str = g_strdup_printf("%s?", autotext->current_searchtext); o_text_set_string (autotext->w_current->toplevel, o_current, str); g_free (str); /* remove the slot attribute if slotting is active */ if (autotext->slotting) { /* get the slot attribute */ o_parent = o_current->attached_to; if (o_parent != NULL) { slot_str = s_slot_search_slot (o_parent, &o_slot); g_free (slot_str); /* Only attempt to remove non-inherited slot attributes */ if (o_slot != NULL && !o_attrib_is_inherited (o_slot)) { /* delete the slot attribute */ o_delete (autotext->w_current, o_slot); } } } gschem_toplevel_page_content_changed (autotext->w_current, autotext->w_current->toplevel->page_current); }
/*! \brief Change visibility status of attribute object. * \par Function Description * This function toggles the visibility status of the attribute \a * object and updates it. The object is erased or redrawn if * necessary. * * \param [in] w_current The GschemToplevel object. * \param [in] object The attribute object. */ void o_attrib_toggle_visibility(GschemToplevel *w_current, OBJECT *object) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (object != NULL && object->type == OBJ_TEXT); if (o_is_visible (object)) { /* only erase if we are not showing hidden text */ if (!toplevel->show_hidden_text) { o_invalidate (w_current, object); } o_set_visibility (toplevel, object, INVISIBLE); if (toplevel->show_hidden_text) { /* draw text so that little I is drawn */ o_invalidate (w_current, object); } } else { /* if we are in the special show hidden mode, then erase text first */ /* to get rid of the little I */ if (toplevel->show_hidden_text) { o_invalidate (w_current, object); } o_set_visibility (toplevel, object, VISIBLE); o_text_recreate(toplevel, object); } gschem_toplevel_page_content_changed (w_current, toplevel->page_current); }
/*! \brief Rotate all objects in list. * \par Function Description * Given an object <B>list</B>, and the center of rotation * (<B>centerx</B>,<B>centery</B>, this function traverses all the selection * list, rotating each object through angle <B>angle</B>. * The list contains a given object and all its attributes * (refdes, pinname, pinlabel, ...). * There is a second pass to run the rotate hooks of non-simple objects, * like pin or complex objects, for example. * * \param [in] w_current The GschemToplevel object. * \param [in] centerx Center x coordinate of rotation. * \param [in] centery Center y coordinate of rotation. * \param [in] angle Angle to rotate the objects through. * \param [in] list The list of objects to rotate. */ void o_rotate_world_update(GschemToplevel *w_current, int centerx, int centery, int angle, GList *list) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *o_current; GList *o_iter; /* this is okay if you just hit rotate and have nothing selected */ if (list == NULL) { i_action_stop (w_current); i_set_state(w_current, SELECT); return; } o_invalidate_glist (w_current, list); /* Find connected objects, removing each object in turn from the * connection list. We only _really_ want those objects connected * to the selection, not those within in it. */ for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) { o_current = o_iter->data; s_conn_remove_object_connections (toplevel, o_current); } o_glist_rotate_world( toplevel, centerx, centery, angle, list ); /* Find connected objects, adding each object in turn back to the * connection list. We only _really_ want those objects connected * to the selection, not those within in it. */ for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) { o_current = o_iter->data; s_conn_update_object (o_current->page, o_current); } o_invalidate_glist (w_current, list); /* Run rotate-objects-hook */ g_run_hook_object_list (w_current, "%rotate-objects-hook", list); /* Don't save the undo state if we are inside an action */ /* This is useful when rotating the selection while moving, for example */ gschem_toplevel_page_content_changed (w_current, toplevel->page_current); if (!w_current->inside_action) { o_undo_savestate_old(w_current, UNDO_ALL); } if (w_current->event_state == ROTATEMODE) { i_set_state(w_current, SELECT); } }
/*! \brief finish a bus drawing action * \par Function Description * This function finishes a net drawing action. The function draws * a bus from the point (<B>first_wx</B>,<B>first_wy</B>) to * (<B>second_wx</B>,<B>second_wy</B>). Both points are taken from * the <B>GschemToplevel</B> structure. * * The function returns TRUE if a bus object has been created and * FALSE if no bus object has been created. * * \param [in] w_current The GschemToplevel object. * \param [in] w_x (unused) * \param [in] w_y (unused) */ void o_bus_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); GList *prev_conn_objects = NULL; /* erase the rubberbus */ /* o_bus_invalidate_rubber (w_current); */ w_current->rubber_visible = 0; /* don't allow zero length bus */ /* this ends the bus drawing behavior we want this? hack */ if ( (w_current->first_wx != w_current->second_wx) || (w_current->first_wy != w_current->second_wy) ) { new_obj = geda_bus_object_new (toplevel, BUS_COLOR, w_current->first_wx, w_current->first_wy, w_current->second_wx, w_current->second_wy, 0); s_page_append (toplevel, page, new_obj); /* connect the new bus to the other busses */ prev_conn_objects = s_conn_return_others (prev_conn_objects, new_obj); o_invalidate_glist (w_current, prev_conn_objects); g_list_free (prev_conn_objects); /* Call add-objects-hook */ g_run_hook_object (w_current, "%add-objects-hook", new_obj); w_current->first_wx = w_current->second_wx; w_current->first_wy = w_current->second_wy; gschem_toplevel_page_content_changed (w_current, page); o_undo_savestate(w_current, page, UNDO_ALL); } /* Don't reset w_current->inside_action here since we want to continue drawing */ }
/*! \brief Allow the undo manager to process changes * * \param [in] w_current */ static void handle_undo (GschemToplevel *w_current) { TOPLEVEL *toplevel; g_return_if_fail (w_current != NULL); toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (toplevel != NULL); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); o_undo_savestate_old (w_current, UNDO_ALL); }
/*! \brief Delete an object. * \par Function Description * This function erases the object \a object before deleting it. It * deals with connection and object connected to it. * * \param [in] w_current The GschemToplevel object. * \param [in] object The object to delete. */ void o_delete (GschemToplevel *w_current, OBJECT *object) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (object != NULL); o_selection_remove (toplevel, toplevel->page_current->selection_list, object); s_page_remove (toplevel, toplevel->page_current, object); g_run_hook_object (w_current, "%remove-objects-hook", object); s_delete_object (toplevel, object); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); }
/*! \brief Set what part of an attribute is shown. * \par Function Description * This function changes what part (name, value or both) of an * attribute is shown by its attribute object. The attribute object * is erased, updated and finally redrawn. * * \param [in] w_current The GschemToplevel object. * \param [in] object The attribute object. * \param [in] show_name_value The new display flag for attribute. */ void o_attrib_toggle_show_name_value(GschemToplevel *w_current, OBJECT *object, int show_name_value) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (object != NULL && object->type == OBJ_TEXT); o_invalidate (w_current, object); object->show_name_value = show_name_value; o_text_recreate(toplevel, object); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void o_mirror_world_update(GschemToplevel *w_current, int centerx, int centery, GList *list) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *o_current; GList *o_iter; if (list == NULL) { i_action_stop (w_current); i_set_state(w_current, SELECT); return; } o_invalidate_glist (w_current, list); /* Find connected objects, removing each object in turn from the * connection list. We only _really_ want those objects connected * to the selection, not those within in it. */ for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) { o_current = o_iter->data; s_conn_remove_object_connections (toplevel, o_current); } o_glist_mirror_world( toplevel, centerx, centery, list ); /* Find connected objects, adding each object in turn back to the * connection list. We only _really_ want those objects connected * to the selection, not those within in it. */ for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) { o_current = o_iter->data; s_conn_update_object (o_current->page, o_current); } o_invalidate_glist (w_current, list); /* Run mirror-objects-hook */ g_run_hook_object_list (w_current, "%mirror-objects-hook", list); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); o_undo_savestate_old(w_current, UNDO_ALL); if (w_current->event_state == MIRRORMODE) { i_set_state(w_current, SELECT); } }
/*! \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 = geda_circle_object_new (toplevel, 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); }
/*! \brief Changes the number <B>OBJECT</B> element. Changes the slot attribute. * \par Function Description * This function updates the text content of the <B>o_current</B> object. * If the <B>slot</B> value is not zero. It updates the slot attribut of the * complex element that is also the parent object of the o_current element. */ void autonumber_apply_new_text(AUTONUMBER_TEXT * autotext, OBJECT *o_current, gint number, gint slot) { char *str; if (slot != 0) { /* update the slot on the owning object */ str = g_strdup_printf ("slot=%d", slot); o_slot_end (autotext->w_current, o_current->attached_to, str); g_free (str); } /* replace old text */ str = g_strdup_printf("%s%d", autotext->current_searchtext, number); o_text_set_string (autotext->w_current->toplevel, o_current, str); g_free (str); gschem_toplevel_page_content_changed (autotext->w_current, autotext->w_current->toplevel->page_current); }
/*! \brief End the input of a circle. * \par Function Description * This function ends the input of the second corner of a picture. * The picture is defined by (<B>w_current->first_wx</B>,<B>w_current->first_wy</B> * and (<B>w_current->second_wx</B>,<B>w_current->second_wy</B>. * * The temporary picture frame is erased ; a new picture object is allocated, * initialized and linked to the object list ; The object is finally * drawn on the current sheet. * * \param [in] w_current The GschemToplevel object. * \param [in] w_x (unused) * \param [in] w_y (unused) */ void o_picture_end(GschemToplevel *w_current, int w_x, int w_y) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *new_obj; int picture_width, picture_height; int picture_left, picture_top; g_assert( w_current->inside_action != 0 ); /* erase the temporary picture */ /* o_picture_draw_rubber(w_current); */ w_current->rubber_visible = 0; picture_width = GET_PICTURE_WIDTH (w_current); picture_height = GET_PICTURE_HEIGHT(w_current); picture_left = GET_PICTURE_LEFT (w_current); picture_top = GET_PICTURE_TOP (w_current); /* pictures with null width and height are not allowed */ if ((picture_width == 0) && (picture_height == 0)) { /* cancel the object creation */ return; } /* create the object */ new_obj = o_picture_new(toplevel, NULL, 0, w_current->pixbuf_filename, OBJ_PICTURE, picture_left, picture_top, picture_left + picture_width, picture_top - picture_height, 0, FALSE, FALSE); s_page_append (toplevel, toplevel->page_current, new_obj); /* Run %add-objects-hook */ g_run_hook_object (w_current, "%add-objects-hook", new_obj); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); o_undo_savestate_old(w_current, UNDO_ALL); }
/*! \brief End the input of a box. * \par Function Description * This function ends the input of the second corner of a box. * The (<B>w_x</B>,<B>w_y</B>) point is set to be this second corner. The box is * then defined by (<B>w_current->first_wx</B>,<B>w_current->first_wy</B> and * (<B>w_current->second_wx</B>,<B>w_current->second_wy</B>. * <B>w_x</B> and <B>w_y</B> are in screen unit. * * The temporary box is erased ; a new box object is allocated, initialized * and linked to the object list ; The object is finally drawn on the * current sheet. * * \param [in] w_current The GschemToplevel object. * \param [in] w_x Current x coordinate of pointer in world units. * \param [in] w_y Current y coordinate of pointer in world units. */ void o_box_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); int box_width, box_height; int box_left, box_top; /* get the last coords of the pointer */ w_current->second_wx = w_x; w_current->second_wy = w_y; /* erase the temporary box */ /* o_box_invalidate_rubber (w_current); */ w_current->rubber_visible = 0; box_width = GET_BOX_WIDTH (w_current); box_height = GET_BOX_HEIGHT(w_current); box_left = GET_BOX_LEFT (w_current); box_top = GET_BOX_TOP (w_current); /* boxes with null width or height are not allowed */ if ((box_width == 0) || (box_height == 0)) { /* cancel the object creation */ w_current->first_wx = (-1); w_current->first_wy = (-1); w_current->second_wx = (-1); w_current->second_wy = (-1); } else { /* create the object */ new_obj = geda_box_object_new (toplevel, OBJ_BOX, GRAPHIC_COLOR, box_left, box_top, box_left + box_width, box_top - box_height); s_page_append (toplevel, page, new_obj); #if DEBUG printf("coords: %d %d %d %d\n", box_left, box_top, box_width, box_height); #endif w_current->first_wx = (-1); w_current->first_wy = (-1); w_current->second_wx = (-1); w_current->second_wy = (-1); /* 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); }
/*! \brief End placement action * * \par Function Description * This function finishes the current placement action by adding * objects to the current page at the given new world coordinates * and redrawing them on the canvas. It also saves the current * state in the undo list and updates the menus. * * If \a continue_placing is TRUE, a copy of the placement list * is saved to start a new place action. * * \param [in] w_current GschemToplevel which we're drawing for. * \param [in] w_x The current world X coordinate. * \param [in] w_y The current world Y coordinate. * \param [in] hook_name The hook to run after adding the objects. */ void o_place_end (GschemToplevel *w_current, int w_x, int w_y, int continue_placing, const char* hook_name) { int w_diff_x, w_diff_y; OBJECT *o_current; GList *temp_dest_list = NULL; GList *connected_objects = NULL; GList *iter; g_return_if_fail (w_current != NULL); g_assert (w_current->inside_action != 0); GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (page_view != NULL); PAGE *page = gschem_page_view_get_page (page_view); g_return_if_fail (page != NULL); /* erase old image */ /* o_place_invalidate_rubber (w_current, FALSE); */ w_current->rubber_visible = 0; /* Calc final object positions */ w_current->second_wx = w_x; w_current->second_wy = w_y; w_diff_x = w_current->second_wx - w_current->first_wx; w_diff_y = w_current->second_wy - w_current->first_wy; if (continue_placing) { /* Make a copy of the place list if we want to keep it afterwards */ temp_dest_list = o_glist_copy_all (page->toplevel, page->place_list, temp_dest_list); } else { /* Otherwise just take it */ temp_dest_list = page->place_list; page->place_list = NULL; } geda_object_list_translate (temp_dest_list, w_diff_x, w_diff_y); /* Attach each item back onto the page's object list. Update object * connectivity and add the new objects to the selection list.*/ for (iter = temp_dest_list; iter != NULL; iter = g_list_next (iter)) { o_current = (OBJECT*) iter->data; s_page_append (page->toplevel, page, o_current); /* Update object connectivity */ s_conn_update_object (page, o_current); connected_objects = s_conn_return_others (connected_objects, o_current); } if (hook_name != NULL) { g_run_hook_object_list (w_current, hook_name, temp_dest_list); } o_invalidate_glist (w_current, connected_objects); g_list_free (connected_objects); connected_objects = NULL; gschem_toplevel_page_content_changed (w_current, page); o_invalidate_glist (w_current, temp_dest_list); /* only redraw new objects */ g_list_free (temp_dest_list); o_undo_savestate_old (w_current, UNDO_ALL); i_update_menus (w_current); if (!continue_placing) { i_set_state(w_current, SELECT); i_action_stop (w_current); } }
/*! \brief End the input of a path. * \par Function Description * This function ends the process of interactively adding a path to the * current sheet. * * It first erases the last temporary path displayed, calculates the * corresponding world coordinates of the two ends of the path and finally * adds a new initialized path object to the list of object of the current * sheet. * * \param [in] w_current The GschemToplevel object. * \param [in] w_x (unused) * \param [in] w_y (unused) */ gboolean o_path_end(GschemToplevel *w_current, int w_x, int w_y) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); TOPLEVEL *toplevel = gschem_page_view_get_toplevel (page_view); PAGE *page = gschem_page_view_get_page (page_view); gboolean close_path, end_path, start_path; PATH *p; PATH_SECTION *section, *prev_section; int x1, y1, x2, y2; g_assert (w_current); g_assert (w_current->toplevel); g_assert (w_current->temp_path != NULL); g_assert (w_current->temp_path->sections != NULL); g_assert (toplevel != NULL); g_assert (page != NULL); o_path_invalidate_rubber (w_current); x1 = w_current->first_wx; y1 = w_current->first_wy; x2 = w_current->second_wx; y2 = w_current->second_wy; p = w_current->temp_path; /* Check whether the section that's being added is the initial * MOVETO. This is detected if the path is currently empty. */ start_path = (p->num_sections == 0); prev_section = start_path ? NULL : &p->sections[p->num_sections - 1]; /* Check whether the section that's being added closes the path. * This is detected if the location of the node is the same as the * location of the starting node, and there is at least one section * in the path in addition to the initial MOVETO section. */ section = &p->sections[0]; close_path = (!start_path && x1 == section->x3 && y1 == section->y3); /* Check whether the section that's being added ends the path. This * is detected if the location of the node is the same as the * location of the previous node. */ end_path = (!start_path && x1 == prev_section->x3 && y1 == prev_section->y3); /* Add predicted next sections */ path_next_sections (w_current); if (end_path || close_path) { /* Add object to page and clean up path drawing state */ OBJECT *obj = o_path_new_take_path (toplevel, OBJ_PATH, GRAPHIC_COLOR, p); w_current->temp_path = NULL; w_current->first_wx = -1; w_current->first_wy = -1; w_current->second_wx = -1; w_current->second_wy = -1; w_current->third_wx = -1; w_current->third_wy = -1; s_page_append (toplevel, page, obj); g_run_hook_object (w_current, "%add-objects-hook", obj); gschem_toplevel_page_content_changed (w_current, page); o_undo_savestate (w_current, page, UNDO_ALL); w_current->rubber_visible = FALSE; return FALSE; } else { /* Leave state as it is and continue path drawing... */ /* Save the control point coordinates for the next section */ w_current->third_wx = x2; w_current->third_wy = y2; return TRUE; } }
/*! \brief finish a net drawing action * \par Function Description * This function finishes the drawing of a net. If we have a visible * magnetic marker, we use that instead of the current cursor * position. * * The rubber nets are removed, the nets and cues are drawn and the * net is added to the TOPLEVEL structure. * * The function returns TRUE if it has drawn a net, FALSE otherwise. */ void o_net_end(GschemToplevel *w_current, int w_x, int w_y) { int primary_zero_length, secondary_zero_length; int found_primary_connection = FALSE; int save_wx, save_wy; GList *prev_conn_objects; OBJECT *new_net = NULL; /* Save a list of added objects to run the %add-objects-hook later */ GList *added_objects = NULL; g_assert( w_current->inside_action != 0 ); GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (page_view != NULL); PAGE *page = gschem_page_view_get_page (page_view); g_return_if_fail (page != NULL); o_net_invalidate_rubber (w_current); if (w_current->magnetic_wx != -1 && w_current->magnetic_wy != -1) o_net_finishmagnetic(w_current); w_current->rubber_visible = 0; /* See if either of the nets are zero length. We'll only add */ /* the non-zero ones */ primary_zero_length = (w_current->first_wx == w_current->second_wx) && (w_current->first_wy == w_current->second_wy); secondary_zero_length = (w_current->second_wx == w_current->third_wx) && (w_current->second_wy == w_current->third_wy); /* If both nets are zero length... */ /* this ends the net drawing behavior */ if ( primary_zero_length && secondary_zero_length ) { o_net_reset(w_current); return; } save_wx = w_current->third_wx; save_wy = w_current->third_wy; if (w_current->third_wx != snap_grid (w_current, w_current->third_wx) || w_current->third_wy != snap_grid (w_current, w_current->third_wy)) s_log_message(_("Warning: Ending net at off grid coordinate\n")); if (!primary_zero_length ) { /* create primary net */ new_net = o_net_new(page->toplevel, OBJ_NET, NET_COLOR, w_current->first_wx, w_current->first_wy, w_current->second_wx, w_current->second_wy); s_page_append (page->toplevel, page, new_net); added_objects = g_list_prepend (added_objects, new_net); /* conn stuff */ /* LEAK CHECK 1 */ prev_conn_objects = s_conn_return_others (NULL, new_net); o_net_add_busrippers (w_current, new_net, prev_conn_objects); g_list_free (prev_conn_objects); #if DEBUG printf("primary:\n"); s_conn_print(new_net->conn_list); #endif /* Go off and search for valid connection on this newly created net */ found_primary_connection = s_conn_net_search(new_net, 1, new_net->conn_list); if (found_primary_connection) { /* if a net connection is found, reset start point of next net */ save_wx = w_current->second_wx; save_wy = w_current->second_wy; } } /* If the second net is not zero length, add it as well */ /* Also, a valid net connection from the primary net was not found */ if (!secondary_zero_length && !found_primary_connection) { /* Add secondary net */ new_net = o_net_new(page->toplevel, OBJ_NET, NET_COLOR, w_current->second_wx, w_current->second_wy, w_current->third_wx, w_current->third_wy); s_page_append (page->toplevel, page, new_net); added_objects = g_list_prepend (added_objects, new_net); /* conn stuff */ /* LEAK CHECK 2 */ prev_conn_objects = s_conn_return_others (NULL, new_net); o_net_add_busrippers (w_current, new_net, prev_conn_objects); g_list_free (prev_conn_objects); #if DEBUG s_conn_print(new_net->conn_list); #endif } /* Call add-objects-hook */ if (added_objects != NULL) { g_run_hook_object_list (w_current, "%add-objects-hook", added_objects); g_list_free (added_objects); } w_current->first_wx = save_wx; w_current->first_wy = save_wy; gschem_toplevel_page_content_changed (w_current, page); o_undo_savestate_old(w_current, UNDO_ALL); /* Continue net drawing */ o_net_start(w_current, w_current->first_wx, w_current->first_wy); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * * <B>type</B> can be one of the following values: * <DL> * <DT>*</DT><DD>UNDO_ACTION * <DT>*</DT><DD>REDO_ACTION * </DL> */ void o_undo_callback (GschemToplevel *w_current, PAGE *page, int type) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); UNDO *u_current; UNDO *u_next; UNDO *save_bottom; UNDO *save_tos; UNDO *save_current; int save_logging; int find_prev_data=FALSE; char *save_filename; g_return_if_fail (w_current != NULL); g_return_if_fail (page != NULL); if (w_current->undo_control == FALSE) { s_log_message(_("Undo/Redo disabled in rc file\n")); return; } if (page->undo_current == NULL) { return; } if (type == UNDO_ACTION) { u_current = page->undo_current->prev; } else { u_current = page->undo_current->next; } u_next = page->undo_current; if (u_current == NULL) { return; } if (u_next->type == UNDO_ALL && u_current->type == UNDO_VIEWPORT_ONLY) { #if DEBUG printf("Type: %d\n", u_current->type); printf("Current is an undo all, next is viewport only!\n"); #endif find_prev_data = TRUE; if (w_current->undo_type == UNDO_DISK) { u_current->filename = o_undo_find_prev_filename(u_current); } else { u_current->object_list = o_undo_find_prev_object_head (u_current); } } /* save filename */ save_filename = g_strdup (page->page_filename); /* save structure so it's not nuked */ save_bottom = page->undo_bottom; save_tos = page->undo_tos; save_current = page->undo_current; page->undo_bottom = NULL; page->undo_tos = NULL; page->undo_current = NULL; o_select_unselect_all (w_current); if (w_current->undo_type == UNDO_DISK && u_current->filename) { /* delete objects of page */ s_page_delete_objects (toplevel, page); /* Free the objects in the place list. */ geda_object_list_delete (toplevel, page->place_list); page->place_list = NULL; gschem_toplevel_page_content_changed (w_current, page); } else if (w_current->undo_type == UNDO_MEMORY && u_current->object_list) { /* delete objects of page */ s_page_delete_objects (toplevel, page); /* Free the objects in the place list. */ geda_object_list_delete (toplevel, page->place_list); page->place_list = NULL; gschem_toplevel_page_content_changed (w_current, page); } /* temporarily disable logging */ save_logging = do_logging; do_logging = FALSE; if (w_current->undo_type == UNDO_DISK && u_current->filename) { f_open(toplevel, page, u_current->filename, NULL); } else if (w_current->undo_type == UNDO_MEMORY && u_current->object_list) { s_page_append_list (toplevel, page, o_glist_copy_all (toplevel, u_current->object_list, NULL)); } page->page_control = u_current->page_control; page->up = u_current->up; gschem_toplevel_page_content_changed (w_current, page); GschemPageView *view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (view != NULL); GschemPageGeometry *geometry = gschem_page_view_get_page_geometry (view); if (u_current->scale != 0) { gschem_page_geometry_set_viewport (geometry, u_current->x, u_current->y, u_current->scale); gschem_page_view_invalidate_all (view); } else { gschem_page_view_zoom_extents (view, u_current->object_list); } /* restore logging */ do_logging = save_logging; /* set filename right */ g_free(page->page_filename); page->page_filename = save_filename; /* final redraw */ x_pagesel_update (w_current); x_multiattrib_update (w_current); i_update_menus(w_current); /* restore saved undo structures */ page->undo_bottom = save_bottom; page->undo_tos = save_tos; page->undo_current = save_current; if (type == UNDO_ACTION) { if (page->undo_current) { page->undo_current = page->undo_current->prev; if (page->undo_current == NULL) { page->undo_current = page->undo_bottom; } } } else { /* type is REDO_ACTION */ if (page->undo_current) { page->undo_current = page->undo_current->next; if (page->undo_current == NULL) { page->undo_current = page->undo_tos; } } } /* don't have to free data here since filename, object_list are */ /* just pointers to the real data (lower in the stack) */ if (find_prev_data) { u_current->filename = NULL; u_current->object_list = NULL; } #if DEBUG printf("\n\n---Undo----\n"); s_undo_print_all(page->undo_bottom); printf("TOS: %s\n", page->undo_tos->filename); printf("CURRENT: %s\n", page->undo_current->filename); printf("----\n"); #endif }
/*! \brief Create dialog to exchange picture objects * \par Function Description * This function opens a file chooser and replaces all pictures of the selections * with the new picture. * * \todo Maybe merge this dialog function with picture_selection_dialog() */ void picture_change_filename_dialog (GschemToplevel *w_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); gchar *filename; gboolean result; GError *error = NULL; w_current->pfswindow = gtk_file_chooser_dialog_new (_("Select a picture file..."), GTK_WINDOW(w_current->main_window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); /* Set the alternative button order (ok, cancel, help) for other systems */ gtk_dialog_set_alternative_button_order(GTK_DIALOG(w_current->pfswindow), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1); if (w_current->pixbuf_filename) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w_current->pfswindow), w_current->pixbuf_filename); if (gtk_dialog_run (GTK_DIALOG (w_current->pfswindow)) == GTK_RESPONSE_ACCEPT) { filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w_current->pfswindow)); gtk_widget_destroy(w_current->pfswindow); w_current->pfswindow=NULL; /* Actually update the pictures */ result = o_picture_exchange (w_current, filename, &error); if (!result) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to replace pictures: %s"), error->message); /* Wait for any user response */ gtk_dialog_run (GTK_DIALOG (dialog)); g_error_free (error); gtk_widget_destroy(dialog); } else { gschem_toplevel_page_content_changed (w_current, toplevel->page_current); } g_free (filename); } i_update_toolbar(w_current); if (w_current->pfswindow) { gtk_widget_destroy(w_current->pfswindow); w_current->pfswindow=NULL; } }
/*! \brief Creates the add image dialog * \par Function Description * This function creates the add image dialog and loads the selected picture. */ void picture_selection_dialog (GschemToplevel *w_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); gchar *filename; GdkPixbuf *pixbuf; GError *error = NULL; w_current->pfswindow = gtk_file_chooser_dialog_new (_("Select a picture file..."), GTK_WINDOW(w_current->main_window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); /* Set the alternative button order (ok, cancel, help) for other systems */ gtk_dialog_set_alternative_button_order(GTK_DIALOG(w_current->pfswindow), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1); if (w_current->pixbuf_filename) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w_current->pfswindow), w_current->pixbuf_filename); if (gtk_dialog_run (GTK_DIALOG (w_current->pfswindow)) == GTK_RESPONSE_ACCEPT) { filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w_current->pfswindow)); gtk_widget_destroy(w_current->pfswindow); w_current->pfswindow=NULL; pixbuf = gdk_pixbuf_new_from_file (filename, &error); if (!pixbuf) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to load picture: %s"), error->message); /* Wait for any user response */ gtk_dialog_run (GTK_DIALOG (dialog)); g_error_free (error); gtk_widget_destroy(dialog); } else { #if DEBUG printf("Picture loaded succesfully.\n"); #endif o_invalidate_rubber(w_current); i_update_middle_button(w_current, i_callback_add_picture, _("Picture")); w_current->inside_action = 0; o_picture_set_pixbuf(w_current, pixbuf, filename); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); i_set_state(w_current, DRAWPICTURE); } g_free (filename); } i_update_toolbar(w_current); if (w_current->pfswindow) { gtk_widget_destroy(w_current->pfswindow); w_current->pfswindow=NULL; } }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void o_move_end(GschemToplevel *w_current) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (page_view != NULL); PAGE *page = gschem_page_view_get_page (page_view); g_return_if_fail (page != NULL); GList *s_current = NULL; OBJECT *object; int diff_x, diff_y; GList *s_iter; GList *rubbernet_objects = NULL; gboolean net_rubber_band_mode; g_return_if_fail (w_current != NULL); g_return_if_fail (page != NULL); g_assert (w_current->inside_action != 0); object = o_select_return_first_object(w_current); if (!object) { /* actually this is an error condition hack */ i_action_stop (w_current); i_set_state(w_current, SELECT); return; } diff_x = w_current->second_wx - w_current->first_wx; diff_y = w_current->second_wy - w_current->first_wy; o_move_invalidate_rubber (w_current, FALSE); w_current->rubber_visible = 0; net_rubber_band_mode = gschem_options_get_net_rubber_band_mode (w_current->options); if (net_rubber_band_mode) { o_move_end_rubberband (w_current, diff_x, diff_y, &rubbernet_objects); } /* Unset the dont_redraw flag on rubberbanded objects. * We set this above, in o_move_start(). */ for (s_iter = w_current->stretch_list; s_iter != NULL; s_iter = g_list_next (s_iter)) { STRETCH *stretch = s_iter->data; stretch->object->dont_redraw = FALSE; } s_current = geda_list_get_glist( page->selection_list ); while (s_current != NULL) { object = (OBJECT *) s_current->data; if (object == NULL) { fprintf(stderr, _("ERROR: NULL object in o_move_end!\n")); exit(-1); } switch (object->type) { case (OBJ_COMPLEX): case (OBJ_PLACEHOLDER): /* TODO: Fix so we can just pass the complex to o_move_end_lowlevel, * IE.. by falling through the bottom of this case statement. */ /* this next section of code is from */ /* o_complex_world_translate_world */ object->complex->x = object->complex->x + diff_x; object->complex->y = object->complex->y + diff_y; o_move_end_lowlevel_glist (w_current, object->complex->prim_objs, diff_x, diff_y); object->w_bounds_valid_for = NULL; break; default: o_move_end_lowlevel (w_current, object, diff_x, diff_y); break; } s_current = g_list_next(s_current); } /* Draw the objects that were moved */ o_invalidate_glist (w_current, geda_list_get_glist (page->selection_list)); /* Draw the connected nets/buses that were also changed */ o_invalidate_glist (w_current, rubbernet_objects); /* Call move-objects-hook for moved objects and changed connected * nets/buses */ GList *moved_list = g_list_concat (page->place_list, rubbernet_objects); page->place_list = NULL; rubbernet_objects = NULL; g_run_hook_object_list (w_current, "%move-objects-hook", moved_list); g_list_free (moved_list); gschem_toplevel_page_content_changed (w_current, page); o_undo_savestate_old(w_current, UNDO_ALL); s_stretch_destroy_all (w_current->stretch_list); w_current->stretch_list = NULL; i_set_state(w_current, SELECT); i_action_stop (w_current); }
/* text item */ OBJECT *o_attrib_add_attrib(GschemToplevel *w_current, const char *text_string, int visibility, int show_name_value, OBJECT *object) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *new_obj; int world_x = - 1, world_y = -1; int align = LOWER_LEFT; int angle = 0; int color; int left, right, top, bottom; OBJECT *o_current; color = DETACHED_ATTRIBUTE_COLOR; o_current = object; /* creating a toplevel or unattached attribute */ if (o_current) { /* get coordinates of where to place the text object */ switch(o_current->type) { case(OBJ_COMPLEX): case(OBJ_PLACEHOLDER): world_x = o_current->complex->x; world_y = o_current->complex->y; align = LOWER_LEFT; angle = 0; color = ATTRIBUTE_COLOR; break; case(OBJ_ARC): world_x = o_current->arc->x; world_y = o_current->arc->y; align = LOWER_LEFT; angle = 0; color = ATTRIBUTE_COLOR; break; case(OBJ_CIRCLE): world_x = o_current->circle->center_x; world_y = o_current->circle->center_y; align = LOWER_LEFT; angle = 0; color = ATTRIBUTE_COLOR; break; case(OBJ_BOX): world_x = o_current->box->upper_x; world_y = o_current->box->upper_y; align = LOWER_LEFT; angle = 0; color = ATTRIBUTE_COLOR; break; case(OBJ_LINE): case(OBJ_NET): case(OBJ_PIN): case(OBJ_BUS): { int dx = o_current->line->x[1] - o_current->line->x[0]; int dy = o_current->line->y[1] - o_current->line->y[0]; if (dy == 0) { if (dx > 0) { world_x = o_current->line->x[0] + SPACING_FROM_END; world_y = o_current->line->y[0] + SPACING_PERPENDICULAR; align = LOWER_LEFT; angle = 0; } else { world_x = o_current->line->x[0] - SPACING_FROM_END; world_y = o_current->line->y[0] + SPACING_PERPENDICULAR; align = LOWER_RIGHT; angle = 0; } } else if (dx == 0) { if (dy > 0) { world_x = o_current->line->x[0] - SPACING_PERPENDICULAR; world_y = o_current->line->y[0] + SPACING_FROM_END; align = LOWER_LEFT; angle = 90; } else { world_x = o_current->line->x[0] - SPACING_PERPENDICULAR; world_y = o_current->line->y[0] - SPACING_FROM_END; align = LOWER_RIGHT; angle = 90; } } else { world_x = o_current->line->x[0]; world_y = o_current->line->y[0]; align = LOWER_LEFT; angle = 0; } color = ATTRIBUTE_COLOR; } break; case(OBJ_TEXT): world_x = o_current->text->x; world_y = o_current->text->y; color = DETACHED_ATTRIBUTE_COLOR; align = LOWER_LEFT; angle = 0; o_current = NULL; break; } } else { world_get_object_glist_bounds (toplevel, s_page_objects (toplevel->page_current), &left, &top, &right, &bottom); /* this really is the lower left hand corner */ world_x = left; world_y = top; /* printf("%d %d\n", world_x, world_y); */ align = LOWER_LEFT; angle = 0; color = DETACHED_ATTRIBUTE_COLOR; } /* first create text item */ new_obj = o_text_new(toplevel, color, world_x, world_y, align, angle, text_string, w_current->text_size, /* current text size */ visibility, show_name_value); s_page_append (toplevel, toplevel->page_current, new_obj); /* now attach the attribute to the object (if o_current is not NULL) */ /* remember that o_current contains the object to get the attribute */ if (o_current) { o_attrib_attach (toplevel, new_obj, o_current, FALSE); } o_selection_add (toplevel, toplevel->page_current->selection_list, new_obj); /* handle slot= attribute, it's a special case */ if (o_current != NULL && g_ascii_strncasecmp (text_string, "slot=", 5) == 0) { o_slot_end (w_current, o_current, text_string); } /* Call add-objects-hook. */ g_run_hook_object (w_current, "%add-objects-hook", new_obj); g_run_hook_object (w_current, "%select-objects-hook", new_obj); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); return new_obj; }
/*! \brief Delete objects from the selection. * \par Function Description * This function deletes the objects selected on the current page of * toplevel \a w_current. * * \param [in] w_current The GschemToplevel object. */ void o_delete_selected (GschemToplevel *w_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); SELECTION *selection = toplevel->page_current->selection_list; GList *to_remove; GList *iter; OBJECT *obj; unsigned int locked_num = 0; g_return_if_fail (o_select_selected (w_current)); to_remove = g_list_copy (geda_list_get_glist (selection)); for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; if (obj->selectable == FALSE) locked_num++; } if (locked_num > 0) { GList *non_locked = NULL; gint resp; GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, ngettext ("Delete locked object?", "Delete %u locked objects?", locked_num), locked_num); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_YES, GTK_RESPONSE_YES, GTK_STOCK_NO, GTK_RESPONSE_NO, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO); resp = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); switch (resp) { case GTK_RESPONSE_YES: /* Remove all */ break; case GTK_RESPONSE_NO: /* Remove non locked */ for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; if (obj->selectable == TRUE) non_locked = g_list_append (non_locked, iter->data); } g_list_free (to_remove); to_remove = non_locked; break; default: /* Cancel */ g_list_free (to_remove); return; } } for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; o_selection_remove (toplevel, selection, obj); s_page_remove (toplevel, toplevel->page_current, obj); } g_run_hook_object_list (w_current, "%remove-objects-hook", to_remove); for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; s_delete_object (toplevel, obj); } g_list_free (to_remove); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); w_current->inside_action = 0; o_undo_savestate_old (w_current, UNDO_ALL); i_update_menus (w_current); }
/*! \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 GschemToplevel object. * \param [in,out] o_current The OBJECT to be updated. * * \return the new OBJECT that replaces \a o_current. */ OBJECT * o_update_component (GschemToplevel *w_current, OBJECT *o_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); 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); /* Force symbol data to be reloaded from source */ clib = s_clib_get_symbol_by_name (o_current->complex_basename); s_clib_symbol_invalidate_data (clib); 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 */ gschem_toplevel_page_content_changed (w_current, toplevel->page_current); o_undo_savestate_old (w_current, UNDO_ALL); return o_new; }