// Fill list from selection
        private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill)
        {
            listToFill = new List <DrawObject>();

            foreach (DrawObject o in graphicsList.Selection)
            {
                listToFill.Add(o.Clone());
            }
        }
示例#2
0
        public void LoadFromStream(SerializationInfo info, int orderNumber)
        {
            _graphicsList = new GraphicsList();

            _name = info.GetString(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerName, orderNumber));

            _visible = info.GetBoolean(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerVisible, orderNumber));

            _active = info.GetBoolean(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerActive, orderNumber));

            int n = info.GetInt32(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryGraphicsCount, orderNumber));

            for (int i = 0; i < n; i++)
            {
                string typeName;
                typeName = info.GetString(
                    String.Format(CultureInfo.InvariantCulture,
                                  "{0}{1}-{2}",
                                  entryObjectType, orderNumber, i));

                object drawObject;
                drawObject = Assembly.GetExecutingAssembly().CreateInstance(typeName);

                ((DrawObject)drawObject).LoadFromStream(info, orderNumber, i);

                // Thanks to Member 3272353 for this fix to object ordering problem.
                // _graphicsList.Add((DrawObject)drawObject);
                _graphicsList.Append((DrawObject)drawObject);
            }
        }
        private static Point TestForConnection(DrawArea drawArea, Point p, out int objectID)
        {
            // Determine if within 5 pixels of a connection point
            // Step 1: see if a 5 x 5 rectangle centered on the mouse cursor intersects with an object
            // Step 2: If it does, then see if there is a connection point within the rectangle
            // Step 3: If there is, move the point to the connection point, record the object's id in the connector
            //
            objectID = -1;
            Rectangle    testRectangle  = new Rectangle(p.X - 2, p.Y - 2, 5, 5);
            int          al             = drawArea.TheLayers.ActiveLayerIndex;
            bool         connectionHere = false;
            Point        h  = new Point(-1, -1);
            GraphicsList gl = drawArea.TheLayers[al].Graphics;

            for (int i = 1; i < gl.Count; i++)
            {
                if (gl[i].IntersectsWith(testRectangle))
                {
                    DrawObject obj = (DrawObject)gl[i];
                    for (int j = 1; j < obj.HandleCount + 1; j++)
                    {
                        h = obj.GetHandle(j);
                        if (testRectangle.Contains(h))
                        {
                            connectionHere = true;
                            p        = h;
                            objectID = obj.ID;
                            //			obj.DrawConnection(drawArea., j);
                            break;
                        }
                    }
                }
                if (connectionHere)
                {
                    break;
                }
            }
            return(p);
        }
        // Replace objects in graphicsList with objects from list
        private void ReplaceObjects(GraphicsList graphicsList, List <DrawObject> list)
        {
            for (int i = 0; i < graphicsList.Count; i++)
            {
                DrawObject replacement = null;

                foreach (DrawObject o in list)
                {
                    if (o.ID ==
                        graphicsList[i].ID)
                    {
                        replacement = o;
                        break;
                    }
                }

                if (replacement != null)
                {
                    graphicsList.Replace(i, replacement);
                }
            }
        }