public RuleType Convert(string name, NodeBase rootCondition, List<NodeBase> actionList)
		{
			RuleType rule = new RuleType();

			rule.AddName(new Altova.Types.SchemaString(name));

			//this first node is the condition. Called traverse twice to create the two expressions
			LogicalExpression expression = CreateLogical(rootCondition);

			rule.AddCondition(expression);

			foreach (NodeBase node in actionList)
			{
				if ((node.m_NodeType == NodeType.SETVARIABLE) || (node.m_NodeType == NodeType.CALLSCRIPT))
				{
					XMLRules.ActionType action = MakeAction(node);
					if (action != null)
						rule.AddAction(action);
					else
						Debug.LogError("Error saving an action node");
				}
			}

			rule.AddPriority(new Altova.Types.SchemaLong(100L));

			return rule;
		}
Beispiel #2
0
		public override bool CheckChild(NodeBase child)
		{
			bool result = false;
			
			if (m_Children.Contains (child))
				result = false;
			
			return result;
		}
		public void RemoveNode(NodeBase node)
		{
			foreach(NodeEdge edgeToRemove in m_NodeEdges)
			{
				if (edgeToRemove.CheckForEdge(node))
					break;
			}

			m_RemoveNodeList.Add(node);
		}
Beispiel #4
0
		public bool CheckForEdge(NodeBase node)
		{
			bool result = false;
			if(m_FromNode == node || m_ToNode == node)
			{
				RemoveEdgeFunction();
				result = true;
			}
			return result;
		}
Beispiel #5
0
        public bool GetChildAt(int index, out NodeBase node)
        {
            node = null;

            if (index >= m_Children.Count)
                return false;

            node = m_Children[index];

            return true;
        }
Beispiel #6
0
		public override bool CheckChild(NodeBase child)
		{
			bool result = false;
			
			if (CheckForCycles(this, child))
				return false;
			
			if ((child.m_NodeType == NodeType.ARITHMETIC) || 
			    (child.m_NodeType == NodeType.VARIABLE) || (child.m_NodeType == NodeType.CONSTANT))
				result = true;
			
			return result;
		}
		// Use the number of leaf nodes of a tree as an estimate of its width at the base. 
		int CountLeafNodes(NodeBase node)
		{
			int count = 0;

			if (node.m_Children.Count == 0)
				count++;
			else
				foreach (NodeBase child in node.m_Children) 
				{
					count += CountLeafNodes(child);
				}

			return count;
		}
Beispiel #8
0
		public bool CheckForCycles(NodeBase parent, NodeBase child)
		{
			if (parent.m_Children.Contains(child))
				return true;

			bool result = false;

			foreach (NodeBase node in parent.m_Children) 
			{
				if (result = CheckForCycles (node, child))
					break;
			}

			return result;
		}
		void LayoutTree(NodeBase node, float posx, float posy)
		{	
			node.m_Window.x = posx;
			node.m_Window.y = posy;

			float dx = 0;

			int leafNodes = CountLeafNodes(node);

			dx = leafNodes * 75 / 2;

			if (node.m_Children.Count >= 1)
				LayoutTree(node.m_Children[0], posx - dx, posy + 200);

			if (node.m_Children.Count == 2)
				LayoutTree(node.m_Children[1], posx + dx, posy + 200);
		}
		XMLRules.ActionType MakeAction(NodeBase node)
		{
			if (node.m_NodeType == NodeType.SETVARIABLE)
			{
				SetNode setNode = (SetNode)node;

				if (m_State != null) 
				{
					Variable variable;

					if  (setNode.m_Children.Count >= 1)
					{
						if (m_State.GetVariable(setNode.m_VariableName, out variable))
						{
							ArithmeticExpression value = CreateArithmeticExpression(setNode.m_Children[0]);
							return m_RuleMaker.MakeStateChangeAction(setNode.m_VariableName, variable.m_Type, value);
						}
						else
						{
							Debug.LogError("Invalid assignment: variable " + setNode.m_VariableName + " not found");
						}
					}
					else
					{
						Debug.LogError("Invalid assignment: no value was specified");
					}
				}
			}
			else if (node.m_NodeType == NodeType.CALLSCRIPT)
			{
				CallNode callNode = (CallNode)node;
				return m_RuleMaker.MakeCallScriptAction(callNode);
			}

			return null;
		}
		ArithmeticExpression CreateArithmetic(NodeBase node)
		{
			ArithmeticExpression lhs = CreateArithmeticExpression(node.m_Children[0]);
			ArithmeticExpression rhs = CreateArithmeticExpression(node.m_Children[1]);
			
			return m_RuleMaker.MakeArithmeticSubExperssion(((ArithmeticNode)node).GetOperator(), lhs, rhs);
		}
		LogicalExpression CreateRelationalExpression(NodeBase node)
		{
			ArithmeticExpression lhs = CreateArithmeticExpression(node.m_Children[0]);
			ArithmeticExpression rhs = CreateArithmeticExpression(node.m_Children[1]);
			
			return m_RuleMaker.MakeRelationalExperssion(((RelationalNode)node).GetOperator(), lhs, rhs);
		}
		LogicalExpression CreateLogicalExpression(NodeBase node)
		{
			LogicalExpression expression = null;

			LogicalNode logicalNode = (LogicalNode)node;

			if (logicalNode.m_LogicalType == LogicalOperatorType.NOT) 
			{
				LogicalExpression rhs = CreateLogical(node.m_Children[0]);
				expression = m_RuleMaker.MakeLogical(rhs);
			}
			else 
			{
				switch (node.m_NodeType) 
				{
					case NodeType.RELATIONAL:
					{
						ArithmeticExpression lhs = CreateArithmeticExpression(node.m_Children[0]);
						ArithmeticExpression rhs = CreateArithmeticExpression(node.m_Children[1]);
						expression = m_RuleMaker.MakeRelationalExperssion(((RelationalNode)node).GetOperator(), lhs, rhs);
					}
					break;

					case NodeType.LOGICAL:
					{
						LogicalExpression lhs = CreateLogical(node.m_Children[0]);
						LogicalExpression rhs = CreateLogical(node.m_Children[1]);
						expression = m_RuleMaker.MakeLogical(((LogicalNode)node).GetOperator(), lhs, rhs);
					}
					break;
				}
			}
	
			return expression;
		}
		public override bool CheckChild(NodeBase child)
		{
			bool result = false;
			
			return result;	
		}
Beispiel #15
0
		public void AddChild(NodeBase node) { m_Children.Add(node); }
		void BuildNodeList(NodeBase rootNode, ref List<NodeBase> nodeList)
		{
			nodeList.Add(rootNode);

			foreach (NodeBase node in rootNode.m_Children) 
			{
				BuildNodeList(node, ref nodeList);
			}
		}
Beispiel #17
0
		public void RemoveChild(NodeBase node) { m_Children.Remove(node);}
		ArithmeticExpression CreateArithmeticExpression(NodeBase node)
		{
			ArithmeticExpression expression = null;

			switch (node.m_NodeType) 
			{
				case NodeType.ARITHMETIC:
					expression = CreateArithmetic(node);
				break;

				case NodeType.CONSTANT:
				{
					Value value = m_RuleMaker.MakeConstant(((ConstantNode)node).m_ConstantType, ((ConstantNode)node).m_ConstantValue);
					expression = m_RuleMaker.MakeArithmeticExperssion(value);
				}
				break;

				case NodeType.VARIABLE:
				{
					Value value = m_RuleMaker.MakeVariable(((VariableNode)node).m_VariableName, ((VariableNode)node).m_VariableType);
					expression = m_RuleMaker.MakeArithmeticExperssion(value);
				}
				break;
			}

			return expression;
		}
Beispiel #19
0
        public override bool CheckChild(NodeBase child)
        {
            bool result = false;

            return(result);
        }
Beispiel #20
0
        NodeBase CreateLogicalNode(LogicalExpression exp)
        {
            NodeBase node = null;

            if (exp.HasUnary())
            {
                node = new LogicalNode(m_Container);
                ((LogicalNode)node).m_LogicalType = LogicalOperatorType.NOT;
                node.AddChild(CreateLogicalNode(exp.GetUnary().GetLogicalExpression()));
            }
            else if (exp.HasRelational())
            {
                node = new RelationalNode(m_Container);
                RelationalOperator op = exp.GetRelational().GetRelationalOperator();
                if (op.HasEquals())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.EQUAL;
                }
                else if (op.HasGreaterThan())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.GREATERTHAN;
                }
                else if (op.HasGreaterThanOrEquals())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.GREATERTHANOREQUAL;
                }
                else if (op.HasLessThan())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.LESSTHAN;
                }
                else if (op.HasLessThanOrEquals())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.LESSTHANOREQUAL;
                }
                else if (op.HasNotEquals())
                {
                    ((RelationalNode)node).m_RelationType = RelationType.NOTEQUAL;
                }

                node.AddChild(CreateArithmeticNode(exp.GetRelational().GetLHSArithmeticExpression()));
                node.AddChild(CreateArithmeticNode(exp.GetRelational().GetRHSArithmeticExpression()));
            }
            else if (exp.HasLogical())
            {
                node = new LogicalNode(m_Container);

                if (exp.GetLogical().GetLogicalOperator().HasAnd())
                {
                    ((LogicalNode)node).m_LogicalType = LogicalOperatorType.AND;
                }
                else
                {
                    ((LogicalNode)node).m_LogicalType = LogicalOperatorType.OR;
                }

                node.AddChild(CreateLogicalNode(exp.GetLogical().GetLHSLogicalExpression()));
                node.AddChild(CreateLogicalNode(exp.GetLogical().GetRHSLogicalExpression()));
            }
            else if (exp.HasValue())
            {
                if (exp.GetValue().HasConstant())
                {
                    node = new ConstantNode(m_Container);
                    ((ConstantNode)node).m_ConstantValue = exp.GetValue().GetConstant().GetBoolean().Value;
                    ((ConstantNode)node).m_ConstantType  = VariableType.BOOLEAN;
                }
                else
                {
                    node = new VariableNode(m_Container);

                    ((VariableNode)node).m_VariableName = exp.GetValue().GetVariable().GetName().Value;
                    ((VariableNode)node).m_VariableType = VariableType.BOOLEAN;
                }
            }

            return(node);
        }
Beispiel #21
0
		public NodeEdge (NodeBase from, NodeBase to)
		{
			m_FromNode = from;
			m_ToNode = to;
			m_ConnectWidth = m_FromNode.m_Children.IndexOf(m_ToNode);
		}
		LogicalExpression CreateLogical(NodeBase node)
		{
			LogicalExpression expression = null;

			switch (node.m_NodeType) 
			{
				case NodeType.RELATIONAL:
					expression = CreateRelationalExpression(node);
				break;

				case NodeType.LOGICAL:
					expression = CreateLogicalExpression(node);
				break;
			
				case NodeType.CONSTANT:
				{
					Value value = m_RuleMaker.MakeConstant(((ConstantNode)node).m_ConstantType, ((ConstantNode)node).m_ConstantValue);
					expression = m_RuleMaker.MakeLogical(value);
				}
				break;

				case NodeType.VARIABLE:
				{
					Value value = m_RuleMaker.MakeVariable(((VariableNode)node).m_VariableName, ((VariableNode)node).m_VariableType);
					expression = m_RuleMaker.MakeLogical(value);
				}
				break;
			}

			return expression;
		}
Beispiel #23
0
		public abstract bool CheckChild (NodeBase child);