static void item_data_copy (ItemData *dest, ItemData *src) { g_return_if_fail (dest != NULL); g_return_if_fail (IS_ITEM_DATA (dest)); g_return_if_fail (src != NULL); g_return_if_fail (IS_ITEM_DATA (src)); dest->priv->translate = src->priv->translate; dest->priv->rotate = src->priv->rotate; dest->priv->store = NULL; }
// Create a SheetItem from an ItemData object. This is a bit ugly. // It could be beautified by having a method that creates the item. // E.g. sheet_item->new_from_data (data); SheetItem * sheet_item_factory_create_sheet_item (Sheet *sheet, ItemData *data) { SheetItem *item; g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (IS_ITEM_DATA (data), NULL); g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); item = NULL; // Pick the right model. if (IS_PART (data)) { NG_DEBUG ("sheet_item_factory_create_sheet_item part\n\n"); item = SHEET_ITEM (part_item_new (sheet, PART (data))); } else if (IS_WIRE (data)) { NG_DEBUG ("sheet_item_factory_create_sheet_item wire\n\n"); item = SHEET_ITEM (wire_item_new (sheet, WIRE (data))); } else if (IS_TEXTBOX (data)) { NG_DEBUG ("sheet_item_factory_create_sheet_item text\n\n"); item = SHEET_ITEM (textbox_item_new (sheet, TEXTBOX (data))); } else g_warning ("Unknown Item type."); return item; }
// NodeStore * gpointer item_data_get_store (ItemData *item_data) { g_return_val_if_fail (item_data != NULL, NULL); g_return_val_if_fail (IS_ITEM_DATA (item_data), NULL); return item_data->priv->store; }
/** * \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"); } } }
static void wire_changed_callback (Wire *wire, WireItem *item) { Coords start_pos, length; GooCanvasPoints *points; g_return_if_fail (wire != NULL); g_return_if_fail (IS_ITEM_DATA (wire)); g_return_if_fail (item != NULL); g_return_if_fail (IS_WIRE_ITEM (item)); wire_get_pos_and_length (wire, &start_pos, &length); Sheet *sheet = SHEET (goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (item))); if (G_UNLIKELY(!sheet)) { g_warning ("Failed to determine the Sheet the item is glued to. This should never happen. Ever!"); } else { item_data_snap (ITEM_DATA (wire), sheet->grid); } // Move the canvas item and invalidate the bbox cache. goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (item), start_pos.x, start_pos.y, 1.0, 0.0); item->priv->cache_valid = FALSE; points = goo_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; // this does handle cleanup of previous points internally g_object_set (item->priv->line, "points", points, NULL); goo_canvas_points_unref (points); g_object_set (item->priv->resize1, "x", -RESIZER_SIZE, "y", -RESIZER_SIZE, "width", 2 * RESIZER_SIZE, "height", 2 * RESIZER_SIZE, NULL); g_object_set (item->priv->resize2, "x", length.x-RESIZER_SIZE, "y", length.y-RESIZER_SIZE, "width", 2 * RESIZER_SIZE, "height", 2 * RESIZER_SIZE, NULL); goo_canvas_item_request_update (GOO_CANVAS_ITEM (item->priv->line)); }
/** * returns the top left corner of the item */ void item_data_get_pos (ItemData *item_data, Coords *pos) { g_return_if_fail (item_data != NULL); g_return_if_fail (IS_ITEM_DATA (item_data)); g_return_if_fail (pos != NULL); ItemDataPriv *priv; priv = item_data->priv; pos->x = priv->translate.x0; pos->y = priv->translate.y0; }
void item_data_unregister (ItemData *data) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->unreg) { id_class->unreg (data); } }
void item_data_flip (ItemData *data, IDFlip direction, Coords *center) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->flip) { id_class->flip (data, direction, center); } }
void item_data_rotate (ItemData *data, int angle, Coords *center) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->rotate) { id_class->rotate (data, angle, center); } }
void item_data_set_property (ItemData *data, char *property, char *value) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->set_property) { id_class->set_property (data, property, value); return; } }
gboolean item_data_has_properties (ItemData *data) { ItemDataClass *id_class; g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (IS_ITEM_DATA (data), FALSE); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->has_properties) { return id_class->has_properties (data); } return FALSE; }
void item_data_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); g_return_if_fail (cr != NULL); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->print) { id_class->print (data, cr, ctx); } }
void item_data_move (ItemData *item_data, const Coords *delta) { ItemDataPriv *priv; g_return_if_fail (item_data != NULL); g_return_if_fail (IS_ITEM_DATA (item_data)); if (delta == NULL) return; priv = item_data->priv; cairo_matrix_translate (&(priv->translate), delta->x, delta->y); }
/** * \brief changed, forcefully emits a changed signal to recalculate the morph *matrix * * @param data determines which item to refresh * * \note this function does _not_ request a redraw */ void item_data_changed (ItemData *data) { ItemDataClass *id_class; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->changed == NULL) return; return id_class->changed (data); }
gboolean item_data_register (ItemData *data) { ItemDataClass *id_class; g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (IS_ITEM_DATA (data), FALSE); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->reg) { return id_class->reg (data); } return FALSE; }
ItemData *item_data_clone (ItemData *src) { ItemDataClass *id_class; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (IS_ITEM_DATA (src), NULL); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (src)); if (id_class->clone == NULL) return NULL; return id_class->clone (src); }
char *item_data_get_refdes_prefix (ItemData *data) { ItemDataClass *id_class; g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (IS_ITEM_DATA (data), NULL); id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (data)); if (id_class->get_refdes_prefix) { return id_class->get_refdes_prefix (data); } return NULL; }
static void textbox_text_changed_callback (ItemData *data, gchar *new_text, SheetItem *item) { TextboxItem *textbox_item; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); g_return_if_fail (item != NULL); g_return_if_fail (IS_TEXTBOX_ITEM (item)); textbox_item = TEXTBOX_ITEM (item); g_object_set (textbox_item->priv->text_canvas_item, "text", new_text, NULL); goo_canvas_item_ensure_updated (GOO_CANVAS_ITEM (textbox_item)); }
void item_data_get_relative_bbox (ItemData *data, Coords *p1, Coords *p2) { g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); if (p1) { p1->x = data->priv->bounds.x1; p1->y = data->priv->bounds.y1; } if (p2) { p2->x = data->priv->bounds.x2; p2->y = data->priv->bounds.y2; } }
void item_data_set_relative_bbox (ItemData *data, Coords *p1, Coords *p2) { g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); if (p1) { data->priv->bounds.x1 = p1->x; data->priv->bounds.y1 = p1->y; } if (p2) { data->priv->bounds.x2 = p2->x; data->priv->bounds.y2 = p2->y; } }
// This is called when the textbox data was moved. Update the view accordingly. static void textbox_moved_callback (ItemData *data, Coords *pos, SheetItem *item) { TextboxItem *textbox_item; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); g_return_if_fail (item != NULL); g_return_if_fail (IS_TEXTBOX_ITEM (item)); if (pos == NULL) return; textbox_item = TEXTBOX_ITEM (item); // Move the canvas item and invalidate the bbox cache. goo_canvas_item_translate (GOO_CANVAS_ITEM (item), pos->x, pos->y); textbox_item->priv->cache_valid = FALSE; }
void item_data_get_absolute_bbox (ItemData *data, Coords *p1, Coords *p2) { g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); ItemDataPriv *priv; item_data_get_relative_bbox (data, p1, p2); priv = data->priv; if (p1) { p1->x += priv->translate.x0; p1->y += priv->translate.y0; } if (p2) { p2->x += priv->translate.x0; p2->y += priv->translate.y0; } }
/** * This is called when the wire data was moved. Update the view accordingly. */ static void wire_moved_callback (ItemData *data, SheetPos *pos, SheetItem *item) { WireItem *wire_item; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); g_return_if_fail (item != NULL); g_return_if_fail (IS_WIRE_ITEM (item)); if (pos == NULL) return; wire_item = WIRE_ITEM (item); /* * Move the canvas item and invalidate the bbox cache. */ gnome_canvas_item_move (GNOME_CANVAS_ITEM (item), pos->x, pos->y); wire_item->priv->cache_valid = FALSE; }
/** * remove a single item from the sheet */ void sheet_remove_item_in_sheet (SheetItem *item, Sheet *sheet) { g_return_if_fail (sheet != NULL); g_return_if_fail (IS_SHEET (sheet)); g_return_if_fail (item != NULL); g_return_if_fail (IS_SHEET_ITEM (item)); sheet->priv->items = g_list_remove (sheet->priv->items, item); // Remove the object from the selected-list before destroying. sheet_remove_selected_object (sheet, item); sheet_remove_floating_object (sheet, item); ItemData *data = sheet_item_get_data (item); g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); // properly unregister the itemdata from the sheet item_data_unregister (data); // Destroy the item-data (model) associated to the sheet-item g_object_unref (data); }
// This is called when the wire data was moved. Update the view accordingly. static void wire_moved_callback (ItemData *data, SheetPos *pos, SheetItem *item) { WireItem *wire_item; g_return_if_fail (data != NULL); g_return_if_fail (IS_ITEM_DATA (data)); g_return_if_fail (item != NULL); g_return_if_fail (IS_WIRE_ITEM (item)); if (pos == NULL) return; wire_item = WIRE_ITEM (item); // Move the canvas item and invalidate the bbox cache. goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (item), pos->x, pos->y, 1.0, 0.0); wire_item->priv->cache_valid = FALSE; }
void item_data_set_pos (ItemData *item_data, Coords *pos) { ItemDataPriv *priv; gboolean handler_connected; g_return_if_fail (pos); g_return_if_fail (item_data); g_return_if_fail (IS_ITEM_DATA (item_data)); priv = item_data->priv; cairo_matrix_init_translate (&(priv->translate), pos->x, pos->y); 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", pos); } 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"); } }
/** * @param data * @returns [transfer-none] pointer to cairo matrix which only includes the * rotation */ cairo_matrix_t *item_data_get_rotate (ItemData *data) { g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (IS_ITEM_DATA (data), NULL); return &(data->priv->rotate); }