Exemplo n.º 1
0
        public LimnorContextMenuCollection GetObjectMenuData(object obj)
        {
            LimnorXmlDesignerLoader2 l = this.Loader as LimnorXmlDesignerLoader2;
            UInt32 id = l.ObjectMap.GetObjectID(obj);

            if (_menuData == null)
            {
                _menuData = new Dictionary <UInt32, LimnorContextMenuCollection>();
            }
            LimnorContextMenuCollection data;

            if (!_menuData.TryGetValue(id, out data))
            {
                if (obj == l.RootObject)
                {
                    data = new LimnorContextMenuCollection(l.GetRootId());
                }
                else
                {
                    MemberComponentId mc = MemberComponentId.CreateMemberComponentId(l.GetRootId(), obj, id, null);
                    data = new LimnorContextMenuCollection(mc);
                }
                _menuData.Add(id, data);
            }
            return(data);
        }
Exemplo n.º 2
0
 public void OnPostSerialize(XmlSerializer.ObjectIDmap objMap, System.Xml.XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
     }
     else
     {
         if (_pointer == null && _memberPointer == null)
         {
             XmlNode node = SerializeUtil.GetClassRefNodeByObjectId(objectNode, _memberId);
             if (node != null)
             {
                 XmlObjectReader xr = (XmlObjectReader)serializer;
                 _pointer = xr.ReadObject <ClassInstancePointer>(node, ClassPointer.CreateClassPointer(objMap));
                 //_pointer.ObjectInstance = objMap.GetObjectByID(_pointer.MemberId);
             }
             else
             {
                 _pointer = objMap.GetClassRefById(_memberId) as ClassInstancePointer;
             }
         }
         if (_pointer == null)
         {
             object v = objMap.GetObjectByID(_memberId);
             if (v != null)
             {
                 _memberPointer = new MemberComponentId(objMap.GetTypedData <ClassPointer>(), v, _memberId);
             }
         }
         if (_pointer == null && _memberPointer == null)
         {
             objMap.AddPostProcessor(this);
         }
     }
 }
Exemplo n.º 3
0
 public ComponentPointer(MemberComponentId cid)
 {
     _memberPointer = cid;
     if (cid != null)
     {
         _memberId = cid.MemberId;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// It can be a ClassPointer, a MemberComponentId, or a TypePointer.
        ///
        /// </summary>
        /// <returns></returns>
        private IClass getActionExecuter()
        {
            IPropertySetter sp = ActionMethod as IPropertySetter;

            if (sp != null)
            {
                MemberComponentIdCustom c = sp.SetProperty.Holder as MemberComponentIdCustom;
                if (c != null)
                {
                    return(c.Pointer);
                }
                return(sp.SetProperty.Holder);
            }
            else
            {
                IObjectIdentity mp = ActionMethod.IdentityOwner;
                IMemberPointer  p  = ActionMethod as IMemberPointer;
                if (p != null)
                {
                    return(p.Holder);
                }
                MemberComponentIdCustom mcc = mp as MemberComponentIdCustom;
                if (mcc != null)
                {
                    return(mcc.Pointer);
                }
                MemberComponentId mmc = mp as MemberComponentId;
                if (mmc != null)
                {
                    return(mmc);
                }
                p = mp as IMemberPointer;
                if (p != null)
                {
                    return(p.Holder);
                }
                IObjectPointer op = mp as IObjectPointer;
                IClass         co = mp as IClass;
                while (co == null && op != null)
                {
                    op = op.Owner;
                    co = op as IClass;
                    p  = op as IMemberPointer;
                    if (p != null)
                    {
                        return(p.Holder);
                    }
                }
                if (co != null)
                {
                    return(co);
                }
                else
                {
                    throw new DesignerException("Cannot find holder for Action [{0}]", ActionId);
                }
            }
        }
        public void OnBeforeRead(XmlObjectReader reader, XmlNode node)
        {
            _reader       = reader;
            _xmlNode      = node;
            ScopeMethodId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ScopeId);
            SubScopeId    = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_SubScopeId);
            _varId        = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ComponentID);
            //load DataTypePointer from ComponentIconLocal
            ClassPointer root = reader.ObjectList.GetTypedData <ClassPointer>();

            _var = MemberComponentId.CreateMemberComponentId(root, root.ObjectList.GetObjectByID(_varId), _varId, null);
            adjustParamType();
        }
Exemplo n.º 6
0
 public override void OnPostSerialize(ObjectIDmap objMap, XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
     }
     else
     {
         if (MemberId == objMap.MemberId)
         {
             ClassPointer = objMap.GetTypedData <ClassPointer>();
         }
         else
         {
             ClassInstancePointer cr = DesignUtil.GetClassRef(WholeId, objMap);
             if (cr != null)
             {
                 ClassPointer = cr;
             }
             else
             {
                 object v = objMap.GetObjectByID(MemberId);
                 if (v == null)
                 {
                     if (objMap.Count == 0)
                     {
                     }
                     else
                     {
                         if (MemberId == 3667767822)
                         {
                             //it is the HtmlElement_body
                         }
                         else
                         {
                             //this time the object may not be available.
                         }
                     }
                 }
                 else
                 {
                     MemberComponentId mc = MemberComponentId.CreateMemberComponentId(objMap.GetTypedData <ClassPointer>(), v, MemberId, null);
                     ClassPointer = mc;
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
        public bool IsSameObjectRef(IObjectIdentity objectPointer)
        {
            ClassInstancePointer obj = objectPointer as ClassInstancePointer;

            if (obj != null)
            {
                return(this.WholeId == obj.WholeId);
            }
            MemberComponentId mc = objectPointer as MemberComponentId;

            if (mc != null)
            {
                ClassInstancePointer cr = mc.ObjectInstance as ClassInstancePointer;
                if (cr != null)
                {
                    return(this.WholeId == cr.WholeId);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        void miNewInstance_Click(object sender, EventArgs e)
        {
            MethodDiagramViewer mv = MethodViewer.GetCurrentViewer();

            if (mv != null)
            {
                MemberComponentId     lv  = this.ClassPointer as MemberComponentId;
                ActionAssignComponent act = new ActionAssignComponent(MethodViewer.Method.RootPointer);
                act.ActionOwner = lv;
                act.ActionId    = (UInt32)(Guid.NewGuid().GetHashCode());
                act.ActionName  = MethodViewer.RootClass.CreateNewActionName("Create" + lv.ObjectType.Name);
                Point p = mv.PointToClient(System.Windows.Forms.Cursor.Position);
                if (p.X < 0)
                {
                    p.X = 10;
                }
                if (p.Y < 0)
                {
                    p.Y = 10;
                }
                act.ValidateParameterValues();
                mv.AddNewAction(act, p);
            }
        }
Exemplo n.º 9
0
        public override object OnGetDropDownControl(ITypeDescriptorContext context, IServiceProvider provider, IWindowsFormsEditorService service, object value)
        {
            ComponentPointer cp = (ComponentPointer)value;
            IComponent       h  = context.Instance as IComponent;

            if (h == null || h.Site == null)
            {
                h = VPL.VPLUtil.GetObject(context.Instance) as IComponent;
            }
            if (h == null || h.Site == null)
            {
                ClassPointer root = context.Instance as ClassPointer;
                if (root != null)
                {
                    h = root.ObjectInstance as IComponent;
                }
            }
            if (h == null || h.Site == null)
            {
                IObjectPointer op = context.Instance as IObjectPointer;
                if (op != null)
                {
                    ClassPointer root = op.RootPointer;
                    if (root != null)
                    {
                        h = root.ObjectInstance as IComponent;
                    }
                }
            }
            if (h != null && h.Site != null)
            {
                ListBox list = new ListBox();
                list.Tag       = service;
                list.Click    += new EventHandler(list_Click);
                list.KeyPress += new KeyPressEventHandler(list_KeyPress);
                foreach (IComponent ic in h.Site.Container.Components)
                {
                    if (ic is T)
                    {
                        list.Items.Add(new ComponentName(ic));
                    }
                    else
                    {
                        Type t = VPL.VPLUtil.GetObjectType(ic);
                        if (typeof(T).IsAssignableFrom(t))
                        {
                            int n = list.Items.Add(new ComponentName(ic));
                            if (cp != null && list.SelectedIndex < 0 && ic.Site != null)
                            {
                                if (cp.Name == ic.Site.Name)
                                {
                                    list.SelectedIndex = n;
                                }
                            }
                        }
                    }
                }
                if (list.Items.Count > 0)
                {
                    service.DropDownControl(list);
                    if (list.SelectedIndex >= 0)
                    {
                        ComponentName c = list.Items[list.SelectedIndex] as ComponentName;
                        if (c != null)
                        {
                            ILimnorDesignerLoader loader = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader;
                            UInt32 memberId = loader.ObjectMap.GetObjectID(c.Component);
                            if (memberId != 0)
                            {
                                XmlNode nodeCr = SerializeUtil.GetClassRefNodeByObjectId(loader.Node, memberId);
                                if (nodeCr != null)
                                {
                                    loader.Reader.ResetErrors();
                                    ClassInstancePointer cr = loader.Reader.ReadObject <ClassInstancePointer>(nodeCr, loader.GetRootId());
                                    if (loader.Reader.HasErrors)
                                    {
                                        MathNode.Log(loader.Reader.Errors);
                                    }
                                    ComponentPointer pt = new ComponentPointer(cr);
                                    value = pt;
                                }
                                else
                                {
                                    MemberComponentId cid = new MemberComponentId(loader.GetRootId(), c.Component, memberId);
                                    ComponentPointer  pt  = new ComponentPointer(cid);
                                    value = pt;
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
Exemplo n.º 10
0
        /// <summary>
        /// remove invalid icons
        /// add missing icons
        /// make links
        /// </summary>
        /// <param name="eventPath"></param>
        public void OnLoadData(EventPath eventPath)
        {
            _owner = eventPath;
            //all icons saved in XML
            List <ComponentIconEvent> iconList = ComponentIconList;
            //all components, each corresponding to one icon
            ClassPointer  root    = _owner.Loader.GetRootId();
            List <IClass> objList = root.GetClassList();
            //all custom methods, each corresponding to one icon
            Dictionary <string, MethodClass> methods = root.CustomMethods;
            //all event handlers, each HandlerMathodID object corresponds to one icon
            List <EventAction> handlers = root.EventHandlers;
            //all custom properties
            Dictionary <string, PropertyClass> props = root.CustomProperties;
            //all used html elements
            IList <HtmlElement_BodyBase> htmlElements = null;

            if (root.IsWebPage)
            {
                htmlElements = root.UsedHtmlElements;
            }
            //
            //remove invalid icons
            List <ComponentIconEvent> iconInvalid = new List <ComponentIconEvent>();

            foreach (ComponentIconEvent ic in iconList)
            {
                if (!ic.OnDeserialize(root, _owner.Loader))
                {
                    iconInvalid.Add(ic);
                }
            }
            foreach (ComponentIconEvent ic in iconInvalid)
            {
                iconList.Remove(ic);
            }
            //remove invalid events. unknown reason causing invalid events
            foreach (ComponentIconEvent ic in iconList)
            {
                if (ic.MemberId != 0 && ic.GetType().Equals(typeof(ComponentIconEvent)))
                {
                    MemberComponentId mid0 = ic.ClassPointer as MemberComponentId;
                    if (mid0 != null)
                    {
                        List <EventIcon> eis = ic.EventIcons;
                        if (eis != null && eis.Count > 0)
                        {
                            List <EventIcon> invalidEis = new List <EventIcon>();
                            foreach (EventIcon ei in eis)
                            {
                                if (ei.Event != null)
                                {
                                    MemberComponentId mid = ei.Event.Owner as MemberComponentId;
                                    if (mid != null && mid.MemberId != 0)
                                    {
                                        if (mid.MemberId != ic.MemberId)
                                        {
                                            invalidEis.Add(ei);
                                        }
                                    }
                                }
                            }
                            foreach (EventIcon ei in invalidEis)
                            {
                                eis.Remove(ei);
                            }
                        }
                    }
                }
            }
            //
            //add new icons
            int x0 = 20;
            int y0 = 20;
            int x  = x0;
            int y  = y0;
            int dx = 30;
            int dy = 30;

            //add missing component icon
            foreach (IClass c in objList)
            {
                bool bFound = false;
                foreach (ComponentIconEvent ic in iconList)
                {
                    if (ic.IsForComponent)
                    {
                        if (ic.MemberId == c.MemberId)
                        {
                            ic.Designer = _owner.Loader;
                            bFound      = true;
                            break;
                        }
                    }
                }
                if (!bFound)
                {
                    ComponentIconEvent cip;
                    if (c is HtmlElement_Base)
                    {
                        cip = new ComponentIconHtmlElement();
                    }
                    else
                    {
                        cip = new ComponentIconEvent();
                    }
                    cip.Init(_owner.Loader, c);
                    cip.Location = new Point(x, y);
                    x           += dx;
                    x           += cip.Width;
                    if (x > _owner.Width)
                    {
                        x  = x0;
                        y += dy;
                        y += cip.Height;
                    }
                    iconList.Add(cip);
                }
            }
            ComponentIconEvent rootIcon = null;

            foreach (ComponentIconEvent ci in iconList)
            {
                if (ci.IsForComponent)
                {
                    if (ci.IsRootClass)
                    {
                        rootIcon = ci;
                        break;
                    }
                }
            }
            if (rootIcon == null)
            {
                throw new DesignerException("Root component icon not found for class {0}", root.ClassId);
            }
#if USEHTMLEDITOR
            //add missing html element
            if (htmlElements != null)
            {
                foreach (HtmlElement_Base he in htmlElements)
                {
                    bool bFound = false;
                    foreach (ComponentIconEvent ic in iconList)
                    {
                        ComponentIconHtmlElement cihe = ic as ComponentIconHtmlElement;
                        if (cihe != null)
                        {
                            if (ic.MemberId == cihe.MemberId)
                            {
                                ic.Designer = _owner.Loader;
                                bFound      = true;
                                break;
                            }
                        }
                    }
                    if (!bFound)
                    {
                        ComponentIconHtmlElement cip = new ComponentIconHtmlElement();
                        cip.Init(_owner.Loader, he);
                        cip.Location = new Point(x, y);
                        x           += dx;
                        x           += cip.Width;
                        if (x > _owner.Width)
                        {
                            x  = x0;
                            y += dy;
                            y += cip.Height;
                        }
                        iconList.Add(cip);
                    }
                }
            }
            //add missing current html element
            if (root.IsWebPage)
            {
                bool bFound = false;
                foreach (ComponentIconEvent ic in iconList)
                {
                    ComponentIconHtmlElementCurrent cic = ic as ComponentIconHtmlElementCurrent;
                    if (cic != null)
                    {
                        bFound = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    HtmlElement_body heb = new HtmlElement_body(root);
                    ComponentIconHtmlElementCurrent cip = new ComponentIconHtmlElementCurrent();
                    cip.ClassPointer = heb;
                    cip.Init(_owner.Loader, heb);
                    cip.Location = new Point(x, y);
                    x           += dx;
                    x           += cip.Width;
                    if (x > _owner.Width)
                    {
                        x  = x0;
                        y += dy;
                        y += cip.Height;
                    }
                    iconList.Add(cip);
                }
            }
#endif
            //add missing FireEventMethod, ComponentIconClass and ComponentIconClassType
            Dictionary <UInt32, IAction> actions = root.GetActions();
            foreach (IAction act in actions.Values)
            {
                if (act != null)
                {
                    FireEventMethod fe = act.ActionMethod as FireEventMethod;
                    if (fe != null)
                    {
                        ComponentIconFireEvent cife = null;
                        foreach (ComponentIconEvent ic in iconList)
                        {
                            if (!ic.IsForComponent)
                            {
                                ComponentIconFireEvent cie = ic as ComponentIconFireEvent;
                                if (cie != null)
                                {
                                    if (fe.MemberId == cie.FirerId && fe.EventId == cie.EventId)
                                    {
                                        cie.Firer   = fe;
                                        ic.Designer = _owner.Loader;
                                        cife        = cie;
                                        break;
                                    }
                                }
                            }
                        }
                        if (cife == null)
                        {
                            cife       = new ComponentIconFireEvent();
                            cife.Firer = fe;
                            cife.Init(_owner.Loader, root);
                            cife.Location = new Point(x, y);
                            //cip.FirerPort
                            x += dx;
                            x += cife.Width;
                            if (x > _owner.Width)
                            {
                                x  = x0;
                                y += dy;
                                y += cife.Height;
                            }
                            iconList.Add(cife);
                        }
                        //make port link
                        EventPortInFireEvent epife = null;
                        EventIcon            ei    = rootIcon.GetEventIcon(fe.Event);
                        if (ei == null)
                        {
                            ei       = new EventIcon(rootIcon);
                            ei.Event = fe.Event;
                            ComponentIconEvent.SetInitialPosition(100, ei);
                            rootIcon.EventIcons.Add(ei);
                        }
                        List <EventPortIn> ports = ei.DestinationPorts;
                        foreach (EventPortIn epi in ports)
                        {
                            EventPortInFireEvent epife0 = epi as EventPortInFireEvent;
                            if (epife0 != null)
                            {
                                if (epife0.FireEventMethodId == fe.MemberId)
                                {
                                    epife0.FireEventMethod = fe;
                                    epife = epife0;
                                    break;
                                }
                            }
                        }
                        if (epife == null)
                        {
                            epife = new EventPortInFireEvent(ei);
                            epife.FireEventMethod = fe;
                            ei.DestinationPorts.Add(epife);
                        }
                        epife.LinkedPortID                  = cife.FirerPort.PortID;
                        epife.LinkedPortInstanceID          = cife.FirerPort.PortInstanceID;
                        cife.FirerPort.LinkedPortID         = epife.PortID;
                        cife.FirerPort.LinkedPortInstanceID = epife.PortInstanceID;
                        //
                        epife.RestoreLocation();
                        epife.SetLoaded();
                        //
                        cife.FirerPort.RestoreLocation();
                        cife.FirerPort.SetLoaded();
                    }
                    else if (act.ActionMethod != null)
                    {
                        ClassPointer cp = root.GetExternalExecuterClass(act);
                        if (cp != null)
                        {
                            ComponentIconClass cic = null;
                            foreach (ComponentIconEvent ic in iconList)
                            {
                                ComponentIconClass cic0 = ic as ComponentIconClass;
                                if (cic0 != null)
                                {
                                    if (cic0.ClassId == act.ExecuterClassId)
                                    {
                                        cic          = cic0;
                                        cic.Designer = _owner.Loader;
                                        break;
                                    }
                                }
                            }
                            if (cic == null)
                            {
                                cic = new ComponentIconClass();
                                cic.Init(_owner.Loader, cp);
                                cic.Location = new Point(x, y);
                                x           += dx;
                                x           += cic.Width;
                                if (x > _owner.Width)
                                {
                                    x  = x0;
                                    y += dy;
                                    y += cic.Height;
                                }
                                iconList.Add(cic);
                            }
                        }
                        else
                        {
                            DataTypePointer tp = act.ActionMethod.Owner as DataTypePointer;
                            if (tp != null)
                            {
                                ComponentIconClassType cict = null;
                                foreach (ComponentIconEvent ic in iconList)
                                {
                                    ComponentIconClassType cict0 = ic as ComponentIconClassType;
                                    if (cict0 != null)
                                    {
                                        if (cict0.ClassType.Equals(tp.BaseClassType))
                                        {
                                            cict          = cict0;
                                            cict.Designer = _owner.Loader;
                                            break;
                                        }
                                    }
                                }
                                if (cict == null)
                                {
                                    cict = new ComponentIconClassType();
                                    cict.Init(_owner.Loader, tp);
                                    cict.Location = new Point(x, y);
                                    x            += dx;
                                    x            += cict.Width;
                                    if (x > _owner.Width)
                                    {
                                        x  = x0;
                                        y += dy;
                                        y += cict.Height;
                                    }
                                    iconList.Add(cict);
                                }
                            }
                        }
                    }
                    else
                    {
                        ActionAttachEvent aae = act as ActionAttachEvent;
                        if (aae != null)
                        {
                            IObjectPointer eventOwner = aae.EventOwner;
                            if (eventOwner != null)
                            {
                            }
                        }
                    }
                }
            }
            //add missing method icon
            foreach (MethodClass mc in methods.Values)
            {
                bool bFound = false;
                foreach (ComponentIconEvent ic in iconList)
                {
                    if (!ic.IsForComponent)
                    {
                        ComponentIconMethod cie = ic as ComponentIconMethod;
                        if (cie != null)
                        {
                            if (mc.MethodID == cie.MethodId)
                            {
                                ic.Designer = _owner.Loader;
                                bFound      = true;
                                break;
                            }
                        }
                    }
                }
                if (!bFound)
                {
                    ComponentIconMethod cip = new ComponentIconMethod();
                    cip.Init(_owner.Loader, mc.RootPointer);
                    cip.Method   = mc;
                    cip.MethodId = mc.MethodID;
                    cip.Location = new Point(x, y);
                    x           += dx;
                    x           += cip.Width;
                    if (x > _owner.Width)
                    {
                        x  = x0;
                        y += dy;
                        y += cip.Height;
                    }
                    iconList.Add(cip);
                }
            }
            //add missing handler icon
            foreach (EventAction ea in handlers)
            {
                if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                {
                    foreach (TaskID tid in ea.TaskIDList)
                    {
                        HandlerMethodID hid = tid as HandlerMethodID;
                        if (hid != null)
                        {
                            bool bFound = false;
                            foreach (ComponentIconEvent ic in iconList)
                            {
                                ComponentIconEventhandle cie = ic as ComponentIconEventhandle;
                                if (cie != null)
                                {
                                    if (ic.MemberId == cie.MemberId && cie.MethodId == hid.ActionId)
                                    {
                                        ic.Designer = _owner.Loader;
                                        bFound      = true;
                                        break;
                                    }
                                }
                            }
                            if (!bFound)
                            {
                                ComponentIconEventhandle cip = new ComponentIconEventhandle();
                                cip.Init(_owner.Loader, root);
                                cip.Method   = hid.HandlerMethod;
                                cip.MethodId = hid.ActionId;
                                cip.Location = new Point(x, y);
                                x           += dx;
                                x           += cip.Width;
                                if (x > _owner.Width)
                                {
                                    x  = x0;
                                    y += dy;
                                    y += cip.Height;
                                }
                                iconList.Add(cip);
                            }
                        }
                    }
                }
            }
            //add missing property icon
            foreach (PropertyClass p in props.Values)
            {
                bool bFound = false;
                foreach (ComponentIconEvent ic in iconList)
                {
                    if (!ic.IsForComponent)
                    {
                        ComponentIconProperty cie = ic as ComponentIconProperty;
                        if (cie != null)
                        {
                            if (p.MemberId == cie.PropertyId)
                            {
                                ic.Designer = _owner.Loader;
                                bFound      = true;
                                break;
                            }
                        }
                    }
                }
                if (!bFound)
                {
                    ComponentIconProperty cip = new ComponentIconProperty();
                    cip.Init(_owner.Loader, root);
                    cip.Property   = p;
                    cip.PropertyId = p.MemberId;
                    cip.Location   = new Point(x, y);
                    x += dx;
                    x += cip.Width;
                    if (x > _owner.Width)
                    {
                        x  = x0;
                        y += dy;
                        y += cip.Height;
                    }
                    iconList.Add(cip);
                }
            }

            //add icons to the parent
            _owner.Controls.AddRange(iconList.ToArray());
            //collect all ports
            PortCollection pc = new PortCollection();
            foreach (ComponentIconEvent ic in iconList)
            {
                if (ic.Left < 0)
                {
                    ic.Left = 2;
                }
                if (ic.Top < 0)
                {
                    ic.Top = 2;
                }
                ic.Visible = true;
                ic.BringToFront();
                ic.RefreshLabelPosition();
                //
                if (ic.IsPortOwner)
                {
                    //validate the input/output ports of the icon.
                    //it will also add EventIcon controls to the parent
                    ic.Initialize(this);
                    //collect ports from the icon
                    pc.AddRange(ic.GetAllPorts());
                }
            }
            //add all ports to the parent
            List <Control> cs = pc.GetAllControls(false);
            _owner.Controls.AddRange(cs.ToArray());
            //apply port locations
            foreach (ComponentIconEvent ic in iconList)
            {
                //output ports
                List <EventIcon> eis = ic.EventIcons;
                if (eis != null && eis.Count > 0)
                {
                    foreach (EventIcon ei in eis)
                    {
                        List <EventPortOut> pos = ei.SourcePorts;
                        if (pos != null)
                        {
                            foreach (EventPortOut po in pos)
                            {
                                po.RestoreLocation();
                                po.SetLoaded();
                            }
                        }
                    }
                }
                //input ports
                List <EventPortIn> epis = ic.DestinationPorts;
                if (epis != null && epis.Count > 0)
                {
                    foreach (EventPortIn pi in epis)
                    {
                        pi.RestoreLocation();
                        pi.SetLoaded();
                    }
                }
            }
            pc.ValidatePortLinks();
            //link ports
            MakePortLinks(pc);
            //link lines
            pc.MakeLinks(TraceLogClass.MainForm);
            //set line color
            SetDynamicEventHandlerLineColor(pc);
            //
            pc.CreateLinkLines();
            //
            //remove unlinked inports
            foreach (ComponentIconEvent cieSource in iconList)
            {
                List <EventPortIn> epis = cieSource.DestinationPorts;
                if (epis != null && epis.Count > 0)
                {
                    List <EventPortIn> unlinked = new List <EventPortIn>();
                    foreach (EventPortIn ei in epis)
                    {
                        if (ei.LinkedOutPort == null)
                        {
                            unlinked.Add(ei);
                        }
                    }
                    if (unlinked.Count > 0)
                    {
                        foreach (EventPortIn ei in unlinked)
                        {
                            epis.Remove(ei);
                            if (ei.Parent != null)
                            {
                                ei.Parent.Controls.Remove(ei);
                            }
                        }
                    }
                }
            }
            //monitor and notify link line changes
            eventPath.SetupLineNodeMonitor();
            //
            //remedy for unsolved bug: remove duplicated ComponentIconEvent
            Dictionary <UInt64, List <ComponentIconEvent> > cieList = new Dictionary <UInt64, List <ComponentIconEvent> >();
            foreach (ComponentIconEvent cieSource in iconList)
            {
                if (typeof(ComponentIconEvent).Equals(cieSource.GetType()))
                {
                    UInt64 id = cieSource.WholeId;
                    List <ComponentIconEvent> list;
                    if (!cieList.TryGetValue(id, out list))
                    {
                        list = new List <ComponentIconEvent>();
                        cieList.Add(id, list);
                    }
                    list.Add(cieSource);
                }
            }
            foreach (KeyValuePair <UInt64, List <ComponentIconEvent> > kv in cieList)
            {
                if (kv.Value.Count > 1)
                {
                    //duplicate icons. Find those can be removed
                    List <ComponentIconEvent> deleting = new List <ComponentIconEvent>();
                    foreach (ComponentIconEvent cie in kv.Value)
                    {
                        if (cie.DestinationPorts.Count == 0)
                        {
                            if (cie.EventIcons.Count == 0)
                            {
                                deleting.Add(cie);
                            }
                        }
                    }
                    if (deleting.Count == kv.Value.Count)
                    {
                        deleting.RemoveAt(0);
                    }
                    foreach (ComponentIconEvent cie in deleting)
                    {
                        cie.Parent.Controls.Remove(cie.Label);
                        cie.Parent.Controls.Remove(cie);
                        _componentIconList.Remove(cie);
                        if (cie.DataXmlNode != null)
                        {
                            XmlNode xmp = cie.DataXmlNode.ParentNode;
                            xmp.RemoveChild(cie.DataXmlNode);
                        }
                    }
                }
            }
            eventPath.EnlargeForChildren();
        }