iut-ibk / DynaMind-ToolBox

DynaMind-ToolBox
www.dance4water.org
GNU General Public License v2.0
9 stars 6 forks source link

System API Python #205

Closed christianurich closed 10 years ago

christianurich commented 11 years ago

I'm not sure is the new system API works in Python since it heavily relies on type casting and the mforeach macro has this been tested?

zacharias2k commented 11 years ago

Makros should not make any problem, since they more or less just exchange code fragments. I don't see any problem here. Btw mforeach is just a derivative of foreach (from Qt) - it's basically the same with minior changes.

I don't see the issue with new API regarding type casting either, it does NOT rely heavily on type casting? The only type-casting taking place in the new API is when working with parameters - but the API didn't change there for python (see pydynamind.i). SWIG compiles perfectly.

In any case: why don't we just try it out?

christianurich commented 11 years ago

I ask because uuids should run out and the python API just supports access with uuids. The new things are not working yet. (Errors when try to access an element ). Please fix and than I continue testing

If I want to access a element as face I have to cast it but maybe I use it wrong.

mforeach (DM::Component * c, city->getAllComponentsInView(this->inputView)) {
        DM::System workingSys;
        DM::Face * f = static_cast<DM::Face *> (c);

And this doesn't work at the moment. If I want to use getAllComponentsInView I get an error

>>> sys.getAllComponentsInView(pydynamind.View("T", pydynamind.NODE,pydynamind.READ)
... )
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "pydynamind.py", line 502, in getAllComponentsInView
    return _pydynamind.System_getAllComponentsInView(self, *args)
TypeError: in method 'System_getAllComponentsInView', argument 2 of type 'View const &'
>>> 
zacharias2k commented 11 years ago

The usage is correct, but please use dynamic_cast, it returns NULL if the cast is not possible. static_cast can lead to access violations if the type does not match. A very elaborate way would be

mforeach (DM::Component * c, city->getAllComponentsInView(this->inputView)) 
    if(DM::Face * f = dynamic_cast<DM::Face *> (c)) {
        DM::System workingSys;

In this case non-face objects just get ignored, instead of knocking out the whole application via access violation.

Back to the main issue: python reports not an issue while casting the component, but rather using a constant reference. In contrast to getAllComponentsInView, getUUIDsOfComponentsInView does use a normal view object.

I will have a look if i can fix this, as const & are really state of the art when it comes to performant code.

Update: swig docu says const & should work perfectly ... :-/

zacharias2k commented 11 years ago

Just an idea: instead of

sys.getAllComponentsInView(pydynamind.View("T", pydynamind.NODE,pydynamind.READ)

try

v = pydynamind.View("T", pydynamind.NODE,pydynamind.READ)
sys.getAllComponentsInView(v)
christianurich commented 11 years ago

Had that first and is also not working

zacharias2k commented 11 years ago

try https://github.com/iut-ibk/DynaMind/commit/2352cbd79b1ec96fed00a93f2b8c665d031b1f69

if not working, try getEdge(uuid, uuid) & getUUIDsOfComponentsInView if a similar error occurs. If yes, please submit the error-msg.