/// <summary> /// Provides the graph associated to the namable /// </summary> /// <param name="namable"></param> /// <returns></returns> public static Graph createGraph(Utils.INamable namable, Parameter parameter) { Graph retVal = null; Functions.Function function = namable as Functions.Function; if (function != null) { retVal = function.createGraphForParameter(new Interpreter.InterpretationContext(), parameter); } if (retVal == null) { Values.IValue value = namable as Values.IValue; if (value != null) { retVal = createGraph(Function.getDoubleValue(value), parameter); } } return(retVal); }
/// <summary> /// Provides the value associated to this Expression /// </summary> /// <param name="context">The context on which the value must be found</param> /// <returns></returns> public override Values.IValue GetValue(InterpretationContext context) { Values.IValue retVal = null; ExplanationPart previous = SetupExplanation(); Functions.Function function = getFunction(context); if (function != null) { long start = System.Environment.TickCount; Dictionary <Variables.Actual, Values.IValue> parameterValues = AssignParameterValues(context, function, true); List <Parameter> parameters = GetPlaceHolders(function, parameterValues); if (parameters == null) { retVal = function.Evaluate(context, parameterValues); if (retVal == null) { AddError("Call " + function.Name + " ( " + ParameterValues(parameterValues) + " ) returned nothing"); } } else if (parameters.Count == 1) // graph { int token = context.LocalScope.PushContext(); context.LocalScope.setGraphParameter(parameters[0]); Functions.Graph graph = function.createGraphForParameter(context, parameters[0]); context.LocalScope.PopContext(token); if (graph != null) { retVal = graph.Function; } else { AddError("Cannot create graph on Call " + function.Name + " ( " + ParameterValues(parameterValues) + " )"); } } else // surface { Functions.Surface surface = function.createSurfaceForParameters(context, parameters[0], parameters[1]); if (surface != null) { retVal = surface.Function; } else { AddError("Cannot create surface on Call " + function.Name + " ( " + ParameterValues(parameterValues) + " )"); } } long stop = System.Environment.TickCount; long span = (stop - start); function.ExecutionTimeInMilli += span; function.ExecutionCount += 1; if (explain) { CompleteExplanation(previous, function.Name + " ( " + ParameterValues(parameterValues) + " ) returned " + explainNamable(retVal) + "\n"); } } else { AddError("Cannot find function " + ToString()); } return(retVal); }