1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
Project: AdunShell
Copyright (C) 2008 Michael Johnston
Author: Michael Johnston
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "AdunShell.h"
#include <StepTalk/StepTalk.h>
#include "STShell.h"
@implementation AdunShell
- (id) initWithDictionary: (NSDictionary*) dictionary
{
//Designated initialiser
return self;
}
- (void) dealloc
{
[super dealloc];
}
/***
AdController Methods
***/
- (void) coreWillStartSimulation: (AdCore*) anObject
{
//Call AdControllers implementation
//This sets up the core and configurationGenerator ivars.
[super coreWillStartSimulation: anObject];
}
- (void) runSimulation
{
//Create conversation
STEnvironmentDescription *desc;
STEnvironment *environment;
STConversation *conversation;
STShell* shell;
NSString* languageName;
environment = [STEnvironment environmentWithDefaultDescription];
languageName = [[STLanguageManager defaultManager] defaultLanguage];
/* Register basic objects: Environment, Transcript */
[environment setObject:environment forName:@"Environment"];
[environment setObject:core forName: @"Core"];
[environment setObject:[core checkpointManager] forName: @"CheckpointManager"];
[environment setObject: configurationGenerator forName: @"Simulator"];
[environment setObject: [configurationGenerator forceFields] forName: @"ForceFields"];
[environment setObject: [configurationGenerator systems] forName: @"Systems"];
[environment setObject: [NSNumber numberWithDouble: STCAL] forName: @"ConversionConstant"];
[environment includeFramework: @"AdunKernel"];
[environment includeFramework: @"MolTalk"];
[environment includeFramework: @"ULFramework"];
[environment loadModule:@"SimpleTranscript"];
[environment setCreatesUnknownObjects:YES];
/* FIXME: make this an option */
[environment setFullScriptingEnabled:YES];
conversation = [[STConversation alloc]
initWithContext:environment
language:languageName];
[conversation interpretScript: @"Transcript := SimpleTranscript sharedTranscript"];
shell = [[STShell alloc] initWithConversation:conversation];
GSPrintf(stdout, @"\nInitially available objects:\n\tEnvironment - The shell environment.\n"
@"\tSimulator - The configuration generation object.\n\tSystems - The collection of systems being simulated.\n"
@"\tForceFields - The collection of force-fields operating on the systems.\n"
@"\tCheckpointManager - Object controlling the automatic collection of data.\n"
@"\tTranscript - Object for displaying detailed strings (like a 'print' command')\n\n"
@"\nTo print a list of an objects methods use 'methodNames' e.g. ForceFields methodNames\n\n");
[shell setPrompt: @"AdunShell > "];
[environment setObject: shell forName: @"Shell"];
[shell run];
}
- (id) simulationResults
{
//Return any data sets containing the controller results
NSLog(@"Nothing to return");
return nil;
}
- (void) cleanUp
{
NSLog(@"Finished!");
//Do clean up tasks
}
- (NSString*) description
{
return @"AdunShell - Interactive shell for the AdunCore program";
}
@end
|