Factory Class of a new stimulus core plugin

alemi's Avatar


12 Jan, 2012 03:03 PM

Hi All,

My question is about the factory class of a stimulus (core) plugin. I had written this plugin for earlier versions of MonkeyWorks, and now I am adapting it to work with recent versions of MWorks.
My stimulus class is derived from the BasicTransformStimulus class. I noticed that in the current version the BasicTransformStimulus constructor accepts an argument of the type ParameterValueMap. Therefore, I modified my stimulus constructor to accept one argument of the same type as ParameterValueMap. (I am not sure whether that was a proper choice I made for the plugin and whether it conforms with the new MWorks core architecture).
Now I am wondering what is the pattern to define a new object of my stimulus class in the factory method "createObject", given the fact that "createObject" receives an argument of the type "std::map<std::string, std::string>".

Thanks in advance,

  1. Support Staff 1 Posted by Christopher Sta... on 13 Jan, 2012 05:32 PM

    Christopher Stawarz's Avatar

    Hi Alireza,

    The current component architecture is designed to eliminate the need for custom factory classes. The correct approach is probably best explained by example, so I encourage you to take a look at my DynamicRandomDots plugin. The following two methods of the DynamicRandomDots class are key:

    static void describeComponent(ComponentInfo &info);
    explicit DynamicRandomDots(const ParameterValueMap &parameters);

    The first method defines the component type and specifies what parameters it takes. Parameters can be required or optional and can have a default value. Note that the first thing it does is call describeComponent on its base class (BasicTransformStimulus in your case), in order to add the base's parameters to the ComponentInfo object.

    The second method is the constructor, which uses the contents of the ParameterValueMap to initialize member variables. The ParameterValue class supports casting to a variety of common types (including shared_ptr<Variable>), so you can generally follow the example of DynamicRandomDots and directly initialize your member variables with parameters[PARAMETER_NAME].

    With these two methods in place, you can eliminate your custom factory and instead use the StandardStimulusFactory template. Take a look at DynamicRandomDotsPlugin::registerComponents to see how this is done.

    Hopefully this will be enough to get you started. If you need additional assistance, please let me know!


  2. Christopher Stawarz closed this discussion on 22 Feb, 2012 03:38 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

17 May, 2022 02:12 PM
16 May, 2022 03:12 PM
04 May, 2022 06:02 PM
03 May, 2022 01:30 PM
02 May, 2022 10:47 PM