Esempio n. 1
0
        public void Paste(PointF copyLocation, Construct parent)
        {
            if (Count == 0)
            {
                return;
            }
            List <Connect> pastedCon = new List <Connect>();
            List <Port>    newPort = new List <Port>();
            List <Element> newSelected = new List <Element>();
            Port           pt, pt2;
            Element        el, el2;
            Line           ln, ln2;
            Connect        cn, cn2;
            int            i, j;
            float          dx, dy;

            dx = ((Element)selected[0]).border.X;
            dy = ((Element)selected[0]).border.Y;
            for (i = 1; i < selected.Count; i++)
            {
                el = (Element)selected[i];
                if (dx > el.border.X)
                {
                    dx = el.border.X;
                }
                if (dy > el.border.Y)
                {
                    dy = el.border.Y;
                }
            }
            dx = copyLocation.X - dx;
            dy = copyLocation.Y - dy;
            for (i = 0; i < sport.Count; i++)
            {
                pt = (Port)sport[i];
                newPort.Add(new Port(pt.inout, pt.type, pt.location, null, pt.napr, pt.name, pt.LeftBusBound, pt.RightBusBound, pt.bus));
            }
            for (i = 0; i < selected.Count; i++)
            {
                el       = (Element)selected[i];
                el2      = new Element(el.img, parent, el.isLeftInOut, el.name, el.elementType);
                el2.text = el.text;
                for (j = 0; j < el.ports.Count; j++)
                {
                    pt = (Port)newPort[sport.IndexOf(el.ports[j])];
                    el2.ports.Add(pt);
                    pt.parent = el2;
                }
                el2.border = new RectangleF(el.border.X + dx, el.border.Y + dy, el.border.Width, el.border.Height);
                parent.AddElement(el2);
                newSelected.Add(el2);
            }
            for (i = 0; i < sconnect.Count; i++)
            {
                cn  = (Connect)sconnect[i];
                cn2 = new Connect(new PointF(cn.border.X + dx, cn.border.Y + dy), parent, cn.name);
                cn2.ports.Clear();
                for (j = 0; j < cn.ports.Count; j++)
                {
                    pt = (Port)newPort[sport.IndexOf(cn.ports[j])];
                    cn2.ports.Add(pt);
                    pt.parent = cn2;
                }
                pastedCon.Add(cn2);
                parent.AddConnect(cn2);
            }
            for (i = 0; i < sline.Count; i++)
            {
                ln           = (Line)sline[i];
                pt           = (Port)newPort[sport.IndexOf(ln.parentBegin)];
                pt2          = (Port)newPort[sport.IndexOf(ln.parentEnd)];
                ln2          = new Line(pt, pt2, ln.bus, ln.LeftBusBound, ln.RightBusBound, ln.name);
                ln2.isSignal = ln.isSignal;
                pt.line      = ln2;
                pt2.line     = ln2;
                ln2.PassFinding();
                ln2.assign.Clear();
                foreach (KeyValuePair <int, int> ind in ln.assign)
                {
                    ln2.assign.Add(ind.Key, ind.Value);
                }
                parent.AddLine(ln2);
            }
            ClearAll();
            for (i = 0; i < newSelected.Count; i++)
            {
                Add((Element)newSelected[i]);
            }
            foreach (Connect buf in pastedCon)
            {
                parent.CheckConnect(buf);
            }
            parent.parent.history.Changed();
        }