static ConditionSet ExportConditions( GroupNode node ) { ConditionSet set; switch( node.Op ) { case GroupNodeType.AND: set = new ConditionAND(); break; case GroupNodeType.OR: set = new ConditionOR(); break; case GroupNodeType.NAND: set = new ConditionNAND(); break; case GroupNodeType.NOR: set = new ConditionNOR(); break; default: throw new ArgumentOutOfRangeException(); } foreach( TreeNode subNode in node.Nodes ) { if( subNode is GroupNode ) { set.Add( ExportConditions( (GroupNode)subNode ) ); } else if( subNode is ConditionNode ) { ConditionNode sn = (ConditionNode)subNode; ConditionIntRange cond = new ConditionIntRange { Comparison = sn.Op, Field = sn.Field, Value = sn.Value }; set.Add( cond ); } else { throw new Exception(); } } return set; }
private void cmAddGroup_ItemClicked( object sender, ToolStripItemClickedEventArgs e ) { ToolStripMenuItem item = (ToolStripMenuItem)e.ClickedItem; if( item.DropDownItems.Count > 0 ) return; TreeNode parent = treeData.SelectedNode; if( parent is GroupNode ) { GroupNode newNode = new GroupNode( (GroupNodeType)Enum.Parse( typeof( GroupNodeType ), item.Text ) ); parent.Nodes.Add( newNode ); ((GroupNode)parent).UpdateLabel(); newNode.EnsureVisible(); treeData.SelectedNode = newNode; } }
static void ImportCondition( GroupNode parent, Condition condition ) { if( condition is ConditionIntRange ) { ConditionIntRange cond = (ConditionIntRange)condition; ConditionNode newNode = new ConditionNode { Field = cond.Field, Value = cond.Value, Op = cond.Comparison }; parent.Nodes.Add( newNode ); } else if( condition is ConditionSet ) { ConditionSet set = (ConditionSet)condition; GroupNode newNode = new GroupNode(); if( set is ConditionAND ) { newNode.Op = GroupNodeType.AND; } else if( set is ConditionOR ) { newNode.Op = GroupNodeType.OR; } else if( set is ConditionNAND ) { newNode.Op = GroupNodeType.NAND; } else if( set is ConditionNOR ) { newNode.Op = GroupNodeType.OR; } else { return; } foreach( Condition subCondition in set.Conditions ) { ImportCondition( newNode, subCondition ); } parent.Nodes.Add(newNode); } }