/*
Copyright 2010
Matthias Ehmann,
Michael Gerhaeuser,
Carsten Miller,
Bianca Valentin,
Alfred Wassermann,
Peter Wilfahrt
This file is part of JSXGraph.
JSXGraph is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JSXGraph 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with JSXGraph. If not, see .
*/
/**
* @param {String} string A string containing construction(s) in JSXGraph Construction Syntax.
* @param {String} mode Possible values seem are "normal" or "macro"
* @param {Array} params Parameters, only used in macro mode
* @param {Array} paraIn Parameters, only used in macro mode
* @param {String} macroName Name of the macro, only used in macro mode
* @type object
* @return An object consisting of several arrays (lines, circles, points, angles, ...) where the created elements are stored.
*/
JXG.Board.prototype.construct = function(string, mode, params, paraIn, macroName) {
var splitted, i, j, output = {}, objName, defElements, obj, type, possibleNames, tmp, noMacro, k,l, pattern, createdNames, found,
mac, prop, propName, propValue, attributes;
if(!JXG.exists(mode)) {
mode = "normal";
}
else { // mode = 'macro'
createdNames = [];
}
output.lines = [];
output.circles = [];
output.points = [];
output.intersections = [];
output.angles = [];
output.macros = [];
output.functions = [];
output.texts = [];
output.polygons = [];
if(string.search(/\{/) != -1) { // Macros finden! Innerhalb der {} darf nicht am ; getrennt werden. Noch nicht getestet: mehrere Makros hintereinander in einem construct.
tmp = string.match(/\{/);
tmp = tmp.length;
l=0;
for(j=0; j 0) {
prop = false;
if(splitted[i].search(/=/) != -1) {
objName = splitted[i].split('=');
propValue = objName[1];
propValue = propValue.replace (/^\s+/, '').replace (/\s+$/, '');
if(objName[0].search(/\./) != -1) {
prop = true;
objName = objName[0].split('.');
propName = objName[objName.length-1];
propName = propName.replace (/^\s+/, '').replace (/\s+$/, '');
objName.pop();
objName = objName.join(".");
if(mode == 'macro') {
for(j=0; j
* <macro-name> = Macro(A, B, C) { ; ...; }
* and adds it as a macro so it can be used in the JSXGraph Construction Syntax.
* @param {String} string A string like the one in the methods description.
* @see #construct
*/
JXG.Board.prototype.addMacro = function(string) {
var defHead, defBody, defName = '', i;
string.match(/(.*)\{(.*)\}/);
defHead = RegExp.$1;
defBody = RegExp.$2;
if(defHead.search(/=/) != -1) {
defHead.match(/\s*(\S*)\s*=.*/);
defName = RegExp.$1;
defHead = (defHead.split('='))[1];
}
defHead.match(/Macro\((.*)\)/);
defHead = RegExp.$1;
defHead = defHead.split(',');
for(i=0; i < defHead.length; i++) {
defHead[i].match(/\s*(\S*)\s*/);
defHead[i] = RegExp.$1;
}
if(this.definedMacros == null) {
this.definedMacros = {};
this.definedMacros.macros = [];
}
this.definedMacros.macros.push([defName, defHead, defBody]);
if(defName != '') {
this.definedMacros.defName = this.definedMacros.macros[this.definedMacros.macros.length-1];
}
};