Exemple #1
0
        private void PopulateConstants()
        {
            //Clear out all the old stuff because these UI's are reused by other nodes of the same type.
            ConstantsBox.Clear();
            //Fill it in with the new stuff from this node.
            List <string> Lines = new List <string>();

            ApsimFile.Component outputfileComponent = Controller.ApsimData.Find(NodePath).Parent;
            string FileName = ComponentUtility.CalcFileName(outputfileComponent);

            TitleLabel.Text = "(readonly) Title = " + Path.GetFileNameWithoutExtension(FileName);

            XmlNode ConstantsNode = XmlHelper.Find(Data, "constants");

            if ((ConstantsNode != null))
            {
                foreach (XmlNode Constant in XmlHelper.ChildNodes(ConstantsNode, ""))
                {
                    string ConstantName = XmlHelper.Name(Constant);
                    if (ConstantName.ToLower() != "title")
                    {
                        Lines.Add(ConstantName + " = " + Constant.InnerText);
                    }
                }
            }
            ConstantsBox.Lines = Lines.ToArray();
        }
Exemple #2
0
        protected override void OnLoad()
        {
            base.OnLoad();

            // We need not just the XML for this profile node but the whole soil XML.
            OurComponent = Controller.ApsimData.Find(NodePath);
            ApsimFile.Component SoilComponent;
            if (OurComponent.Parent.Type == "factor")
            {
                XmlNode factorNode    = OurComponent.Parent.ContentsAsXML;
                string  initWaterPath = XmlHelper.Value(factorNode, "targets/target");
                int     posLastSlash  = initWaterPath.LastIndexOf('/');
                if (posLastSlash != -1)
                {
                    string soilPath = initWaterPath.Remove(posLastSlash);
                    SoilComponent = Controller.ApsimData.Find(soilPath);
                }
                else
                {
                    throw new Exception("Cannot find soil node under: " + OurComponent.FullPath);
                }
            }
            else
            {
                SoilComponent = OurComponent.Parent;
            }

            if (SoilComponent.Type.ToLower() != "soil")
            {
                SoilComponent = SoilComponent.Parent;
            }
            if (SoilComponent.Type.ToLower() != "soil")
            {
                throw new Exception("Cannot find soil node under: " + OurComponent.FullPath);
            }

            XmlDocument soilDoc = new XmlDocument();

            soilDoc.LoadXml(SoilComponent.FullXMLNoShortCuts());

            if (OurComponent.Parent.Type == "factor")
            {
                // Install this InitWater under the Soil, replacing the existing one.
                XmlNode existingInitWater = XmlHelper.FindByType(soilDoc.DocumentElement, "InitialWater");
                if (existingInitWater == null)
                {
                    throw new Exception("Cannot find InitWater under soil");
                }
                soilDoc.DocumentElement.RemoveChild(existingInitWater);
                soilDoc.DocumentElement.AppendChild(soilDoc.ImportNode(OurComponent.ContentsAsXML, true));
            }



            Soil = Soil.Create(soilDoc.OuterXml);

            RelativeToCombo.Items.Clear();
            RelativeToCombo.Items.Add("ll15");
            RelativeToCombo.Items.AddRange(Soil.Water.CropNames);
        }
Exemple #3
0
        public static void Rename(BaseController Controller)
        {
            // --------------------------------------------------------
            // Rename selected nodes
            // --------------------------------------------------------

            foreach (string SelectedPath in Controller.SelectedPaths)
            {
                //get the new name the user entered
                string NewName = UIBits.InputDialog.InputBox("Enter new name for node:", "Rename the selected node", Controller.Selection.Name, false);

                //set rename the selected node

                if (!String.IsNullOrEmpty(NewName))
                {
                    if (!CSGeneral.Utility.CheckForInvalidChars(NewName))
                    {
                        ApsimFile.Component Comp = Controller.ApsimData.Find(SelectedPath);
                        Comp.Name = NewName;
                        // Now tell the base controller about the new selections.
                        Controller.SelectedPath = Comp.FullPath;
                    }
                    else
                    {
                        MessageBox.Show("You can not use characters such as < > / \\ ' \" ` : ? | * & = ! . , or space in the name");
                    }
                }
            }
        }
Exemple #4
0
        public static void Delete(BaseController Controller)
        {
            // --------------------------------------------------------
            // Delete selected nodes
            // --------------------------------------------------------
            System.Collections.Specialized.StringCollection PathsToDelete = Controller.SelectedPaths;

            string ParentSelection = Controller.SelectedPaths[0];

            foreach (string SelectedPath in PathsToDelete)
            {
                if (ParentSelection.IndexOf(SelectedPath) == 0)
                {
                    ParentSelection = SelectedPath;
                }
            }
            ApsimFile.Component Selection = Controller.ApsimData.Find(ParentSelection);
            Controller.SelectedPath = Selection.Parent.FullPath;

            foreach (string SelectedPath in PathsToDelete)
            {
                ApsimFile.Component CompToDelete = Controller.ApsimData.Find(SelectedPath);
                CompToDelete.Parent.Delete(CompToDelete);
            }
            Controller.Explorer.RefreshCurrentView();
        }
        public static string GetCSVListOfOutputFiles(BaseController Controller)
        {
            // ---------------------------------------------------------------
            // Return to caller a list of all output files that the user has
            // selected to export. Returns "" if user hits cancel.
            // ---------------------------------------------------------------
            List <string> OutputFiles = new List <string>();

            foreach (string SelectedNodePath in Controller.SelectedPaths)
            {
                ApsimFile.Component SelectedData = Controller.ApsimData.Find(SelectedNodePath);
                while (SelectedData.Type != "simulation" && SelectedData.Type != "folder" && SelectedData.Type != "simulations")
                {
                    SelectedData = SelectedData.Parent;
                }
                GetOutputFiles(Controller, SelectedData, OutputFiles);
            }
            string ReturnString = "";

            foreach (string St in OutputFiles)
            {
                if (!string.IsNullOrEmpty(ReturnString))
                {
                    ReturnString += ",";
                }
                ReturnString += St;
            }
            return(ReturnString);
        }
        /// <summary>
        /// Form is being refreshed.
        /// </summary>
        public override void OnRefresh()
        {
            InRefresh = true;
            ApsimFile.Component Comp = Controller.ApsimData.Find(NodePath);

            // set the banner image correctly.
            this.PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;

            string imagefile = Types.Instance.MetaData(Comp.Type, "image");

            if (!string.IsNullOrEmpty(imagefile) && File.Exists(imagefile))
            {
                PictureBox.Image   = System.Drawing.Image.FromFile(imagefile);
                PictureBox.Visible = true;
            }
            else
            {
                PictureBox.Visible = false;
            }
            this.PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;

            // Look for a memo control and enable the TextBox if it exists.

            MemoComponent    = Comp.Find("Memo");
            TextBox.Visible  = (MemoComponent != null);
            Splitter.Visible = (MemoComponent != null);
            if ((MemoComponent != null))
            {
                XmlDocument Doc = new XmlDocument();
                Doc.LoadXml(MemoComponent.Contents);
                TextBox.Text = Doc.DocumentElement.InnerText;
            }

            // Create a DataTable from our data.
            DataTable Table = CreateTable();

            // Give the DataTable to our grid.
            Grid.DataSourceTable = Table;

            // Size the grid columns sensibly
            Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            for (int Col = 0; Col <= Table.Columns.Count - 1; Col++)
            {
                //Grid.Columns(Col).Width = Grid.Columns(Col).GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, True)
                Grid.Columns[Col].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            }
            Grid.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            Grid.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            int prefWidth = Grid.Columns[4].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);

            if (prefWidth > 5)
            {
                Grid.Columns[4].MinimumWidth = prefWidth;
            }
            Grid.AutoResizeRows(DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders);

            IsDirty = false;
            GotoEditMode(false);
            InRefresh = false;
        }
        /// <summary>
        /// User has clicked the check button - display any errors found in soil.
        /// </summary>
        private void CheckButton_Click(object sender, EventArgs e)
        {
            OnSave();
            bool inSimulation = false;

            OurComponent = Controller.ApsimData.Find(NodePath);
            ApsimFile.Component parent = OurComponent.Parent;
            while (parent != null && !inSimulation)
            {
                if (parent.Type.ToLower() == "simulation")
                {
                    inSimulation = true;
                }
                parent = parent.Parent;
            }

            //string Msg = Soil.Check(Configuration.Instance.ApplicationName != "ApsimUI");
            string Msg = Soil.Check(!inSimulation);

            if (Msg == "")
            {
                MessageBox.Show("No errors found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(Msg, "Soil Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #8
0
        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.SelectedPaths.IndexOf(GetPathFromNode((TreeNode)e.Item)) == -1)
            {
                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.
            //get the full xml of all the selected nodes that are getting dragged
            foreach (string SelectedPath in Controller.SelectedPaths)
            {
                ApsimFile.Component Comp = Controller.ApsimData.Find(SelectedPath);
                //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 = Controller.SelectedPaths;
            //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 | DragDropEffects.Move | DragDropEffects.Link);
            //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]).
        }
Exemple #9
0
        public static void ExportToSoils(BaseController Controller)
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter     = "Soils files (*.soils)|*.soils|All files (*.*)|*.*";
            Dialog.Title      = "Enter a .soils file to export to";
            Dialog.DefaultExt = "soils";
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                XmlDocument Doc = new XmlDocument();
                if (!File.Exists(Dialog.FileName))
                {
                    Doc.AppendChild(XmlHelper.CreateNode(Doc, "soils", ""));
                }
                else
                {
                    Doc.Load(Dialog.FileName);
                }

                foreach (string SelectedPath in Controller.SelectedPaths)
                {
                    ApsimFile.Component Comp    = Controller.ApsimData.Find(SelectedPath);
                    XmlDocument         NodeDoc = new XmlDocument();
                    NodeDoc.LoadXml(Comp.FullXML());
                    Doc.DocumentElement.AppendChild(Doc.ImportNode(NodeDoc.DocumentElement, true));
                }
                XmlHelper.SetAttribute(Doc.DocumentElement, "version", ApsimFile.APSIMChangeTool.CurrentVersion.ToString());
                Doc.Save(Dialog.FileName);
                MessageBox.Show("Soils have been successfully exported to '" + Dialog.FileName + "'. It is suggested that you rename soils within the new file to avoid confusion.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #10
0
        // --------------------------------------------------------
        // User is trying to initiate a drag - allow drag operation
        // --------------------------------------------------------
        private void ListView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
        {
            ApsimFile.Component Comp         = Controller.ApsimData.Find(NodePath);
            ApsimFile.Component SelectedComp = Comp.Find(ListView.SelectedItems[0].Text);
            string DataString = SelectedComp.FullXML();

            ListView.DoDragDrop(DataString, DragDropEffects.All);
        }
        public ComponentVE(ApsimFile.Component c)
        {
            name = c.Name;
            type = c.Type.ToLower();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(c.FullXMLNoShortCuts());
            manager2script = XmlHelper.Value(doc.FirstChild, "text");
        }
Exemple #12
0
        public override void OnRefresh()
        {
            treeSims.Nodes.Clear();
            FactorBuilder builder   = new FactorBuilder();
            List <string> SimsToRun = new List <string>();

            ApsimFile.ApsimFile.ExpandSimsToRun(Controller.ApsimData.RootComponent, ref SimsToRun);
            double iTotalCount = 0;

            foreach (string SimulationPath in SimsToRun)
            {
                int tmpCounter = 0;
                ApsimFile.Component tmpComp = Controller.ApsimData.Find(SimulationPath);
                if (tmpComp != null)
                {
                    List <string> factorials = ApsimFile.Factor.CalcFactorialList(Controller.ApsimData, SimulationPath);
                    TreeNode      treeNode   = treeSims.Nodes.Add(tmpComp.Name + " (" + factorials.Count.ToString() + ")");
                    treeNode.ImageIndex         = 0;
                    treeNode.SelectedImageIndex = 0;
                    AddFactorsToTreeNode(treeNode, factorials);
                    tmpCounter += factorials.Count;
                }
                iTotalCount      += tmpCounter;
                txtTotalSims.Text = iTotalCount.ToString();
            }
            //double tmp = treeSims.Nodes[0].Nodes.Count;
            XmlNode varNode = Data.SelectSingleNode("//settings");

            if (XmlHelper.Attribute(varNode, "fn") == "1")
            {
                radDesc.Checked = true;
            }
            else
            {
                radCount.Checked = true;
            }

            if (XmlHelper.Attribute(varNode, "tl") == "1")
            {
                radMultiple.Checked = true;
            }
            else
            {
                radSingle.Checked = true;
            }

            if (XmlHelper.Attribute(varNode, "fqKeys") == "1")
            {
                fqKeys.Checked = true;
            }
            else
            {
                fqKeys.Checked = false;
            }
        }
Exemple #13
0
        /// <summary>
        /// Go locate all DateFilter components. Uses recursion.
        /// </summary>
        private void FindAllRecursively(ApsimFile.Component Comp, string Name, ref List <ApsimFile.Component> DateFilterComponents)
        {
            if (Comp.Name == Name)
            {
                DateFilterComponents.Add(Comp);
            }

            foreach (ApsimFile.Component Child in Comp.ChildNodes)
            {
                FindAllRecursively(Child, Name, ref DateFilterComponents);
            }
        }
Exemple #14
0
        /// <summary>
        /// Refresh this report. This method will create a worker thread to animate the graphs.
        /// </summary>
        public override void OnRefresh()
        {
            // Refresh the base report.
            base.OnRefresh();

            // Make sure play is selected by default.
            OnPlayClick(null, null);
            Quit    = false;
            Forward = true;

            // Find our ApsimFile.Component class. We'll need this to get the XML we're
            // working with and to find all DateFilter components underneath this report.
            OurComponent = Controller.ApsimData.Find(NodePath);

            // Go create a DataProcessor object. We'll need this to find some data later.
            Doc = new XmlDocument();
            Doc.LoadXml(OurComponent.FullXMLNoShortCuts());
            DataProcessor Processor        = new DataProcessor();
            List <string> DefaultFileNames = new List <string>();

            UIUtility.OutputFileUtility.GetOutputFiles(Controller, Controller.Selection, DefaultFileNames);
            Processor.DefaultOutputFileNames = DefaultFileNames;

            // Now go and try to find some data. We need data so that we can determine the
            // start and end period for the animation.
            DataTable PlotData = null;

            foreach (XmlNode Child in Doc.DocumentElement.ChildNodes)
            {
                PlotData = Processor.Go(Child, "");
                if (PlotData != null)
                {
                    break;
                }
            }

            // If some data was found then work out the start and end date periods, locate
            // all child DataFilter nodes, and create a worker thread for the animation.
            if (PlotData != null && PlotData.Rows.Count > 0)
            {
                StartDate   = DataTableUtility.GetDateFromRow(PlotData.Rows[0]);
                EndDate     = DataTableUtility.GetDateFromRow(PlotData.Rows[PlotData.Rows.Count - 1]);
                Period      = EndDate - StartDate;
                CurrentDate = StartDate;

                // Go find all DateFilter components - we'll need them later.
                DateFilterNodes = new List <ApsimFile.Component>();
                FindAllRecursively(OurComponent, "DateFilter", ref DateFilterNodes);

                WorkerThread = new Thread(DoAnimation);
                WorkerThread.Start();
            }
        }
        public static void CreateDuplicates(BaseController Controller)
        {
            UIBits.DuplicateForm f = new UIBits.DuplicateForm();
            if (f.ShowDialog() == DialogResult.OK)
            {
                ApsimFile.Component Comp = Controller.Selection;

                for (int i = 1; i <= f.NumDuplicates; i++)
                {
                    Comp.Parent.Duplicate(Comp, f.DoLinkDuplicates);
                }
            }
        }
Exemple #16
0
 private static void GetListOfComponentsToPrint(BaseController Controller, ApsimFile.Component Component)
 {
     if ((Component.Type == "Graph") || (Component.Type == "RegressionGraph") || (Component.Type == "GraphReport") || (Component.Type == "memo"))
     {
         ComponentsToPrint.Add(Component.FullPath);
     }
     else
     {
         foreach (ApsimFile.Component Child in Component.ChildNodes)
         {
             GetListOfComponentsToPrint(Controller, Child);
         }
     }
 }
        private void OnLoad(object sender, EventArgs e)
        {
            if (!InOnLoad)
            {
                InOnLoad = true;
                Selected = Controller.ApsimData.Find(Controller.SelectedPath);

                ComponentVE.GetVisibleComponents(Selected, ref MyComponents);

                PopulateComponentFilter();
                PopulateVariableListView();
                InOnLoad = false;
            }
        }
Exemple #18
0
        public static void MoveDown(BaseController Controller)
        {
            // --------------------------------------------------------
            // Move all selected items down
            // --------------------------------------------------------
            List <string> PathsToMove = new List <string>();

            foreach (string SelectedPath in Controller.SelectedPaths)
            {
                PathsToMove.Add(SelectedPath.Substring(SelectedPath.LastIndexOf(XmlHelper.Delimiter) + 1));
            }
            ApsimFile.Component Parent = Controller.ApsimData.Find(Controller.SelectedPaths[0]).Parent;
            Parent.MoveDown(PathsToMove);
        }
 static private void GetSiblingComponents(ApsimFile.Component component, ref List <ComponentVE> Components)
 {
     foreach (ApsimFile.Component Sibling in component.ChildNodes)
     {
         if (Types.Instance.Dlls(Sibling.Type).Count() > 0)
         {
             Components.Add(new ComponentVE(Sibling));
         }
         if (Sibling.Type == "folder")
         {
             GetSiblingComponents(Sibling, ref Components);
         }
     }
 }
Exemple #20
0
        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.
            if (Node.Text != Comp.Name)
            {
                Node.Text = Comp.Name;
            }
            Node.ImageIndex         = Controller.ImageIndex(Comp.Type, "SmallIcon");
            Node.SelectedImageIndex = Node.ImageIndex;
            Node.Tag = Comp.Type;
            if (DisplayNodeTypeInTree)
            {
                Node.ToolTipText = Comp.Type;
            }
            else
            {
                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.
            Node.Nodes.Clear();
            foreach (ApsimFile.Component Child in Comp.ChildNodes)
            {
                if (Child.Type != "factorial")
                {
                    TreeNode ChildTreeNode = Node.Nodes.Add(Child.Name);
                    RefreshNodeAndChildren(ChildTreeNode, Child);
                }
            }
        }
Exemple #21
0
 //create link
 private void DragLink()
 {
     //when you drag from datatree in simulation to datatree in a toolbox the PathsBeingDragged disappear and it causes an error. I have done this to avoid the error but creating a link does not really make sense in this situation anywhere. Instead just doing nothing makes more sense.
     if ((PathsBeingDragged != null))
     {
         //add all the dragged node as a link to the destination node
         foreach (string DraggedPath in PathsBeingDragged)
         {
             ApsimFile.Component Comp = Controller.ApsimData.Find(DraggedPath);
             if ((Comp != null) && !Comp.IsAncestorOf(Controller.Selection))
             {
                 Controller.Selection.AddShortCut(Comp);
                 //add one of the dragged nodes as a link to the destination node (destination node is stored as the current selection in the controller)
             }
         }
     }
 }
Exemple #22
0
        // ----------------------------------
        // Refresh the listview
        // ----------------------------------
        public override void OnRefresh()
        {
            panelArea.Visible = Data.Name.ToLower() == "area";

            ListView.Clear();
            ListView.LargeImageList = Controller.ImageList("LargeIcon");

            // Add an item for all children of this system.
            ApsimFile.Component Comp = Controller.ApsimData.Find(NodePath);
            if ((Comp != null))
            {
                foreach (ApsimFile.Component Child in Comp.ChildNodes)
                {
                    if (Child.Type != "factorial")
                    {
                        //create new item
                        ListViewItem item = new ListViewItem(Child.Name, 0);
                        item.ImageIndex = Controller.ImageIndex(Child.Type, "LargeIcon");
                        ListView.Items.Add(item);
                    }
                }


                // Put up a background bitmap on listview.
                XmlNode BitmapNode = XmlHelper.Find(Data, "bitmap");
                if ((BitmapNode != null))
                {
                    string TempFileName = Path.Combine(Path.GetTempPath(), "apsimui.jpg");
                    Bitmap b            = CSGeneral.BitmapUtility.DecodeStringToBitmap(BitmapNode.Value);
                    b.Save(TempFileName);
                    UIUtility.ListViewAPI.SetListViewImage(ListView, TempFileName, UIUtility.ImagePosition.TopLeft);
                }
            }
            textBoxArea.Text = "1.0";  // Default to a 1 ha area if none is provided
            if (panelArea.Visible && Data.HasChildNodes)
            {
                foreach (XmlNode Child in Data.ChildNodes)
                {
                    if (Child.Name.ToLower() == "paddock_area")
                    {
                        textBoxArea.Text = Child.InnerText;
                        break;
                    }
                }
            }
        }
Exemple #23
0
 //move
 private void DragMove(string FullXML)
 {
     Controller.Selection.Add(FullXML);
     //add the dragged nodes to the destination node (destination node is stored as the current selection in the controller)
     //when you drag from datatree in simulation to datatree in a toolbox the PathsBeingDragged disappear and it causes an error. I have done this to avoid the error but moving does not really make sense in this situation anyway. Instead just copying makes more sense.
     if ((PathsBeingDragged != null))
     {
         //delete all the dragged nodes from their original path.
         foreach (string DraggedPath in PathsBeingDragged)
         {
             ApsimFile.Component Comp = Controller.ApsimData.Find(DraggedPath);
             if ((Comp != null))
             {
                 Comp.Parent.Delete(Comp);
             }
         }
     }
 }
        static public void ExportSelectedToFile(string FileName, BaseController Controller)
        {
            Cursor.Current = Cursors.WaitCursor;

            File.Delete(FileName);
            DataTable Table = new DataTable("SoilData");
            int       Row   = 0;

            foreach (string SelectedPath in Controller.SelectedPaths)
            {
                ApsimFile.Component SoilComponent = Controller.ApsimData.Find(SelectedPath);
                XmlDocument         Doc           = new XmlDocument();
                Doc.LoadXml(SoilComponent.FullXML());
                CreateTableFromData(Doc.DocumentElement, Table, SelectedPath.Replace("/", "\\"), ref Row);
            }
            ExcelHelper.SendDataToSheet(FileName, "SoilData", Table);
            Cursor.Current = Cursors.Default;
        }
        private void OnTextChanged(object sender, EventArgs e)
        {
            try
            {
                List <string> FileNames = new List <string>();
                FileNames.AddRange(FileList.Lines);
                XmlHelper.SetValues(Data, "FileName", FileNames);
                ApsimFile.Component Comp = Controller.ApsimData.Find(NodePath);
                if (Comp != null)
                {
                    Comp.Contents = GetData();
                }

                OnRefresh();
            }
            catch (Exception)
            {
            }
        }
        // --------------------------------------------------
        // Return a list of sibling component names and types
        // for the specified data component
        // --------------------------------------------------
        static public void GetVisibleComponents(ApsimFile.Component component, ref List <ComponentVE> Components)
        {
            Components.Clear();
            List <ApsimFile.Component> heirarchy = new List <ApsimFile.Component>();

            ApsimFile.Component parent = component.Parent;
            while (parent != null)
            {
                if (parent.Type == "area" || parent.Type == "simulation")
                {
                    heirarchy.Insert(0, parent);
                }
                parent = parent.Parent;
            }
            foreach (ApsimFile.Component paddock in heirarchy)
            {
                GetSiblingComponents(paddock, ref Components);
            }
        }
        public static void LinkWherePossible(BaseController Controller)
        {
            Cursor.Current = Cursors.WaitCursor;
            ApsimFile.Component        Base     = Controller.Selection;
            List <ApsimFile.Component> Siblings = new List <ApsimFile.Component>();

            Base.Parent.FindRecursively(Base.Type, ref Siblings);

            foreach (ApsimFile.Component Sibling in Siblings)
            {
                if (Sibling.FullPath != Base.FullPath)
                {
                    Sibling.ConvertToShortcutsUsingBase(Base);
                }
            }
            Controller.ApsimData.PublishComponentChanged(Controller.ApsimData.RootComponent);

            Cursor.Current = Cursors.Default;
        }
 public static void GetSummaryFiles(BaseController Controller, ApsimFile.Component Data, List <string> OutputFiles)
 {
     // ------------------------------------------------------------
     //return an array of summary filenames under the specified data.
     // ------------------------------------------------------------
     if (Data != null)
     {
         while (Data.Type.ToLower() != "area" &&
                Data.Type.ToLower() != "simulation" &&
                Data.Type.ToLower() != "simulations" &&
                Data.Type.ToLower() != "folder" &&
                Data.Type.ToLower() != "outputfile" &&
                Data.Parent != null)
         {
             Data = Data.Parent;
         }
         GetSummaryFilesRecursively(Controller, Data, OutputFiles);
     }
 }
Exemple #29
0
 private static void CheckSoils(ApsimFile.Component Data, ref string ErrorMessage)
 {
     if (Data.Type.ToLower() == "soil")
     {
         Soil   ThisSoil = Soil.Create(Data.FullXML());
         string Errors   = ThisSoil.Check(true);
         if (!string.IsNullOrEmpty(Errors))
         {
             ErrorMessage += Environment.NewLine + Data.FullPath + Environment.NewLine + StringManip.IndentText(Errors, 6);
         }
     }
     else if (Data.Type.ToLower() == "folder")
     {
         foreach (ApsimFile.Component Child in Data.ChildNodes)
         {
             CheckSoils(Child, ref ErrorMessage);
         }
     }
 }
Exemple #30
0
        public static void DeleteFactor(BaseController Controller)
        {
            // --------------------------------------------------------
            // Delete selected nodes
            // --------------------------------------------------------
            ApsimFile.Component CompToDelete = Controller.FactorialSelection;
            //if this is the fatorial node and there is a project loaded, then you cannot delete it
            if ((CompToDelete.Parent == null) || (CompToDelete.Parent.Parent == null))
            {
                return;
            }

            // find next sibling, or previous sibling, or parent the set SelectedFactorialPath
            ApsimFile.Component CompToSelect = CompToDelete.Parent;

            Controller.SelectedFactorialPath = CompToSelect.FullPath;
            CompToDelete.Parent.Delete(CompToDelete);

            Controller.Explorer.RefreshCurrentView();
        }