//is the drag event a drag using the right mouse button private void TreeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { // ----------------------------------------------------------------- // User has initiated a drag on a node - the full xml of the node // is stored as the data associated with the drag event args. // ----------------------------------------------------------------- //If what is being dragged is not already in the controller as a selected item. if ((Controller.SelectedFactorialPath != GetPathFromNode((TreeNode)e.Item))) { SelectedNode = (TreeNode)e.Item; //add it to the base controller (by setting the selected node of the tree to the dragged item. This then fires the selection changed event for the tree which I think is handled by the base controller. This will add the dragged items to the base controller) } //Work out the xml of what you are dragging. string FullXML = ""; //used to store the xml of ALL the components that have been selected in the drag 'reset it to nothing, ready for recreation. ApsimFile.Component Comp = Controller.ApsimData.Find(Controller.SelectedFactorialPath); //get the component for this particular selected node (using it's path) FullXML = FullXML + Comp.FullXML(); //get the xml for the component and add it to the xml of previous selected nodes PathsBeingDragged = new StringCollection(); PathsBeingDragged.Add(Controller.SelectedFactorialPath); //store the paths of ALL the nodes that are being dragged in a global variable, so it can be used by other drag events. //Raise the other DragDropEvents DoDragDrop(FullXML, DragDropEffects.Copy); //parameters: (Store xml of what you are dragging in "data" Drag Event Argument), (allowable types of left mouse drags [Drag Drop Effects are of type FlagsAttribute, which allow bitwise operators AND and OR]). }
public override void OnRefresh() { base.HelpText = "Select fields by clicking on the column(s) at the bottom."; DataProcessor Processor = new DataProcessor(); XmlDocument Doc = new XmlDocument(); ApsimFile.Component c = Controller.ApsimData.Find(NodePath + "/Observed"); if (c != null) { Doc.LoadXml(Controller.ApsimData.Find(NodePath + "/Observed").FullXML()); DataGrid.DataSource = Processor.Go(Doc.DocumentElement, NodePath); } foreach (DataGridViewColumn Col in DataGrid.Columns) { Col.SortMode = DataGridViewColumnSortMode.NotSortable; } DataGrid.BringToFront(); List <string> ListValues = XmlHelper.Values(Data, "FieldsToMatch"); string[] Values = new string[ListValues.Count]; ListValues.CopyTo(Values, 0); FieldNames.Items.Clear(); FieldNames.Items.AddRange(Values); FieldNames.BackColor = HightlightColour; base.OnColumnClickEvent -= OnColumnClick; base.OnColumnClickEvent += OnColumnClick; }
public List <ApsimFile.Component> getShortcutNodes(string sXML) { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(sXML); List <ApsimFile.Component> lstComponents = new List <ApsimFile.Component>(); XmlNodeList nodes = tmpDoc.SelectNodes("//*[@shortcut]"); foreach (XmlNode tmpNode in nodes) { //get xml for destination shortcut //string stores the name attribute for each node in the path ApsimFile.Component tmpComponent = null; string sShortcut = XmlHelper.Attribute(tmpNode, "shortcut"); while (sShortcut != "") { tmpComponent = Controller.ApsimData.Find(sShortcut); if (tmpComponent != null) { //code not correct as Contents refers to innerXML so misses shorcuts to shortcuts sShortcut = XmlHelper.Attribute(tmpComponent.ContentsAsXML, "shortcut"); } } if (tmpComponent != null) { lstComponents.Add(tmpComponent); } } return(lstComponents); }
private void CloseView() { if (CurrentView == -1) { // OK We are still at the select a graph screen. Find out which // graph was selected and go recursively create all the BaseViews // ready for showing to the user. XmlNode SelectedNode = XmlHelper.Find(Graphs, GraphList.Items[GraphList.SelectedIndex].ToString()); if (Controller.ApsimData.RootComponent == null) { Controller.ApsimData.New("<folder name=\"Graphs\"/>"); SelectedComponent = Controller.ApsimData.RootComponent; } SelectedComponent = Controller.Selection.Add(SelectedNode.OuterXml); CreateViews(SelectedComponent); GraphList.Visible = false; GraphListLabel.Visible = false; } else { BaseView View = Views[CurrentView]; ApsimFile.Component Comp = Controller.ApsimData.Find(View.NodePath); Comp.Contents = View.GetData(); View.Visible = false; } }
public void SaveCurrentView() { // ----------------------------------------------------- // Tell current view to save. // ----------------------------------------------------- if (CurrentUIIndex != -1) { BaseView View = (BaseView)UIs[CurrentUIIndex]; //if path has a delimiter at the beginning it is normal view //else it is a factorial view ApsimFile.Component Comp = null; // int pos = View.NodePath.IndexOf(ApsimFile.Component.Delimiter); if ((pos == 0)) { Comp = Controller.ApsimData.Find(View.NodePath); } else { Comp = Controller.FindFactorialComponent(View.NodePath); } if ((Comp != null)) { if (View.ToString() == "CSUserInterface.Factorial" && !Comp.FullPath.Contains("/Factorials")) { // Hack to workaround Bug 1516. } else { View.OnSave(); Comp.Contents = View.GetData(); } } } }
public override void OnRefresh() { Simulation = findCurrentSimulation(); string stmp = MyNodePath; //What UpdateStatesList(); UpdateCropsList(); //Planting Criteria txtStart.Text = ReadUIVariable("date1"); txtEnd.Text = ReadUIVariable("date2"); txtRain.Text = ReadUIVariable("raincrit"); txtDaysRain.Text = ReadUIVariable("rainnumdays"); txtMinWater.Text = ReadUIVariable("esw_amount"); string sResult = ReadUIVariable("must_sow"); chkSow.Checked = sResult == "yes"; sResult = ReadUIVariable("wait_machinery"); chkMachinery.Checked = sResult == "yes"; //Establishment UpdateCultivarsList(); txtDensity.Text = ReadUIVariable("plants"); txtDepth.Text = ReadUIVariable("sowing_depth"); txtRows.Text = ReadUIVariable("row_spacing"); txtSowingcost.Text = ReadUIVariable("sowing_costs"); // machinery UpdateMachineryList(cboTractor, lblTractorWarning, "tractor", "sow_tractor"); UpdateMachineryList(cboImplement, lblImplementWarning, "implement", "sow_implement"); //UpdateTractorsList(); //UpdateImplementsList(); // fertiliser UpdateFertiliserList(); txtFertiliserCost.Text = ReadUIVariable("fert_cost"); txtNitrogen.Text = ReadUIVariable("target_n"); //Harvesting txtHarvestCost.Text = ReadUIVariable("harvest_costs"); txtCropPrice.Text = ReadUIVariable("price"); txtMoisture.Text = ReadUIVariable("moisture"); UpdateMachineryList(cboHarvestTractor, lblHarvestTractorWarning, "tractor", "harv_tractor"); UpdateMachineryList(cboHarvestImplement, lblHarvestImplementWarning, "implement", "harv_implement"); LoadCustom(); XmlNode ScriptNode = Data.SelectSingleNode("//script/text"); string sScript = ""; if (ScriptNode != null) { sScript = XmlHelper.Value(ScriptNode, ""); } syntaxEdit1.Text = sScript; }
private ApsimFile.Component findCurrentSimulation() { ApsimFile.Component thisComp = Controller.ApsimData.Find(NodePath); //loop back up the component datastructure until you get to the parent simulation. while ((thisComp != null)) { if (thisComp.Type.ToLower() == "simulation") { return(thisComp); } thisComp = thisComp.Parent; } return(null); }
private void ShowUI(string SelectedPath, ApsimFile.Component SelectedComponent) { // ------------------------------------------------- // Create and show a specific UI depending on the // currently selected data // ------------------------------------------------- //Dim SelectedData As ApsimFile.Component = Controller.ApsimData.Find(Controller.SelectedPath) if ((SelectedComponent != null)) { if (CurrentUIIndex == -1 || UITypes[CurrentUIIndex] != SelectedComponent.Type) { CloseUI(); CurrentUIIndex = UITypes.IndexOf(SelectedComponent.Type); if (CurrentUIIndex == -1) { BaseView View = Controller.CreateUI(SelectedComponent.Type); if ((View != null)) { UIs.Add(View); UITypes.Add(SelectedComponent.Type); CurrentUIIndex = UIs.Count - 1; } } } else { SaveCurrentView(); } if (CurrentUIIndex != -1) { try { BaseView View = (BaseView)UIs[CurrentUIIndex]; View.OnLoad(Controller, SelectedPath, SelectedComponent.Contents); View.Parent = UIPanel; View.Dock = DockStyle.Fill; View.Show(); View.OnRefresh(); } catch (Exception ex) { if (ex.InnerException != null) { MessageBox.Show(ex.Message + " " + ex.InnerException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
public override bool OnDropData(StringCollection SourcePaths, string FullXML) { //if there are no children, then add the droppednodes as targets //don't add to targets if there is existing children //don't add to targets if the source is from the Factorial Tree ApsimFile.Component thisComp = Controller.ApsimData.Find(NodePath); //if (thisComp.ChildNodes.Count == 0) { FactorTargets.AddTargets(SourcePaths); } thisComp.Add(FullXML); OnRefresh(); return(true); }
private void RefreshNodeAndChildren(TreeNode Node, ApsimFile.Component Comp) { // -------------------------------------------------- // Recursively refresh the specified treenode and its // child nodes in the tree. // -------------------------------------------------- // Refresh the specified node first. Node.Text = Comp.Name; Node.ImageIndex = Controller.ImageIndex(Comp.Type, "SmallIcon"); Node.SelectedImageIndex = Node.ImageIndex; Node.Tag = Comp.Type; Node.ToolTipText = Comp.Description; if ((Comp.ShortCutTo != null)) { Node.ToolTipText = "Linked to " + Comp.ShortCutTo.FullPath; if (!Comp.Enabled) { Node.ToolTipText = "Disabled: " + Node.ToolTipText; } } if (!Comp.Enabled) { Node.ToolTipText = "Disabled" + Node.ToolTipText; } ColourNode(Node); // Go refresh all children. int ChildIndex = 0; foreach (ApsimFile.Component Child in Comp.ChildNodes) { TreeNode ChildTreeNode = null; if (ChildIndex < Node.Nodes.Count) { ChildTreeNode = Node.Nodes[ChildIndex]; } else { ChildTreeNode = Node.Nodes.Add(Child.Name); } RefreshNodeAndChildren(ChildTreeNode, Child); ChildIndex = ChildIndex + 1; } while (Node.Nodes.Count > ChildIndex) { Node.Nodes.Remove(Node.Nodes[Node.Nodes.Count - 1]); } }
private void FindNestedDataSeries() { // Find our ApsimFile.Component class. if (Controller != null && NodePath != "") { ApsimFile.Component OurComponent = Controller.ApsimData.Find(NodePath); List <string> DefaultFileNames = new List <string>(); UIUtility.OutputFileUtility.GetOutputFiles(Controller, Controller.Selection, DefaultFileNames); foreach (DataTable Source in FindDataSources(OurComponent, DefaultFileNames)) { AddDataSource(Source); } } }
public override void OnRefresh() { base.OnRefresh(); this.Grid.CellValueChanged -= new System.Windows.Forms.DataGridViewCellEventHandler(this.OnCellValueChanged); Properties.OnRefresh(); Properties.Visible = !Properties.IsEmpty; // Fill a datatable Table = new DataTable(); Table.TableName = "Data"; Table.Columns.Add("X", typeof(double)); Table.Columns.Add("Y", typeof(double)); foreach (XmlNode XY in XmlHelper.ChildNodes(Data, "XY")) { string[] Values = XY.InnerText.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (Values.Length == 2) { DataRow NewRow = Table.NewRow(); NewRow["X"] = Values[0]; NewRow["Y"] = Values[1]; Table.Rows.Add(NewRow); } } // Give the datatable to the grid. Grid.DataSource = Table; Grid.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; Grid.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; // Give the datatable to the chart. Line.DataSource = Table; Line.XValues.DataMember = "X"; Line.YValues.DataMember = "Y"; this.Grid.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.OnCellValueChanged); ApsimFile.Component Parent = Controller.ApsimData.Find(NodePath).Parent; if (Parent != null) { Chart.Axes.Left.Title.Text = Parent.Name; if (Parent.Type == "GenericFunction") { Chart.Axes.Bottom.Title.Text = XmlHelper.Value(Parent.ContentsAsXML, "XProperty"); } } }
private List <string> findCrops() { //Find a list of states that the management UI knows about //states will come from a rotation management node (nodes called "node") //it is possible for this to be held above simulations - therefore using global stats //otherwise it should only return those states within the current simulation List <string> knownCrops = new List <string>(); ApsimFile.Component component = Simulation; if (component == null) { component = Controller.ApsimData.RootComponent; } AddCrops(component, knownCrops); return(knownCrops); }
public override void OnSave() { base.OnSave(); foreach (Control C in Panel.Controls) { if (C is Controllers.BaseView) { Controllers.BaseView View = (Controllers.BaseView)C; View.OnSave(); ApsimFile.Component Comp = Controller.ApsimData.Find(View.NodePath); if (Comp != null) { Comp.Contents = View.GetData(); } } } }
private void AddCrops(ApsimFile.Component component, List <string> knownCrops) { if (Types.Instance.MetaData(component.Type, "IsCrop").ToLower() == "yes") { //component.NAme is the name that appears in the tree - can be changed //component.Type is the name used toidentify the comonent's type - ie: xml file string cropName = component.Type; if (cropName != null && knownCrops.IndexOf(cropName) < 0) //not found { knownCrops.Add(cropName); } } foreach (ApsimFile.Component child in component.ChildNodes) { AddCrops(child, knownCrops); } }
public void LoadManagerVariables() { //if there is a single manager component as a child, then allow parameters to be defined //parameters will be stored in a separate node "variables" //we don't allow combination similar to complexfactor... yet. ApsimFile.Component thisComp = Controller.ApsimData.Find(NodePath); if (thisComp.ChildNodes.Count == 1) { ApsimFile.Component childComp = thisComp.ChildNodes[0]; List <string> variableTypes = new List <string>(); LoadVariableTypes(Types.Instance.MetaDataNode("Factor", "FactorVariables"), variableTypes); if (variableTypes.Contains(childComp.Type.ToLower())) { Table = CreateTable(childComp); } } //gridManager.DataSourceTable = Table; gridManager.DataSource = Table; //Size the grid columns sensibly gridManager.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; foreach (DataGridViewColumn col in gridManager.Columns) { // It would be clearer to use the Column.GetPreferredWidth function, but this is // broken on Mono (always returns 0), so instead we can temporarily let the column // auto-size itself, get it's width, then turn off auto-sizing and apply the width. // We don't want to leave auto-sizing on, since that disables the user's ability // to resize the columns col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; int w = col.Width; col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; col.Width = w; col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; } if (gridManager.Columns.Count > 3) { //gridManager.Columns[1].Visible = false; //gridManager.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; gridManager.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; } }
private void OnAfterEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { // --------------------------------------------------- // User has just finished editing the label of a node. // --------------------------------------------------- if (!FirstTimeRename) { if ((e.Label != null)) { //Check user typed something in. So you are not trying to rename it to a blank. if ((e.Label.Length > 0)) { if (!(CSGeneral.Utility.CheckForInvalidChars(e.Label))) { // Firstly empty the current selections. Controller.SelectedFactorialPath = ""; // Change the data ApsimFile.Component Comp = Controller.ApsimData.Find(GetPathFromNode(e.Node)); Comp.Name = e.Label; // Now tell the base controller about the new selections. Controller.SelectedFactorialPath = Comp.FullPath; } else { MessageBox.Show("You can not use characters such as < > / \\ ' \" ` : ? | * & = ! . or space in the name"); e.CancelEdit = true; //cancel the edit event. } } else { e.CancelEdit = true; //cancel the edit event. } } LabelEdit = false; } FirstTimeRename = false; this.ContextMenuStrip.Enabled = true; }
public List <DataTable> FindDataSources(ApsimFile.Component C, List <string> DefaultFileNames) { List <DataTable> DataSources = new List <DataTable>(); DataProcessor Processor = new DataProcessor(); Processor.DefaultOutputFileNames = DefaultFileNames; foreach (ApsimFile.Component Child in C.ChildNodes) { XmlDocument Doc = new XmlDocument(); Doc.LoadXml(Child.FullXMLNoShortCuts()); DataTable Table = Processor.Go(Doc.DocumentElement, ""); if (Table != null) { DataSources.Add(Table); } } return(DataSources); }
public override void OnRefresh() { // ----------------------------------------------- // Called when it's time to refresh the canvas and // everything on it. // ----------------------------------------------- base.OnRefresh(); DataGrid.DataSource = null; DataProcessor Processor = new DataProcessor(); if (Controller.Selection.Type == "ReportDb") { ApsimFile.Component Simulation = ApsimFile.ComponentUtility.FindComponentWithinScopeOf(Controller.Selection, "simulation"); if (Simulation != null) { string FileName = Path.Combine(Path.GetDirectoryName(Controller.ApsimData.FileName), Simulation.Name + "-" + Controller.Selection.Name + ".db"); Processor.DefaultOutputFileNames.Add(FileName); } } else { List <string> DefaultFileNames = new List <string>(); UIUtility.OutputFileUtility.GetOutputFiles(Controller, Controller.Selection, DefaultFileNames); Processor.DefaultOutputFileNames = DefaultFileNames; } XmlDocument Doc = new XmlDocument(); Doc.LoadXml(Controller.ApsimData.Find(NodePath).FullXML()); DataGrid.DataSource = Processor.Go(Doc.DocumentElement, NodePath); foreach (DataGridViewColumn Col in DataGrid.Columns) { Col.SortMode = DataGridViewColumnSortMode.NotSortable; } }
private void CreateViews(ApsimFile.Component Comp) { // ---------------------------------------------------- // Create a view for the specified component and add // it to the list of views that we'll display later. // ---------------------------------------------------- foreach (ApsimFile.Component Child in Comp.ChildNodes) { CreateViews(Child); } if (Comp.Type == "GDApsimFileReader") { // Auto populate the ApsimFileReader with the filenames in the response file. string FileReaderContents = "<GDApsimFileReader name=\"ApsimFileReader\">"; foreach (string FileName in OutputFileNames) { FileReaderContents += "<FileName>" + FileName + "</FileName>"; } FileReaderContents += "</GDApsimFileReader>"; Comp.Contents = FileReaderContents; } if (Comp.Type != "Graph") { if (Comp.Type == "GDApsimFileReader" && OutputFileNames.Count > 0) { // No need to put the file reader in the wizard as it already has filenames. return; } BaseView View = Controller.CreateUI(Comp.Type); if (View != null && View.GetType().ToString() != "CSUserInterface.EmptyUI") { Views.Add(View); Components.Add(Comp); } } }
private void TreeView_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { // -------------------------------------------------- // User has dragged a node over us - allow drop? // -------------------------------------------------- //Make sure you are actually dragging something //check the "data" Drag Event Argument if (e.Data.GetDataPresent(typeof(System.String))) { //If the mouse is currently dragging over a node and not over blank area Point pt = PointToClient(new Point(e.X, e.Y)); //get the drop location TreeNode DestinationNode = GetNodeAt(pt); //find the node closest to the drop location if ((DestinationNode != null)) { //Work out the type of left drag this is (copy, move, create link/shortcut), and store it in the "Effect" Drag Event Argument string FullXML = (string)e.Data.GetData(DataFormats.Text); Debug.Print("drop = " + FullXML); ApsimFile.Component DropComp = Controller.ApsimData.Find(GetPathFromNode(DestinationNode)); //get the corresponding component for the destination node. // //If DropComp.AllowAdd(FullXML) Then 'if allowed to drop this node onto this destination node //If Not IsNothing(PathsBeingDragged) AndAlso PathsBeingDragged.Count > 0 Then e.Effect = DragDropEffects.Copy; //End If //Else 'if NOT allowed to drop this node onto this destination node //e.Effect = DragDropEffects.None 'display circle with line through it symbol } else { e.Effect = DragDropEffects.None; //display circle with line through it symbol } } }
public override void OnRefresh() { base.OnRefresh(); XmlDocument Doc = new XmlDocument(); Doc.LoadXml(Controller.Selection.FullXML()); AllData = Doc.DocumentElement; Panel.Controls.Clear(); foreach (XmlNode GraphNode in XmlHelper.ChildNodes(AllData, "")) { string GraphNodePath = NodePath + "/" + XmlHelper.Name(GraphNode); ApsimFile.Component Comp = Controller.ApsimData.Find(GraphNodePath); if (GraphNode.Name == "Graph") { GraphUI Graph = new GraphUI(); Graph.Parent = Panel; Graph.OnLoad(Controller, GraphNodePath, Comp.Contents); } if (GraphNode.Name == "Graph2") { GraphUI2 Graph = new GraphUI2(); Graph.Parent = Panel; Graph.OnLoad(Controller, GraphNodePath, Comp.Contents); } if (GraphNode.Name == "RegressionGraph") { RegressionGraphUI Graph = new RegressionGraphUI(); Graph.Parent = Panel; Graph.OnLoad(Controller, GraphNodePath, Comp.Contents); } } PositionAndRefreshGraphs(); }
void Save() { ApsimFile.Component C = Controller.ApsimData.Find(NodePath); C.Contents = Data.OuterXml; }
public DataTable CreateTable(ApsimFile.Component childComp) { DataTable Table = new DataTable(); XmlNodeList uiNodes = childComp.ContentsAsXML.SelectNodes("//ui/* | //CustomUI/*"); bool isManager = true; if (uiNodes.Count == 0) { uiNodes = childComp.ContentsAsXML.ChildNodes; isManager = false; } bool useSingleColumnTable = uiNodes.Count == 1 || childComp.Type == "siloinput"; if (useSingleColumnTable) { csvLabel.Visible = false; XmlNodeList foundNodes = Data.SelectNodes("//vars/" + uiNodes[0].Name); string[] values = null; if (foundNodes.Count == 1) { values = foundNodes[0].InnerText.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } else { values = new string[0]; } DataTableUtility.AddColumn(Table, uiNodes[0].Name, values); // If there is only 1 variable, then turn the table into lots of rows so that the user can // enter one value per row rather than all on one line csv style. for (int i = 0; i < 10000; i++) { Table.Rows.Add(Table.NewRow()); } } else { csvLabel.Visible = true; Table.Columns.Add(" ", typeof(System.Boolean)); Table.Columns.Add("names", typeof(string)); Table.Columns.Add("Variables", typeof(string)); Table.Columns.Add("Parameters", typeof(string)); foreach (XmlNode ui in uiNodes) { DataRow newRow = Table.NewRow(); newRow[0] = false; string varName = ""; string text = ""; if (isManager) { varName = ui.Name; if (ui.Attributes["description"] != null) { text = ui.Attributes["description"].Value; } else { text = varName; } } else { varName = XmlHelper.Name(ui); } newRow[1] = varName; newRow[2] = text; newRow[3] = ui.InnerText; //look for corresponding node in the variables node if (varName != "#comment") { XmlNodeList foundNodes = Data.SelectNodes("//vars/" + varName); if (foundNodes.Count == 1) { XmlNode varNode = foundNodes[0]; if (varNode != null) { newRow[0] = true; newRow[3] = varNode.InnerText; } } Table.Rows.Add(newRow); } } } return(Table); }
private void OnRefresh(ApsimFile.Component Comp) { //This should only happen if the user opens a file /or new file that doesn't have a Factorial Component if ((Controller.ApsimData.FactorComponent == null) && Controller.FactorialMode) { Controller.FactorialMode = false; return; } // ---------------------------------------------- // Do a refresh from the specified Comp down // ---------------------------------------------- System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; //set the cursor object (usually an arrow) to the wait cursor (usually an hourglass) BeginUpdate(); //inbuilt tree function, it disables redrawing of the tree try { if (Controller.ApsimData.FactorComponent == null) { Nodes.Clear(); //get rid of all the nodes in the tree } else { //If (the tree has no nodes) OR (Comp [the component parameter this sub was passed] is Null) if ((Nodes.Count == 0) || (Comp == null)) { Nodes.Clear(); //get rid of all the nodes in the tree TreeNode RootNode = Nodes.Add(Controller.ApsimData.FactorComponent.Name); //create the root node from the root component and add it to the tree. RefreshNodeAndChildren(RootNode, Controller.ApsimData.FactorComponent); //refresh the tree from the root node down. } else { TreeNode NodeToRefresh = GetNodeFromPath(Comp.FullPath); //get the corresponding node for the component this sub was passed //return the corresponding component to the node that was selected. //if you have switched from one toolbox to another toolbox, then even though the components exist to do the refresh, the corresponding nodes do not yet exist because this OnRefresh is supposed to provide them. So GetNodeFromPath will return Nothing. if ((NodeToRefresh == null)) { RefreshNodeAndChildren(Nodes[0], Controller.ApsimData.FactorComponent); //refresh the tree from this node down. } else { RefreshNodeAndChildren(NodeToRefresh, Comp); //refresh the tree from this node down. } } } } catch (Exception) { EndUpdate(); //inbuilt tree function, reinables redrawing of the tree System.Windows.Forms.Cursor.Current = Cursors.Default; //set the cursor object back to the default windows cursor (usually an arrow) throw; } EndUpdate(); //inbuilt tree function, reinables redrawing of the tree System.Windows.Forms.Cursor.Current = Cursors.Default; //set the cursor object back to the default windows cursor (usually an arrow) }