public ReturnIcon(RaisDataType dataType)
        {
            Location = new Point(300, 300);
            SaveLocation();
            this.Size = new Size(32, 32);
            System.Drawing.ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(this.GetType())[typeof(System.Drawing.ToolboxBitmapAttribute)] as System.Drawing.ToolboxBitmapAttribute;
            if (tba != null)
            {
                bmp = (System.Drawing.Bitmap)tba.GetImage(this.GetType());
            }
            MathNodeRoot root = new MathNodeRoot();

            root.IsVariableHolder = true;
            var     = new MathNodeVariableDummy(root);
            root[0] = var;
            if (dataType != null)
            {
                var.VariableType = dataType;
                var.TypeDefined  = true;
            }
            LinkLineNodeInPort port = new LinkLineNodeInPort(var);

            port.ClearLine();
            port.SetPrevious(null);
            port.Owner = this;
            port.HideLabel();
            var.InPort         = port;
            port.Owner         = this;
            port.Label.Visible = false;
            port.Location      = new Point(this.Left + this.Width / 2 - port.Width / 2, this.Top - port.Height);
            port.SaveLocation();
        }
示例#2
0
        public void AddInPort(LinkLineNodeInPort port)
        {
            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            EventPortIn epi = port as EventPortIn;

            if (epi == null)
            {
                throw new DesignerException("Cannot add non-EventPortIn to EventIcon");
            }
            else
            {
                _inPortList.Add(epi);
            }
        }
        public void AddInPort(LinkLineNodeInPort port)
        {
            if (port == null)
            {
                throw new DesignerException("Cannot add null to inports for {1}", this.GetType().Name);
            }
            EventPortIn epi = port as EventPortIn;

            if (epi == null)
            {
                throw new DesignerException("Cannot add {0} to inports for {1}", port.GetType().Name, this.GetType().Name);
            }
            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            _inPortList.Add(epi);
        }
        private void miDisconnectNodes_Click(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                NodeData nd = mi.Tag as NodeData;
                if (nd != null)
                {
                    LinkLineNode node = nd.Node;

                    if (node != null)
                    {
                        if (nd.Data != null)
                        {
                            if (nd.Data.GetType().Equals(typeof(Point)))
                            {
                                Point pt = (Point)nd.Data;
                                if (node.Line != null)
                                {
                                    //===================
                                    UInt32             key  = node.ActiveDrawingID;
                                    UInt32             key1 = 0;
                                    UInt32             key2 = 0;
                                    LinkLineNodeInPort ip   = node.LinkedInPort;
                                    node.BreakLine(pt, ref key1, ref key2);
                                    OnDisconnectLine(ip);
                                    if (UndoHost != null)
                                    {
                                        if (!UndoHost.DisableUndo)
                                        {
                                            LinkLineUndoReconnect undo = new LinkLineUndoReconnect(UndoHost, key, key1, key2);
                                            LinkLineUndoBreak     redo = new LinkLineUndoBreak(UndoHost, key, key1, key2, pt);
                                            UndoHost.AddUndoEntity(new UndoEntity(undo, redo));
                                        }
                                    }
                                    ActiveDrawing.RefreshControl(this);
                                }
                            }
                        }
                    }
                }
            }
        }
        public bool IsOnTheLine(LinkLineNode lineNode)
        {
            LinkLineNodeOutPort start = lineNode.Start as LinkLineNodeOutPort;

            if (start != null)
            {
                if (start.PortID == _startNode.PortID && start.PortInstanceID == _startNode.PortInstanceID)
                {
                    LinkLineNodeInPort end = lineNode.End as LinkLineNodeInPort;
                    if (end != null)
                    {
                        if (end.PortID == _endNode.PortID && end.PortInstanceID == _endNode.PortInstanceID)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#6
0
        public void OnReadFromXmlNode(IXmlCodeReader serializer, XmlNode node)
        {
            _owner = (ObjectRef)XmlSerialization.ReadFromChildXmlNode(serializer, node, XML_Owner);
            XmlNodeList nodes = node.SelectNodes(XmlSerialization.FormatString("{0}/{1}",
                                                                               XML_Inports, XmlSerialization.XML_PORT));

            _inports = new ProgramInPort[nodes.Count];
            for (int i = 0; i < nodes.Count; i++)
            {
                _inports[i] = (ProgramInPort)XmlSerialization.ReadFromXmlNode(serializer, nodes[i], this);
            }
            nodes = node.SelectNodes(XmlSerialization.FormatString("{0}/{1}",
                                                                   XML_Outports, XmlSerialization.XML_PORT));
            _outports = new ProgramOutPort[nodes.Count];
            for (int i = 0; i < nodes.Count; i++)
            {
                _outports[i] = (ProgramOutPort)XmlSerialization.ReadFromXmlNode(serializer, nodes[i], this);
            }
            _newInport  = (LinkLineNodeInPort)XmlSerialization.ReadFromChildXmlNode(serializer, node, XML_NewInport, this);
            _newOutport = (LinkLineNodeOutPort)XmlSerialization.ReadFromChildXmlNode(serializer, node, XML_NewOutport, this);
        }
示例#7
0
 public static void SetDynamicEventHandlerLineColor(PortCollection pc)
 {
     foreach (LinkLineNodePort p in pc)
     {
         LinkLineNodeInPort ip = p as LinkLineNodeInPort;
         if (ip != null)
         {
             ComponentIconEventhandle ieh = ip.PortOwner as ComponentIconEventhandle;
             if (ieh != null)
             {
                 EventHandlerMethod ehm = ieh.Method as EventHandlerMethod;
                 if (ehm != null)
                 {
                     UInt32 actId = ehm.GetDynamicActionId();
                     if (actId != 0)
                     {
                         ip.SetLineColor(Color.Yellow);
                     }
                 }
             }
         }
         else
         {
             EventPortOutExecuteMethod op = p as EventPortOutExecuteMethod;
             if (op != null)
             {
                 EventHandlerMethod ehm = op.Method as EventHandlerMethod;
                 if (ehm != null)
                 {
                     UInt32 actId = ehm.GetDynamicActionId();
                     if (actId != 0)
                     {
                         op.SetLineColor(Color.Yellow);
                     }
                 }
             }
         }
     }
 }
示例#8
0
        public virtual PortCollection GetAllPorts()
        {
            PortCollection ports = new PortCollection();

            if (_newInport == null)
            {
                _newInport = new ProgramNewInPort(this);
            }
            if (_newOutport == null)
            {
                _newOutport = new ProgramNewOutPort(this);
            }
            ports.Add(_newInport);
            ports.Add(_newOutport);
            if (_inports != null)
            {
                ports.AddRange(_inports);
            }
            if (_outports != null)
            {
                ports.AddRange(_outports);
            }
            return(ports);
        }
 //const string XMLATTR_CanLink = "canLinkOutPort";
 public MathNodeVariableDummy(MathNode parent)
     : base(parent)
 {
     VariableName = "dummy";
     InPort       = new LinkLineNodeInPort(this);
 }
 public void AddInPort(LinkLineNodeInPort port)
 {
 }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            LinkLineNode nodeTest = HitTest(e.X, e.Y);

            if (nodeTest != null)
            {
                if (AllowLineSelection)
                {
                    nodeTest.SelectLine(true);
                    if (nodeTest.Start != null && nodeTest.End != null)
                    {
                        LinkLineNodeOutPort startNode = nodeTest.Start as LinkLineNodeOutPort;
                        LinkLineNodeInPort  endNode   = nodeTest.End as LinkLineNodeInPort;
                        if (startNode != null && endNode != null)
                        {
                            bool bChanged = true;
                            if (_selectedLine != null)
                            {
                                if (_selectedLine.StartNode.PortID == startNode.PortID &&
                                    _selectedLine.StartNode.PortInstanceID == startNode.PortInstanceID &&
                                    _selectedLine.EndNode.PortID == endNode.PortID &&
                                    _selectedLine.EndNode.PortInstanceID == endNode.PortInstanceID)
                                {
                                    bChanged = false;
                                }
                            }
                            if (bChanged)
                            {
                                _selectedLine = new LinkLineEnds(startNode, endNode);
                                OnLineSelectionChanged();
                            }
                        }
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu mnu = new ContextMenu();
                Point       pt  = new Point(e.X, e.Y);
                if (nodeTest != null)
                {
                    //nodeTest is the line holder
                    nodeTest.SelectLine(true);
                    MenuItemWithBitmap mi = new MenuItemWithBitmap("Add line join", Resource1.newLineBreak);
                    mi.Click += new EventHandler(miAddLineNode_Click);
                    mi.Tag    = new NodeData(nodeTest, pt);
                    mnu.MenuItems.Add(mi);
                    //
                    if (AllowLineDisconnect)
                    {
                        if (nodeTest.LinkedInPort != null && nodeTest.LinkedOutPort != null)
                        {
                            mi        = new MenuItemWithBitmap("Disconnect", Resource1.disconnect);
                            mi.Click += new EventHandler(miDisconnectNodes_Click);
                            mi.Tag    = new NodeData(nodeTest, pt);
                            mnu.MenuItems.Add(mi);
                        }
                    }
                    OnCreateContextMenuForLinkLine(nodeTest, mnu, pt);
                }
                else
                {
                    OnCreateContextMenu(mnu, pt);
                }
                if (mnu.MenuItems.Count > 0)
                {
                    _menuPoint = pt;
                    mnu.Show(this, pt);
                }
            }
        }
 protected virtual void OnDisconnectLine(LinkLineNodeInPort port)
 {
 }
 public LinkLineEnds(LinkLineNodeOutPort startNode, LinkLineNodeInPort endNode)
 {
     _startNode = startNode;
     _endNode   = endNode;
 }
示例#14
0
        /// <summary>
        /// new load or re-load.
        /// this control must already be added to the viewer (DiagramViewer).
        /// It generates ports for all variables
        /// </summary>
        /// <param name="data">the result of lower level editing</param>
        public void LoadData(IMathExpression data)
        {
            bLoading = true;
            DiagramViewer dv = this.Parent as DiagramViewer;
            VariableList  currentVariables = null;
            IVariable     currOutVar       = null;

            if (mathExp != null)
            {
                currOutVar       = mathExp.OutputVariable;
                currentVariables = mathExp.InputVariables;
            }
            mathExp = data;
            if (mathExp == null)
            {
                mathExp = new MathNodeRoot();
            }
            mathExp.ClearFocus();
            //1. find out all unique and non-local variables
            VariableList _portVariables = mathExp.InputVariables;

            //2. remove removed ports
            if (currentVariables != null)
            {
                foreach (IVariable v in currentVariables)
                {
                    if (_portVariables.GetVariableById(v.ID) == null)
                    {
                        //remove port and nodes
                        List <Control> cs = new List <Control>();
                        foreach (Control c in dv.Controls)
                        {
                            LinkLineNodeInPort p = c as LinkLineNodeInPort;
                            if (p != null)
                            {
                                if (p.PortID == v.ID)
                                {
                                    cs.Add(p);
                                    cs.Add(p.Label);
                                    ILinkLineNode prev = p.PrevNode;
                                    while (prev != null)
                                    {
                                        if (prev is LinkLineNodePort)
                                        {
                                            break;
                                        }
                                        cs.Add((Control)prev);
                                        prev = prev.PrevNode;
                                    }
                                    break;
                                }
                            }
                        }
                        foreach (Control c in cs)
                        {
                            dv.Controls.Remove(c);
                        }
                    }
                }
            }
            List <Control>            newControls = new List <Control>();
            List <LinkLineNodeInPort> newInPorts  = new List <LinkLineNodeInPort>();

            //3.create new ports
            foreach (IVariable v in _portVariables)
            {
                if (currentVariables == null || currentVariables.GetVariableById(v.ID) == null)
                {
                    if (data.IsContainer)
                    {
                        //create a new variable instance
                        MathNodeRoot r = new MathNodeRoot();
                        ((MathNode)v).root.CopyAttributesToTarget(r);
                        r[1] = new MathNodeVariable(r);
                        IVariable vi = (IVariable)r[1];
                        vi.VariableType  = (RaisDataType)v.VariableType.Clone();
                        vi.VariableName  = v.VariableName;
                        vi.SubscriptName = v.SubscriptName;
                        vi.ResetID(v.ID);
                        vi.InPort = new LinkLineNodeInPort(vi);
                        vi.InPort.SetPortOwner(vi);
                        vi.InPort.Owner = this;
                        newControls.Add(vi.InPort);
                        newControls.Add(vi.InPort.Label);
                        vi.InPort.CheckCreatePreviousNode();
                        newControls.Add((Control)vi.InPort.PrevNode);
                        newInPorts.Add(vi.InPort);
                    }
                    else
                    {
                        v.InPort       = new LinkLineNodeInPort(v);
                        v.InPort.Owner = this;
                        newControls.Add(v.InPort);
                        newControls.Add(v.InPort.Label);
                        v.InPort.CheckCreatePreviousNode();
                        newControls.Add((Control)v.InPort.PrevNode);
                        newInPorts.Add(v.InPort);
                    }
                }
            }
            if (newInPorts.Count > 0)
            {
                int dn = this.Width / (newInPorts.Count + 1);
                for (int i = 0; i < newInPorts.Count; i++)
                {
                    newInPorts[i].Position = i * dn + dn;
                    newInPorts[i].Left     = this.Left + newInPorts[i].Position;
                    newInPorts[i].SaveLocation();
                    newInPorts[i].PrevNode.Left = newInPorts[i].Left;
                }
            }
            //3. re-map to existing ports
            if (currOutVar != null && currOutVar.OutPorts != null)
            {
                //if port exists then re-use it
                mathExp.OutputVariable.OutPorts = currOutVar.OutPorts;
                for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++)
                {
                    mathExp.OutputVariable.OutPorts[i].SetPortOwner(mathExp.OutputVariable);
                    //if linking exists then re-establish it
                    if (currOutVar.OutPorts[i].LinkedPortID != 0)
                    {
                        //find the variable
                        if (dv != null)
                        {
                            IVariable v = dv.FindVariableById(currOutVar.OutPorts[i].LinkedPortID);
                            if (v != null)
                            {
                                v.InPort.LinkedPortID = mathExp.OutputVariable.ID;
                            }
                        }
                    }
                }
            }
            else
            {
                //for a new load, create the output port
                mathExp.OutputVariable.OutPorts = new LinkLineNodeOutPort[] { new LinkLineNodeOutPort(mathExp.OutputVariable) };
                mathExp.OutputVariable.OutPorts[0].CheckCreateNextNode();
                ////use the default position
                mathExp.OutputVariable.OutPorts[0].Position = this.Width / 2;
            }
            for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++)
            {
                mathExp.OutputVariable.OutPorts[i].Owner         = this;
                mathExp.OutputVariable.OutPorts[i].Label.Visible = false;
                mathExp.OutputVariable.OutPorts[i].SaveLocation();
            }
            if (!(currOutVar != null && currOutVar.OutPorts != null))
            {
                for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++)
                {
                    //for a new load, set default postion for the empty linking node
                    ((Control)(mathExp.OutputVariable.OutPorts[i].NextNode)).Location = mathExp.OutputVariable.OutPorts[i].DefaultNextNodePosition();
                    //add new controls
                    newControls.Add(mathExp.OutputVariable.OutPorts[i]);
                    newControls.Add((Control)mathExp.OutputVariable.OutPorts[i].NextNode);
                    newControls.Add(mathExp.OutputVariable.OutPorts[i].Label);
                }
            }
            //add the new controls
            if (this.Parent != null && newControls.Count > 0)
            {
                Control[] a = new Control[newControls.Count];
                newControls.CopyTo(a);
                this.Parent.Controls.AddRange(a);
            }
            mathExp.PrepareDrawInDiagram();
            //
            createImage();
            bLoading = false;
        }
示例#15
0
 public void AddInPort(LinkLineNodeInPort port)
 {
     AddInport((ProgramInPort)port);
 }