Exemple #1
0
// Retrieves the bounding box. We use a caching scheme for this
// since it's too expensive to calculate it every time we need it.
inline static void get_boundingbox (WireItem *item, Coords *p1, Coords *p2)
{
	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (item));

	WireItemPriv *priv;
	priv = item->priv;

	if (!priv->cache_valid) {
		Coords start_pos, end_pos;
		GooCanvasBounds bounds; //, canvas_bounds;

		goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (item), &bounds);
		priv->bbox_start.x = bounds.x1;
		priv->bbox_start.y = bounds.y1;
		priv->bbox_end.x = bounds.x2;
		priv->bbox_end.y = bounds.y2;

		priv->cache_valid = TRUE;
	}

	if (p1)
		*p1 = priv->bbox_start;
	if (p2)
		*p2 = priv->bbox_end;
}
Exemple #2
0
static void wire_rotated_callback (ItemData *data, int angle, SheetItem *sheet_item)
{
	WireItem *wire_item;
	GooCanvasPoints *points;
	Coords start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	wire_item = WIRE_ITEM (sheet_item);

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = goo_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	g_object_set (wire_item->priv->line, "points", points, NULL);
	goo_canvas_points_unref (points);

	g_object_set (wire_item, "x", start_pos.x, "y", start_pos.y, NULL);

	g_object_set (wire_item->priv->resize2, "x", length.x - RESIZER_SIZE, "y",
	              length.y - RESIZER_SIZE, NULL);

	// Invalidate the bounding box cache.
	wire_item->priv->cache_valid = FALSE;
}
Exemple #3
0
static void wire_flipped_callback (ItemData *data, IDFlip direction, SheetItem *sheet_item)
{
	GooCanvasPoints *points;
	WireItem *item;
	WireItemPriv *priv;
	Coords start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	item = WIRE_ITEM (sheet_item);
	priv = item->priv;

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = goo_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	g_object_set (item->priv->line, "points", points, NULL);
	goo_canvas_points_unref (points);

	g_object_set (item, "x", start_pos.x, "y", start_pos.y, NULL);

	// Invalidate the bounding box cache.
	priv->cache_valid = FALSE;
}
Exemple #4
0
static void
wire_item_destroy (GtkObject *object)
{
	WireItem *wire;
	WireItemPriv *priv;

	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_WIRE_ITEM (object));

	wire = WIRE_ITEM (object);
	priv = wire->priv;

	if (priv) {
		if (priv->line) {
			/* TODO Check if destroy or unref have to be used for
			 * GnomeCanvasItem */
			gtk_object_destroy (GTK_OBJECT (priv->line));
			priv->line = NULL;
		}
		g_free (priv);
		wire->priv = NULL;
	}

	if (GTK_OBJECT_CLASS(wire_item_parent_class)->destroy){
		GTK_OBJECT_CLASS(wire_item_parent_class)->destroy(object);
	}
}
Exemple #5
0
// This function returns the position of the canvas item. It has
// nothing to do with where the wire is stored in the sheet node store.
void wire_item_get_start_pos (WireItem *item, Coords *pos)
{
	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (item));
	g_return_if_fail (pos != NULL);

	g_object_get (G_OBJECT (item), "x", &pos->x, "y", &pos->y, NULL);
}
Exemple #6
0
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));
}
Exemple #7
0
static void wire_item_set_property (GObject *object, guint property_id, const GValue *value,
                                    GParamSpec *pspec)
{
	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_WIRE_ITEM (object));

	switch (property_id) {
	default:
		g_warning ("PartItem: Invalid argument.\n");
	}
}
Exemple #8
0
static void wire_item_get_property (GObject *object, guint property_id, GValue *value,
                                    GParamSpec *pspec)
{
	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_WIRE_ITEM (object));

	switch (property_id) {
	default:
		pspec->value_type = G_TYPE_INVALID;
		break;
	}
}
Exemple #9
0
static void
wire_rotated_callback (ItemData *data, int angle, SheetItem *sheet_item)
{
	WireItem *wire_item;
	GnomeCanvasPoints *points;
	SheetPos start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	wire_item = WIRE_ITEM (sheet_item);

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (wire_item->priv->line),
		"points", points,
		NULL);
	gnome_canvas_points_unref (points);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (wire_item),
		"x", start_pos.x,
		"y", start_pos.y,
		NULL);

	gnome_canvas_item_set (
		GNOME_CANVAS_ITEM (wire_item-> priv->resize2),
		"x1", length.x-RESIZER_SIZE,
		"y1", length.y-RESIZER_SIZE,
		"x2", length.x+RESIZER_SIZE,
		"y2", length.y+RESIZER_SIZE,
		NULL
	);

	/*
	 * Invalidate the bounding box cache.
	 */
	wire_item->priv->cache_valid = FALSE;
}
Exemple #10
0
// This function returns the length of the canvas item.
void wire_item_get_length (WireItem *item, Coords *pos)
{
	WireItemPriv *priv;
	GooCanvasPoints *points;

	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (item));
	g_return_if_fail (pos != NULL);

	priv = item->priv;

	g_object_get (G_OBJECT (priv->line), "points", &points, NULL);

	// This is not strictly neccessary, since the first point is always
	// (0,0) but it's more correct and good to have if this changes in the
	// future.
	pos->x = points->coords[2] - points->coords[0];
	pos->y = points->coords[3] - points->coords[1];
	goo_canvas_points_unref (points);
}
Exemple #11
0
/**
 * 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;
}
Exemple #12
0
static void
wire_flipped_callback (ItemData *data,
	gboolean horizontal, SheetItem *sheet_item)
{
	GnomeCanvasPoints *points;
	WireItem *item;
	WireItemPriv *priv;
	SheetPos start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	item = WIRE_ITEM (sheet_item);
	priv = item->priv;

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item->priv->line),
			       "points", points,
			       NULL);
	gnome_canvas_points_unref (points);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item),
			       "x", start_pos.x,
			       "y", start_pos.y,
			       NULL);

	/*
	 * Invalidate the bounding box cache.
	 */
	priv->cache_valid = FALSE;
}
Exemple #13
0
// 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;
}