コード例 #1
0
        public FiguresList.FigureList LoadFiguresList(FileStream fs, List <Type> types)
        {
            FiguresList.FigureList Rezlist     = new FiguresList.FigureList();
            SerialFiguresList      SerFigsList = (SerialFiguresList)formatter.Deserialize(fs);

            for (int i = 0; i < SerFigsList.Size(); i++)
            {
                Type typ = null;
                for (int j = 0; j < types.Count(); j++)
                {
                    if (types[j].FullName == SerFigsList.Item(i).figtype)
                    {
                        typ = types[j];
                    }
                }
                if (typ == null)
                {
                    throw new SerializationException("Unable to load item " + SerFigsList.Item(i).figtype + ": Assembly is not found.");
                }
                var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                if (fig is MyInterfaces.IFillingable)
                {
                    ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                }
                Rezlist.Add(fig);
            }
            return(Rezlist);
        }
コード例 #2
0
        public FiguresList.FigureList TransformToFullList(FiguresList.FigureList srclist)
        {
            var Rezlist = new FiguresList.FigureList();

            for (int i = 0; i < srclist.Size(); i++)
            {
                if (srclist.Item(i) is UserFigure)
                {
                    for (int j = 0; j < ((UserFigure)srclist.Item(i)).Primitives.Size(); j++)
                    {
                        Rezlist.Add(((UserFigure)srclist.Item(i)).Primitives.Item(j));
                    }
                }
                else
                {
                    Rezlist.Add(srclist.Item(i));
                }
            }
            return(Rezlist);
        }
コード例 #3
0
        public FiguresList.FigureList TransformOneFigureToPrimitives(FiguresList.FigureList srclist, int index)
        {
            var Rezlist = new FiguresList.FigureList();

            for (int i = 0; i < srclist.Size(); i++)
            {
                if (i == index)
                {
                    for (int j = 0; j < ((UserFigure)srclist.Item(i)).Primitives.Size(); j++)
                    {
                        Rezlist.Add(((UserFigure)srclist.Item(i)).Primitives.Item(j));
                    }
                }
                else
                {
                    Rezlist.Add(srclist.Item(i));
                }
            }

            return(Rezlist);
        }
コード例 #4
0
 private void btnTransform_Click(object sender, EventArgs e)
 {
     if (lboxFigures.SelectedIndex != -1)
     {
         var transformer = new UserFiguresTransformer();
         var tmplist     = transformer.TransformOneFigureToPrimitives(FigList, CurrFig);
         FigList.Clear();
         for (int i = 0; i < tmplist.Size(); i++)
         {
             FigList.Add(tmplist.Item(i));
         }
         lboxFigures.Items.Clear();
         CurrFig   = -1;
         isPressed = false;
         isMoved   = false;
         isChanged = false;
         FigList.PrintList(lboxFigures);
         grRez.Clear(Color.Transparent);
         grMajor.Clear(Color.Transparent);
         FigList.DrawAll(grMajor);
         grRez.DrawImage(Layers[2], 0, 0);
         btnBack.Enabled = false;
     }
 }
コード例 #5
0
 public UserFigure(string srcname, FiguresList.FigureList srclist, Pen pens, int x1, int y1, int x2, int y2) : base(pens, x1, y1, x2, y2)
 {
     Primitives    = new FiguresList.FigureList();
     SourceFigures = new FiguresList.FigureList();
     for (int i = 0; i < srclist.Size(); i++)
     {
         SourceFigures.Add(srclist.Item(i).Copy());
     }
     for (int i = 0; i < srclist.Size(); i++)
     {
         Primitives.Add(srclist.Item(i).Copy());
     }
     Name = srcname;
     GetEdgeCoordinates();
     GetRelativeCoords();
 }
コード例 #6
0
        public FiguresList.FigureList LoadFiguresList(FileStream fs, List <Type> types, List <string> nameslist, List <FiguresList.FigureList> srclists)
        {
            FiguresList.FigureList Rezlist     = new FiguresList.FigureList();
            SerialFiguresList      SerFigsList = (SerialFiguresList)formatter.Deserialize(fs);
            UserFigure             tmpusrfig   = new UserFigure("UserFigure", new Pen(Brushes.Black, 1), 0, 0, 0, 0);

            int i = 0;

            while (i < SerFigsList.Size())
            {
                //if (SerFigsList.Item(i).Name == "UserFigure" && SerFigsList.Item(i).isUserFigure == false)
                if (CheckUserName(nameslist, SerFigsList.Item(i).Name) && SerFigsList.Item(i).isUserFigure == false)
                {
                    if (srclists[FindNumberInList(nameslist, SerFigsList.Item(i).Name)].CalculateHash() == SerFigsList.Item(i).Hash)
                    {
                        tmpusrfig = new UserFigure(SerFigsList.Item(i).Name, new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth), SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2);
                        i++;
                        while (SerFigsList.Item(i).isUserFigure == true)
                        {
                            Type typ = null;
                            for (int j = 0; j < types.Count(); j++)
                            {
                                if (types[j].FullName == SerFigsList.Item(i).figtype)
                                {
                                    typ = types[j];
                                }
                            }
                            if (typ == null)
                            {
                                throw new SerializationException("Unable to load item " + SerFigsList.Item(i).figtype + ": Assembly is not found.");
                            }
                            var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                            var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                            if (fig is MyInterfaces.IFillingable)
                            {
                                ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                            }
                            fig.isUserFigure = SerFigsList.Item(i).isUserFigure;
                            tmpusrfig.SourceFigures.Add(fig);
                            i++;
                            if (i == SerFigsList.Size())
                            {
                                break;
                            }
                        }
                        tmpusrfig.OnDeserialize();
                        Rezlist.Add(tmpusrfig);
                    }
                    else
                    {
                        throw new SerializationException("Unable to load item \"UserFigure." + SerFigsList.Item(i).Name + "\": Saved picture doesn't match with loaded.");
                    }
                }
                //else if (SerFigsList.Item(i).Name != "UserFigure" && SerFigsList.Item(i).isUserFigure == false)
                else if (!CheckUserName(nameslist, SerFigsList.Item(i).Name) && SerFigsList.Item(i).isUserFigure == false)
                {
                    Type typ = null;
                    for (int j = 0; j < types.Count(); j++)
                    {
                        if (types[j].FullName == SerFigsList.Item(i).figtype)
                        {
                            typ = types[j];
                        }
                    }
                    if (typ == null)
                    {
                        if (SerFigsList.Item(i).figtype != "Lab1.UserFigure")
                        {
                            throw new SerializationException("Unable to load item \"" + SerFigsList.Item(i).figtype + "\": Assembly is not found.");
                        }
                        else
                        {
                            throw new SerializationException("Unable to load item \"UserFigure." + SerFigsList.Item(i).Name + "\": UserFigure is not found.");
                        }
                    }
                    var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                    var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                    if (fig is MyInterfaces.IFillingable)
                    {
                        ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                    }
                    fig.isUserFigure = SerFigsList.Item(i).isUserFigure;
                    Rezlist.Add(fig);
                    i++;
                    if (i == SerFigsList.Size())
                    {
                        break;
                    }
                }
            }

            return(Rezlist);
        }
コード例 #7
0
        private void btnMkUsrFig_Click(object sender, EventArgs e)
        {
            isOpenFile = true;
            string name = Microsoft.VisualBasic.Interaction.InputBox("Creating figure...", "Enter name:");

            {
                if (name != "")
                {
                    if (!IsExistName(name))
                    {
                        FileStream fs = new FileStream(Application.StartupPath.ToString() + "\\" + UserFiguresPath + "\\" + name + "." + UserFiguresExtension,
                                                       FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        userfigsbinser = new MyCustomFiguresBinarySerializer();
                        var transformer = new UserFiguresTransformer();
                        var tmplist     = transformer.TransformToFullList(FigList);
                        userfigsbinser.SaveFiguresList(fs, tmplist);
                        fs.Close();

                        for (int i = 0; i < tmplist.Size(); i++)
                        {
                            usrlst.Add(tmplist.Item(i).Copy());
                        }

                        SourceLists.Add(usrlst);
                        typ = Type.GetType("Lab1.UserFigure");
                        var nextRB = new RadioButton();
                        nextRB.Parent = grboxFigures;
                        nextRB.Left   = 8;
                        nextRB.Top    = StartRBPos;
                        StartRBPos   += 27;
                        nextRB.Width  = 100;
                        nextRB.Height = 21;
                        nextRB.Text   = name;
                        UserNamesList.Add(name);

                        nextRB.CheckedChanged += (a, b) =>
                        {
                            try
                            {
                                CurrentList = usrlst;
                                CurrentName = name;
                                FigParams   = new Object[] { CurrentName, CurrentList, CurrPen, 0, 0, 0, 0 };
                                figure      = (Figure.Figure)Activator.CreateInstance(typ, FigParams);
                                isChanged   = true;
                                isPointer   = false;
                            }
                            catch (Exception ee)
                            {
                                MessageBoxException(ee.Message);
                            }
                        };
                    }
                    else
                    {
                        MessageBoxError("Such name is already exist.", "Error");
                    }
                }
                else
                {
                    MessageBoxError("Field couldn't be empty.", "Error");
                }
            }
            isOpenFile = false;
        }