Ejemplo n.º 1
0
		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;
		}
Ejemplo n.º 2
0
		public override bool CheckChild(NodeBase child)
		{
			bool result = false;
			
			if (m_Children.Contains (child))
				result = false;
			
			return result;
		}
Ejemplo n.º 3
0
		public void RemoveNode(NodeBase node)
		{
			foreach(NodeEdge edgeToRemove in m_NodeEdges)
			{
				if (edgeToRemove.CheckForEdge(node))
					break;
			}

			m_RemoveNodeList.Add(node);
		}
Ejemplo n.º 4
0
		public bool CheckForEdge(NodeBase node)
		{
			bool result = false;
			if(m_FromNode == node || m_ToNode == node)
			{
				RemoveEdgeFunction();
				result = true;
			}
			return result;
		}
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 7
0
		// 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;
		}
Ejemplo n.º 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;
		}
Ejemplo n.º 9
0
		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);
		}
Ejemplo n.º 10
0
		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;
		}
Ejemplo n.º 11
0
		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);
		}
Ejemplo n.º 12
0
		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);
		}
Ejemplo n.º 13
0
		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;
		}
Ejemplo n.º 14
0
		public override bool CheckChild(NodeBase child)
		{
			bool result = false;
			
			return result;	
		}
Ejemplo n.º 15
0
		public void AddChild(NodeBase node) { m_Children.Add(node); }
Ejemplo n.º 16
0
		void BuildNodeList(NodeBase rootNode, ref List<NodeBase> nodeList)
		{
			nodeList.Add(rootNode);

			foreach (NodeBase node in rootNode.m_Children) 
			{
				BuildNodeList(node, ref nodeList);
			}
		}
Ejemplo n.º 17
0
		public void RemoveChild(NodeBase node) { m_Children.Remove(node);}
Ejemplo n.º 18
0
		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;
		}
Ejemplo n.º 19
0
        public override bool CheckChild(NodeBase child)
        {
            bool result = false;

            return(result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 21
0
		public NodeEdge (NodeBase from, NodeBase to)
		{
			m_FromNode = from;
			m_ToNode = to;
			m_ConnectWidth = m_FromNode.m_Children.IndexOf(m_ToNode);
		}
Ejemplo n.º 22
0
		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;
		}
Ejemplo n.º 23
0
		public abstract bool CheckChild (NodeBase child);