void CreateNode(object key) { BaseNode node = null; switch ((NodeType)key) { case NodeType.InputNode: node = new InputNode(this, _curevent.mousePosition); break; case NodeType.OutputNode: node = new OutputNode(this, _curevent.mousePosition); break; case NodeType.CalcNode: node = new CalcNode(this, _curevent.mousePosition); break; case NodeType.CompNode: node = new CompNode(this, _curevent.mousePosition); break; } if (node != null) { _nodes.Add(node); } }
static public CalcNode FromChar(char c) { CalcNode cn = new CalcNode(NodeType.Operator); cn.Value = c; return(cn); }
static public CalcNode FromDouble(double d) { CalcNode cn = new CalcNode(NodeType.Num); cn.Num = d; return(cn); }
static bool ContainsOrEqual(CalcCalculationManager mgr, CalcLocalIdentity id1, CalcLocalIdentity id2) { CalcLocalIdentityExtension.CompareResult result; CalcLocalIdentityExtension.CompareResult result2; if (id2.TryCompareTo(id1, out result, out result2)) { CalcNode objA = mgr.Graph.GetNode(id2); CalcExpression expression = mgr.GetExpression(id2); if (expression == null) { return(false); } if ((!object.ReferenceEquals(objA, null) && (objA.OwnerNode != null)) && (expression is CalcSharedExpression)) { return(false); } if (((id2 is CalcRangeIdentity) && (((result == CalcLocalIdentityExtension.CompareResult.Great_Intersected) || (result == CalcLocalIdentityExtension.CompareResult.Less_Intersected)) || (result == CalcLocalIdentityExtension.CompareResult.Contains))) && (((result2 == CalcLocalIdentityExtension.CompareResult.Great_Intersected) || (result2 == CalcLocalIdentityExtension.CompareResult.Less_Intersected)) || (result2 == CalcLocalIdentityExtension.CompareResult.Contains))) { if (!(mgr.GetExpression(id2) is CalcSharedExpression)) { throw new InvalidOperationException(ResourceStrings.FormulaChangePartOfArrayFormulaError); } return(false); } if (((result == CalcLocalIdentityExtension.CompareResult.Contained) || (result == CalcLocalIdentityExtension.CompareResult.Equal)) && ((result2 == CalcLocalIdentityExtension.CompareResult.Contained) || (result2 == CalcLocalIdentityExtension.CompareResult.Equal))) { return(true); } } return(false); }
/// <summary> /// Context Click selection. Here you'll need to register your own using a string identifier /// </summary> public void ContextCallback(object obj) { switch (obj.ToString()) { case "calcNode": CalcNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); //CalcNode calcNode = CalcNode.Create (new Rect (mousePos.x, mousePos.y, 200, 100)); break; case "inputNode": InputNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50)); //InputNode inputNode = InputNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50)); break; case "displayNode": DisplayNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50)); //DisplayNode displayNode = DisplayNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50)); break; case "dialNode": DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); //DialNode dialNode = DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); break; case "deleteNode": Node node = NodeAtPosition(mousePos); if (node != null) { nodeCanvas.nodes.Remove(node); node.OnDelete(); } break; } }
public void RemoveSheet(IList sources, ICalcSource replacedSource) { ICalcSource currentSource = this.Manager.Source; Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > dictionary = new Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> >(); foreach (object obj2 in sources) { ICalcSource source = obj2 as ICalcSource; if (source != null) { CalcCalculationManager manager = this.Manager.Service.GetCalculationManager(source, null, true); if (manager != null) { foreach (CalcLocalIdentity identity in manager.Graph.GetAllSheetRangeIdentities()) { CalcNode node = manager.Graph.GetNode(identity); if (node.Precedents != null) { using (List <CalcNode> .Enumerator enumerator3 = node.Precedents.GetEnumerator()) { while (enumerator3.MoveNext()) { if (enumerator3.Current.Source == currentSource) { Dictionary <CalcLocalIdentity, CalcExpression> dictionary2; if (!dictionary.TryGetValue(manager, out dictionary2)) { dictionary2 = new Dictionary <CalcLocalIdentity, CalcExpression>(); dictionary[manager] = dictionary2; } dictionary2[identity] = manager.GetExpression(identity); } } } } } } } } RemoveSheetVisitor visitor = new RemoveSheetVisitor(currentSource, replacedSource); foreach (KeyValuePair <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > pair in dictionary) { CalcCalculationManager mgr = pair.Key; foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in pair.Value) { int num; int num2; int num3; int num4; mgr.ClearExpression(pair2.Key); FormulaOperatorHelper.Identity2Indexs(pair2.Key, out num, out num2, out num3, out num4); CalcExpression expr = visitor.Visit(pair2.Value, num, num2); CalcExpressionHelper.SetExpression(mgr, pair2.Key, expr, true); mgr.Invalidate(pair2.Key, false); } } }
/// <summary> /// 将字符串解析为中序表达式 /// </summary> /// <param name="str">要解析的字符串</param> /// <returns>一个中序表达式结构体</returns> static public MiddleExpression TurnToMiddle(string str) { string s = str.Replace(" ", ""); MiddleExpression m = new MiddleExpression(); CalcNode LastNode = new CalcNode(NodeType.Num); char[] cs = s.ToCharArray(); LastNode = null; foreach (char c in cs) { if (c >= 48 && c <= 57) { if (LastNode != null && LastNode.Type == NodeType.Num) { LastNode.Num = LastNode.Num * 10 + c - 48; } else { LastNode = CalcNode.FromDouble(c - 48.0); m.Add(LastNode); } } else if (Operators.Contains(c)) { LastNode = CalcNode.FromChar(c); m.Add(LastNode); } else { if (LastNode != null && LastNode.Type == NodeType.Variable) { LastNode.Value += c; } else { LastNode = new CalcNode(NodeType.Variable); LastNode.Value = c.ToString(); m.Add(LastNode); } } } // 检查是否有计算节点是函数 foreach (CalcNode node in m) { if (node.Type == NodeType.Variable) { if (Functions.Contains(node.Value)) { node.Type = NodeType.Function; } } } return(m); }
static void GetDependentsFromulas(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, ChangingContext context, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, Dictionary <CalcLocalIdentity, CalcExpression> formulas, int fromColumnCount, bool offsetSelf, bool updataDependens) { int rowOffset = toRow - fromRow; int columnOffset = toColumn - fromColumn; CalcLocalIdentity id = FormulaOperatorHelper.Indexs2Identity(fromRow, fromColumn, (fromRow + fromRowCount) - 1, (fromColumn + fromColumnCount) - 1); CellRange fromRange = new CellRange(fromRow, fromColumn, fromRowCount, fromColumnCount); MoveVisitor visitor = new MoveVisitor(fromRange, rowOffset, columnOffset, 0x7fffffff, 0x7fffffff, true, targetMgr.Source, sourceMgr != targetMgr, null, !offsetSelf); sourceMgr.Source.GetEvaluatorContext(new CalcCellIdentity(toRow, toColumn)); new Dictionary <CalcIdentity, CalcIdentity>(); CalcNode node = sourceMgr.Graph.GetNode(id); IFormulaOperatorSource mgr = new SpreadCalcAxialManager.FormulaOperatorSource(sourceMgr); List <CalcLocalIdentity> list = new List <CalcLocalIdentity>(); HashSet <CalcNode> arrayFormulaNodes = new HashSet <CalcNode>(); if ((node != null) && updataDependens) { list = FormulaOperatorHelper.GetChangedDependents(mgr, context, node, arrayFormulaNodes, formulas, null); } if (offsetSelf && updataDependens) { foreach (CalcIdentity identity2 in sourceMgr.Graph.GetAllLocalIdentities()) { int num3; int num4; int num5; int num6; FormulaOperatorHelper.Identity2Indexs(identity2, out num3, out num4, out num5, out num6); if ((((fromRow == -1) || (num3 >= fromRow)) && ((fromRow == -1) || (num5 < (fromRow + fromRowCount)))) && (((fromColumn == -1) || (num4 >= fromColumn)) && ((fromColumn == -1) || (num6 < (fromColumn + fromColumnCount))))) { CalcNode node2 = sourceMgr.Graph.GetNode(identity2); if ((node2 != null) && (node2.Dependents != null)) { list.AddRange((IEnumerable <CalcLocalIdentity>)FormulaOperatorHelper.GetChangedDependents(mgr, context, node2, arrayFormulaNodes, formulas, null)); } } } visitor.CurrentCalcSource = sourceMgr.Source; foreach (CalcLocalIdentity identity3 in list) { int num7; int num8; int num9; int num10; CalcExpression expr = formulas[identity3]; FormulaOperatorHelper.Identity2Indexs(identity3, out num7, out num8, out num9, out num10); expr = visitor.Visit(expr, num7, num8); formulas[identity3] = expr; } } FormulaOperatorHelper.UpdataInvalidFormula(mgr, context, visitor); }
static void GetInvalidFormulas(IFormulaOperatorSource mgr, ChangingContext context) { HashSet <CalcNode> arrayFormulaNodes = new HashSet <CalcNode>(); foreach (CalcLocalIdentity identity in context.ChangingIdentities.Keys) { CalcNode node = mgr.GetNode(identity); if ((node != null) && (node.Dependents != null)) { GetChangedDependents(mgr, context, node, arrayFormulaNodes, null, null); } } }
public override Node Create(Vector2 pos) { CalcNode node = CreateInstance <CalcNode> (); node.name = "Calc Node"; node.rect = new Rect(pos.x, pos.y, 200, 100); node.m_Value1 = new FloatRemap(0, -1, 1); node.m_Value2 = new FloatRemap(0, -1, 1); node.CreateOutput("Output 1", "Float"); return(node); }
public override Node Create(Vector2 pos) { CalcNode node = CreateInstance <CalcNode> (); node.name = "Calc Node"; node.rect = new Rect(pos.x, pos.y, 200, 100); node.CreateInput("Input 1", "Float"); node.CreateInput("Input 2", "Float"); node.CreateOutput("Output 1", "Float"); return(node); }
static int Rank(CalcNode node) { if (node.Type == NodeType.Operator) { return(Rank(node.Operater)); } else if (node.Type == NodeType.Function) { return(2); } else { return(-1); } }
public static CalcNode Create(Rect NodeRect) { // This function has to be registered in Node_Editor.ContextCallback CalcNode node = ScriptableObject.CreateInstance <CalcNode> (); node.name = "Calc Node"; node.rect = NodeRect; NodeInput.Create(node, "Input 1", typeof(float)); NodeInput.Create(node, "Input 2", typeof(float)); NodeOutput.Create(node, "Output 1", typeof(float)); node.Init(); return(node); }
private void Initialize() { // Initialize the VISITED set and OPEN set by inserting // the start point CalcNode initialVisited = new CalcNode(); initialVisited.Node = this.start; initialVisited.Open = 1; initialVisited.Closed = 0; initialVisited.Parent = null; initialVisited.g = 0; if (goal != null) { initialVisited.h = manhattanHeuristic(start, goal, graph, m_Unit); initialVisited.f = (alpha * initialVisited.g + (1 - alpha) * initialVisited.h) / Math.Max(alpha, 1 - alpha); } visited.Add(start.nodeToString(), initialVisited); open.Push(initialVisited); }
static public MiddleExpression TurnToMiddle(string str) { string s = str.Replace(" ", ""); MiddleExpression m = new MiddleExpression(); CalcNode LastNode = new CalcNode(NodeType.Num); char[] cs = s.ToCharArray(); LastNode = null; foreach (char c in cs) { if (c >= 48 && c <= 57) { if (LastNode != null && LastNode.Type == NodeType.Num) { LastNode.Num = LastNode.Num * 10 + c - 48; } else { LastNode = CalcNode.FromDouble(c - 48.0); m.Add(LastNode); } } else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '%' || c == '^' || c == '(' || c == ')') { LastNode = CalcNode.FromChar(c); m.Add(LastNode); } else { LastNode = new CalcNode(NodeType.Variable); LastNode.Value = c; m.Add(LastNode); } } return(m); }
private Node mulExp() { EnterRule_mulExp(); EnterRule("mulExp", 5); TraceIn("mulExp", 5); Node node = default(Node); IToken op = default(IToken); Node lhs = default(Node); Node rhs = default(Node); Node unaryExp6 = default(Node); try { DebugEnterRule(GrammarFileName, "mulExp"); DebugLocation(53, 2); try { // KnightyCode.g:54:3: (lhs= unaryExp op= ( '*' | '/' ) rhs= mulExp | unaryExp ) int alt6=2; try { DebugEnterDecision(6, false); switch (input.LA(1)) { case Number: { int LA6_2 = input.LA(2); if ((EvaluatePredicate(synpred8_KnightyCode_fragment))) { alt6 = 1; } else if ((true)) { alt6 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 6, 1, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case If: { int LA6_2 = input.LA(2); if ((EvaluatePredicate(synpred8_KnightyCode_fragment))) { alt6 = 1; } else if ((true)) { alt6 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 6, 2, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case While: { int LA6_2 = input.LA(2); if ((EvaluatePredicate(synpred8_KnightyCode_fragment))) { alt6 = 1; } else if ((true)) { alt6 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 6, 3, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case 12: { int LA6_2 = input.LA(2); if ((EvaluatePredicate(synpred8_KnightyCode_fragment))) { alt6 = 1; } else if ((true)) { alt6 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 6, 4, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; default: { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 6, 0, input, 1); DebugRecognitionException(nvae); throw nvae; } } } finally { DebugExitDecision(6); } switch (alt6) { case 1: DebugEnterAlt(1); // KnightyCode.g:54:6: lhs= unaryExp op= ( '*' | '/' ) rhs= mulExp { DebugLocation(54, 9); PushFollow(Follow._unaryExp_in_mulExp238); lhs=unaryExp(); PopFollow(); if (state.failed) return node; DebugLocation(54, 21); op=(IToken)input.LT(1); if (input.LA(1)==14||input.LA(1)==17) { input.Consume(); state.errorRecovery=false;state.failed=false; } else { if (state.backtracking>0) {state.failed=true; return node;} MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(54, 37); PushFollow(Follow._mulExp_in_mulExp252); rhs=mulExp(); PopFollow(); if (state.failed) return node; DebugLocation(54, 45); if (state.backtracking == 0) { node = new CalcNode( (op!=null?op.Text:null), lhs, rhs ); } } break; case 2: DebugEnterAlt(2); // KnightyCode.g:55:5: unaryExp { DebugLocation(55, 5); PushFollow(Follow._unaryExp_in_mulExp260); unaryExp6=unaryExp(); PopFollow(); if (state.failed) return node; DebugLocation(55, 14); if (state.backtracking == 0) { node = unaryExp6; } } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("mulExp", 5); LeaveRule("mulExp", 5); LeaveRule_mulExp(); } DebugLocation(56, 2); } finally { DebugExitRule(GrammarFileName, "mulExp"); } return node; }
void ContextCallback(object obj) { string clb = obj.ToString(); if (clb.Equals("inputNode")) { InputNode inputNode = new InputNode(); inputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150); windows.Add(inputNode); } else if (clb.Equals("outputNode")) { OutputNode outputNode = new OutputNode(); outputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 100); windows.Add(outputNode); } else if (clb.Equals("calcNode")) { CalcNode calcNode = new CalcNode(); calcNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150); windows.Add(calcNode); } else if (clb.Equals("compNode")) { ComparisonNode compNode = new ComparisonNode(); compNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 200); windows.Add(compNode); } else if (clb.Equals("makeTransition")) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { selectedNode = windows[selectIndex]; makeTransitionMode = true; } } else if (clb.Equals("deleteNode")) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { BaseNode selNode = windows[selectIndex]; windows.RemoveAt(selectIndex); // inform each basenode in the window that this specific node was deleted. foreach (BaseNode n in windows) { n.NodeDeleted(selNode); } } } }
static void GetChangingIds(IFormulaOperatorSource mgr, bool row, ChangingContext context, OperatorExpressionVisistor visitor, bool updateDependents) { foreach (CalcLocalIdentity identity in mgr.GetAllLocalIdentities()) { CalcIdentity id = identity; if (identity is ConditionalGraph.ConditionalIdentity) { ConditionalGraph.ConditionalIdentity identity3 = identity as ConditionalGraph.ConditionalIdentity; id = (identity3.OldActualIdentity != null) ? identity3.OldActualIdentity : identity3.ActualIdentity; } CalcNode node = mgr.GetNode(id); if ((node == null) || (node.OwnerNode == null)) { CalcCellIdentity identity4 = id as CalcCellIdentity; CalcRangeIdentity identity5 = id as CalcRangeIdentity; CalcExpression expression = mgr.GetExpression(identity); CalcLocalIdentity identity6 = null; int oldStart = -2147483648; int oldEnd = -2147483648; int newEnd = -2147483648; if (identity4 != null) { oldStart = row ? identity4.RowIndex : identity4.ColumnIndex; } else if (identity5 != null) { if (identity5.IsFullRow && identity5.IsFullColumn) { identity6 = identity; oldStart = 0; } else if ((identity5.IsFullRow && !row) || (identity5.IsFullColumn && row)) { if (node != null) { context.InvalidateFormula(mgr, identity5); } if (((node == null) || (node.Dependents == null)) || ((node.Dependents.Count == 0) || !updateDependents)) { continue; } InvalidateNode(mgr, context, node); } else { oldStart = row ? identity5.RowIndex : identity5.ColumnIndex; oldEnd = row ? ((identity5.RowIndex + identity5.RowCount) - 1) : ((identity5.ColumnIndex + identity5.ColumnCount) - 1); } } if (oldStart != -2147483648) { if (identity6 == null) { int num2; if (identity5 != null) { visitor.GetRangeOffset(oldStart, oldEnd, out num2, out newEnd); if ((num2 == oldStart) && (newEnd == oldEnd)) { continue; } if ((num2 == -2147483648) || (newEnd == -2147483648)) { expression = null; } else if (identity5.IsFullRow && row) { identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, true); } else if (identity5.IsFullColumn && !row) { identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, false); } else if (row) { identity6 = new CalcRangeIdentity(num2, identity5.ColumnIndex, (newEnd - num2) + 1, identity5.ColumnCount); } else { identity6 = new CalcRangeIdentity(identity5.RowIndex, num2, identity5.RowCount, (newEnd - num2) + 1); } } else if (identity4 != null) { visitor.GetCellOffset(oldStart, out num2); if (num2 == oldStart) { continue; } if (num2 == -2147483648) { expression = null; } else if (identity4 != null) { identity6 = row ? new CalcCellIdentity(num2, identity4.ColumnIndex) : new CalcCellIdentity(identity4.RowIndex, num2); } } } context.ChangingIdentities[identity] = identity; if (expression != null) { identity6 = (identity is ConditionalGraph.ConditionalIdentity) ? identity : identity6; context.ChangedFormulas[identity6] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expression); } } } } }
static void InvalidateNode(IFormulaOperatorSource mgr, ChangingContext context, CalcNode node) { using (Dictionary <CalcNode, CalcNode> .Enumerator enumerator = node.Dependents.GetEnumerator()) { while (enumerator.MoveNext()) { CalcLocalIdentity id = enumerator.Current.Key.Id as CalcLocalIdentity; if ((id != null) && (node.Source == mgr.Source)) { if (!context.ChangingIdentities.ContainsKey(id) && (mgr.GetExpression(id) != null)) { context.InvalidateFormula(mgr, id); } } else if (id != null) { IFormulaOperatorSource externalManager = mgr.GetExternalManager(node.Source); if ((externalManager != null) && (externalManager.GetExpression(id) != null)) { context.InvalidateFormula(externalManager, id); } } } } }
static public PolishExpression TurnToPolish(MiddleExpression f) { Stack <CalcNode> S1 = new Stack <CalcNode>(); Stack <CalcNode> S2 = new Stack <CalcNode>(); S1.Push(new CalcNode(NodeType.Operator)); PolishExpression e = new PolishExpression(); foreach (CalcNode node in f) { if (node.Type == NodeType.Operator) { if (node.Value == '(') { S1.Push(node); } else if (node.Value == ')') { CalcNode LastNode = S1.Pop(); while (LastNode.Value != '(') { S2.Push(LastNode); LastNode = S1.Pop(); } } else { if (S1.Peek().Value == '(') { S1.Push(node); } else { int rank = Rank(node.Value); int Toprank = Rank(S1.Peek().Value); if (rank <= Toprank) { while (!(S2.Peek().Value == '(' || Rank(S1.Peek().Value) < rank)) { S2.Push(S1.Pop()); } } S1.Push(node); } } } else { S2.Push(node); } } if (S1.Count != 0) { while (S1.Count > 1) { S2.Push(S1.Pop()); } } PolishExpression p = new PolishExpression(); while (S2.Count > 0) { p.Push(S2.Pop()); } return(p); }
//returns if the path is found; variable path contains the path public bool findPath() { while (open.Count > 0) { // Find the best node (lowest f). After sorting it // will be the last element in the array, and we // remove it from OPEN and also update its open flag. //open = open.sortOn('f', Array.DESCENDING | Array.NUMERIC); open = SortStack <CalcNode>(open); CalcNode best = open.Pop(); best.Open = 0; // If we find the goal, we're done. if (goal.Equals(best.Node)) { reconstructPath(); return(true); } // Add the neighbors of this node to OPEN ILocation[] next = graph.GetNodeNeighbors(best.Node); for (int j = 0; j != next.GetLength(0); j++) { float c = cost(best.Node, next[j], m_Unit); if (float.IsInfinity(c)) { continue; // cannot pass } // Every node needs to be in VISITED; be sure it's there. CalcNode e; if (!visited.TryGetValue(next[j].nodeToString(), out e)) { e = new CalcNode(); e.Node = next[j]; e.Open = 0; e.Closed = 0; e.Parent = null; e.g = float.PositiveInfinity; e.h = 0; e.f = 0; visited.Add(next[j].nodeToString(), e); } //if the movement-range of the unit is already used up we cannot reach target if ((this.m_Unit.GetRange() - (best.g + c)) < 0f) { continue; } // We'll consider this node if the new cost (g) is // better than the old cost. The old cost starts // at Infinity, so it's always better the first // time we see this node. if (best.g + c < e.g) { if (e.Open <= 0) { e.Open = 1; open.Push(e); } e.g = best.g + c; e.h = manhattanHeuristic(e.Node, goal, graph, m_Unit); e.f = (alpha * e.g + (1 - alpha) * e.h) / Math.Max(alpha, 1 - alpha); e.Parent = best; } } } return(false); }
void ContextCallback(object obj) { string clb = obj.ToString(); bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < _windows.Count; i++) { if (_windows[i].WindowRect.Contains(_mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } switch (clb) { case "inputNode": InputNode inputNode = new InputNode(); inputNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150); _windows.Add(inputNode); break; case "outputNode": OutputNode outputNode = new OutputNode(); outputNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 100); _windows.Add(outputNode); break; case "calcNode": CalcNode calcNode = new CalcNode(); calcNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150); _windows.Add(calcNode); break; case "compNode": ComparisonNode compNode = new ComparisonNode(); compNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150); _windows.Add(compNode); break; case "makeTransition": if (clickedOnWindow) { _selectedNode = _windows[selectIndex]; _makeTransitionMode = true; } break; case "deleteNode": if (clickedOnWindow) { BaseNode selectedNode = _windows[selectIndex]; _windows.RemoveAt(selectIndex); foreach (BaseNode baseNode in _windows) { baseNode.NodeDeleted(selectedNode); } } break; } }
public static List <CalcLocalIdentity> GetChangedDependents(IFormulaOperatorSource mgr, ChangingContext context, CalcNode node, HashSet <CalcNode> arrayFormulaNodes, Dictionary <CalcLocalIdentity, CalcExpression> formulas1 = null, Dictionary <CalcLocalIdentity, CalcExpression> formulas2 = null) { List <CalcLocalIdentity> list = new List <CalcLocalIdentity>(); if (node.Dependents != null) { CalcNode myOwnerNode; foreach (CalcNode ownerNode in node.Dependents.Keys) { myOwnerNode = ownerNode; if (ownerNode.OwnerNode != null) { myOwnerNode = ownerNode.OwnerNode; if (arrayFormulaNodes.Contains(myOwnerNode) || (mgr.GetExpression(myOwnerNode.Id as CalcLocalIdentity) is CalcSharedExpression)) { continue; } arrayFormulaNodes.Add(myOwnerNode); } CalcLocalIdentity id = myOwnerNode.Id as CalcLocalIdentity; if ((id != null) && (myOwnerNode.Source == mgr.Source)) { if (!context.ChangingIdentities.ContainsKey(id)) { CalcExpression expression = mgr.GetExpression(id); if (expression != null) { if (((formulas1 != null) && formulas1.ContainsKey(id)) || ((formulas2 != null) && formulas2.ContainsKey(id))) { list.Add(id); } else { context.ChangedFormulas[id] = new Tuple <CalcLocalIdentity, CalcExpression>(id, expression); } } } } else if ((id != null) && ((myOwnerNode.Source != mgr.Source) || !context.ChangingIdentities.ContainsKey(id))) { IFormulaOperatorSource externalManager = mgr.GetExternalManager(myOwnerNode.Source); if (externalManager != null) { CalcExpression expr = externalManager.GetExpression(id); if (expr != null) { if (((formulas1 != null) && formulas1.ContainsKey(id)) || ((formulas2 != null) && formulas2.ContainsKey(id))) { list.Add(id); } else { context.AddExtChangedFormula(externalManager, id, id, expr); } } } } } } return(list); }
private Node addExp() { EnterRule_addExp(); EnterRule("addExp", 4); TraceIn("addExp", 4); Node node = default(Node); IToken op = default(IToken); Node lhs = default(Node); Node rhs = default(Node); Node mulExp5 = default(Node); try { DebugEnterRule(GrammarFileName, "addExp"); DebugLocation(48, 2); try { // KnightyCode.g:49:3: (lhs= mulExp op= ( '+' | '-' ) rhs= addExp | mulExp ) int alt5=2; try { DebugEnterDecision(5, false); switch (input.LA(1)) { case Number: { int LA5_2 = input.LA(2); if ((EvaluatePredicate(synpred6_KnightyCode_fragment))) { alt5 = 1; } else if ((true)) { alt5 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 5, 1, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case If: { int LA5_2 = input.LA(2); if ((EvaluatePredicate(synpred6_KnightyCode_fragment))) { alt5 = 1; } else if ((true)) { alt5 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 5, 2, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case While: { int LA5_2 = input.LA(2); if ((EvaluatePredicate(synpred6_KnightyCode_fragment))) { alt5 = 1; } else if ((true)) { alt5 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 5, 3, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; case 12: { int LA5_2 = input.LA(2); if ((EvaluatePredicate(synpred6_KnightyCode_fragment))) { alt5 = 1; } else if ((true)) { alt5 = 2; } else { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 5, 4, input, 2); DebugRecognitionException(nvae); throw nvae; } } break; default: { if (state.backtracking>0) {state.failed=true; return node;} NoViableAltException nvae = new NoViableAltException("", 5, 0, input, 1); DebugRecognitionException(nvae); throw nvae; } } } finally { DebugExitDecision(5); } switch (alt5) { case 1: DebugEnterAlt(1); // KnightyCode.g:49:6: lhs= mulExp op= ( '+' | '-' ) rhs= addExp { DebugLocation(49, 9); PushFollow(Follow._mulExp_in_addExp194); lhs=mulExp(); PopFollow(); if (state.failed) return node; DebugLocation(49, 19); op=(IToken)input.LT(1); if ((input.LA(1)>=15 && input.LA(1)<=16)) { input.Consume(); state.errorRecovery=false;state.failed=false; } else { if (state.backtracking>0) {state.failed=true; return node;} MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(49, 35); PushFollow(Follow._addExp_in_addExp208); rhs=addExp(); PopFollow(); if (state.failed) return node; DebugLocation(49, 43); if (state.backtracking == 0) { node = new CalcNode( (op!=null?op.Text:null), lhs, rhs ); } } break; case 2: DebugEnterAlt(2); // KnightyCode.g:50:5: mulExp { DebugLocation(50, 5); PushFollow(Follow._mulExp_in_addExp216); mulExp5=mulExp(); PopFollow(); if (state.failed) return node; DebugLocation(50, 12); if (state.backtracking == 0) { node = mulExp5; } } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("addExp", 4); LeaveRule("addExp", 4); LeaveRule_addExp(); } DebugLocation(51, 2); } finally { DebugExitRule(GrammarFileName, "addExp"); } return node; }
//Is called when a selection from the context menu is made void ContextCallback(object obj) { //make the passed object to a string string clb = obj.ToString(); //add the node we want if (clb.Equals("inputNode")) { InputNode inputNode = ScriptableObject.CreateInstance <InputNode>(); inputNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80); windows.Add(inputNode); } else if (clb.Equals("outputNode")) { OutputNode outputNode = ScriptableObject.CreateInstance <OutputNode>(); outputNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80); windows.Add(outputNode); } else if (clb.Equals("calcNode")) { CalcNode calcNode = ScriptableObject.CreateInstance <CalcNode>(); calcNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95); windows.Add(calcNode); } else if (clb.Equals("compNode")) { ComparisonNode compNode = ScriptableObject.CreateInstance <ComparisonNode>(); compNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95); windows.Add(compNode); } else if (clb.Equals("numNode")) { NumberNode numNode = ScriptableObject.CreateInstance <NumberNode>(); numNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95); windows.Add(numNode); } else if (clb.Equals("goObj")) { GameObjectNode goObj = ScriptableObject.CreateInstance <GameObjectNode>(); goObj.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 100); windows.Add(goObj); } else if (clb.Equals("goActive")) { GameObjectActive goNode = ScriptableObject.CreateInstance <GameObjectActive>(); goNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80); windows.Add(goNode); } else if (clb.Equals("goDistance")) { GameObjectDistance goDistance = ScriptableObject.CreateInstance <GameObjectDistance>(); goDistance.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80); windows.Add(goDistance); } else if (clb.Equals("timerNode")) { TimerNode tNode = ScriptableObject.CreateInstance <TimerNode>(); tNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95); windows.Add(tNode); } else if (clb.Equals("boolNode")) { BoolNode bNode = ScriptableObject.CreateInstance <BoolNode>(); bNode.WindowRect = new Rect(mousePos.x, mousePos.y, 120, 75); windows.Add(bNode); } else if (clb.Equals("clearAll")) { windows.Clear(); } else if (clb.Equals("reset")) { PanX = PanY = 0; } else if (clb.Equals("makeTransition")) //if it's a transition { bool clickedOnWindow = false; int selectedIndex = -1; //find the window that it was clicked for (int i = 0; i < windows.Count; i++) { if (windows[i].WindowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } //and make it the selected node of the transition if (clickedOnWindow) { selectedNode = windows[selectedIndex]; makeTransitionMode = true; } } else if (clb.Equals("deleteNode")) //if it's a delete node { bool clickedOnWindow = false; int selectedIndex = -1; //find the selected node for (int i = 0; i < windows.Count; i++) { if (windows[i].WindowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { //delete it from our list BaseNode selNode = windows[selectedIndex]; windows.RemoveAt(selectedIndex); //then pass it to all our nodes that is deleted foreach (BaseNode n in windows) { n.NodeDeleted(selNode); } } } //we use else if instead of a switch because: /*Selecting from a set of multiple cases is faster with if statements than with switch */ }