Kitts wrote:

Hi all,

I have been doing some coding and using the property manager in flightgear but i want to know what is the right way to do it.

I use the method "fgGetNode("/path/to/property", true)" to get an existing property or create one if not there. There are a few things i want to know that i list below:

1) A node that is used in the flight system also results in the method "isTied" failing and the It does allow me to tie this already existing property to a variable?!? Is this the expected behavior? Isn't the property supposed to be tied to a variable somewhere already?
No, properties are not stored by default in the program 'variables', that's why they are not tied. In practice however there is a lot of properties wich have some get/set code associated with
them, and very few wich are directly tied to a variable.

2) When a property did not previously exist, is it necessary to create a variable and tie the node to that variable? I find the system to be working either ways. If i do not tie it, the property is displayed as "double" in the property browser else it displays the data type that it has been tied to.
If it's tied to a variable then the property will allways be of the right type. Else it will has the type you gave it when you created it / accessed it the first time. Even if you write something in another type it will keep it's creation type. The props functions are doing all the casting for you.

3) When the property has been explicitly tied, no matter what the value is initialized to using the "setDoubleValue" method the property browser shows the value as zero. This display of zero does not happen when the property is not tied explicitly.
Perhaps are you overwriting the value in your code (and why would you use setdoublevalue in your own code when you can directly write in the container variable ?). Look at the AIBase class, they use tied properties and you can check the values in the property browser. Btw, for properties tied or having a setter function, the property browser *won't* update the value displayed when the
property change. You must close/open the property browser to see the change.

4) I would also like to add a change listener to the class that i have written so that the class is informed as and when a variable being watched has changed value. I believe the way to do this is to use the "SGPropertyChangeListener" class as a base class and implement the "valueChanged" method to do the job. Is this correct?
I think, never done it myself. Note that if you own the property you can also use a set function to update its value, and then you allways know when the property has changed.

So now, back to my question. What is the right way to use the property manager? Which are the right methods that are to be used and in what sequence?

If you own the property and you manage it I think the usual way is to use the C++ style, ie you use a get and a set function to access the member, so you can use fgTie(propertyname, this, get_function, set_function).
If it's not your property then you use fgGetXXX.

Harald.


_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to