/** * \brief snaps to the grid, updates the model if snapping was necessary * * \attention this will cause a loop cycle of "changed" signals * until no more snapping is necessary * * @param item_data * @param grid */ void item_data_snap (ItemData *item_data, Grid *grid) { gboolean handler_connected; g_return_if_fail (item_data); g_return_if_fail (IS_ITEM_DATA (item_data)); g_return_if_fail (grid); g_return_if_fail (IS_GRID (grid)); if (snap_to_grid (grid, &(item_data->priv->translate.x0), &(item_data->priv->translate.y0))) { #if 1 // TODO FIXME XXX rename this to "snapped" instead of moved handler_connected = g_signal_handler_is_connected (G_OBJECT (item_data), item_data->moved_handler_id); if (handler_connected) { g_signal_emit_by_name (G_OBJECT (item_data), "moved"); // FIXME replace this by a "snapped" signal } #endif handler_connected = g_signal_handler_is_connected (G_OBJECT (item_data), item_data->changed_handler_id); if (handler_connected) { g_signal_emit_by_name (G_OBJECT (item_data), "changed"); } } }
/* This function defines the drawing sheet on which schematic will be drawn * @param grid the grid (not a GtkGrid but a Grid struct) */ GtkWidget * sheet_new (Grid *grid) { g_return_val_if_fail (grid, NULL); g_return_val_if_fail (IS_GRID (grid), NULL); GooCanvas *sheet_canvas; GooCanvasGroup *sheet_group; GooCanvasPoints *points; Sheet *sheet; GtkWidget *sheet_widget; GooCanvasItem *root; gdouble height=-1., width=-1.; g_object_get (grid, "height", &height, "width", &width, NULL); g_printf ("%s xxx %lf x %lf\n", __FUNCTION__, height, width); // Creation of the Canvas sheet = SHEET (g_object_new (TYPE_SHEET, NULL)); sheet_canvas = GOO_CANVAS (sheet); g_object_set (G_OBJECT (sheet_canvas), "bounds-from-origin", FALSE, "bounds-padding", 4.0, "background-color-rgb", 0xFFFFFF, NULL); root = goo_canvas_get_root_item (sheet_canvas); sheet_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, NULL)); sheet_widget = GTK_WIDGET (sheet); goo_canvas_set_bounds (GOO_CANVAS (sheet_canvas), 0., 0., width + 20., height + 20.); // Define vicinity around GooCanvasItem //sheet_canvas->close_enough = 6.0; sheet->priv->width = width; sheet->priv->height = height; // Create the dot grid. sheet->grid = grid; sheet->grid_item = grid_item_new (GOO_CANVAS_ITEM (sheet_group), sheet->grid); // Everything outside the sheet should be gray. // top // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, width + 20.0, 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, height, width + 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); // right // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), width, 0.0, width + 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); // Draw a thin black border around the sheet. points = goo_canvas_points_new (5); points->coords[0] = 20.0; points->coords[1] = 20.0; points->coords[2] = width; points->coords[3] = 20.0; points->coords[4] = width; points->coords[5] = height; points->coords[6] = 20.0; points->coords[7] = height; points->coords[8] = 20.0; points->coords[9] = 20.0; goo_canvas_polyline_new (GOO_CANVAS_ITEM (sheet_group), FALSE, 0, "line-width", 1.0, "points", points, NULL); goo_canvas_points_unref (points); // Finally, create the object group that holds all objects. sheet->object_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("root group %p", sheet->object_group); sheet->priv->selected_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("selected group %p", sheet->priv->selected_group); sheet->priv->floating_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("floating group %p", sheet->priv->floating_group); // Hash table that maps coordinates to a specific dot. sheet->priv->node_dots = g_hash_table_new_full (dot_hash, dot_equal, g_free, NULL); //this requires object_group to be setup properly sheet->priv->rubberband_info = rubberband_info_new (sheet); sheet->priv->create_wire_info = create_wire_info_new (sheet); return sheet_widget; }