/// <summary> /// Adds an item to the PulseTree based on current form inputs. /// </summary> /// <param name="bIsRoot">If true adds new node as sibling to currently selected node. If false adds as child to currently selected node.</param> void AddNewState(bool bIsRoot) { bool bIsLoop; if (PulseTypeTabs.SelectedTab == LoopTabPage) { bIsLoop = true; } else { bIsLoop = false; } Pulse P = CreatePulseFromForm(bIsLoop); TreeNode T; if (PulseTree.SelectedNode != null) //make sure there is a node selected { if (!bIsRoot) { if (PulseTree.SelectedNode.Tag is LaserState) { WriteMessage("Can't Create New Pulse: Laser States can't have child nodes", true); return; } T = PulseTree.SelectedNode.Nodes.Add(P.Name);//create a child node of currently selected node } else //add a sibling to currently selected node. { if (PulseTree.SelectedNode.Parent != null) //is node NOT a top-level node? { T = PulseTree.SelectedNode.Parent.Nodes.Add(P.Name); //add as a sibling to selected node } else { T = PulseTree.Nodes.Add(P.Name); //if top-level node then just add to the top-level list } } } else { T = PulseTree.Nodes.Add(P.Name); //add as top level node if nothing is selected } T.Tag = P; //Tag is any object we choose so put in the specific laser data. if (bIsLoop) { if (FPGALoopSelect.Checked == true) { T.Text += " (FPGA Loop x" + ((LoopState)P).LoopCount + ")"; } else { T.Text += " (Loop x" + ((LoopState)P).LoopCount + ")"; } } //PulseTree.Select(); //PulseTree.SelectedNode = T; //select the new node }
/// <summary> /// Called when an item is selected in the PulseTree. Updates other form elements with the Pulse data at the particular tree node. /// </summary> void PulseTreeSelect() { if (PulseTree.SelectedNode != null) { Pulse P = (Pulse)PulseTree.SelectedNode.Tag; NameBox.Text = P.Name; if (PulseTree.SelectedNode.Tag is LoopState) { PulseTypeTabs.SelectedTab = LoopTabPage; LoopNumberBox.Value = ((LoopState)P).LoopCount; FPGALoopSelect.Checked = ((LoopState)P).bIsFPGALoop; } else { PulseTypeTabs.SelectedTab = PulseTabPage; LaserBox397B1.Checked = ((LaserState)P).Laser397B1; LaserBox397B2.Checked = ((LaserState)P).Laser397B2; LaserBox729.Checked = ((LaserState)P).Laser729; LaserBox854.Checked = ((LaserState)P).Laser854; LaserBox854POWER.Checked = ((LaserState)P).Laser854POWER; LaserBox854FREQ.Checked = ((LaserState)P).Laser854FREQ; LaserBoxAux1.Checked = ((LaserState)P).LaserAux1; LaserBoxAux2.Checked = ((LaserState)P).LaserAux2; if (((LaserState)P).Laser729RF1 == true && ((LaserState)P).Laser729RF2 == true) { SourceSelect729.Value = 1; } else if (((LaserState)P).Laser729RF1 == false && ((LaserState)P).Laser729RF2 == true) { SourceSelect729.Value = 2; } else if (((LaserState)P).Laser729RF1 == true && ((LaserState)P).Laser729RF2 == false) { SourceSelect729.Value = 3; } else if (((LaserState)P).Laser729RF1 == false && ((LaserState)P).Laser729RF2 == false) { SourceSelect729.Value = 4; } //Update tick box to target length, and call tickRounder to update rounded length display TicksBox.Value = ((LaserState)P).TargetLength; tickRounder(); PulseTypeBox.SelectedIndex = (int)((LaserState)P).StateType; } PulseTree.Select(); //make sure that focus stays on PulseTree } }