Hi, Right_connection and left_connection members of the UMLAttribute structure are not available from bindings.
Here is a patch which allows to access to these connection points with pydia. In attachement, test.py is an example of use. Comments are welcome :) Pierre-Louis
>From fe79a1c1c583e64e0873fb049de07db7cc2ad8b8 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli <[email protected]> Date: Wed, 17 Aug 2011 12:15:36 +0200 Subject: [PATCH 1/4] add property type for connection point --- lib/prop_connpoint.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/prop_connpoint.h | 32 ++++++++++++++++++++ lib/properties.c | 1 + lib/properties.h | 1 + lib/propinternals.h | 1 + 5 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 lib/prop_connpoint.c create mode 100644 lib/prop_connpoint.h diff --git a/lib/prop_connpoint.c b/lib/prop_connpoint.c new file mode 100644 index 0000000..17822e5 --- /dev/null +++ b/lib/prop_connpoint.c @@ -0,0 +1,80 @@ +/* Dia -- a diagram creation/manipulation program -*- c -*- + * + * Property types for connection point type + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> + +#include "properties.h" +#include "propinternals.h" +#include "prop_connpoint.h" +#include "prefs.h" + +/*********************************/ +/* The CONNPOINT property type. */ +/*********************************/ + +static ConnpointProperty * +connpointprop_new(const PropDescription *pdesc, PropDescToPropPredicate reason) +{ + ConnpointProperty *prop = g_new0(ConnpointProperty, 1); + initialize_property(&prop->common, pdesc, reason); + memset(&prop->connpoint_data, 0, sizeof(prop->connpoint_data)); + return prop; +} + +static ConnpointProperty * +connpointprop_copy(ConnpointProperty *src) +{ + ConnpointProperty *prop = + (ConnpointProperty *)src->common.ops->new_prop(src->common.descr, + src->common.reason); + copy_init_property(&prop->common,&src->common); + prop->connpoint_data = src->connpoint_data; + return prop; +} + +static void +connpointprop_get_from_offset(ConnpointProperty *prop, + void *base, guint offset, guint offset2) +{ + prop->connpoint_data = struct_member(base, offset, ConnectionPoint*); +} + +static const PropertyOps connpointprop_ops = { + (PropertyType_New) connpointprop_new, + (PropertyType_Free) noopprop_free, + (PropertyType_Copy) connpointprop_copy, + (PropertyType_Load) invalidprop_load, + (PropertyType_Save) invalidprop_save, + (PropertyType_GetWidget) invalidprop_get_widget, + (PropertyType_ResetWidget) invalidprop_reset_widget, + (PropertyType_SetFromWidget) invalidprop_set_from_widget, + + (PropertyType_CanMerge) noopprop_can_merge, + (PropertyType_GetFromOffset) connpointprop_get_from_offset, + (PropertyType_SetFromOffset) invalidprop_set_from_offset +}; + +void +prop_connpoint_register(void) +{ + prop_type_register(PROP_TYPE_CONNPOINT, &connpointprop_ops); +} diff --git a/lib/prop_connpoint.h b/lib/prop_connpoint.h new file mode 100644 index 0000000..fdb368c --- /dev/null +++ b/lib/prop_connpoint.h @@ -0,0 +1,32 @@ +/* Dia -- a diagram creation/manipulation program -*- c -*- + * + * Property types for connection point type + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +#ifndef PROP_CONNPOINT_H +#define PROP_CONNPOINT_H + +#include "properties.h" +#include "connectionpoint.h" + +typedef struct { + Property common; + ConnectionPoint * connpoint_data; +} ConnpointProperty; + +void prop_connpoint_register(void); + +#endif diff --git a/lib/properties.c b/lib/properties.c index 2880ca1..cff1451 100644 --- a/lib/properties.c +++ b/lib/properties.c @@ -53,6 +53,7 @@ stdprops_init(void) prop_dicttypes_register(); prop_pixbuftypes_register(); prop_matrix_register(); + prop_connpoint_register(); } /* --------------------------------------- */ diff --git a/lib/properties.h b/lib/properties.h index a1127e2..7b8037c 100644 --- a/lib/properties.h +++ b/lib/properties.h @@ -199,6 +199,7 @@ typedef const gchar *PropertyType; #define PROP_TYPE_DICT "dict" /* DictProperty */ #define PROP_TYPE_PIXBUF "pixbuf" /* PixbufProperty */ #define PROP_TYPE_MATRIX "matrix" /* MatrixProperty */ +#define PROP_TYPE_CONNPOINT "connpoint" /* ConnpointProperty */ /* **************************************************************** */ diff --git a/lib/propinternals.h b/lib/propinternals.h index b4b1734..070919e 100644 --- a/lib/propinternals.h +++ b/lib/propinternals.h @@ -88,6 +88,7 @@ void do_get_props_from_offsets(void *base, GPtrArray *props, #include "prop_dict.h" #include "prop_pixbuf.h" #include "prop_matrix.h" +#include "prop_connpoint.h" #endif /* PROPINTERNALS_H */ -- 1.7.5.4
>From 4ac7740f89078dfa263362928ba01b5e5f831823 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli <[email protected]> Date: Wed, 17 Aug 2011 12:23:11 +0200 Subject: [PATCH 2/4] pydia: handle new property PROP_TYPE_CONNPOINT --- plug-ins/python/pydia-property.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/plug-ins/python/pydia-property.c b/plug-ins/python/pydia-property.c index 04efbe4..67de778 100644 --- a/plug-ins/python/pydia-property.c +++ b/plug-ins/python/pydia-property.c @@ -30,6 +30,7 @@ #include "pydia-font.h" #include "pydia-color.h" #include "pydia-text.h" +#include "pydia-cpoint.h" #include <structmember.h> /* PyMemberDef */ @@ -42,6 +43,7 @@ #include "prop_dict.h" #include "prop_matrix.h" #include "prop_pixbuf.h" +#include "prop_connpoint.h" /* * New @@ -205,6 +207,8 @@ static int PyDia_set_Dict (Property *prop, PyObject *val); static PyObject * PyDia_get_Pixbuf (PixbufProperty *prop); static int PyDia_set_Pixbuf (Property *prop, PyObject *val); +static PyObject * PyDia_get_Connectionpoint (ConnpointProperty *prop); + static int PyDia_set_Bool (Property *prop, PyObject *val) { @@ -585,7 +589,8 @@ struct { { PROP_TYPE_SARRAY, PyDia_get_Array, PyDia_set_Array }, { PROP_TYPE_DARRAY, PyDia_get_Array, PyDia_set_Array }, { PROP_TYPE_DICT, PyDia_get_Dict, PyDia_set_Dict }, - { PROP_TYPE_PIXBUF, PyDia_get_Pixbuf, PyDia_set_Pixbuf } + { PROP_TYPE_PIXBUF, PyDia_get_Pixbuf, PyDia_set_Pixbuf }, + { PROP_TYPE_CONNPOINT, PyDia_get_Connectionpoint } }; static void @@ -797,6 +802,13 @@ PyDia_set_Pixbuf (Property *prop, PyObject *val) return -1; } +static PyObject * +PyDia_get_Connectionpoint (ConnpointProperty *prop) +{ + return PyDiaConnectionPoint_New (prop->connpoint_data); +} + + /* * GetAttr */ -- 1.7.5.4
>From 1562ac4669ef187486571ad6083b7adb82d066f1 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli <[email protected]> Date: Wed, 17 Aug 2011 12:24:48 +0200 Subject: [PATCH 3/4] use PROP_TYPE_CONNPOINT for left/right_connection --- objects/UML/umlattribute.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/objects/UML/umlattribute.c b/objects/UML/umlattribute.c index 92ddb2a..c39a59c 100644 --- a/objects/UML/umlattribute.c +++ b/objects/UML/umlattribute.c @@ -47,6 +47,10 @@ static PropDescription umlattribute_props[] = { N_("Abstract (?)"), NULL, NULL }, { "class_scope", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL, N_("Class scope (static)"), NULL, NULL }, + { "left_connection", PROP_TYPE_CONNPOINT, PROP_FLAG_VISIBLE|PROP_FLAG_DONT_SAVE, + N_("Left connection"), NULL, NULL }, + { "right_connection", PROP_TYPE_CONNPOINT, PROP_FLAG_VISIBLE|PROP_FLAG_DONT_SAVE, + N_("Right connection"), NULL, NULL }, PROP_DESC_END }; @@ -59,7 +63,9 @@ static PropOffset umlattribute_offsets[] = { { "visibility", PROP_TYPE_ENUM, offsetof(UMLAttribute, visibility) }, { "abstract", PROP_TYPE_BOOL, offsetof(UMLAttribute, abstract) }, { "class_scope", PROP_TYPE_BOOL, offsetof(UMLAttribute, class_scope) }, - { NULL, 0, 0 }, + { "left_connection", PROP_TYPE_CONNPOINT, offsetof(UMLAttribute, left_connection) }, + { "right_connection", PROP_TYPE_CONNPOINT, offsetof(UMLAttribute, right_connection) }, + { NULL, 0, 0 }, }; -- 1.7.5.4
>From 3117e7e9930929d76ce689837cc69b240d504f32 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli <[email protected]> Date: Wed, 17 Aug 2011 12:25:58 +0200 Subject: [PATCH 4/4] build scripts:add new property connection point --- lib/Makefile.am | 2 ++ lib/makefile.mingw | 1 + lib/makefile.msc | 1 + 3 files changed, 4 insertions(+), 0 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 1fca5ca..698770d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -12,6 +12,8 @@ stdprop_files = \ propobject.c \ prop_basic.c \ prop_basic.h \ + prop_connpoint.c \ + prop_connpoint.h \ prop_dict.c \ prop_dict.h \ prop_matrix.c \ diff --git a/lib/makefile.mingw b/lib/makefile.mingw index fe62690..4c9b31a 100644 --- a/lib/makefile.mingw +++ b/lib/makefile.mingw @@ -66,6 +66,7 @@ OBJECTS = \ prefs.o \ prop_attr.o \ prop_basic.o \ + prop_connpoint.o \ prop_geomtypes.o \ prop_inttypes.o \ prop_sdarray.o \ diff --git a/lib/makefile.msc b/lib/makefile.msc index a6a8be3..a91903e 100644 --- a/lib/makefile.msc +++ b/lib/makefile.msc @@ -95,6 +95,7 @@ OBJECTS = \ prefs.obj \ prop_attr.obj \ prop_basic.obj \ + prop_connpoint.obj \ prop_dict.obj \ prop_geomtypes.obj \ prop_inttypes.obj \ -- 1.7.5.4
#encoding: utf-8
import dia
def test(data, flags):
classes = []
layer = dia.active_display().diagram.data.layers[0]
for obj in layer.objects:
if obj.type.name == "UML - Class":
print "\nobject", obj
for attr in obj.properties['attributes'].value:
# attr is a tuple, len(attr) == 9
# left_connection: attr[7] -> ConnectionPoint
# right_connection: attr[8] -> ConnectionPoint
if attr[7].connected:
print "\t %s left: connected to %s" % (attr[0],
attr[7].connected)
if attr[8].connected:
print "\t %s right: connected to %s" % (attr[0],
attr[8].connected)
classes.append(obj)
dia.register_callback("Test", "<Display>/Dialogs/Test", test)
test.dia
Description: application/dia-diagram
_______________________________________________ dia-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/dia-list FAQ at http://live.gnome.org/Dia/Faq Main page at http://live.gnome.org/Dia
