Re: Differentiating between Connectors and Objects



Am 11.07.2008 07:17, Sameer Sahasrabuddhe schrieb:
On Wed, Jul 9, 2008 at 11:20 PM, Fred Morcos <fred morcos gmail com> wrote:

(pseudo code)
if (objtype == "Standard - Line" || "UML - Generalization" || "UML -
Dependency" || etc...)

It seems from the rest of the conversation that you will indeed be
stuck with comparing strings. If that is actually the case, I would
suggest that you make your code as future-proof as possible.

For starters, quite a few string constants are already declared as
macros. Instead of hard-coding the value as you have shown in the
pseudocode, you should consider using such macros. You could possibly
define them if they don't already exist, and replace all occurences of
each string with the corresponding macro. (As an aside, actually I had
promised to clean up many of these hard-coded strings, but that's one
of my commitments that has been left by the way-side due to my current
busy status)

I don't think this is the right thing to do for an expandable type system, i.e. I will not accept which moves knowledge about every object type name in existance into the core. As tried to outline before not type is the key here but interface, respectively existance of properties.

So for shared property definitions the proposed solution is fine, for object types it is not.

In addition, try to create a function that captures your intention
clearly. Instead of inserting a long series of comparisons in the
condition part of an if-statement, make it a function with a name like
(is_connector) or something specific and meaningful like that. If you
can figure out an appropriate file to put that function, that is even
better, so that others could also use it.

I think there is (almost) enough information in the Object interface to solve the problem at hand. But regarding conections I always need to take a look at the capabilities of Handle and ConnectionPoint and their cooperation with DiaObject myself.

Just tested with the attached Python script. The key to "connectors" is counting the connectable handles, i.e.

def IsConnectable (object) :
        for h in object.handles :
                if h.connect_type != HANDLE_NONCONNECTABLE :
                        return 1
        return 0

If you really want to get into details, consider implementing this as
a function in the Object vtable. Both Lars and Hans will give you a
very hard time if you decide to take this last option, but it can
sometimes be worth it!

:-)

        Hans


-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert
import dia

def count_cb (data, flags) :
        if not data :
                dia.message_warning ("Nothing to count.")
        bc = {}
        for layer in data.layers :
                for object in layer.objects :
                        count = len(object.connections)
                        if bc.has_key (count) :
                                bc[count].append (object)
                        else :
                                bc[count] = [object]
        keys = bc.keys()
        keys.sort ()
        inspected = {}
        for k in keys :
                print "Connections", k, "types:", len(bc[k])
                for o in bc[k] :
                        if inspected.has_key(o.type.name) :
                                continue
                        connectable = 0
                        hts = []
                        for h in o.handles :
                                hts.append (h.connect_type)
                                if h.connect_type != 0 : # HANDLE_CONNECTABLE
                                        connectable += 1
                        print o.type.name, connectable, "connectable handles", hts
                        inspected[o.type.name] = 1
                                
dia.register_action ("DebugCount", "Count Connections", 
                     "/DisplayMenu/Debug/DebugExtensionStart", 
                     count_cb)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]