Esempio n. 1
0
        }// private void button_delete_MouseClick

        //“提交”按钮
        private void button_commit_MouseClick(object sender, MouseEventArgs e)
        {
            //若端口参数表格无表项,则直接关闭端口配置表单窗口,并退出函数
            if (listView1.Items.Count == 0)
            {
                this.Close();
                return;
            }

            //若组件端口不为空,则先删除组件端口,后面依据表格内容重新创建端口
            if (component.inout_ports != null)
            {
                for (int i = 0; i < component.inout_ports.Length; i++)
                {
                    //component.graphControl.RemoveShape(component.inout_ports[i]);
                    component.graphControl.Shapes.Remove(component.inout_ports[i]);
                }
                component.inout_ports = null;
                //component.graphControl.Refresh();
                //foreach (Inout_port inout_port in component.inout_ports)
                //    component.graphControl.RemoveShape(inout_port);
            }
            if (component.input_ports != null)
            {
                for (int i = 0; i < component.input_ports.Length; i++)
                {
                    //component.graphControl.RemoveShape(component.input_ports[i]);
                    component.graphControl.Shapes.Remove(component.input_ports[i]);
                }
                component.input_ports = null;
            }
            if (component.output_ports != null)
            {
                for (int i = 0; i < component.output_ports.Length; i++)
                {
                    //component.graphControl.RemoveShape(component.output_ports[i]);
                    component.graphControl.Shapes.Remove(component.output_ports[i]);
                }
                component.output_ports = null;
            }

            //创建端口数组对象,数组长度对应端口参数表格行数
            //Port[] ports = new Port[listView1.Items.Count];

            int input_num  = 0; //记录Input_port端口数量
            int output_num = 0; //记录Output_port端口数量
            int inout_num  = 0; //记录Inout_port端口数量

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                ListViewItem item = listView1.Items[i];

                //若端口方向为input
                if (item.SubItems[1].Text == "input")
                {
                    input_num++;
                }
                //若端口方向为output
                else if (item.SubItems[1].Text == "output")
                {
                    output_num++;
                }
                //若端口方向为inout
                else if (item.SubItems[1].Text == "inout")
                {
                    inout_num++;
                }//for (int i = 0; i < listView1.Items.Count; i++)
            }

            int j = 0; int n1 = 1;
            int k = 0; int n2 = 1;
            int l = 0; int n3 = 1;

            Inout_port[]  inout_ports = null;
            Input_port[]  input_ports = null;
            Output_port[] output_ports = null;

            if (inout_num > 0)
            {
                inout_ports = new Inout_port[inout_num];
            }
            if (input_num > 0)
            {
                input_ports = new Input_port[input_num];
            }
            if (output_num > 0)
            {
                output_ports = new Output_port[output_num];
            }

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                ListViewItem item = listView1.Items[i];

                //若为inout类型
                if (item.SubItems[1].Text == "inout")
                {
                    //创建Inout端口对象
                    //inout_ports[j] = new Inout_port();
                    //inout_ports[j].Port_ID1 = item.SubItems[0].Text;
                    //inout_ports[j].Port_type1 = item.SubItems[2].Text;
                    inout_ports[j] = new Inout_port(item.SubItems[0].Text, this.component.name + "Port", item.SubItems[1].Text, item.SubItems[2].Text, this.component);

                    //计算组件当前inout端口位置以及大小
                    int inout_ports_LocationX = (int)(component.Location.X + n1 * (component.Width / (inout_num + 1)) - inout_ports[j].Width / 2);
                    //int inout_ports_LocationY = (int)(component.Location.Y + component.Height - inout_ports[j].Height / 2);
                    int inout_ports_LocationY = (int)(component.Location.Y + component.Height - inout_ports[j].Height / 3);

                    //component.inout_ports[j].Rectangle = new RectangleF(inout_ports_LocationX, inout_ports_LocationY, 12, 8);
                    inout_ports[j].Rectangle = new RectangleF(inout_ports_LocationX, inout_ports_LocationY, 12, 8);

                    //component.graphControl.AddShape(component.inout_ports[j], new Point(inout_ports_LocationX, inout_ports_LocationY));
                    component.graphControl.AddShape(inout_ports[j], new Point(inout_ports_LocationX, inout_ports_LocationY));
                    n1++;
                    j++;
                }// if (item.SubItems[1].Text=="inout")

                //若为input类型
                if (item.SubItems[1].Text == "input")
                {
                    //创建Input端口对象
                    //input_ports[k] = new Input_port();
                    //input_ports[k].Port_ID1 = item.SubItems[0].Text;
                    //input_ports[k].Port_type1 = item.SubItems[2].Text;
                    input_ports[k] = new Input_port(item.SubItems[0].Text, this.component.name + "Port", item.SubItems[1].Text, item.SubItems[2].Text, this.component);

                    //+++++++++++++++ Debug 输出input端口所附属的组件+++++++++++++++++++++++++++++++++++++++++++//
                    //Console.WriteLine(input_ports[k].Port_ID1 + "所属的组件为:" + input_ports[k].BelongTo());
                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

                    //计算组件当前input端口位置以及大小
                    //int input_ports_LocationX = (int)(component.Location.X - input_ports[k].Width / 2);
                    int input_ports_LocationX = (int)(component.Location.X);
                    int input_ports_LocationY = (int)(component.Location.Y + n2 * (component.Height / (input_num + 1)) - input_ports[k].Height / 2);

                    //component.inout_ports[j].Rectangle = new RectangleF(inout_ports_LocationX, inout_ports_LocationY, 12, 8);
                    input_ports[k].Rectangle = new RectangleF(input_ports_LocationX, input_ports_LocationY, 15, 15);

                    //component.graphControl.AddShape(component.inout_ports[j], new Point(inout_ports_LocationX, inout_ports_LocationY));
                    component.graphControl.AddShape(input_ports[k], new Point(input_ports_LocationX, input_ports_LocationY));
                    n2++;
                    k++;
                }//if (item.SubItems[1].Text == "input")

                //若为output类型
                if (item.SubItems[1].Text == "output")
                {
                    //创建Output端口对象
                    //output_ports[l] = new Output_port();
                    //output_ports[l].Port_ID1 = item.SubItems[0].Text;
                    //output_ports[l].Port_type1 = item.SubItems[2].Text;
                    output_ports[l] = new Output_port(item.SubItems[0].Text, this.component.name + "Port", item.SubItems[1].Text, item.SubItems[2].Text, this.component);

                    //计算组件当前output端口位置以及大小
                    //int output_ports_LocationX = (int)(component.Location.X + component.Width - output_ports[l].Width / 2);
                    int output_ports_LocationX = (int)(component.Location.X + component.Width - 2);
                    int output_ports_LocationY = (int)(component.Location.Y + n3 * (component.Height / (output_num + 1)) - output_ports[l].Height / 2);

                    //component.inout_ports[j].Rectangle = new RectangleF(inout_ports_LocationX, inout_ports_LocationY, 12, 8);
                    output_ports[l].Rectangle = new RectangleF(output_ports_LocationX, output_ports_LocationY, 15, 15);

                    component.graphControl.AddShape(output_ports[l], new Point(output_ports_LocationX, output_ports_LocationY));
                    n3++;
                    l++;
                } //if (item.SubItems[1].Text == "output")
            }     // for (int i = 0; i < listView1.Items.Count; i++)

            //将inout端口与组件进行绑定
            component.inout_ports = inout_ports;
            //Debug
            //foreach(Inout_port inout in component.inout_ports){
            //     Console.WriteLine(inout.Port_ID1+" "+inout.Location);
            //}

            //将input端口与组件进行绑定
            component.input_ports = input_ports;
            //将output端口与组件进行绑定
            component.output_ports = output_ports;

            ////若组件为血压组件,则所有端口名设置为BloodPressureOutputPort
            //if (component.name == "BloodPressure")
            //{
            //    if (component.inout_ports != null)
            //    {
            //        foreach (Inout_port inout_port in component.inout_ports)
            //        {
            //            inout_port.Port_name1 = "BloodPressureOutputPort";
            //        }
            //    }
            //    if (component.input_ports != null)
            //    {
            //        foreach (Input_port input_port in component.inout_ports)
            //        {
            //            input_port.Port_name1 = "BloodPressureOutputPort";
            //        }
            //    }
            //}

            this.Close();
        } //button_commit_MouseClick
Esempio n. 2
0
        }// public void ComponentDataTransfer(Component component,Object data)

        /*********************************************************************************
        * 函数名称:PortDataTransfer()
        * 功能:端口数据传输函数,仅用于复合组件,若端口为output端口,output端口将数据传输
        *       至相连的另一组件input端口;若端口为input端口,input端口将组件传输至相连的
        *       内部组件input端口
        * 参数:port 表示进行数据传输的端口
        * 返回值:无
        * *******************************************************************************/
        public void PortDataTransfer(Port port)
        {
            try
            {
                Thread.Sleep(10);
                //若端口为output端口
                if (port.GetType().Name == "Output_port")
                {
                    Output_port output = (Output_port)port;
                    Object      temp   = null;
                    //若输出端口队列数据大于0且输出端口存在连线
                    if (output.Port_queue1.Count > 0 && output.PortConnector1.Connections.Count > 0)
                    {
                        try
                        {
                            temp = output.Port_queue1.Dequeue();

                            //++++++++++++ Debug - 读取output端口队列中的数据 +++++++++++//
                            //Console.Write(output.Component.name + "组件" + output.Port_ID1 + "端口队列数据(出队后):");
                            //foreach (Object arr in output.Port_queue1)
                            //{
                            //    //Console.Write("[" + arr[0] + "," + arr[1] + " ];");
                            //    Console.Write(arr.GetType().Name + " ;");
                            //}
                            //Console.WriteLine("");
                            ////Console.WriteLine("=========================");
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

                            //遍历该output端口所有连接线
                            foreach (Connection connection in output.PortConnector1.Connections)
                            {
                                //记录连接线起点
                                Connector start_connector = connection.From;
                                //记录连接线终点
                                Connector end_connector = connection.To;

                                //获取连接线起点所附属的端口
                                Port start_port = (Port)start_connector.BelongsTo;
                                //获取连接线终点所附属的端口
                                Port end_port = (Port)end_connector.BelongsTo;
                                if (temp != null)
                                {
                                    end_port.Port_queue1.Enqueue(temp);
                                }

                                //++++++++++++ Debug - 读取input/inout端口队列中的数据 +++++++++++//
                                //Console.Write(end_port.Component.name + "组件" + end_port.Port_ID1 + "端口队列数据(入队后):");
                                //foreach (Object arr in end_port.Port_queue1)
                                //{
                                //    //Console.Write("[" + arr[0] + "," + arr[1] + " ];");
                                //    Console.Write(arr.GetType().Name + " ;");
                                //}
                                //Console.WriteLine("");
                                //Console.WriteLine("=========================");
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
                            }
                        }catch (Exception e) {
                            Console.WriteLine("6错误情况:" + e.Message);
                        }
                    }
                }// if (port.GetType().Name == "Output_port")

                //若端口为input端口
                if (port.GetType().Name == "Input_port")
                {
                    Input_port input = (Input_port)port;
                    Object     temp  = null;
                    //Console.WriteLine("input.Port_queue1.Count=" + input.Port_queue1.Count + " input.PortConnector1.Connections.Count="
                    //    + input.PortConnector1.Connections.Count);
                    //若input端口队列数据大于0且input端口存在连线
                    if (input.Port_queue1.Count > 0 && input.PortConnector1.Connections.Count > 0)
                    {
                        temp = input.Port_queue1.Dequeue(); //input端口内部队列数据出列
                        //遍历该input端口所有连接线
                        foreach (Connection connection in input.PortConnector1.Connections)
                        {
                            //若连接线的起点为该input端口,且连接线终点为输入端口类型
                            if (connection.From.BelongsTo == input && connection.To.BelongsTo.GetType().Name == "Input_port")
                            {
                                try
                                {
                                    Input_port input_end = (Input_port)connection.To.BelongsTo;
                                    input_end.Port_queue1.Enqueue(temp);
                                    //++++++++++++ Debug - 读取input/inout端口队列中的数据 +++++++++++//
                                    //Console.Write(input_end.Component.name + "组件" + input_end.Port_ID1 + "端口队列数据(入队后):");
                                    //foreach (Object arr in input_end.Port_queue1)
                                    //{
                                    //    //Console.Write("[" + arr[0] + "," + arr[1] + " ];");
                                    //    Console.Write(arr.GetType().Name + " ;");
                                    //}
                                    //Console.WriteLine("");
                                    //Console.WriteLine("=========================");
                                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("7错误情况:" + e.Message);
                                }
                            }
                        }
                    }
                }// if (port.GetType().Name == "Input_port")
            }
            catch (Exception e1)
            {
                Console.WriteLine("8错误情况:" + e1.Message + e1.StackTrace);
            }
        }