Esempio n. 1
0
        /// <summary>
        /// Creates desktop from Xml documet
        /// </summary>
        /// <param name="document">The document</param>
        /// <param name="create">The create function</param>
        /// <returns>The desktop</returns>
        public static PureDesktopPeer LoadFromXml(this XmlDocument document, Func <XmlElement, object> create)
        {
            PureDesktopPeer desktop = new PureDesktopPeer();
            Dictionary <string, IObjectLabel> dictionary = new Dictionary <string, IObjectLabel>();
            XmlElement objs = document.GetElementsByTagName("Objects")[0] as XmlElement;

            foreach (XmlElement e in objs.ChildNodes)
            {
                string name = e.GetAttribute("Name");
                object o    = create(e);
                if (o == null)
                {
                    continue;
                }
                string t = o.GetType() + "";
                string k = "";
                if (t.Equals("DataPerformer.DataLink") | t.Equals("DataPerformer.VectorFormulaConsumer"))
                {
                    k = "Mv";
                }
                PureObjectLabelPeer l = new PureObjectLabelPeer(name, k, t, 0, 0);
                dictionary[name] = l;
                desktop.AddObjectLabel(l, o as ICategoryObject, true);
                l.Desktop = desktop;
            }
            XmlElement arrs = document.GetElementsByTagName("Arrows")[0] as XmlElement;

            foreach (XmlElement e in arrs.ChildNodes)
            {
                string         name = e.GetAttribute("Name");
                ICategoryArrow a    = create(e) as ICategoryArrow;
                if (a == null)
                {
                    continue;
                }
                string s = e.GetAttribute("Source");
                string t = e.GetAttribute("Target");
                if (!dictionary.ContainsKey(s) | !dictionary.ContainsKey(t))
                {
                    continue;
                }
                try
                {
                    desktop.AddArrowWithExistingLabels(a, dictionary[s], dictionary[t], name, "");
                }
                catch (Exception)
                {
                }
            }
            return(desktop);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets component name relatively desktop
 /// </summary>
 /// <param name="desktop">The desktop</param>
 /// <returns>Relalive name</returns>
 public override string GetName(IDesktop desktop)
 {
     return(PureObjectLabelPeer.GetName(this, desktop));
 }
Esempio n. 3
0
 /// <summary>
 /// Copies objects and arrows
 /// </summary>
 /// <param name="objects">Objects</param>
 /// <param name="arrows">Arrows</param>
 /// <param name="associated">Copy associated objects sign</param>
 public override void Copy(IEnumerable <IObjectLabel> objects, IEnumerable <IArrowLabel> arrows, bool associated)
 {
     foreach (IObjectLabel l in objects)
     {
         string type = l.Type;
         string st   = l.Object.GetType() + "";
         if (!type.Equals(st))
         {
             //type = st;
         }
         PureObjectLabelPeer lp = new PureObjectLabelPeer(l.Name, l.Kind, type, l.X, l.Y);
         Type     t             = l.GetType();
         object[] o             = t.GetCustomAttributes(typeof(SerializableLabelAttribute), true);
         if (o != null)
         {
             if (o.Length > 0)
             {
                 IObjectLabelHolder lh = lp;
                 lh.Label = l;
             }
         }
         IObjectLabel lab = lp;
         lab.Object  = l.Object;
         lab.Desktop = this;
         this.objects.Add(lab);
         if (associated)
         {
             lab.Object.Object = lab;
         }
         table[l.Name] = lab;
     }
     //PureObjectLabel.Wrappers = false;
     foreach (IArrowLabel l in arrows)
     {
         PureArrowLabelPeer lp = new PureArrowLabelPeer(l.Name, l.Kind, l.Type, l.X, l.Y);
         Type     t            = l.GetType();
         object[] o            = t.GetCustomAttributes(typeof(SerializableLabelAttribute), true);
         if (o != null)
         {
             if (o.Length > 0)
             {
                 IArrowLabelHolder lh = lp;
                 lh.Label = l;
             }
         }
         IArrowLabel lab = new PureArrowLabelPeer(l.Name, l.Kind, l.Type, l.X, l.Y);
         lab.Arrow = l.Arrow;
         if (associated)
         {
             lab.Arrow.Object = lab;
         }
         lab.Desktop = this;
         this.arrows.Add(lab);
         // components.Add(lab);
         table[l.Name] = lab;
         List <IObjectLabel> objs  = objects.ToList <IObjectLabel>();
         List <IObjectLabel> tobjs = this.Objects.ToList <IObjectLabel>();
         lab.Source = PureDesktop.Find(objs, tobjs, l.Source, l.Desktop);
         lab.Target = PureDesktop.Find(objs, tobjs, l.Target, l.Desktop);
     }
     if (!associated)
     {
         return;
     }
     this.SetParents();
     PureObjectLabel.SetLabels(objects);
     PureArrowLabel.SetLabels(arrows);
 }