void test_nodestore () { gint i; NodeStore *store; Part *part; Wire *wire; Node *node; Coords p_pos = {111.,22.}; Coords n_pos = {111.,33.}; Coords w_pos = {111.,7.}; Coords w_len = {0.,88.}; store = node_store_new (); part = part_new (); wire = wire_new (); // add one Pin with a offset that is on the wire when rotation N*Pi times Pin *pin = g_new (Pin, 1); pin->offset.x = n_pos.x - p_pos.x; pin->offset.y = n_pos.y - p_pos.y; GSList *list = NULL; list = g_slist_prepend (list, pin); part_set_pins (part, list); g_slist_free (list); item_data_set_pos (ITEM_DATA (part), &p_pos); item_data_set_pos (ITEM_DATA (wire), &w_pos); wire_set_length (wire, &w_len); node_store_add_part (store, part); node_store_add_wire (store, wire); { for (i=0; i<11; i++) item_data_rotate (ITEM_DATA (part), 90, NULL); item_data_set_pos (ITEM_DATA (part), &w_len); for (i=0; i<4; i++) item_data_rotate (ITEM_DATA (part), 90, NULL); item_data_set_pos (ITEM_DATA (part), &n_pos); for (i=0; i<7; i++) item_data_rotate (ITEM_DATA (part), -90, NULL); item_data_set_pos (ITEM_DATA (part), &p_pos); } g_assert (node_store_is_wire_at_pos (store, n_pos)); g_assert (node_store_is_pin_at_pos (store, n_pos)); node = node_store_get_node (store, n_pos); g_assert (!node_is_empty (node)); g_assert (node_needs_dot (node)); node_store_remove_part (store, part); node_store_remove_wire (store, wire); g_object_unref (store); }
static gboolean create_textbox_event (Sheet *sheet, GdkEvent *event) { switch (event->type) { case GDK_3BUTTON_PRESS: case GDK_2BUTTON_PRESS: return TRUE; case GDK_BUTTON_PRESS: if (event->button.button == 4 || event->button.button == 5) return FALSE; if (event->button.button == 1) { if (sheet->state == SHEET_STATE_TEXTBOX_WAIT) sheet->state = SHEET_STATE_TEXTBOX_START; return TRUE; } else return FALSE; case GDK_BUTTON_RELEASE: if (event->button.button == 4 || event->button.button == 5) return FALSE; if (sheet->state == SHEET_STATE_TEXTBOX_START) { Textbox *textbox; Coords pos; sheet->state = SHEET_STATE_NONE; sheet_get_pointer (sheet, &pos.x, &pos.y); textbox = textbox_new (NULL); textbox_set_text (textbox, _ ("Label")); item_data_set_pos (ITEM_DATA (textbox), &pos); schematic_add_item (schematic_view_get_schematic_from_sheet (sheet), ITEM_DATA (textbox)); schematic_view_reset_tool (schematic_view_get_schematicview_from_sheet (sheet)); g_signal_handlers_disconnect_by_func (G_OBJECT (sheet), G_CALLBACK (create_textbox_event), sheet); } return TRUE; default: return FALSE; } return TRUE; }
static void place_cmd (GtkWidget *widget, Browser *br) { LibraryPart *library_part; char *part_name; Coords pos; Sheet *sheet; Part *part; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; schematic_view_reset_tool (br->schematic_view); sheet = schematic_view_get_sheet (br->schematic_view); // Get the current selected row selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (br->list)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (br->list)); if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { return; } gtk_tree_model_get (model, &iter, 0, &part_name, -1); library_part = library_get_part (br->library, part_name); part = part_new_from_library_part (library_part); if (!part) { oregano_error (_("Unable to load required part")); return; } pos.x = pos.y = 0; item_data_set_pos (ITEM_DATA (part), &pos); sheet_connect_part_item_to_floating_group (sheet, (gpointer) br->schematic_view); sheet_select_all (sheet, FALSE); sheet_clear_ghosts (sheet); sheet_add_ghost_item (sheet, ITEM_DATA (part)); }
static void flip_items (Sheet *sheet, GList *items, IDFlip direction) { GList *iter, *item_data_list; Coords center, b1, b2; Coords after; item_data_list = NULL; for (iter = items; iter; iter = iter->next) { item_data_list = g_list_prepend (item_data_list, sheet_item_get_data (iter->data)); } item_data_list_get_absolute_bbox (item_data_list, &b1, &b2); // FIXME center is currently not used by item_data_flip (part.c implentation) center.x = (b2.x + b1.x) / 2; center.y = (b2.y + b1.y) / 2; // FIXME - registering an item after flipping it still creates an offset as the position is still 0 for (iter = item_data_list; iter; iter = iter->next) { ItemData *item_data = iter->data; if (sheet->state == SHEET_STATE_NONE) item_data_unregister (item_data); item_data_flip (item_data, direction, ¢er); // Make sure we snap to grid. item_data_get_pos (item_data, &after); snap_to_grid (sheet->grid, &after.x, &after.y); item_data_set_pos (item_data, &after); if (sheet->state == SHEET_STATE_NONE) item_data_register (item_data); } g_list_free (item_data_list); }