Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downcast issue with ColaTopologyAddon when using the C# bindings #15

Closed
foolnotion opened this issue May 1, 2015 · 1 comment
Closed

Comments

@foolnotion
Copy link

Hello,

I am using the four adaptagrams libraries on windows, via the C# bindings generated with SWIG. Basic layouting and edge routing works, however I am trying to use the topology preserving addon using the Dunnart code as an example (is there any other documentation available?). It goes like this:

layout = new ConstrainedFDLayout(rectangles, edges, idealEdgeLength, true);
// passing libcola an empty instance of this class will cause it to populate it 
// with the current topology information for nodes and edges when layout.makeFeasible() is run
var topology = new ColaTopologyAddon();
layout.setTopology(topology);
layout.makeFeasible();
layout.run();

var nodes = topology.topologyNodes; //  nodes count is zero
var routes = topology.topologyRoutes; // routes count is zero

var newTopology = (ColaTopologyAddon)layout.getTopology(); // cast exception

The issue is that the getTopology() method returns an instance of the base class TopologyAddonInterface which cannot be downcasted in C#. This sounds like a problem with the SWIG-generated bindings (after I've read some related issues here http://johnnado.com/swig-csharp-java-downcast/).

Any ideas? Thanks.

@foolnotion foolnotion changed the title Downcast issue with ColaTopologyAddon Downcast issue with ColaTopologyAddon when using the C# bindings May 1, 2015
@foolnotion
Copy link
Author

This issue can be resolved by adapting the swig interface:

%extend topology::ColaTopologyAddon {
    static topology::ColaTopologyAddon * CastToConcreteType(cola::TopologyAddonInterface *obj) {
        return dynamic_cast<topology::ColaTopologyAddon*>(obj);
    }
}

The above code inserts a static method in the ColaTopologyAddon generated class which makes use of the underlying dynamic_cast to produce the correct result. This can then be used like this:

var topologyInterface = layout.getTopology();
topology = ColaTopologyAddon.CastToConcreteType(topologyInterface);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant