/**
 * Called when the FitnessFunction is attached to the System. 
 */
void ScriptedFitnessFunction::attachToSystem() {
	TRACE("ScriptedFitnessFunction::attachToSystem");

	ControllerFitnessFunction::attachToSystem();

	if(mScriptFileNameArg != 0) {
		int numberOfEntries = mScriptFileNameArg->getNumberOfEntries();
		for(int i = 0; i < numberOfEntries; ++i) {
			QStringList args = mScriptFileNameArg->getEntryParameters(i);
			if(args.size() != 2) {
				continue;
			}
			if(args.at(0) == getName()) {
				mScriptFileName->set(args.at(1));

				if(!loadScriptCode(false)) {
					continue;
				}
				break;
			}
		}
	}

	mScriptFileName->addValueChangedListener(this);

	EventManager *em = Core::getInstance()->getEventManager();
	mSimEnvironmentChangedEvent = em->registerForEvent(
					EvolutionConstants::EVENT_PHYSICS_ENVIRONMENT_CHANGED,
					this);
}
void PluginGeneratorGUI::menuSelection( QAction* act)
{
	if (act != NULL)
	{
		int indact = act->data().toInt();
		switch(indact)
		{
			case MN_EXECUTECODE:
			{
				/*FilterGeneratorTab* tb = tab(tabs->currentIndex());
				if (tb != NULL)
				{
					QScriptValue result = tb->executeCode(doc);
					emit scriptCodeExecuted(result);
				}
				else
					throw MeshLabException("System Error: A FilterGeneratorTab object has been expected.");*/
				executeCurrentCode();
				break;
			}
			case MN_LOADCODE:
			{
				loadScriptCode();
				break;
			}
			case MN_SAVECODE:
			{
				saveScriptCode();
				break;
			}
			case MN_ADDFILTER:
			{
				addNewFilter();
				break;
			}
			case MN_REMOVEFILTER:
			{
				removeFilter();
				break;
			}
			case MN_NEWXMLPLUGIN:
			{
				newXMLPlugin();
				break;
			}
			case MN_SAVEXMLPLUGIN:
			{
				saveXMLPlugin();
				break;
			}
			case MN_SAVEASXMLPLUGIN:
			{
				saveAsXMLPlugin();
				break;
			}
			case MN_LOADXMLPLUGIN:
			{
				loadXMLPlugin();
				break;
			}
			case MN_GETHISTORY:
			{
				importHistory();
				break;
			}
			case MN_INSERTPLUGINMESHLAB:
			{
				insertPluginInMeshLab();
				break;
			}
		}
	}
}