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)); }
PartItem * part_item_new (Sheet *sheet, Part *part) { Library *library; LibraryPart *library_part; PartPriv *priv; PartItem *item; priv = part->priv; library = priv->library; library_part = library_get_part (library, priv->name); // Create the PartItem canvas item item = part_item_canvas_new (sheet, part); create_canvas_items (GOO_CANVAS_GROUP (item), library_part); create_canvas_labels (item, part); create_canvas_label_nodes (item, part); goo_canvas_item_ensure_updated (GOO_CANVAS_ITEM (item)); return item; }
void part_browser_dnd (GtkSelectionData *selection_data, int x, int y) { LibraryPart *library_part; Coords pos; DndData *data; Sheet *sheet; Part *part; data = (DndData *) (gtk_selection_data_get_data (selection_data)); g_return_if_fail (data != NULL); pos.x = x; pos.y = y; sheet = schematic_view_get_sheet (data->schematic_view); snap_to_grid (sheet->grid, &pos.x, &pos.y); library_part = library_get_part (data->br->library, data->part_name); part = part_new_from_library_part (library_part); if (!part) { oregano_error (_("Unable to load required part")); return; } item_data_set_pos (ITEM_DATA (part), &pos); sheet_connect_part_item_to_floating_group (sheet, (gpointer) data->schematic_view); sheet_select_all (sheet, FALSE); sheet_clear_ghosts (schematic_view_get_sheet (data->schematic_view)); sheet_add_ghost_item (sheet, ITEM_DATA (part)); }
static void update_preview (Browser *br) { LibraryPart *library_part; gdouble new_x, new_y, x1, y1, x2, y2; gdouble text_width; gdouble width, height; GooCanvasBounds bounds; gdouble scale; cairo_matrix_t transf, affine; gchar *part_name; char *description; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; // 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_IS_TREE_SELECTION (selection)) return; 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); // If there is already a preview part-item, destroy its group and create a // new one. if (br->preview != NULL) { goo_canvas_item_remove (GOO_CANVAS_ITEM (br->preview)); } br->preview = GOO_CANVAS_GROUP (goo_canvas_group_new ( goo_canvas_get_root_item (GOO_CANVAS (br->canvas)), NULL)); goo_canvas_set_bounds (GOO_CANVAS (br->canvas), 0.0, 0.0, 250.0, 110.0); g_object_get (br->preview, "width", &width, "height", &height, NULL); if (!library_part) return; part_item_create_canvas_items_for_preview (br->preview, library_part); // Unconstraint the canvas width & height to adjust for the part description g_object_set (br->preview, "width", -1.0, "height", -1.0, NULL); // Get the coordonates */ goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (br->preview), &bounds); x1 = bounds.x1; x2 = bounds.x2; y1 = bounds.y1; y2 = bounds.y2; // Translate in such a way that the canvas centre remains in (0, 0) cairo_matrix_init_translate (&transf, -(x2 + x1) / 2.0f + PREVIEW_WIDTH / 2, -(y2 + y1) / 2.0f + PREVIEW_HEIGHT / 2); // Compute the scale of the widget if ((x2 - x1 != 0) || (y2 - y1 != 0)) { if ((x2 - x1) < (y2 - y1)) scale = 0.60f * PREVIEW_HEIGHT / (y2 - y1); else scale = 0.60f * PREVIEW_WIDTH / (x2 - x1); } else scale = 5; cairo_matrix_init_scale (&affine, scale, scale); cairo_matrix_multiply (&transf, &transf, &affine); // Apply the transformation goo_canvas_item_set_transform (GOO_CANVAS_ITEM (br->preview), &transf); // Compute the motion to centre the Preview widget new_x = 100 + (PREVIEW_WIDTH - x1 - x2) / 2; new_y = (PREVIEW_HEIGHT - y1 - y2) / 2 - 10; // Apply the transformation if (scale > 5.0) scale = 3.0; goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (br->preview), new_x, new_y, scale, 0.0); description = g_strdup (library_part->description); wrap_string (description, 20); g_object_set (br->description, "text", description, NULL); g_free (description); g_object_get (G_OBJECT (br->description), "width", &text_width, NULL); goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (br->description), 50.0, -20.0, 1.0, 0.0); g_free (part_name); }