Hi,
I am doing some work with UML diagrams and I use Dia to load diagrams
generated from a UXF description. To cut a longer story short, attached is
a patch that solves one of my problems.
I had this problem when loading generated UML diagrams: in such a diagram,
not all coordinates are specified because I cannot know the font metrics
etc. Elements (eg. UML Class) load fine when given only the elem_corner
attribute. But connections (eg. UML Generalization) between elements are a
more difficult issue.
Autorouting set aside, I was annoyed by the fact that in order for a
connection to be drawn connected to its respective elements, the elements
have to be clicked first. (You can try it on attached dia-test.dia )
The patch solves it by calling diagram_update_connections_object for all
objects after the diagram has been loaded. I originally wanted to put the
code into diagram_data_load (load_save.c) but there's no access to the
Diagram there and I didn't want to change the interfaces. If you want to
move the code, feel free to do so.
For a background on UXF, see an earlier message of mine,
http://www.mail-archive.com/dia-list%40lysator.liu.se/msg02878.html
That's it, enjoy.
Martin
PS: Um, James, can we expect a release anytime soon?
<?xml version='1.0'?>
<diagram xmlns:dia='http://www.lysator.liu.se/~alla/dia/'
xmlns:uxf='http://www.yy.cs.keio.ac.jp/~suzuki/project/uxf/'>
<diagramdata>
<attribute name='background'>
<color val='#ffffff'/>
</attribute>
<attribute name='paper'>
<composite type='paper'>
<attribute name='name'>
<string>#A4#</string>
</attribute>
<attribute name='tmargin'>
<real val='2.82'/>
</attribute>
<attribute name='bmargin'>
<real val='2.82'/>
</attribute>
<attribute name='lmargin'>
<real val='2.82'/>
</attribute>
<attribute name='rmargin'>
<real val='2.82'/>
</attribute>
<attribute name='is_portrait'>
<boolean val='true'/>
</attribute>
<attribute name='scaling'>
<real val='1'/>
</attribute>
<attribute name='fitto'>
<boolean val='false'/>
</attribute>
</composite>
</attribute>
<attribute name='grid'>
<composite type='grid'>
<attribute name='width_x'>
<real val='1'/>
</attribute>
<attribute name='width_y'>
<real val='1'/>
</attribute>
<attribute name='visible_x'>
<int val='1'/>
</attribute>
<attribute name='visible_y'>
<int val='1'/>
</attribute>
</composite>
</attribute>
<attribute name='guides'>
<composite type='guides'>
<attribute name='hguides'/>
<attribute name='vguides'/>
</composite>
</attribute>
</diagramdata>
<layer visible='true' name='Background'>
<object version='0' id='Foo' type='UML - Class'>
<attribute name='elem_corner'>
<point val='3,0'/>
</attribute>
<attribute name='name'>
<string>#Foo#</string>
</attribute>
<attribute name='stereotype'>
<string/>
</attribute>
<attribute name='abstract'>
<boolean val=''/>
</attribute>
<attribute name='suppress_attributes'>
<boolean val='false'/>
</attribute>
<attribute name='suppress_operations'>
<boolean val='false'/>
</attribute>
<attribute name='visible_attributes'>
<boolean val='true'/>
</attribute>
<attribute name='visible_operations'>
<boolean val='true'/>
</attribute>
<attribute name='attributes'>
<composite type='umlattribute'>
<attribute name='name'>
<string>#i#</string>
</attribute>
<attribute name='type'>
<string>#int#</string>
</attribute>
<attribute name='value'>
<string/>
</attribute>
<attribute name='visibility'>
<enum val='1'/>
</attribute>
<attribute name='class_scope'>
<boolean val=''/>
</attribute>
</composite>
</attribute>
<attribute name='operations'/>
<attribute name='template'>
<boolean val='false'/>
</attribute>
<attribute name='templates'/>
</object>
<object version='0' id='Bar' type='UML - Class'>
<attribute name='elem_corner'>
<point val='3,7'/>
</attribute>
<attribute name='name'>
<string>#Bar#</string>
</attribute>
<attribute name='stereotype'>
<string/>
</attribute>
<attribute name='abstract'>
<boolean val=''/>
</attribute>
<attribute name='suppress_attributes'>
<boolean val='false'/>
</attribute>
<attribute name='suppress_operations'>
<boolean val='false'/>
</attribute>
<attribute name='visible_attributes'>
<boolean val='true'/>
</attribute>
<attribute name='visible_operations'>
<boolean val='true'/>
</attribute>
<attribute name='attributes'>
<composite type='umlattribute'>
<attribute name='name'>
<string>#j#</string>
</attribute>
<attribute name='type'>
<string>#int#</string>
</attribute>
<attribute name='value'>
<string/>
</attribute>
<attribute name='visibility'>
<enum val='1'/>
</attribute>
<attribute name='class_scope'>
<boolean val=''/>
</attribute>
</composite>
</attribute>
<attribute name='operations'/>
<attribute name='template'>
<boolean val='false'/>
</attribute>
<attribute name='templates'/>
</object>
<object version='0' id='137161096' type='UML - Generalization'>
<attribute name='obj_pos'>
<point val='7.0,7.0'/>
</attribute>
<attribute name='obj_bb'>
<rectangle val='2.25,4.8;8.45,9.55'/>
</attribute>
<attribute name='orth_points'>
<point val='7.0,7.0'/>
<point val='7.0,6.25'/>
<point val='3.7,6.25'/>
<point val='3.7,8.1'/>
<point val='7.0,8.1'/>
</attribute>
<attribute name='orth_orient'>
<enum val='1'/>
<enum val='0'/>
<enum val='1'/>
<enum val='0'/>
</attribute>
<attribute name='name'>
<string/>
</attribute>
<attribute name='stereotype'>
<string/>
</attribute>
<connections>
<connection connection='6' to='Foo' handle='0'/>
<connection connection='1' to='Bar' handle='1'/>
</connections>
</object>
</layer>
</diagram>
<?xml version="1.0"?>
<UXF Version="2.0">
<Package>
<Name>A Package</Name>
<ClassDiagram>
<Name>A Diagram</Name>
<Class>
<TaggedValue>
<Tag>DiagramPosition</Tag>
<Value>3,0</Value>
</TaggedValue>
<TaggedValue>
<Tag>SourceFile</Tag>
<Value>/home/martin/medusa/testcode/dia/inheritance.h</Value>
</TaggedValue>
<TaggedValue>
<Tag>SourceLine</Tag>
<Value>2</Value>
</TaggedValue>
<Name>Foo</Name>
<Attribute>
<Name>i</Name>
<Type>int</Type>
<Visibility>private</Visibility>
</Attribute>
</Class>
<Class>
<TaggedValue>
<Tag>DiagramPosition</Tag>
<Value>3,7</Value>
</TaggedValue>
<TaggedValue>
<Tag>SourceFile</Tag>
<Value>/home/martin/medusa/testcode/dia/inheritance.h</Value>
</TaggedValue>
<TaggedValue>
<Tag>SourceLine</Tag>
<Value>7</Value>
</TaggedValue>
<Name>Bar</Name>
<Attribute>
<Name>j</Name>
<Type>int</Type>
<Visibility>private</Visibility>
</Attribute>
</Class>
<Generalization>
<TaggedValue>
<Tag>Visibility</Tag>
<Value>public</Value>
</TaggedValue>
<Parent>Foo</Parent>
<Child>Bar</Child>
</Generalization>
</ClassDiagram>
</Package>
</UXF>
diff -ur dia-0.86-orig/app/diagram.c dia-0.86/app/diagram.c
--- dia-0.86-orig/app/diagram.c Tue Jul 25 15:19:06 2000
+++ dia-0.86/app/diagram.c Sun Feb 11 16:33:43 2001
@@ -23,6 +23,7 @@
#include "diagram.h"
#include "group.h"
#include "object_ops.h"
+#include "connectionpoint_ops.h"
#include "render_eps.h"
#include "focus.h"
#include "message.h"
@@ -48,6 +49,20 @@
ifilter = &dia_import_filter;
diagram = new_diagram(filename);
if (ifilter->import(filename, diagram->data)) {
+ /* Update connections for all objects. Useful when loading
+ generated diagrams where coordinates are bogus. */
+ int i;
+ Layer *layer;
+ for (i = 0; i < diagram->data->layers->len; i++) {
+ GList *objects;
+ layer = (Layer *) g_ptr_array_index(diagram->data->layers, i);
+ objects = layer->objects;
+ while (objects != NULL) {
+ Object *obj = (Object *) objects->data;
+ diagram_update_connections_object(diagram, obj, TRUE);
+ objects = g_list_next(objects);
+ }
+ }
diagram->unsaved = FALSE;
diagram_set_modified(diagram, FALSE);
} else {