2010-09-20 18:18:30 +02:00
|
|
|
/*
|
|
|
|
* ld-symbol.c
|
|
|
|
*
|
|
|
|
* This file is a part of logdiag.
|
2011-01-08 06:44:40 +01:00
|
|
|
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
|
|
|
* See the file LICENSE for licensing information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-10 11:20:14 +01:00
|
|
|
#include "liblogdiag.h"
|
2010-09-20 18:18:30 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:ld-symbol
|
2011-01-28 17:39:40 +01:00
|
|
|
* @short_description: A symbol
|
2011-01-09 06:46:48 +01:00
|
|
|
* @see_also: #LdDiagramSymbol, #LdCanvas
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
2011-01-09 06:46:48 +01:00
|
|
|
* #LdSymbol represents a symbol to be drawn onto a #LdCanvas.
|
2010-11-16 10:30:10 +01:00
|
|
|
*
|
|
|
|
* All implementations of this abstract class are required to use
|
|
|
|
* cairo_save() and cairo_restore() when drawing to store the state.
|
2010-09-20 18:18:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-24 13:43:41 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2010-10-27 15:52:36 +02:00
|
|
|
PROP_NAME,
|
|
|
|
PROP_HUMAN_NAME,
|
2011-01-08 12:09:45 +01:00
|
|
|
PROP_AREA,
|
|
|
|
PROP_TERMINALS
|
2010-10-24 13:43:41 +02:00
|
|
|
};
|
|
|
|
|
2010-12-05 15:21:00 +01:00
|
|
|
static void ld_symbol_get_property (GObject *object, guint property_id,
|
2010-10-24 13:43:41 +02:00
|
|
|
GValue *value, GParamSpec *pspec);
|
2010-12-05 15:21:00 +01:00
|
|
|
static void ld_symbol_set_property (GObject *object, guint property_id,
|
2010-10-24 13:43:41 +02:00
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2011-01-04 14:52:57 +01:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
static void
|
|
|
|
ld_symbol_class_init (LdSymbolClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
2010-10-24 13:43:41 +02:00
|
|
|
GParamSpec *pspec;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2010-10-24 13:43:41 +02:00
|
|
|
object_class->get_property = ld_symbol_get_property;
|
|
|
|
object_class->set_property = ld_symbol_set_property;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2010-10-24 13:43:41 +02:00
|
|
|
/**
|
|
|
|
* LdSymbol:name:
|
|
|
|
*
|
|
|
|
* The name of this symbol.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("name", "Name",
|
|
|
|
"The name of this symbol.",
|
2010-10-27 15:52:36 +02:00
|
|
|
"", G_PARAM_READABLE);
|
2010-10-24 13:43:41 +02:00
|
|
|
g_object_class_install_property (object_class, PROP_NAME, pspec);
|
|
|
|
|
2010-10-27 15:52:36 +02:00
|
|
|
/**
|
|
|
|
* LdSymbol:human-name:
|
|
|
|
*
|
|
|
|
* The localized human name of this symbol.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("human-name", "Human name",
|
|
|
|
"The localized human name of this symbol.",
|
|
|
|
"", G_PARAM_READABLE);
|
|
|
|
g_object_class_install_property (object_class, PROP_HUMAN_NAME, pspec);
|
2010-10-27 18:15:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LdSymbol:area:
|
|
|
|
*
|
|
|
|
* The area of this symbol.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_boxed ("area", "Area",
|
|
|
|
"The area of this symbol.",
|
2011-01-08 06:44:40 +01:00
|
|
|
LD_TYPE_RECTANGLE, G_PARAM_READABLE);
|
2010-10-27 18:15:31 +02:00
|
|
|
g_object_class_install_property (object_class, PROP_AREA, pspec);
|
2011-01-08 12:09:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LdSymbol:terminals:
|
|
|
|
*
|
|
|
|
* A point array that specifies terminals of this symbol.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_boxed ("terminals", "Terminals",
|
|
|
|
"A point array that specifies terminals of this symbol.",
|
|
|
|
LD_TYPE_POINT_ARRAY, G_PARAM_READABLE);
|
|
|
|
g_object_class_install_property (object_class, PROP_TERMINALS, pspec);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_symbol_init (LdSymbol *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-24 13:43:41 +02:00
|
|
|
static void
|
|
|
|
ld_symbol_get_property (GObject *object, guint property_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
LdSymbol *self;
|
|
|
|
|
|
|
|
self = LD_SYMBOL (object);
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, ld_symbol_get_name (self));
|
|
|
|
break;
|
2010-10-27 15:52:36 +02:00
|
|
|
case PROP_HUMAN_NAME:
|
|
|
|
g_value_set_string (value, ld_symbol_get_human_name (self));
|
|
|
|
break;
|
2010-10-27 18:15:31 +02:00
|
|
|
case PROP_AREA:
|
|
|
|
{
|
2011-01-08 06:44:40 +01:00
|
|
|
LdRectangle area;
|
2010-10-27 18:15:31 +02:00
|
|
|
|
|
|
|
ld_symbol_get_area (self, &area);
|
|
|
|
g_value_set_boxed (value, &area);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-08 12:09:45 +01:00
|
|
|
case PROP_TERMINALS:
|
|
|
|
g_value_set_boxed (value, ld_symbol_get_terminals (self));
|
|
|
|
break;
|
2010-10-24 13:43:41 +02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_symbol_set_property (GObject *object, guint property_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
2010-10-27 15:52:36 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2010-10-24 13:43:41 +02:00
|
|
|
}
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2010-10-27 15:52:36 +02:00
|
|
|
/**
|
|
|
|
* ld_symbol_get_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbol object.
|
2010-10-27 15:52:36 +02:00
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: the name of the symbol.
|
2010-10-27 15:52:36 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ld_symbol_get_name (LdSymbol *self)
|
|
|
|
{
|
|
|
|
LdSymbolClass *klass;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2010-12-05 15:21:00 +01:00
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL (self), NULL);
|
2010-10-24 13:43:41 +02:00
|
|
|
|
2010-10-27 15:52:36 +02:00
|
|
|
klass = LD_SYMBOL_GET_CLASS (self);
|
|
|
|
g_return_val_if_fail (klass->get_name != NULL, NULL);
|
|
|
|
return klass->get_name (self);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-24 13:43:41 +02:00
|
|
|
/**
|
2010-10-27 15:52:36 +02:00
|
|
|
* ld_symbol_get_human_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbol object.
|
2010-10-24 13:43:41 +02:00
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: the localised human name of the symbol.
|
2010-10-24 13:43:41 +02:00
|
|
|
*/
|
2010-10-27 15:52:36 +02:00
|
|
|
const gchar *
|
|
|
|
ld_symbol_get_human_name (LdSymbol *self)
|
2010-10-24 13:43:41 +02:00
|
|
|
{
|
2010-10-27 15:52:36 +02:00
|
|
|
LdSymbolClass *klass;
|
|
|
|
|
2010-12-05 15:21:00 +01:00
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL (self), NULL);
|
2010-10-24 13:43:41 +02:00
|
|
|
|
2010-10-27 15:52:36 +02:00
|
|
|
klass = LD_SYMBOL_GET_CLASS (self);
|
|
|
|
g_return_val_if_fail (klass->get_human_name != NULL, NULL);
|
|
|
|
return klass->get_human_name (self);
|
2010-10-24 13:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-27 15:52:36 +02:00
|
|
|
* ld_symbol_get_area:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbol object.
|
|
|
|
* @area: where the area of the symbol will be returned.
|
2010-10-24 13:43:41 +02:00
|
|
|
*
|
2010-10-27 15:52:36 +02:00
|
|
|
* Get the area of the symbol.
|
2010-10-24 13:43:41 +02:00
|
|
|
*/
|
2010-10-27 15:52:36 +02:00
|
|
|
void
|
2011-01-08 06:44:40 +01:00
|
|
|
ld_symbol_get_area (LdSymbol *self, LdRectangle *area)
|
2010-10-24 13:43:41 +02:00
|
|
|
{
|
2010-10-27 15:52:36 +02:00
|
|
|
LdSymbolClass *klass;
|
|
|
|
|
2010-10-24 13:43:41 +02:00
|
|
|
g_return_if_fail (LD_IS_SYMBOL (self));
|
2010-10-27 15:52:36 +02:00
|
|
|
g_return_if_fail (area != NULL);
|
|
|
|
|
|
|
|
klass = LD_SYMBOL_GET_CLASS (self);
|
|
|
|
g_return_if_fail (klass->get_area != NULL);
|
|
|
|
klass->get_area (self, area);
|
2010-10-24 13:43:41 +02:00
|
|
|
}
|
|
|
|
|
2011-01-08 12:09:45 +01:00
|
|
|
/**
|
|
|
|
* ld_symbol_get_terminals:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbol object.
|
2011-01-08 12:09:45 +01:00
|
|
|
*
|
|
|
|
* Get a list of symbol terminals.
|
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: an #LdPointArray structure.
|
2011-01-08 12:09:45 +01:00
|
|
|
*/
|
|
|
|
const LdPointArray *
|
|
|
|
ld_symbol_get_terminals (LdSymbol *self)
|
|
|
|
{
|
|
|
|
LdSymbolClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL (self), NULL);
|
|
|
|
|
|
|
|
klass = LD_SYMBOL_GET_CLASS (self);
|
|
|
|
g_return_val_if_fail (klass->get_terminals != NULL, NULL);
|
|
|
|
return klass->get_terminals (self);
|
|
|
|
}
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
/**
|
|
|
|
* ld_symbol_draw:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbol object.
|
|
|
|
* @cr: a cairo surface to be drawn on.
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
|
|
|
* Draw the symbol onto a Cairo surface.
|
|
|
|
*/
|
|
|
|
void
|
2010-09-25 20:59:20 +02:00
|
|
|
ld_symbol_draw (LdSymbol *self, cairo_t *cr)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
2010-09-25 20:59:20 +02:00
|
|
|
LdSymbolClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL (self));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
|
|
|
klass = LD_SYMBOL_GET_CLASS (self);
|
2010-10-27 15:52:36 +02:00
|
|
|
g_return_if_fail (klass->draw != NULL);
|
|
|
|
klass->draw (self, cr);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|