JBotSim icon indicating copy to clipboard operation
JBotSim copied to clipboard

RingGenerator does not use the default node model

Open acasteigts opened this issue 4 years ago • 6 comments

When executing the following code:

Topology topology = new Topology();
topology.setDefaultNodeModel(MyNode.class);
new RingGenerator(N).generate(topology);

the created nodes are not of type MyNode, but of class Node.

It is possible that the other generators have the same problem.

acasteigts avatar Nov 03 '21 17:11 acasteigts

@acasteigts, as you mentioned in another thread, TopologyGenerators.generateRing() uses the proper model.

The "issue" comes from the fact that the RingGenerator, as any child of AbstractGenerator, separately stores a nodeClass which defaults on Node.class. It is modified via AbstractGenerator.setNodeClass() which is properly used by TopologyGenerators.generateRing().

I am not sure if we really want to remove the AbstractGenerator's capability to use "non-default".

remikey avatar Nov 04 '21 20:11 remikey

This being said, AbstractGenerator could be notified rather easily, to try and get the Topology's default node model if none has been set using AbstractGenerator.setNodeClass().

remikey avatar Nov 04 '21 20:11 remikey

I suppose we could postpone the decision on this issue. Moreover, the following "workaround" should work:

RingGenerator generator = new RingGenerator(nbNodes);
[...]
generator.setNodeClass(RedNode.class);
generator.generate(topology);

What do you think?

remikey avatar Nov 04 '21 20:11 remikey

OK to postpone the decision on RingGenerator and use TopologyGenerators.generateRing() instead for some time.

Now, I feel like setNodeClass() in AbstractGenerator is definitely redundant with setDefaultNodeModel() in Topology. Note that several models can also be registered using various names directly in the Topology.

I do not mind keeping setNodeClass() in AbstractGenerator so long as the default node model of the Topology is taken into account without any additional action from the user.

acasteigts avatar Nov 13 '21 16:11 acasteigts

I have made a proposition on branch fix/110-ringgenerator-default-node. I will try and create a PR, for practice purpose.

remikey avatar Nov 18 '21 19:11 remikey

Looks good to me. Priority was given to the generator's own node model (if any), over the one of the topology, which makes sense so long as we keep both ways of using models.

acasteigts avatar Nov 19 '21 14:11 acasteigts