Re: Patch to custom object: object-specific properties(preliminary)
From: Lars Clausen <lrclause cs uiuc edu>
To: dia-list gnome org
Subject: Re: Patch to custom object: object-specific properties(preliminary)
Date: Wed, 26 Nov 2003 11:25:35 -0600
On 24 Nov 2003, Marco Contenti wrote:
> ----- Original Message -----
> From: "Lars Clausen"
> Sent: Sunday, November 23, 2003 8:59 AM
>
>
> On 14 Nov 2003, Marco Contenti wrote:
>> Hello, here is a very first version of what I described last week. Now
>> only four types are supported. It seems it's working. Please try using
>> it and tell me what you think about.
>>
>> Apply the patch to files in <dia>/object/custom, then try using the
> modified
>> resistor shape I'm attaching or try making your own, it's simple, just
>> insert your custom attributes in the shape like this:
>> <shape ... >
>> ...
>> <ext_attributes>
>> <attribute name="ID" type="string"/>
>> <attribute name="Resistance (ohms)" type="int"/>
>> <attribute name="Power dissipation (W)" type="real"/>
>> <attribute name="SMD package" type="bool"/>
>> </ext_attributes>
>> ...
>> </shape>
>
> I'm still wondering why you don't put these together with the normal
> attributes. Since they're statically defined on the shapes, there's
> nothing to distinguish them from the other attributes anyway, so you
> could save some work & complexity by using the regular attributes
> mechanism.
>
> ___
>
> Just because I don't want to have a fixed set of attributes for ALL
> custom objects, but a different set for each object type (=shape). What
> I'd like to do in next step (but this is a bit specific to my
> application) is being able to reload a shape info without shutting down
> Dia, after the user has changed its characteristics (connection points,
> text labels, extended attributes) in a user-friendly way by editing a
> related diagram. I never checked out, but I think that at least some of
> the above is implemented in MS Visio.
Reloading is a separate issue, let's get the attributes for shapes thing
right first.
I applied your patch (though didn't commit that yet), and notice that you
actually do what I was suggesting, kinda. You're adding the custom
attributes to the normal attributes in describe_props (I think it should be
a part of shape loading, then we're sure it's done in time). However, the
saving part didn't seem to work. I tried replacing the save function with
object_save_using_properties, and it saved nicely (though without the
'custom:' prefix). You should be aware of the distinction between 'name'
and the 'description' field of the props -- 'name' is only for internal
identification (including in the save format), while 'description' is
what's shown in the dialog. You're using the same string for both, and
then doing a hack in saving to mark them as custom. I'd suggest adding the
"custom:" mark in the name as soon as you create the property, then you're
sure you won't be confused about when it's there. Essentially, it should
be done for the ShapeInfo, not for the Custom.
Using object_load_using_properties to load (wrapped to give appropriate
type) is a mite trickier, as you'll need to ensure the right shape is used
in time for the rest of the load. Moving the addition of extended
attributes into the ShapeInfo creation code should help with this.
You may want to ocnsider if the shape designer should be able to specify a
default value. It'd have to be used in custom_create.
-Lars
--
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| HĂ„rdgrim of Numenor
"I do not agree with a word that you say, but I |----------------------------
will defend to the death your right to say it." | Where are we going, and
--Evelyn Beatrice Hall paraphrasing Voltaire | what's with the handbasket?