Re: Named connection points?
- From: Hans Breuer <hans breuer org>
- To: discussions about usage and development of dia <dia-list gnome org>
- Subject: Re: Named connection points?
- Date: Fri, 17 Feb 2012 21:43:02 +0100
At 16.02.2012 16:07, Dan Katz wrote:
Hi -
I'm doing a bunch of work on yet another Python diagram->code
generator plugin, and several times now I've found myself wishing that
connection points (and handles, to a lesser extent) had names that
were assignable in the Custom Shape Module shape files and accessible
through the Python API.
For the use case at hand this would be names on the type level, not
changeable per object. But I don't see why you could not use named
constants for the connection point index instead.
The connection points are parsed in the order in the shape (see
objects/custom/shape_info.c) and put into the connection point array in
that order.
In any case (either with index or names) you have to ensure that your
script and your shapes are matching.
I actually got so far as beginning to hack
the C code to add this capability when I found that Dia actually used
to have named connection points and that they were removed in 2009
(https://mail.gnome.org/archives/commits-list/2009-August/msg00148.html).
I guess I have two questions: could we bring back named connection
points,
Not without a convincing use case. As my removal comment says they were
unused and just wasting memory (
http://git.gnome.org/browse/dia/commit/?id=a8193caff ) And it even was per
object, not per type.
and if not, then how do people usually deal with the issues
I'm having.
Just rely on the stable numbering of connection points and handles. If it
would be broken, than even the standard loading and saving of diagrams
would break.
A bit of context: I'm writing a Python plug-in for Dia which
translates a data-flow diagram to code in a home-grown legacy
job-control language. The plugin is exposed as an export filter (like
codegen.py and siblings) [...]
Where are the siblings of codegen.py?
The annoyance comes when I want to differentiate among the connection
points in the back-end pass of the Python code generator. I'd like to
be able to name the connection points as part of the custom object
definition (e.g. 'minuend', 'subtrahend', 'difference') and then then
get them by name in the Python API. In my imagination, the change in
the shape file would look something like this (a small syntactic
extension to what's there today):
<connection>
<point x="2" y="3" name="minuend"/>
<point x="2" y="5" name="subtrahend"/>
<point x="6" y="4" name="difference"/>
<connections>
(where the name attribute is optional, of course, defaulting to the
empty string) and would then allow code like
foo = [c for c in differencer.connections if c.name() == 'minuend']
You could spare the loop and the string compare by just using named
constants ...
which is rather cleaner than what I'm doing now which involves things
like getting the list of connections and sorting the connections by
y-coordinate to find the 'top' one and knowing that 'top'='minuend',
or sorting by x-coordinate and knowing that the right-most connection
point is the output. (In fact, is that sort of logic even reliable in
the face of actions like "Flip horizontal"?I haven't checked that…)
>
No, it is not. But the connection point index will stay stable.
HTH,
Hans
-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it. -- Dilbert
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]