Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public override void Process(Component Simulation, string prefix, SortedDictionary <string, string> factorsToMatch)
 {
     foreach (string par in Parameters)
     {
         if (factorsToMatch.Contains(new KeyValuePair <string, string>((Builder.useFQKeys ? pfx(prefix) + FactorComponent.Name + "." : "") + Variable.Name, par)))
         {
             //replace each target that is within the provided simulation with the child's xml
             foreach (string target in Targets)
             {
                 string    sRelativeTarget = target.Substring(target.IndexOf(Simulation.Name) + Simulation.Name.Length + 1);
                 Component targetComp      = Simulation.Find(sRelativeTarget);
                 if (targetComp != null)
                 {
                     //find name of var in ui or CustomUI nodes
                     XmlNode variablesNode = targetComp.ContentsAsXML;
                     XmlNode varNode       = variablesNode.SelectSingleNode("//ui/" + Variable.Name + " | " + "//CustomUI/" + Variable.Name);
                     if (varNode != null)
                     {
                         varNode.InnerText = par;
                     }
                     else
                     {
                         string sSelect = "//property[@name='" + Variable.Name + "']";
                         varNode = variablesNode.SelectSingleNode(sSelect);
                         if (varNode == null)
                         {
                             sSelect = "//" + Variable.Name;
                             varNode = variablesNode.SelectSingleNode(sSelect);
                         }
                         if (varNode != null)
                         {
                             varNode.InnerText = par;
                         }//TODO if else then record as an error
                     }
                     targetComp.Contents = variablesNode.OuterXml;
                 }
                 else
                 {
                     throw new Exception("target " + target + ", rel path" + sRelativeTarget + " was not found in factor " + (Builder.useFQKeys ? pfx(prefix) + FactorComponent.Name + "." : "") + Variable.Name);
                 }
             }
         }
     }
     if (NextItem != null)
     {
         //call next factor in the list
         NextItem.Process(Simulation, prefix, factorsToMatch);
     }
 }
Exemplo n.º 4
0
 public virtual void Process(Component Simulation, string prefix, SortedDictionary <string, string> factorsToMatch)
 {
     if (FactorComponent.Type != "folder")
     {
         foreach (Component child in FactorComponent.ChildNodes)
         {
             if (factorsToMatch.Contains(new KeyValuePair <string, string>(pfx(prefix) + FactorComponent.Name, child.Name)))
             {
                 //replace each target that is within the provided simulation with the child's xml
                 foreach (string target in Targets)
                 {
                     //need to remove the path of this simulation from the target to get the relative path
                     string    relativePath = target.Substring(target.IndexOf(Simulation.FullPath) + Simulation.FullPath.Length + 1);
                     Component targetComp   = Simulation.Find(relativePath);
                     if (targetComp != null)
                     {
                         //replace target nodes with factor nodes - add child factor nodes if they don't exist
                         //don't remove any children from the target
                         ReplaceComponent(targetComp, child);
                     }
                     else
                     {
                         throw new Exception("target " + target + ", path " + relativePath + " was not found in factor " + pfx(prefix) + FactorComponent.Name);
                     }
                 }
             }
         }
         if (NextItem != null)
         {
             NextItem.Process(Simulation, prefix, factorsToMatch);
         }
     }
     else
     {
         if (factorsToMatch.Contains(new KeyValuePair <string, string>(FactorComponent.Name, FolderLevel)))
         {
             if (NextItem != null)
             {
                 //call next factor in the list
                 NextItem.Process(Simulation, (Builder.useFQKeys ? pfx(prefix) + FactorComponent.Name + "." + FolderLevel : ""), factorsToMatch);
             }
         }
     }
 }
Exemplo n.º 5
0
 public void ConvertToShortcutsUsingBase(Component Base)
 {
     if (ShortCutTo == null)
     {
         // If this node is a simulation or paddock then link the simulation and
         // not worry about the different name. The call to IsEqual below will
         // test the name attributes and find them different.
         if (Type == "area" || Type == "simulation" || XmlHelper.IsEqual(ContentsAsXML, Base.ContentsAsXML))
         {
             MyContents   = "";
             MyShortCutTo = Base;
         }
     }
     foreach (Component Child in ChildNodes)
     {
         Component RelatedBaseComponent = Base.Find(Child.Name);
         if (RelatedBaseComponent != null)
         {
             Child.ConvertToShortcutsUsingBase(RelatedBaseComponent);
         }
     }
 }