コード例 #1
0
        private void panel2_MouseUp(object sender, MouseEventArgs e)
        {
            int     H          = 0;
            int     W          = 0;
            GObject GContainer = new GObject();
            GObject GToDrag    = new GObject();

            GToDrag = GNetwork.GObjects[CurrObjDragIndx];
            double   d1     = 0;
            double   d2     = 0;
            TimeSpan DTDrag = new TimeSpan();

            DTDrag = DateTime.Now.Subtract(Tdown);
            if ((Dragging == true) && (DTDrag.Milliseconds > DragTimeMin))
            {
                //如果拖动的是线,并且有容器
                if ((GNetwork.GObjects[CurrObjDragIndx].Type == "Line") &&
                    (GNetwork.FindContainerObject(e.X, e.Y, ref GContainer, true) > -1))
                {
                    //
                    //    What is the point of the line to link ?
                    //    The nearest to (Xdown,Ydown)
                    //
                    d1 = CommFnc.distance(Xdown, Ydown, GToDrag.x1, GToDrag.y1);
                    d2 = CommFnc.distance(Xdown, Ydown, GToDrag.x2, GToDrag.y2);
                    if (d1 <= d2)
                    {
                        GToDrag.x1   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y1   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk1 = GContainer.Name;
                    }
                    else
                    {
                        GToDrag.x2   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y2   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk2 = GContainer.Name;
                    }
                }
                else
                {
                    W          = GToDrag.x2 - GToDrag.x1;
                    H          = GToDrag.y2 - GToDrag.y1;
                    GToDrag.x1 = e.X;
                    GToDrag.y1 = e.Y;
                    GToDrag.x2 = e.X + W;
                    GToDrag.y2 = e.Y + H;
                    GNetwork.AdjustLinkedTo(GToDrag.Name);
                }
                Cursor.Current = Cursors.Default;
                Dragging       = false;



                //this.panel2.Refresh();

                ReDrawAll();

                //this.Refresh();
            }
        }
コード例 #2
0
ファイル: GObject.cs プロジェクト: AreaOfLongRong/HDDNCONIAMP
        public bool LoadFile(string FileFullPath, ref string sErrFileMsg)
        {
            string  sVariable = "";
            string  sValue    = "";
            string  cFirst    = "";
            int     i         = 0;
            int     iLine     = 0;
            GObject NewGObj   = new GObject();

            sErrFileMsg = "";
            try
            {
                using (StreamReader sr = new StreamReader(FileFullPath))
                {
                    String sLine = "";
                    while (sLine != "end network file.")
                    {
                        sLine = sr.ReadLine();
                        iLine++;
                        if (sLine == "end object.")
                        {
                            sLine = sr.ReadLine();
                            iLine++;
                        }
                        if (sLine == "")
                        {
                            cFirst = "*";
                        }
                        else
                        {
                            cFirst = sLine.Substring(0, 1);
                        }
                        if (cFirst == "*")
                        {
                            // null o *-beginning lines are like comments
                        }
                        else
                        {
                            while ((sLine != "end object.") && (sLine != "end network file."))
                            {
                                CommFnc.RowDecode(sLine, ref sVariable, ref sValue);
                                switch (sVariable)
                                {
                                case "object":
                                    NewGObj.Name = sValue;
                                    break;

                                case "type":
                                    NewGObj.Type = sValue;
                                    break;

                                case "lnk1":
                                    NewGObj.Lnk1 = sValue;
                                    break;

                                case "lnk2":
                                    NewGObj.Lnk2 = sValue;
                                    break;

                                case "x1":
                                    NewGObj.x1 = System.Convert.ToInt32(sValue);
                                    break;

                                case "x2":
                                    NewGObj.x2 = System.Convert.ToInt32(sValue);
                                    break;

                                case "y1":
                                    NewGObj.y1 = System.Convert.ToInt32(sValue);
                                    break;

                                case "y2":
                                    NewGObj.y2 = System.Convert.ToInt32(sValue);
                                    break;

                                default:
                                    break;
                                }
                                sLine = sr.ReadLine();
                                iLine++;
                            }
                            if (sLine == "end object.")
                            {
                                GObjects[i] = new GObject(NewGObj.Name, NewGObj.Type,
                                                          NewGObj.x1, NewGObj.y1, NewGObj.Lnk1, NewGObj.x2, NewGObj.y2, NewGObj.Lnk2);
                                i++;
                                CurrObjIndx = i;
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                sErrFileMsg = "Error reading file : " + e.Message + " line = " + i.ToString() + "\n";
                return(false);
            }
        }