-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FGFDMExec.get_property_catalog() is supposed to take 0 arguments, but is says it needs exactly one #641
Comments
Lines 771 to 785 in 59389f6
Lines 512 to 518 in 59389f6
So it takes a filter argument, if you don't want to filter. >>> fdm.get_property_catalog('')
{'inertial/sea-level-radius_ft': 20925646.32546, 'simulation/gravity-model': 1.0, 'simulation/integrator/rate/rotational': 1.0, 'simulation/integrator/rate/translational': 3.0, 'simulation/integrator/position/rotational': 1.0, 'simulation/integrator/position/translational': 4.0, |
I see, jsbsim.pyx.in is a good hint, thanks for that! So there are some differences with the original C++ function, or is the C++ function subject to change? Line 526 in 59389f6
I still have some issues with properties, since I am not able to reset the accelerations properly (the aircraft always starts with some acceleration and consequently with velocities), but I will open a new discussion thread for this as soon as I've done some more digging. |
Yes there are a couple of differences, i.e. the python version takes a filter option and returns a dictionary, whereas the C++ version doesn't take the filter option and returns a vector/array rather than a dictionary.
JSBSim is open source and doesn't make any API guarantees so yes it could change. |
Well, indeed the current Python API for |
The C++ API looks a bit messy/inconsistent to me. std::vector<std::string> PropertyCatalog;
std::vector<std::string>& GetPropertyCatalog(void) {return PropertyCatalog;}
string FGFDMExec::QueryPropertyCatalog(const string& in)
{
string results;
for (auto &catalogElm: PropertyCatalog) {
if (catalogElm.find(in) != string::npos) results += catalogElm + "\n";
}
if (results.empty()) return "No matches found\n";
return results;
} At a high-level the one But the one returns a vector of strings and the other a single string delimited by So how about consolidating them into a single method? std::vector<std::string> PropertyCatalog;
std::vector<std::string>& FGFDMExec::QueryPropertyCatalog(const string& in = "")
{
if(in.length() < 1)
return PropertyCatalog;
std::vector<std::string> results;
for (auto &catalogElm: PropertyCatalog) {
if (catalogElm.find(in) != string::npos) results.push_back(catalogElm);
}
return results;
} |
The the other difference with the current python def get_property_catalog(self, check):
"""
Retrieves the property catalog as a dictionary.
"""
catalog = {}
for item in self.query_property_catalog(check):
catalog[item] = self.get_property_value(item)
return catalog |
I actually don't mind the difference, but in the original doxygen doc it should say that the python API may differ, or the Readme page should reference the .pyx.in file as proper documentation.
Well yeah, obviously there is no guarantee for anything, in fact private / proprietary software also don't necessarily provide API guarantees. But especially open software is included in many other projects, so why introduce breaking changes? I was just asking, if there is a plan specific for these kind of functions to output maps rather than vectors. I also don't mind if there are features lacking or if the python module is incomplete. But the Readme states: "A Python module which provides the exact same features than the C++ library". That's why I thought that maybe I've done something wrong or that there may be some bugs. I just now am beginning to dig deeper, for example I realized that the FGPropagate class has almost none of the original accessors. So maybe we should include a little disclaimer that the python module still needs some work. What do you think? |
@seanmcleod as the C++ API largely predates the Python module, I am not too keen on modifying the C++ API even if, as you mentioned, it is a bit messy and inconsistent. I'd rather update the Python API. @LuFlo, as you mentioned, we are advertising that the Python module provides the exact same features than the C++ library. Sure we could argue that providing the same features and providing the same API are somewhat different and we could update the docs stating that My vote would rather be to update the Python code of |
@bcoconni @seanmcleod |
I guess I'm out voted 2-1 😉 Changing only the python API will only affect python users as opposed to my suggestion which would affect both C++ users and python users.
@agodemar I'm a bit confused because the existing C++ API already has a function that filters the catalog, i.e. std::vector<std::string> PropertyCatalog;
std::vector<std::string>& GetPropertyCatalog(void) {return PropertyCatalog;}
string FGFDMExec::QueryPropertyCatalog(const string& in)
{
string results;
for (auto &catalogElm: PropertyCatalog) {
if (catalogElm.find(in) != string::npos) results += catalogElm + "\n";
}
if (results.empty()) return "No matches found\n";
return results;
} |
ok @seanmcleod so we are almost done ;-) My fault, didn't recall |
There still seems to be some differences. For example, the python version outputs a list, instead of the string, also the python version has the R / RW indicators, unfortunately I can't test the C++ version yet, because I only have access to my mobile setup atm. I would suggest to make the check variable of def get_property_catalog(self, check=''):
"""Retrieves the property catalog as a dictionary."""
catalog = {}
for item in self.query_property_catalog(check):
property_name = item.split(" ")[0] # remove any (RW) flags
catalog[property_name] = self.get_property_value(property_name)
return catalog As far as I'm aware Cython should support optional keyword arguments. That way existing API-uses don't brake and you still have the flexibility. The trickier question is if we should also change the |
Oh yeah, then outputting a list instead of a dictionary of course, sorry for the confusion. |
…nd `FGFDMExec.get_property_catalog()` now behave like their C++ counterpart.
This issue should now be fixed by the commit 157f91e. |
…nd `FGFDMExec.get_property_catalog()` now behave like their C++ counterpart.
The problem reported in this issue is now considered fixed and the issue is closed. |
I'm submitting a ...
Describe the issue
Given following python code:
According to the C++ documentation, getPropertyDialog does not require an argument (it also wouldn't make much sense), see: https://jsbsim-team.github.io/jsbsim/classJSBSim_1_1FGFDMExec.html#ac19c4ddfeb51d183eb9e40d9a8200850
What is the current behavior?
What is the expected behavior?
Just give a list of the properties available (probably)
What is the motivation / use case for changing the behavior?
I would like to print a list of all accelerations available, without hardcoding them
Please tell us about your environment:
Other information
The text was updated successfully, but these errors were encountered: