//evaluate cell accepts a cell as an argument and checks to see if it is an expression // or just a string. if it begins with '=' it is an expression and will be evaluated as such. //otherwise the text will just be reassigned. private void EvaluateCell(Cell cell) { ss_cell c = cell as ss_cell; //cell represents an expression if (c.text[0] == '=') { //chop off '=' string expression = c.text.Substring(1); string[] ABC = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; //creates an expression tree based off of the expression ExpTree exp = new ExpTree(expression); //get a list of the variables string[] vars = exp.getVars(); foreach (string variableName in vars) { if (GetCell(variableName) == null) //does not reference an actual cell { break; } setVariable(exp, variableName); } c.SetValue(exp.Eval().ToString()); CellPropertyChanged(cell, new PropertyChangedEventArgs("value")); //trigger cellpropertychanged CellPropertyChanged(cell, new PropertyChangedEventArgs("text")); } //not an expression else { c.SetValue(c.text); CellPropertyChanged(cell, new PropertyChangedEventArgs("value")); } if (DependencyDict.ContainsKey(c.name)) { foreach (string dependentCell in DependencyDict[c.name]) { EvaluateCell(GetCell(dependentCell)); } } //else //{ // //just set the value to the text of the node passed in // c.SetValue(c.text); // //event trigger. // CellPropertyChanged(cell, new PropertyChangedEventArgs("value")); //} }
//OnPropertyChanged is what is happening when a cell's PropertyChanged event is triggered. //it simply evaluates the cell and sends the update to the next layer. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "text") { ss_cell c = sender as ss_cell; RemoveDependencies(c.name);//remove dependencies here if (c.text != "" && c.text[0] == '=') { ExpTree exp = new ExpTree(c.text.Substring(1)); MakeDependencies(c.name, exp.getVars()); } EvaluateCell(sender as Cell); } }