A little help on understanding properties ??

P

Paic Citron

Hi,
I'm currently working on an scenegraph editor. I have a treeview, and
when I select a node, it shows its properties in a propertygrid. Each
node has a link to the scenegraph node, and I override the property
accessors to modify the scenegraph node when the user change something
in the propertygrid. For example :


// this is a custom 3 dimensional vector object.
[TypeConverterAttribute(ExpandableObjectConverter::typeid)]
public ref struct CVector3
{
CVector3(void) { x = 0.0f; y = 0.0f; z = 0.0f; }
CVector3(float X, float Y, float Z) { x =X; y = Y; z = Z; }

property float x;
property float y;
property float z;

virtual String ^ ToString(void) override
{
return("" + x + "; " + y + "; " + z);
}
};


Now, in the treeviewnode, I have something like :


property CVector3 ^ Position
{
void set(CVector3 ^ value)
{
// when the Position property is modified, I want
// to send the new position to the scenegraph node.

m_pNode->SetPosition(value->x, value->y, value->z);
}

CVector3 ^ get(void)
{
// I always get the position from the scengraph node.

return(gcnew CVector3(m_pNode->GetPositionX(),
m_pNode->GetPositionY(),
m_pNode->GetPositionZ());
}
}

where m_pNode is a pointer to the associated scenegraph node.

Now, the problem is that when I expand the Position property, and modify
the x component, the CTreeViewNode::position::set() method is not
called. I overrided the x, y and z accessors in the CVector3, and they
are correctly called, but I need to "notify" my CTreeViewNode that its
Position property changed, and I really don't know how to do that :/

If anyone know how to do this, I would really appreciate a little help ^^

And I apologize for my english :/ If you didn't understand my problem,
tell me, I'll try to be a little clearer ^^

Have a good day.


Damien
 
P

Paic Citron

Sorry to insist, but I really need help :/
Is the question too easy, and nobody answered because I can find the
answer on the web ? (in this case, I spend hours looking for information
without success :/) I wasn't clear in the explanation of my problem ? Or
is it impossible to do ??

Damien
 
S

Stoitcho Goutsev \(100\)

Paic,

Try to attribute your x,y and z properties with
NottifyParentPropertyAttribute(true).

[NottifyParentPropertyAttribute(true)]
property float x;
 
P

Paic Citron

Stoitcho said:
Paic,

Try to attribute your x,y and z properties with
NottifyParentPropertyAttribute(true).

[NottifyParentPropertyAttribute(true)]
property float x;

Thanks for the reply, but unfortunately, it doesn't work :/
But I didn't find this attribute in the MSDN which is given with Visual
C++ 2005 Express Edition ... do you mind telling me where did you find
this attribute, and how to use it ???

Thx again.

Damien
 
S

Stoitcho Goutsev \(100\)

Damien,

You say it didn't work, but you also said you couldn't find the attribute.
Did you actually tried.

The attribute is in the System.ComponentModel namespace in system.dll.

I didn't go into details, but this attribute is mostly related to the design
time support. That is when the 'x' property changes the designers will be
notified (IComponentChangedService) for the change on the parent property as
well. This doesn't mean thow that the setter of the parent property is going
to be called. Because you were talking about the *property window* I kind of
assumed that you are interested in the design time support.


--
Stoitcho Goutsev (100)

Paic Citron said:
Stoitcho said:
Paic,

Try to attribute your x,y and z properties with
NottifyParentPropertyAttribute(true).

[NottifyParentPropertyAttribute(true)]
property float x;

Thanks for the reply, but unfortunately, it doesn't work :/
But I didn't find this attribute in the MSDN which is given with Visual
C++ 2005 Express Edition ... do you mind telling me where did you find
this attribute, and how to use it ???

Thx again.

Damien
 
P

Paic Citron

Stoitcho said:
Damien,

You say it didn't work, but you also said you couldn't find the attribute.
Did you actually tried.

The attribute is in the System.ComponentModel namespace in system.dll.

I didn't go into details, but this attribute is mostly related to the design
time support. That is when the 'x' property changes the designers will be
notified (IComponentChangedService) for the change on the parent property as
well. This doesn't mean thow that the setter of the parent property is going
to be called. Because you were talking about the *property window* I kind of
assumed that you are interested in the design time support.

Ah, forgive me if I wasn't clear. I tried this attribute, and it didn't
work in the sense that the setter of the parent wasn't called. What I
didn't find is where did you found the documentation about this one. In
the documentation, there's a page entitled "Attributes for Control
Properties" and I didn't find it here :)

In fact, I'm not really interested in the design time support. I just
want to be able to know when a property was modified. For example, if a
CTreeViewNode instance has a CVector3 property, and I modify the x, y or
z property of this CVector3, I'd like to be able to catch this "event"
in CTreeViewNode.

Thanks for your help.


Damien
 
S

Stoitcho Goutsev \(100\)

Damien,

The setter of the CTreeViewNode will be never called simply because you
don't modify the tree node, but rather the vector object. the tree node
still reference the same instance of the vector class.

You need to implement some kind of notification by your self. For example
the vector class can fire an event when some of its properties change and
the tree node can hook on this event and act accordingly or the vector class
my accept a owner in its constructor with the recuirements the owner to
support a special interface that will be used for notification. It is up to
you to decide how to do it, but there is definitely no solution out of the
box.

What you can see in the winforms controls where you can expand the Size
poperty and change its Width for example and the control changes right a way
is all design time support. Try to do that in code - you can't because the
Size is a value type and you have to set it as a whole; this is a compile
time error. That's the reason the control provide properties Width and
Height where the programmers can set only one of the dimensions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top