It is a conundrum. The reason MASON looks up the portrayal objects themselves before portrayals registered for them was efficiency: otherwise every time an object was drawn it'd be one or more hash lookups. Is this a big deal? Probably not any more.
I have made a new trial version of sim.portrayal.FieldPortrayal which permits an "alternate portrayal ordering" where the hash lookups are checked before the objects themselves are used. You could try this version and see how it goes; I'd prefer not to commit it before it's been tested.
Sean
> On Apr 14, 2021, at 6:39 PM, Alex Hughes <[log in to unmask]> wrote:
>
> Dear MASON Interest Group,
>
> I have run into difficulty with using Wrapper Portrayals.
>
> My simulation GUI takes inspiration from the Student Demo of the MASON manual, I use the "setPortrayalForAll(...)" method of my main Field Portrayal, where the portrayal being set is the LabelledPortrayal2D wrapper. To do this, I create a new sim.portrayal.simple.LabelledPortrayal2D object, passing "null" to the child argument, and "Hello World" to the label argument. Setting the child to null is necessary because the agents my model uses are their own Portrayals, extending a class that extends SimplePortrayal2D. Now up to this point, everything works, and the wrappers display as I want.
>
> However, I would like only some of the classes I use to use wrappers but using the "setPortrayalForClass(...)" method doesn't work. Looking at the documentation, it seems that this is the case because of the order of priority different portrayals take. Where the portrayal set by setPortrayalForAll is used first, then the object itself if it implements Portrayal, and the setPortrayalForClass portrayal beneath this. Is it possible to use wrappers if the object is its own portrayal?
>
> The obvious solution would be to simply not have my objects portrayal themselves, to instead decouple the portrayal from agent, and have a separate AgentPortrayal class that I then can register using the setPortrayalForClass method. I don't think this is possible, since I'm using the Physics2D framework, and my agents extend the MobileObject2D, is its own portrayal.
>
> What would be the best work around solution here? (I am new to Java and the MASON framework so could be missing an obvious solution here).
>
> Many thanks,
>
> Alex
|